Search in sources :

Example 1 with NotificationDataImpl

use of org.onap.so.asdc.client.test.emulators.NotificationDataImpl in project so by onap.

the class ASDCRestInterfaceTest method test_Vcpe_Infra_Distribution.

@Test
public void test_Vcpe_Infra_Distribution() throws Exception {
    wireMockServer.stubFor(post(urlPathMatching("/aai/.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")));
    wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(org.springframework.http.HttpStatus.ACCEPTED.value())));
    String resourceLocation = "src/test/resources/resource-examples/vcpe-infra/";
    ObjectMapper mapper = new ObjectMapper();
    NotificationDataImpl request = mapper.readValue(new File(resourceLocation + "demovcpeinfra-notification.json"), NotificationDataImpl.class);
    headers.add("resource-location", resourceLocation);
    HttpEntity<NotificationDataImpl> entity = new HttpEntity<NotificationDataImpl>(request, headers);
    ResponseEntity<String> response = restTemplate.exchange(createURLWithPort("test/treatNotification/v1"), HttpMethod.POST, entity, String.class);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
    Optional<ToscaCsar> toscaCsar = toscaCsarRepo.findById("144606d8-a505-4ba0-90a9-6d1c6219fc6b");
    assertTrue(toscaCsar.isPresent());
    assertEquals("service-Demovcpeinfra-csar.csar", toscaCsar.get().getName());
    Optional<Service> service = serviceRepo.findById("8a77cbbb-9850-40bb-a42f-7aec8e3e6ab7");
    assertTrue(service.isPresent());
    assertEquals("demoVCPEInfra", service.get().getModelName());
    Optional<NetworkResource> networkResource = networkRepo.findById("89789b26-a46b-4cee-aed0-d46e21f93a5e");
    assertTrue(networkResource.isPresent());
    assertEquals("Generic NeutronNet", networkResource.get().getModelName());
    List<VnfResourceCustomization> vnfCustomizationResources = vnfCustRepo.findByModelCustomizationUUID("01564fe7-0541-4d92-badc-464cc35f83ba");
    for (VnfResourceCustomization vnfResourceCustomization : vnfCustomizationResources) {
        assertTrue(vnfResourceCustomization.getVfModuleCustomizations().stream().anyMatch(vfModuleCust -> "354b1e83-47db-4af1-8af4-9c14b03b482d".equals(vfModuleCust.getModelCustomizationUUID())));
    }
}
Also used : Matchers.sameBeanAs(com.shazam.shazamcrest.matcher.Matchers.sameBeanAs) ArgumentMatchers(org.mockito.ArgumentMatchers) Autowired(org.springframework.beans.factory.annotation.Autowired) DistributionClientEmulator(org.onap.so.asdc.client.test.emulators.DistributionClientEmulator) Service(org.onap.so.db.catalog.beans.Service) Spy(org.mockito.Spy) NetworkResourceRepository(org.onap.so.db.catalog.data.repository.NetworkResourceRepository) WireMock.post(com.github.tomakehurst.wiremock.client.WireMock.post) ConfigurationResourceCustomization(org.onap.so.db.catalog.beans.ConfigurationResourceCustomization) Transactional(javax.transaction.Transactional) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) HttpHeaders(org.springframework.http.HttpHeaders) Set(java.util.Set) List(java.util.List) AllottedResource(org.onap.so.db.catalog.beans.AllottedResource) HttpEntity(org.springframework.http.HttpEntity) Response(javax.ws.rs.core.Response) Optional(java.util.Optional) NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) VnfCustomizationRepository(org.onap.so.db.catalog.data.repository.VnfCustomizationRepository) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) HashSet(java.util.HashSet) AllottedResourceCustomizationRepository(org.onap.so.db.catalog.data.repository.AllottedResourceCustomizationRepository) WireMock.urlPathMatching(com.github.tomakehurst.wiremock.client.WireMock.urlPathMatching) AllottedResourceRepository(org.onap.so.db.catalog.data.repository.AllottedResourceRepository) VnfResource(org.onap.so.db.catalog.beans.VnfResource) Before(org.junit.Before) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) WorkflowRepository(org.onap.so.db.catalog.data.repository.WorkflowRepository) Files(java.nio.file.Files) BaseTest(org.onap.so.asdc.BaseTest) Assert.assertNotNull(org.junit.Assert.assertNotNull) MatcherAssert.assertThat(com.shazam.shazamcrest.MatcherAssert.assertThat) VnfResourceRepository(org.onap.so.db.catalog.data.repository.VnfResourceRepository) HttpMethod(org.springframework.http.HttpMethod) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) ReflectionTestUtils(org.springframework.test.util.ReflectionTestUtils) Test(org.junit.Test) ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar) File(java.io.File) NetworkResourceCustomization(org.onap.so.db.catalog.beans.NetworkResourceCustomization) Workflow(org.onap.so.db.catalog.beans.Workflow) LocalServerPort(org.springframework.boot.web.server.LocalServerPort) Mockito(org.mockito.Mockito) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) Paths(java.nio.file.Paths) ServiceRepository(org.onap.so.db.catalog.data.repository.ServiceRepository) AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization) ResponseEntity(org.springframework.http.ResponseEntity) TestRestTemplate(org.springframework.boot.test.web.client.TestRestTemplate) Assert.assertEquals(org.junit.Assert.assertEquals) TemporaryFolder(org.junit.rules.TemporaryFolder) ToscaCsarRepository(org.onap.so.db.catalog.data.repository.ToscaCsarRepository) HttpEntity(org.springframework.http.HttpEntity) Service(org.onap.so.db.catalog.beans.Service) NetworkResource(org.onap.so.db.catalog.beans.NetworkResource) NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) File(java.io.File) ToscaCsar(org.onap.so.db.catalog.beans.ToscaCsar) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) VnfResourceCustomization(org.onap.so.db.catalog.beans.VnfResourceCustomization) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Example 2 with NotificationDataImpl

use of org.onap.so.asdc.client.test.emulators.NotificationDataImpl in project so by onap.

the class ASDCRestInterfaceTest method test_Vcperescust_Distribution.

@Test
public void test_Vcperescust_Distribution() throws Exception {
    wireMockServer.stubFor(post(urlPathMatching("/aai/.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")));
    wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(org.springframework.http.HttpStatus.ACCEPTED.value())));
    String resourceLocation = "src/test/resources/resource-examples/vcpe-rescust/";
    ObjectMapper mapper = new ObjectMapper();
    NotificationDataImpl request = mapper.readValue(new File(resourceLocation + "demo-vcpe-rescust-notification.json"), NotificationDataImpl.class);
    headers.add("resource-location", resourceLocation);
    HttpEntity<NotificationDataImpl> entity = new HttpEntity<NotificationDataImpl>(request, headers);
    ResponseEntity<String> response = restTemplate.exchange(createURLWithPort("test/treatNotification/v1"), HttpMethod.POST, entity, String.class);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
    Optional<Service> service = serviceRepo.findById("d3aac917-543d-4421-b6d7-ba2b65884eb7");
    assertTrue(service.isPresent());
    assertEquals("vCPEResCust 2019-10-01 _2364", service.get().getModelName());
}
Also used : NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) HttpEntity(org.springframework.http.HttpEntity) Service(org.onap.so.db.catalog.beans.Service) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Example 3 with NotificationDataImpl

use of org.onap.so.asdc.client.test.emulators.NotificationDataImpl in project so by onap.

the class ASDCRestInterfaceTest method test_CCVPN_Distribution.

@Test
public void test_CCVPN_Distribution() throws Exception {
    wireMockServer.stubFor(post(urlPathMatching("/aai/.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")));
    wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(org.springframework.http.HttpStatus.ACCEPTED.value())));
    String resourceLocation = "src/test/resources/resource-examples/ccvpn/";
    ObjectMapper mapper = new ObjectMapper();
    NotificationDataImpl request = mapper.readValue(new File(resourceLocation + "demo-ccvpn-notification.json"), NotificationDataImpl.class);
    headers.add("resource-location", resourceLocation);
    HttpEntity<NotificationDataImpl> entity = new HttpEntity<NotificationDataImpl>(request, headers);
    ResponseEntity<String> response = restTemplate.exchange(createURLWithPort("test/treatNotification/v1"), HttpMethod.POST, entity, String.class);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
    Optional<Service> service = serviceRepo.findById("317887d3-a4e4-45cb-8971-2a78426fefac");
    assertTrue(service.isPresent());
    assertEquals("CCVPNService", service.get().getModelName());
}
Also used : NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) HttpEntity(org.springframework.http.HttpEntity) Service(org.onap.so.db.catalog.beans.Service) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Example 4 with NotificationDataImpl

use of org.onap.so.asdc.client.test.emulators.NotificationDataImpl in project so by onap.

the class ASDCRestInterfaceTest method testAllottedResourceService.

@Test
@Transactional
public void testAllottedResourceService() throws Exception {
    wireMockServer.stubFor(post(urlPathMatching("/aai/.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")));
    wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(org.springframework.http.HttpStatus.ACCEPTED.value())));
    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<NotificationDataImpl> entity = new HttpEntity<NotificationDataImpl>(request, headers);
    ResponseEntity<String> 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<AllottedResourceCustomization> arCustomizationSet = new HashSet<AllottedResourceCustomization>();
    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"));
}
Also used : NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) HttpEntity(org.springframework.http.HttpEntity) File(java.io.File) AllottedResource(org.onap.so.db.catalog.beans.AllottedResource) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) AllottedResourceCustomization(org.onap.so.db.catalog.beans.AllottedResourceCustomization) HashSet(java.util.HashSet) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test) Transactional(javax.transaction.Transactional)

Example 5 with NotificationDataImpl

use of org.onap.so.asdc.client.test.emulators.NotificationDataImpl in project so by onap.

the class ASDCRestInterfaceTest method testServiceBasicCnf.

@Test
public void testServiceBasicCnf() throws Exception {
    wireMockServer.stubFor(post(urlPathMatching("/aai/.*")).willReturn(aResponse().withStatus(200).withHeader("Content-Type", "application/json")));
    wireMockServer.stubFor(post(urlPathMatching("/v1.0/activity-spec")).willReturn(aResponse().withHeader("Content-Type", "application/json").withStatus(org.springframework.http.HttpStatus.ACCEPTED.value())));
    String resourceLocation = "src/test/resources/resource-examples/service-BasicCnf/";
    ObjectMapper mapper = new ObjectMapper();
    NotificationDataImpl request = mapper.readValue(new File(resourceLocation + "service-BasicCnf-notification.json"), NotificationDataImpl.class);
    headers.add("resource-location", resourceLocation);
    HttpEntity<NotificationDataImpl> entity = new HttpEntity<NotificationDataImpl>(request, headers);
    ResponseEntity<String> response = restTemplate.exchange(createURLWithPort("test/treatNotification/v1"), HttpMethod.POST, entity, String.class);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatusCode().value());
    Optional<Service> service = serviceRepo.findById("31e0cd50-0a84-42b4-a7a8-dd5d82e6907d");
    assertTrue(service.isPresent());
    assertEquals("basic_cnf", service.get().getModelName());
}
Also used : NotificationDataImpl(org.onap.so.asdc.client.test.emulators.NotificationDataImpl) HttpEntity(org.springframework.http.HttpEntity) Service(org.onap.so.db.catalog.beans.Service) File(java.io.File) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) BaseTest(org.onap.so.asdc.BaseTest) Test(org.junit.Test)

Aggregations

NotificationDataImpl (org.onap.so.asdc.client.test.emulators.NotificationDataImpl)18 Test (org.junit.Test)16 BaseTest (org.onap.so.asdc.BaseTest)16 Service (org.onap.so.db.catalog.beans.Service)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)11 File (java.io.File)11 HttpEntity (org.springframework.http.HttpEntity)10 ArrayList (java.util.ArrayList)5 EntityNotFoundException (javax.persistence.EntityNotFoundException)5 ToscaCsar (org.onap.so.db.catalog.beans.ToscaCsar)5 WatchdogComponentDistributionStatus (org.onap.so.db.request.beans.WatchdogComponentDistributionStatus)5 Transactional (javax.transaction.Transactional)4 ASDCControllerException (org.onap.so.asdc.client.exceptions.ASDCControllerException)4 ArtifactInfoImpl (org.onap.so.asdc.client.test.emulators.ArtifactInfoImpl)3 ResourceInfoImpl (org.onap.so.asdc.client.test.emulators.ResourceInfoImpl)3 HashSet (java.util.HashSet)2 Before (org.junit.Before)2 AllottedResource (org.onap.so.db.catalog.beans.AllottedResource)2 AllottedResourceCustomization (org.onap.so.db.catalog.beans.AllottedResourceCustomization)2 PnfResourceCustomization (org.onap.so.db.catalog.beans.PnfResourceCustomization)2