diff options
Diffstat (limited to 'src/test')
9 files changed, 108 insertions, 234 deletions
diff --git a/src/test/java/org/onap/aai/modelloader/config/TestModelLoaderConfig.java b/src/test/java/org/onap/aai/modelloader/config/TestModelLoaderConfig.java index 87fbd6a..89f343c 100644 --- a/src/test/java/org/onap/aai/modelloader/config/TestModelLoaderConfig.java +++ b/src/test/java/org/onap/aai/modelloader/config/TestModelLoaderConfig.java @@ -21,16 +21,12 @@ package org.onap.aai.modelloader.config; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertFalse; import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; import java.util.List; import java.util.Properties; import org.eclipse.jetty.util.security.Password; import org.junit.jupiter.api.Test; -import org.onap.aai.modelloader.restclient.AaiRestClient; import org.onap.sdc.utils.ArtifactTypeEnum; /** @@ -150,23 +146,6 @@ public class TestModelLoaderConfig { } @Test - public void testMissingAuthenticationProperties() throws IOException { - Properties props = new Properties(); - props.load(new FileInputStream("src/test/resources/model-loader-empty-auth-password.properties")); - - ModelLoaderConfig config = new ModelLoaderConfig(props, null); - AaiRestClient aaiClient = new AaiRestClient(config); - - assertFalse(aaiClient.useBasicAuth(), "Empty AAI Password should result in no basic authentication"); - - props.load(new FileInputStream("src/test/resources/model-loader-no-auth-password.properties")); - config = new ModelLoaderConfig(props, null); - aaiClient = new AaiRestClient(config); - - assertFalse(aaiClient.useBasicAuth(), "No AAI Password should result in no basic authentication"); - } - - @Test public void testGetUrls() { Properties props = new Properties(); props.put(ModelLoaderConfig.PROP_AAI_MODEL_RESOURCE_URL, "/aai/v*/service-design-and-creation/models/model/"); diff --git a/src/test/java/org/onap/aai/modelloader/entity/catalog/TestVnfCatalogArtifactHandler.java b/src/test/java/org/onap/aai/modelloader/entity/catalog/TestVnfCatalogArtifactHandler.java index 8145599..3da25b0 100644 --- a/src/test/java/org/onap/aai/modelloader/entity/catalog/TestVnfCatalogArtifactHandler.java +++ b/src/test/java/org/onap/aai/modelloader/entity/catalog/TestVnfCatalogArtifactHandler.java @@ -23,6 +23,7 @@ package org.onap.aai.modelloader.entity.catalog; import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -35,9 +36,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; - import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Mockito; @@ -45,7 +43,9 @@ import org.onap.aai.modelloader.config.ModelLoaderConfig; import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.entity.ArtifactType; import org.onap.aai.modelloader.restclient.AaiRestClient; -import org.onap.aai.restclient.client.OperationResult; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; public class TestVnfCatalogArtifactHandler { @@ -61,24 +61,23 @@ public class TestVnfCatalogArtifactHandler { @Test public void testUpdateVnfImages() throws Exception { // GET operation - OperationResult mockGetResp = mock(OperationResult.class); + ResponseEntity mockGetResp = mock(ResponseEntity.class); // @formatter:off - when(mockGetResp.getResultCode()) - .thenReturn(Response.Status.OK.getStatusCode()) - .thenReturn(Response.Status.NOT_FOUND.getStatusCode()) - .thenReturn(Response.Status.NOT_FOUND.getStatusCode()) - .thenReturn(Response.Status.OK.getStatusCode()); + when(mockGetResp.getStatusCodeValue()) + .thenReturn(HttpStatus.OK.value()) + .thenReturn(HttpStatus.NOT_FOUND.value()) + .thenReturn(HttpStatus.NOT_FOUND.value()) + .thenReturn(HttpStatus.OK.value()); // @formatter:on - when(mockRestClient.getResource(Mockito.anyString(), Mockito.anyString(), Mockito.any(MediaType.class))) + when(mockRestClient.getResource(Mockito.anyString(), Mockito.anyString(), Mockito.any(MediaType.class), Mockito.any())) .thenReturn(mockGetResp); mockPutOperations(); // Example VNF Catalog XML VnfCatalogArtifactHandler handler = new VnfCatalogArtifactHandler(createConfig()); - assertThat(handler.pushArtifacts(createVnfCatalogArtifact(), "test", new ArrayList<Artifact>(), mockRestClient), - is(true)); + assertTrue(handler.pushArtifacts(createVnfCatalogArtifact(), "test", new ArrayList<Artifact>(), mockRestClient)); assertPutOperationsSucceeded(); } @@ -86,17 +85,17 @@ public class TestVnfCatalogArtifactHandler { @Test public void testUpdateVnfImagesFromXml() throws Exception { // GET operation - OperationResult mockGetResp = mock(OperationResult.class); + ResponseEntity mockGetResp = mock(ResponseEntity.class); // @formatter:off - when(mockGetResp.getResultCode()) - .thenReturn(Response.Status.OK.getStatusCode()) - .thenReturn(Response.Status.NOT_FOUND.getStatusCode()) - .thenReturn(Response.Status.NOT_FOUND.getStatusCode()) - .thenReturn(Response.Status.OK.getStatusCode()); + when(mockGetResp.getStatusCodeValue()) + .thenReturn(HttpStatus.OK.value()) + .thenReturn(HttpStatus.NOT_FOUND.value()) + .thenReturn(HttpStatus.NOT_FOUND.value()) + .thenReturn(HttpStatus.OK.value()); // @formatter:on - when(mockRestClient.getResource(Mockito.anyString(), Mockito.anyString(), Mockito.any(MediaType.class))) + when(mockRestClient.getResource(Mockito.anyString(), Mockito.anyString(), Mockito.any(MediaType.class), Mockito.any())) .thenReturn(mockGetResp); mockPutOperations(); @@ -109,7 +108,7 @@ public class TestVnfCatalogArtifactHandler { // Only two of the VNF images should be pushed ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class); AaiRestClient client = Mockito.verify(mockRestClient, Mockito.times(2)); - client.putResource(Mockito.anyString(), argument.capture(), Mockito.anyString(), Mockito.any(MediaType.class)); + client.putResource(Mockito.anyString(), argument.capture(), Mockito.anyString(), Mockito.any(MediaType.class), Mockito.any()); assertThat(argument.getAllValues().size(), is(2)); assertThat(argument.getAllValues().get(0), containsString("5.2.5")); assertThat(argument.getAllValues().get(0), containsString("VM00")); @@ -161,10 +160,10 @@ public class TestVnfCatalogArtifactHandler { * Always return CREATED (success) for a PUT operation. */ private void mockPutOperations() { - OperationResult mockPutResp = mock(OperationResult.class); - when(mockPutResp.getResultCode()).thenReturn(Response.Status.CREATED.getStatusCode()); + ResponseEntity mockPutResp = mock(ResponseEntity.class); + when(mockPutResp.getStatusCode()).thenReturn(HttpStatus.CREATED); when(mockRestClient.putResource(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(), - Mockito.any(MediaType.class))).thenReturn(mockPutResp); + Mockito.any(MediaType.class), Mockito.any())).thenReturn(mockPutResp); } private void assertPutOperationsSucceeded() { @@ -172,7 +171,7 @@ public class TestVnfCatalogArtifactHandler { ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class); AaiRestClient mockedClient = Mockito.verify(mockRestClient, Mockito.times(2)); mockedClient.putResource(Mockito.anyString(), argument.capture(), Mockito.anyString(), - Mockito.any(MediaType.class)); + Mockito.any(MediaType.class), Mockito.any()); assertThat(argument.getAllValues().get(0), containsString("3.16.9")); assertThat(argument.getAllValues().get(0), containsString("VM00")); assertThat(argument.getAllValues().get(1), containsString("3.16.1")); diff --git a/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java b/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java index 177a8d2..b16c8a0 100644 --- a/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java +++ b/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java @@ -32,8 +32,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import javax.ws.rs.core.Response; - import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -41,7 +39,8 @@ import org.mockito.MockitoAnnotations; import org.onap.aai.modelloader.config.ModelLoaderConfig; import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.restclient.AaiRestClient; -import org.onap.aai.restclient.client.OperationResult; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; /** * Test the Model Artifact Handler using Mocks @@ -69,25 +68,13 @@ public class TestModelArtifactHandler { } @Test - public void testSingleItemList() { - when(config.getAaiBaseUrl()).thenReturn(""); - when(config.getAaiModelUrl(any())).thenReturn(""); - - ModelArtifactHandler handler = new ModelArtifactHandler(config); - List<Artifact> artifacts = Collections.singletonList(new ModelArtifact()); - handler.pushArtifacts(artifacts, "", Collections.emptyList(), aaiClient); - handler.rollback(Collections.emptyList(), "", aaiClient); - assertThat(artifacts, hasSize(1)); - } - - @Test public void testPushExistingModelsWithRollback() { when(config.getAaiBaseUrl()).thenReturn(""); when(config.getAaiModelUrl(any())).thenReturn(""); - OperationResult operationResult = mock(OperationResult.class); - when(aaiClient.getResource(any(), any(), any())).thenReturn(operationResult); - when(operationResult.getResultCode()).thenReturn(Response.Status.OK.getStatusCode()); + ResponseEntity operationResult = mock(ResponseEntity.class); + when(aaiClient.getResource(any(), any(), any(), any())).thenReturn(operationResult); + when(operationResult.getStatusCode()).thenReturn(HttpStatus.OK); List<Artifact> artifacts = new ArrayList<>(); Artifact artifact = new ModelArtifact(); @@ -105,13 +92,13 @@ public class TestModelArtifactHandler { when(config.getAaiModelUrl(any())).thenReturn(""); when(config.getAaiNamedQueryUrl(any())).thenReturn(""); - OperationResult getResult = mock(OperationResult.class); - when(aaiClient.getResource(any(), any(), any())).thenReturn(getResult); - when(getResult.getResultCode()).thenReturn(Response.Status.NOT_FOUND.getStatusCode()); + ResponseEntity getResult = mock(ResponseEntity.class); + when(aaiClient.getResource(any(), any(), any(), any())).thenReturn(getResult); + when(getResult.getStatusCode()).thenReturn(HttpStatus.NOT_FOUND); - OperationResult putResult = mock(OperationResult.class); - when(aaiClient.putResource(any(), any(), any(), any())).thenReturn(putResult); - when(putResult.getResultCode()).thenReturn(Response.Status.CREATED.getStatusCode()); + ResponseEntity putResult = mock(ResponseEntity.class); + when(aaiClient.putResource(any(), any(), any(), any(), any())).thenReturn(putResult); + when(putResult.getStatusCode()).thenReturn(HttpStatus.CREATED); List<Artifact> artifacts = new ArrayList<>(); artifacts.add(new ModelArtifact()); @@ -133,13 +120,13 @@ public class TestModelArtifactHandler { when(config.getAaiModelUrl(any())).thenReturn(""); when(config.getAaiNamedQueryUrl(any())).thenReturn(""); - OperationResult getResult = mock(OperationResult.class); - when(aaiClient.getResource(any(), any(), any())).thenReturn(getResult); - when(getResult.getResultCode()).thenReturn(Response.Status.NOT_FOUND.getStatusCode()); + ResponseEntity getResult = mock(ResponseEntity.class); + when(aaiClient.getResource(any(), any(), any(), any())).thenReturn(getResult); + when(getResult.getStatusCode()).thenReturn(HttpStatus.NOT_FOUND); - OperationResult putResult = mock(OperationResult.class); - when(aaiClient.putResource(any(), any(), any(), any())).thenReturn(putResult); - when(putResult.getResultCode()).thenReturn(Response.Status.BAD_REQUEST.getStatusCode()); + ResponseEntity putResult = mock(ResponseEntity.class); + when(aaiClient.putResource(any(), any(), any(), any(), any())).thenReturn(putResult); + when(putResult.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST); checkRollback(Collections.singletonList(new ModelArtifact())); } @@ -149,18 +136,9 @@ public class TestModelArtifactHandler { when(config.getAaiBaseUrl()).thenReturn(""); when(config.getAaiModelUrl(any())).thenReturn(""); - OperationResult operationResult = mock(OperationResult.class); - when(aaiClient.getResource(any(), any(), any())).thenReturn(operationResult); - when(operationResult.getResultCode()).thenReturn(Response.Status.BAD_REQUEST.getStatusCode()); - - checkRollback(Collections.singletonList(new ModelArtifact())); - } - - @Test - public void testNullResourceModelResult() { - when(config.getAaiBaseUrl()).thenReturn(""); - when(config.getAaiModelUrl(any())).thenReturn(""); - when(aaiClient.getResource(any(), any(), any())).thenReturn(null); + ResponseEntity operationResult = mock(ResponseEntity.class); + when(aaiClient.getResource(any(), any(), any(), any())).thenReturn(operationResult); + when(operationResult.getStatusCode()).thenReturn(HttpStatus.BAD_REQUEST); checkRollback(Collections.singletonList(new ModelArtifact())); } diff --git a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerTest.java b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerTest.java index 0985790..eb31688 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerTest.java +++ b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerTest.java @@ -33,7 +33,6 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import java.util.ArrayList; import java.util.List; -import org.apache.http.entity.ContentType; import org.junit.jupiter.api.Test; import org.onap.aai.modelloader.DistributionClientTestConfiguration; import org.onap.aai.modelloader.entity.Artifact; @@ -66,11 +65,11 @@ public class ArtifactDownloadManagerTest { notificationData.setServiceVersion("2.0"); stubFor(get(urlEqualTo("/sdc/v1/catalog/services/DemovlbCds/1.0/artifacts/service-TestSvc-csar.csar")) - .withHeader("Accept", equalTo(ContentType.APPLICATION_OCTET_STREAM.toString())) + .withHeader("Accept", equalTo(MediaType.APPLICATION_OCTET_STREAM_VALUE)) .withHeader("X-ECOMP-RequestID", matching(".+")) .withHeader("X-ECOMP-InstanceID", equalTo("aai-ml-id-test")) .willReturn(aResponse() - .withHeader("Content-Type", MediaType.APPLICATION_OCTET_STREAM.toString()) + .withHeader("Content-Type", MediaType.APPLICATION_OCTET_STREAM_VALUE) .withBodyFile("service-TestSvc-csar.csar"))); stubFor( @@ -83,7 +82,7 @@ public class ArtifactDownloadManagerTest { .withRequestBody(matchingJsonPath("$.csar", matching(".*"))) .willReturn( aResponse() - .withHeader("Content-Type", "application/json") + .withHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE) .withBodyFile("service-TestSvc-csar-babel-response.json"))); ArtifactInfoImpl artifactInfo = new ArtifactInfoImpl(); diff --git a/src/test/java/org/onap/aai/modelloader/notification/ModelArtifactHandlerTest.java b/src/test/java/org/onap/aai/modelloader/notification/ModelArtifactHandlerTest.java index 4d7b53e..d3495d4 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/ModelArtifactHandlerTest.java +++ b/src/test/java/org/onap/aai/modelloader/notification/ModelArtifactHandlerTest.java @@ -41,13 +41,13 @@ import org.onap.aai.modelloader.entity.Artifact; import org.onap.aai.modelloader.entity.model.ModelArtifact; import org.onap.aai.modelloader.entity.model.ModelArtifactHandler; import org.onap.aai.modelloader.restclient.AaiRestClient; -import org.onap.aai.restclient.client.OperationResult; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cloud.contract.wiremock.AutoConfigureWireMock; import org.springframework.http.HttpStatus; -import org.w3c.dom.Node; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; import com.fasterxml.jackson.databind.ObjectMapper; import com.github.tomakehurst.wiremock.client.WireMock; @@ -89,7 +89,8 @@ public class ModelArtifactHandlerTest { WireMock.stubFor( WireMock.put(urlEqualTo("/aai/v28/service-design-and-creation/models/model/modelInvariantId")) - .withHeader("Content-Type", equalTo("application/xml")) + .withHeader("Accept", equalTo(MediaType.APPLICATION_XML_VALUE)) + .withHeader("Content-Type", equalTo(MediaType.APPLICATION_XML_VALUE)) .withHeader("X-TransactionId", equalTo("someId")) .withHeader("X-FromAppId", equalTo("ModelLoader")) .willReturn( @@ -98,6 +99,7 @@ public class ModelArtifactHandlerTest { ModelArtifact modelArtifact = new ModelArtifact(); modelArtifact.setModelInvariantId("modelInvariantId"); + modelArtifact.setPayload(""); List<Artifact> artifacts = List.of(modelArtifact); List<Artifact> completedArtifacts = new ArrayList<>(); @@ -134,7 +136,8 @@ public class ModelArtifactHandlerTest { WireMock.stubFor( WireMock.put(urlEqualTo( "/aai/v28/service-design-and-creation/models/model/modelInvariantId/model-vers/model-ver/modelVersionId")) - .withHeader("Content-Type", equalTo("application/xml")) + .withHeader("Accept", equalTo(MediaType.APPLICATION_XML_VALUE)) + .withHeader("Content-Type", equalTo(MediaType.APPLICATION_XML_VALUE)) .withHeader("X-TransactionId", equalTo("distributionId")) .withHeader("X-FromAppId", equalTo("ModelLoader")) .willReturn( @@ -144,8 +147,8 @@ public class ModelArtifactHandlerTest { ModelArtifact modelArtifact = new ModelArtifact(); modelArtifact.setModelInvariantId("modelInvariantId"); modelArtifact.setModelVerId("modelVersionId"); - Node node = Mockito.mock(Node.class); - modelArtifact.setModelVer(node); + modelArtifact.setPayload(""); + modelArtifact.setModelVer("2.0"); List<Artifact> artifacts = List.of(modelArtifact); List<Artifact> completedArtifacts = new ArrayList<>(); @@ -159,9 +162,11 @@ public class ModelArtifactHandlerTest { @Test public void thatModelCanBeRolledBack() { stubFor(WireMock.get(urlEqualTo("/aai/v28/service-design-and-creation/models/model/3a40ab73-6694-4e75-bb6d-9a4a86ce35b3")) + .withHeader("Accept", equalTo(MediaType.APPLICATION_XML_VALUE)) .withHeader("X-FromAppId", equalTo("ModelLoader")) .withHeader("X-TransactionId", equalTo("distributionId")) .willReturn(aResponse() + .withHeader("Content-Type", MediaType.APPLICATION_XML_VALUE) .withBodyFile("modelResponse.xml"))); stubFor(WireMock.delete(urlEqualTo("/aai/v28/service-design-and-creation/models/model/3a40ab73-6694-4e75-bb6d-9a4a86ce35b3?resource-version=1710523260974")) @@ -172,8 +177,8 @@ public class ModelArtifactHandlerTest { ModelArtifact modelArtifact = new ModelArtifact(); modelArtifact.setModelInvariantId("3a40ab73-6694-4e75-bb6d-9a4a86ce35b3"); modelArtifact.setModelVerId("modelVersionId"); - Node node = Mockito.mock(Node.class); - modelArtifact.setModelVer(node); + // modelArtifact.setModelVer("2.0"); + List<Artifact> completedArtifacts = new ArrayList<>(); completedArtifacts.add(modelArtifact); @@ -195,30 +200,46 @@ public class ModelArtifactHandlerTest { * @param modelArtifact */ private void mockModelCreation(ModelArtifact modelArtifact) { - OperationResult createdResult = Mockito.mock(OperationResult.class); - when(createdResult.getResultCode()).thenReturn(HttpStatus.CREATED.value()); - OperationResult notFoundResult = Mockito.mock(OperationResult.class); - when(notFoundResult.getResultCode()).thenReturn(HttpStatus.NOT_FOUND.value()); + ResponseEntity createdResult = Mockito.mock(ResponseEntity.class); + when(createdResult.getStatusCode()).thenReturn(HttpStatus.CREATED); + ResponseEntity notFoundResult = Mockito.mock(ResponseEntity.class); + when(notFoundResult.getStatusCode()).thenReturn(HttpStatus.NOT_FOUND); AaiRestClient aaiClient = Mockito.mock(AaiRestClient.class); - when(aaiClient.putResource(any(), any(), any(), any())).thenReturn(createdResult); - when(aaiClient.getResource(any(), any(), any())).thenReturn(notFoundResult); + when(aaiClient.putResource(any(), any(), any(), any(), any())).thenReturn(createdResult); + when(aaiClient.getResource(any(), any(), any(), any())).thenReturn(notFoundResult); modelArtifact.push(aaiClient, config, null, new ArrayList<>()); } @Test public void thatModelVersionCanBeRolledBack() { - // "http://localhost:10594/aai/v28/service-design-and-creation/models/model/modelInvariantId/model-vers/model-ver/modelVersionId" + WireMock.stubFor( + WireMock.get(urlEqualTo( + "/aai/v28/service-design-and-creation/models/model/modelInvariantId/model-vers/model-ver/modelVersionId")) + .withHeader("Accept", equalTo("application/xml")) + .withHeader("X-TransactionId", equalTo("distributionId")) + .withHeader("X-FromAppId", equalTo("ModelLoader")) + .willReturn( + WireMock.aResponse() + .withHeader("Content-Type", MediaType.APPLICATION_XML_VALUE) + .withBodyFile("modelVersion.xml"))); + + stubFor(WireMock.delete(urlEqualTo("/aai/v28/service-design-and-creation/models/model/modelInvariantId/model-vers/model-ver/modelVersionId?resource-version=1708937324692")) + .withHeader("X-FromAppId", equalTo("ModelLoader")) + .withHeader("X-TransactionId", equalTo("distributionId")) + .willReturn(aResponse().withStatus(HttpStatus.OK.value()))); ModelArtifact modelArtifact = new ModelArtifact(); modelArtifact.setModelInvariantId("modelInvariantId"); modelArtifact.setModelVerId("modelVersionId"); - Node node = Mockito.mock(Node.class); - modelArtifact.setModelVer(node); + List<Artifact> completedArtifacts = new ArrayList<>(); completedArtifacts.add(modelArtifact); modelArtifactHandler.rollback(completedArtifacts, "distributionId", restClient); + verify( + deleteRequestedFor( + urlEqualTo("/aai/v28/service-design-and-creation/models/model/modelInvariantId/model-vers/model-ver/modelVersionId?resource-version=1708937324692"))); } }
\ No newline at end of file diff --git a/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDeploymentManager.java b/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDeploymentManager.java index dfced1a..618a268 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDeploymentManager.java +++ b/src/test/java/org/onap/aai/modelloader/notification/TestArtifactDeploymentManager.java @@ -48,9 +48,11 @@ import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException; import org.onap.aai.modelloader.entity.model.ModelArtifactHandler; import org.onap.aai.modelloader.extraction.InvalidArchiveException; import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder; +import org.onap.aai.modelloader.restclient.AaiRestClient; import org.onap.aai.modelloader.service.ArtifactDeploymentManager; import org.onap.aai.modelloader.util.ArtifactTestUtils; import org.onap.sdc.api.notification.INotificationData; +import org.springframework.web.client.RestTemplate; /** * Tests {@link ArtifactDeploymentManager}. @@ -73,7 +75,8 @@ public class TestArtifactDeploymentManager { configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE)); ModelLoaderConfig modelLoaderConfig = new ModelLoaderConfig(configProperties, null); - manager = new ArtifactDeploymentManager(modelLoaderConfig, modelArtifactHandlerMock, vnfCatalogArtifactHandlerMock); + AaiRestClient aaiRestClient = new AaiRestClient(modelLoaderConfig, new RestTemplate()); + manager = new ArtifactDeploymentManager(modelArtifactHandlerMock, vnfCatalogArtifactHandlerMock, aaiRestClient); } @AfterEach diff --git a/src/test/java/org/onap/aai/modelloader/restclient/TestAaiRestClient.java b/src/test/java/org/onap/aai/modelloader/restclient/TestAaiRestClient.java index 37b7e12..c992d06 100644 --- a/src/test/java/org/onap/aai/modelloader/restclient/TestAaiRestClient.java +++ b/src/test/java/org/onap/aai/modelloader/restclient/TestAaiRestClient.java @@ -30,15 +30,16 @@ import java.util.Properties; import java.util.stream.IntStream; import java.util.stream.Stream; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; import javax.xml.parsers.DocumentBuilderFactory; import org.onap.aai.modelloader.config.ModelLoaderConfig; import org.onap.aai.modelloader.entity.ArtifactType; import org.onap.aai.modelloader.entity.model.ModelArtifact; import org.onap.aai.modelloader.entity.model.ModelArtifactParser; -import org.onap.aai.restclient.client.OperationResult; +import org.springframework.http.HttpStatus; +import org.springframework.http.MediaType; +import org.springframework.http.ResponseEntity; +import org.springframework.web.client.RestTemplate; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -89,21 +90,21 @@ public class TestAaiRestClient { model.setPayload(readFile(MODEL_FILE)); model.setModelNamespace("http://org.openecomp.aai.inventory/v9"); - AaiRestClient aaiClient = new AaiRestClient(config); + AaiRestClient aaiClient = new AaiRestClient(config, new RestTemplate()); // GET model - OperationResult opResult = - aaiClient.getResource(getUrl(model, config), "example-trans-id-0", MediaType.APPLICATION_XML_TYPE); - assertEquals(opResult.getResultCode(), Response.Status.NOT_FOUND.getStatusCode()); + ResponseEntity opResult = + aaiClient.getResource(getUrl(model, config), "example-trans-id-0", MediaType.APPLICATION_XML, String.class); + assertEquals(opResult.getStatusCode(), HttpStatus.NOT_FOUND); // PUT the model opResult = aaiClient.putResource(getUrl(model, config), model.getPayload(), "example-trans-id-1", - MediaType.APPLICATION_XML_TYPE); - assertEquals(opResult.getResultCode(), Response.Status.CREATED.getStatusCode()); + MediaType.APPLICATION_XML, String.class); + assertEquals(opResult.getStatusCode(), HttpStatus.CREATED); // DELETE the model opResult = aaiClient.getAndDeleteResource(getUrl(model, config), "example-trans-id-3"); - assertEquals(opResult.getResultCode(), Response.Status.NO_CONTENT.getStatusCode()); + assertEquals(opResult.getStatusCode(), HttpStatus.NO_CONTENT); } catch (Exception e) { e.printStackTrace(); } diff --git a/src/test/java/org/onap/aai/modelloader/restclient/TestAaiServiceClient.java b/src/test/java/org/onap/aai/modelloader/restclient/TestAaiServiceClient.java deleted file mode 100644 index 18753b1..0000000 --- a/src/test/java/org/onap/aai/modelloader/restclient/TestAaiServiceClient.java +++ /dev/null @@ -1,114 +0,0 @@ -/** - * ============LICENSE_START======================================================= - * org.onap.aai - * ================================================================================ - * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 European Software Marketing Ltd. - * ================================================================================ - * 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========================================================= - */ -package org.onap.aai.modelloader.restclient; - -import static javax.servlet.http.HttpServletResponse.SC_OK; -import static org.apache.commons.io.IOUtils.write; -import static org.junit.jupiter.api.Assertions.assertTrue; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.Properties; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import javax.ws.rs.core.MediaType; - -import org.eclipse.jetty.server.Handler; -import org.eclipse.jetty.server.Request; -import org.eclipse.jetty.server.Server; -import org.eclipse.jetty.server.handler.AbstractHandler; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.onap.aai.modelloader.config.ModelLoaderConfig; - -/** - * Local testing of the A&AI Service client. - * - */ -public class TestAaiServiceClient { - - private Server server; - private AaiRestClient aaiClient; - - @BeforeEach - public void startJetty() throws Exception { - server = new Server(0); - server.setHandler(getMockHandler()); - server.start(); - - Properties props = new Properties(); - props.put("ml.aai.KEYSTORE_PASSWORD", "2244"); - props.put("ml.aai.RESTCLIENT_CONNECT_TIMEOUT", "3000"); - props.put("ml.aai.RESTCLIENT_READ_TIMEOUT", "3000"); - ModelLoaderConfig config = new ModelLoaderConfig(props, "."); - aaiClient = new AaiRestClient(config); - } - - @AfterEach - public void stopJetty() throws Exception { - server.stop(); - } - - @Test - public void testBuildAaiRestClient() { - Properties props = new Properties(); - ModelLoaderConfig config = new ModelLoaderConfig(props, "."); - new AaiRestClient(config); - assertTrue(true); - } - - @Test - public void testOperations() { - String url = server.getURI().toString(); - String transId = ""; - MediaType mediaType = MediaType.APPLICATION_JSON_TYPE; - aaiClient.getResource(url, "", mediaType); - aaiClient.deleteResource(url, "", transId); - aaiClient.getAndDeleteResource(url, transId); - aaiClient.postResource(url, "", transId, mediaType); - aaiClient.putResource(url, "", transId, mediaType); - assertTrue(true); - } - - - /** - * Creates an {@link AbstractHandler handler} returning an arbitrary String as a response. - * - * @return never <code>null</code>. - */ - private Handler getMockHandler() { - Handler handler = new AbstractHandler() { - @Override - public void handle(String target, Request request, HttpServletRequest servletRequest, - HttpServletResponse response) throws IOException, ServletException { - response.setStatus(SC_OK); - response.setContentType("text/json;charset=utf-8"); - write("", response.getOutputStream(), Charset.defaultCharset()); - request.setHandled(true); - } - }; - return handler; - } -} - diff --git a/src/test/resources/__files/modelVersion.xml b/src/test/resources/__files/modelVersion.xml new file mode 100644 index 0000000..efee516 --- /dev/null +++ b/src/test/resources/__files/modelVersion.xml @@ -0,0 +1,8 @@ +<?xml version="1.0" encoding="UTF-8"?> +<model-ver + xmlns="http://org.onap.aai.inventory/v28"> + <model-version-id>fe578080-ce19-4604-8760-fc264fbb2565</model-version-id> + <model-name>group-assignment</model-name> + <model-version>1.0</model-version> + <resource-version>1708937324692</resource-version> +</model-ver>
\ No newline at end of file |