diff options
Diffstat (limited to 'mso-api-handlers/mso-api-handler-infra/src/test/java')
2 files changed, 71 insertions, 0 deletions
diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java index f1d5a5487f..d1e5dc717e 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/MsoRequestTest.java @@ -22,6 +22,7 @@ package org.onap.so.apihandlerinfra; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.mockito.Mockito.doReturn; import java.io.IOException; import java.io.StringReader; import java.nio.file.Files; @@ -34,12 +35,19 @@ import javax.ws.rs.core.Response; import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import org.apache.http.HttpStatus; +import org.junit.Before; import org.junit.ClassRule; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.aai.domain.yang.Service; +import org.onap.aai.domain.yang.Tenant; import org.onap.so.apihandler.common.ErrorNumbers; +import org.onap.so.apihandlerinfra.infra.rest.AAIDataRetrieval; import org.onap.so.exceptions.ValidationException; import org.onap.so.serviceinstancebeans.ServiceInstancesRequest; import org.springframework.test.context.junit4.rules.SpringClassRule; @@ -75,6 +83,17 @@ public class MsoRequestTest extends BaseTest { @Rule public ExpectedException thrown = ExpectedException.none(); + @Mock + private AAIDataRetrieval aaiDataRet; + + @InjectMocks + private MsoRequest msoRequestMock; + + @Before + public void setUp() { + MockitoAnnotations.initMocks(this); + } + public String inputStream(String JsonInput) throws IOException { JsonInput = "src/test/resources/MsoRequestTest" + JsonInput; String input = new String(Files.readAllBytes(Paths.get(JsonInput))); @@ -1056,5 +1075,37 @@ public class MsoRequestTest extends BaseTest { assertNotNull(result); } + @Test + public void getTenantNameFromAAITest() throws Exception { + this.sir = mapper.readValue(inputStream("/SuccessfulValidation/ServiceAssign.json"), + ServiceInstancesRequest.class); + String tenantId = "88a6ca3ee0394ade9403f075db23167e"; + String tenantNameFromAAI = "testTenantName"; + String cloudRegion = "mdt1"; + String cloudOwner = "cloudOwner"; + this.sir.getRequestDetails().getCloudConfiguration().setCloudOwner(cloudOwner); + Tenant tenant = new Tenant(); + tenant.setTenantId(tenantId); + tenant.setTenantName(tenantNameFromAAI); + doReturn(tenant).when(aaiDataRet).getTenant(cloudOwner, cloudRegion, tenantId); + String tenantName = msoRequestMock.getTenantNameFromAAI(this.sir); + assertEquals(tenantNameFromAAI, tenantName); + } + + + @Test + public void getProductFamilyNameFromAAITest() throws Exception { + this.sir = mapper.readValue(inputStream("/SuccessfulValidation/ServiceAssign.json"), + ServiceInstancesRequest.class); + String serviceId = "a9a77d5a-123e-4ca2-9eb9-0b015d2ee0fb"; + String serviceDescription = "testServiceDescription"; + Service service = new Service(); + service.setServiceId(serviceId); + service.setServiceDescription(serviceDescription); + doReturn(service).when(aaiDataRet).getService(serviceId); + String productFamilyName = msoRequestMock.getProductFamilyNameFromAAI(this.sir); + assertEquals(serviceDescription, productFamilyName); + } + } diff --git a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java index f566628ee3..1332ffd913 100644 --- a/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java +++ b/mso-api-handlers/mso-api-handler-infra/src/test/java/org/onap/so/apihandlerinfra/ServiceInstancesTest.java @@ -441,6 +441,10 @@ public class ServiceInstancesTest extends BaseTest { .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlMatching(".*/service/search/.*")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK))); @@ -483,6 +487,10 @@ public class ServiceInstancesTest extends BaseTest { .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlMatching(".*/service/search/.*")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK))); @@ -524,6 +532,10 @@ public class ServiceInstancesTest extends BaseTest { .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlMatching(".*/service/search/.*")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK))); @@ -1939,6 +1951,10 @@ public class ServiceInstancesTest extends BaseTest { .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK))); @@ -2114,6 +2130,10 @@ public class ServiceInstancesTest extends BaseTest { .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(defaultService)).withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlMatching(".*/service-design-and-creation/services/service/.*")) + .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) + .withBodyFile("/aai/ServiceFromAAI.json").withStatus(HttpStatus.SC_OK))); + wireMockServer.stubFor(get(urlMatching(".*/serviceRecipe/search.*")) .willReturn(aResponse().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON) .withBody(mapper.writeValueAsString(serviceRecipe)).withStatus(HttpStatus.SC_OK))); |