summaryrefslogtreecommitdiffstats
path: root/src/test/java
diff options
context:
space:
mode:
authorBlimkie, Steven (sb787e) <steven.blimkie@amdocs.com>2017-05-15 20:15:44 +0300
committerBlimkie, Steven (sb787e) <steven.blimkie@amdocs.com>2017-05-16 17:08:31 +0300
commit4c0349b696a1a2d8990d9ec98c4df894c45acde5 (patch)
tree6a89174cdd609c9003571de8cc4dfd0fd0385f33 /src/test/java
parent0e51e3e43b9fce4934dc76d56f262542c3153282 (diff)
[AAI-3] Remove dependency on SDC
Change-Id: Iacdf8fb0dabdfe396f508dec3755ef1a2ea0210e Signed-off-by: Blimkie, Steven (sb787e) <steven.blimkie@amdocs.com>
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/org/openecomp/modelloader/config/ModelLoaderConfigTest.java260
-rw-r--r--src/test/java/org/openecomp/modelloader/entity/model/ModelSorterTest.java276
-rw-r--r--src/test/java/org/openecomp/modelloader/restclient/AaiRestClientTest.java242
3 files changed, 394 insertions, 384 deletions
diff --git a/src/test/java/org/openecomp/modelloader/config/ModelLoaderConfigTest.java b/src/test/java/org/openecomp/modelloader/config/ModelLoaderConfigTest.java
index 0d068d5..2c895b8 100644
--- a/src/test/java/org/openecomp/modelloader/config/ModelLoaderConfigTest.java
+++ b/src/test/java/org/openecomp/modelloader/config/ModelLoaderConfigTest.java
@@ -1,125 +1,135 @@
-/**
- * ============LICENSE_START=======================================================
- * Model Loader
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property.
- * Copyright © 2017 Amdocs
- * All rights reserved.
- * ================================================================================
- * 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=========================================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- */
-package org.openecomp.modelloader.config;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-
-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.Test;
-import org.openecomp.modelloader.restclient.AaiRestClient;
-
-import org.openecomp.sdc.utils.ArtifactTypeEnum;
-
-public class ModelLoaderConfigTest {
-
- @Test
- public void testYangModelArtifactType() {
- Properties props = new Properties();
- props.setProperty("ml.distribution.ARTIFACT_TYPES",
- "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG");
- ModelLoaderConfig config = new ModelLoaderConfig(props, null);
-
- List<String> types = config.getRelevantArtifactTypes();
-
- System.out.println("ArtifactType: " + types.get(0));
- assertEquals(0,
- types.get(0).compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()));
-
- System.out.println("ArtifactType: " + types.get(1));
- assertEquals(0, types.get(1).compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()));
-
- System.out.println("ArtifactType: " + types.get(2));
- assertEquals(0, types.get(2).compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()));
-
- assertEquals(3, types.size());
- }
-
- @Test
- public void testDecryptPassword() {
- Properties props = new Properties();
- String testPass = "youshallnotpass";
- String encryptedTestPass = Password.obfuscate(testPass);
-
- System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);
-
- props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, encryptedTestPass);
- ModelLoaderConfig config = new ModelLoaderConfig(props, null);
-
- assertEquals(testPass, config.getPassword());
- }
-
- @Test
- public void testDecryptKeystorePassword() {
- Properties props = new Properties();
- String testPass = "youshallnotpass";
- String encryptedTestPass = Password.obfuscate(testPass);
-
- System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);
-
- props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, encryptedTestPass);
- ModelLoaderConfig config = new ModelLoaderConfig(props, null);
-
- assertEquals(testPass, config.getKeyStorePassword());
- }
-
- @Test
- public void testDecryptAAIPassword() {
-
- Properties props = new Properties();
- String testPassword = "myvoiceismypassword";
- String encryptedTestPassword = Password.obfuscate(testPassword);
-
- props.put(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, encryptedTestPassword);
- ModelLoaderConfig config = new ModelLoaderConfig(props, null);
-
- assertEquals(testPassword, config.getAaiAuthenticationPassword());
- }
-
- @Test
- public void testNoAAIAuth() 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("Empty AAI Password should result in no basic authentication",
- aaiClient.useBasicAuth());
-
- props.load(new FileInputStream("src/test/resources/model-loader-no-auth-password.properties"));
- config = new ModelLoaderConfig(props, null);
- aaiClient = new AaiRestClient(config);
-
- assertFalse("No AAI Password should result in no basic authentication",
- aaiClient.useBasicAuth());
- }
-
-}
+/**
+ * ============LICENSE_START=======================================================
+ * Model Loader
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property.
+ * Copyright © 2017 Amdocs
+ * All rights reserved.
+ * ================================================================================
+ * 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=========================================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ */
+package org.openecomp.modelloader.config;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+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.Test;
+import org.openecomp.modelloader.restclient.AaiRestClient;
+
+import org.openecomp.sdc.utils.ArtifactTypeEnum;
+
+public class ModelLoaderConfigTest {
+
+ @Test
+ public void testYangModelArtifactType() {
+ Properties props = new Properties();
+ props.setProperty("ml.distribution.ARTIFACT_TYPES",
+ "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG");
+ ModelLoaderConfig config = new ModelLoaderConfig(props, null);
+
+ List<String> types = config.getRelevantArtifactTypes();
+
+ System.out.println("ArtifactType: " + types.get(0));
+ assertEquals(0,
+ types.get(0).compareToIgnoreCase(ArtifactTypeEnum.MODEL_INVENTORY_PROFILE.toString()));
+
+ System.out.println("ArtifactType: " + types.get(1));
+ assertEquals(0, types.get(1).compareToIgnoreCase(ArtifactTypeEnum.MODEL_QUERY_SPEC.toString()));
+
+ System.out.println("ArtifactType: " + types.get(2));
+ assertEquals(0, types.get(2).compareToIgnoreCase(ArtifactTypeEnum.VNF_CATALOG.toString()));
+
+ assertEquals(3, types.size());
+ }
+
+ @Test
+ public void testDecryptPassword() {
+ Properties props = new Properties();
+ String testPass = "youshallnotpass";
+ String encryptedTestPass = Password.obfuscate(testPass);
+
+ System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);
+
+ props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, encryptedTestPass);
+ ModelLoaderConfig config = new ModelLoaderConfig(props, null);
+
+ assertEquals(testPass, config.getPassword());
+ }
+
+ @Test
+ public void testDecryptKeystorePassword() {
+ Properties props = new Properties();
+ String testPass = "youshallnotpass";
+ String encryptedTestPass = Password.obfuscate(testPass);
+
+ System.out.println("Encrypt " + testPass + " ==> " + encryptedTestPass);
+
+ props.put(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, encryptedTestPass);
+ ModelLoaderConfig config = new ModelLoaderConfig(props, null);
+
+ assertEquals(testPass, config.getKeyStorePassword());
+ }
+
+ @Test
+ public void testDecryptAAIPassword() {
+
+ Properties props = new Properties();
+ String testPassword = "myvoiceismypassword";
+ String encryptedTestPassword = Password.obfuscate(testPassword);
+
+ props.put(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, encryptedTestPassword);
+ ModelLoaderConfig config = new ModelLoaderConfig(props, null);
+
+ assertEquals(testPassword, config.getAaiAuthenticationPassword());
+ }
+
+ @Test
+ public void testNoAAIAuth() 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("Empty AAI Password should result in no basic authentication",
+ aaiClient.useBasicAuth());
+
+ props.load(new FileInputStream("src/test/resources/model-loader-no-auth-password.properties"));
+ config = new ModelLoaderConfig(props, null);
+ aaiClient = new AaiRestClient(config);
+
+ assertFalse("No AAI Password should result in no basic authentication",
+ aaiClient.useBasicAuth());
+ }
+
+ @Test
+ public void testGetUrls() {
+ Properties props = new Properties();
+ props.put(ModelLoaderConfig.PROP_AAI_MODEL_RESOURCE_URL, "/aai/v*/service-design-and-creation/models/model/");
+ props.put(ModelLoaderConfig.PROP_AAI_NAMED_QUERY_RESOURCE_URL, "/aai/v*/service-design-and-creation/named-queries/named-query/");
+ ModelLoaderConfig config = new ModelLoaderConfig(props, null);
+
+ assertEquals("/aai/v9/service-design-and-creation/models/model/", config.getAaiModelUrl("v9"));
+ assertEquals("/aai/v10/service-design-and-creation/named-queries/named-query/", config.getAaiNamedQueryUrl("v10"));
+ }
+}
diff --git a/src/test/java/org/openecomp/modelloader/entity/model/ModelSorterTest.java b/src/test/java/org/openecomp/modelloader/entity/model/ModelSorterTest.java
index 6a9cf88..03eaa39 100644
--- a/src/test/java/org/openecomp/modelloader/entity/model/ModelSorterTest.java
+++ b/src/test/java/org/openecomp/modelloader/entity/model/ModelSorterTest.java
@@ -1,138 +1,138 @@
-/**
- * ============LICENSE_START=======================================================
- * Model Loader
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property.
- * Copyright © 2017 Amdocs
- * All rights reserved.
- * ================================================================================
- * 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=========================================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- */
-package org.openecomp.modelloader.entity.model;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-import org.junit.Test;
-import org.openecomp.modelloader.entity.Artifact;
-
-public class ModelSorterTest {
-
- @Test
- public void noModels() {
-
- List<Artifact> emptyList = Collections.emptyList();
-
- ModelSorter sorter = new ModelSorter();
- sorter = new ModelSorter();
-
- List<Artifact> sortedList = sorter.sort(emptyList);
- assertNotNull(sortedList);
- assertEquals(0, sortedList.size());
-
- }
-
- @Test
- public void singleModel() {
-
- List<Artifact> modelList = new ArrayList<Artifact>();
-
- ModelArtifact model = new ModelArtifact();
- model.setNameVersionId("aaaaa");
- model.addDependentModelId("xyz");
- modelList.add(model);
-
- ModelSorter sorter = new ModelSorter();
- sorter = new ModelSorter();
-
- List<Artifact> sortedList = sorter.sort(modelList);
- assertNotNull(sortedList);
- assertEquals(1, sortedList.size());
-
- }
-
- /**
- *
- * depends on depends on B ------> A -------> C
- *
- *
- * Input list = a, b, c Sorted list = c, a, b
- *
- */
- @Test
- public void multipleModels() {
-
- List<Artifact> modelList = new ArrayList<Artifact>();
-
- ModelArtifact aaaa = new ModelArtifact();
- aaaa.setModelInvariantId("aaaa");
- aaaa.setModelVerId("mvaaaa");
- aaaa.addDependentModelId("cccc|mvcccc");
-
- ModelArtifact bbbb = new ModelArtifact();
- bbbb.setModelInvariantId("bbbb");
- bbbb.setModelVerId("mvbbbb");
- bbbb.addDependentModelId("aaaa|mvaaaa");
-
- ModelArtifact cccc = new ModelArtifact();
- cccc.setModelInvariantId("cccc");
- cccc.setModelVerId("mvcccc");
-
- modelList.add(aaaa);
- modelList.add(bbbb);
- modelList.add(cccc);
-
- ModelSorter sorter = new ModelSorter();
- sorter = new ModelSorter();
-
- List<Artifact> sortedList = sorter.sort(modelList);
- assertNotNull(sortedList);
- assertEquals(3, sortedList.size());
-
- assertEquals(cccc, sortedList.get(0));
- assertEquals(aaaa, sortedList.get(1));
- assertEquals(bbbb, sortedList.get(2));
- }
-
- @Test(expected = RuntimeException.class)
- public void circularDependency() {
-
- List<Artifact> modelList = new ArrayList<Artifact>();
-
- ModelArtifact aaaa = new ModelArtifact();
- aaaa.setNameVersionId("aaaa");
- aaaa.addDependentModelId("bbbb");
-
- ModelArtifact bbbb = new ModelArtifact();
- bbbb.setNameVersionId("bbbb");
- bbbb.addDependentModelId("aaaa");
-
- modelList.add(aaaa);
- modelList.add(bbbb);
-
- ModelSorter sorter = new ModelSorter();
- sorter = new ModelSorter();
-
- List<Artifact> sortedList = sorter.sort(modelList);
- assertNotNull(sortedList);
- assertEquals(3, sortedList.size());
-
- }
-
-}
+/**
+ * ============LICENSE_START=======================================================
+ * Model Loader
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property.
+ * Copyright © 2017 Amdocs
+ * All rights reserved.
+ * ================================================================================
+ * 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=========================================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ */
+package org.openecomp.modelloader.entity.model;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+import org.junit.Test;
+import org.openecomp.modelloader.entity.Artifact;
+
+public class ModelSorterTest {
+
+ @Test
+ public void noModels() {
+
+ List<Artifact> emptyList = Collections.emptyList();
+
+ ModelSorter sorter = new ModelSorter();
+ sorter = new ModelSorter();
+
+ List<Artifact> sortedList = sorter.sort(emptyList);
+ assertNotNull(sortedList);
+ assertEquals(0, sortedList.size());
+
+ }
+
+ @Test
+ public void singleModel() {
+
+ List<Artifact> modelList = new ArrayList<Artifact>();
+
+ ModelArtifact model = new ModelArtifact();
+ model.setNameVersionId("aaaaa");
+ model.addDependentModelId("xyz");
+ modelList.add(model);
+
+ ModelSorter sorter = new ModelSorter();
+ sorter = new ModelSorter();
+
+ List<Artifact> sortedList = sorter.sort(modelList);
+ assertNotNull(sortedList);
+ assertEquals(1, sortedList.size());
+
+ }
+
+ /**
+ *
+ * depends on depends on B ------> A -------> C
+ *
+ *
+ * Input list = a, b, c Sorted list = c, a, b
+ *
+ */
+ @Test
+ public void multipleModels() {
+
+ List<Artifact> modelList = new ArrayList<Artifact>();
+
+ ModelArtifact aaaa = new ModelArtifact();
+ aaaa.setModelInvariantId("aaaa");
+ aaaa.setModelVerId("mvaaaa");
+ aaaa.addDependentModelId("cccc|mvcccc");
+
+ ModelArtifact bbbb = new ModelArtifact();
+ bbbb.setModelInvariantId("bbbb");
+ bbbb.setModelVerId("mvbbbb");
+ bbbb.addDependentModelId("aaaa|mvaaaa");
+
+ ModelArtifact cccc = new ModelArtifact();
+ cccc.setModelInvariantId("cccc");
+ cccc.setModelVerId("mvcccc");
+
+ modelList.add(aaaa);
+ modelList.add(bbbb);
+ modelList.add(cccc);
+
+ ModelSorter sorter = new ModelSorter();
+ sorter = new ModelSorter();
+
+ List<Artifact> sortedList = sorter.sort(modelList);
+ assertNotNull(sortedList);
+ assertEquals(3, sortedList.size());
+
+ assertEquals(cccc, sortedList.get(0));
+ assertEquals(aaaa, sortedList.get(1));
+ assertEquals(bbbb, sortedList.get(2));
+ }
+
+ @Test(expected = RuntimeException.class)
+ public void circularDependency() {
+
+ List<Artifact> modelList = new ArrayList<Artifact>();
+
+ ModelArtifact aaaa = new ModelArtifact();
+ aaaa.setNameVersionId("aaaa");
+ aaaa.addDependentModelId("bbbb");
+
+ ModelArtifact bbbb = new ModelArtifact();
+ bbbb.setNameVersionId("bbbb");
+ bbbb.addDependentModelId("aaaa");
+
+ modelList.add(aaaa);
+ modelList.add(bbbb);
+
+ ModelSorter sorter = new ModelSorter();
+ sorter = new ModelSorter();
+
+ List<Artifact> sortedList = sorter.sort(modelList);
+ assertNotNull(sortedList);
+ assertEquals(2, sortedList.size());
+
+ }
+
+}
diff --git a/src/test/java/org/openecomp/modelloader/restclient/AaiRestClientTest.java b/src/test/java/org/openecomp/modelloader/restclient/AaiRestClientTest.java
index dc6f9d6..5d9edc9 100644
--- a/src/test/java/org/openecomp/modelloader/restclient/AaiRestClientTest.java
+++ b/src/test/java/org/openecomp/modelloader/restclient/AaiRestClientTest.java
@@ -1,121 +1,121 @@
-/**
- * ============LICENSE_START=======================================================
- * Model Loader
- * ================================================================================
- * Copyright © 2017 AT&T Intellectual Property.
- * Copyright © 2017 Amdocs
- * All rights reserved.
- * ================================================================================
- * 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=========================================================
- *
- * ECOMP and OpenECOMP are trademarks
- * and service marks of AT&T Intellectual Property.
- */
-package org.openecomp.modelloader.restclient;
-
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-
-import org.openecomp.modelloader.config.ModelLoaderConfig;
-import org.openecomp.modelloader.entity.ArtifactType;
-import org.openecomp.modelloader.entity.model.ModelArtifact;
-
-public class AaiRestClientTest {
-
- // This test requires a running A&AI system. Uncomment to test locally.
- /*
- * @Test public void testRestClient() throws Exception { final String
- * MODEL_FILE = "src/test/resources/models/vnf-model.xml";
- *
- * Properties props = new Properties();
- * props.setProperty("ml.distribution.ARTIFACT_TYPES",
- * "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG");
- * props.setProperty("ml.aai.BASE_URL", "https://127.0.0.1:4321");
- * props.setProperty("ml.aai.MODEL_URL",
- * "/aai/v8/service-design-and-creation/models/model/");
- * props.setProperty("ml.aai.KEYSTORE_FILE", "aai-client-cert.p12");
- * props.setProperty("ml.aai.KEYSTORE_PASSWORD",
- * "OBF:1i9a1u2a1unz1lr61wn51wn11lss1unz1u301i6o");
- *
- * ModelLoaderConfig config = new ModelLoaderConfig(props, "");
- *
- * String payload = readFile(MODEL_FILE); System.out.println("FILE:" +
- * payload);
- *
- * File xmlFile = new File(MODEL_FILE); DocumentBuilderFactory dbFactory =
- * DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder =
- * dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(xmlFile);
- *
- * // Get the ID of the model String modelId = null; NodeList nodeList =
- * doc.getDocumentElement().getChildNodes(); for (int i = 0; i <
- * nodeList.getLength(); i++) { Node currentNode = nodeList.item(i); if
- * (currentNode.getNodeName().equals("model-name-version-id")) { modelId =
- * currentNode.getTextContent(); break; } }
- *
- * // Add the model try { ModelArtifact model = new ModelArtifact();
- * model.setNameVersionId(modelId); model.setType(ArtifactType.MODEL);
- * model.setPayload(payload);
- *
- * AAIRestClient aaiClient = new AAIRestClient(config);
- *
- * // GET model System.out.println("Calling GET API ..."); ClientResponse
- * getResponse = aaiClient.getResource(getURL(model, config),
- * "example-trans-id-0", AAIRestClient.MimeType.XML); System.out.println(
- * "GET result: " + getResponse.getStatus());
- * assertTrue(getResponse.getStatus() ==
- * Response.Status.NOT_FOUND.getStatusCode());
- *
- * // Add the model System.out.println("Calling PUT API ..."); ClientResponse
- * res = aaiClient.putResource(getURL(model, config), model.getPayload(),
- * "example-trans-id-1", AAIRestClient.MimeType.XML); System.out.println(
- * "PUT result: " + res.getStatus()); assertTrue(res.getStatus() ==
- * Response.Status.CREATED.getStatusCode());
- *
- * // Delete the model System.out.println("Calling DELETE API ..."); res =
- * aaiClient.getAndDeleteResource(getURL(model, config),
- * "example-trans-id-3"); System.out.println("DELETE result: " +
- * res.getStatus()); assertTrue(res.getStatus() ==
- * Response.Status.NO_CONTENT.getStatusCode()); } catch (Exception e) {
- * e.printStackTrace(); } }
- */
-
- static String readFile(String path) throws IOException {
- byte[] encoded = Files.readAllBytes(Paths.get(path));
- return new String(encoded);
- }
-
- private String getURL(ModelArtifact model, ModelLoaderConfig config) {
- String baseURL = config.getAaiBaseUrl().trim();
- String subURL = null;
- if (model.getType().equals(ArtifactType.MODEL)) {
- subURL = config.getAaiModelUrl().trim();
- } else {
- subURL = config.getAaiNamedQueryUrl().trim();
- }
-
- if ((!baseURL.endsWith("/")) && (!subURL.startsWith("/"))) {
- baseURL = baseURL + "/";
- }
-
- if (baseURL.endsWith("/") && subURL.startsWith("/")) {
- baseURL = baseURL.substring(0, baseURL.length() - 1);
- }
-
- if (!subURL.endsWith("/")) {
- subURL = subURL + "/";
- }
-
- String url = baseURL + subURL + model.getNameVersionId();
- return url;
- }
-}
+/**
+ * ============LICENSE_START=======================================================
+ * Model Loader
+ * ================================================================================
+ * Copyright © 2017 AT&T Intellectual Property.
+ * Copyright © 2017 Amdocs
+ * All rights reserved.
+ * ================================================================================
+ * 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=========================================================
+ *
+ * ECOMP and OpenECOMP are trademarks
+ * and service marks of AT&T Intellectual Property.
+ */
+package org.openecomp.modelloader.restclient;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+
+import org.openecomp.modelloader.config.ModelLoaderConfig;
+import org.openecomp.modelloader.entity.ArtifactType;
+import org.openecomp.modelloader.entity.model.ModelArtifact;
+
+public class AaiRestClientTest {
+
+ // This test requires a running A&AI system. Uncomment to test locally.
+ /*
+ * @Test public void testRestClient() throws Exception { final String
+ * MODEL_FILE = "src/test/resources/models/vnf-model.xml";
+ *
+ * Properties props = new Properties();
+ * props.setProperty("ml.distribution.ARTIFACT_TYPES",
+ * "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG");
+ * props.setProperty("ml.aai.BASE_URL", "https://127.0.0.1:4321");
+ * props.setProperty("ml.aai.MODEL_URL",
+ * "/aai/v8/service-design-and-creation/models/model/");
+ * props.setProperty("ml.aai.KEYSTORE_FILE", "aai-client-cert.p12");
+ * props.setProperty("ml.aai.KEYSTORE_PASSWORD",
+ * "OBF:1i9a1u2a1unz1lr61wn51wn11lss1unz1u301i6o");
+ *
+ * ModelLoaderConfig config = new ModelLoaderConfig(props, "");
+ *
+ * String payload = readFile(MODEL_FILE); System.out.println("FILE:" +
+ * payload);
+ *
+ * File xmlFile = new File(MODEL_FILE); DocumentBuilderFactory dbFactory =
+ * DocumentBuilderFactory.newInstance(); DocumentBuilder dBuilder =
+ * dbFactory.newDocumentBuilder(); Document doc = dBuilder.parse(xmlFile);
+ *
+ * // Get the ID of the model String modelId = null; NodeList nodeList =
+ * doc.getDocumentElement().getChildNodes(); for (int i = 0; i <
+ * nodeList.getLength(); i++) { Node currentNode = nodeList.item(i); if
+ * (currentNode.getNodeName().equals("model-name-version-id")) { modelId =
+ * currentNode.getTextContent(); break; } }
+ *
+ * // Add the model try { ModelArtifact model = new ModelArtifact();
+ * model.setNameVersionId(modelId); model.setType(ArtifactType.MODEL);
+ * model.setPayload(payload);
+ *
+ * AAIRestClient aaiClient = new AAIRestClient(config);
+ *
+ * // GET model System.out.println("Calling GET API ..."); ClientResponse
+ * getResponse = aaiClient.getResource(getURL(model, config),
+ * "example-trans-id-0", AAIRestClient.MimeType.XML); System.out.println(
+ * "GET result: " + getResponse.getStatus());
+ * assertTrue(getResponse.getStatus() ==
+ * Response.Status.NOT_FOUND.getStatusCode());
+ *
+ * // Add the model System.out.println("Calling PUT API ..."); ClientResponse
+ * res = aaiClient.putResource(getURL(model, config), model.getPayload(),
+ * "example-trans-id-1", AAIRestClient.MimeType.XML); System.out.println(
+ * "PUT result: " + res.getStatus()); assertTrue(res.getStatus() ==
+ * Response.Status.CREATED.getStatusCode());
+ *
+ * // Delete the model System.out.println("Calling DELETE API ..."); res =
+ * aaiClient.getAndDeleteResource(getURL(model, config),
+ * "example-trans-id-3"); System.out.println("DELETE result: " +
+ * res.getStatus()); assertTrue(res.getStatus() ==
+ * Response.Status.NO_CONTENT.getStatusCode()); } catch (Exception e) {
+ * e.printStackTrace(); } }
+ */
+
+ static String readFile(String path) throws IOException {
+ byte[] encoded = Files.readAllBytes(Paths.get(path));
+ return new String(encoded);
+ }
+
+ private String getURL(ModelArtifact model, ModelLoaderConfig config) {
+ String baseURL = config.getAaiBaseUrl().trim();
+ String subURL = null;
+ if (model.getType().equals(ArtifactType.MODEL)) {
+ subURL = config.getAaiModelUrl(model.getModelNamespaceVersion()).trim();
+ } else {
+ subURL = config.getAaiNamedQueryUrl(model.getModelNamespaceVersion()).trim();
+ }
+
+ if ((!baseURL.endsWith("/")) && (!subURL.startsWith("/"))) {
+ baseURL = baseURL + "/";
+ }
+
+ if (baseURL.endsWith("/") && subURL.startsWith("/")) {
+ baseURL = baseURL.substring(0, baseURL.length() - 1);
+ }
+
+ if (!subURL.endsWith("/")) {
+ subURL = subURL + "/";
+ }
+
+ String url = baseURL + subURL + model.getNameVersionId();
+ return url;
+ }
+}