You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by alopresto <gi...@git.apache.org> on 2017/03/09 04:18:10 UTC

[GitHub] nifi pull request #1474: NIFI-3442 - Explictly support EL on Username, passw...

Github user alopresto commented on a diff in the pull request:

    https://github.com/apache/nifi/pull/1474#discussion_r105083940
  
    --- Diff: nifi-nar-bundles/nifi-standard-bundle/nifi-standard-processors/src/test/java/org/apache/nifi/processors/standard/TestFTP.java ---
    @@ -0,0 +1,170 @@
    +/*
    + * Licensed to the Apache Software Foundation (ASF) under one or more
    + * contributor license agreements.  See the NOTICE file distributed with
    + * this work for additional information regarding copyright ownership.
    + * The ASF licenses this file to You under the Apache License, Version 2.0
    + * (the "License"); you may not use this file except in compliance with
    + * the License.  You may obtain a copy of the License at
    + *
    + *     http://www.apache.org/licenses/LICENSE-2.0
    + *
    + * Unless required by applicable law or agreed to in writing, software
    + * distributed under the License is distributed on an "AS IS" BASIS,
    + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    + * See the License for the specific language governing permissions and
    + * limitations under the License.
    + */
    +package org.apache.nifi.processors.standard;
    +
    +import org.apache.nifi.components.ValidationResult;
    +import org.apache.nifi.flowfile.attributes.CoreAttributes;
    +import org.apache.nifi.processor.ProcessContext;
    +import org.apache.nifi.processors.standard.util.FTPTransfer;
    +import org.apache.nifi.util.MockFlowFile;
    +import org.apache.nifi.util.MockProcessContext;
    +import org.apache.nifi.util.TestRunner;
    +import org.apache.nifi.util.TestRunners;
    +import org.junit.After;
    +import org.junit.Assert;
    +import org.junit.Before;
    +import org.junit.Test;
    +import org.mockftpserver.fake.FakeFtpServer;
    +import org.mockftpserver.fake.UserAccount;
    +import org.mockftpserver.fake.filesystem.DirectoryEntry;
    +import org.mockftpserver.fake.filesystem.FileEntry;
    +import org.mockftpserver.fake.filesystem.FileSystem;
    +import org.mockftpserver.fake.filesystem.WindowsFakeFileSystem;
    +
    +import java.io.FileInputStream;
    +
    +import java.io.IOException;
    +import java.util.Collection;
    +import java.util.HashMap;
    +import java.util.HashSet;
    +import java.util.Map;
    +
    +import static org.junit.Assert.assertEquals;
    +
    +public class TestFTP {
    +
    +    final FakeFtpServer fakeFtpServer = new FakeFtpServer();
    +    final String username = "nifi-ftp-user";
    +    final String password = "Test test test chocolate";
    +    int ftpPort;
    +
    +    @Before
    +    public void setUp() throws Exception {
    +        fakeFtpServer.setServerControlPort(0);
    +        fakeFtpServer.addUserAccount(new UserAccount(username, password, "c:\\data"));
    +
    +        FileSystem fileSystem = new WindowsFakeFileSystem();
    +        fileSystem.add(new DirectoryEntry("c:\\data"));
    +        fakeFtpServer.setFileSystem(fileSystem);
    +
    +        fakeFtpServer.start();
    +
    +        ftpPort = fakeFtpServer.getServerControlPort();
    +    }
    +
    +    @After
    +    public void tearDown() throws Exception {
    +        fakeFtpServer.stop();
    +    }
    +
    +    @Test
    +    public void testValidators() {
    +        TestRunner runner = TestRunners.newTestRunner(PutFTP.class);
    +        Collection<ValidationResult> results;
    +        ProcessContext pc;
    +
    +        /* Set the basic required values */
    +        results = new HashSet<>();
    +        runner.setProperty(FTPTransfer.USERNAME, "${el-username}");
    +        runner.setProperty(FTPTransfer.HOSTNAME, "static-hostname");
    +        runner.setProperty(FTPTransfer.PORT, "${el-portNumber}");
    +
    +        results = new HashSet<>();
    +        runner.setProperty(FTPTransfer.REMOTE_PATH, "static-remote-target");
    +        runner.enqueue(new byte[0]);
    +        pc = runner.getProcessContext();
    +        if (pc instanceof MockProcessContext) {
    +            results = ((MockProcessContext) pc).validate();
    +        }
    +        assertEquals(0, results.size());
    +
    +
    +        results = new HashSet<>();
    +        runner.setProperty(FTPTransfer.REMOTE_PATH, "${el-remote-target}");
    +        runner.enqueue(new byte[0]);
    +        pc = runner.getProcessContext();
    +        if (pc instanceof MockProcessContext) {
    +            results = ((MockProcessContext) pc).validate();
    +        }
    +        assertEquals(0, results.size());
    +
    +        results = new HashSet<>();
    +        runner.setProperty(FTPTransfer.USERNAME, "static-username");
    +        runner.enqueue(new byte[0]);
    +        pc = runner.getProcessContext();
    +        if (pc instanceof MockProcessContext) {
    +            results = ((MockProcessContext) pc).validate();
    +        }
    +        assertEquals(0, results.size());
    +
    +        /* Try an invalid expression */
    +        results = new HashSet<>();
    +        runner.setProperty(FTPTransfer.USERNAME, "$static-username}");
    --- End diff --
    
    In the test, `MockValidationContext` is used which does not validate the actual EL expression. Therefore, I was getting a test failure here (**0** validation errors present when **1** was expected). I changed the property value to be `""` and the test succeeded (i.e. the validator threw an error). 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---