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

    https://github.com/apache/nifi/pull/2158#discussion_r140449340
  
    --- Diff: 
nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/test/java/org/apache/nifi/processors/adls/TestPutADLSFile.java
 ---
    @@ -0,0 +1,522 @@
    +/*
    + * 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.adls;
    +
    +import com.microsoft.azure.datalake.store.ADLStoreClient;
    +import com.microsoft.azure.datalake.store.ADLStoreOptions;
    +import okhttp3.mockwebserver.MockResponse;
    +import okhttp3.mockwebserver.MockWebServer;
    +import okhttp3.mockwebserver.QueueDispatcher;
    +import okhttp3.mockwebserver.RecordedRequest;
    +import org.apache.nifi.processor.Processor;
    +import org.apache.nifi.reporting.InitializationException;
    +import org.apache.nifi.util.TestRunner;
    +import org.apache.nifi.util.TestRunners;
    +import org.hamcrest.CoreMatchers;
    +import org.junit.Assert;
    +import org.junit.Before;
    +import org.junit.Test;
    +
    +import java.io.ByteArrayInputStream;
    +import java.io.IOException;
    +import java.io.InputStream;
    +import java.nio.file.Paths;
    +import java.util.HashMap;
    +import java.util.Map;
    +import java.util.concurrent.TimeUnit;
    +
    +
    +public class TestPutADLSFile {
    +
    +    private MockWebServer server;
    +    private ADLStoreClient client;
    +    private Processor processor;
    +    private TestRunner runner;
    +    Map<String, String> fileAttributes;
    +
    +    @Before
    +    public void init() throws IOException, InitializationException {
    +        server = new MockWebServer();
    +        QueueDispatcher dispatcher = new QueueDispatcher();
    +        dispatcher.setFailFast(new MockResponse().setResponseCode(400));
    +        server.setDispatcher(dispatcher);
    +        server.start();
    +        String accountFQDN = server.getHostName() + ":" + server.getPort();
    +        String dummyToken = "testDummyAadToken";
    +
    +        client = ADLStoreClient.createClient(accountFQDN, dummyToken);
    +        client.setOptions(new ADLStoreOptions().setInsecureTransport());
    +
    +        processor = new PutADLSWithMockClient(client);
    +
    +        runner = TestRunners.newTestRunner(processor);
    +
    +        runner.setProperty(ADLSConstants.ACCOUNT_NAME, accountFQDN);
    +        runner.setProperty(ADLSConstants.CLIENT_ID, "foobar");
    +        runner.setProperty(ADLSConstants.CLIENT_SECRET, "foobar");
    +        runner.setProperty(ADLSConstants.AUTH_TOKEN_ENDPOINT, "foobar");
    +        runner.setProperty(PutADLSFile.DIRECTORY, "/sample/");
    +        runner.setProperty(PutADLSFile.CONFLICT_RESOLUTION, 
PutADLSFile.FAIL_RESOLUTION_AV);
    +        runner.removeProperty(PutADLSFile.UMASK);
    +        runner.removeProperty(PutADLSFile.ACL);
    +
    +        fileAttributes = new HashMap<>();
    +        fileAttributes.put("filename", "sample.txt");
    +        fileAttributes.put("path", "/root/");
    +    }
    +
    +    @Test
    +    public void testPutConflictFail() throws IOException, 
InterruptedException {
    +
    +        //for create call
    +        server.enqueue(new MockResponse().setResponseCode(200));
    +        //for append call(internal call while writing to stream)
    +        server.enqueue(new MockResponse().setResponseCode(200));
    +        //for rename call(since its fail conflict)
    +        server.enqueue(new 
MockResponse().setResponseCode(200).setBody("{\"boolean\":true}"));
    +        //for delete call(removing temp file)
    +        server.enqueue(new MockResponse().setResponseCode(200));
    +
    +//        String bodySimpleFileContent = new 
String(Files.readAllBytes(Paths.get(bodySimpleFileName)));
    +        String bodySimpleFileContent = "sample content to be send to 
external adls resource";
    +        runner.enqueue(bodySimpleFileContent, fileAttributes);
    +
    +        runner.run();
    +
    +        RecordedRequest createRequest = server.takeRequest(1, 
TimeUnit.SECONDS);
    +        String queryOpCreateRequest = 
createRequest.getRequestUrl().queryParameter("op");
    +        String pathCreateRequest = createRequest.getPath();
    +        String queryOverwiteCreateRequest = 
createRequest.getRequestUrl().queryParameter("overwrite");
    +        Assert.assertEquals("CREATE", queryOpCreateRequest);
    +        Assert.assertEquals("true", queryOverwiteCreateRequest);
    +        String expectedPath = "sample.txt.nifipart";
    +        Assert.assertThat(pathCreateRequest, 
CoreMatchers.containsString(expectedPath));
    +
    +        RecordedRequest appendRequest = server.takeRequest(1, 
TimeUnit.SECONDS);
    +        String pathAppendRequest = appendRequest.getPath();
    +        String bodyAppendRequest = appendRequest.getBody().toString();
    +        String queryOpAppendRequest = 
appendRequest.getRequestUrl().queryParameter("op");
    +        Assert.assertEquals("APPEND", queryOpAppendRequest);
    +        Assert.assertEquals("[text="+bodySimpleFileContent+"]", 
bodyAppendRequest);
    +        Assert.assertThat(pathAppendRequest, 
CoreMatchers.containsString(expectedPath));
    +
    +        RecordedRequest renameRequest = server.takeRequest(1, 
TimeUnit.SECONDS);
    +        String pathRenameRequest = renameRequest.getPath();
    +        String queryOpRenameRequest = 
renameRequest.getRequestUrl().queryParameter("op");
    +        String queryOverwriteRenameRequest = 
renameRequest.getRequestUrl().queryParameter("overwrite");
    +        Assert.assertThat(pathRenameRequest, 
CoreMatchers.containsString(expectedPath));
    +        Assert.assertEquals("RENAME", queryOpRenameRequest);
    +        Assert.assertEquals(null, queryOverwriteRenameRequest);
    +
    +        RecordedRequest deleteRequest = server.takeRequest(1, 
TimeUnit.SECONDS);
    +        String pathDeleteRequest = deleteRequest.getPath();
    +        String queryOpDeleteRequest = 
deleteRequest.getRequestUrl().queryParameter("op");
    +        Assert.assertEquals("DELETE", queryOpDeleteRequest);
    +        Assert.assertThat(pathDeleteRequest, 
CoreMatchers.containsString(expectedPath));
    +
    +        runner.assertAllFlowFilesTransferred(ADLSConstants.REL_SUCCESS, 1);
    +    }
    +
    +    @Test
    +    public void testPutConflictReplace() throws IOException, 
InterruptedException {
    --- End diff --
    
    ````
    testPutConflictReplace(org.apache.nifi.processors.adls.TestPutADLSFile)  
Time elapsed: 0.031 sec  <<< FAILURE!
    java.lang.AssertionError: expected:<true> but was:<null>
        at org.junit.Assert.fail(Assert.java:88)
        at org.junit.Assert.failNotEquals(Assert.java:834)
        at org.junit.Assert.assertEquals(Assert.java:118)
        at org.junit.Assert.assertEquals(Assert.java:144)
        at 
org.apache.nifi.processors.adls.TestPutADLSFile.testPutConflictReplace(TestPutADLSFile.java:176)
    
    
    Results :
    
    Failed tests:
      TestPutADLSFile.testPutConflictReplace:176 expected:<true> but was:<null>
    ````


---

Reply via email to