This is an automated email from the ASF dual-hosted git repository. exceptionfactory pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/nifi.git
commit e8d554d9b40f9f540d1457830721556fbd95edb1 Author: dan-s1 <[email protected]> AuthorDate: Fri Nov 25 17:39:36 2022 +0000 NIFI-10876 Converted some nifi-framework tests from JUnit 4 to JUnit 5 This closes #6720 Signed-off-by: David Handermann <[email protected]> --- .../nifi/authorization/AuthorizerFactoryTest.java | 65 ++++----- .../nifi/web/api/dto/TestProcessGroupDTO.java | 9 +- .../nifi/web/api/dto/TestProcessGroupEntity.java | 9 +- .../web/api/dto/TestRemoteProcessGroupDTO.java | 20 ++- .../nifi/web/api/dto/util/TestNumberUtil.java | 7 +- .../html/ProcessorDocumentationWriterTest.java | 20 +-- .../FileAccessPolicyProviderTest.java | 57 +++++--- .../nifi/authorization/FileAuthorizerTest.java | 73 ++++++---- .../authorization/FileUserGroupProviderTest.java | 43 +++--- .../resource/DataAuthorizableTest.java | 21 +-- .../resource/OperationAuthorizableTest.java | 6 +- .../resource/ProvenanceDataAuthorizableTest.java | 22 +-- .../jaxb/message/TestJaxbProtocolUtils.java | 6 +- .../repository/TestRingBufferEventRepository.java | 17 ++- .../repository/TestStandardFlowFileRecord.java | 7 +- .../repository/TestStandardProvenanceReporter.java | 6 +- .../metrics/TestSecondPrecisionEventContainer.java | 8 +- ...StandardControllerServiceInvocationHandler.java | 18 +-- ...StandardVersionedComponentSynchronizerTest.java | 23 ++-- .../nifi/logging/TestStandardLogRepository.java | 6 +- .../parameter/TestStandardParameterContext.java | 150 ++++++++++----------- .../nifi/processor/TestStandardPropertyValue.java | 12 +- .../processor/TestStandardValidationContext.java | 7 +- .../NiFiRegistryExtensionBundleMetadataTest.java | 6 +- .../flow/mapping/TestNiFiRegistryFlowMapper.java | 8 +- .../org/apache/nifi/util/ReflectionUtilsTest.java | 36 ++--- .../nifi/util/TestFlowDifferenceFilters.java | 24 ++-- .../TestControllerServiceApiMatcher.java | 10 +- .../apache/nifi/controller/TestStandardFunnel.java | 4 +- .../apache/nifi/util/CharacterFilterUtilsTest.java | 7 +- 30 files changed, 367 insertions(+), 340 deletions(-) diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-authorizer/src/test/java/org/apache/nifi/authorization/AuthorizerFactoryTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-authorizer/src/test/java/org/apache/nifi/authorization/AuthorizerFactoryTest.java index 6dbe4bbdc7..888a3842b9 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-authorizer/src/test/java/org/apache/nifi/authorization/AuthorizerFactoryTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-authorizer/src/test/java/org/apache/nifi/authorization/AuthorizerFactoryTest.java @@ -18,20 +18,20 @@ package org.apache.nifi.authorization; import org.apache.nifi.authorization.AuthorizationResult.Result; import org.apache.nifi.authorization.exception.AuthorizerCreationException; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.util.HashSet; import java.util.LinkedHashSet; import java.util.Set; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; public class AuthorizerFactoryTest { - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenPoliciesWithSameResourceAndAction() { User user1 = new User.Builder().identifier("user-id-1").identity("user-1").build(); @@ -58,10 +58,11 @@ public class AuthorizerFactoryTest { AuthorizerConfigurationContext context = Mockito.mock(AuthorizerConfigurationContext.class); Authorizer authorizer = AuthorizerFactory.installIntegrityChecks(new MockPolicyBasedAuthorizer(new HashSet<>(), users, policies)); - authorizer.onConfigured(context); + + assertThrows(AuthorizerCreationException.class, () -> authorizer.onConfigured(context)); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenUsersWithSameIdentity() { User user1 = new User.Builder().identifier("user-id-1").identity("user-1").build(); User user2 = new User.Builder().identifier("user-id-2").identity("user-1").build(); @@ -72,10 +73,11 @@ public class AuthorizerFactoryTest { AuthorizerConfigurationContext context = Mockito.mock(AuthorizerConfigurationContext.class); Authorizer authorizer = AuthorizerFactory.installIntegrityChecks(new MockPolicyBasedAuthorizer(new HashSet<>(), users, new HashSet<>())); - authorizer.onConfigured(context); + + assertThrows(AuthorizerCreationException.class, () -> authorizer.onConfigured(context)); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenGroupsWithSameName() { Group group1 = new Group.Builder().identifier("group-id-1").name("group-1").build(); Group group2 = new Group.Builder().identifier("group-id-2").name("group-1").build(); @@ -86,7 +88,8 @@ public class AuthorizerFactoryTest { AuthorizerConfigurationContext context = Mockito.mock(AuthorizerConfigurationContext.class); Authorizer authorizer = AuthorizerFactory.installIntegrityChecks(new MockPolicyBasedAuthorizer(groups, new HashSet<>(), new HashSet<>())); - authorizer.onConfigured(context); + + assertThrows(AuthorizerCreationException.class, () -> authorizer.onConfigured(context)); } @Test @@ -117,12 +120,8 @@ public class AuthorizerFactoryTest { .addUser(user1.getIdentifier()) .build(); - try { - accessPolicyProvider.addAccessPolicy(policy2); - Assert.fail("Should have thrown exception"); - } catch (IllegalStateException e) { - - } + assertThrows(IllegalStateException.class, + () -> accessPolicyProvider.addAccessPolicy(policy2)); } @Test @@ -140,12 +139,8 @@ public class AuthorizerFactoryTest { User user2 = new User.Builder().identifier("user-id-2").identity("user-1").build(); - try { - userGroupProvider.addUser(user2); - Assert.fail("Should have thrown exception"); - } catch (IllegalStateException e) { - - } + assertThrows(IllegalStateException.class, + () -> userGroupProvider.addUser(user2)); } @Test @@ -163,12 +158,8 @@ public class AuthorizerFactoryTest { Group group2 = new Group.Builder().identifier("group-id-2").name("group-1").build(); - try { - userGroupProvider.addGroup(group2); - Assert.fail("Should have thrown exception"); - } catch (IllegalStateException e) { - - } + assertThrows(IllegalStateException.class, + () -> userGroupProvider.addGroup(group2)); } @Test @@ -221,13 +212,10 @@ public class AuthorizerFactoryTest { User user2 = new User.Builder().identifier("user-id-2").identity("xyz").build(); userGroupProvider.addUser(user2); - try { - User user1Updated = new User.Builder().identifier("user-id-1").identity("xyz").build(); - userGroupProvider.updateUser(user1Updated); - Assert.fail("Should have thrown exception"); - } catch (IllegalStateException e) { + User user1Updated = new User.Builder().identifier("user-id-1").identity("xyz").build(); - } + assertThrows(IllegalStateException.class, + () -> userGroupProvider.updateUser(user1Updated)); } @Test @@ -246,13 +234,10 @@ public class AuthorizerFactoryTest { Group group2 = new Group.Builder().identifier("group-id-2").name("xyz").build(); userGroupProvider.addGroup(group2); - try { - Group group1Updated = new Group.Builder().identifier("group-id-1").name("xyz").build(); - userGroupProvider.updateGroup(group1Updated); - Assert.fail("Should have thrown exception"); - } catch (IllegalStateException e) { + Group group1Updated = new Group.Builder().identifier("group-id-1").name("xyz").build(); - } + assertThrows(IllegalStateException.class, + () -> userGroupProvider.updateGroup(group1Updated)); } @Test diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/TestProcessGroupDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/TestProcessGroupDTO.java index 5c28b7183b..d12998c3f2 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/TestProcessGroupDTO.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/TestProcessGroupDTO.java @@ -16,16 +16,17 @@ */ package org.apache.nifi.web.api.dto; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class TestProcessGroupDTO { @Test public void testGetInputPortCount() { final ProcessGroupDTO dto = new ProcessGroupDTO(); - assertEquals(null, dto.getInputPortCount()); + assertNull(dto.getInputPortCount()); dto.setLocalInputPortCount(3); dto.setPublicInputPortCount(4); @@ -38,7 +39,7 @@ public class TestProcessGroupDTO { @Test public void testGetOutputPortCount() { final ProcessGroupDTO dto = new ProcessGroupDTO(); - assertEquals(null, dto.getOutputPortCount()); + assertNull(dto.getOutputPortCount()); dto.setLocalOutputPortCount(2); dto.setPublicOutputPortCount(3); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/TestProcessGroupEntity.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/TestProcessGroupEntity.java index ae4124db24..5fbfe50879 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/TestProcessGroupEntity.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/TestProcessGroupEntity.java @@ -17,16 +17,17 @@ package org.apache.nifi.web.api.dto; import org.apache.nifi.web.api.entity.ProcessGroupEntity; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class TestProcessGroupEntity { @Test public void testGetInputPortCount() { final ProcessGroupEntity entity = new ProcessGroupEntity(); - assertEquals(null, entity.getInputPortCount()); + assertNull(entity.getInputPortCount()); entity.setLocalInputPortCount(3); entity.setPublicInputPortCount(4); @@ -39,7 +40,7 @@ public class TestProcessGroupEntity { @Test public void testGetOutputPortCount() { final ProcessGroupEntity entity = new ProcessGroupEntity(); - assertEquals(null, entity.getOutputPortCount()); + assertNull(entity.getOutputPortCount()); entity.setLocalOutputPortCount(2); entity.setPublicOutputPortCount(3); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/TestRemoteProcessGroupDTO.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/TestRemoteProcessGroupDTO.java index ff8c61bbfb..e43ec024e2 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/TestRemoteProcessGroupDTO.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/TestRemoteProcessGroupDTO.java @@ -16,10 +16,10 @@ */ package org.apache.nifi.web.api.dto; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class TestRemoteProcessGroupDTO { @@ -30,20 +30,18 @@ public class TestRemoteProcessGroupDTO { assertNull(dto.getTargetUri()); dto.setTargetUris("http://node1:8080/nifi, http://node2:8080/nifi"); - assertEquals("If targetUris are set but targetUri is not, it should returns the first uru of the targetUris", - "http://node1:8080/nifi", dto.getTargetUri()); + assertEquals("http://node1:8080/nifi", dto.getTargetUri(), + "If targetUris are set but targetUri is not, it should returns the first uri of the targetUris"); assertEquals("http://node1:8080/nifi, http://node2:8080/nifi", dto.getTargetUris()); dto.setTargetUri("http://node3:9090/nifi"); - assertEquals("If both targetUri and targetUris are set, each returns its own values", - "http://node3:9090/nifi", dto.getTargetUri()); + assertEquals("http://node3:9090/nifi", dto.getTargetUri(), + "If both targetUri and targetUris are set, each returns its own values"); assertEquals("http://node1:8080/nifi, http://node2:8080/nifi", dto.getTargetUris()); dto.setTargetUris(null); assertEquals("http://node3:9090/nifi", dto.getTargetUri()); - assertEquals("getTargetUris should return targetUri when it's not set", - "http://node3:9090/nifi", dto.getTargetUris()); - + assertEquals("http://node3:9090/nifi", dto.getTargetUris(), + "getTargetUris should return targetUri when it's not set"); } - } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/util/TestNumberUtil.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/util/TestNumberUtil.java index 85395431f8..68cba57c5c 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/util/TestNumberUtil.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-client-dto/src/test/java/org/apache/nifi/web/api/dto/util/TestNumberUtil.java @@ -16,10 +16,11 @@ */ package org.apache.nifi.web.api.dto.util; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.apache.nifi.web.api.dto.util.NumberUtil.sumNullableIntegers; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class TestNumberUtil { @@ -31,7 +32,7 @@ public class TestNumberUtil { assertEquals(Integer.valueOf(0), sumNullableIntegers(-1, null, 1)); - assertEquals(null, sumNullableIntegers(null, null)); + assertNull(sumNullableIntegers(null, null)); } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java index c10428e33b..401bfaf6a5 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-documentation/src/test/java/org/apache/nifi/documentation/html/ProcessorDocumentationWriterTest.java @@ -28,14 +28,14 @@ import org.apache.nifi.documentation.example.ProcessorWithLogger; import org.apache.nifi.init.ProcessorInitializer; import org.apache.nifi.nar.ExtensionManager; import org.apache.nifi.nar.StandardExtensionDiscoveringManager; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.ByteArrayOutputStream; import java.io.IOException; import static org.apache.nifi.documentation.html.XmlValidator.assertContains; import static org.apache.nifi.documentation.html.XmlValidator.assertNotContains; +import static org.junit.jupiter.api.Assertions.assertEquals; public class ProcessorDocumentationWriterTest { @@ -115,11 +115,11 @@ public class ProcessorDocumentationWriterTest { assertContains(results, "Not Specified"); // verify the right OnRemoved and OnShutdown methods were called - Assert.assertEquals(0, processor.getOnRemovedArgs()); - Assert.assertEquals(0, processor.getOnRemovedNoArgs()); + assertEquals(0, processor.getOnRemovedArgs()); + assertEquals(0, processor.getOnRemovedNoArgs()); - Assert.assertEquals(1, processor.getOnShutdownArgs()); - Assert.assertEquals(1, processor.getOnShutdownNoArgs()); + assertEquals(1, processor.getOnShutdownArgs()); + assertEquals(1, processor.getOnShutdownNoArgs()); } @Test @@ -236,10 +236,10 @@ public class ProcessorDocumentationWriterTest { assertNotContains(results, "Additional Details..."); // verify the right OnRemoved and OnShutdown methods were called - Assert.assertEquals(0, processor.getOnRemovedArgs()); - Assert.assertEquals(0, processor.getOnRemovedNoArgs()); + assertEquals(0, processor.getOnRemovedArgs()); + assertEquals(0, processor.getOnRemovedNoArgs()); - Assert.assertEquals(1, processor.getOnShutdownArgs()); - Assert.assertEquals(1, processor.getOnShutdownNoArgs()); + assertEquals(1, processor.getOnShutdownArgs()); + assertEquals(1, processor.getOnShutdownNoArgs()); } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileAccessPolicyProviderTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileAccessPolicyProviderTest.java index 92ac0b4dfc..2c60e59d27 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileAccessPolicyProviderTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileAccessPolicyProviderTest.java @@ -24,9 +24,9 @@ import org.apache.nifi.authorization.resource.ResourceType; import org.apache.nifi.components.PropertyValue; import org.apache.nifi.util.NiFiProperties; import org.apache.nifi.util.file.FileUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -41,11 +41,12 @@ import java.util.Map; import java.util.Properties; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -151,7 +152,7 @@ public class FileAccessPolicyProviderTest { private AuthorizerConfigurationContext configurationContext; - @Before + @BeforeEach public void setup() throws IOException { // primary authorizations primaryAuthorizations = new File("target/authorizations/authorizations.xml"); @@ -271,7 +272,7 @@ public class FileAccessPolicyProviderTest { accessPolicyProvider.initialize(initializationContext); } - @After + @AfterEach public void cleanup() throws Exception { deleteFile(primaryAuthorizations); deleteFile(primaryTenants); @@ -507,17 +508,19 @@ public class FileAccessPolicyProviderTest { assertTrue(outputPortPolicy.getUsers().contains(user4.getIdentifier())); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenBadLegacyUsersFileProvided() throws Exception { when(configurationContext.getProperty(eq(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE))) .thenReturn(new StandardPropertyValue("src/test/resources/does-not-exist.xml", null, ParameterLookup.EMPTY)); writeFile(primaryAuthorizations, EMPTY_AUTHORIZATIONS_CONCISE); writeFile(primaryTenants, EMPTY_TENANTS_CONCISE); - accessPolicyProvider.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> accessPolicyProvider.onConfigured(configurationContext)); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenInitialAdminAndLegacyUsersProvided() throws Exception { final String adminIdentity = "admin-user"; when(configurationContext.getProperty(eq(FileAccessPolicyProvider.PROP_INITIAL_ADMIN_IDENTITY))) @@ -528,7 +531,9 @@ public class FileAccessPolicyProviderTest { writeFile(primaryAuthorizations, EMPTY_AUTHORIZATIONS_CONCISE); writeFile(primaryTenants, EMPTY_TENANTS_CONCISE); - accessPolicyProvider.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> accessPolicyProvider.onConfigured(configurationContext)); } @Test @@ -806,7 +811,7 @@ public class FileAccessPolicyProviderTest { assertNull(accessPolicyProvider.getAccessPolicy(ResourceType.Proxy.getValue(), RequestAction.WRITE)); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenNodeGroupDoesNotExist() throws Exception { final String adminIdentity = "admin-user"; @@ -819,7 +824,9 @@ public class FileAccessPolicyProviderTest { writeFile(primaryTenants, TENANTS_FOR_ADMIN_AND_NODE_GROUP); userGroupProvider.onConfigured(configurationContext); - accessPolicyProvider.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> accessPolicyProvider.onConfigured(configurationContext)); } @Test @@ -857,26 +864,32 @@ public class FileAccessPolicyProviderTest { assertEquals(primaryTenants.length(), restoreTenants.length()); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenPrimaryDoesNotExist() throws Exception { writeFile(restoreAuthorizations, EMPTY_AUTHORIZATIONS_CONCISE); userGroupProvider.onConfigured(configurationContext); - accessPolicyProvider.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, () -> + accessPolicyProvider.onConfigured(configurationContext)); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenPrimaryAuthorizationsDifferentThanRestore() throws Exception { writeFile(primaryAuthorizations, EMPTY_AUTHORIZATIONS); writeFile(restoreAuthorizations, EMPTY_AUTHORIZATIONS_CONCISE); userGroupProvider.onConfigured(configurationContext); - accessPolicyProvider.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> accessPolicyProvider.onConfigured(configurationContext)); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWithBadAuthorizationsSchema() throws Exception { writeFile(primaryAuthorizations, BAD_SCHEMA_AUTHORIZATIONS); userGroupProvider.onConfigured(configurationContext); - accessPolicyProvider.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> accessPolicyProvider.onConfigured(configurationContext)); } @Test diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileAuthorizerTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileAuthorizerTest.java index b238d24f70..85aa1410d3 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileAuthorizerTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileAuthorizerTest.java @@ -26,11 +26,11 @@ import org.apache.nifi.authorization.resource.ResourceType; import org.apache.nifi.components.PropertyValue; import org.apache.nifi.util.NiFiProperties; import org.apache.nifi.util.file.FileUtils; -import org.junit.After; -import org.junit.Assume; -import org.junit.Before; -import org.junit.BeforeClass; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.Assumptions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -45,12 +45,13 @@ import java.util.Map; import java.util.Properties; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -162,12 +163,12 @@ public class FileAuthorizerTest { private AuthorizerConfigurationContext configurationContext; - @BeforeClass + @BeforeAll public static void setUpSuite() { - Assume.assumeTrue("Test only runs on *nix", !SystemUtils.IS_OS_WINDOWS); + Assumptions.assumeTrue(!SystemUtils.IS_OS_WINDOWS, "Test only runs on *nix"); } - @Before + @BeforeEach public void setup() throws IOException { // primary authorizations primaryAuthorizations = new File("target/authorizations/authorizations.xml"); @@ -247,7 +248,7 @@ public class FileAuthorizerTest { authorizer.initialize(null); } - @After + @AfterEach public void cleanup() throws Exception { deleteFile(primaryAuthorizations); deleteFile(primaryTenants); @@ -515,17 +516,19 @@ public class FileAuthorizerTest { assertTrue(outputPortPolicy.getUsers().contains(user4.getIdentifier())); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenBadLegacyUsersFileProvided() throws Exception { when(configurationContext.getProperty(Mockito.eq(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE))) .thenReturn(new StandardPropertyValue("src/test/resources/does-not-exist.xml", null, ParameterLookup.EMPTY)); writeFile(primaryAuthorizations, EMPTY_AUTHORIZATIONS_CONCISE); writeFile(primaryTenants, EMPTY_TENANTS_CONCISE); - authorizer.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> authorizer.onConfigured(configurationContext)); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenInitialAdminAndLegacyUsersProvided() throws Exception { final String adminIdentity = "admin-user"; when(configurationContext.getProperty(Mockito.eq(FileAccessPolicyProvider.PROP_INITIAL_ADMIN_IDENTITY))) @@ -536,7 +539,9 @@ public class FileAuthorizerTest { writeFile(primaryAuthorizations, EMPTY_AUTHORIZATIONS_CONCISE); writeFile(primaryTenants, EMPTY_TENANTS_CONCISE); - authorizer.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> authorizer.onConfigured(configurationContext)); } @Test @@ -831,37 +836,47 @@ public class FileAuthorizerTest { assertEquals(primaryTenants.length(), restoreTenants.length()); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenPrimaryDoesNotExist() throws Exception { writeFile(restoreAuthorizations, EMPTY_AUTHORIZATIONS_CONCISE); writeFile(restoreTenants, EMPTY_TENANTS_CONCISE); - authorizer.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> authorizer.onConfigured(configurationContext)); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenPrimaryAuthorizationsDifferentThanRestore() throws Exception { writeFile(primaryAuthorizations, EMPTY_AUTHORIZATIONS); writeFile(restoreAuthorizations, EMPTY_AUTHORIZATIONS_CONCISE); - authorizer.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> authorizer.onConfigured(configurationContext)); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenPrimaryTenantsDifferentThanRestore() throws Exception { writeFile(primaryTenants, EMPTY_TENANTS); writeFile(restoreTenants, EMPTY_TENANTS_CONCISE); - authorizer.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> authorizer.onConfigured(configurationContext)); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWithBadAuthorizationsSchema() throws Exception { writeFile(primaryAuthorizations, BAD_SCHEMA_AUTHORIZATIONS); - authorizer.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> authorizer.onConfigured(configurationContext)); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWithBadTenantsSchema() throws Exception { writeFile(primaryTenants, BAD_SCHEMA_TENANTS); - authorizer.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> authorizer.onConfigured(configurationContext)); } @Test diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileUserGroupProviderTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileUserGroupProviderTest.java index 2f51e1f346..6bcae42c8e 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileUserGroupProviderTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-file-authorizer/src/test/java/org/apache/nifi/authorization/FileUserGroupProviderTest.java @@ -22,9 +22,9 @@ import org.apache.nifi.authorization.exception.AuthorizerCreationException; import org.apache.nifi.components.PropertyValue; import org.apache.nifi.util.NiFiProperties; import org.apache.nifi.util.file.FileUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -38,10 +38,11 @@ import java.util.Map; import java.util.Properties; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.mock; @@ -96,7 +97,7 @@ public class FileUserGroupProviderTest { private AuthorizerConfigurationContext configurationContext; - @Before + @BeforeEach public void setup() throws IOException { // primary tenants primaryTenants = new File("target/authorizations/users.xml"); @@ -144,7 +145,7 @@ public class FileUserGroupProviderTest { userGroupProvider.initialize(null); } - @After + @AfterEach public void cleanup() throws Exception { deleteFile(primaryTenants); deleteFile(restoreTenants); @@ -274,13 +275,15 @@ public class FileUserGroupProviderTest { assertEquals("GROUP1", group1.getName()); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenBadLegacyUsersFileProvided() throws Exception { when(configurationContext.getProperty(eq(FileAuthorizer.PROP_LEGACY_AUTHORIZED_USERS_FILE))) .thenReturn(new StandardPropertyValue("src/test/resources/does-not-exist.xml", null, ParameterLookup.EMPTY)); writeFile(primaryTenants, EMPTY_TENANTS_CONCISE); - userGroupProvider.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> userGroupProvider.onConfigured(configurationContext)); } @Test @@ -356,24 +359,30 @@ public class FileUserGroupProviderTest { assertEquals(primaryTenants.length(), restoreTenants.length()); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenPrimaryDoesNotExist() throws Exception { writeFile(restoreTenants, EMPTY_TENANTS_CONCISE); - userGroupProvider.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> userGroupProvider.onConfigured(configurationContext)); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWhenPrimaryTenantsDifferentThanRestore() throws Exception { writeFile(primaryTenants, EMPTY_TENANTS); writeFile(restoreTenants, EMPTY_TENANTS_CONCISE); - userGroupProvider.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> userGroupProvider.onConfigured(configurationContext)); } - @Test(expected = AuthorizerCreationException.class) + @Test public void testOnConfiguredWithBadTenantsSchema() throws Exception { writeFile(primaryTenants, BAD_SCHEMA_TENANTS); - userGroupProvider.onConfigured(configurationContext); + + assertThrows(AuthorizerCreationException.class, + () -> userGroupProvider.onConfigured(configurationContext)); } @Test diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/test/java/org/apache/nifi/authorization/resource/DataAuthorizableTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/test/java/org/apache/nifi/authorization/resource/DataAuthorizableTest.java index 331d179c7e..3bb06b1e43 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/test/java/org/apache/nifi/authorization/resource/DataAuthorizableTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/test/java/org/apache/nifi/authorization/resource/DataAuthorizableTest.java @@ -24,10 +24,11 @@ import org.apache.nifi.authorization.Authorizer; import org.apache.nifi.authorization.RequestAction; import org.apache.nifi.authorization.user.NiFiUser; import org.apache.nifi.authorization.user.StandardNiFiUser.Builder; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.mock; @@ -45,7 +46,7 @@ public class DataAuthorizableTest { private Authorizer testAuthorizer; private DataAuthorizable testDataAuthorizable; - @Before + @BeforeEach public void setup() { testProcessorAuthorizable = mock(Authorizable.class); when(testProcessorAuthorizable.getParentAuthorizable()).thenReturn(null); @@ -69,9 +70,11 @@ public class DataAuthorizableTest { testDataAuthorizable = new DataAuthorizable(testProcessorAuthorizable); } - @Test(expected = AccessDeniedException.class) + @Test public void testAuthorizeNullUser() { - testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, null, null); + assertThrows(AccessDeniedException.class,() -> + testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, + null, null)); } @Test @@ -80,10 +83,12 @@ public class DataAuthorizableTest { assertEquals(Result.Denied, result.getResult()); } - @Test(expected = AccessDeniedException.class) + @Test public void testAuthorizeUnauthorizedUser() { final NiFiUser user = new Builder().identity("unknown").build(); - testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null); + + assertThrows(AccessDeniedException.class, () -> + testDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null)); } @Test diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/test/java/org/apache/nifi/authorization/resource/OperationAuthorizableTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/test/java/org/apache/nifi/authorization/resource/OperationAuthorizableTest.java index 87a4fc48b3..669a8c3db6 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/test/java/org/apache/nifi/authorization/resource/OperationAuthorizableTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/test/java/org/apache/nifi/authorization/resource/OperationAuthorizableTest.java @@ -22,12 +22,12 @@ import org.apache.nifi.authorization.MockPolicyBasedAuthorizer; import org.apache.nifi.authorization.Resource; import org.apache.nifi.authorization.User; import org.apache.nifi.authorization.user.StandardNiFiUser; -import org.junit.Test; +import org.junit.jupiter.api.Test; import static org.apache.nifi.authorization.RequestAction.READ; import static org.apache.nifi.authorization.RequestAction.WRITE; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.fail; public class OperationAuthorizableTest { diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/test/java/org/apache/nifi/authorization/resource/ProvenanceDataAuthorizableTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/test/java/org/apache/nifi/authorization/resource/ProvenanceDataAuthorizableTest.java index 98c555b827..42af7d3d33 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/test/java/org/apache/nifi/authorization/resource/ProvenanceDataAuthorizableTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-authorization/src/test/java/org/apache/nifi/authorization/resource/ProvenanceDataAuthorizableTest.java @@ -24,10 +24,11 @@ import org.apache.nifi.authorization.Authorizer; import org.apache.nifi.authorization.RequestAction; import org.apache.nifi.authorization.user.NiFiUser; import org.apache.nifi.authorization.user.StandardNiFiUser.Builder; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.argThat; import static org.mockito.Mockito.mock; @@ -42,7 +43,7 @@ public class ProvenanceDataAuthorizableTest { private Authorizer testAuthorizer; private ProvenanceDataAuthorizable testProvenanceDataAuthorizable; - @Before + @BeforeEach public void setup() { Authorizable testProcessorAuthorizable; testProcessorAuthorizable = mock(Authorizable.class); @@ -63,9 +64,11 @@ public class ProvenanceDataAuthorizableTest { testProvenanceDataAuthorizable = new ProvenanceDataAuthorizable(testProcessorAuthorizable); } - @Test(expected = AccessDeniedException.class) + @Test public void testAuthorizeNullUser() { - testProvenanceDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, null, null); + assertThrows( AccessDeniedException.class, () -> + testProvenanceDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, + null, null)); } @Test @@ -74,10 +77,13 @@ public class ProvenanceDataAuthorizableTest { assertEquals(Result.Denied, result.getResult()); } - @Test(expected = AccessDeniedException.class) + @Test public void testAuthorizeUnauthorizedUser() { final NiFiUser user = new Builder().identity("unknown").build(); - testProvenanceDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, null); + + assertThrows(AccessDeniedException.class, () -> + testProvenanceDataAuthorizable.authorize(testAuthorizer, RequestAction.READ, user, + null)); } @Test diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/test/java/org/apache/nifi/cluster/protocol/jaxb/message/TestJaxbProtocolUtils.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/test/java/org/apache/nifi/cluster/protocol/jaxb/message/TestJaxbProtocolUtils.java index d45bf4a2e0..3848bd8502 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/test/java/org/apache/nifi/cluster/protocol/jaxb/message/TestJaxbProtocolUtils.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-cluster-protocol/src/test/java/org/apache/nifi/cluster/protocol/jaxb/message/TestJaxbProtocolUtils.java @@ -35,7 +35,7 @@ import org.apache.nifi.cluster.protocol.message.HeartbeatMessage; import org.apache.nifi.cluster.protocol.message.NodeConnectionStatusRequestMessage; import org.apache.nifi.cluster.protocol.message.NodeConnectionStatusResponseMessage; import org.apache.nifi.web.Revision; -import org.junit.Test; +import org.junit.jupiter.api.Test; import javax.xml.bind.JAXBException; import java.io.ByteArrayInputStream; @@ -47,8 +47,8 @@ import java.util.List; import java.util.Map; import java.util.stream.IntStream; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestJaxbProtocolUtils { diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestRingBufferEventRepository.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestRingBufferEventRepository.java index cb5d8dd8e0..ec27713ae2 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestRingBufferEventRepository.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestRingBufferEventRepository.java @@ -17,14 +17,17 @@ package org.apache.nifi.controller.repository; import org.apache.nifi.controller.repository.metrics.RingBufferEventRepository; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.Collections; import java.util.Map; import java.util.concurrent.TimeUnit; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; + + public class TestRingBufferEventRepository { @Test @@ -57,21 +60,21 @@ public class TestRingBufferEventRepository { repo.updateRepository(generateEvent(), id2); RepositoryStatusReport report = repo.reportTransferEvents(System.currentTimeMillis()); FlowFileEvent entry = report.getReportEntry(id1); - Assert.assertNotNull(entry); + assertNotNull(entry); entry = report.getReportEntry(id2); - Assert.assertNotNull(entry); + assertNotNull(entry); repo.purgeTransferEvents(id1); report = repo.reportTransferEvents(System.currentTimeMillis()); entry = report.getReportEntry(id1); - Assert.assertNull(entry); + assertNull(entry); entry = report.getReportEntry(id2); - Assert.assertNotNull(entry); + assertNotNull(entry); repo.purgeTransferEvents(id2); report = repo.reportTransferEvents(System.currentTimeMillis()); entry = report.getReportEntry(id2); - Assert.assertNull(entry); + assertNull(entry); repo.close(); } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestStandardFlowFileRecord.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestStandardFlowFileRecord.java index 55c0e3e3a9..b4b525cd10 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestStandardFlowFileRecord.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestStandardFlowFileRecord.java @@ -17,14 +17,14 @@ package org.apache.nifi.controller.repository; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; import java.util.HashMap; import java.util.Map; import java.util.UUID; -import org.junit.Test; +import org.junit.jupiter.api.Test; public class TestStandardFlowFileRecord { @@ -56,5 +56,4 @@ public class TestStandardFlowFileRecord { assertEquals(original.getAttributes(), removeAttribute.getAttributes()); assertEquals(addAttributeMapCopy, addAttribute.getAttributes()); } - } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestStandardProvenanceReporter.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestStandardProvenanceReporter.java index c079163250..43eead433e 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestStandardProvenanceReporter.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/TestStandardProvenanceReporter.java @@ -25,14 +25,14 @@ import java.util.Set; import org.apache.nifi.flowfile.FlowFile; import org.apache.nifi.provenance.ProvenanceEventRecord; import org.apache.nifi.provenance.ProvenanceEventRepository; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; public class TestStandardProvenanceReporter { @Test - @Ignore + @Disabled public void testDuplicatesIgnored() { final ProvenanceEventRepository mockRepo = Mockito.mock(ProvenanceEventRepository.class); final StandardProvenanceReporter reporter = new StandardProvenanceReporter(null, "1234", "TestProc", mockRepo, null); diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/metrics/TestSecondPrecisionEventContainer.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/metrics/TestSecondPrecisionEventContainer.java index f8b4559416..2d22ce7610 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/metrics/TestSecondPrecisionEventContainer.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/repository/metrics/TestSecondPrecisionEventContainer.java @@ -17,9 +17,9 @@ package org.apache.nifi.controller.repository.metrics; import org.apache.nifi.controller.repository.FlowFileEvent; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestSecondPrecisionEventContainer { @@ -39,8 +39,8 @@ public class TestSecondPrecisionEventContainer { final long timestamp = startTime + 300_000 * i + 300_000; final FlowFileEvent result = container.generateReport(timestamp); - assertEquals("Failure at i=" + i, 300 * 100, result.getBytesRead()); - assertEquals("Failure at i=" + i, 300 * 100, result.getBytesWritten()); + assertEquals(300 * 100, result.getBytesRead(), "Failure at i=" + i); + assertEquals( 300 * 100, result.getBytesWritten(), "Failure at i=" + i); } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceInvocationHandler.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceInvocationHandler.java index 7d94b372d5..e7b741665b 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceInvocationHandler.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/controller/service/TestStandardControllerServiceInvocationHandler.java @@ -20,25 +20,25 @@ package org.apache.nifi.controller.service; import org.apache.nifi.controller.AbstractControllerService; import org.apache.nifi.controller.ControllerService; import org.apache.nifi.nar.ExtensionManager; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import java.lang.reflect.Proxy; import java.net.URL; import java.net.URLClassLoader; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestStandardControllerServiceInvocationHandler { private ClassLoader originalClassLoader; - @Before + @BeforeEach public void setEmptyClassLoader() { this.originalClassLoader = Thread.currentThread().getContextClassLoader(); @@ -47,7 +47,7 @@ public class TestStandardControllerServiceInvocationHandler { Thread.currentThread().setContextClassLoader(classLoader); } - @After + @AfterEach public void setOriginalClassLoaderBack() { if (originalClassLoader != null) Thread.currentThread().setContextClassLoader(originalClassLoader); } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizerTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizerTest.java index 96445ab437..8a91c011ec 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizerTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/flow/synchronization/StandardVersionedComponentSynchronizerTest.java @@ -67,7 +67,6 @@ import org.apache.nifi.processor.Relationship; import org.apache.nifi.registry.flow.mapping.FlowMappingOptions; import org.apache.nifi.scheduling.ExecutionNode; import org.apache.nifi.scheduling.SchedulingStrategy; -import org.junit.Assert; import org.junit.Before; import org.junit.Test; import org.mockito.Mockito; @@ -94,10 +93,11 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.function.Function; import java.util.stream.Collectors; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertThrows; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.AdditionalMatchers.or; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyBoolean; @@ -532,7 +532,7 @@ public class StandardVersionedComponentSynchronizerTest { verify(connectionAB, times(0)).setName("Hello"); // Ensure that the source was stopped but not restarted. We don't restart in this situation because the intent is to drop - // the connection so we will leave the source stopped so that the data can eventually drain from the queue and the connection + // the connection, so we will leave the source stopped so that the data can eventually drain from the queue and the connection // can be removed. verifyStopped(processorA); verifyNotRestarted(processorA); @@ -548,12 +548,10 @@ public class StandardVersionedComponentSynchronizerTest { // Use a background thread to synchronize the connection. final CountDownLatch completionLatch = new CountDownLatch(1); final Thread syncThread = new Thread(() -> { - try { + assertDoesNotThrow(() -> { synchronizer.synchronize(connectionAB, null, group, synchronizationOptions); completionLatch.countDown(); - } catch (final Exception e) { - Assert.fail(e.toString()); - } + }); }); syncThread.start(); @@ -1195,7 +1193,7 @@ public class StandardVersionedComponentSynchronizerTest { } void assertNumProcessorUpdates(int expectedNum) { - assertEquals("Expected " + expectedNum + " processor state changes", expectedNum, processorUpdates.size()); + assertEquals(expectedNum, processorUpdates.size(), "Expected " + expectedNum + " processor state changes"); } void assertProcessorUpdates(final ScheduledStateUpdate<ProcessorNode>... updates) { @@ -1212,7 +1210,8 @@ public class StandardVersionedComponentSynchronizerTest { } void assertNumPortUpdates(int expectedNum) { - assertEquals("Expected " + expectedNum + " port state changes", expectedNum, portUpdates.size()); + assertEquals(expectedNum, portUpdates.size(), + "Expected " + expectedNum + " port state changes"); } } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/logging/TestStandardLogRepository.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/logging/TestStandardLogRepository.java index 22bbffffd4..a5381bacd4 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/logging/TestStandardLogRepository.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/logging/TestStandardLogRepository.java @@ -20,14 +20,14 @@ package org.apache.nifi.logging; import org.apache.nifi.flowfile.attributes.CoreAttributes; import org.apache.nifi.logging.repository.StandardLogRepository; import org.apache.nifi.util.MockFlowFile; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.io.IOException; import java.util.ArrayList; import java.util.List; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNull; public class TestStandardLogRepository { diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/parameter/TestStandardParameterContext.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/parameter/TestStandardParameterContext.java index c1671f8aec..b92efed25e 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/parameter/TestStandardParameterContext.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/parameter/TestStandardParameterContext.java @@ -20,8 +20,7 @@ import org.apache.nifi.controller.ProcessorNode; import org.apache.nifi.controller.service.ControllerServiceNode; import org.apache.nifi.controller.service.ControllerServiceState; import org.apache.nifi.groups.ProcessGroup; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.ArgumentMatchers; import org.mockito.Mockito; @@ -34,11 +33,13 @@ import java.util.List; import java.util.Map; import java.util.Set; -import static junit.framework.TestCase.assertTrue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertThrows; +import static org.junit.jupiter.api.Assertions.assertArrayEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.fail; public class TestStandardParameterContext { @@ -229,21 +230,15 @@ public class TestStandardParameterContext { updatedParameters.put("foo", new Parameter(fooDescriptor, "baz")); updatedParameters.put("xyz", new Parameter(sensitiveXyzDescriptor, "242526")); - try { - context.setParameters(updatedParameters); - Assert.fail("Succeeded in changing parameter from non-sensitive to sensitive"); - } catch (final IllegalStateException expected) { - } + assertThrows(IllegalStateException.class, + () -> context.setParameters(updatedParameters)); final ParameterDescriptor insensitiveAbcDescriptor = new ParameterDescriptor.Builder().name("abc").sensitive(false).build(); updatedParameters.clear(); updatedParameters.put("abc", new Parameter(insensitiveAbcDescriptor, "123")); - try { - context.setParameters(updatedParameters); - Assert.fail("Succeeded in changing parameter from sensitive to non-sensitive"); - } catch (final IllegalStateException expected) { - } + assertThrows(IllegalStateException.class, + () -> context.setParameters(updatedParameters)); } @Test @@ -272,18 +267,16 @@ public class TestStandardParameterContext { parameters.put("abc", new Parameter(abcDescriptor, "123")); // Cannot update parameters while running - Assert.assertThrows(IllegalStateException.class, () -> context.setParameters(parameters)); + assertThrows(IllegalStateException.class, () -> context.setParameters(parameters)); // This passes no parameters to update, so it should be fine context.setParameters(Collections.emptyMap()); parameters.clear(); parameters.put("abc", new Parameter(abcDescriptor, null)); - try { - context.setParameters(parameters); - Assert.fail("Was able to remove parameter while referencing processor was running"); - } catch (final IllegalStateException expected) { - } + + assertThrows(IllegalStateException.class, + () -> context.setParameters(parameters)); assertEquals("321", context.getParameter("abc").get().getValue()); } @@ -313,36 +306,32 @@ public class TestStandardParameterContext { final ProcessorNode procNode = getProcessorNode(inheritedParamName, referenceManager); // Show that inherited param 'def' starts with the original value from B - Assert.assertEquals(originalValue, a.getParameter(inheritedParamName).get().getValue()); + assertEquals(originalValue, a.getParameter(inheritedParamName).get().getValue()); // Now demonstrate that we can't effectively add the parameter by referencing Context B while processor runs a.setInheritedParameterContexts(Collections.emptyList()); // A now no longer includes 'def' startProcessor(procNode); try { a.setInheritedParameterContexts(Arrays.asList(b)); - Assert.fail("Was able to change effective parameter while referencing processor was running"); + fail("Was able to change effective parameter while referencing processor was running"); } catch (final IllegalStateException expected) { - Assert.assertTrue(expected.getMessage().contains("def")); + assertTrue(expected.getMessage().contains("def")); } // Safely add Context B, and show we can't effectively remove 'def' while processor runs stopProcessor(procNode); a.setInheritedParameterContexts(Arrays.asList(b)); startProcessor(procNode); - try { - a.setInheritedParameterContexts(Collections.emptyList()); - Assert.fail("Was able to remove parameter while referencing processor was running"); - } catch (final IllegalStateException expected) { - Assert.assertTrue(expected.getMessage().contains("def")); - } + + IllegalStateException illegalStateException = + assertThrows(IllegalStateException.class, + () -> a.setInheritedParameterContexts(Collections.emptyList())); + assertTrue(illegalStateException.getMessage().contains("def")); // Show we can't effectively change the value by changing it in B - try { - addParameter(b, inheritedParamName, changedValue); - Assert.fail("Was able to change parameter while referencing processor was running"); - } catch (final IllegalStateException expected) { - Assert.assertTrue(expected.getMessage().contains("def")); - } + illegalStateException = assertThrows(IllegalStateException.class, + () -> a.setInheritedParameterContexts(Collections.emptyList())); + assertTrue(illegalStateException.getMessage().contains("def")); assertEquals(originalValue, a.getParameter(inheritedParamName).get().getValue()); // Show we can't effectively change the value by adding Context C with 'def' ahead of 'B' @@ -351,12 +340,9 @@ public class TestStandardParameterContext { addParameter(c, inheritedParamName, changedValue); startProcessor(procNode); - try { - a.setInheritedParameterContexts(Arrays.asList(c, b)); - Assert.fail("Was able to change parameter while referencing processor was running"); - } catch (final IllegalStateException expected) { - Assert.assertTrue(expected.getMessage().contains("def")); - } + illegalStateException = assertThrows(IllegalStateException.class, + () -> a.setInheritedParameterContexts(Arrays.asList(c, b))); + assertTrue(illegalStateException.getMessage().contains("def")); assertEquals(originalValue, a.getParameter(inheritedParamName).get().getValue()); // Show that if the effective value of 'def' doesn't change, we don't prevent updating @@ -372,7 +358,7 @@ public class TestStandardParameterContext { // Show that updating a value on a grandchild is prevented because the processor is running and // references the parameter via the grandparent startProcessor(procNode); - Assert.assertThrows(IllegalStateException.class, () -> removeParameter(c, inheritedParamName)); + assertThrows(IllegalStateException.class, () -> removeParameter(c, inheritedParamName)); } private static ProcessorNode getProcessorNode(String parameterName, HashMapParameterReferenceManager referenceManager) { @@ -462,21 +448,21 @@ public class TestStandardParameterContext { for (final ControllerServiceState state : EnumSet.of(ControllerServiceState.ENABLED, ControllerServiceState.ENABLING, ControllerServiceState.DISABLING)) { setControllerServiceState(serviceNode, state); - Assert.assertThrows(IllegalStateException.class, () -> addParameter(b, inheritedParamName, changedValue)); + assertThrows(IllegalStateException.class, () -> addParameter(b, inheritedParamName, changedValue)); - Assert.assertThrows(IllegalStateException.class, () -> b.setInheritedParameterContexts(Collections.singletonList(c))); + assertThrows(IllegalStateException.class, () -> b.setInheritedParameterContexts(Collections.singletonList(c))); assertEquals(originalValue, a.getParameter(inheritedParamName).get().getValue()); } - Assert.assertThrows(IllegalStateException.class, () -> removeParameter(b, inheritedParamName)); + assertThrows(IllegalStateException.class, () -> removeParameter(b, inheritedParamName)); setControllerServiceState(serviceNode, ControllerServiceState.DISABLED); b.setInheritedParameterContexts(Collections.singletonList(c)); setControllerServiceState(serviceNode, ControllerServiceState.DISABLING); - Assert.assertThrows(IllegalStateException.class, () -> b.setInheritedParameterContexts(Collections.emptyList())); + assertThrows(IllegalStateException.class, () -> b.setInheritedParameterContexts(Collections.emptyList())); } @Test @@ -502,7 +488,7 @@ public class TestStandardParameterContext { try { context.setParameters(parameters); - Assert.fail("Was able to update parameter being referenced by Controller Service that is " + state); + fail("Was able to update parameter being referenced by Controller Service that is " + state); } catch (final IllegalStateException expected) { } @@ -515,7 +501,7 @@ public class TestStandardParameterContext { parameters.put("abc", new Parameter(abcDescriptor, null)); try { context.setParameters(parameters); - Assert.fail("Was able to remove parameter being referenced by Controller Service that is DISABLING"); + fail("Was able to remove parameter being referenced by Controller Service that is DISABLING"); } catch (final IllegalStateException expected) { } } @@ -548,7 +534,7 @@ public class TestStandardParameterContext { b.setInheritedParameterContexts(Arrays.asList(d, e)); - Assert.assertThrows(IllegalStateException.class, () -> a.setInheritedParameterContexts(Arrays.asList(b, c))); + assertThrows(IllegalStateException.class, () -> a.setInheritedParameterContexts(Arrays.asList(b, c))); } @Test @@ -587,9 +573,9 @@ public class TestStandardParameterContext { d.setInheritedParameterContexts(Arrays.asList(f)); a.setInheritedParameterContexts(Arrays.asList(b, c)); - Assert.assertEquals(Arrays.asList(b, c), a.getInheritedParameterContexts()); + assertEquals(Arrays.asList(b, c), a.getInheritedParameterContexts()); - Assert.assertArrayEquals(new String[] {"B", "C"}, a.getInheritedParameterContextNames().toArray()); + assertArrayEquals(new String[] {"B", "C"}, a.getInheritedParameterContextNames().toArray()); } @Test @@ -626,22 +612,22 @@ public class TestStandardParameterContext { final Map<ParameterDescriptor, Parameter> effectiveParameters = a.getEffectiveParameters(); - Assert.assertEquals(5, effectiveParameters.size()); + assertEquals(5, effectiveParameters.size()); - Assert.assertEquals("a.foo", effectiveParameters.get(foo).getValue()); - Assert.assertEquals("a", effectiveParameters.get(foo).getParameterContextId()); + assertEquals("a.foo", effectiveParameters.get(foo).getValue()); + assertEquals("a", effectiveParameters.get(foo).getParameterContextId()); - Assert.assertEquals("a.bar", effectiveParameters.get(bar).getValue()); - Assert.assertEquals("a", effectiveParameters.get(bar).getParameterContextId()); + assertEquals("a.bar", effectiveParameters.get(bar).getValue()); + assertEquals("a", effectiveParameters.get(bar).getParameterContextId()); - Assert.assertEquals("b.child", effectiveParameters.get(child).getValue()); - Assert.assertEquals("b", effectiveParameters.get(child).getParameterContextId()); + assertEquals("b.child", effectiveParameters.get(child).getValue()); + assertEquals("b", effectiveParameters.get(child).getParameterContextId()); - Assert.assertEquals("c.secondChild", effectiveParameters.get(secondChild).getValue()); - Assert.assertEquals("c", effectiveParameters.get(secondChild).getParameterContextId()); + assertEquals("c.secondChild", effectiveParameters.get(secondChild).getValue()); + assertEquals("c", effectiveParameters.get(secondChild).getParameterContextId()); - Assert.assertEquals("d.grandchild", effectiveParameters.get(grandchild).getValue()); - Assert.assertEquals("d", effectiveParameters.get(grandchild).getParameterContextId()); + assertEquals("d.grandchild", effectiveParameters.get(grandchild).getValue()); + assertEquals("d", effectiveParameters.get(grandchild).getParameterContextId()); } @Test @@ -674,10 +660,10 @@ public class TestStandardParameterContext { final Map<ParameterDescriptor, Parameter> effectiveParameters = a.getEffectiveParameters(); - Assert.assertEquals(1, effectiveParameters.size()); + assertEquals(1, effectiveParameters.size()); - Assert.assertEquals("c.child", effectiveParameters.get(child).getValue()); - Assert.assertEquals("c", effectiveParameters.get(child).getParameterContextId()); + assertEquals("c.child", effectiveParameters.get(child).getValue()); + assertEquals("c", effectiveParameters.get(child).getParameterContextId()); } @Test @@ -693,7 +679,7 @@ public class TestStandardParameterContext { addParameter(b, "child", "b.child", false); a.setInheritedParameterContexts(Arrays.asList(b)); - Assert.assertEquals(Arrays.asList(b), a.getInheritedParameterContexts()); + assertEquals(Arrays.asList(b), a.getInheritedParameterContexts()); } @Test @@ -710,14 +696,14 @@ public class TestStandardParameterContext { b.setInheritedParameterContexts(Arrays.asList(c, d)); d.setInheritedParameterContexts(Arrays.asList(e)); - Assert.assertTrue(a.inheritsFrom("b")); - Assert.assertTrue(a.inheritsFrom("c")); - Assert.assertTrue(a.inheritsFrom("d")); - Assert.assertTrue(a.inheritsFrom("e")); - Assert.assertFalse(a.inheritsFrom("a")); + assertTrue(a.inheritsFrom("b")); + assertTrue(a.inheritsFrom("c")); + assertTrue(a.inheritsFrom("d")); + assertTrue(a.inheritsFrom("e")); + assertFalse(a.inheritsFrom("a")); - Assert.assertTrue(b.inheritsFrom("e")); - Assert.assertFalse(b.inheritsFrom("a")); + assertTrue(b.inheritsFrom("e")); + assertFalse(b.inheritsFrom("a")); } @@ -735,11 +721,11 @@ public class TestStandardParameterContext { try { a.setInheritedParameterContexts(Arrays.asList(b)); - Assert.fail("Should get a failure for sensitivity mismatch in overriding"); + fail("Should get a failure for sensitivity mismatch in overriding"); } catch (IllegalStateException e) { - Assert.assertTrue(e.getMessage().contains("foo")); + assertTrue(e.getMessage().contains("foo")); } - Assert.assertEquals(Collections.emptyList(), a.getInheritedParameterContexts()); + assertEquals(Collections.emptyList(), a.getInheritedParameterContexts()); // Now switch and set a.foo to non-sensitive and b.foo to sensitive removeParameter(a, "foo"); @@ -750,11 +736,11 @@ public class TestStandardParameterContext { try { a.setInheritedParameterContexts(Arrays.asList(b)); - Assert.fail("Should get a failure for sensitivity mismatch in overriding"); + fail("Should get a failure for sensitivity mismatch in overriding"); } catch (IllegalStateException e) { - Assert.assertTrue(e.getMessage().contains("foo")); + assertTrue(e.getMessage().contains("foo")); } - Assert.assertEquals(Collections.emptyList(), a.getInheritedParameterContexts()); + assertEquals(Collections.emptyList(), a.getInheritedParameterContexts()); } private static void removeParameter(final ParameterContext parameterContext, final String name) { diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestStandardPropertyValue.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestStandardPropertyValue.java index fbefcc108f..6f49d80b86 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestStandardPropertyValue.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestStandardPropertyValue.java @@ -23,15 +23,16 @@ import org.apache.nifi.controller.ControllerService; import org.apache.nifi.controller.ControllerServiceLookup; import org.apache.nifi.controller.repository.StandardFlowFileRecord; import org.apache.nifi.flowfile.FlowFile; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Calendar; import java.util.HashMap; import java.util.Map; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertThrows; public class TestStandardPropertyValue { @@ -97,13 +98,14 @@ public class TestStandardPropertyValue { assertEquals(139, value.evaluateAttributeExpressions(createFlowFile(attributes)).asInteger().intValue()); } - @Test(expected = NumberFormatException.class) + @Test() public void testGetValueAsIntegerAfterSubstitutingWithNonInteger() { final PropertyValue value = new StandardPropertyValue("1${value}", lookup, ParameterLookup.EMPTY); final Map<String, String> attributes = new HashMap<>(); attributes.put("value", "Yes"); final PropertyValue substituted = value.evaluateAttributeExpressions(createFlowFile(attributes)); - substituted.asInteger(); + + assertThrows(NumberFormatException.class, substituted::asInteger); } @Test diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestStandardValidationContext.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestStandardValidationContext.java index cb761fae4f..b652ee3fc1 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestStandardValidationContext.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/processor/TestStandardValidationContext.java @@ -24,15 +24,15 @@ import org.apache.nifi.controller.service.ControllerServiceProvider; import org.apache.nifi.parameter.StandardParameterTokenList; import org.apache.nifi.processor.util.StandardValidators; import org.apache.nifi.registry.VariableRegistry; -import org.junit.Test; +import org.junit.jupiter.api.Test; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.function.Function; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; public class TestStandardValidationContext { @@ -77,5 +77,4 @@ public class TestStandardValidationContext { // Property A's dependency should still (always) satisfied b/c no dependency assertTrue(context.isDependencySatisfied(descriptorA, propertyLookup)); } - } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/registry/NiFiRegistryExtensionBundleMetadataTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/registry/NiFiRegistryExtensionBundleMetadataTest.java index 74cba5c209..bb0ab374d0 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/registry/NiFiRegistryExtensionBundleMetadataTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/registry/NiFiRegistryExtensionBundleMetadataTest.java @@ -17,10 +17,10 @@ package org.apache.nifi.registry; import org.apache.nifi.registry.extension.NiFiRegistryExtensionBundleMetadata; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; public class NiFiRegistryExtensionBundleMetadataTest { diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/registry/flow/mapping/TestNiFiRegistryFlowMapper.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/registry/flow/mapping/TestNiFiRegistryFlowMapper.java index b168dfcce6..a29cd5b6dd 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/registry/flow/mapping/TestNiFiRegistryFlowMapper.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/registry/flow/mapping/TestNiFiRegistryFlowMapper.java @@ -37,7 +37,7 @@ import org.apache.nifi.parameter.ParameterReference; import org.apache.nifi.parameter.ParameterTokenList; import org.apache.nifi.scheduling.ExecutionNode; import org.apache.nifi.scheduling.SchedulingStrategy; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.stubbing.Answer; import java.util.ArrayList; @@ -48,9 +48,9 @@ import java.util.Map; import java.util.Optional; import java.util.UUID; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/util/ReflectionUtilsTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/util/ReflectionUtilsTest.java index 8a956db66d..59c2a2212b 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/util/ReflectionUtilsTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/util/ReflectionUtilsTest.java @@ -16,25 +16,26 @@ */ package org.apache.nifi.util; -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.verify; +import org.apache.nifi.annotation.lifecycle.OnStopped; +import org.apache.nifi.logging.ComponentLog; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import java.lang.reflect.InvocationTargetException; import java.util.ArrayList; import java.util.List; -import org.apache.nifi.annotation.lifecycle.OnStopped; -import org.apache.nifi.logging.ComponentLog; -import org.junit.Before; -import org.junit.Test; -import org.mockito.Mockito; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; public class ReflectionUtilsTest { - private List<String> invocations = new ArrayList<>(); + private final List<String> invocations = new ArrayList<>(); - @Before + @BeforeEach public void reset() { this.invocations.clear(); } @@ -66,9 +67,10 @@ public class ReflectionUtilsTest { assertEquals("D", this.invocations.get(0)); } - @Test(expected = IllegalArgumentException.class) + @Test public void validateFailureWithWrongArgumentType() throws Exception { - ReflectionUtils.invokeMethodsWithAnnotation(OnStopped.class, new B(), "foo"); + assertThrows(IllegalArgumentException.class, () -> + ReflectionUtils.invokeMethodsWithAnnotation(OnStopped.class, new B(), "foo")); } @Test @@ -86,9 +88,10 @@ public class ReflectionUtilsTest { assertEquals("E", this.invocations.get(0)); } - @Test(expected = IllegalArgumentException.class) + @Test public void validateFailureIfOneOfArgumentsWrongType() throws Exception { - ReflectionUtils.invokeMethodsWithAnnotation(OnStopped.class, new E(), 3, "hjk", "hjk"); + assertThrows(IllegalArgumentException.class, () -> + ReflectionUtils.invokeMethodsWithAnnotation(OnStopped.class, new E(), 3, "hjk", "hjk")); } @Test @@ -98,9 +101,10 @@ public class ReflectionUtilsTest { verify(pl, Mockito.atMost(1)).error(Mockito.anyString()); } - @Test(expected = InvocationTargetException.class) + @Test public void validateInvocationFailure() throws Exception { - ReflectionUtils.invokeMethodsWithAnnotation(OnStopped.class, new F(), 3); + assertThrows(InvocationTargetException.class, () -> + ReflectionUtils.invokeMethodsWithAnnotation(OnStopped.class, new F(), 3)); } @Test diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/util/TestFlowDifferenceFilters.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/util/TestFlowDifferenceFilters.java index 9adebff5ae..a606769cea 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/util/TestFlowDifferenceFilters.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-components/src/test/java/org/apache/nifi/util/TestFlowDifferenceFilters.java @@ -24,8 +24,10 @@ import org.apache.nifi.flow.VersionedProcessor; import org.apache.nifi.flow.VersionedRemoteGroupPort; import org.apache.nifi.registry.flow.diff.DifferenceType; import org.apache.nifi.registry.flow.diff.StandardFlowDifference; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; + +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestFlowDifferenceFilters { @@ -38,7 +40,7 @@ public class TestFlowDifferenceFilters { DifferenceType.COMPONENT_ADDED, null, remoteGroupPort, null, null, ""); // predicate should return false because we don't want to include changes for adding a remote input port - Assert.assertFalse(FlowDifferenceFilters.FILTER_ADDED_REMOVED_REMOTE_PORTS.test(flowDifference)); + assertFalse(FlowDifferenceFilters.FILTER_ADDED_REMOVED_REMOTE_PORTS.test(flowDifference)); } @Test @@ -50,7 +52,7 @@ public class TestFlowDifferenceFilters { DifferenceType.COMPONENT_ADDED, remoteGroupPort, null, null, null, ""); // predicate should return false because we don't want to include changes for adding a remote input port - Assert.assertFalse(FlowDifferenceFilters.FILTER_ADDED_REMOVED_REMOTE_PORTS.test(flowDifference)); + assertFalse(FlowDifferenceFilters.FILTER_ADDED_REMOVED_REMOTE_PORTS.test(flowDifference)); } @Test @@ -62,7 +64,7 @@ public class TestFlowDifferenceFilters { DifferenceType.COMPONENT_ADDED, null, remoteGroupPort, null, null, ""); // predicate should return false because we don't want to include changes for adding a remote input port - Assert.assertFalse(FlowDifferenceFilters.FILTER_ADDED_REMOVED_REMOTE_PORTS.test(flowDifference)); + assertFalse(FlowDifferenceFilters.FILTER_ADDED_REMOVED_REMOTE_PORTS.test(flowDifference)); } @Test @@ -74,7 +76,7 @@ public class TestFlowDifferenceFilters { DifferenceType.COMPONENT_ADDED, null, versionedProcessor, null, null, ""); // predicate should return true because we do want to include changes for adding a non-port - Assert.assertTrue(FlowDifferenceFilters.FILTER_ADDED_REMOVED_REMOTE_PORTS.test(flowDifference)); + assertTrue(FlowDifferenceFilters.FILTER_ADDED_REMOVED_REMOTE_PORTS.test(flowDifference)); } @Test @@ -97,7 +99,7 @@ public class TestFlowDifferenceFilters { coordinatesA.getRegistryUrl(), coordinatesB.getRegistryUrl(), ""); - Assert.assertFalse(FlowDifferenceFilters.FILTER_IGNORABLE_VERSIONED_FLOW_COORDINATE_CHANGES.test(flowDifference)); + assertFalse(FlowDifferenceFilters.FILTER_IGNORABLE_VERSIONED_FLOW_COORDINATE_CHANGES.test(flowDifference)); } @Test @@ -120,7 +122,7 @@ public class TestFlowDifferenceFilters { coordinatesA.getRegistryUrl(), coordinatesB.getRegistryUrl(), ""); - Assert.assertTrue(FlowDifferenceFilters.FILTER_IGNORABLE_VERSIONED_FLOW_COORDINATE_CHANGES.test(flowDifference)); + assertTrue(FlowDifferenceFilters.FILTER_IGNORABLE_VERSIONED_FLOW_COORDINATE_CHANGES.test(flowDifference)); } @Test @@ -134,7 +136,7 @@ public class TestFlowDifferenceFilters { "http://localhost:18080", "http://localhost:17080", ""); - Assert.assertTrue(FlowDifferenceFilters.FILTER_PUBLIC_PORT_NAME_CHANGES.test(flowDifference)); + assertTrue(FlowDifferenceFilters.FILTER_PUBLIC_PORT_NAME_CHANGES.test(flowDifference)); } @Test @@ -148,7 +150,7 @@ public class TestFlowDifferenceFilters { "Port A", "Port B", ""); - Assert.assertTrue(FlowDifferenceFilters.FILTER_PUBLIC_PORT_NAME_CHANGES.test(flowDifference)); + assertTrue(FlowDifferenceFilters.FILTER_PUBLIC_PORT_NAME_CHANGES.test(flowDifference)); } @Test @@ -165,7 +167,7 @@ public class TestFlowDifferenceFilters { "Port A", "Port B", ""); - Assert.assertFalse(FlowDifferenceFilters.FILTER_PUBLIC_PORT_NAME_CHANGES.test(flowDifference)); + assertFalse(FlowDifferenceFilters.FILTER_PUBLIC_PORT_NAME_CHANGES.test(flowDifference)); } } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestControllerServiceApiMatcher.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestControllerServiceApiMatcher.java index 4bc1849ef2..0cde7a6949 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestControllerServiceApiMatcher.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestControllerServiceApiMatcher.java @@ -20,20 +20,20 @@ import org.apache.nifi.components.PropertyDescriptor; import org.apache.nifi.components.ValidationContext; import org.apache.nifi.components.ValidationResult; import org.apache.nifi.reporting.InitializationException; -import org.junit.Before; -import org.junit.Test; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; import java.util.Collection; import java.util.List; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; public class TestControllerServiceApiMatcher { private ControllerServiceApiMatcher serviceApiMatcher; - @Before + @BeforeEach public void setup() { this.serviceApiMatcher = new ControllerServiceApiMatcher(); } diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestStandardFunnel.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestStandardFunnel.java index 799eb20ecb..1c2dda3cc6 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestStandardFunnel.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/controller/TestStandardFunnel.java @@ -17,9 +17,9 @@ package org.apache.nifi.controller; -import org.junit.Test; +import org.junit.jupiter.api.Test; -import static org.junit.Assert.assertEquals; +import static org.junit.jupiter.api.Assertions.assertEquals; public class TestStandardFunnel { diff --git a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/util/CharacterFilterUtilsTest.java b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/util/CharacterFilterUtilsTest.java index 216cbcdd8c..bcf9d7c9ce 100644 --- a/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/util/CharacterFilterUtilsTest.java +++ b/nifi-nar-bundles/nifi-framework-bundle/nifi-framework/nifi-framework-core-api/src/test/java/org/apache/nifi/util/CharacterFilterUtilsTest.java @@ -16,8 +16,8 @@ */ package org.apache.nifi.util; -import org.junit.Assert; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertEquals; public class CharacterFilterUtilsTest { @@ -27,7 +27,6 @@ public class CharacterFilterUtilsTest { final String filtered = CharacterFilterUtils.filterInvalidXmlCharacters(text); final String expected = "This is an example with characters that need to be filtered in it. "; - Assert.assertEquals(expected, filtered); + assertEquals(expected, filtered); } - } \ No newline at end of file
