summaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/onap/aai/modelloader/csar/extractor/VnfCatalogExtractorTest.java138
-rw-r--r--src/test/java/org/onap/aai/modelloader/entity/catalog/TestVnfCatalogArtifactHandler.java49
-rw-r--r--src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerVnfcTest.java227
-rw-r--r--src/test/java/org/onap/aai/modelloader/service/TestModelLoaderService.java4
-rw-r--r--src/test/java/org/onap/aai/modelloader/util/TestJsonXmlConverter.java36
-rw-r--r--src/test/resources/compressedArtifacts/noVnfcFilesArchive.csarbin0 -> 1193 bytes
-rw-r--r--src/test/resources/compressedArtifacts/threeVnfcFilesArchive.csarbin0 -> 3501 bytes
-rw-r--r--src/test/resources/xmlFiles/fortigate.xml129
-rw-r--r--src/test/resources/xmlFiles/vnfcatalog-1.xml100
-rw-r--r--src/test/resources/xmlFiles/vnfcatalog-2.xml100
-rw-r--r--src/test/resources/xmlFiles/vnfcatalog-3.xml100
11 files changed, 863 insertions, 20 deletions
diff --git a/src/test/java/org/onap/aai/modelloader/csar/extractor/VnfCatalogExtractorTest.java b/src/test/java/org/onap/aai/modelloader/csar/extractor/VnfCatalogExtractorTest.java
new file mode 100644
index 0000000..bd8c33f
--- /dev/null
+++ b/src/test/java/org/onap/aai/modelloader/csar/extractor/VnfCatalogExtractorTest.java
@@ -0,0 +1,138 @@
+/**
+ * ============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.csar.extractor;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+import java.util.stream.Collectors;
+import org.junit.Test;
+import org.onap.aai.modelloader.entity.Artifact;
+import org.onap.aai.modelloader.entity.ArtifactType;
+import org.onap.aai.modelloader.extraction.InvalidArchiveException;
+import org.onap.aai.modelloader.extraction.VnfCatalogExtractor;
+import org.onap.aai.modelloader.util.ArtifactTestUtils;
+
+
+/**
+ * Tests {@link VnfCatalogExtractor}.
+ */
+public class VnfCatalogExtractorTest {
+
+ private static final String FOO = "foo";
+ private static final String SOME_BYTES = "just some bytes that will pass the firsts validation";
+ private static final String SUPPLY_AN_ARCHIVE = "An archive must be supplied for processing.";
+ private static final String SUPPLY_NAME = "The name of the archive must be supplied for processing.";
+
+ @Test
+ public void nullContentSupplied() {
+ invalidArgumentsTest(null, FOO, SUPPLY_AN_ARCHIVE);
+ }
+
+ @Test
+ public void emptyContentSupplied() {
+ invalidArgumentsTest(new byte[0], FOO, SUPPLY_AN_ARCHIVE);
+ }
+
+ @Test
+ public void nullNameSupplied() {
+ invalidArgumentsTest(SOME_BYTES.getBytes(), null, SUPPLY_NAME);
+ }
+
+ @Test
+ public void blankNameSupplied() {
+ invalidArgumentsTest("just some bytes that will pass the firsts validation".getBytes(), " \t ", SUPPLY_NAME);
+ }
+
+ @Test
+ public void emptyNameSupplied() {
+ invalidArgumentsTest("just some bytes that will pass the firsts validation".getBytes(), "", SUPPLY_NAME);
+ }
+
+ @Test
+ public void invalidContentSupplied() {
+ invalidArgumentsTest("This is a piece of nonsense and not a zip file".getBytes(), FOO,
+ "An error occurred trying to create a ZipFile. Is the content being converted really a csar file?");
+ }
+
+ @Test
+ public void archiveContainsNoVnfcFiles() throws InvalidArchiveException, IOException {
+ List<Artifact> vnfcArtifacts = new VnfCatalogExtractor().extract(
+ new ArtifactTestUtils().loadResource("compressedArtifacts/noVnfcFilesArchive.csar"),
+ "noVnfcFilesArchive.csar");
+ assertTrue("No VNFC files should have been extracted, but " + vnfcArtifacts.size() + " were found.",
+ vnfcArtifacts.isEmpty());
+ }
+
+ @Test
+ public void archiveContainsThreeRelevantVnfcFiles() throws IOException, InvalidArchiveException {
+ List<String> payloads = new ArrayList<>();
+ payloads.add("xmlFiles/vnfcatalog-1.xml");
+ payloads.add("xmlFiles/vnfcatalog-2.xml");
+ payloads.add("xmlFiles/vnfcatalog-3.xml");
+ String csarArchiveFile = "threeVnfcFilesArchive.csar";
+ performVnfcAsserts(new VnfCatalogExtractor().extract(
+ new ArtifactTestUtils().loadResource("compressedArtifacts/" + csarArchiveFile), csarArchiveFile),
+ payloads);
+ }
+
+ public void performVnfcAsserts(List<Artifact> actualVnfcArtifacts, List<String> expectedVnfcPayloadsToLoad) {
+ assertThat("An unexpected number of VNFC files have been extracted", actualVnfcArtifacts.size(),
+ is(expectedVnfcPayloadsToLoad.size()));
+
+ for (Artifact artifact : actualVnfcArtifacts) {
+ assertThat("Unexpected artifact type found.", artifact.getType(), is(ArtifactType.VNF_CATALOG_XML));
+ }
+
+ Set<String> expectedVnfcPayloads = expectedVnfcPayloadsToLoad.stream().map(s -> {
+ try {
+ return ArtifactTestUtils.loadResourceAsString(s);
+ } catch (IOException e) {
+ throw new RuntimeException(e);
+ }
+ }).collect(Collectors.toSet());
+
+ Set<String> actualVnfcPayloads =
+ actualVnfcArtifacts.stream().map(s -> s.getPayload()).collect(Collectors.toSet());
+
+ assertThat("Unexpected VNF Catalog file(s) found.", expectedVnfcPayloads.containsAll(actualVnfcPayloads),
+ is(true));
+ }
+
+ private void invalidArgumentsTest(byte[] archive, String name, String expectedErrorMessage) {
+ try {
+ new VnfCatalogExtractor().extract(archive, name);
+ fail("An instance of InvalidArchiveException should have been thrown");
+ } catch (Exception ex) {
+ assertTrue(ex instanceof InvalidArchiveException);
+ assertEquals(expectedErrorMessage, ex.getLocalizedMessage());
+ }
+ }
+
+}
+
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 b54bb20..cead699 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
@@ -41,6 +41,7 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
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;
@@ -80,6 +81,40 @@ public class TestVnfCatalogArtifactHandler {
assertPutOperationsSucceeded();
}
+ @Test
+ public void testUpdateVnfImagesFromXml() throws Exception {
+ // GET operation
+ OperationResult mockGetResp = mock(OperationResult.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());
+ // @formatter:on
+
+ when(mockRestClient.getResource(Mockito.anyString(), Mockito.anyString(), Mockito.any(MediaType.class)))
+ .thenReturn(mockGetResp);
+ mockPutOperations();
+
+ // Example VNF Catalog XML
+ VnfCatalogArtifactHandler handler = new VnfCatalogArtifactHandler(createConfig());
+ assertThat(
+ handler.pushArtifacts(createVnfCatalogXmlArtifact(), "test", new ArrayList<Artifact>(), mockRestClient),
+ is(true));
+
+ // 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));
+ assertThat(argument.getAllValues().size(), is(2));
+ assertThat(argument.getAllValues().get(0), containsString("5.2.5"));
+ assertThat(argument.getAllValues().get(0), containsString("VM00"));
+ assertThat(argument.getAllValues().get(1), containsString("5.2.4"));
+ assertThat(argument.getAllValues().get(1), containsString("VM00"));
+ }
+
private ModelLoaderConfig createConfig() {
Properties configProperties = new Properties();
try {
@@ -107,6 +142,20 @@ public class TestVnfCatalogArtifactHandler {
}
/**
+ * Example VNF Catalog based on VNF_CATALOG XML
+ *
+ * @return test Artifacts
+ * @throws IOException
+ * @throws UnsupportedEncodingException
+ */
+ private List<Artifact> createVnfCatalogXmlArtifact() throws IOException, UnsupportedEncodingException {
+ byte[] encoded = Files.readAllBytes(Paths.get("src/test/resources/xmlFiles/fortigate.xml"));
+ List<Artifact> artifacts = new ArrayList<Artifact>();
+ artifacts.add(new VnfCatalogArtifact(ArtifactType.VNF_CATALOG_XML, new String(encoded, "utf-8")));
+ return artifacts;
+ }
+
+ /**
* Always return CREATED (success) for a PUT operation.
*/
private void mockPutOperations() {
diff --git a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerVnfcTest.java b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerVnfcTest.java
new file mode 100644
index 0000000..6c7a77f
--- /dev/null
+++ b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerVnfcTest.java
@@ -0,0 +1,227 @@
+/**
+ * ============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.notification;
+
+import static org.hamcrest.CoreMatchers.is;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThat;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
+import org.onap.aai.babel.service.data.BabelArtifact;
+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.entity.catalog.VnfCatalogArtifact;
+import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
+import org.onap.aai.modelloader.entity.model.ModelArtifact;
+import org.onap.aai.modelloader.extraction.InvalidArchiveException;
+import org.onap.aai.modelloader.extraction.VnfCatalogExtractor;
+import org.onap.aai.modelloader.restclient.BabelServiceClient;
+import org.onap.aai.modelloader.restclient.BabelServiceClientException;
+import org.onap.aai.modelloader.service.BabelServiceClientFactory;
+import org.onap.aai.modelloader.util.ArtifactTestUtils;
+import org.onap.sdc.api.IDistributionClient;
+import org.onap.sdc.api.notification.IArtifactInfo;
+import org.onap.sdc.api.notification.INotificationData;
+import org.onap.sdc.api.results.IDistributionClientDownloadResult;
+import org.onap.sdc.impl.DistributionClientDownloadResultImpl;
+import org.onap.sdc.utils.DistributionActionResultEnum;
+
+/**
+ * Tests {@link ArtifactDownloadManager} with VNF Catalog Artifacts.
+ */
+public class ArtifactDownloadManagerVnfcTest {
+
+ private ArtifactDownloadManager downloadManager;
+ private BabelServiceClient mockBabelClient;
+ private IDistributionClient mockDistributionClient;
+ private NotificationPublisher mockNotificationPublisher;
+ private BabelArtifactConverter mockBabelArtifactConverter;
+ private BabelServiceClientFactory mockClientFactory;
+ private VnfCatalogExtractor mockVnfCatalogExtractor;
+
+ @Before
+ public void setup() throws Exception {
+ mockBabelClient = mock(BabelServiceClient.class);
+ mockDistributionClient = mock(IDistributionClient.class);
+ mockNotificationPublisher = mock(NotificationPublisher.class);
+ mockBabelArtifactConverter = mock(BabelArtifactConverter.class);
+ mockClientFactory = mock(BabelServiceClientFactory.class);
+ when(mockClientFactory.create(Mockito.any())).thenReturn(mockBabelClient);
+ mockVnfCatalogExtractor = mock(VnfCatalogExtractor.class);
+
+ Properties configProperties = new Properties();
+ configProperties.load(this.getClass().getClassLoader().getResourceAsStream("model-loader.properties"));
+ downloadManager = new ArtifactDownloadManager(mockDistributionClient,
+ new ModelLoaderConfig(configProperties, "."), mockClientFactory);
+
+
+ Whitebox.setInternalState(downloadManager, "notificationPublisher", mockNotificationPublisher);
+ Whitebox.setInternalState(downloadManager, "babelArtifactConverter", mockBabelArtifactConverter);
+ Whitebox.setInternalState(downloadManager, "vnfCatalogExtractor", mockVnfCatalogExtractor);
+ }
+
+ @Test
+ public void downloadArtifacts_validToscaVnfcCsarFile()
+ throws IOException, BabelServiceClientException, BabelArtifactParsingException, InvalidArchiveException {
+ INotificationData data = getNotificationDataWithToscaCsarFile();
+ IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
+
+ setupValidDownloadCsarMocks(data, artifactInfo);
+ when(mockBabelClient.postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(),
+ Matchers.anyString())).thenReturn(createBabelArtifacts());
+ when(mockVnfCatalogExtractor.extract(Matchers.any(), Matchers.anyString())).thenReturn(new ArrayList<>());
+
+ List<Artifact> modelArtifacts = new ArrayList<>();
+ List<Artifact> catalogFiles = new ArrayList<>();
+ assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles),
+ is(true));
+
+ assertEquals("There should have been some catalog files", 2, catalogFiles.size());
+ }
+
+ @Test
+ public void downloadArtifacts_validXmlVnfcCsarFile()
+ throws IOException, BabelServiceClientException, BabelArtifactParsingException, InvalidArchiveException {
+ INotificationData data = getNotificationDataWithToscaCsarFile();
+ IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
+
+ setupValidDownloadCsarMocks(data, artifactInfo);
+ when(mockBabelClient.postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(),
+ Matchers.anyString())).thenReturn(createBabelArtifactsNoVnfc());
+ when(mockVnfCatalogExtractor.extract(Matchers.any(), Matchers.anyString()))
+ .thenReturn(createXmlVnfcArtifacts());
+
+ List<Artifact> modelArtifacts = new ArrayList<>();
+ List<Artifact> catalogFiles = new ArrayList<>();
+ assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles),
+ is(true));
+
+ assertEquals("There should have been some catalog files", 3, catalogFiles.size());
+ }
+
+ @Test
+ public void downloadArtifacts_validNoVnfcCsarFile()
+ throws IOException, BabelServiceClientException, BabelArtifactParsingException, InvalidArchiveException {
+ INotificationData data = getNotificationDataWithToscaCsarFile();
+ IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
+
+ setupValidDownloadCsarMocks(data, artifactInfo);
+ when(mockBabelClient.postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(),
+ Matchers.anyString())).thenReturn(createBabelArtifactsNoVnfc());
+ when(mockVnfCatalogExtractor.extract(Matchers.any(), Matchers.anyString())).thenReturn(new ArrayList<>());
+
+ List<Artifact> modelArtifacts = new ArrayList<>();
+ List<Artifact> catalogFiles = new ArrayList<>();
+ assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles),
+ is(true));
+
+ assertEquals("There should not have been any catalog files", 0, catalogFiles.size());
+ }
+
+ @Test
+ public void downloadArtifacts_invalidXmlAndToscaVnfcCsarFile()
+ throws IOException, BabelServiceClientException, BabelArtifactParsingException, InvalidArchiveException {
+ INotificationData data = getNotificationDataWithToscaCsarFile();
+ IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
+
+ setupValidDownloadCsarMocks(data, artifactInfo);
+ when(mockBabelClient.postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(),
+ Matchers.anyString())).thenReturn(createBabelArtifacts());
+ when(mockVnfCatalogExtractor.extract(Matchers.any(), Matchers.anyString()))
+ .thenReturn(createXmlVnfcArtifacts());
+ doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifactInfo);
+
+ List<Artifact> modelArtifacts = new ArrayList<>();
+ List<Artifact> catalogFiles = new ArrayList<>();
+ assertThat(downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles),
+ is(false));
+
+ Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifactInfo);
+ }
+
+ private IDistributionClientDownloadResult createDistributionClientDownloadResult(
+ DistributionActionResultEnum status, String message, byte[] payload) {
+ IDistributionClientDownloadResult downloadResult = new DistributionClientDownloadResultImpl(status, message);
+
+ ((DistributionClientDownloadResultImpl) downloadResult).setArtifactPayload(payload);
+
+ return downloadResult;
+ }
+
+ private void setupValidDownloadCsarMocks(INotificationData data, IArtifactInfo artifactInfo)
+ throws IOException, BabelServiceClientException, BabelArtifactParsingException {
+ when(mockDistributionClient.download(artifactInfo))
+ .thenReturn(createDistributionClientDownloadResult(DistributionActionResultEnum.SUCCESS, null,
+ new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar")));
+ when(mockBabelArtifactConverter.convertToModel(Mockito.anyListOf(BabelArtifact.class)))
+ .thenReturn(createModelArtifacts());
+ when(mockBabelArtifactConverter.convertToCatalog(Mockito.anyListOf(BabelArtifact.class)))
+ .thenReturn(createToscaVnfcArtifacts());
+ }
+
+ private List<BabelArtifact> createBabelArtifacts() {
+ List<BabelArtifact> artifactList = new ArrayList<>();
+ artifactList.add(new BabelArtifact("ModelArtifact", BabelArtifact.ArtifactType.MODEL, "Some model payload"));
+ artifactList.add(new BabelArtifact("VNFCArtifact", BabelArtifact.ArtifactType.VNFCATALOG, "Some VNFC payload"));
+ return artifactList;
+ }
+
+ private List<BabelArtifact> createBabelArtifactsNoVnfc() {
+ List<BabelArtifact> artifactList = new ArrayList<>();
+ artifactList.add(new BabelArtifact("ModelArtifact", BabelArtifact.ArtifactType.MODEL, "Some model payload"));
+ return artifactList;
+ }
+
+ private List<Artifact> createModelArtifacts() {
+ List<Artifact> modelArtifacts = new ArrayList<>();
+ modelArtifacts.add(new ModelArtifact());
+ modelArtifacts.add(new ModelArtifact());
+ return modelArtifacts;
+ }
+
+ private List<Artifact> createToscaVnfcArtifacts() {
+ List<Artifact> vnfcArtifacts = new ArrayList<>();
+ vnfcArtifacts.add(new VnfCatalogArtifact("Some VNFC payload"));
+ vnfcArtifacts.add(new VnfCatalogArtifact("Some VNFC payload"));
+ return vnfcArtifacts;
+ }
+
+ private List<Artifact> createXmlVnfcArtifacts() {
+ List<Artifact> vnfcArtifacts = new ArrayList<>();
+ vnfcArtifacts.add(new VnfCatalogArtifact(ArtifactType.VNF_CATALOG_XML, "Some VNFC payload"));
+ vnfcArtifacts.add(new VnfCatalogArtifact(ArtifactType.VNF_CATALOG_XML, "Some VNFC payload"));
+ vnfcArtifacts.add(new VnfCatalogArtifact(ArtifactType.VNF_CATALOG_XML, "Some VNFC payload"));
+ return vnfcArtifacts;
+ }
+}
diff --git a/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderService.java b/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderService.java
index 8e07650..e40ca3c 100644
--- a/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderService.java
+++ b/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderService.java
@@ -56,7 +56,7 @@ public class TestModelLoaderService {
public void testMissingConfig() {
new ModelLoaderService().start();
}
-
+
@Test
public void testLoadModel() {
Response response = service.loadModel("");
@@ -80,7 +80,7 @@ public class TestModelLoaderService {
public void testIngestModelMissingName() throws IOException {
byte[] csarPayload = new ArtifactTestUtils().loadResource("compressedArtifacts/service-VscpaasTest-csar.csar");
Response response = service.ingestModel("", "", Base64.getEncoder().encodeToString(csarPayload));
- assertThat(response.getStatus(), is(Response.Status.OK.getStatusCode()));
+ assertThat(response.getStatus(), is(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()));
}
}
diff --git a/src/test/java/org/onap/aai/modelloader/util/TestJsonXmlConverter.java b/src/test/java/org/onap/aai/modelloader/util/TestJsonXmlConverter.java
index 4b7db56..81a4833 100644
--- a/src/test/java/org/onap/aai/modelloader/util/TestJsonXmlConverter.java
+++ b/src/test/java/org/onap/aai/modelloader/util/TestJsonXmlConverter.java
@@ -49,34 +49,34 @@ public class TestJsonXmlConverter {
@Test
public void testConversion() throws Exception {
- byte[] encoded = Files.readAllBytes(Paths.get(XML_MODEL_FILE));
- assertThat(JsonXmlConverter.isValidJson(new String(encoded)), is(false));
- encoded = Files.readAllBytes(Paths.get(JSON_MODEL_FILE));
+ byte[] encoded = Files.readAllBytes(Paths.get(XML_MODEL_FILE));
+ assertThat(JsonXmlConverter.isValidJson(new String(encoded)), is(false));
+ encoded = Files.readAllBytes(Paths.get(JSON_MODEL_FILE));
String originalJson = new String(encoded);
assertThat(JsonXmlConverter.isValidJson(originalJson), is(true));
String xmlFromJson = JsonXmlConverter.convertJsonToXml(originalJson);
- // Spot check one of the attributes
- DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
- factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
- DocumentBuilder builder = factory.newDocumentBuilder();
- Document doc = builder.parse(new ByteArrayInputStream(xmlFromJson.getBytes()));
- NodeList nodeList = doc.getDocumentElement().getChildNodes();
+ // Spot check one of the attributes
+ DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
+ factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
+ DocumentBuilder builder = factory.newDocumentBuilder();
+ Document doc = builder.parse(new ByteArrayInputStream(xmlFromJson.getBytes()));
+ NodeList nodeList = doc.getDocumentElement().getChildNodes();
- String modelVid = "notFound";
- for (int i = 0; i < nodeList.getLength(); i++) {
- Node currentNode = nodeList.item(i);
- if (currentNode.getNodeName().equals("model-invariant-id")) {
- modelVid = currentNode.getTextContent();
- break;
- }
+ String modelVid = "notFound";
+ for (int i = 0; i < nodeList.getLength(); i++) {
+ Node currentNode = nodeList.item(i);
+ if (currentNode.getNodeName().equals("model-invariant-id")) {
+ modelVid = currentNode.getTextContent();
+ break;
}
+ }
assertThat(modelVid.equals("3d560d81-57d0-438b-a2a1-5334dba0651a"), is(true));
- // Convert the XML form back into JSON
- JsonXmlConverter.convertXmlToJson(xmlFromJson);
+ // Convert the XML form back into JSON
+ JsonXmlConverter.convertXmlToJson(xmlFromJson);
}
}
diff --git a/src/test/resources/compressedArtifacts/noVnfcFilesArchive.csar b/src/test/resources/compressedArtifacts/noVnfcFilesArchive.csar
new file mode 100644
index 0000000..fa2a327
--- /dev/null
+++ b/src/test/resources/compressedArtifacts/noVnfcFilesArchive.csar
Binary files differ
diff --git a/src/test/resources/compressedArtifacts/threeVnfcFilesArchive.csar b/src/test/resources/compressedArtifacts/threeVnfcFilesArchive.csar
new file mode 100644
index 0000000..fc5080b
--- /dev/null
+++ b/src/test/resources/compressedArtifacts/threeVnfcFilesArchive.csar
Binary files differ
diff --git a/src/test/resources/xmlFiles/fortigate.xml b/src/test/resources/xmlFiles/fortigate.xml
new file mode 100644
index 0000000..16fce07
--- /dev/null
+++ b/src/test/resources/xmlFiles/fortigate.xml
@@ -0,0 +1,129 @@
+<vnf-catalog>
+ <part-number-list>
+ <part-number>FortiGate-VM00</part-number>
+ <vnf-type>FW</vnf-type>
+ <vendor-info>
+ <vendor-name>FORTINET</vendor-name>
+ <vendor-part-number>FortiGate-VM00</vendor-part-number>
+ <vendor-model>VM00</vendor-model>
+ </vendor-info>
+ <vcpu>
+ <vcpu-default>1</vcpu-default>
+ <vcpu-min>1</vcpu-min>
+ <vcpu-max>1</vcpu-max>
+ </vcpu>
+ <vmemory>
+ <vmemory-default>1</vmemory-default>
+ <vmemory-units>GB</vmemory-units>
+ <vmemory-min>1</vmemory-min>
+ <vmemory-max>1</vmemory-max>
+ </vmemory>
+ <vdisk>
+ <vdisk-default>2</vdisk-default>
+ <vdisk-units>GB</vdisk-units>
+ <vdisk-min>2</vdisk-min>
+ <vdisk-max>32</vdisk-max>
+ </vdisk>
+ <software-version-list>
+ <software-version>5.2.7</software-version>
+ <software-version-state>0</software-version-state>
+ <software-filetype>IMAGE</software-filetype>
+ <file-md5-value>1c59a521885c465004456f74d003726c</file-md5-value>
+ <software-filename>test3</software-filename>
+ </software-version-list>
+ <software-version-list>
+ <software-version>5.2.5</software-version>
+ <software-version-state>1</software-version-state>
+ <software-filetype>IMAGE</software-filetype>
+ <file-md5-value>C4D2CBE51669796E48623E006782F7DC</file-md5-value>
+ <software-filename>test2</software-filename>
+ </software-version-list>
+ <software-version-list>
+ <software-version>5.2.4</software-version>
+ <software-version-state>2</software-version-state>
+ <software-filetype>IMAGE</software-filetype>
+ <file-md5-value>4987E1E743FD641C879E1D3C5D50BCE0</file-md5-value>
+ <software-filename>test1</software-filename>
+ </software-version-list>
+ <vnf-features-list>
+ <vnf-feature>APPID</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>IPS-IDS</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>URLF</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>Anti-Virus</vnf-feature>
+ </vnf-features-list>
+ <license-list>
+ <license-assignment-group>FortiGate-VM00</license-assignment-group>
+ <license-required>FALSE</license-required>
+ </license-list>
+ </part-number-list>
+ <part-number-list>
+ <part-number>FortiGate-VM01</part-number>
+ <vnf-type>FW</vnf-type>
+ <vendor-info>
+ <vendor-name>FORTINET</vendor-name>
+ <vendor-part-number>FortiGate-VM01</vendor-part-number>
+ <vendor-model>VM01</vendor-model>
+ </vendor-info>
+ <vcpu>
+ <vcpu-default>1</vcpu-default>
+ <vcpu-min>1</vcpu-min>
+ <vcpu-max>1</vcpu-max>
+ </vcpu>
+ <vmemory>
+ <vmemory-default>2</vmemory-default>
+ <vmemory-units>GB</vmemory-units>
+ <vmemory-min>1</vmemory-min>
+ <vmemory-max>2</vmemory-max>
+ </vmemory>
+ <vdisk>
+ <vdisk-default>2</vdisk-default>
+ <vdisk-units>GB</vdisk-units>
+ <vdisk-min>2</vdisk-min>
+ <vdisk-max>32</vdisk-max>
+ </vdisk>
+ <software-version-list>
+ <software-version>5.2.7</software-version>
+ <software-version-state>0</software-version-state>
+ <software-filetype>IMAGE</software-filetype>
+ <file-md5-value>1c59a521885c465004456f74d003726c</file-md5-value>
+ <software-filename>software file name 3</software-filename>
+ </software-version-list>
+ <software-version-list>
+ <software-version>5.2.5</software-version>
+ <software-version-state>1</software-version-state>
+ <software-filetype>IMAGE</software-filetype>
+ <file-md5-value>C4D2CBE51669796E48623E006782F7DC</file-md5-value>
+ <software-filename>software file name 2</software-filename>
+ </software-version-list>
+ <software-version-list>
+ <software-version>5.2.4</software-version>
+ <software-version-state>2</software-version-state>
+ <software-filetype>IMAGE</software-filetype>
+ <file-md5-value>4987E1E743FD641C879E1D3C5D50BCE0</file-md5-value>
+ <software-filename>software file name</software-filename>
+ </software-version-list>
+ <vnf-features-list>
+ <vnf-feature>APPID</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>IPS-IDS</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>URLF</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>Anti-Virus</vnf-feature>
+ </vnf-features-list>
+ <license-list>
+ <license-assignment-group>license group</license-assignment-group>
+ <license-required>FALSE</license-required>
+ </license-list>
+ </part-number-list>
+
+</vnf-catalog> \ No newline at end of file
diff --git a/src/test/resources/xmlFiles/vnfcatalog-1.xml b/src/test/resources/xmlFiles/vnfcatalog-1.xml
new file mode 100644
index 0000000..979589c
--- /dev/null
+++ b/src/test/resources/xmlFiles/vnfcatalog-1.xml
@@ -0,0 +1,100 @@
+<vnf-catalog>
+ <part-number-list>
+ <att-part-number>att-part-number1</att-part-number>
+ <vnf-type>vnf-type1</vnf-type>
+ <vendor-info>
+ <vendor-name>vendor-name1</vendor-name>
+ <vendor-part-number>vendor-part-number1</vendor-part-number>
+ <vendor-model>vendor-model1</vendor-model>
+ </vendor-info>
+ <vcpu>
+ <vcpu-default>2</vcpu-default>
+ <vcpu-min>2</vcpu-min>
+ <vcpu-max>2</vcpu-max>
+ </vcpu>
+ <vmemory>
+ <vmemory-default>2</vmemory-default>
+ <vmemory-units>GB</vmemory-units>
+ <vmemory-min>2</vmemory-min>
+ <vmemory-max>2</vmemory-max>
+ </vmemory>
+ <vdisk>
+ <vdisk-default>50</vdisk-default>
+ <vdisk-units>GB</vdisk-units>
+ <vdisk-min>50</vdisk-min>
+ <vdisk-max>50</vdisk-max>
+ </vdisk>
+ <software-version-list>
+ <software-version>software-version1</software-version>
+ <software-version-state>0</software-version-state>
+ <software-filetype>IMAGE</software-filetype>
+ <file-md5-value>BE2B249315B4410896099CFD1AE1948C</file-md5-value>
+ <software-filename>software-filename1</software-filename>
+ </software-version-list>
+ <vnf-features-list>
+ <vnf-feature>APPID</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>IPS-IDS</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>URLF</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>Anti-Virus</vnf-feature>
+ </vnf-features-list>
+ <license-list>
+ <license-assignment-group>license-assignment-group1</license-assignment-group>
+ <license-required>TRUE</license-required>
+ </license-list>
+ </part-number-list>
+ <part-number-list>
+ <att-part-number>att-part-number2</att-part-number>
+ <vnf-type>vnf-type2</vnf-type>
+ <vendor-info>
+ <vendor-name>vendor-name2</vendor-name>
+ <vendor-part-number>vendor-part-number2</vendor-part-number>
+ <vendor-model>vendor-model2</vendor-model>
+ </vendor-info>
+ <vcpu>
+ <vcpu-default>2</vcpu-default>
+ <vcpu-min>2</vcpu-min>
+ <vcpu-max>2</vcpu-max>
+ </vcpu>
+ <vmemory>
+ <vmemory-default>2</vmemory-default>
+ <vmemory-units>GB</vmemory-units>
+ <vmemory-min>2</vmemory-min>
+ <vmemory-max>2</vmemory-max>
+ </vmemory>
+ <vdisk>
+ <vdisk-default>50</vdisk-default>
+ <vdisk-units>GB</vdisk-units>
+ <vdisk-min>50</vdisk-min>
+ <vdisk-max>50</vdisk-max>
+ </vdisk>
+ <software-version-list>
+ <software-version>software-version2</software-version>
+ <software-version-state>0</software-version-state>
+ <software-filetype>IMAGE</software-filetype>
+ <file-md5-value>BE2B249315B4410896099CFD1AE1948C</file-md5-value>
+ <software-filename>software-filename2</software-filename>
+ </software-version-list>
+ <vnf-features-list>
+ <vnf-feature>APPID</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>IPS-IDS</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>URLF</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>Anti-Virus</vnf-feature>
+ </vnf-features-list>
+ <license-list>
+ <license-assignment-group>license-assignment-group2</license-assignment-group>
+ <license-required>TRUE</license-required>
+ </license-list>
+ </part-number-list>
+</vnf-catalog> \ No newline at end of file
diff --git a/src/test/resources/xmlFiles/vnfcatalog-2.xml b/src/test/resources/xmlFiles/vnfcatalog-2.xml
new file mode 100644
index 0000000..9bcdac3
--- /dev/null
+++ b/src/test/resources/xmlFiles/vnfcatalog-2.xml
@@ -0,0 +1,100 @@
+<vnf-catalog>
+ <part-number-list>
+ <att-part-number>att-part-number3</att-part-number>
+ <vnf-type>vnf-type3</vnf-type>
+ <vendor-info>
+ <vendor-name>vendor-name3</vendor-name>
+ <vendor-part-number>vendor-part-number3</vendor-part-number>
+ <vendor-model>vendor-model3</vendor-model>
+ </vendor-info>
+ <vcpu>
+ <vcpu-default>2</vcpu-default>
+ <vcpu-min>2</vcpu-min>
+ <vcpu-max>2</vcpu-max>
+ </vcpu>
+ <vmemory>
+ <vmemory-default>2</vmemory-default>
+ <vmemory-units>GB</vmemory-units>
+ <vmemory-min>2</vmemory-min>
+ <vmemory-max>2</vmemory-max>
+ </vmemory>
+ <vdisk>
+ <vdisk-default>50</vdisk-default>
+ <vdisk-units>GB</vdisk-units>
+ <vdisk-min>50</vdisk-min>
+ <vdisk-max>50</vdisk-max>
+ </vdisk>
+ <software-version-list>
+ <software-version>software-version3</software-version>
+ <software-version-state>0</software-version-state>
+ <software-filetype>IMAGE</software-filetype>
+ <file-md5-value>BE2B249315B4410896099CFD1AE1948C</file-md5-value>
+ <software-filename>software-filename3</software-filename>
+ </software-version-list>
+ <vnf-features-list>
+ <vnf-feature>APPID</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>IPS-IDS</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>URLF</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>Anti-Virus</vnf-feature>
+ </vnf-features-list>
+ <license-list>
+ <license-assignment-group>license-assignment-group3</license-assignment-group>
+ <license-required>TRUE</license-required>
+ </license-list>
+ </part-number-list>
+ <part-number-list>
+ <att-part-number>att-part-number4</att-part-number>
+ <vnf-type>vnf-type4</vnf-type>
+ <vendor-info>
+ <vendor-name>vendor-name4</vendor-name>
+ <vendor-part-number>vendor-part-number4</vendor-part-number>
+ <vendor-model>vendor-model4</vendor-model>
+ </vendor-info>
+ <vcpu>
+ <vcpu-default>4</vcpu-default>
+ <vcpu-min>4</vcpu-min>
+ <vcpu-max>4</vcpu-max>
+ </vcpu>
+ <vmemory>
+ <vmemory-default>4</vmemory-default>
+ <vmemory-units>GB</vmemory-units>
+ <vmemory-min>4</vmemory-min>
+ <vmemory-max>4</vmemory-max>
+ </vmemory>
+ <vdisk>
+ <vdisk-default>50</vdisk-default>
+ <vdisk-units>GB</vdisk-units>
+ <vdisk-min>50</vdisk-min>
+ <vdisk-max>50</vdisk-max>
+ </vdisk>
+ <software-version-list>
+ <software-version>software-version4</software-version>
+ <software-version-state>0</software-version-state>
+ <software-filetype>IMAGE</software-filetype>
+ <file-md5-value>BE2B249315B4410896099CFD1AE1948C</file-md5-value>
+ <software-filename>software-filename4</software-filename>
+ </software-version-list>
+ <vnf-features-list>
+ <vnf-feature>APPID</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>IPS-IDS</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>URLF</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>Anti-Virus</vnf-feature>
+ </vnf-features-list>
+ <license-list>
+ <license-assignment-group>license-assignment-group4</license-assignment-group>
+ <license-required>TRUE</license-required>
+ </license-list>
+ </part-number-list>
+</vnf-catalog> \ No newline at end of file
diff --git a/src/test/resources/xmlFiles/vnfcatalog-3.xml b/src/test/resources/xmlFiles/vnfcatalog-3.xml
new file mode 100644
index 0000000..d420398
--- /dev/null
+++ b/src/test/resources/xmlFiles/vnfcatalog-3.xml
@@ -0,0 +1,100 @@
+<vnf-catalog>
+ <part-number-list>
+ <att-part-number>att-part-number5</att-part-number>
+ <vnf-type>vnf-type5</vnf-type>
+ <vendor-info>
+ <vendor-name>vendor-name5</vendor-name>
+ <vendor-part-number>vendor-part-number5</vendor-part-number>
+ <vendor-model>vendor-model5</vendor-model>
+ </vendor-info>
+ <vcpu>
+ <vcpu-default>2</vcpu-default>
+ <vcpu-min>2</vcpu-min>
+ <vcpu-max>2</vcpu-max>
+ </vcpu>
+ <vmemory>
+ <vmemory-default>2</vmemory-default>
+ <vmemory-units>GB</vmemory-units>
+ <vmemory-min>2</vmemory-min>
+ <vmemory-max>2</vmemory-max>
+ </vmemory>
+ <vdisk>
+ <vdisk-default>50</vdisk-default>
+ <vdisk-units>GB</vdisk-units>
+ <vdisk-min>50</vdisk-min>
+ <vdisk-max>50</vdisk-max>
+ </vdisk>
+ <software-version-list>
+ <software-version>software-version5</software-version>
+ <software-version-state>0</software-version-state>
+ <software-filetype>IMAGE</software-filetype>
+ <file-md5-value>BE2B249315B4410896099CFD1AE1948C</file-md5-value>
+ <software-filename>software-filename5</software-filename>
+ </software-version-list>
+ <vnf-features-list>
+ <vnf-feature>APPID</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>IPS-IDS</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>URLF</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>Anti-Virus</vnf-feature>
+ </vnf-features-list>
+ <license-list>
+ <license-assignment-group>license-assignment-group5</license-assignment-group>
+ <license-required>TRUE</license-required>
+ </license-list>
+ </part-number-list>
+ <part-number-list>
+ <att-part-number>att-part-number6</att-part-number>
+ <vnf-type>vnf-type6</vnf-type>
+ <vendor-info>
+ <vendor-name>vendor-name6</vendor-name>
+ <vendor-part-number>vendor-part-number6</vendor-part-number>
+ <vendor-model>vendor-model6</vendor-model>
+ </vendor-info>
+ <vcpu>
+ <vcpu-default>6</vcpu-default>
+ <vcpu-min>6</vcpu-min>
+ <vcpu-max>6</vcpu-max>
+ </vcpu>
+ <vmemory>
+ <vmemory-default>6</vmemory-default>
+ <vmemory-units>GB</vmemory-units>
+ <vmemory-min>6</vmemory-min>
+ <vmemory-max>6</vmemory-max>
+ </vmemory>
+ <vdisk>
+ <vdisk-default>50</vdisk-default>
+ <vdisk-units>GB</vdisk-units>
+ <vdisk-min>50</vdisk-min>
+ <vdisk-max>50</vdisk-max>
+ </vdisk>
+ <software-version-list>
+ <software-version>software-version6</software-version>
+ <software-version-state>0</software-version-state>
+ <software-filetype>IMAGE</software-filetype>
+ <file-md5-value>BE2B249315B4410896099CFD1AE1948C</file-md5-value>
+ <software-filename>software-filename6</software-filename>
+ </software-version-list>
+ <vnf-features-list>
+ <vnf-feature>APPID</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>IPS-IDS</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>URLF</vnf-feature>
+ </vnf-features-list>
+ <vnf-features-list>
+ <vnf-feature>Anti-Virus</vnf-feature>
+ </vnf-features-list>
+ <license-list>
+ <license-assignment-group>license-assignment-group6</license-assignment-group>
+ <license-required>TRUE</license-required>
+ </license-list>
+ </part-number-list>
+</vnf-catalog> \ No newline at end of file