diff options
author | 2020-08-21 08:40:37 -0400 | |
---|---|---|
committer | 2020-08-21 08:52:29 -0400 | |
commit | 47b65efd69c5158d958261846803d2e15adfb448 (patch) | |
tree | d0f3752b551a31cf39a36cbee16392bbcc36c72b /ccsdk-app-common/src/test | |
parent | c32511155acad5b70dcc3cf29e9bfa36276f3894 (diff) |
java 11 upgrade and sonar scan fixes
Recompile java source code using jdk11
Run in ojdk11 JRE
tomcat container upgrade
alpine base image
Issue-ID: DCAEGEN2-2298
Change-Id: Ic4bf2626e5805508589cafe52b7c4e91d7ae3580
Signed-off-by: Kotagiri, Ramprasad (rp5662) <rp5662@att.com>
Diffstat (limited to 'ccsdk-app-common/src/test')
17 files changed, 1130 insertions, 1142 deletions
diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/api/controller/NbApiControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/api/controller/NbApiControllerTest.java index 3c33bda..a620608 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/api/controller/NbApiControllerTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/api/controller/NbApiControllerTest.java @@ -21,7 +21,10 @@ package org.onap.ccsdk.api.controller; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; @@ -47,7 +50,6 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -76,6 +78,7 @@ import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentInput; import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentRequest; import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResponse; import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentResponseLinks; +import org.onap.ccsdk.dashboard.model.inventory.Blueprint; import org.onap.ccsdk.dashboard.model.inventory.Service; import org.onap.ccsdk.dashboard.model.inventory.ServiceList; import org.onap.ccsdk.dashboard.model.inventory.ServiceQueryParams; @@ -94,6 +97,9 @@ import org.onap.ccsdk.dashboard.rest.DeploymentHandlerClient; import org.onap.ccsdk.dashboard.rest.InventoryClient; import org.onap.portalsdk.core.domain.User; import org.onap.portalsdk.core.util.CacheManager; +import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; +import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; @@ -108,6 +114,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; @RunWith(PowerMockRunner.class) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) +@PrepareForTest({Blueprint.class}) public class NbApiControllerTest extends MockitoTestSuite { @Mock @@ -124,10 +132,10 @@ public class NbApiControllerTest extends MockitoTestSuite { @Mock ServletUriComponentsBuilder uriBuilder; - + @InjectMocks - NbApiController subject = new NbApiController(); - + NbApiController subject; + private HttpStatusCodeException httpException = new HttpServerErrorException(HttpStatus.BAD_GATEWAY); @@ -140,7 +148,6 @@ public class NbApiControllerTest extends MockitoTestSuite { ServiceList deplList = null; Service deplItem = null; - ServiceTypeSummary bpItem, bpItem2 = null; ServiceTypeSummaryList bpList, bpList2 = null; ServiceType bpItemFull = null; @@ -171,13 +178,14 @@ public class NbApiControllerTest extends MockitoTestSuite { downStrmError = new DownstreamException("error occured in downstream"); notFoundError = new DeploymentNotFoundException("item not found"); CacheManager testCache = new CacheManager(); - subject.setCacheManager(testCache); + subject.setCacheManager(testCache); User user = mockUser.mockUser(); user.setLoginId("tester"); StringBuffer urlBuff = new StringBuffer(); urlBuff.append("http://orcl.com"); - //Mockito.when(mockedRequest.getRemoteUser()).thenReturn("tester"); + // Mockito.when(mockedRequest.getRemoteUser()).thenReturn("tester"); Mockito.when(mockedRequest.getRequestURL()).thenReturn(urlBuff); + PowerMockito.mockStatic(Blueprint.class); } public void getExpectedDeployments() @@ -199,15 +207,17 @@ public class NbApiControllerTest extends MockitoTestSuite { public void getExpectedBueprints() throws JsonParseException, JsonMappingException, IOException { - - /*bpItem = new ServiceTypeSummary.Builder().application("DCAE").component("dcae"). - typeName("xyz1731-helm-1906").owner("xyz1731").typeVersion(1906).build();*/ - - bpItem = new ServiceTypeSummary("xyz1730", "xyz1730-helm-1905", 1905, "DCAE", "dcae", "123-456-321", - "342343", true); - - bpItem2 = new ServiceTypeSummary("xyz1731", "xyz1731-helm-1906", 1906, "DCAE", "dcae", "123-456-789", - "342343", true); + + /* + * bpItem = new ServiceTypeSummary.Builder().application("DCAE").component("dcae"). + * typeName("xyz1731-helm-1906").owner("xyz1731").typeVersion(1906).build(); + */ + + bpItem = new ServiceTypeSummary("xyz1730", "xyz1730-helm-1905", 1905, "DCAE", "dcae", + "123-456-321", "342343", true); + + bpItem2 = new ServiceTypeSummary("xyz1731", "xyz1731-helm-1906", 1906, "DCAE", "dcae", + "123-456-789", "342343", true); bpItemFull = new ServiceType.Builder("xyz1731", "xyz1731-helm-1906", 1906, "tosca_definitions_version: cloudify_dsl_1_3", "", "DCAE", "dcae").build(); @@ -216,7 +226,7 @@ public class NbApiControllerTest extends MockitoTestSuite { Collection<ServiceTypeSummary> items2 = new ArrayList<ServiceTypeSummary>(); items2.add(bpItem2); - + String pageLinks2 = "{\"previousLink\":null,\"nextLink\":{\"rel\":\"next\",\"href\":\"https://invt.com:30123/dcae-services/?offset=25\"}}"; ServiceTypeSummaryList.PaginationLinks paginationLinks = @@ -224,7 +234,7 @@ public class NbApiControllerTest extends MockitoTestSuite { int totalCount = 1; bpList = new ServiceTypeSummaryList(items, totalCount, paginationLinks); bpList2 = new ServiceTypeSummaryList(items2, totalCount, paginationLinks); - + } public void createBpUploadItem() { @@ -237,52 +247,66 @@ public class NbApiControllerTest extends MockitoTestSuite { @Test public final void testCreateBlueprint() throws Exception { + // Given String bpTemplate = "tosca_definitions_version: cloudify_dsl_1_3"; - ServiceTypeUploadRequest bpUploadReq = + ServiceTypeUploadRequest bpUploadReq = new ServiceTypeUploadRequest("dcae_user", "mod1", 2008, bpTemplate, "DCAE", "dcae"); - - when(inventoryClient.addServiceType(Matchers.<ServiceTypeRequest>any())) - .thenThrow(BlueprintParseException.class).thenThrow(httpException) - .thenThrow(Exception.class).thenReturn(bpItemFull); - - //when(mockedRequest.getRequestURI()).thenReturn("https://invt-svc:8080/dcae-service-types"); - String actual = subject.createBlueprint(mockedRequest, mockedResponse, bpUploadReq, uriBuilder); - assertTrue(actual.contains("error")); - actual = subject.createBlueprint(mockedRequest, mockedResponse, bpUploadReq, uriBuilder); + + // When + when(inventoryClient.addServiceType(Mockito.<ServiceTypeRequest>any())) + .thenThrow(httpException).thenThrow(Exception.class).thenReturn(bpItemFull); + + // Then + String actual = + subject.createBlueprint(mockedRequest, mockedResponse, bpUploadReq, uriBuilder); assertTrue(actual.contains("error")); actual = subject.createBlueprint(mockedRequest, mockedResponse, bpUploadReq, uriBuilder); assertTrue(actual.contains("error")); actual = subject.createBlueprint(mockedRequest, mockedResponse, bpUploadReq, uriBuilder); assertTrue(actual.contains("xyz")); } - + + @Test + public final void testCreateBlueprint_badBp() throws Exception { + + String bpTemplate = "tosca_definitions_version: cloudify_dsl_1_3"; + ServiceTypeUploadRequest bpUploadReq = + new ServiceTypeUploadRequest("dcae_user", "mod1", 2008, bpTemplate, "DCAE", "dcae"); + + when(Blueprint.parse(bpUploadReq.getBlueprintTemplate())) + .thenThrow(BlueprintParseException.class); + + String actual1 = + subject.createBlueprint(mockedRequest, mockedResponse, bpUploadReq, uriBuilder); + assertTrue(actual1.contains("error")); + } + @Test public final void testCreateBlueprint_badReq() throws Exception { String bpTemplate = "tosca_definitions_version: cloudify_dsl_1_3"; - ServiceTypeUploadRequest bpUploadReq = + ServiceTypeUploadRequest bpUploadReq = new ServiceTypeUploadRequest("dcae_user", "mod1", 2008, bpTemplate, "DCAE", ""); - - when(inventoryClient.addServiceType(Matchers.<ServiceTypeRequest>any())) - .thenThrow(BlueprintParseException.class).thenThrow(httpException) - .thenThrow(Exception.class).thenReturn(null); - - String actual = subject.createBlueprint(mockedRequest, mockedResponse, bpUploadReq, uriBuilder); + + String actual = + subject.createBlueprint(mockedRequest, mockedResponse, bpUploadReq, uriBuilder); assertTrue(actual.contains("error")); } - + @Test public final void testQueryBlueprint() throws Exception { - + Optional<ServiceType> optionBp = Optional.ofNullable(bpItemFull); - when(inventoryClient.getServiceType(Mockito.any())).thenReturn(optionBp).thenThrow(Exception.class); - - String actual = subject.queryBlueprint("123-343", mockedRequest, mockedResponse, uriBuilder); + when(inventoryClient.getServiceType(Mockito.any())).thenReturn(optionBp) + .thenThrow(Exception.class); + + String actual = + subject.queryBlueprint("123-343", mockedRequest, mockedResponse, uriBuilder); assertTrue(actual.contains("xyz")); - + actual = subject.queryBlueprint("123-343", mockedRequest, mockedResponse, uriBuilder); assertTrue(actual.contains("error")); } - + @Test public final void testGetTenants() throws Exception { String tenantsList = @@ -301,38 +325,41 @@ public class NbApiControllerTest extends MockitoTestSuite { String tenantStr = subject.getTenants(mockedRequest); assertTrue(tenantStr.contains("dyh1b")); } - + @Test - public final void testGetBlueprintsByPage() { + public final void testGetBlueprintsByPage() throws Exception { User user = mockUser.mockUser(); user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); - String filterStr = "{\"owner\": \"xyz1730\", \"name\": \"xyz1730-helm-1905\", \"id\": \"123\"}"; - + String filterStr = + "{\"owner\": \"xyz1730\", \"name\": \"xyz1730-helm-1905\", \"id\": \"123\"}"; + mockedRequest.addParameter("filters", filterStr); mockedRequest.addParameter("sort", "name"); Set<String> userRoleSet = new HashSet<String>(); Set<String> userApps = new TreeSet<>(); userRoleSet.add("Standard User"); - userRoleSet.add("ECOMPC_DCAE_WRITE"); + userRoleSet.add("DCAE_WRITE"); userApps.add("dcae"); - + Mockito.when(mockedRequest.getAttribute("userRoles")).thenReturn(userRoleSet); Mockito.when(mockedRequest.getAttribute("userApps")).thenReturn(userApps); Collection<ServiceTypeSummary> items = bpList.items; Stream<ServiceTypeSummary> sampleStream1 = items.stream(); - Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1).thenThrow(Exception.class); - String result = subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); - assertTrue(result.contains("xyz")); - + Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1) + .thenThrow(Exception.class); + String result = + subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); + assertTrue(result.contains("xyz")); + result = subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); assertTrue(result.contains("error")); } - + @Test - public final void testGetBlueprintsByPage_sortByOwner() { + public final void testGetBlueprintsByPage_sortByOwner() throws Exception { User user = mockUser.mockUser(); user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); @@ -343,22 +370,24 @@ public class NbApiControllerTest extends MockitoTestSuite { userRoleSet.add("Standard User"); userRoleSet.add("ECOMPC_DCAE_WRITE"); userApps.add("dcae"); - + Mockito.when(mockedRequest.getAttribute("userRoles")).thenReturn(userRoleSet); Mockito.when(mockedRequest.getAttribute("userApps")).thenReturn(userApps); Collection<ServiceTypeSummary> items = bpList.items; Stream<ServiceTypeSummary> sampleStream1 = items.stream(); - Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1).thenThrow(Exception.class); - String result = subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); - assertTrue(result.contains("xyz")); - + Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1) + .thenThrow(Exception.class); + String result = + subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); + assertTrue(result.contains("xyz")); + result = subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); assertTrue(result.contains("error")); } - + @Test - public final void testGetBlueprintsByPage_sortByTypeId() { + public final void testGetBlueprintsByPage_sortByTypeId() throws Exception { User user = mockUser.mockUser(); user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); @@ -369,22 +398,24 @@ public class NbApiControllerTest extends MockitoTestSuite { userRoleSet.add("Standard User"); userRoleSet.add("ECOMPC_DCAE_WRITE"); userApps.add("dcae"); - + Mockito.when(mockedRequest.getAttribute("userRoles")).thenReturn(userRoleSet); Mockito.when(mockedRequest.getAttribute("userApps")).thenReturn(userApps); Collection<ServiceTypeSummary> items = bpList.items; Stream<ServiceTypeSummary> sampleStream1 = items.stream(); - Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1).thenThrow(Exception.class); - String result = subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); - assertTrue(result.contains("xyz")); - + Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1) + .thenThrow(Exception.class); + String result = + subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); + assertTrue(result.contains("xyz")); + result = subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); assertTrue(result.contains("error")); } - + @Test - public final void testGetBlueprintsByPage_sortByCreated() { + public final void testGetBlueprintsByPage_sortByCreated() throws Exception { User user = mockUser.mockUser(); user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); @@ -395,22 +426,24 @@ public class NbApiControllerTest extends MockitoTestSuite { userRoleSet.add("Standard User"); userRoleSet.add("ECOMPC_DCAE_WRITE"); userApps.add("dcae"); - + Mockito.when(mockedRequest.getAttribute("userRoles")).thenReturn(userRoleSet); Mockito.when(mockedRequest.getAttribute("userApps")).thenReturn(userApps); Collection<ServiceTypeSummary> items = bpList.items; Stream<ServiceTypeSummary> sampleStream1 = items.stream(); - Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1).thenThrow(Exception.class); - String result = subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); - assertTrue(result.contains("xyz")); - + Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1) + .thenThrow(Exception.class); + String result = + subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); + assertTrue(result.contains("xyz")); + result = subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); assertTrue(result.contains("error")); } - + @Test - public final void testGetBlueprintsByPage_sortByVersion() { + public final void testGetBlueprintsByPage_sortByVersion() throws Exception { User user = mockUser.mockUser(); user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); @@ -421,23 +454,25 @@ public class NbApiControllerTest extends MockitoTestSuite { userRoleSet.add("Standard User"); userRoleSet.add("ECOMPC_DCAE_WRITE"); userApps.add("dcae"); - + Mockito.when(mockedRequest.getAttribute("userRoles")).thenReturn(userRoleSet); Mockito.when(mockedRequest.getAttribute("userApps")).thenReturn(userApps); Collection<ServiceTypeSummary> items = bpList.items; Stream<ServiceTypeSummary> sampleStream1 = items.stream(); - Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1).thenThrow(Exception.class); - String result = subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); - assertTrue(result.contains("xyz")); - + Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1) + .thenThrow(Exception.class); + String result = + subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); + assertTrue(result.contains("xyz")); + result = subject.getBlueprintsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); assertTrue(result.contains("error")); } - + @SuppressWarnings("unchecked") @Test - public final void testGetDeployment() { + public final void testGetDeployment() throws HttpStatusCodeException, Exception { CloudifyDeployment cldDepl = new CloudifyDeployment("description", "blueprint_id", "created_at", "updated_at", "id1", null, null, null, null, null, null, null, "tenant1"); @@ -451,15 +486,16 @@ public class NbApiControllerTest extends MockitoTestSuite { CloudifyDeploymentList cldDeplList = new CloudifyDeploymentList(items, metadata); - when(cfyClient.getDeployment(Mockito.any())).thenReturn(cldDeplList).thenThrow(Exception.class); - + when(cfyClient.getDeployment(Mockito.any())).thenReturn(cldDeplList) + .thenThrow(Exception.class); + String actual = subject.getDeployment("id1", mockedRequest); assertTrue(actual.contains("id1")); - + actual = subject.getDeployment("id1", mockedRequest); assertTrue(actual.contains("error")); } - + @Test public final void testGetDeploymentsByPage() throws Exception { CloudifyDeployment cldDepl = new CloudifyDeployment("description", "blueprint_id", @@ -475,15 +511,17 @@ public class NbApiControllerTest extends MockitoTestSuite { CloudifyDeploymentList cldDeplList = new CloudifyDeploymentList(items, metadata); - when(cfyClient.getDeploymentsWithFilter(Mockito.any())).thenReturn(items).thenThrow(Exception.class); - - String actual = subject.getDeploymentsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); + when(cfyClient.getDeploymentsWithFilter(Mockito.any())).thenReturn(items) + .thenThrow(Exception.class); + + String actual = + subject.getDeploymentsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); assertTrue(actual.contains("id1")); - + actual = subject.getDeploymentsByPage(mockedRequest, 1, 1, uriBuilder, mockedResponse); assertTrue(actual.contains("error")); } - + @Test public final void testGetDeploymentInputs() throws Exception { CloudifyDeployment cldDepl = new CloudifyDeployment("description", "blueprint_id", @@ -499,8 +537,9 @@ public class NbApiControllerTest extends MockitoTestSuite { CloudifyDeploymentList cldDeplList = new CloudifyDeploymentList(items, metadata); - when(cfyClient.getDeploymentInputs(Mockito.any(), Mockito.any())).thenReturn(cldDeplList).thenThrow(httpException).thenThrow(Exception.class); - + when(cfyClient.getDeploymentInputs(Mockito.any(), Mockito.any())).thenReturn(cldDeplList) + .thenThrow(httpException).thenThrow(Exception.class); + String actual = subject.getDeploymentInputs("dep_id", "tenant1", mockedRequest); assertTrue(actual.contains("id1")); @@ -511,7 +550,7 @@ public class NbApiControllerTest extends MockitoTestSuite { assertTrue(actual.contains("error")); } - + @Test public final void testGetServicesForType() throws Exception { String testTypeIds = "44234234"; @@ -520,56 +559,58 @@ public class NbApiControllerTest extends MockitoTestSuite { expectedSrvcIds.add(expectedSrvc); ServiceRefList expectedSrvcRefList = new ServiceRefList(expectedSrvcIds, 1); - when(inventoryClient.getServicesForType(Matchers.<ServiceQueryParams>any())) + when(inventoryClient.getServicesForType(any(ServiceQueryParams.class))) .thenReturn(expectedSrvcRefList); String actual = subject.getServicesForType(mockedRequest, testTypeIds); assertTrue(actual.contains(testTypeIds)); } - + @SuppressWarnings("unchecked") @Test public final void testCreateDeployment() throws Exception { + // Given Map<String, Object> inputs = new HashMap<>(); inputs.put("key1", "value1"); inputs.put("key2", "value2"); inputs.put("key3", "value3"); inputs.put("key4", 100); - DeploymentInput deployInput1 = new DeploymentInput("component1", "tag1", - "xyz1731-helm-1906", 1906, "blueprintId", inputs, "tenant1", - null, true, true, true, false, true, false); + DeploymentInput deployInput1 = + new DeploymentInput("component1", "tag1", "xyz1731-helm-1906", 1906, "blueprintId", + inputs, "tenant1", null, true, true, true, false, true, false); - DeploymentInput deployInput2 = new DeploymentInput("component1", "tag1", - "xyz1731-helm-1906", 1906, null, inputs, "tenant1", - null, true, true, true, false, true, false); + DeploymentInput deployInput2 = + new DeploymentInput("component1", "tag1", "xyz1731-helm-1906", 1906, null, inputs, + "tenant1", null, true, true, true, false, true, false); DeploymentResponseLinks expectLink = new DeploymentResponseLinks("self", "status"); DeploymentResponse expectResp = new DeploymentResponse("req1", expectLink); Collection<ServiceTypeSummary> items = bpList2.items; Stream<ServiceTypeSummary> sampleStream1 = items.stream(); - Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any())) - .thenReturn(sampleStream1); - -/* String actualResp0 = subject.createDeployment(mockedRequest, mockedResponse, deployInput2); - assertTrue(actualResp0.contains("error"));*/ Optional<ServiceType> optionBp = Optional.ofNullable(bpItemFull); - Mockito.when(inventoryClient.getServiceType(Matchers.anyString())).thenReturn(optionBp); - + StringBuffer expectedStrBuff = new StringBuffer(); expectedStrBuff.append("http://oom.s2.com"); + + // When + when(inventoryClient.getServiceTypes(any(ServiceTypeQueryParams.class))) + .thenReturn(sampleStream1); + + when(inventoryClient.getServiceType(anyString())).thenReturn(optionBp); + when(mockedRequest.getRequestURL()).thenReturn(expectedStrBuff); - when(deploymentHandlerClient.putDeployment(Matchers.anyString(), Matchers.anyString(), - Matchers.<DeploymentRequest>any())).thenReturn(expectResp).thenReturn(expectResp) - .thenThrow(badReqError) - .thenThrow(srvcExistError).thenThrow(serverError).thenThrow(downStrmError) - .thenThrow(Exception.class); + when(deploymentHandlerClient.putDeployment(anyString(), anyString(), + any(DeploymentRequest.class))).thenReturn(expectResp).thenReturn(expectResp) + .thenThrow(badReqError).thenThrow(srvcExistError).thenThrow(serverError) + .thenThrow(downStrmError).thenThrow(Exception.class); + // Then String actualResp = subject.createDeployment(mockedRequest, mockedResponse, deployInput1); assertTrue(actualResp.contains("component1")); - + actualResp = subject.createDeployment(mockedRequest, mockedResponse, deployInput2); assertTrue(actualResp.contains("component1")); @@ -589,83 +630,82 @@ public class NbApiControllerTest extends MockitoTestSuite { assertTrue(actualResp.contains("error")); } - + @Test public final void testGetExecutionByDeploymentId() throws Exception { - CloudifyExecution cldExecution = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); - + CloudifyExecution cldExecution = new CloudifyExecution("successful", "created_at", + "ended_at", "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); + List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>(); cldExecutionList.add(cldExecution); CloudifyExecutionList cloudifyExecutionList = new CloudifyExecutionList(cldExecutionList, null); - + when(cfyClient.getExecutionsSummary(Mockito.any(), Mockito.any())) .thenReturn(cloudifyExecutionList).thenThrow(httpException).thenThrow(Exception.class);; - + String actual = subject.getExecutionByDeploymentId("deploymentId", "tenant", mockedRequest); assertTrue(actual.contains("execution_id1")); - + actual = subject.getExecutionByDeploymentId("deploymentId", "tenant", mockedRequest); assertTrue(actual.contains("error")); - + actual = subject.getExecutionByDeploymentId("deploymentId", "tenant", mockedRequest); assertTrue(actual.contains("error")); } - + @Test public final void testGetServiceHealthByDeploymentId() throws Exception { - String[] svcTags = {"cfytenantname=onap"}; + String[] svcTags = {"cfytenantname=onap"}; ConsulServiceHealth consulSrvcHlth = new ConsulServiceHealth("cjlvmcnsl00", "service:pgaas1_Service_ID", "Service 'pgaasServer1' check", "passing", "This is a pgaas1_Service_ID health check", "HTTP GET http://srvc.com:8000/healthcheck/status: 200 OK Output: { \"output\": \"Thu Apr 20 19:53:01 UTC 2017|INFO|masters=1 pgaas1.com|secondaries=0 |maintenance= |down=1 pgaas2.com| \" }\n", "pgaas1_Service_ID", "pgaasServer1", svcTags, 190199, 199395); - - ConsulDeploymentHealth cnslDeployHlth = + + ConsulDeploymentHealth cnslDeployHlth = new ConsulDeploymentHealth.Builder(consulSrvcHlth).build(); - + when(consulClient.getServiceHealthByDeploymentId(Mockito.any())).thenReturn(cnslDeployHlth) .thenThrow(httpException).thenThrow(Exception.class); String actual = subject.getServiceHealthByDeploymentId("deploymentId", mockedRequest); assertTrue(actual.contains("cjlvmcnsl00")); - + actual = subject.getServiceHealthByDeploymentId("deploymentId", mockedRequest); assertTrue(actual.contains("error")); - + actual = subject.getServiceHealthByDeploymentId("deploymentId", mockedRequest); assertTrue(actual.contains("error")); } - + @Test public final void testDeleteBlueprint() throws Exception { - //String expected = "{\"202\": \"OK\"}"; + // String expected = "{\"202\": \"OK\"}"; String expected = "{\"204\": \"Blueprint deleted\"}"; List<CloudifyDeployedTenant> deplForBp = new ArrayList<>(); deplForBp.clear(); - Mockito.when(cfyClient.getDeploymentForBlueprint(Matchers.<String>any())) - .thenReturn(deplForBp); - + Mockito.when(cfyClient.getDeploymentForBlueprint(anyString())).thenReturn(deplForBp); + Optional<ServiceType> optionBp = Optional.ofNullable(bpItemFull); - Mockito.when(inventoryClient.getServiceType(Matchers.anyString())).thenReturn(optionBp); + Mockito.when(inventoryClient.getServiceType(anyString())).thenReturn(optionBp); List<ServiceRef> srvcRefList = new ArrayList<>(); srvcRefList.clear(); int itemCnt = 0; ServiceRefList mockSvcRefList = new ServiceRefList(srvcRefList, itemCnt); - Mockito.when(inventoryClient.getServicesForType(Matchers.<ServiceQueryParams>any())) + Mockito.when(inventoryClient.getServicesForType(any(ServiceQueryParams.class))) .thenReturn(mockSvcRefList); - + doNothing().doThrow(serviceTypeException).doThrow(Exception.class).when(inventoryClient) - .deleteServiceType(Matchers.anyString()); + .deleteServiceType(anyString()); - String actual = subject.deleteBlueprint("srvcId", mockedRequest, mockedResponse, uriBuilder); + String actual = + subject.deleteBlueprint("srvcId", mockedRequest, mockedResponse, uriBuilder); assertEquals(expected, actual); actual = subject.deleteBlueprint("srvcId", mockedRequest, mockedResponse, uriBuilder); @@ -677,25 +717,26 @@ public class NbApiControllerTest extends MockitoTestSuite { @Test public final void testDeleteBlueprint_withDepl() throws Exception { - CloudifyDeployedTenant mockCfyDeplTen = + CloudifyDeployedTenant mockCfyDeplTen = new CloudifyDeployedTenant("id1", "tenant", "45435435", "54543534"); - + Optional<ServiceType> optionBp = Optional.ofNullable(bpItemFull); - Mockito.when(inventoryClient.getServiceType(Matchers.anyString())).thenReturn(optionBp); - + Mockito.when(inventoryClient.getServiceType(anyString())).thenReturn(optionBp); + List<CloudifyDeployedTenant> deplForBp = new ArrayList<>(); deplForBp.add(mockCfyDeplTen); - Mockito.when(cfyClient.getDeploymentForBlueprint(Matchers.<String>any())) - .thenReturn(deplForBp); - - String actual = subject.deleteBlueprint("srvcId", mockedRequest, mockedResponse, uriBuilder); + Mockito.when(cfyClient.getDeploymentForBlueprint(anyString())).thenReturn(deplForBp); + + String actual = + subject.deleteBlueprint("srvcId", mockedRequest, mockedResponse, uriBuilder); assertTrue(actual.contains("error")); } - + @Test public final void testDeleteDeployment() throws Exception { - CloudifyDeployment cldDepl = new CloudifyDeployment("description", "blueprint_id", - "created_at", "updated_at", "dcae_dep_id", null, null, null, null, null, null, null, "tenant1"); + CloudifyDeployment cldDepl = + new CloudifyDeployment("description", "blueprint_id", "created_at", "updated_at", + "dcae_dep_id", null, null, null, null, null, null, null, "tenant1"); List<CloudifyDeployment> items = new ArrayList<CloudifyDeployment>(); items.add(cldDepl); @@ -707,27 +748,28 @@ public class NbApiControllerTest extends MockitoTestSuite { CloudifyDeploymentList cldDeplList = new CloudifyDeploymentList(items, metadata); - Mockito.when(cfyClient.getDeployment(Matchers.anyString(), Matchers.anyString())).thenReturn(cldDeplList); - + Mockito.when(cfyClient.getDeployment(anyString(), anyString())).thenReturn(cldDeplList); + doNothing().doThrow(badReqError).doThrow(serverError).doThrow(downStrmError) - .doThrow(notFoundError).doThrow(Exception.class).when(deploymentHandlerClient) - .deleteDeployment(Matchers.anyString(), Matchers.anyString()); + .doThrow(notFoundError).doThrow(Exception.class).when(deploymentHandlerClient) + .deleteDeployment(anyString(), anyString()); - String actual = subject.deleteDeployment("dcae_dep_id", mockedRequest, "tenant1", mockedResponse); + String actual = + subject.deleteDeployment("dcae_dep_id", mockedRequest, "tenant1", mockedResponse); assertTrue(actual.contains("dcae_dep_id")); - + actual = subject.deleteDeployment("dcae_dep_id", mockedRequest, "tenant1", mockedResponse); assertTrue(actual.contains("error")); - + actual = subject.deleteDeployment("dcae_dep_id", mockedRequest, "tenant1", mockedResponse); assertTrue(actual.contains("error")); - + actual = subject.deleteDeployment("dcae_dep_id", mockedRequest, "tenant1", mockedResponse); assertTrue(actual.contains("error")); - + actual = subject.deleteDeployment("dcae_dep_id", mockedRequest, "tenant1", mockedResponse); assertTrue(actual.contains("error")); - + actual = subject.deleteDeployment("dcae_dep_id", mockedRequest, "tenant1", mockedResponse); assertTrue(actual.contains("error")); @@ -742,9 +784,8 @@ public class NbApiControllerTest extends MockitoTestSuite { HttpHeaders httpHeader = new HttpHeaders(); httpHeader.put("tenant", tenants); - CloudifyExecution cfyExecObj = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); + CloudifyExecution cfyExecObj = new CloudifyExecution("successful", "created_at", "ended_at", + "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); when(cfyClient.cancelExecution(Mockito.any(), Mockito.any(), Mockito.any())) .thenReturn(cfyExecObj).thenThrow(Exception.class).thenThrow(httpException); @@ -761,13 +802,12 @@ public class NbApiControllerTest extends MockitoTestSuite { subject.cancelExecution(httpHeader, "id1", null, mockedRequest, mockedResponse); assertTrue(actualResult.contains("error")); } - + @SuppressWarnings("unchecked") @Test public final void testModifyDeployment() throws Exception { - CloudifyExecution cldExecution = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); + CloudifyExecution cldExecution = new CloudifyExecution("successful", "created_at", + "ended_at", "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); Map<String, Object> params = new HashMap<String, Object>(); params.put("tenant", "tenant1"); @@ -775,7 +815,7 @@ public class NbApiControllerTest extends MockitoTestSuite { CloudifyExecutionRequest cfyExecReq = new CloudifyExecutionRequest("deployment_id", "upgrade", false, false, "tenant1", params); - + CloudifyNodeInstanceId cfyNodeInst = new CloudifyNodeInstanceId("node_instance_id1"); List<CloudifyNodeInstanceId> cfyNodeInstItems = new ArrayList<CloudifyNodeInstanceId>(); @@ -786,18 +826,18 @@ public class NbApiControllerTest extends MockitoTestSuite { new CloudifyNodeInstanceIdList(cfyNodeInstItems, null); when(cfyClient.getNodeInstanceId(Mockito.any(), Mockito.any())).thenReturn(cfyNodeInstList); - + String secretTokenStr = - "{\"created_at\": \"created_ts\", \"key\": \"acl_key\", \"updated_at\": \"updated_ts\", \"value\": \"acl_token_val\", \"visibility\": \"global\", \"is_hidden_value\": \"false\", \"tenant_name\": \"tenant\", \"resource_availability\": \"rsrc\"}"; + "{\"created_at\": \"created_ts\", \"key\": \"acl_key\", \"updated_at\": \"updated_ts\", \"value\": \"acl_token_val\", \"visibility\": \"global\", \"is_hidden_value\": \"false\", \"tenant_name\": \"tenant\", \"resource_availability\": \"rsrc\"}"; CloudifySecret secretData = null; try { secretData = objectMapper.readValue(secretTokenStr, CloudifySecret.class); } catch (Exception e) { - + } when(cfyClient.getSecret(Mockito.any(), Mockito.any())).thenReturn(secretData); - when(cfyClient.startExecution(Matchers.<CloudifyExecutionRequest>any())) - .thenReturn(cldExecution).thenThrow(Exception.class).thenThrow(httpException); + when(cfyClient.startExecution(any(CloudifyExecutionRequest.class))).thenReturn(cldExecution) + .thenThrow(Exception.class).thenThrow(httpException); String inputParamStr = "{\"tenant\": \"tenant1\", \"workflow\":\"upgrade\"}"; @@ -805,7 +845,7 @@ public class NbApiControllerTest extends MockitoTestSuite { String actualResult = subject.modifyDeployment("depId", mockedRequest, is1); assertTrue(actualResult.contains("execution_id1")); - InputStream is2 = new ByteArrayInputStream(inputParamStr.getBytes()); + InputStream is2 = new ByteArrayInputStream(inputParamStr.getBytes()); actualResult = subject.modifyDeployment("depId", mockedRequest, is2); assertTrue(actualResult.contains("error")); diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dasboard/exceptions/DahboardControllerExceptionTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dasboard/exceptions/DahboardControllerExceptionTest.java index ab98400..dbf0e2a 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dasboard/exceptions/DahboardControllerExceptionTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dasboard/exceptions/DahboardControllerExceptionTest.java @@ -2,24 +2,24 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. - * - * Modifications Copyright (C) 2019 IBM. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2019 IBM. * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * ============LICENSE_END========================================================= * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ECOMP is a trademark and service mark of AT&T Intellectual Property. *******************************************************************************/ package org.onap.ccsdk.dasboard.exceptions; @@ -30,38 +30,41 @@ import org.onap.ccsdk.dashboard.exceptions.DashboardControllerException; public class DahboardControllerExceptionTest { - @Test - public void TestException1() { - - DashboardControllerException sta = new DashboardControllerException(); - assertEquals("org.onap.ccsdk.dashboard.exceptions.DashboardControllerException",sta.getClass().getName()); - - } + @Test + public void TestException1() { - @Test - public void TestException2() { - - DashboardControllerException sta= new DashboardControllerException("org.onap.ccsdk.dashboard.exceptions.DashboardControllerException"); - assertEquals(sta.getMessage(), "org.onap.ccsdk.dashboard.exceptions.DashboardControllerException"); - - } + DashboardControllerException sta = new DashboardControllerException(); + assertEquals("org.onap.ccsdk.dashboard.exceptions.DashboardControllerException", + sta.getClass().getName()); + } - @Test - public void TestException3() { - - DashboardControllerException sta= new DashboardControllerException(new Throwable()); - assertEquals("org.onap.ccsdk.dashboard.exceptions.DashboardControllerException", sta.getClass().getName()); - - } + @Test + public void TestException2() { - + DashboardControllerException sta = new DashboardControllerException( + "org.onap.ccsdk.dashboard.exceptions.DashboardControllerException"); + assertEquals(sta.getMessage(), + "org.onap.ccsdk.dashboard.exceptions.DashboardControllerException"); - @Test - public void TestException4() { - - DashboardControllerException sta= new DashboardControllerException("org.onap.ccsdk.dashboard.exceptions.DashboardControllerException", new Throwable()); - assertEquals("org.onap.ccsdk.dashboard.exceptions.DashboardControllerException",sta.getClass().getName()); - - } + } + + @Test + public void TestException3() { + + DashboardControllerException sta = new DashboardControllerException(new Throwable()); + assertEquals("org.onap.ccsdk.dashboard.exceptions.DashboardControllerException", + sta.getClass().getName()); + + } + + @Test + public void TestException4() { + + DashboardControllerException sta = new DashboardControllerException( + "org.onap.ccsdk.dashboard.exceptions.DashboardControllerException", new Throwable()); + assertEquals("org.onap.ccsdk.dashboard.exceptions.DashboardControllerException", + sta.getClass().getName()); + + } } diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CloudifyControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CloudifyControllerTest.java index d88e530..6744fd4 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CloudifyControllerTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/CloudifyControllerTest.java @@ -25,6 +25,8 @@ package org.onap.ccsdk.dashboard.controller; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.when; @@ -35,11 +37,9 @@ import java.util.List; import java.util.Map; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; @@ -73,26 +73,28 @@ import org.onap.ccsdk.dashboard.rest.InventoryClient; import org.onap.portalsdk.core.domain.User; import org.onap.portalsdk.core.util.CacheManager; import org.onap.portalsdk.core.web.support.UserUtils; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpStatus; import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpStatusCodeException; -import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; @RunWith(PowerMockRunner.class) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) public class CloudifyControllerTest extends MockitoTestSuite { @Mock private CloudifyClient restClient; - + @Mock private InventoryClient invClient; @InjectMocks - private CloudifyController subject = new CloudifyController(); + private CloudifyController subject; protected final ObjectMapper objectMapper = new ObjectMapper(); @@ -112,7 +114,7 @@ public class CloudifyControllerTest extends MockitoTestSuite { objectMapper.registerModule(new Jdk8Module()); httpException = new HttpClientErrorException(HttpStatus.BAD_REQUEST, "statusText"); CacheManager testCache = new CacheManager(); - subject.setCacheManager(testCache); + subject.setCacheManager(testCache); } @SuppressWarnings("unchecked") @@ -150,10 +152,10 @@ public class CloudifyControllerTest extends MockitoTestSuite { User user = mockUser.mockUser(); user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); - //mockedRequest.addParameter("searchBy", "xyz"); + // mockedRequest.addParameter("searchBy", "xyz"); mockedRequest.addParameter("sortBy", "owner"); Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); - + CloudifyDeployment cldDepl = new CloudifyDeployment("description", "blueprint_id", "created_at", "updated_at", "id1", null, null, null, null, null, null, null, "tenant1"); @@ -166,14 +168,14 @@ public class CloudifyControllerTest extends MockitoTestSuite { CloudifyDeploymentList.Metadata metadata = new CloudifyDeploymentList.Metadata(pageObj); CloudifyDeploymentList cldDeplList = new CloudifyDeploymentList(items, metadata); - - Mockito.when(restClient.getDeployments( - Mockito.any(),Mockito.anyInt(), Mockito.anyInt(), Mockito.anyBoolean())) - .thenReturn(items); - + + Mockito.when(restClient.getDeployments(Mockito.any(), Mockito.anyInt(), Mockito.anyInt(), + Mockito.anyBoolean())).thenReturn(items); + String actual = subject.getAllServiceNames(mockedRequest); assertTrue(actual.contains("id1")); } + @Test public final void testGetDeploymentsByPage() { User user = mockUser.mockUser(); @@ -182,7 +184,7 @@ public class CloudifyControllerTest extends MockitoTestSuite { mockedRequest.addParameter("searchBy", "tenant:default_tenant;cache:false;serviceRef:id1"); mockedRequest.addParameter("sortBy", "owner"); Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); - + CloudifyDeployment cldDepl = new CloudifyDeployment("description", "blueprint_id", "created_at", "updated_at", "id1", null, null, null, null, null, null, null, "tenant1"); @@ -195,43 +197,38 @@ public class CloudifyControllerTest extends MockitoTestSuite { CloudifyDeploymentList.Metadata metadata = new CloudifyDeploymentList.Metadata(pageObj); CloudifyDeploymentList cldDeplList = new CloudifyDeploymentList(items, metadata); - - Mockito.when(restClient.getDeployments( - Mockito.any(),Mockito.anyInt(), Mockito.anyInt(), Mockito.anyBoolean(), Mockito.anyBoolean())) - .thenReturn(items); - List<CloudifyDeploymentExt> cfyDepExList = - new ArrayList<CloudifyDeploymentExt>(); - List<CloudifyDeploymentHelm> cfyDeplHelmList = - new ArrayList<CloudifyDeploymentHelm>(); - - Mockito.when(restClient.updateWorkflowStatus(Mockito.any())). - thenReturn(cfyDepExList); - Mockito.when(restClient.updateHelmInfo(Mockito.any())). - thenReturn(cfyDeplHelmList); - + + Mockito.when(restClient.getDeployments(Mockito.any(), Mockito.anyInt(), Mockito.anyInt(), + Mockito.anyBoolean(), Mockito.anyBoolean())).thenReturn(items); + List<CloudifyDeploymentExt> cfyDepExList = new ArrayList<CloudifyDeploymentExt>(); + List<CloudifyDeploymentHelm> cfyDeplHelmList = new ArrayList<CloudifyDeploymentHelm>(); + + Mockito.when(restClient.updateWorkflowStatus(Mockito.any())).thenReturn(cfyDepExList); + Mockito.when(restClient.updateHelmInfo(Mockito.any())).thenReturn(cfyDeplHelmList); + String actual = subject.getDeploymentsByPage(mockedRequest); assertTrue(actual.contains("id1")); } - + @Test public final void testViewBlueprintContentById() throws Exception { byte[] result = "sample blueprint yaml content".getBytes(); - + when(restClient.viewBlueprint(Mockito.any(), Mockito.any())).thenReturn(result); - + byte[] actual = subject.viewBlueprintContentById("id", "tenant", mockedRequest); assertArrayEquals(result, actual); } - + @Test public final void testGetDepCount() throws Exception { User user = mockUser.mockUser(); user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); - //mockedRequest.addParameter("searchBy", "xyz"); + // mockedRequest.addParameter("searchBy", "xyz"); mockedRequest.addParameter("sortBy", "owner"); Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); - + CloudifyDeployment cldDepl = new CloudifyDeployment("description", "blueprint_id", "created_at", "updated_at", "id1", null, null, null, null, null, null, null, "tenant1"); @@ -244,17 +241,16 @@ public class CloudifyControllerTest extends MockitoTestSuite { CloudifyDeploymentList.Metadata metadata = new CloudifyDeploymentList.Metadata(pageObj); CloudifyDeploymentList cldDeplList = new CloudifyDeploymentList(items, metadata); - - Mockito.when(restClient.getDeploymentsWithFilter(Mockito.any())) - .thenReturn(items); - + + Mockito.when(restClient.getDeploymentsWithFilter(Mockito.any())).thenReturn(items); + String actual = subject.getDepCount(mockedRequest); assertTrue(actual.contains("items")); } - + @Test - public final void testGetPluginCount() throws JsonProcessingException { - CloudifyPlugin sampleData = + public final void testGetPluginCount() throws HttpStatusCodeException, Exception { + CloudifyPlugin sampleData = new CloudifyPlugin("plugin1", "202001", "linux", "linux_k8s_plugin", "20200801"); List<CloudifyPlugin> cfyPlugins = new ArrayList<CloudifyPlugin>(); @@ -265,56 +261,51 @@ public class CloudifyControllerTest extends MockitoTestSuite { CloudifyPluginList.Metadata metadata = new CloudifyPluginList.Metadata(pageObj); CloudifyPluginList cfyPluginList = new CloudifyPluginList(cfyPlugins, metadata); - + when(restClient.getPlugins()).thenReturn(cfyPluginList); String actual = subject.getPluginCount(mockedRequest); assertTrue(actual.contains("1")); } - + @Test public final void testDeleteBlueprint() throws Exception { - String json = "{\"202\": \"OK\"}"; - - doNothing().doThrow(httpException).doThrow(Exception.class).when(restClient).deleteBlueprint(Mockito.any(), Mockito.any()); - + String json = "{\"202\": \"OK\"}"; + + doNothing().doThrow(httpException).doThrow(Exception.class).when(restClient) + .deleteBlueprint(Mockito.any(), Mockito.any()); + String actual = subject.deleteBlueprint("id", "tenant", mockedRequest, mockedResponse); assertTrue(actual.equals(json)); - + actual = subject.deleteBlueprint("id", "tenant", mockedRequest, mockedResponse); assertTrue(actual.contains("error")); - + actual = subject.deleteBlueprint("id", "tenant", mockedRequest, mockedResponse); assertTrue(actual.contains("error")); } - + @Test - public final void testGetDeploymentsForType() throws Exception { + public final void testGetDeploymentsForType() throws Exception { String[] testTypeIds = {"44234234"}; ServiceRef expectedSrvc = new ServiceRef("dcae_dtiapi_1902", "432423", "433434"); Collection<ServiceRef> expectedSrvcIds = new ArrayList<ServiceRef>(); expectedSrvcIds.add(expectedSrvc); ServiceRefList expectedSrvcRefList = new ServiceRefList(expectedSrvcIds, 1); - CloudifyDeployedTenant cfyDepTen = + CloudifyDeployedTenant cfyDepTen = new CloudifyDeployedTenant("id", "tenant_name", "created_at", "updated_at"); - + List<CloudifyDeployedTenant> cfyDeplTenList = new ArrayList<>(); cfyDeplTenList.add(cfyDepTen); - + when(restClient.getDeploymentForBlueprint(Mockito.any())).thenReturn(cfyDeplTenList); - - when(invClient.getServicesForType(Matchers.<ServiceQueryParams>any())) + + when(invClient.getServicesForType(any(ServiceQueryParams.class))) .thenReturn(expectedSrvcRefList); String actual = subject.getDeploymentsForType(mockedRequest, testTypeIds); assertTrue(actual.contains(testTypeIds[0])); } - - @Test - @Ignore - public final void testCacheOwnerDeployMap() { - - } - + @Test public final void testGetExecutionsPerTenant() throws Exception { String tenantsList = @@ -328,22 +319,21 @@ public class CloudifyControllerTest extends MockitoTestSuite { } MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); Mockito.when(restClient.getTenants()).thenReturn(tenantData); - - CloudifyExecution cldExecution = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); - + + CloudifyExecution cldExecution = new CloudifyExecution("successful", "created_at", + "ended_at", "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); + List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>(); cldExecutionList.add(cldExecution); CloudifyExecutionList cloudifyExecutionList = new CloudifyExecutionList(cldExecutionList, null); - + when(restClient.getExecutionsSummaryPerTenant(Mockito.any())) .thenReturn(cloudifyExecutionList).thenReturn(cloudifyExecutionList) .thenReturn(cloudifyExecutionList); - + String actual = subject.getExecutionsPerTenant(mockedRequest, "default_tenant", "failed"); assertFalse(actual.contains("execution_id1")); actual = subject.getExecutionsPerTenant(mockedRequest, "default_tenant", "successful"); @@ -351,7 +341,7 @@ public class CloudifyControllerTest extends MockitoTestSuite { actual = subject.getExecutionsPerTenant(mockedRequest, null, "successful"); assertTrue(actual.contains("execution_id1")); } - + @Test public final void testGetExecutionsPerTenant_error() throws Exception { String tenantsList = @@ -365,46 +355,44 @@ public class CloudifyControllerTest extends MockitoTestSuite { } MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); Mockito.when(restClient.getTenants()).thenReturn(tenantData); - - CloudifyExecution cldExecution = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); - + + CloudifyExecution cldExecution = new CloudifyExecution("successful", "created_at", + "ended_at", "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); + List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>(); cldExecutionList.add(cldExecution); CloudifyExecutionList cloudifyExecutionList = new CloudifyExecutionList(cldExecutionList, null); - - when(restClient.getExecutionsSummaryPerTenant(Mockito.any())) - .thenThrow(Exception.class).thenThrow(Exception.class).thenThrow(Exception.class); - + + when(restClient.getExecutionsSummaryPerTenant(Mockito.any())).thenThrow(Exception.class) + .thenThrow(Exception.class).thenThrow(Exception.class); + String actual = subject.getExecutionsPerTenant(mockedRequest, "default_tenant", "failed"); assertTrue(actual.contains("error")); - + actual = subject.getExecutionsPerTenant(mockedRequest, "default_tenant", "successful"); assertTrue(actual.contains("error")); - + actual = subject.getExecutionsPerTenant(mockedRequest, null, "failed"); assertTrue(actual.contains("error")); } - + @Test - public final void testQueryExecution() throws Exception { - CloudifyExecution cldExecution = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); + public final void testQueryExecution() throws Exception { + CloudifyExecution cldExecution = new CloudifyExecution("successful", "created_at", + "ended_at", "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>(); cldExecutionList.add(cldExecution); - - when(restClient.getExecutionIdSummary( - Mockito.any(), Mockito.any())).thenReturn(cldExecution); - + + when(restClient.getExecutionIdSummary(Mockito.any(), Mockito.any())) + .thenReturn(cldExecution); + String actual = subject.queryExecution("id", "tenant", mockedRequest); assertTrue(actual.contains("items")); } - + @SuppressWarnings("unchecked") @Test public final void testGetActiveExecutions() throws Exception { @@ -419,36 +407,34 @@ public class CloudifyControllerTest extends MockitoTestSuite { } MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); Mockito.when(restClient.getTenants()).thenReturn(tenantData).thenThrow(Exception.class); - - CloudifyExecution cldExecution = - new CloudifyExecution("started", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); - + + CloudifyExecution cldExecution = new CloudifyExecution("started", "created_at", "ended_at", + "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); + List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>(); cldExecutionList.add(cldExecution); CloudifyExecutionList cloudifyExecutionList = new CloudifyExecutionList(cldExecutionList, null); - + when(restClient.getExecutionsSummaryPerTenant(Mockito.any())) .thenReturn(cloudifyExecutionList).thenReturn(cloudifyExecutionList); - + String actual = subject.getActiveExecutions(mockedRequest); assertTrue(actual.contains("execution_id1")); actual = subject.getActiveExecutions(mockedRequest); assertTrue(actual.contains("error")); - + } - + @Test public final void testGetNodeInstanceDetails() throws Exception { - - Map<String, Object> runtime_properties = - new HashMap<>(); + + Map<String, Object> runtime_properties = new HashMap<>(); runtime_properties.put("key1", "value1"); - - CloudifyNodeInstance cfyNodeInst = + + CloudifyNodeInstance cfyNodeInst = new CloudifyNodeInstance("node_instance_id1", runtime_properties); List<CloudifyNodeInstance> cfyNodeInstItems = new ArrayList<CloudifyNodeInstance>(); @@ -457,24 +443,20 @@ public class CloudifyControllerTest extends MockitoTestSuite { CloudifyNodeInstanceList cfyNodeInstList = new CloudifyNodeInstanceList(cfyNodeInstItems, null); - - when(restClient.getNodeInstanceDetails(Mockito.any(), Mockito.any())). - thenReturn(cfyNodeInstList).thenThrow(httpException). - thenThrow(Exception.class); - - String actual = - subject.getNodeInstanceDetails("deploymentId", "tenant", mockedRequest); + + when(restClient.getNodeInstanceDetails(Mockito.any(), Mockito.any())) + .thenReturn(cfyNodeInstList).thenThrow(httpException).thenThrow(Exception.class); + + String actual = subject.getNodeInstanceDetails("deploymentId", "tenant", mockedRequest); assertTrue(actual.contains("node_instance_id1")); - - actual = - subject.getNodeInstanceDetails("deploymentId", "tenant", mockedRequest); + + actual = subject.getNodeInstanceDetails("deploymentId", "tenant", mockedRequest); + assertTrue(actual.contains("error")); + + actual = subject.getNodeInstanceDetails("deploymentId", "tenant", mockedRequest); assertTrue(actual.contains("error")); - - actual = - subject.getNodeInstanceDetails("deploymentId", "tenant", mockedRequest); - assertTrue(actual.contains("error")); } - + @Test public final void testGetNodeInstances() throws Exception { CloudifyNodeInstanceId cfyNodeInst = new CloudifyNodeInstanceId("node_instance_id1"); @@ -485,27 +467,23 @@ public class CloudifyControllerTest extends MockitoTestSuite { CloudifyNodeInstanceIdList cfyNodeInstList = new CloudifyNodeInstanceIdList(cfyNodeInstItems, null); - - when(restClient.getNodeInstances(Mockito.any(), Mockito.any())). - thenReturn(cfyNodeInstList).thenThrow(httpException). - thenThrow(Exception.class); - - String actual = - subject.getNodeInstances("deploymentId", "tenant", mockedRequest); + + when(restClient.getNodeInstances(Mockito.any(), Mockito.any())).thenReturn(cfyNodeInstList) + .thenThrow(httpException).thenThrow(Exception.class); + + String actual = subject.getNodeInstances("deploymentId", "tenant", mockedRequest); assertTrue(actual.contains("node_instance_id1")); - - actual = - subject.getNodeInstances("deploymentId", "tenant", mockedRequest); + + actual = subject.getNodeInstances("deploymentId", "tenant", mockedRequest); assertTrue(actual.contains("error")); - - actual = - subject.getNodeInstances("deploymentId", "tenant", mockedRequest); + + actual = subject.getNodeInstances("deploymentId", "tenant", mockedRequest); assertTrue(actual.contains("error")); } - + @Test public final void testGetPlugins() throws Exception { - CloudifyPlugin sampleData = + CloudifyPlugin sampleData = new CloudifyPlugin("plugin1", "202001", "linux", "linux_k8s_plugin", "20200801"); List<CloudifyPlugin> cfyPlugins = new ArrayList<CloudifyPlugin>(); @@ -516,38 +494,15 @@ public class CloudifyControllerTest extends MockitoTestSuite { CloudifyPluginList.Metadata metadata = new CloudifyPluginList.Metadata(pageObj); CloudifyPluginList cfyPluginList = new CloudifyPluginList(cfyPlugins, metadata); - + when(restClient.getPlugins()).thenReturn(cfyPluginList).thenThrow(Exception.class); String actual = subject.getPlugins(mockedRequest); assertTrue(actual.contains("plugin1")); - + actual = subject.getPlugins(mockedRequest); assertTrue(actual.contains("error")); } - - @Test - @Ignore - public final void testGetSecrets() { - - } - - @Test - @Ignore - public final void testGetSecret() { - - } - - @Test - @Ignore - public final void testDeleteSecret() { - - } - - @Test - @Ignore - public final void testCreateSecret() { - } - + @SuppressWarnings({"unchecked", "unchecked"}) @Test public final void testGetBlueprintById() throws Exception { @@ -619,13 +574,12 @@ public class CloudifyControllerTest extends MockitoTestSuite { actualResult = subject.getDeploymentById("id1", null, mockedRequest); assertTrue(actualResult.contains("error")); } - + @Test public void testGetExecutionsByPage() throws Exception { - CloudifyExecution cldExecution = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); - + CloudifyExecution cldExecution = new CloudifyExecution("successful", "created_at", + "ended_at", "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); + List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>(); cldExecutionList.add(cldExecution); @@ -644,8 +598,9 @@ public class CloudifyControllerTest extends MockitoTestSuite { CloudifyDeploymentList.Metadata metadata = new CloudifyDeploymentList.Metadata(pageObj); CloudifyDeploymentList cldDeployList = new CloudifyDeploymentList(cfyDeployItems, metadata); - - when(restClient.getDeployments(Mockito.any(), Mockito.anyInt(), Mockito.anyInt())).thenReturn(cldDeployList); + + when(restClient.getDeployments(Mockito.any(), Mockito.anyInt(), Mockito.anyInt())) + .thenReturn(cldDeployList); when(restClient.getExecutions(Mockito.any(), Mockito.any())) .thenReturn(cloudifyExecutionList).thenThrow(Exception.class) .thenReturn(cloudifyExecutionList); @@ -660,37 +615,39 @@ public class CloudifyControllerTest extends MockitoTestSuite { actualResult = subject.getExecutionsByPage(mockedRequest, null, "successful", "tenant1"); assertTrue(actualResult.contains("successful")); } -/* - @SuppressWarnings("unchecked") - @Test - public void testGetExecutionByIdAndDeploymentId() throws Exception { - CloudifyExecution cldExecution = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); - - List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>(); - - cldExecutionList.add(cldExecution); - - CloudifyExecutionList cloudifyExecutionList = - new CloudifyExecutionList(cldExecutionList, null); - - when(restClient.getExecutions(Mockito.any(), Mockito.any())) - .thenReturn(cloudifyExecutionList).thenThrow(Exception.class).thenThrow(httpException); - - String actualResult = subject.getExecutionByIdAndDeploymentId("execution_id", - "deployment_id", "tenant", mockedRequest); - assertTrue(actualResult.contains("successful")); - - actualResult = subject.getExecutionByIdAndDeploymentId("execution_id", "deployment_id", - "tenant", mockedRequest); - assertTrue(actualResult.contains("error")); - actualResult = subject.getExecutionByIdAndDeploymentId("execution_id", "deployment_id", - "tenant", mockedRequest); - assertTrue(actualResult.contains("error")); - } -*/ + /* + * @SuppressWarnings("unchecked") + * + * @Test + * public void testGetExecutionByIdAndDeploymentId() throws Exception { + * CloudifyExecution cldExecution = + * new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", + * "tenant1", "error", "execution_id1", null); + * + * List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>(); + * + * cldExecutionList.add(cldExecution); + * + * CloudifyExecutionList cloudifyExecutionList = + * new CloudifyExecutionList(cldExecutionList, null); + * + * when(restClient.getExecutions(Mockito.any(), Mockito.any())) + * .thenReturn(cloudifyExecutionList).thenThrow(Exception.class).thenThrow(httpException); + * + * String actualResult = subject.getExecutionByIdAndDeploymentId("execution_id", + * "deployment_id", "tenant", mockedRequest); + * assertTrue(actualResult.contains("successful")); + * + * actualResult = subject.getExecutionByIdAndDeploymentId("execution_id", "deployment_id", + * "tenant", mockedRequest); + * assertTrue(actualResult.contains("error")); + * + * actualResult = subject.getExecutionByIdAndDeploymentId("execution_id", "deployment_id", + * "tenant", mockedRequest); + * assertTrue(actualResult.contains("error")); + * } + */ @SuppressWarnings("unchecked") @Test public void testGetExecutionEventsById() throws Exception { @@ -708,7 +665,7 @@ public class CloudifyControllerTest extends MockitoTestSuite { CloudifyEventList cfyEventsList = new CloudifyEventList(cfyEventItems, null); - when(restClient.getEventlogs(Mockito.any(), Mockito.any())).thenReturn(cfyEventsList) + when(restClient.getEventlogs(anyString(), anyString())).thenReturn(cfyEventsList) .thenThrow(Exception.class).thenThrow(httpException); String actualResult = @@ -727,9 +684,8 @@ public class CloudifyControllerTest extends MockitoTestSuite { @SuppressWarnings("unchecked") @Test public void testStartExecution() throws Exception { - CloudifyExecution cldExecution = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); + CloudifyExecution cldExecution = new CloudifyExecution("successful", "created_at", + "ended_at", "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); Map<String, Object> params = new HashMap<String, Object>(); params.put("key1", "value1"); @@ -745,21 +701,20 @@ public class CloudifyControllerTest extends MockitoTestSuite { CloudifyNodeInstanceIdList cfyNodeInstList = new CloudifyNodeInstanceIdList(cfyNodeInstItems, null); - + String secretTokenStr = - "{\"created_at\": \"created_ts\", \"key\": \"acl_key\", \"updated_at\": \"updated_ts\", \"value\": \"acl_token_val\", \"visibility\": \"global\", \"is_hidden_value\": \"false\", \"tenant_name\": \"tenant\", \"resource_availability\": \"rsrc\"}"; + "{\"created_at\": \"created_ts\", \"key\": \"acl_key\", \"updated_at\": \"updated_ts\", \"value\": \"acl_token_val\", \"visibility\": \"global\", \"is_hidden_value\": \"false\", \"tenant_name\": \"tenant\", \"resource_availability\": \"rsrc\"}"; CloudifySecret secretData = null; try { secretData = objectMapper.readValue(secretTokenStr, CloudifySecret.class); } catch (Exception e) { - + } - when(restClient.getSecret(Mockito.any(), Mockito.any())).thenReturn(secretData); - - when(restClient.getNodeInstanceId(Mockito.any(), Mockito.any())) - .thenReturn(cfyNodeInstList); + when(restClient.getSecret(anyString(), anyString())).thenReturn(secretData); + + when(restClient.getNodeInstanceId(anyString(), anyString())).thenReturn(cfyNodeInstList); - when(restClient.startExecution(Matchers.<CloudifyExecutionRequest>any())) + when(restClient.startExecution(any(CloudifyExecutionRequest.class))) .thenReturn(cldExecution).thenThrow(Exception.class).thenThrow(httpException); String actualResult = subject.startExecution(mockedRequest, cfyExecReq); @@ -785,7 +740,7 @@ public class CloudifyControllerTest extends MockitoTestSuite { CloudifyNodeInstanceIdList cfyNodeInstList = new CloudifyNodeInstanceIdList(cfyNodeInstItems, null); - when(restClient.getNodeInstanceId(Mockito.any(), Mockito.any(), Mockito.any())) + when(restClient.getNodeInstanceId(anyString(), anyString(), anyString())) .thenReturn(cfyNodeInstList).thenThrow(Exception.class).thenThrow(httpException); String actualResult = @@ -811,7 +766,7 @@ public class CloudifyControllerTest extends MockitoTestSuite { CloudifyNodeInstanceList cfyNodeInstList = new CloudifyNodeInstanceList(cfyNodeInstanceItems, null); - when(restClient.getNodeInstanceVersion(Mockito.any(), Mockito.any())) + when(restClient.getNodeInstanceVersion(anyString(), anyString())) .thenReturn(cfyNodeInstList).thenThrow(Exception.class).thenThrow(httpException); String actualResult = @@ -834,11 +789,10 @@ public class CloudifyControllerTest extends MockitoTestSuite { HttpHeaders httpHeader = new HttpHeaders(); httpHeader.put("tenant", tenants); - CloudifyExecution cfyExecObj = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); + CloudifyExecution cfyExecObj = new CloudifyExecution("successful", "created_at", "ended_at", + "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); - when(restClient.cancelExecution(Mockito.any(), Mockito.any(), Mockito.any())) + when(restClient.cancelExecution(anyString(), Mockito.any(), anyString())) .thenReturn(cfyExecObj).thenThrow(Exception.class).thenThrow(httpException); String actualResult = diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ConsulControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ConsulControllerTest.java index 53657ed..2642164 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ConsulControllerTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ConsulControllerTest.java @@ -23,28 +23,22 @@ package org.onap.ccsdk.dashboard.controller; import static org.junit.Assert.assertTrue; +import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.Mockito.when; import java.util.ArrayList; import java.util.List; -import javax.servlet.http.HttpServletRequest; - import org.junit.After; import org.junit.Before; -import org.junit.Ignore; import org.junit.Test; import org.mockito.InjectMocks; -import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; -import org.onap.ccsdk.dashboard.controller.ConsulController.ConsulDataItem; import org.onap.ccsdk.dashboard.core.MockUser; import org.onap.ccsdk.dashboard.core.MockitoTestSuite; -import org.onap.ccsdk.dashboard.model.RestResponseSuccess; import org.onap.ccsdk.dashboard.model.consul.ConsulDatacenter; -import org.onap.ccsdk.dashboard.model.consul.ConsulHealthServiceRegistration; import org.onap.ccsdk.dashboard.model.consul.ConsulNodeInfo; import org.onap.ccsdk.dashboard.model.consul.ConsulServiceHealth; import org.onap.ccsdk.dashboard.model.consul.ConsulServiceInfo; @@ -63,15 +57,15 @@ public class ConsulControllerTest extends MockitoTestSuite { ConsulClient consulClient; @InjectMocks - ConsulController subject = new ConsulController(); + ConsulController subject; protected final ObjectMapper objectMapper = new ObjectMapper(); MockUser mockUser = new MockUser(); HttpClientErrorException httpException; - String[] svcTags = {"cfytenantname=onap"}; - + String[] svcTags = {"cfytenantname=onap"}; + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); @@ -97,7 +91,7 @@ public class ConsulControllerTest extends MockitoTestSuite { List<ConsulServiceHealth> expectedCnslSrvcHlth = new ArrayList<ConsulServiceHealth>(); expectedCnslSrvcHlth.add(consulSrvcHlth); - when(consulClient.getServiceHealth(Matchers.anyString(), Matchers.anyString())) + when(consulClient.getServiceHealth(anyString(), anyString())) .thenReturn(expectedCnslSrvcHlth).thenThrow(Exception.class); String actualResult = subject.getServiceHealthDetails(mockedRequest, "dc1", "srvc1"); @@ -128,8 +122,8 @@ public class ConsulControllerTest extends MockitoTestSuite { List<ConsulServiceHealth> expectedCnslSrvcHlth = new ArrayList<ConsulServiceHealth>(); expectedCnslSrvcHlth.add(consulSrvcHlth); - when(consulClient.getServices(Matchers.anyString())).thenReturn(expectedCnslSrvcs); - when(consulClient.getServiceHealth(Matchers.anyString(), Matchers.anyString())) + when(consulClient.getServices(anyString())).thenReturn(expectedCnslSrvcs); + when(consulClient.getServiceHealth(anyString(), anyString())) .thenReturn(expectedCnslSrvcHlth).thenThrow(Exception.class); String actualResult = subject.getServicesHealth(mockedRequest, "dc1"); @@ -140,7 +134,7 @@ public class ConsulControllerTest extends MockitoTestSuite { } @Test - public final void testGetNodesInfo() { + public final void testGetNodesInfo() throws Exception { User user = mockUser.mockUser(); user.setLoginId("tester"); user.setId(1000L); @@ -152,7 +146,7 @@ public class ConsulControllerTest extends MockitoTestSuite { List<ConsulNodeInfo> cnslNodeList = new ArrayList<ConsulNodeInfo>(); cnslNodeList.add(cnslNode); - when(consulClient.getNodes(Matchers.anyString())).thenReturn(cnslNodeList); + when(consulClient.getNodes(anyString())).thenReturn(cnslNodeList); String actualResult = subject.getNodesInfo(mockedRequest, "dc1"); assertTrue(actualResult.contains("cjlvmcnsl00")); @@ -170,7 +164,7 @@ public class ConsulControllerTest extends MockitoTestSuite { List<ConsulServiceHealth> expectedCnslSrvcHlth = new ArrayList<ConsulServiceHealth>(); expectedCnslSrvcHlth.add(consulSrvcHlth); - when(consulClient.getNodeServicesHealth(Matchers.anyString(), Matchers.anyString())) + when(consulClient.getNodeServicesHealth(anyString(), anyString())) .thenReturn(expectedCnslSrvcHlth).thenThrow(Exception.class); String actualResult = subject.getNodeServicesHealth(mockedRequest, "dc1", "node1"); @@ -204,9 +198,9 @@ public class ConsulControllerTest extends MockitoTestSuite { user.setLoginId("tester"); user.setId(1000L); Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); - String actualResult = - subject.getItemListForPageWrapper(mockedRequest, "dc1", ConsulController.ConsulDataItem.SERVICE_INFO); + String actualResult = subject.getItemListForPageWrapper(mockedRequest, "dc1", + ConsulController.ConsulDataItem.SERVICE_INFO); assertTrue(actualResult.contains("error")); - + } } diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/DeploymentHandlerControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/DeploymentHandlerControllerTest.java index 4833c12..962d995 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/DeploymentHandlerControllerTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/DeploymentHandlerControllerTest.java @@ -58,7 +58,7 @@ public class DeploymentHandlerControllerTest extends MockitoTestSuite { DeploymentHandlerClient restClient; @InjectMocks - DeploymentHandlerController subject = new DeploymentHandlerController(); + DeploymentHandlerController subject; protected final ObjectMapper objectMapper = new ObjectMapper(); @@ -91,14 +91,14 @@ public class DeploymentHandlerControllerTest extends MockitoTestSuite { public final void testPutDeployment_create() throws Exception { DeploymentRequestObject expectReq = new DeploymentRequestObject("dep1", "dep1", "create", null, "tenant1"); - + DeploymentResponseLinks expectLink = new DeploymentResponseLinks("self", "status"); DeploymentResponse expectResp = new DeploymentResponse("req1", expectLink); - + when(restClient.putDeployment(Matchers.anyString(), Matchers.anyString(), - Matchers.<DeploymentRequest>any(), Matchers.<HttpServletRequest>any()) ).thenReturn(expectResp).thenThrow(badReqError) - .thenThrow(srvcExistError).thenThrow(serverError).thenThrow(downStrmError) - .thenThrow(Exception.class); + Matchers.<DeploymentRequest>any(), Matchers.<HttpServletRequest>any())) + .thenReturn(expectResp).thenThrow(badReqError).thenThrow(srvcExistError) + .thenThrow(serverError).thenThrow(downStrmError).thenThrow(Exception.class); String actualResp = subject.putDeployment(mockedRequest, expectReq); assertTrue(actualResp.contains("req1")); @@ -123,8 +123,8 @@ public class DeploymentHandlerControllerTest extends MockitoTestSuite { public final void testDeleteDeployment() throws Exception { doNothing().doThrow(badReqError).doThrow(serverError).doThrow(downStrmError) - .doThrow(notFoundError).doThrow(Exception.class).when(restClient) - .deleteDeployment(Matchers.anyString(), Matchers.anyString(), Matchers.<HttpServletRequest>any()); + .doThrow(notFoundError).doThrow(Exception.class).when(restClient).deleteDeployment( + Matchers.anyString(), Matchers.anyString(), Matchers.<HttpServletRequest>any()); StringBuffer expectedStrBuff = new StringBuffer(); expectedStrBuff.append("http://oom.s2.com"); diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ECDSingleSignOnControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ECDSingleSignOnControllerTest.java index 771c085..f0c7102 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ECDSingleSignOnControllerTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/ECDSingleSignOnControllerTest.java @@ -34,7 +34,7 @@ import org.springframework.web.servlet.ModelAndView; public class ECDSingleSignOnControllerTest extends MockitoTestSuite { @InjectMocks - ECDSingleSignOnController subject = new ECDSingleSignOnController(); + ECDSingleSignOnController subject; @Before public void setUp() throws Exception { diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/HealthCheckControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/HealthCheckControllerTest.java index 4e44c39..dd245e4 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/HealthCheckControllerTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/HealthCheckControllerTest.java @@ -35,15 +35,17 @@ import org.onap.ccsdk.dashboard.core.MockitoTestSuite; import org.onap.ccsdk.dashboard.model.HealthStatus; import org.onap.portalsdk.core.util.SystemProperties; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; @RunWith(PowerMockRunner.class) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @PrepareForTest({SystemProperties.class}) public class HealthCheckControllerTest extends MockitoTestSuite { @InjectMocks - HealthCheckController subject = new HealthCheckController(); + HealthCheckController subject; @Before public void setUp() throws Exception { diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/InventoryControllerTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/InventoryControllerTest.java index 9cce55e..9a3f662 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/InventoryControllerTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/controller/InventoryControllerTest.java @@ -47,36 +47,31 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.ccsdk.dashboard.core.MockUser; import org.onap.ccsdk.dashboard.core.MockitoTestSuite; import org.onap.ccsdk.dashboard.exceptions.inventory.BlueprintParseException; -import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceNotFoundException; import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeNotFoundException; import org.onap.ccsdk.dashboard.model.cloudify.CloudifyDeployedTenant; -import org.onap.ccsdk.dashboard.model.inventory.Service; -import org.onap.ccsdk.dashboard.model.inventory.ServiceList; +import org.onap.ccsdk.dashboard.model.inventory.Blueprint; import org.onap.ccsdk.dashboard.model.inventory.ServiceQueryParams; import org.onap.ccsdk.dashboard.model.inventory.ServiceRef; import org.onap.ccsdk.dashboard.model.inventory.ServiceRefList; import org.onap.ccsdk.dashboard.model.inventory.ServiceType; import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeList; -import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeQueryParams; import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeRequest; import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeSummary; import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeSummaryList; import org.onap.ccsdk.dashboard.rest.CloudifyClient; import org.onap.ccsdk.dashboard.rest.InventoryClient; -import org.onap.ccsdk.dashboard.util.DashboardProperties; import org.onap.portalsdk.core.domain.User; import org.onap.portalsdk.core.util.CacheManager; -import org.onap.portalsdk.core.util.SystemProperties; import org.onap.portalsdk.core.web.support.AppUtils; import org.onap.portalsdk.core.web.support.UserUtils; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.http.HttpStatus; @@ -89,6 +84,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; @RunWith(PowerMockRunner.class) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) +@PrepareForTest({Blueprint.class}) public class InventoryControllerTest extends MockitoTestSuite { @Mock @@ -98,16 +95,13 @@ public class InventoryControllerTest extends MockitoTestSuite { private InventoryClient inventoryClient; @InjectMocks - private InventoryController subject = new InventoryController(); + private InventoryController subject; protected final ObjectMapper objectMapper = new ObjectMapper(); private HttpServerErrorException httpException = new HttpServerErrorException(HttpStatus.BAD_GATEWAY); - private ServiceNotFoundException serviceException = - new ServiceNotFoundException("Invalid deployment"); - private ServiceTypeNotFoundException serviceTypeException = new ServiceTypeNotFoundException("Invalid blueprint"); @@ -130,7 +124,7 @@ public class InventoryControllerTest extends MockitoTestSuite { ServiceType bpItemFull = null; ServiceTypeList bpItemFullList = null; - + ServiceTypeRequest bpUploadItem = null; @Before @@ -142,25 +136,27 @@ public class InventoryControllerTest extends MockitoTestSuite { mockedRequest = getMockedRequest(); mockedResponse = getMockedResponse(); CacheManager testCache = new CacheManager(); - Map<String, List<ServiceTypeSummary>> bpPerOwner = new HashMap<String, List<ServiceTypeSummary>>(); - bpPerOwner.put("xyz1731", (List<ServiceTypeSummary>)bpList2.items); + Map<String, List<ServiceTypeSummary>> bpPerOwner = + new HashMap<String, List<ServiceTypeSummary>>(); + bpPerOwner.put("xyz1731", (List<ServiceTypeSummary>) bpList2.items); testCache.putObject("owner_bp_map", bpPerOwner); - subject.setCacheManager(testCache); + subject.setCacheManager(testCache); /* - PowerMockito.mockStatic(SystemProperties.class); - Mockito - .when(SystemProperties.getProperty("cache_switch")) - .thenReturn("1"); - */ + * PowerMockito.mockStatic(SystemProperties.class); + * Mockito + * .when(SystemProperties.getProperty("cache_switch")) + * .thenReturn("1"); + */ + PowerMockito.mockStatic(Blueprint.class); } public void getExpectedBlueprints() throws JsonParseException, JsonMappingException, IOException { - bpItem = new ServiceTypeSummary.Builder().application("app1").component("comp1"). - typeName("xyz1731-helm-1906").owner("xyz1731").typeVersion(1906).build(); - - bpItem2 = new ServiceTypeSummary("xyz1731", "xyz1731-helm-1906", 1906, "app1", "comp1", "123-456-789", - "342343", true); + bpItem = new ServiceTypeSummary.Builder().application("app1").component("comp1") + .typeName("xyz1731-helm-1906").owner("xyz1731").typeVersion(1906).build(); + + bpItem2 = new ServiceTypeSummary("xyz1731", "xyz1731-helm-1906", 1906, "app1", "comp1", + "123-456-789", "342343", true); bpItemFull = new ServiceType.Builder("xyz1731", "xyz1731-helm-1906", 1906, "tosca_definitions_version: cloudify_dsl_1_3", "", "app1", "comp1").build(); @@ -169,7 +165,7 @@ public class InventoryControllerTest extends MockitoTestSuite { Collection<ServiceTypeSummary> items2 = new ArrayList<ServiceTypeSummary>(); items2.add(bpItem2); - + String pageLinks2 = "{\"previousLink\":null,\"nextLink\":{\"rel\":\"next\",\"href\":\"https://invt.com:30123/dcae-services/?offset=25\"}}"; ServiceTypeSummaryList.PaginationLinks paginationLinks = @@ -188,7 +184,7 @@ public class InventoryControllerTest extends MockitoTestSuite { } @Test - public final void testGetOwnersByPage() { + public final void testGetOwnersByPage() throws Exception { User user = mockUser.mockUser(); user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); @@ -199,9 +195,9 @@ public class InventoryControllerTest extends MockitoTestSuite { String result = subject.getServiceTypesByPage(mockedRequest); assertTrue(result.contains("xyz")); } - + @Test - public final void testGetAllServiceTypeNames() { + public final void testGetAllServiceTypeNames() throws Exception { User user = mockUser.mockUser(); user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); @@ -210,11 +206,11 @@ public class InventoryControllerTest extends MockitoTestSuite { Stream<ServiceTypeSummary> sampleStream1 = items.stream(); Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1); String result = subject.getAllServiceTypeNames(mockedRequest); - assertTrue(result.contains("xyz")); + assertTrue(result.contains("xyz")); } - + @Test - public final void testGetAllServiceTypeIds() { + public final void testGetAllServiceTypeIds() throws Exception { User user = mockUser.mockUser(); user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); @@ -223,15 +219,15 @@ public class InventoryControllerTest extends MockitoTestSuite { Stream<ServiceTypeSummary> sampleStream1 = items.stream(); Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1); String result = subject.getAllServiceTypeIds(mockedRequest); - assertTrue(result.contains("xyz")); + assertTrue(result.contains("xyz")); } - + @Test - public final void testGetServiceTypesByPage() { + public final void testGetServiceTypesByPage() throws Exception { User user = mockUser.mockUser(); user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); - //mockedRequest.addParameter("searchBy", "xyz"); + // mockedRequest.addParameter("searchBy", "xyz"); mockedRequest.addParameter("sortBy", "owner"); // # 1st case @@ -241,7 +237,7 @@ public class InventoryControllerTest extends MockitoTestSuite { Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream1); String result = subject.getServiceTypesByPage(mockedRequest); assertTrue(result.contains("xyz")); - + // # 2nd case HttpSession session = mockedRequest.getSession(); HashMap<String, Boolean> comp_deploy_tab = new HashMap<String, Boolean>(); @@ -253,19 +249,18 @@ public class InventoryControllerTest extends MockitoTestSuite { when(session.getAttribute("authComponents")).thenReturn(userApps); Stream<ServiceTypeSummary> sampleStream2 = items.stream(); - Mockito.when(inventoryClient.getServiceTypes()) - .thenReturn(sampleStream2); + Mockito.when(inventoryClient.getServiceTypes()).thenReturn(sampleStream2); /* - Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any())) - .thenReturn(sampleStream2); - */ + * Mockito.when(inventoryClient.getServiceTypes(Matchers.<ServiceTypeQueryParams>any())) + * .thenReturn(sampleStream2); + */ String result2 = subject.getServiceTypesByPage(mockedRequest); assertTrue(result2.contains("xyz")); } - + @Test - public final void testGetServiceTypesByPage_appDevUser() { + public final void testGetServiceTypesByPage_appDevUser() throws Exception { User user = mockUser.mockUser(); user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); @@ -286,9 +281,9 @@ public class InventoryControllerTest extends MockitoTestSuite { String result = subject.getServiceTypesByPage(mockedRequest); assertTrue(result.contains("xyz")); } - + @Test - public final void testGetServiceTypesByPage_containsFilter() { + public final void testGetServiceTypesByPage_containsFilter() throws Exception { User user = mockUser.mockUser(); user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); @@ -302,13 +297,14 @@ public class InventoryControllerTest extends MockitoTestSuite { String result = subject.getServiceTypesByPage(mockedRequest); assertTrue(result.contains("error")); } - + @Test - public final void testGetServiceTypesByPage_AllFilters() { + public final void testGetServiceTypesByPage_AllFilters() throws Exception { User user = mockUser.mockUser(); user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); - mockedRequest.addParameter("searchBy", "serviceRef:xyz1731-helm-1906;app:app1;comp:comp1;owner:xyz1731;"); + mockedRequest.addParameter("searchBy", + "serviceRef:xyz1731-helm-1906;app:app1;comp:comp1;owner:xyz1731;"); Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); Collection<ServiceTypeSummary> items = bpList.items; @@ -317,13 +313,13 @@ public class InventoryControllerTest extends MockitoTestSuite { String result = subject.getServiceTypesByPage(mockedRequest); assertTrue(result.contains("xyz")); - + } - + @Test - public final void testGetServiceTypesByPage_comp() { + public final void testGetServiceTypesByPage_comp() throws Exception { User user = mockUser.mockUser(); - user.setLoginId("tester"); + user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); mockedRequest.addParameter("sortBy", "component"); @@ -338,9 +334,9 @@ public class InventoryControllerTest extends MockitoTestSuite { } @Test - public final void testGetServiceTypesByPage_typeId() { + public final void testGetServiceTypesByPage_typeId() throws Exception { User user = mockUser.mockUser(); - user.setLoginId("tester"); + user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); mockedRequest.addParameter("sortBy", "typeId"); @@ -353,9 +349,9 @@ public class InventoryControllerTest extends MockitoTestSuite { } @Test - public final void testGetServiceTypesByPage_typeName() { + public final void testGetServiceTypesByPage_typeName() throws Exception { User user = mockUser.mockUser(); - user.setLoginId("tester"); + user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); mockedRequest.addParameter("sortBy", "typeName"); @@ -367,9 +363,9 @@ public class InventoryControllerTest extends MockitoTestSuite { } @Test - public final void testGetServiceTypesByPage_typeVer() { + public final void testGetServiceTypesByPage_typeVer() throws Exception { User user = mockUser.mockUser(); - user.setLoginId("tester"); + user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); mockedRequest.addParameter("sortBy", "typeVersion"); @@ -382,9 +378,9 @@ public class InventoryControllerTest extends MockitoTestSuite { } @Test - public final void testGetServiceTypesByPage_created() { + public final void testGetServiceTypesByPage_created() throws Exception { User user = mockUser.mockUser(); - user.setLoginId("tester"); + user.setLoginId("tester"); MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); Mockito.when(UserUtils.getUserSession(mockedRequest)).thenReturn(user); mockedRequest.addParameter("sortBy", "created"); @@ -396,10 +392,9 @@ public class InventoryControllerTest extends MockitoTestSuite { assertTrue(result.contains("xyz")); } - @SuppressWarnings("unchecked") @Test - public final void testGetServiceTypesByPage_Exception() { + public final void testGetServiceTypesByPage_Exception() throws Exception { when(inventoryClient.getServiceTypes()).thenThrow(RestClientException.class) .thenThrow(httpException); @@ -410,19 +405,14 @@ public class InventoryControllerTest extends MockitoTestSuite { assertTrue(errResp.contains("error")); } - - @SuppressWarnings("unchecked") @Test public final void testUploadServiceTypeBlueprint() throws Exception { MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); String expected = "{\"201\": \"OK\"}"; - when(inventoryClient.addServiceType(Matchers.<ServiceTypeRequest>any())) - .thenThrow(BlueprintParseException.class).thenThrow(httpException) - .thenThrow(Exception.class).thenReturn(null); - String actual1 = subject.uploadServiceTypeBlueprint(mockedRequest, bpUploadItem); - assertTrue(actual1.contains("error")); + when(inventoryClient.addServiceType(Mockito.<ServiceTypeRequest>any())) + .thenThrow(httpException).thenThrow(Exception.class).thenReturn(null); String actual2 = subject.uploadServiceTypeBlueprint(mockedRequest, bpUploadItem); assertTrue(actual2.contains("error")); @@ -437,15 +427,25 @@ public class InventoryControllerTest extends MockitoTestSuite { @SuppressWarnings("unchecked") @Test + public final void testUploadServiceTypeBlueprint_badBp() throws Exception { + MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); + + when(Blueprint.parse(bpUploadItem.getBlueprintTemplate())) + .thenThrow(BlueprintParseException.class); + + String actual1 = subject.uploadServiceTypeBlueprint(mockedRequest, bpUploadItem); + assertTrue(actual1.contains("error")); + + } + + @SuppressWarnings("unchecked") + @Test public final void testUpdateServiceTypeBlueprint() throws Exception { MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); String expected = "{\"201\": \"OK\"}"; - Mockito.when(inventoryClient.addServiceType(Matchers.<ServiceType>any())) - .thenThrow(BlueprintParseException.class).thenThrow(httpException) - .thenThrow(Exception.class).thenReturn(null); - String actual1 = subject.updateServiceTypeBlueprint(mockedRequest, bpItemFull); - assertTrue(actual1.contains("error")); + Mockito.when(inventoryClient.addServiceType(Mockito.<ServiceType>any())) + .thenThrow(httpException).thenThrow(Exception.class).thenReturn(null); String actual2 = subject.updateServiceTypeBlueprint(mockedRequest, bpItemFull); assertTrue(actual2.contains("error")); @@ -458,24 +458,36 @@ public class InventoryControllerTest extends MockitoTestSuite { } @Test + public final void testUpdateServiceTypeBlueprint_badBp() throws Exception { + MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); + + when(Blueprint.parse(bpUploadItem.getBlueprintTemplate())) + .thenThrow(BlueprintParseException.class); + + String actual1 = subject.updateServiceTypeBlueprint(mockedRequest, bpItemFull); + assertTrue(actual1.contains("error")); + + } + + @Test public final void testDeleteServiceType() throws Exception { - //String expected = "{\"202\": \"OK\"}"; + // String expected = "{\"202\": \"OK\"}"; String expected = "{\"204\": \"Blueprint deleted\"}"; List<CloudifyDeployedTenant> deplForBp = new ArrayList<>(); deplForBp.clear(); - Mockito.when(cfyClient.getDeploymentForBlueprint(Matchers.<String>any())) - .thenReturn(deplForBp); - + Mockito.when(cfyClient.getDeploymentForBlueprint(Mockito.anyString())) + .thenReturn(deplForBp); + List<ServiceRef> srvcRefList = new ArrayList<>(); srvcRefList.clear(); int itemCnt = 0; ServiceRefList mockSvcRefList = new ServiceRefList(srvcRefList, itemCnt); - Mockito.when(inventoryClient.getServicesForType(Matchers.<ServiceQueryParams>any())) + Mockito.when(inventoryClient.getServicesForType(Mockito.<ServiceQueryParams>any())) .thenReturn(mockSvcRefList); - + doNothing().doThrow(serviceTypeException).doThrow(Exception.class).when(inventoryClient) - .deleteServiceType(Matchers.anyString()); + .deleteServiceType(Mockito.anyString()); String actual = subject.deleteServiceType("srvcId", mockedRequest, mockedResponse); assertEquals(expected, actual); @@ -489,23 +501,23 @@ public class InventoryControllerTest extends MockitoTestSuite { @Test public final void testDeleteServiceType_withDepl() throws Exception { - CloudifyDeployedTenant mockCfyDeplTen = + CloudifyDeployedTenant mockCfyDeplTen = new CloudifyDeployedTenant("id1", "tenant", "45435435", "54543534"); - + List<CloudifyDeployedTenant> deplForBp = new ArrayList<>(); deplForBp.add(mockCfyDeplTen); - Mockito.when(cfyClient.getDeploymentForBlueprint(Matchers.<String>any())) - .thenReturn(deplForBp); - + Mockito.when(cfyClient.getDeploymentForBlueprint(Mockito.anyString())) + .thenReturn(deplForBp); + String actual = subject.deleteServiceType("srvcId", mockedRequest, mockedResponse); assertTrue(actual.contains("error")); } - + @SuppressWarnings("unchecked") @Test public final void testViewServiceTypeBlueprintContentById() throws Exception { Optional<ServiceType> expected = Optional.of(bpItemFull); - when(inventoryClient.getServiceType(Matchers.anyString())).thenReturn(expected) + when(inventoryClient.getServiceType(Mockito.anyString())).thenReturn(expected) .thenThrow(httpException).thenThrow(Exception.class); String result = subject.viewServiceTypeBlueprintContentById("typeId", mockedRequest); @@ -526,49 +538,10 @@ public class InventoryControllerTest extends MockitoTestSuite { expectedSrvcIds.add(expectedSrvc); ServiceRefList expectedSrvcRefList = new ServiceRefList(expectedSrvcIds, 1); - when(inventoryClient.getServicesForType(Matchers.<ServiceQueryParams>any())) + when(inventoryClient.getServicesForType(Mockito.<ServiceQueryParams>any())) .thenReturn(expectedSrvcRefList); String actual = subject.getServicesForType(mockedRequest, testTypeIds); assertTrue(actual.contains(testTypeIds[0])); } - /* - * @Test public final void testGetItemListForPageWrapper() { - * fail("Not yet implemented"); // TODO } - * - * @Test public final void testGetServicesForType() { - * fail("Not yet implemented"); // TODO } - * - * - * - * @Test public final void testViewServiceTypeBlueprintContentById() { - * fail("Not yet implemented"); // TODO } - * - * @Test public final void testDeleteServiceType() { - * fail("Not yet implemented"); // TODO } - * - * @Test public final void testDeleteService() { fail("Not yet implemented"); // - * TODO } - * - * @Test public final void testUpdateServiceTypeBlueprint() { - * fail("Not yet implemented"); // TODO } - * - * @Test public final void testUploadServiceTypeBlueprint() { - * fail("Not yet implemented"); // TODO } - * - * @Test public final void testGetAppProperties() { fail("Not yet implemented"); - * // TODO } - * - * @Test public final void testGetOrSetControllerEndpointSelectionLong() { - * fail("Not yet implemented"); // TODO } - * - * @Test public final void testGetOrSetControllerEndpointSelection() { - * fail("Not yet implemented"); // TODO } - * - * @Test public final void testGetInventoryClientHttpServletRequest() { - * fail("Not yet implemented"); // TODO } - * - * @Test public final void testGetInventoryClientLong() { - * fail("Not yet implemented"); // TODO } - */ } diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/BlueprintParseExceptionTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/BlueprintParseExceptionTest.java index c28bc42..0becbe0 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/BlueprintParseExceptionTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/BlueprintParseExceptionTest.java @@ -2,42 +2,41 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. - * - * Modifications Copyright (C) 2019 IBM. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2019 IBM. * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * ============LICENSE_END========================================================= * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ECOMP is a trademark and service mark of AT&T Intellectual Property. *******************************************************************************/ - package org.onap.ccsdk.dashboard.exceptions.inventory; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.Test; public class BlueprintParseExceptionTest { - @Test - public void TestException3() { - - BlueprintParseException mae = new BlueprintParseException(new Throwable()); - assertEquals("org.onap.ccsdk.dashboard.exceptions.inventory.BlueprintParseException", mae.getClass().getName()); - - } + @Test + public void TestException3() { + + BlueprintParseException mae = new BlueprintParseException(new Throwable()); + assertEquals("org.onap.ccsdk.dashboard.exceptions.inventory.BlueprintParseException", + mae.getClass().getName()); + } } diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceAlreadyDeactivatedExceptionTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceAlreadyDeactivatedExceptionTest.java index 95cccc7..66ba372 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceAlreadyDeactivatedExceptionTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceAlreadyDeactivatedExceptionTest.java @@ -2,39 +2,41 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. - * - * Modifications Copyright (C) 2019 IBM. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2019 IBM. * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * ============LICENSE_END========================================================= * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ECOMP is a trademark and service mark of AT&T Intellectual Property. *******************************************************************************/ package org.onap.ccsdk.dashboard.exceptions.inventory; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.Test; public class ServiceAlreadyDeactivatedExceptionTest { - @Test - public void TestException1() { - - ServiceAlreadyDeactivatedException sad = new ServiceAlreadyDeactivatedException("org.onap.ccsdk.dashboard.exceptions.inventory.ServiceAlreadyDeactivatedException"); - assertEquals(sad.getMessage(),"org.onap.ccsdk.dashboard.exceptions.inventory.ServiceAlreadyDeactivatedException"); - - } - + @Test + public void TestException1() { + + ServiceAlreadyDeactivatedException sad = new ServiceAlreadyDeactivatedException( + "org.onap.ccsdk.dashboard.exceptions.inventory.ServiceAlreadyDeactivatedException"); + assertEquals(sad.getMessage(), + "org.onap.ccsdk.dashboard.exceptions.inventory.ServiceAlreadyDeactivatedException"); + + } + } diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceNotFoundExceptionTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceNotFoundExceptionTest.java index ea9359b..39529fb 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceNotFoundExceptionTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceNotFoundExceptionTest.java @@ -2,38 +2,39 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. - * - * Modifications Copyright (C) 2019 IBM. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2019 IBM. * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * ============LICENSE_END========================================================= * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ECOMP is a trademark and service mark of AT&T Intellectual Property. *******************************************************************************/ package org.onap.ccsdk.dashboard.exceptions.inventory; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.Test; public class ServiceNotFoundExceptionTest { - @Test - public void TestException1() { - - ServiceNotFoundException sad = new ServiceNotFoundException(); - assertEquals("org.onap.ccsdk.dashboard.exceptions.inventory.ServiceNotFoundException", sad.getClass().getName()); - - } + @Test + public void TestException1() { + + ServiceNotFoundException sad = new ServiceNotFoundException(); + assertEquals("org.onap.ccsdk.dashboard.exceptions.inventory.ServiceNotFoundException", + sad.getClass().getName()); + + } } diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeActiveExceptionTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeActiveExceptionTest.java index 913c36c..72ee5fe 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeActiveExceptionTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeActiveExceptionTest.java @@ -2,28 +2,28 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. - * - * Modifications Copyright (C) 2019 IBM. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2019 IBM. * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * ============LICENSE_END========================================================= * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ECOMP is a trademark and service mark of AT&T Intellectual Property. *******************************************************************************/ package org.onap.ccsdk.dashboard.exceptions.inventory; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.Test; @@ -31,42 +31,41 @@ public class ServiceTypeActiveExceptionTest { @Test public void TestException1() { - - ServiceTypeActiveException sta = new ServiceTypeActiveException(); - assertEquals("org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException", sta.getClass().getName()); - + + ServiceTypeActiveException sta = new ServiceTypeActiveException(); + assertEquals("org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException", + sta.getClass().getName()); + } @Test public void TestException2() { - - ServiceTypeActiveException sta= new ServiceTypeActiveException("org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException"); - assertEquals(sta.getMessage(), "org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException"); - - } + ServiceTypeActiveException sta = new ServiceTypeActiveException( + "org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException"); + assertEquals(sta.getMessage(), + "org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException"); + + } @Test public void TestException3() { - - ServiceTypeActiveException sta= new ServiceTypeActiveException(new Throwable()); - assertEquals("org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException", sta.getClass().getName()); - - } - + ServiceTypeActiveException sta = new ServiceTypeActiveException(new Throwable()); + assertEquals("org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException", + sta.getClass().getName()); - @Test - public void TestException4() { - - ServiceTypeActiveException sta= new ServiceTypeActiveException("org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException", new Throwable()); - assertEquals("org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException",sta.getClass().getName()); - } - -} + @Test + public void TestException4() { - + ServiceTypeActiveException sta = new ServiceTypeActiveException( + "org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException", + new Throwable()); + assertEquals("org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException", + sta.getClass().getName()); + } +} diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeAlreadyDeactivatedExceptionTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeAlreadyDeactivatedExceptionTest.java index 0ec2cb5..5ebdf5e 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeAlreadyDeactivatedExceptionTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/exceptions/inventory/ServiceTypeAlreadyDeactivatedExceptionTest.java @@ -2,39 +2,42 @@ * =============LICENSE_START========================================================= * * ================================================================================= - * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. - * - * Modifications Copyright (C) 2019 IBM. + * Copyright (c) 2019 AT&T Intellectual Property. All rights reserved. + * + * Modifications Copyright (C) 2019 IBM. * ================================================================================ - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. * ============LICENSE_END========================================================= * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. + * ECOMP is a trademark and service mark of AT&T Intellectual Property. *******************************************************************************/ package org.onap.ccsdk.dashboard.exceptions.inventory; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.junit.Test; public class ServiceTypeAlreadyDeactivatedExceptionTest { - @Test - public void TestException3() { - - ServiceTypeAlreadyDeactivatedException mae = new ServiceTypeAlreadyDeactivatedException("org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeAlreadyDeactivatedException"); - assertEquals("org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeAlreadyDeactivatedException", mae.getClass().getName()); - - } + @Test + public void TestException3() { + + ServiceTypeAlreadyDeactivatedException mae = new ServiceTypeAlreadyDeactivatedException( + "org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeAlreadyDeactivatedException"); + assertEquals( + "org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeAlreadyDeactivatedException", + mae.getClass().getName()); + + } } diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImplTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImplTest.java index 68223da..a6f5038 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImplTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/CloudifyRestClientImplTest.java @@ -17,8 +17,8 @@ * limitations under the License. * ============LICENSE_END========================================================= * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. *******************************************************************************/ + package org.onap.ccsdk.dashboard.rest; import static org.hamcrest.CoreMatchers.is; @@ -27,6 +27,11 @@ import static org.junit.Assert.assertThat; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.ArgumentMatchers.contains; import java.io.IOException; import java.util.ArrayList; @@ -44,13 +49,12 @@ import org.junit.Before; import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; +import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; -import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.onap.ccsdk.dashboard.core.MockitoTestSuite; -import org.onap.ccsdk.dashboard.core.MockitoTestSuite.MockHttpServletRequestWrapper; import org.onap.ccsdk.dashboard.model.cloudify.CloudifyBlueprint; import org.onap.ccsdk.dashboard.model.cloudify.CloudifyBlueprintList; import org.onap.ccsdk.dashboard.model.cloudify.CloudifyDeployedTenant; @@ -60,6 +64,7 @@ import org.onap.ccsdk.dashboard.model.cloudify.CloudifyDeploymentList; import org.onap.ccsdk.dashboard.model.cloudify.CloudifyEvent; import org.onap.ccsdk.dashboard.model.cloudify.CloudifyEventList; import org.onap.ccsdk.dashboard.model.cloudify.CloudifyEventList.Metadata; +import org.onap.ccsdk.dashboard.model.consul.ConsulServiceHealth; import org.onap.ccsdk.dashboard.model.cloudify.CloudifyExecution; import org.onap.ccsdk.dashboard.model.cloudify.CloudifyExecutionList; import org.onap.ccsdk.dashboard.model.cloudify.CloudifyExecutionRequest; @@ -76,6 +81,7 @@ import org.onap.ccsdk.dashboard.model.cloudify.CloudifyTenantList; import org.onap.ccsdk.dashboard.util.DashboardProperties; import org.onap.portalsdk.core.util.CacheManager; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.core.ParameterizedTypeReference; @@ -83,6 +89,7 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.RestClientException; import org.springframework.web.client.RestTemplate; @@ -92,6 +99,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; @RunWith(PowerMockRunner.class) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @PrepareForTest({DashboardProperties.class}) public class CloudifyRestClientImplTest extends MockitoTestSuite { @@ -99,8 +107,8 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { RestTemplate mockRest; @InjectMocks - CloudifyRestClientImpl subject = new CloudifyRestClientImpl(); - + CloudifyRestClientImpl subject; + HttpServletRequest mockedRequest; HttpServletResponse mockedResponse; protected final static ObjectMapper objectMapper = new ObjectMapper(); @@ -113,13 +121,12 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { when(DashboardProperties.getControllerProperty("site.primary", DashboardProperties.SITE_SUBKEY_CLOUDIFY_URL)).thenReturn("https://orcl.com"); CacheManager testCache = new CacheManager(); - subject.setCacheManager(testCache); + subject.setCacheManager(testCache); this.subject.init(); } @Test - public final void getEventlogsTest() - throws JsonParseException, JsonMappingException, IOException { + public final void getEventlogsTest() throws HttpStatusCodeException, Exception { String executionId = "123a123a"; String tenant = "thisTenant"; List<CloudifyEvent> items = new ArrayList<CloudifyEvent>(); @@ -146,11 +153,8 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyEventList> response = new ResponseEntity<CloudifyEventList>(expected, HttpStatus.OK); - Mockito - .when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyEventList>>any())) - .thenReturn(response); + Mockito.when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyEventList>() {}))).thenReturn(response); CloudifyEventList actual = subject.getEventlogs(executionId, tenant); assertTrue(actual.items.size() == 2); @@ -158,7 +162,7 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { @Test public final void testGetTenants_GetData() { - // define the entity you want the exchange to return + // Given String tenantsList = "{\"items\": [{\"id\": 1, \"dName\": null, \"name\": \"default_tenant\"}, {\"id\": 2, \"dName\": null, \"name\": \"dyh1b1902\"}], \"metadata\": {\"pagination\": {\"total\": 2, \"offset\": 0, \"size\": 0}}}"; CloudifyTenantList sampleData = null; @@ -169,12 +173,12 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyTenantList> response = new ResponseEntity<CloudifyTenantList>(sampleData, HttpStatus.OK); - Mockito - .when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyTenantList>>any())) - .thenReturn(response); + // When + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<CloudifyTenantList>() {}))).thenReturn(response); + + // Then CloudifyTenantList res = subject.getTenants(); assertNotNull(res); assertThat(res.items.get(1).name, is("dyh1b1902")); @@ -183,17 +187,17 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { @SuppressWarnings("unchecked") @Test(expected = RestClientException.class) public final void testGetTenants_withException() { - // define the entity you want the exchange to return - Mockito - .when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyTenantList>>any())) - .thenThrow(RestClientException.class); + // When + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<CloudifyTenantList>() {}))) + .thenThrow(RestClientException.class); + + // Then subject.getTenants(); } @Test - public final void testGetNodeInstanceId() { + public final void testGetNodeInstanceId() throws HttpStatusCodeException, Exception { CloudifyNodeInstanceId cfyNodeInst = new CloudifyNodeInstanceId("node_instance_id1"); List<CloudifyNodeInstanceId> cfyNodeInstItems = new ArrayList<CloudifyNodeInstanceId>(); cfyNodeInstItems.add(cfyNodeInst); @@ -203,9 +207,8 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyNodeInstanceIdList> response = new ResponseEntity<CloudifyNodeInstanceIdList>(cfyNodeInstList, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyNodeInstanceIdList>>any())) + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyNodeInstanceIdList>() {}))) .thenReturn(response); CloudifyNodeInstanceIdList actualResult = @@ -214,7 +217,7 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { } @Test - public final void testGetNodeInstanceVersion() { + public final void testGetNodeInstanceVersion() throws HttpStatusCodeException, Exception { CloudifyNodeInstance cfyNodeInstance = new CloudifyNodeInstance("id1", null); List<CloudifyNodeInstance> cfyNodeInstanceItems = new ArrayList<CloudifyNodeInstance>(); @@ -225,9 +228,8 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyNodeInstanceList> response = new ResponseEntity<CloudifyNodeInstanceList>(cfyNodeInstList, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyNodeInstanceList>>any())) + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyNodeInstanceList>() {}))) .thenReturn(response); CloudifyNodeInstanceList actualResult = @@ -236,7 +238,8 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { } @Test - public final void testGetNodeInstanceVersion_blueprint() { + public final void testGetNodeInstanceVersion_blueprint() + throws HttpStatusCodeException, Exception { CloudifyNodeId cfyNodeId = new CloudifyNodeId("node_id"); List<CloudifyNodeId> cfyNodeIdItems = new ArrayList<CloudifyNodeId>(); cfyNodeIdItems.add(cfyNodeId); @@ -245,10 +248,6 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyNodeIdList> response1 = new ResponseEntity<CloudifyNodeIdList>(cfyNodeIdList, HttpStatus.OK); - when(mockRest.exchange(Matchers.contains("nodes"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyNodeIdList>>any())).thenReturn(response1); - CloudifyNodeInstance cfyNodeInstance = new CloudifyNodeInstance("id1", null); List<CloudifyNodeInstance> cfyNodeInstanceItems = new ArrayList<CloudifyNodeInstance>(); @@ -259,10 +258,14 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyNodeInstanceList> response2 = new ResponseEntity<CloudifyNodeInstanceList>(cfyNodeInstList, HttpStatus.OK); - when(mockRest.exchange(Matchers.contains("node-instances"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyNodeInstanceList>>any())) - .thenReturn(response2); + + when(mockRest.exchange(contains("nodes"), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyNodeIdList>() {}))).thenReturn(response1); + + when( + mockRest.exchange(contains("node-instances"), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyNodeInstanceList>() {}))) + .thenReturn(response2); CloudifyNodeInstanceList actualResult = subject.getNodeInstanceVersion("blueprintId", "tenant"); @@ -270,7 +273,7 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { } @Test - public final void testGetNodeInstanceId_blueprint() { + public final void testGetNodeInstanceId_blueprint() throws HttpStatusCodeException, Exception { CloudifyNodeId cfyNodeId = new CloudifyNodeId("node_id"); List<CloudifyNodeId> cfyNodeIdItems = new ArrayList<CloudifyNodeId>(); cfyNodeIdItems.add(cfyNodeId); @@ -279,9 +282,8 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyNodeIdList> response1 = new ResponseEntity<CloudifyNodeIdList>(cfyNodeIdList, HttpStatus.OK); - when(mockRest.exchange(Matchers.contains("nodes"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyNodeIdList>>any())).thenReturn(response1); + when(mockRest.exchange(contains("nodes"), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyNodeIdList>() {}))).thenReturn(response1); CloudifyNodeInstanceId cfyNodeInst = new CloudifyNodeInstanceId("node_instance_id1"); List<CloudifyNodeInstanceId> cfyNodeInstItems = new ArrayList<CloudifyNodeInstanceId>(); @@ -292,20 +294,19 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyNodeInstanceIdList> response = new ResponseEntity<CloudifyNodeInstanceIdList>(cfyNodeInstList, HttpStatus.OK); - when(mockRest.exchange(Matchers.contains("node-instances"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyNodeInstanceIdList>>any())) - .thenReturn(response); + when( + mockRest.exchange(contains("node-instances"), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyNodeInstanceIdList>() {}))) + .thenReturn(response); CloudifyNodeInstanceIdList actualResult = subject.getNodeInstanceId("bpId", "tenant"); assertTrue(actualResult.items.get(0).id.equals("node_instance_id1")); } @Test - public void testGetExecutions() { - CloudifyExecution cldExecution = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, - "bp1", "id1","tenant1", "error", "execution_id1", null); + public void testGetExecutions() throws Exception { + CloudifyExecution cldExecution = new CloudifyExecution("successful", "created_at", + "ended_at", "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>(); @@ -317,20 +318,17 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyExecutionList> response = new ResponseEntity<CloudifyExecutionList>(cloudifyExecutionList, HttpStatus.OK); - when(mockRest.exchange(Matchers.contains("deployment_id"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyExecutionList>>any())) - .thenReturn(response); + when(mockRest.exchange(contains("deployment_id"), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyExecutionList>() {}))).thenReturn(response); CloudifyExecutionList actualResult = subject.getExecutions("deploymentId1", "tenant1"); assertTrue(actualResult.items.get(0).id.contains("id1")); } @Test - public void testGetExecutionsSummary() { - CloudifyExecution cldExecution = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); + public void testGetExecutionsSummary() throws HttpStatusCodeException, Exception { + CloudifyExecution cldExecution = new CloudifyExecution("successful", "created_at", + "ended_at", "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>(); @@ -342,10 +340,8 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyExecutionList> response = new ResponseEntity<CloudifyExecutionList>(cloudifyExecutionList, HttpStatus.OK); - when(mockRest.exchange(Matchers.contains("include"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyExecutionList>>any())) - .thenReturn(response); + when(mockRest.exchange(contains("include"), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyExecutionList>() {}))).thenReturn(response); CloudifyExecutionList actualResult = subject.getExecutionsSummary("deploymentId1", "tenant1"); @@ -353,9 +349,9 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { } @Test - public void testStartExecution() { - CloudifyExecution cfyExecObj = new CloudifyExecution("successful", "created_at", "ended-at", "install", - false, "bp1", "id1", "tenant1", "error", "execution_id1", null); + public void testStartExecution() throws HttpStatusCodeException, Exception { + CloudifyExecution cfyExecObj = new CloudifyExecution("successful", "created_at", "ended-at", + "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); Map<String, Object> params = new HashMap<String, Object>(); params.put("key1", "value1"); @@ -363,18 +359,16 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { CloudifyExecutionRequest cfyExecReq = new CloudifyExecutionRequest("deployment_id", "upgrade", false, false, "tenant1", params); - when(mockRest.postForObject(Matchers.anyString(), Matchers.<HttpEntity<?>>any(), - Matchers.<Class<CloudifyExecution>>any())).thenReturn(cfyExecObj); + when(mockRest.postForObject(anyString(), any(), any())).thenReturn(cfyExecObj); CloudifyExecution actualResult = subject.startExecution(cfyExecReq); assertTrue(actualResult.status.equals("successful")); } @Test - @Ignore - public void testCancelExecution() { - CloudifyExecution cfyExecObj = new CloudifyExecution("successful", "created_at", "end_at", "install", - false, "bp1", "id1", "tenant1", "error", "execution_id1", null); + public void testCancelExecution() throws HttpStatusCodeException, Exception { + CloudifyExecution cfyExecObj = new CloudifyExecution("successful", "created_at", "end_at", + "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); Map<String, Object> params = new HashMap<String, Object>(); params.put("key1", "value1"); @@ -382,9 +376,8 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyExecution> response = new ResponseEntity<CloudifyExecution>(cfyExecObj, HttpStatus.OK); - when(mockRest.exchange(Matchers.contains("executions"), Matchers.eq(HttpMethod.POST), - Matchers.<HttpEntity<?>>any(), Matchers.<Class<CloudifyExecution>>any())) - .thenReturn(response); + when(mockRest.exchange(contains("executions"), eq(HttpMethod.POST), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyExecution>() {}))).thenReturn(response); Map<String, String> parameters = new HashMap<String, String>(); parameters.put("key1", "value1"); @@ -395,7 +388,7 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { } @Test - public void testGetBlueprint() { + public void testGetBlueprint() throws HttpStatusCodeException, Exception { CloudifyBlueprint cldBp = new CloudifyBlueprint("file1", "description1", "343242", "3423423", "id1", null); @@ -412,9 +405,8 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyBlueprintList> response = new ResponseEntity<CloudifyBlueprintList>(cldBpList, HttpStatus.OK); - doReturn(response).when(mockRest).exchange(Matchers.anyString(), - Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyBlueprintList>>any()); + doReturn(response).when(mockRest).exchange(anyString(), eq(HttpMethod.GET), + any(HttpEntity.class), eq(new ParameterizedTypeReference<CloudifyBlueprintList>() {})); CloudifyBlueprintList actualResult = subject.getBlueprint("id1", "tenant1"); assertTrue(actualResult.items.get(0).id.equals("id1")); @@ -437,14 +429,13 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyDeploymentList> response = new ResponseEntity<CloudifyDeploymentList>(cldDeployList, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<CloudifyDeploymentList>>any())) - .thenReturn(response); - + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyDeploymentList>() {}))).thenReturn(response); + CloudifyDeploymentList actualResult = subject.getDeployments("tenant", 10, 0); assertTrue(actualResult.items.get(0).id.equals("id")); } - + @Test public void testGetDeployments_from_cache() { CloudifyDeployment cldDeployment = new CloudifyDeployment("description", "blueprint_id", @@ -462,41 +453,41 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyDeploymentList> response = new ResponseEntity<CloudifyDeploymentList>(cldDeployList, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<CloudifyDeploymentList>>any())) - .thenReturn(response); - + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyDeploymentList>() {}))).thenReturn(response); + List<CloudifyDeployment> actualResult = subject.getDeployments("tenant", 10, 0, true, true); assertTrue(actualResult.get(0).id.equals("id")); } - + @Test public void testGetDeploymentForBlueprint() { - CloudifyDeployedTenant cfyDepTenant = + CloudifyDeployedTenant cfyDepTenant = new CloudifyDeployedTenant("id", "tenant", "created_at", "updated_at"); List<CloudifyDeployedTenant> cfyDepTenantList = new ArrayList<>(); cfyDepTenantList.add(cfyDepTenant); - + CloudifyDeployedTenantList.Metadata.Pagination pageObj = new CloudifyDeployedTenantList.Metadata.Pagination(1, 0, 1); - CloudifyDeployedTenantList.Metadata metadata = new CloudifyDeployedTenantList.Metadata(pageObj); + CloudifyDeployedTenantList.Metadata metadata = + new CloudifyDeployedTenantList.Metadata(pageObj); - CloudifyDeployedTenantList cldDeployList = new CloudifyDeployedTenantList(cfyDepTenantList, metadata); + CloudifyDeployedTenantList cldDeployList = + new CloudifyDeployedTenantList(cfyDepTenantList, metadata); ResponseEntity<CloudifyDeployedTenantList> response = new ResponseEntity<CloudifyDeployedTenantList>(cldDeployList, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyDeployedTenantList>>any())) + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<CloudifyDeployedTenantList>() {}))) .thenReturn(response); - + List<CloudifyDeployedTenant> actuals = subject.getDeploymentForBlueprint("bpId"); assertTrue(actuals.get(0).id.equals("id")); } - + @Test - public void testGetDeploymentResource() { + public void testGetDeploymentResource() { CloudifyDeployment cldDeployment = new CloudifyDeployment("description", "blueprint_id", "created_at", "updated_at", "id", null, null, null, null, null, null, null, "tenant"); @@ -512,16 +503,15 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyDeploymentList> response = new ResponseEntity<CloudifyDeploymentList>(cldDeployList, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<CloudifyDeploymentList>>any())) - .thenReturn(response); + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyDeploymentList>() {}))).thenReturn(response); - CloudifyDeployment actualResult = subject.getDeploymentResource("id", "tenant"); + CloudifyDeployment actualResult = subject.getDeploymentResource("id", "tenant"); assertTrue(actualResult.id.equals("id")); } - + @Test - public void testGetNodeInstanceDetails() { + public void testGetNodeInstanceDetails() throws HttpStatusCodeException, Exception { CloudifyNodeInstance cfyNodeInstance = new CloudifyNodeInstance("id1", null); List<CloudifyNodeInstance> cfyNodeInstanceItems = new ArrayList<CloudifyNodeInstance>(); @@ -532,18 +522,18 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyNodeInstanceList> response2 = new ResponseEntity<CloudifyNodeInstanceList>(cfyNodeInstList, HttpStatus.OK); - when(mockRest.exchange(Matchers.contains("node-instances"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyNodeInstanceList>>any())) - .thenReturn(response2); - - CloudifyNodeInstanceList actualResult = - subject.getNodeInstanceDetails("id", "tenant"); + + when( + mockRest.exchange(contains("node-instances"), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyNodeInstanceList>() {}))) + .thenReturn(response2); + + CloudifyNodeInstanceList actualResult = subject.getNodeInstanceDetails("id", "tenant"); assertTrue(actualResult.items.get(0).id.equals("id1")); } - + @Test - public void testGetNodeInstances() { + public void testGetNodeInstances() throws HttpStatusCodeException, Exception { CloudifyNodeInstanceId cfyNodeInstance = new CloudifyNodeInstanceId("id1"); List<CloudifyNodeInstanceId> cfyNodeInstanceItems = new ArrayList<CloudifyNodeInstanceId>(); @@ -554,22 +544,20 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyNodeInstanceIdList> response2 = new ResponseEntity<CloudifyNodeInstanceIdList>(cfyNodeInstList, HttpStatus.OK); - when(mockRest.exchange(Matchers.contains("node-instances"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyNodeInstanceIdList>>any())) - .thenReturn(response2); - - CloudifyNodeInstanceIdList actualResult = - subject.getNodeInstances("id", "tenant"); + + when( + mockRest.exchange(contains("node-instances"), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyNodeInstanceIdList>() {}))) + .thenReturn(response2); + + CloudifyNodeInstanceIdList actualResult = subject.getNodeInstances("id", "tenant"); assertTrue(actualResult.items.get(0).id.equals("id1")); } - - - @Test - public void testGetExecutionsSummaryPerTenant() { - CloudifyExecution cldExecution = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); + + @Test + public void testGetExecutionsSummaryPerTenant() throws HttpStatusCodeException, Exception { + CloudifyExecution cldExecution = new CloudifyExecution("successful", "created_at", + "ended_at", "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>(); @@ -581,36 +569,31 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyExecutionList> response = new ResponseEntity<CloudifyExecutionList>(cloudifyExecutionList, HttpStatus.OK); - when(mockRest.exchange(Matchers.contains("include"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyExecutionList>>any())) - .thenReturn(response); + when(mockRest.exchange(contains("include"), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyExecutionList>() {}))).thenReturn(response); - CloudifyExecutionList actualResult = - subject.getExecutionsSummaryPerTenant("tenant1"); + CloudifyExecutionList actualResult = subject.getExecutionsSummaryPerTenant("tenant1"); assertTrue(actualResult.items.get(0).id.contains("id1")); } - + @Test - public void testGetExecutionIdSummary() { - CloudifyExecution cldExecution = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); + public void testGetExecutionIdSummary() throws HttpStatusCodeException, Exception { + CloudifyExecution cldExecution = new CloudifyExecution("successful", "created_at", + "ended_at", "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); ResponseEntity<CloudifyExecution> response = new ResponseEntity<CloudifyExecution>(cldExecution, HttpStatus.OK); - when(mockRest.exchange(Matchers.contains("include"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyExecution>>any())) - .thenReturn(response); + + when(mockRest.exchange(contains("include"), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyExecution>() {}))).thenReturn(response); + CloudifyExecution actuals = subject.getExecutionIdSummary("execution_id1", "tenant"); assertTrue(actuals.id.contains("execution_id1")); } - + @Test public void testGetInstallExecutionSummary() { - CloudifyExecution cldExecution = - new CloudifyExecution("successful", "created_at", "ended_at", "install", false, "bp1", "id1", - "tenant1", "error", "execution_id1", null); + CloudifyExecution cldExecution = new CloudifyExecution("successful", "created_at", + "ended_at", "install", false, "bp1", "id1", "tenant1", "error", "execution_id1", null); List<CloudifyExecution> cldExecutionList = new ArrayList<CloudifyExecution>(); @@ -622,43 +605,39 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyExecutionList> response = new ResponseEntity<CloudifyExecutionList>(cloudifyExecutionList, HttpStatus.OK); - when(mockRest.exchange(Matchers.contains("include"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyExecutionList>>any())) - .thenReturn(response); + when(mockRest.exchange(contains("include"), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyExecutionList>() {}))).thenReturn(response); - CloudifyExecutionList actualResult = - subject.getInstallExecutionSummary("id1", "tenant1"); + CloudifyExecutionList actualResult = subject.getInstallExecutionSummary("id1", "tenant1"); assertTrue(actualResult.items.get(0).id.contains("id1")); } - + @Test - public void testViewBlueprint() { - byte[] outArr = "Any String you want".getBytes(); - ResponseEntity<byte[]> response = - new ResponseEntity<byte[]>(outArr, HttpStatus.OK); - - doReturn(response).when(mockRest).exchange(Matchers.anyString(), - Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(), - Matchers.<Class<?>>any()); - + public void testViewBlueprint() throws HttpStatusCodeException, Exception { + byte[] outArr = "Any String you want".getBytes(); + ResponseEntity<byte[]> response = new ResponseEntity<byte[]>(outArr, HttpStatus.OK); + + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + ArgumentMatchers.any(Class.class))).thenReturn(response); + + /* + * doReturn(response).when(mockRest).exchange(Matchers.anyString(), + * Matchers.eq(HttpMethod.GET), Matchers.<HttpEntity<?>>any(), + * Matchers.<Class<?>>any()); + */ + subject.viewBlueprint("tenant1", "id1"); } - + @Test public void testGetDeploymentNamesWithFilter() throws Exception { MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); - //mockedRequest.addParameter("filters", filterStr); - //mockedRequest.addParameter("sort", "name"); Set<String> userRoleSet = new HashSet<String>(); Set<String> userApps = new TreeSet<>(); userRoleSet.add("Standard User"); userRoleSet.add("ECOMPC_DCAE_WRITE"); userApps.add("dcae"); - - Mockito.when(mockedRequest.getAttribute("userRoles")).thenReturn(userRoleSet); - Mockito.when(mockedRequest.getAttribute("userApps")).thenReturn(userApps); - + String tenantsList = "{\"items\": [{\"id\": 1, \"dName\": null, \"name\": \"default_tenant\"}, {\"id\": 2, \"dName\": null, \"name\": \"dyh1b1902\"}], \"metadata\": {\"pagination\": {\"total\": 2, \"offset\": 0, \"size\": 0}}}"; CloudifyTenantList sampleData = null; @@ -670,7 +649,6 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyTenantList> response1 = new ResponseEntity<CloudifyTenantList>(sampleData, HttpStatus.OK); - CloudifyDeployment cldDeployment = new CloudifyDeployment("description", "blueprint_id", "created_at", "updated_at", "id", null, null, null, null, null, null, null, "tenant"); @@ -686,34 +664,34 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyDeploymentList> response2 = new ResponseEntity<CloudifyDeploymentList>(cldDeployList, HttpStatus.OK); - Mockito - .when(mockRest.exchange(Matchers.contains("tenants"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyTenantList>>any())) - .thenReturn(response1); + // When + when(mockedRequest.getAttribute("userRoles")).thenReturn(userRoleSet); + when(mockedRequest.getAttribute("userApps")).thenReturn(userApps); + + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<CloudifyTenantList>() {}))).thenReturn(response1); + + when(mockRest.exchange(contains("deployments"), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyDeploymentList>() {}))).thenReturn(response2); - Mockito.when(mockRest.exchange(Matchers.contains("deployments"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<CloudifyDeploymentList>>any())) - .thenReturn(response2); - List<String> actual = subject.getDeploymentNamesWithFilter(mockedRequest); assertTrue(actual.size() > 0); } - + @Test public void testGetDeploymentsWithFilter() throws Exception { MockHttpServletRequestWrapper mockedRequest = getMockedRequest(); - //mockedRequest.addParameter("filters", filterStr); - //mockedRequest.addParameter("sort", "name"); + // mockedRequest.addParameter("filters", filterStr); + // mockedRequest.addParameter("sort", "name"); Set<String> userRoleSet = new HashSet<String>(); Set<String> userApps = new TreeSet<>(); userRoleSet.add("Standard User"); userRoleSet.add("ECOMPC_DCAE_WRITE"); userApps.add("dcae"); - + Mockito.when(mockedRequest.getAttribute("userRoles")).thenReturn(userRoleSet); Mockito.when(mockedRequest.getAttribute("userApps")).thenReturn(userApps); - + String tenantsList = "{\"items\": [{\"id\": 1, \"dName\": null, \"name\": \"default_tenant\"}, {\"id\": 2, \"dName\": null, \"name\": \"dyh1b1902\"}], \"metadata\": {\"pagination\": {\"total\": 2, \"offset\": 0, \"size\": 0}}}"; CloudifyTenantList sampleData = null; @@ -725,7 +703,6 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyTenantList> response1 = new ResponseEntity<CloudifyTenantList>(sampleData, HttpStatus.OK); - CloudifyDeployment cldDeployment = new CloudifyDeployment("description", "blueprint_id", "created_at", "updated_at", "id", null, null, null, null, null, null, null, "tenant"); @@ -741,54 +718,47 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyDeploymentList> response2 = new ResponseEntity<CloudifyDeploymentList>(cldDeployList, HttpStatus.OK); - Mockito - .when(mockRest.exchange(Matchers.contains("tenants"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyTenantList>>any())) - .thenReturn(response1); + when(mockRest.exchange(contains("tenants"), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<CloudifyTenantList>() {}))).thenReturn(response1); + + when(mockRest.exchange(contains("deployments"), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyDeploymentList>() {}))).thenReturn(response2); - Mockito.when(mockRest.exchange(Matchers.contains("deployments"), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<CloudifyDeploymentList>>any())) - .thenReturn(response2); - List<CloudifyDeployment> actuals = subject.getDeploymentsWithFilter(mockedRequest); assertTrue(actuals.size() > 0); } - + @Test public void testGetSecret() { String secretTokenStr = - "{\"created_at\": \"created_ts\", \"key\": \"acl_key\", \"updated_at\": \"updated_ts\", \"value\": \"acl_token_val\", \"visibility\": \"global\", \"is_hidden_value\": \"false\", \"tenant_name\": \"tenant\", \"resource_availability\": \"rsrc\"}"; + "{\"created_at\": \"created_ts\", \"key\": \"acl_key\", \"updated_at\": \"updated_ts\", \"value\": \"acl_token_val\", \"visibility\": \"global\", \"is_hidden_value\": \"false\", \"tenant_name\": \"tenant\", \"resource_availability\": \"rsrc\"}"; CloudifySecret sampleData = null; try { sampleData = objectMapper.readValue(secretTokenStr, CloudifySecret.class); } catch (Exception e) { - + } - + ResponseEntity<CloudifySecret> response = new ResponseEntity<CloudifySecret>(sampleData, HttpStatus.OK); - - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifySecret>>any())) - .thenReturn(response); - + + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifySecret>() {}))).thenReturn(response); + CloudifySecret actuals = subject.getSecret("acl_key", "tenant"); assertTrue(actuals.getKey().equals("acl_key")); } - + @Test - public void testDeleteBlueprint() { - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyBlueprint>>any())).thenReturn(null); + public void testDeleteBlueprint() throws HttpStatusCodeException, Exception { + when(mockRest.exchange(anyString(), eq(HttpMethod.DELETE), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyBlueprint>() {}))).thenReturn(null); subject.deleteBlueprint("bp", "tenant"); } - + @Test - public void testGetPlugins() { - CloudifyPlugin sampleData = + public void testGetPlugins() throws HttpStatusCodeException, Exception { + CloudifyPlugin sampleData = new CloudifyPlugin("plugin1", "202001", "linux", "linux_k8s_plugin", "20200801"); List<CloudifyPlugin> cfyPlugins = new ArrayList<CloudifyPlugin>(); @@ -801,18 +771,16 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { CloudifyPluginList cfyPluginList = new CloudifyPluginList(cfyPlugins, metadata); ResponseEntity<CloudifyPluginList> response = new ResponseEntity<CloudifyPluginList>(cfyPluginList, HttpStatus.OK); - - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifyPluginList>>any())) - .thenReturn(response); - + + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<CloudifyPluginList>() {}))).thenReturn(response); + CloudifyPluginList actuals = subject.getPlugins(); assertTrue(actuals.items.get(0).package_name.equals("plugin1")); } - + @Test - public void testGetDeploymentInputs() { + public void testGetDeploymentInputs() throws HttpStatusCodeException, Exception { CloudifyDeployment cldDeployment = new CloudifyDeployment("description", "blueprint_id", "created_at", "updated_at", "id", null, null, null, null, null, null, null, "tenant"); @@ -828,14 +796,64 @@ public class CloudifyRestClientImplTest extends MockitoTestSuite { ResponseEntity<CloudifyDeploymentList> response = new ResponseEntity<CloudifyDeploymentList>(cldDeployList, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<CloudifyDeploymentList>>any())) - .thenReturn(response); - + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyDeploymentList>() {}))).thenReturn(response); + CloudifyDeploymentList actualResult = subject.getDeploymentInputs("id", "tenant"); assertTrue(actualResult.items.get(0).id.equals("id")); } - -} + @Test + public void testGetDeployment_noTenant() throws HttpStatusCodeException, Exception { + // Given + CloudifyDeployment cldDeployment = new CloudifyDeployment("description", "blueprint_id", + "created_at", "updated_at", "id", null, null, null, null, null, null, null, "tenant"); + List<CloudifyDeployment> cfyDeployItems = new ArrayList<CloudifyDeployment>(); + cfyDeployItems.add(cldDeployment); + + CloudifyDeploymentList.Metadata.Pagination pageObj = + new CloudifyDeploymentList.Metadata.Pagination(1, 0, 1); + CloudifyDeploymentList.Metadata metadata = new CloudifyDeploymentList.Metadata(pageObj); + + CloudifyDeploymentList cldDeployList = new CloudifyDeploymentList(cfyDeployItems, metadata); + + ResponseEntity<CloudifyDeploymentList> response = + new ResponseEntity<CloudifyDeploymentList>(cldDeployList, HttpStatus.OK); + + // When + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<CloudifyDeploymentList>() {}))).thenReturn(response); + + // Then + CloudifyDeploymentList actualResult = subject.getDeployment("id"); + assertTrue(actualResult.items.get(0).id.equals("id")); + } + + @Test + public void testGetDeployment() throws HttpStatusCodeException, Exception { + // Given + CloudifyDeployment cldDeployment = new CloudifyDeployment("description", "blueprint_id", + "created_at", "updated_at", "id", null, null, null, null, null, null, null, "tenant"); + + List<CloudifyDeployment> cfyDeployItems = new ArrayList<CloudifyDeployment>(); + cfyDeployItems.add(cldDeployment); + + CloudifyDeploymentList.Metadata.Pagination pageObj = + new CloudifyDeploymentList.Metadata.Pagination(1, 0, 1); + CloudifyDeploymentList.Metadata metadata = new CloudifyDeploymentList.Metadata(pageObj); + + CloudifyDeploymentList cldDeployList = new CloudifyDeploymentList(cfyDeployItems, metadata); + + ResponseEntity<CloudifyDeploymentList> response = + new ResponseEntity<CloudifyDeploymentList>(cldDeployList, HttpStatus.OK); + + // When + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<CloudifyDeploymentList>() {}))).thenReturn(response); + + // Then + CloudifyDeploymentList actualResult = subject.getDeployment("id", "tenant"); + assertTrue(actualResult.items.get(0).id.equals("id")); + } +} diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/ConsulRestClientImplTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/ConsulRestClientImplTest.java index 7d85196..306fc1d 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/ConsulRestClientImplTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/ConsulRestClientImplTest.java @@ -17,13 +17,16 @@ * limitations under the License. * ============LICENSE_END========================================================= * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. *******************************************************************************/ package org.onap.ccsdk.dashboard.rest; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.ArgumentMatchers.eq; import java.net.MalformedURLException; import java.net.URL; @@ -38,7 +41,6 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.InjectMocks; -import org.mockito.Matchers; import org.mockito.Mock; import org.mockito.MockitoAnnotations; import org.onap.ccsdk.dashboard.model.cloudify.CloudifySecret; @@ -47,8 +49,10 @@ import org.onap.ccsdk.dashboard.model.consul.ConsulDeploymentHealth; import org.onap.ccsdk.dashboard.model.consul.ConsulNodeInfo; import org.onap.ccsdk.dashboard.model.consul.ConsulServiceHealth; import org.onap.ccsdk.dashboard.model.consul.ConsulServiceInfo; +import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeSummaryList; import org.onap.ccsdk.dashboard.util.DashboardProperties; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.core.ParameterizedTypeReference; @@ -57,33 +61,34 @@ import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.RestTemplate; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; @RunWith(PowerMockRunner.class) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @PrepareForTest({DashboardProperties.class}) public class ConsulRestClientImplTest { @Mock RestTemplate mockRest; - + @InjectMocks ConsulRestClientImpl subject; - String[] svcTags = {"cfytenantname=onap"}; - + String[] svcTags = {"cfytenantname=onap"}; + protected final static ObjectMapper objectMapper = new ObjectMapper(); static HttpClientErrorException httpException; - @BeforeClass public static void setUpBeforeClass() throws Exception { httpException = new HttpClientErrorException(HttpStatus.FORBIDDEN, "statusText"); - objectMapper.registerModule(new Jdk8Module()); + objectMapper.registerModule(new Jdk8Module()); } - + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); @@ -91,12 +96,12 @@ public class ConsulRestClientImplTest { when(DashboardProperties.getControllerProperty("site.primary", DashboardProperties.SITE_SUBKEY_CONSUL_URL)).thenReturn("https://cnsl-svc.com"); when(DashboardProperties.getControllerProperty("site.primary", - DashboardProperties.SITE_SUBKEY_CLOUDIFY_URL)).thenReturn("https://orcl-svc.com"); + DashboardProperties.SITE_SUBKEY_CLOUDIFY_URL)).thenReturn("https://orcl-svc.com"); when(DashboardProperties.getControllerProperty("site.primary", - DashboardProperties.SITE_SUBKEY_CLOUDIFY_USERNAME)).thenReturn("admin"); + DashboardProperties.SITE_SUBKEY_CLOUDIFY_USERNAME)).thenReturn("admin"); when(DashboardProperties.getControllerProperty("site.primary", - DashboardProperties.SITE_SUBKEY_CLOUDIFY_PASS)).thenReturn("admin"); - subject.setConsul_acl_token("consul_acl_token_for_dash"); + DashboardProperties.SITE_SUBKEY_CLOUDIFY_PASS)).thenReturn("admin"); + subject.setConsulAclToken("consul_acl_token_for_dash"); subject.init(); } @@ -107,20 +112,19 @@ public class ConsulRestClientImplTest { @Test public final void testGetConsulAcl() { String secretTokenStr = - "{\"created_at\": \"created_ts\", \"key\": \"acl_key\", \"updated_at\": \"updated_ts\", \"value\": \"acl_token_val\", \"visibility\": \"global\", \"is_hidden_value\": \"false\", \"tenant_name\": \"tenant\", \"resource_availability\": \"rsrc\"}"; + "{\"created_at\": \"created_ts\", \"key\": \"acl_key\", \"updated_at\": \"updated_ts\", \"value\": \"acl_token_val\", \"visibility\": \"global\", \"is_hidden_value\": \"false\", \"tenant_name\": \"tenant\", \"resource_availability\": \"rsrc\"}"; CloudifySecret sampleData = null; try { sampleData = objectMapper.readValue(secretTokenStr, CloudifySecret.class); } catch (Exception e) { } - + ResponseEntity<CloudifySecret> response = new ResponseEntity<CloudifySecret>(sampleData, HttpStatus.OK); - - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<CloudifySecret>>any())) - .thenReturn(response); + + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<CloudifySecret>() {}))).thenReturn(response); + String actualSecretStr = subject.getConsulAcl(mockRest); assertTrue(actualSecretStr.equals("acl_token_val")); } @@ -128,7 +132,7 @@ public class ConsulRestClientImplTest { @Test(expected = Exception.class) public final void testCreateCfyRestTemplate() throws Exception { String webapiUrl = DashboardProperties.getControllerProperty("site.primary", - DashboardProperties.SITE_SUBKEY_CLOUDIFY_URL); + DashboardProperties.SITE_SUBKEY_CLOUDIFY_URL); String user = DashboardProperties.getControllerProperty("site.primary", DashboardProperties.SITE_SUBKEY_CLOUDIFY_USERNAME); String pass = DashboardProperties.getControllerProperty("site.primary", @@ -143,25 +147,23 @@ public class ConsulRestClientImplTest { String urlScheme = webapiUrl.split(":")[0]; subject.createCfyRestTemplate(url, user, pass, urlScheme); } - + @Test - public final void testGetServiceHealth() { + public final void testGetServiceHealth() throws Exception { ConsulServiceHealth consulSrvcHlth = new ConsulServiceHealth("cjlvmcnsl00", "service:pgaas1_Service_ID", "Service 'pgaasServer1' check", "passing", - "This is a pgaas1_Service_ID health check", - "OK Output:", - "pgaas1_Service_ID", "pgaasServer1", svcTags, 34234, 4234); + "This is a pgaas1_Service_ID health check", "OK Output:", "pgaas1_Service_ID", + "pgaasServer1", svcTags, 34234, 4234); - // new ConsulServiceHealth() + // new ConsulServiceHealth() List<ConsulServiceHealth> expectedCnslSrvcHlth = new ArrayList<ConsulServiceHealth>(); expectedCnslSrvcHlth.add(consulSrvcHlth); ResponseEntity<List<ConsulServiceHealth>> response = new ResponseEntity<List<ConsulServiceHealth>>(expectedCnslSrvcHlth, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<List<ConsulServiceHealth>>>any())) + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<List<ConsulServiceHealth>>() {}))) .thenReturn(response); List<ConsulServiceHealth> actualCnslSrvcHlth = subject.getServiceHealth("dc1", "srvc1"); @@ -169,26 +171,23 @@ public class ConsulRestClientImplTest { } @Test(expected = Exception.class) - public final void get_svc_health_rest_client_exception() { - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<List<ConsulServiceHealth>>>any())) + public final void get_svc_health_rest_client_exception() throws Exception { + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<List<ConsulServiceHealth>>() {}))) .thenThrow(httpException); - - subject.getServiceHealth("dc1", "srvc1"); + + subject.getServiceHealth("dc1", "srvc1"); } - + @Test(expected = Exception.class) - public final void get_services_rest_client_exception() { - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<Map<String, Object>>>any())) - .thenThrow(httpException); + public final void get_services_rest_client_exception() throws Exception { + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<Map<String, Object>>() {}))).thenThrow(httpException); subject.getServices("dc1"); } - + @Test - public final void testGetServices() { + public final void testGetServices() throws Exception { List<String> srvcIps = new ArrayList<String>(); srvcIps.add("135.91.224.136"); srvcIps.add("135.91.224.138"); @@ -196,23 +195,22 @@ public class ConsulRestClientImplTest { Map<String, Object> respObj = new HashMap<String, Object>(); respObj.put("pgaasServer1", srvcIps); - + List<ConsulServiceInfo> expectedCnslSrvcs = new ArrayList<ConsulServiceInfo>(); expectedCnslSrvcs.add(consulSrvcInfo); - ResponseEntity<Map<String, Object>> response = - new ResponseEntity<Map<String,Object>>(respObj, HttpStatus.OK); - - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<Map<String, Object>>>any())).thenReturn(response); + ResponseEntity<Map<String, Object>> response = + new ResponseEntity<Map<String, Object>>(respObj, HttpStatus.OK); + + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<Map<String, Object>>() {}))).thenReturn(response); List<ConsulServiceInfo> actualSvcList = subject.getServices("dc1"); assertTrue(actualSvcList.get(0).name.equals("pgaasServer1")); } @Test - public final void testGetNodes() { + public final void testGetNodes() throws Exception { ConsulNodeInfo cnslNode = new ConsulNodeInfo("a2788806-6e2e-423e-8ee7-6cad6f3d3de6", "cjlvmcnsl00", "10.170.8.13", null, null, 6, 17980); @@ -222,9 +220,8 @@ public class ConsulRestClientImplTest { ResponseEntity<List<ConsulNodeInfo>> response = new ResponseEntity<List<ConsulNodeInfo>>(cnslNodeList, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<List<ConsulNodeInfo>>>any())).thenReturn(response); + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<List<ConsulNodeInfo>>() {}))).thenReturn(response); List<ConsulNodeInfo> actualNodeList = subject.getNodes("dc1"); assertTrue(actualNodeList.get(0).node.equals("cjlvmcnsl00")); @@ -232,16 +229,15 @@ public class ConsulRestClientImplTest { } @Test(expected = Exception.class) - public final void get_nodes_rest_client_exception() { - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<List<ConsulNodeInfo>>>any())) - .thenThrow(httpException); + public final void get_nodes_rest_client_exception() throws Exception { + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<List<ConsulNodeInfo>>() {}))) + .thenThrow(httpException); subject.getNodes("dc1"); } - + @Test - public final void testGetNodeServicesHealth() { + public final void testGetNodeServicesHealth() throws Exception { ConsulServiceHealth consulSrvcHlth = new ConsulServiceHealth("cjlvmcnsl00", "service:pgaas1_Service_ID", "Service 'pgaasServer1' check", "passing", "This is a pgaas1_Service_ID health check", @@ -254,9 +250,8 @@ public class ConsulRestClientImplTest { ResponseEntity<List<ConsulServiceHealth>> response = new ResponseEntity<List<ConsulServiceHealth>>(expectedCnslSrvcHlth, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<List<ConsulServiceHealth>>>any())) + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<List<ConsulServiceHealth>>() {}))) .thenReturn(response); List<ConsulServiceHealth> actualNodeHlthList = @@ -265,14 +260,13 @@ public class ConsulRestClientImplTest { } @Test(expected = Exception.class) - public final void get_node_svc_rest_client_exception() { - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<List<ConsulServiceHealth>>>any())) - .thenThrow(httpException); + public final void get_node_svc_rest_client_exception() throws Exception { + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<List<ConsulServiceHealth>>() {}))) + .thenThrow(httpException); subject.getNodeServicesHealth("dc1", "nodeId1"); } - + @Test public final void testGetDatacenters() { ConsulDatacenter cnslDc = new ConsulDatacenter("dc1"); @@ -285,24 +279,22 @@ public class ConsulRestClientImplTest { ResponseEntity<List<String>> response = new ResponseEntity<List<String>>(dcItems, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<List<String>>>any())).thenReturn(response); + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<List<String>>() {}))).thenReturn(response); List<ConsulDatacenter> actualDcList = subject.getDatacenters(); assertTrue(actualDcList.get(0).name.equals("dc1")); } @Test(expected = Exception.class) public final void get_dc_rest_client_exception() { - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<List<String>>>any())) - .thenThrow(httpException); + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<List<String>>() {}))).thenThrow(httpException); subject.getDatacenters(); } - + @Test - public final void testGetServiceHealthByDeploymentId() { + public final void testGetServiceHealthByDeploymentId() + throws HttpStatusCodeException, Exception { ConsulServiceHealth consulSrvcHlth = new ConsulServiceHealth("cjlvmcnsl00", "service:pgaas1_Service_ID", "Service 'pgaasServer1' check", "passing", "This is a pgaas1_Service_ID health check", @@ -315,22 +307,21 @@ public class ConsulRestClientImplTest { ResponseEntity<List<ConsulServiceHealth>> response = new ResponseEntity<List<ConsulServiceHealth>>(expectedCnslSrvcHlth, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<List<ConsulServiceHealth>>>any())) + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<List<ConsulServiceHealth>>() {}))) .thenReturn(response); ConsulDeploymentHealth cdh = subject.getServiceHealthByDeploymentId("deploymentId"); assertTrue(cdh.getNode().equals("cjlvmcnsl00")); } - + @Test(expected = Exception.class) - public final void get_svc_health_by_depId_rest_client_exception() { - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<List<ConsulServiceHealth>>>any())) - .thenThrow(httpException); + public final void get_svc_health_by_depId_rest_client_exception() + throws HttpStatusCodeException, Exception { + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), any(HttpEntity.class), + eq(new ParameterizedTypeReference<List<ConsulServiceHealth>>() {}))) + .thenThrow(httpException); subject.getServiceHealthByDeploymentId("deploymentId"); } - + } diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClientImplTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClientImplTest.java index 2024d72..035b005 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClientImplTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/DeploymentHandlerClientImplTest.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. *******************************************************************************/ package org.onap.ccsdk.dashboard.rest; @@ -51,6 +50,7 @@ import org.onap.ccsdk.dashboard.model.deploymenthandler.DeploymentsListResponse; import org.onap.ccsdk.dashboard.util.DashboardProperties; import org.onap.portalsdk.core.util.CacheManager; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.core.ParameterizedTypeReference; @@ -63,6 +63,7 @@ import org.springframework.web.client.HttpServerErrorException; import org.springframework.web.client.RestTemplate; @RunWith(PowerMockRunner.class) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @PrepareForTest({DashboardProperties.class}) public class DeploymentHandlerClientImplTest { @@ -71,7 +72,7 @@ public class DeploymentHandlerClientImplTest { @Mock CloudifyClient cfyClient; - + @InjectMocks DeploymentHandlerClientImpl subject; @@ -82,7 +83,7 @@ public class DeploymentHandlerClientImplTest { when(DashboardProperties.getControllerProperty("site.primary", DashboardProperties.SITE_SUBKEY_DHANDLER_URL)).thenReturn("https://dplh.com"); CacheManager testCache = new CacheManager(); - subject.setCacheManager(testCache); + subject.setCacheManager(testCache); this.subject.init(); } @@ -93,14 +94,12 @@ public class DeploymentHandlerClientImplTest { @Test public final void testCheckHealth() { String expectStr = "DH mS health check"; - ResponseEntity<String> response = - new ResponseEntity<String>(expectStr, HttpStatus.OK); - + ResponseEntity<String> response = new ResponseEntity<String>(expectStr, HttpStatus.OK); + when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<String>>any())).thenReturn(response) - .thenReturn(response); - + Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<String>>any())) + .thenReturn(response).thenReturn(response); + String actualStr = subject.checkHealth(); assertTrue(actualStr.equals(expectStr)); } @@ -241,11 +240,12 @@ public class DeploymentHandlerClientImplTest { Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<DeploymentResponse>>any())).thenReturn(response); - CloudifyDeployment cfyDepl = - new CloudifyDeployment("description", "blueprint_id", "created_at", "updated_at", - "id", null, null, null, null, null, null, null, "tenant_name"); + CloudifyDeployment cfyDepl = + new CloudifyDeployment("description", "blueprint_id", "created_at", "updated_at", "id", + null, null, null, null, null, null, null, "tenant_name"); - when(cfyClient.getDeploymentResource(Matchers.anyString(), Matchers.anyString())).thenReturn(cfyDepl); + when(cfyClient.getDeploymentResource(Matchers.anyString(), Matchers.anyString())) + .thenReturn(cfyDepl); subject.deleteDeployment("deploymentId", "tenant"); } diff --git a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientImplTest.java b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientImplTest.java index e0452d0..192946e 100644 --- a/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientImplTest.java +++ b/ccsdk-app-common/src/test/java/org/onap/ccsdk/dashboard/rest/RestInventoryClientImplTest.java @@ -17,7 +17,6 @@ * limitations under the License. * ============LICENSE_END========================================================= * - * ECOMP is a trademark and service mark of AT&T Intellectual Property. *******************************************************************************/ package org.onap.ccsdk.dashboard.rest; @@ -26,6 +25,10 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; import static org.mockito.Mockito.when; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.anyString; +import static org.mockito.ArgumentMatchers.isNull; +import static org.mockito.ArgumentMatchers.eq; import java.io.IOException; import java.util.ArrayList; @@ -44,7 +47,9 @@ import org.junit.runner.RunWith; import org.mockito.InjectMocks; import org.mockito.Matchers; import org.mockito.Mock; +import org.mockito.Mockito; import org.mockito.MockitoAnnotations; +import org.onap.ccsdk.dashboard.exceptions.inventory.ServiceTypeActiveException; import org.onap.ccsdk.dashboard.model.inventory.ApiResponseMessage; import org.onap.ccsdk.dashboard.model.inventory.Service; import org.onap.ccsdk.dashboard.model.inventory.ServiceList; @@ -61,6 +66,7 @@ import org.onap.ccsdk.dashboard.model.inventory.ServiceTypeSummaryList; import org.onap.ccsdk.dashboard.util.DashboardProperties; import org.onap.portalsdk.core.util.CacheManager; import org.powermock.api.mockito.PowerMockito; +import org.powermock.core.classloader.annotations.PowerMockIgnore; import org.powermock.core.classloader.annotations.PrepareForTest; import org.powermock.modules.junit4.PowerMockRunner; import org.springframework.core.ParameterizedTypeReference; @@ -68,6 +74,8 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpMethod; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; +import org.springframework.web.client.HttpClientErrorException; +import org.springframework.web.client.HttpStatusCodeException; import org.springframework.web.client.RestTemplate; import com.fasterxml.jackson.core.JsonParseException; @@ -76,6 +84,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.datatype.jdk8.Jdk8Module; @RunWith(PowerMockRunner.class) +@PowerMockIgnore({"com.sun.org.apache.xerces.*", "javax.xml.*", "org.xml.*", "javax.management.*"}) @PrepareForTest({DashboardProperties.class}) public class RestInventoryClientImplTest { @@ -83,7 +92,7 @@ public class RestInventoryClientImplTest { RestTemplate mockRest; @InjectMocks - RestInventoryClientImpl subject = new RestInventoryClientImpl(); + RestInventoryClientImpl subject; protected final ObjectMapper objectMapper = new ObjectMapper(); @@ -96,11 +105,13 @@ public class RestInventoryClientImplTest { ServiceType bpItemFull = null; ServiceTypeList bpItemFullList = null; - + ServiceTypeSummaryList bpListNext = null; ServiceTypeRequest bpUploadItem = null; + HttpClientErrorException httpException = new HttpClientErrorException(HttpStatus.GONE, "gone"); + @Before public void setUp() throws Exception { MockitoAnnotations.initMocks(this); @@ -111,7 +122,7 @@ public class RestInventoryClientImplTest { when(DashboardProperties.getControllerProperty("site.primary", DashboardProperties.SITE_SUBKEY_INVENTORY_URL)).thenReturn("https://invt.com"); CacheManager testCache = new CacheManager(); - subject.setCacheManager(testCache); + subject.setCacheManager(testCache); this.subject.init(); } @@ -126,12 +137,8 @@ public class RestInventoryClientImplTest { Collection<Service> items = new ArrayList<Service>(); items.add(deplItem); - String pageLinks = - "{\"previousLink\":null,\"nextLink\":{\"rel\":\"next\",\"href\":\"https://invt.com:30123/dcae-services/?offset=25\"}}"; String pageLinks2 = "{\"previousLink\":null,\"nextLink\":null}"; - ServiceList.PaginationLinks paginationLinks = - objectMapper.readValue(pageLinks, ServiceList.PaginationLinks.class); ServiceList.PaginationLinks paginationLinks2 = objectMapper.readValue(pageLinks2, ServiceList.PaginationLinks.class); @@ -139,23 +146,23 @@ public class RestInventoryClientImplTest { deplList = new ServiceList(items, totalCount, paginationLinks2); deplListNext = new ServiceList(items, totalCount, paginationLinks2); } - + public void getExpectedBlueprints() throws JsonParseException, JsonMappingException, IOException { - - bpItem = new ServiceTypeSummary.Builder().application("app1").component("comp1"). - typeName("xyz1731-helm-1906").owner("xyz1731").typeVersion(1906).build(); - - bpItem2 = new ServiceTypeSummary("xyz1731", "xyz1731-helm-1906", 1906, "app1", "comp1", "123-456-789", - "342343", true); + + bpItem = new ServiceTypeSummary.Builder().application("app1").component("comp1") + .typeName("xyz1731-helm-1906").owner("xyz1731").typeVersion(1906).build(); + + bpItem2 = new ServiceTypeSummary("xyz1731", "xyz1731-helm-1906", 1906, "app1", "comp1", + "123-456-789", "342343", true); bpItemFull = new ServiceType.Builder("xyz1731", "xyz1731-helm-1906", 1906, "tosca_definitions_version: cloudify_dsl_1_3", "", "app1", "comp1").build(); Collection<ServiceTypeSummary> items = new ArrayList<ServiceTypeSummary>(); items.add(bpItem); Collection<ServiceTypeSummary> items2 = new ArrayList<ServiceTypeSummary>(); - items2.add(bpItem2); - + items2.add(bpItem2); + String pageLinks = "{\"previousLink\":null,\"nextLink\":{\"rel\":\"next\",\"href\":\"https://invt.com:30123/dcae-service-types/?offset=25\"}}"; String pageLinks2 = "{\"previousLink\":null,\"nextLink\":null}"; @@ -170,23 +177,21 @@ public class RestInventoryClientImplTest { bpListNext = new ServiceTypeSummaryList(items, totalCount, paginationLinks2); } + @SuppressWarnings("unchecked") @Test public final void testCheckHealth() { String expectStr = "Inventory mS health check"; - ResponseEntity<String> response = - new ResponseEntity<String>(expectStr, HttpStatus.OK); - - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<String>>any())).thenReturn(response) - .thenReturn(response); - + ResponseEntity<String> response = new ResponseEntity<String>(expectStr, HttpStatus.OK); + + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<String>() {}))).thenReturn(response); + String actualStr = subject.checkHealth(); assertTrue(actualStr.equals(expectStr)); } @Test - public final void testGetServiceTypes() { + public final void testGetServiceTypes() throws Exception { Collection<ServiceTypeSummary> items = bpList.items; Stream<ServiceTypeSummary> expectedResult = items.stream(); @@ -196,9 +201,8 @@ public class RestInventoryClientImplTest { ResponseEntity<ServiceTypeSummaryList> response2 = new ResponseEntity<ServiceTypeSummaryList>(bpListNext, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<ServiceTypeSummaryList>>any())).thenReturn(response) + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<ServiceTypeSummaryList>() {}))).thenReturn(response) .thenReturn(response2); Stream<ServiceTypeSummary> actualResult = subject.getServiceTypes(); @@ -214,14 +218,13 @@ public class RestInventoryClientImplTest { ResponseEntity<ServiceTypeSummaryList> response2 = new ResponseEntity<ServiceTypeSummaryList>(bpListNext, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<ServiceTypeSummaryList>>any())).thenReturn(response) + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<ServiceTypeSummaryList>() {}))).thenReturn(response) .thenReturn(response2); - + subject.cacheServiceTypes(); } - + @Test public final void testGetServiceTypesServiceTypeQueryParams() { ServiceTypeQueryParams qryParms = new ServiceTypeQueryParams.Builder() @@ -237,9 +240,8 @@ public class RestInventoryClientImplTest { ResponseEntity<ServiceTypeSummaryList> response2 = new ResponseEntity<ServiceTypeSummaryList>(bpListNext, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<ServiceTypeSummaryList>>any())).thenReturn(response) + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<ServiceTypeSummaryList>() {}))).thenReturn(response) .thenReturn(response2); Stream<ServiceTypeSummary> actualResult = subject.getServiceTypes(qryParms); @@ -248,22 +250,27 @@ public class RestInventoryClientImplTest { } @Test - public final void testGetServiceType() { + public final void testGetServiceType() throws HttpStatusCodeException, Exception { + + // Given Optional<ServiceType> expectedResult = Optional.of(bpItemFull); ResponseEntity<ServiceType> response = new ResponseEntity<ServiceType>(bpItemFull, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<ServiceType>>any())) - .thenReturn(response); + // When + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<ServiceType>() {}))).thenReturn(response); + // Then Optional<ServiceType> actualResult = subject.getServiceType("432432423"); assertTrue(expectedResult.get().getTypeName().equals(actualResult.get().getTypeName())); } @Test public final void testGetServicesForType() throws Exception { + + // Given String typeId = "44234234"; ServiceRef expectedSrvc = new ServiceRef("dcae_dtiapi_1902", "432423", "433434"); Collection<ServiceRef> expectedSrvcIds = new ArrayList<ServiceRef>(); @@ -272,78 +279,80 @@ public class RestInventoryClientImplTest { ResponseEntity<ServiceList> response = new ResponseEntity<ServiceList>(deplList, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), Matchers.<ParameterizedTypeReference<ServiceList>>any())) - .thenReturn(response); - + // When + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<ServiceList>() {}))).thenReturn(response); + + // Then ServiceQueryParams qryParams = new ServiceQueryParams.Builder().typeId(typeId).build(); ServiceRefList actualSvcRefList = subject.getServicesForType(qryParams); - assertTrue(actualSvcRefList.totalCount == expectedSvcRefList.totalCount); + assertTrue(actualSvcRefList.totalCount == expectedSvcRefList.totalCount); } - - @Test - public final void testAddServiceTypeServiceType() { - - when(mockRest.postForObject(Matchers.anyString(), Matchers.<HttpEntity<?>>any(), - Matchers.<Class<ServiceType>>any())).thenReturn(bpItemFull); - - ResponseEntity<ServiceTypeSummaryList> response = - new ResponseEntity<ServiceTypeSummaryList>(bpList, HttpStatus.OK); + @Test + public final void testAddServiceType() throws ServiceTypeActiveException, Exception { + // Given ResponseEntity<ServiceTypeSummaryList> response2 = new ResponseEntity<ServiceTypeSummaryList>(bpListNext, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<ServiceTypeSummaryList>>any())).thenReturn(response) - .thenReturn(response2); - + // When + when(mockRest.postForObject(anyString(), any(ServiceTypeRequest.class), + eq(ServiceType.class))).thenReturn(bpItemFull); + + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<ServiceTypeSummaryList>() {}))).thenReturn(response2); + + // Then ServiceType actualResult = subject.addServiceType(bpItemFull); assertTrue(actualResult.getTypeName().contains("xyz")); } @Test - public final void testAddServiceTypeServiceTypeRequest() { + public final void testAddServiceTypeServiceTypeRequest() + throws ServiceTypeActiveException, Exception { + // Given ServiceTypeRequest srvcReq = ServiceTypeRequest.from(bpItemFull); - when(mockRest.postForObject(Matchers.anyString(), Matchers.<HttpEntity<?>>any(), - Matchers.<Class<ServiceType>>any())).thenReturn(bpItemFull); - ResponseEntity<ServiceTypeSummaryList> response = new ResponseEntity<ServiceTypeSummaryList>(bpList, HttpStatus.OK); ResponseEntity<ServiceTypeSummaryList> response2 = new ResponseEntity<ServiceTypeSummaryList>(bpListNext, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<ServiceTypeSummaryList>>any())).thenReturn(response) - .thenReturn(response2); + // When + when(mockRest.postForObject(anyString(), any(ServiceTypeRequest.class), + eq(ServiceType.class))).thenReturn(bpItemFull); + + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<ServiceTypeSummaryList>() {}))).thenReturn(response2); + + // Then ServiceType actualResult = subject.addServiceType(srvcReq); assertTrue(actualResult.getTypeName().contains("xyz")); } @Test public final void testDeleteServiceType() throws Exception { + // Given ResponseEntity<ApiResponseMessage> response = new ResponseEntity<ApiResponseMessage>(HttpStatus.OK); - - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.DELETE), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<ApiResponseMessage>>any())).thenReturn(response); - ResponseEntity<ServiceTypeSummaryList> response1 = new ResponseEntity<ServiceTypeSummaryList>(bpList, HttpStatus.OK); - ResponseEntity<ServiceTypeSummaryList> response2 = new ResponseEntity<ServiceTypeSummaryList>(bpListNext, HttpStatus.OK); - when(mockRest.exchange(Matchers.anyString(), Matchers.eq(HttpMethod.GET), - Matchers.<HttpEntity<?>>any(), - Matchers.<ParameterizedTypeReference<ServiceTypeSummaryList>>any())).thenReturn(response1) + // When + when(mockRest.exchange(anyString(), eq(HttpMethod.DELETE), isNull(), + eq(new ParameterizedTypeReference<ApiResponseMessage>() {}))).thenReturn(response); + // .thenThrow(httpException); + + when(mockRest.exchange(anyString(), eq(HttpMethod.GET), isNull(), + eq(new ParameterizedTypeReference<ServiceTypeSummaryList>() {}))).thenReturn(response1) .thenReturn(response2); - + + // Then subject.deleteServiceType("4243234"); + // subject.deleteServiceType("4243234"); } } |