diff options
author | Rodrigo Lima <rodrigo.lima@yoppworks.com> | 2020-05-06 10:35:01 -0400 |
---|---|---|
committer | Ofir Sonsino <ofir.sonsino@intl.att.com> | 2020-05-10 06:24:57 +0000 |
commit | cdadb774cce59454fc217ac34edb9ac7130a06b2 (patch) | |
tree | 9e9dc44b0921a9dc9ca1ebb68d580d74fd47b684 | |
parent | 2fcd69426559f3464840309444596a3978d5f8e6 (diff) |
Remove porwermock from ComponentImplTest
- Remove power mock from ComponentImplTest
- Add new constructor to ComponentsImpl
Issue-ID: SDC-3026
Signed-off-by: Rodrigo Lima <rodrigo.lima@yoppworks.com>
Change-Id: I919fdb55990d813f4ac2950e3950b28e4686acbc
2 files changed, 14 insertions, 27 deletions
diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/ComponentsImpl.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/ComponentsImpl.java index b2af68d25a..fefa52842e 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/ComponentsImpl.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/main/java/org/openecomp/sdcrests/vsp/rest/services/ComponentsImpl.java @@ -44,8 +44,15 @@ import java.util.Collection; @Service("components") @Scope(value = "prototype") public class ComponentsImpl implements Components { - private ComponentManager componentManager = - ComponentManagerFactory.getInstance().createInterface(); + private final ComponentManager componentManager; + + public ComponentsImpl() { + this.componentManager = ComponentManagerFactory.getInstance().createInterface(); + } + + public ComponentsImpl(ComponentManager componentManager) { + this.componentManager = componentManager; + } @Override public Response list(String vspId, String versionId, String user) { diff --git a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentImplTest.java b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentImplTest.java index 7e7dae9930..ab64bfca11 100644 --- a/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentImplTest.java +++ b/openecomp-be/api/openecomp-sdc-rest-webapp/vendor-software-products-rest/vendor-software-products-rest-services/src/test/java/org/openecomp/sdcrests/vsp/rest/services/ComponentImplTest.java @@ -24,13 +24,11 @@ import org.apache.http.HttpStatus; import org.junit.Assert; import org.junit.Before; import org.junit.Test; -import org.junit.runner.RunWith; import org.mockito.ArgumentMatchers; import org.mockito.Mock; import org.openecomp.sdc.logging.api.Logger; import org.openecomp.sdc.logging.api.LoggerFactory; import org.openecomp.sdc.vendorsoftwareproduct.ComponentManager; -import org.openecomp.sdc.vendorsoftwareproduct.ComponentManagerFactory; import org.openecomp.sdc.vendorsoftwareproduct.dao.type.ComponentEntity; import org.openecomp.sdc.vendorsoftwareproduct.types.CompositionEntityResponse; import org.openecomp.sdc.vendorsoftwareproduct.types.QuestionnaireResponse; @@ -43,8 +41,6 @@ import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentDto; import org.openecomp.sdcrests.vendorsoftwareproducts.types.ComponentRequestDto; import org.openecomp.sdcrests.vendorsoftwareproducts.types.QuestionnaireResponseDto; import org.openecomp.sdcrests.wrappers.GenericCollectionWrapper; -import org.powermock.core.classloader.annotations.PrepareForTest; -import org.powermock.modules.junit4.PowerMockRunner; import javax.ws.rs.core.Response; import java.util.Collection; @@ -52,19 +48,12 @@ import java.util.Collections; import java.util.UUID; import static org.mockito.MockitoAnnotations.initMocks; -import static org.powermock.api.mockito.PowerMockito.mockStatic; -import static org.powermock.api.mockito.PowerMockito.when; +import static org.mockito.Mockito.when; -@RunWith(PowerMockRunner.class) -@PrepareForTest({ComponentsImpl.class, ComponentManagerFactory.class}) public class ComponentImplTest { private Logger logger = LoggerFactory.getLogger(ComponentImplTest.class); - - @Mock - private ComponentManagerFactory componentManagerFactory; - @Mock private ComponentManager componentManager; @@ -73,15 +62,13 @@ public class ComponentImplTest { private final String componentId = "" + System.currentTimeMillis(); private final String user = "cs0008"; + private ComponentsImpl ci; + @Before public void setUp() { try { initMocks(this); - mockStatic(ComponentManagerFactory.class); - when(ComponentManagerFactory.getInstance()).thenReturn(componentManagerFactory); - when(componentManagerFactory.createInterface()).thenReturn(componentManager); - ComponentEntity ce = new ComponentEntity(); ce.setId(vspId); ce.setVspId(vspId); @@ -115,6 +102,8 @@ public class ComponentImplTest { ArgumentMatchers.any(), ArgumentMatchers.eq(componentId))).thenReturn(qr); + ci = new ComponentsImpl(componentManager); + } catch (Exception e) { logger.error(e.getMessage(), e); @@ -123,8 +112,6 @@ public class ComponentImplTest { @Test public void testList() { - ComponentsImpl ci = new ComponentsImpl(); - Response rsp = ci.list(vspId, versionId, user); Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus()); Object e = rsp.getEntity(); @@ -136,7 +123,6 @@ public class ComponentImplTest { @Test public void testDeleteList() { - ComponentsImpl ci = new ComponentsImpl(); Response rsp = ci.deleteList(vspId, versionId, user); Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus()); Assert.assertNull(rsp.getEntity()); @@ -152,7 +138,6 @@ public class ComponentImplTest { dto.setName("name"); dto.setDisplayName("world"); - ComponentsImpl ci = new ComponentsImpl(); Response rsp = ci.create(dto, vspId, versionId, user); Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus()); Object e = rsp.getEntity(); @@ -168,7 +153,6 @@ public class ComponentImplTest { @Test public void testDelete() { - ComponentsImpl ci = new ComponentsImpl(); Response rsp = ci.delete(vspId, versionId, componentId, user); Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus()); Assert.assertNull(rsp.getEntity()); @@ -177,7 +161,6 @@ public class ComponentImplTest { @Test public void testGet() { - ComponentsImpl ci = new ComponentsImpl(); Response rsp = ci.get(vspId, versionId, componentId, user); Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus()); Assert.assertNotNull(rsp.getEntity()); @@ -185,7 +168,6 @@ public class ComponentImplTest { @Test public void testUpdate() { - ComponentsImpl ci = new ComponentsImpl(); ComponentRequestDto dto = new ComponentRequestDto(); Response rsp = ci.update(dto, vspId, versionId, componentId, user); Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus()); @@ -194,7 +176,6 @@ public class ComponentImplTest { @Test public void testGetQuestionaire() { - ComponentsImpl ci = new ComponentsImpl(); Response rsp = ci.getQuestionnaire(vspId, versionId, componentId, user); Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus()); try { @@ -210,7 +191,6 @@ public class ComponentImplTest { @Test public void testUpdateQuestionaire() { - ComponentsImpl ci = new ComponentsImpl(); Response rsp = ci.updateQuestionnaire("helloworld", vspId, versionId, componentId, user); Assert.assertEquals("Response should be 200", HttpStatus.SC_OK, rsp.getStatus()); Assert.assertNull(rsp.getEntity()); |