exceptionfactory commented on code in PR #7752: URL: https://github.com/apache/nifi/pull/7752#discussion_r1333218746
########## nifi-nar-bundles/nifi-scripting-bundle/nifi-scripting-processors/src/test/java/org/apache/nifi/reporting/script/ScriptedReportingTaskTest.java: ########## @@ -0,0 +1,165 @@ +/* + * 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.reporting.script; + +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.controller.ConfigurationContext; +import org.apache.nifi.logging.ComponentLog; +import org.apache.nifi.processors.script.AccessibleScriptingComponentHelper; +import org.apache.nifi.processors.script.ScriptRunner; +import org.apache.nifi.provenance.ProvenanceEventRecord; +import org.apache.nifi.registry.VariableRegistry; +import org.apache.nifi.reporting.ReportingInitializationContext; +import org.apache.nifi.script.ScriptingComponentHelper; +import org.apache.nifi.script.ScriptingComponentUtils; +import org.apache.nifi.util.MockConfigurationContext; +import org.apache.nifi.util.MockEventAccess; +import org.apache.nifi.util.MockReportingContext; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.junit.jupiter.api.io.TempDir; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; + +import javax.script.ScriptEngine; +import java.math.BigInteger; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.nio.file.StandardCopyOption; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.UUID; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.doReturn; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Unit tests for ScriptedReportingTask. + */ +@ExtendWith(MockitoExtension.class) +class ScriptedReportingTaskTest { + private static final String SCRIPT_ENGINE = "Script Engine"; + private static final PropertyDescriptor SCRIPT_ENGINE_PROPERTY_DESCRIPTOR = new PropertyDescriptor.Builder().name(SCRIPT_ENGINE).build(); + private static final String GROOVY = "Groovy"; + @TempDir + private Path targetPath; + @Mock + private ReportingInitializationContext initContext; + private MockScriptedReportingTask task; + private Map<PropertyDescriptor, String> properties; + private ConfigurationContext configurationContext; + private MockReportingContext reportingContext; + + @BeforeEach + public void setUp(@Mock ComponentLog logger) { + task = new MockScriptedReportingTask(); + properties = new HashMap<>(); + configurationContext = new MockConfigurationContext(properties, null); + reportingContext = new MockReportingContext(new LinkedHashMap<>(), null, VariableRegistry.EMPTY_REGISTRY); + when(initContext.getIdentifier()).thenReturn(UUID.randomUUID().toString()); + when(initContext.getLogger()).thenReturn(logger); + } + + @Test + void testProvenanceGroovyScript() throws Exception { + properties.put(SCRIPT_ENGINE_PROPERTY_DESCRIPTOR, GROOVY); + Files.copy(Paths.get("src/test/resources/groovy/test_log_provenance_events.groovy"), targetPath, StandardCopyOption.REPLACE_EXISTING); + properties.put(ScriptingComponentUtils.SCRIPT_FILE, targetPath.toString()); + reportingContext.setProperty(SCRIPT_ENGINE, GROOVY); + reportingContext.setProperty(ScriptingComponentUtils.SCRIPT_FILE.getName(), targetPath.toString()); + + final MockEventAccess eventAccess = reportingContext.getEventAccess(); + for(long index = 1; index < 4; index++) { Review Comment: Extra space needed. -- 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: issues-unsubscr...@nifi.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org