X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=asdc-controller%2Fsrc%2Ftest%2Fjava%2Forg%2Fonap%2Fso%2Fasdc%2Fclient%2Ftest%2Frest%2FASDCRestInterfaceTest.java;h=2e5ad13c216ce314b39a01d33d097af4d691aa2c;hb=8b56e8d08070785152ba7c97e9a1878fa3652722;hp=947da4f492bf81ce49635bed89477c61fddbd297;hpb=3690db02a3035306d6be5fae7529a2f27b90ee71;p=so.git diff --git a/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java b/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java index 947da4f492..2e5ad13c21 100644 --- a/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java +++ b/asdc-controller/src/test/java/org/onap/so/asdc/client/test/rest/ASDCRestInterfaceTest.java @@ -27,14 +27,11 @@ import static com.shazam.shazamcrest.MatcherAssert.assertThat; import static com.shazam.shazamcrest.matcher.Matchers.sameBeanAs; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; - import java.io.File; import java.util.HashSet; import java.util.Set; - import javax.transaction.Transactional; import javax.ws.rs.core.Response; - import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -45,6 +42,7 @@ import org.onap.so.asdc.client.test.emulators.DistributionClientEmulator; import org.onap.so.asdc.client.test.emulators.NotificationDataImpl; import org.onap.so.db.catalog.beans.AllottedResource; import org.onap.so.db.catalog.beans.AllottedResourceCustomization; +import org.onap.so.db.catalog.beans.Service; import org.onap.so.db.catalog.data.repository.AllottedResourceRepository; import org.onap.so.db.catalog.data.repository.NetworkResourceRepository; import org.onap.so.db.catalog.data.repository.ServiceRepository; @@ -55,105 +53,139 @@ import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; - import com.fasterxml.jackson.databind.ObjectMapper; public class ASDCRestInterfaceTest extends BaseTest { - @Autowired - private AllottedResourceRepository allottedRepo; - - @Autowired - private ServiceRepository serviceRepo; - - @Autowired - private NetworkResourceRepository networkRepo; - - @Autowired - private ASDCRestInterface asdcRestInterface; - - private TestRestTemplate restTemplate = new TestRestTemplate("test", "test"); - - private HttpHeaders headers = new HttpHeaders(); - - @Spy - DistributionClientEmulator spyClient = new DistributionClientEmulator(); - - @LocalServerPort - private int port; - - - @Rule - public TemporaryFolder folder= new TemporaryFolder(); - - - @Before - public void setUp() { - //ASDC Controller writes to this path - System.setProperty("mso.config.path", folder.getRoot().toString()); - } - - @Test - @Transactional - public void testAllottedResourceService() throws Exception { - - wireMockServer.stubFor(post(urlPathMatching("/aai/.*")) - .willReturn(aResponse() - .withStatus(200) - .withHeader("Content-Type", "application/json"))); - - ObjectMapper mapper = new ObjectMapper(); - NotificationDataImpl request = mapper.readValue(new File("src/test/resources/resource-examples/allottedresource/notif-portm.json"), NotificationDataImpl.class); - headers.add("resource-location", "src/test/resources/resource-examples/allottedresource/"); - HttpEntity entity = new HttpEntity(request, headers); - - ResponseEntity response = restTemplate.exchange(createURLWithPort("test/treatNotification/v1"), HttpMethod.POST, - entity, String.class); - - assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); - - AllottedResource expectedService = new AllottedResource(); - expectedService.setDescription("rege1802pnf"); - expectedService.setModelInvariantUUID("b8f83c3f-077c-4e2c-b489-c66382060436"); - expectedService.setModelName("rege1802pnf"); - expectedService.setModelUUID("5b18c75e-2d08-4bf2-ad58-4ea704ec648d"); - expectedService.setModelVersion("1.0"); - expectedService.setSubcategory("Contrail Route"); - expectedService.setToscaNodeType("org.openecomp.resource.pnf.Rege1802pnf"); - Set arCustomizationSet = new HashSet(); - AllottedResourceCustomization arCustomization = new AllottedResourceCustomization(); - arCustomization.setModelCustomizationUUID("f62bb612-c5d4-4406-865c-0abec30631ba"); - arCustomization.setModelInstanceName("rege1802pnf 0"); - arCustomizationSet.add(arCustomization); - - arCustomization.setAllottedResource(expectedService); - - - expectedService.setAllotedResourceCustomization(arCustomizationSet); - - AllottedResource actualResponse = allottedRepo.findResourceByModelUUID("5b18c75e-2d08-4bf2-ad58-4ea704ec648d"); - - - if(actualResponse == null) - throw new Exception("No Allotted Resource Written to database"); - - - assertThat(actualResponse, sameBeanAs(expectedService).ignoring("0x1.created").ignoring("0x1.allotedResourceCustomization.created")); - } - - @Test - public void invokeASDCStatusDataNullTest() { - String request = ""; - Response response = asdcRestInterface.invokeASDCStatusData(request); - assertNull(response); - - } - - - - - - protected String createURLWithPort(String uri) { - return "http://localhost:" + port + uri; - } + @Autowired + private AllottedResourceRepository allottedRepo; + + @Autowired + private ServiceRepository serviceRepo; + + @Autowired + private NetworkResourceRepository networkRepo; + + @Autowired + private ASDCRestInterface asdcRestInterface; + + private TestRestTemplate restTemplate = new TestRestTemplate("test", "test"); + + private HttpHeaders headers = new HttpHeaders(); + + @Spy + DistributionClientEmulator spyClient = new DistributionClientEmulator(); + + @LocalServerPort + private int port; + + + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + + @Before + public void setUp() { + // ASDC Controller writes to this path + System.setProperty("mso.config.path", folder.getRoot().toString()); + } + + @Test + @Transactional + public void testAllottedResourceService() throws Exception { + + wireMockServer.stubFor(post(urlPathMatching("/aai/.*")) + .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json"))); + + ObjectMapper mapper = new ObjectMapper(); + NotificationDataImpl request = + mapper.readValue(new File("src/test/resources/resource-examples/allottedresource/notif-portm.json"), + NotificationDataImpl.class); + headers.add("resource-location", "src/test/resources/resource-examples/allottedresource/"); + HttpEntity entity = new HttpEntity(request, headers); + + ResponseEntity response = restTemplate.exchange(createURLWithPort("test/treatNotification/v1"), + HttpMethod.POST, entity, String.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + + AllottedResource expectedService = new AllottedResource(); + expectedService.setDescription("rege1802pnf"); + expectedService.setModelInvariantUUID("b8f83c3f-077c-4e2c-b489-c66382060436"); + expectedService.setModelName("rege1802pnf"); + expectedService.setModelUUID("5b18c75e-2d08-4bf2-ad58-4ea704ec648d"); + expectedService.setModelVersion("1.0"); + expectedService.setSubcategory("Contrail Route"); + expectedService.setToscaNodeType("org.openecomp.resource.pnf.Rege1802pnf"); + Set arCustomizationSet = new HashSet(); + AllottedResourceCustomization arCustomization = new AllottedResourceCustomization(); + arCustomization.setModelCustomizationUUID("f62bb612-c5d4-4406-865c-0abec30631ba"); + arCustomization.setModelInstanceName("rege1802pnf 0"); + arCustomizationSet.add(arCustomization); + + arCustomization.setAllottedResource(expectedService); + + + expectedService.setAllotedResourceCustomization(arCustomizationSet); + + AllottedResource actualResponse = allottedRepo.findResourceByModelUUID("5b18c75e-2d08-4bf2-ad58-4ea704ec648d"); + + + if (actualResponse == null) + throw new Exception("No Allotted Resource Written to database"); + + + assertThat(actualResponse, sameBeanAs(expectedService).ignoring("0x1.created") + .ignoring("0x1.allotedResourceCustomization.created")); + } + + @Test + @Transactional + public void test_VFW_Distrobution() throws Exception { + + wireMockServer.stubFor(post(urlPathMatching("/aai/.*")) + .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json"))); + + ObjectMapper mapper = new ObjectMapper(); + NotificationDataImpl request = mapper.readValue( + new File("src/test/resources/resource-examples/vFW/notification.json"), NotificationDataImpl.class); + headers.add("resource-location", "src/test/resources/resource-examples/vFW/"); + HttpEntity entity = new HttpEntity(request, headers); + + ResponseEntity response = restTemplate.exchange(createURLWithPort("test/treatNotification/v1"), + HttpMethod.POST, entity, String.class); + + assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value()); + + Service expectedService = new Service(); + expectedService.setDescription("catalog service description"); + expectedService.setModelInvariantUUID("3164f9ff-d7e7-4813-ab32-6be7e1cacb18"); + expectedService.setModelName("vFW 2019-04-10 21:53:05"); + expectedService.setModelUUID("e16e4ed9-3429-423a-bc3c-1389ae91491c"); + expectedService.setModelVersion("1.0"); + + + + Service actualService = serviceRepo.findOneByModelUUID("e16e4ed9-3429-423a-bc3c-1389ae91491c"); + + + if (actualService == null) + throw new Exception("No Allotted Resource Written to database"); + + assertEquals(expectedService.getModelName(), actualService.getModelName()); + } + + @Test + public void invokeASDCStatusDataNullTest() { + String request = ""; + Response response = asdcRestInterface.invokeASDCStatusData(request); + assertNull(response); + + } + + + + protected String createURLWithPort(String uri) { + return "http://localhost:" + port + uri; + } }