tpalfy commented on code in PR #6355:
URL: https://github.com/apache/nifi/pull/6355#discussion_r966201974


##########
nifi-nar-bundles/nifi-box-bundle/nifi-box-processors/src/test/java/org/apache/nifi/processors/box/AbstractBoxFilesIT.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.box;
+
+import com.box.sdk.BoxAPIConnection;
+import com.box.sdk.BoxConfig;
+import com.box.sdk.BoxDeveloperEditionAPIConnection;
+import com.box.sdk.BoxFile;
+import com.box.sdk.BoxFolder;
+import org.apache.nifi.processor.Processor;
+import org.apache.nifi.util.TestRunner;
+import org.apache.nifi.util.TestRunners;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+
+import java.io.ByteArrayInputStream;
+import java.io.FileReader;
+import java.io.Reader;
+import java.nio.charset.StandardCharsets;
+import java.util.Arrays;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+/**
+ * Set the following constants before running:<br />
+ * <br />
+ * FOLDER_ID - The ID of a Folder the test can use to create files and 
sub-folders within.<br />
+ * USER_ID - The ID of the user owning the Folder.<br />
+ * BOX_CONFIG_FILE - An App Settings Configuration JSON file. The app needs to 
have 'OAuth 2.0 with JSON Web Tokens (Server Authentication)' authentication 
method,
+ * have App + Enterprise access level and be able to read and write files and 
folders as well as generate user access tokens.<br />
+ * <br />
+ * Created files and folders are cleaned up, but it's advisable to dedicate a 
folder for this test so that it can be cleaned up easily should the test fail 
to do so.
+ */
+public abstract class AbstractBoxFilesIT<T extends BoxTrait & Processor> {
+    static final String FOLDER_ID = "";
+    static final String USER_ID = "";
+    static final String BOX_CONFIG_FILE = "";
+
+    protected static final String DEFAULT_FILE_CONTENT = "test_content";
+    public static final String MAIN_FOLDER_NAME = "main";
+
+    protected T testSubject;
+    protected TestRunner testRunner;
+
+    protected BoxAPIConnection boxAPIConnection;
+
+    protected String targetFolderName;
+    protected String mainFolderId;
+
+    protected abstract T createTestSubject();
+
+    @BeforeEach
+    protected void init() throws Exception {
+        testSubject = createTestSubject();
+        testRunner = createTestRunner();
+
+        try (
+            Reader reader = new FileReader(BOX_CONFIG_FILE);
+        ) {
+            BoxConfig boxConfig = BoxConfig.readFrom(reader);
+            boxAPIConnection = 
BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig);
+            boxAPIConnection.asUser(USER_ID);
+        }
+
+        targetFolderName = new BoxFolder(boxAPIConnection, 
FOLDER_ID).getInfo("name").getName();
+
+        BoxFolder.Info mainFolderInfo = createFolder(MAIN_FOLDER_NAME, 
FOLDER_ID);
+        mainFolderId = mainFolderInfo.getID();
+    }
+
+    @AfterEach
+    protected void tearDown() {
+        if (boxAPIConnection != null) {
+            BoxFolder folder = new BoxFolder(boxAPIConnection, mainFolderId);
+            folder.delete(true);
+        }
+    }
+
+    protected TestRunner createTestRunner() {
+        TestRunner testRunner = TestRunners.newTestRunner(testSubject);

Review Comment:
   I think it's better though to have a simple variable instead of an 
expression as a return value.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to