From b260c10ad4dd66d31d31a6615481584105cd58ec Mon Sep 17 00:00:00 2001 From: Emilio Setiadarma Date: Thu, 28 Jul 2022 17:02:32 -0700 Subject: [PATCH] NIFI-10293 Refactored tests in nifi-jolt-transform-json-ui to use JUnit 5 This closes #6258 Signed-off-by: David Handermann --- .../api/processor/TestProcessorResource.java | 15 ++++------ .../api/processor/TestProcessorWebUtils.java | 22 ++++---------- .../TestTransformJSONResource.java | 29 ++++++++----------- 3 files changed, 22 insertions(+), 44 deletions(-) diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorResource.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorResource.java index c69d9f02ed..071d546d98 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorResource.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorResource.java @@ -30,7 +30,7 @@ import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; import org.glassfish.jersey.test.inmemory.InMemoryTestContainerFactory; import org.glassfish.jersey.test.spi.TestContainerFactory; -import org.junit.Test; +import org.junit.jupiter.api.Test; import org.mockito.AdditionalMatchers; import org.mockito.Mockito; @@ -42,9 +42,9 @@ import javax.ws.rs.core.Response; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertNotNull; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.isNull; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; @@ -129,12 +129,7 @@ public class TestProcessorResource extends JerseyTest { assertNotNull(value); - try{ - assertTrue(value.get("name").asText().equals("mytransform")); - } catch (Exception e){ - fail("Failed due to: " + e.toString()); - } - + assertEquals("mytransform", value.get("name").asText()); } public static class MockRequestContext implements Factory { diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorWebUtils.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorWebUtils.java index 9bc1e33a75..45711ac359 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorWebUtils.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/processor/TestProcessorWebUtils.java @@ -18,12 +18,10 @@ package org.apache.nifi.web.standard.api.processor; import org.apache.nifi.web.ComponentDetails; -import org.apache.nifi.web.HttpServletConfigurationRequestContext; import org.apache.nifi.web.HttpServletRequestContext; import org.apache.nifi.web.NiFiWebConfigurationContext; import org.apache.nifi.web.NiFiWebRequestContext; -import org.junit.Ignore; -import org.junit.Test; +import org.junit.jupiter.api.Test; import javax.servlet.http.HttpServletRequest; import javax.ws.rs.core.CacheControl; @@ -32,8 +30,9 @@ import java.io.IOException; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; -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.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; @@ -52,17 +51,6 @@ public class TestProcessorWebUtils { } - @Test - @Ignore("Capability to get specific client revision has been removed as of commit 05a1d63090d97d06bf823821d1b0e9b5482c7cd2") - // FIXME java11 Capability to get specific client revision has been removed as of commit 05a1d63090d97d06bf823821d1b0e9b5482c7cd2 - // Add test case for ProcessorWebUtils.getRequestContext() to verify proper revision is returned - public void testGetComponentDetailsForProcessorWithSpecificClientRevision(){ - NiFiWebConfigurationContext configurationContext = mock(NiFiWebConfigurationContext.class); - when(configurationContext.getComponentDetails(any(HttpServletConfigurationRequestContext.class))).thenReturn(new ComponentDetails.Builder().build()); - ComponentDetails componentDetails = ProcessorWebUtils.getComponentDetails(configurationContext,"1",mock(HttpServletRequest.class)); - assertNotNull(componentDetails); - } - @Test public void testApplyCacheControl(){ Response.ResponseBuilder response = mock(Response.ResponseBuilder.class); @@ -77,7 +65,7 @@ public class TestProcessorWebUtils { method.setAccessible(true); NiFiWebRequestContext requestContext = (NiFiWebRequestContext) method.invoke(null,"1",mock(HttpServletRequest.class)); assertTrue(requestContext instanceof HttpServletRequestContext); - assertTrue(requestContext.getId().equals("1")); + assertEquals("1", requestContext.getId()); } diff --git a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/transformjson/TestTransformJSONResource.java b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/transformjson/TestTransformJSONResource.java index d6eab9a9fa..60e2f5cabf 100644 --- a/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/transformjson/TestTransformJSONResource.java +++ b/nifi-nar-bundles/nifi-standard-bundle/nifi-jolt-transform-json-ui/src/test/java/org/apache/nifi/web/standard/api/transformjson/TestTransformJSONResource.java @@ -18,7 +18,6 @@ package org.apache.nifi.web.standard.api.transformjson; import com.bazaarvoice.jolt.Diffy; import com.bazaarvoice.jolt.JsonUtils; -import junit.framework.TestCase; import org.apache.nifi.web.ComponentDetails; import org.apache.nifi.web.NiFiWebConfigurationContext; import org.apache.nifi.web.NiFiWebRequestContext; @@ -31,9 +30,7 @@ import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; import org.glassfish.jersey.test.inmemory.InMemoryTestContainerFactory; import org.glassfish.jersey.test.spi.TestContainerFactory; -import org.junit.Rule; -import org.junit.Test; -import org.junit.rules.ExpectedException; +import org.junit.jupiter.api.Test; import org.mockito.Mockito; import javax.servlet.ServletContext; @@ -44,18 +41,16 @@ import javax.ws.rs.core.Response.Status; import java.util.HashMap; import java.util.Map; -import static org.junit.Assert.assertEquals; -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; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.mock; public class TestTransformJSONResource extends JerseyTest { - @Rule - public final ExpectedException exception = ExpectedException.none(); - public static final ServletContext servletContext = mock(ServletContext.class); @Override @@ -95,7 +90,7 @@ public class TestTransformJSONResource extends JerseyTest { .post(Entity.json(joltSpecificationDTO), ValidationDTO.class); assertNotNull(validate); - assertTrue(!validate.isValid()); + assertFalse(validate.isValid()); } @@ -107,7 +102,7 @@ public class TestTransformJSONResource extends JerseyTest { .request() .post(Entity.json(joltSpecificationDTO), ValidationDTO.class); - TestCase.assertNotNull(validation); + assertNotNull(validation); assertTrue(validation.isValid()); } @@ -119,7 +114,7 @@ public class TestTransformJSONResource extends JerseyTest { .request() .post(Entity.json(joltSpecificationDTO), ValidationDTO.class); - TestCase.assertNotNull(validation); + assertNotNull(validation); assertTrue(validation.isValid()); } @@ -131,7 +126,7 @@ public class TestTransformJSONResource extends JerseyTest { .request() .post(Entity.json(joltSpecificationDTO), ValidationDTO.class); - TestCase.assertNotNull(validation); + assertNotNull(validation); assertTrue(validation.isValid()); } @@ -143,7 +138,7 @@ public class TestTransformJSONResource extends JerseyTest { .request() .post(Entity.json(joltSpecificationDTO), ValidationDTO.class); - TestCase.assertNotNull(validation); + assertNotNull(validation); assertTrue(!validation.isValid()); } @@ -155,7 +150,7 @@ public class TestTransformJSONResource extends JerseyTest { .request() .post(Entity.json(joltSpecificationDTO), ValidationDTO.class); - TestCase.assertNotNull(validation); + assertNotNull(validation); assertTrue(validation.isValid()); } @@ -198,7 +193,7 @@ public class TestTransformJSONResource extends JerseyTest { .post(Entity.json(joltSpecificationDTO), ValidationDTO.class); assertNotNull(validate); - assertTrue(!validate.isValid()); + assertFalse(validate.isValid()); } @Test