diff options
Diffstat (limited to 'src/test/java/org/onap')
25 files changed, 1269 insertions, 648 deletions
diff --git a/src/test/java/org/onap/aai/modelloader/config/ModelLoaderConfigTest.java b/src/test/java/org/onap/aai/modelloader/config/ModelLoaderConfigTest.java index 1b6b847..e8060e2 100644 --- a/src/test/java/org/onap/aai/modelloader/config/ModelLoaderConfigTest.java +++ b/src/test/java/org/onap/aai/modelloader/config/ModelLoaderConfigTest.java @@ -1,193 +1,192 @@ -/**
- * ============LICENSE_START==========================================
- * org.onap.aai
- * ===================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ===================================================================
- * 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.config;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.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.Test;
-import org.onap.aai.modelloader.restclient.AaiRestClient;
-import org.openecomp.sdc.utils.ArtifactTypeEnum;
-
-/**
- * Tests for ModelLoaderConfig class
- *
- */
-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 testMsgBusAddrs() {
- Properties props = new Properties();
- props.setProperty("ml.distribution.MSG_BUS_ADDRESSES", "host1.onap.com:3904,host2.onap.com:3904");
- ModelLoaderConfig config = new ModelLoaderConfig(props, null);
-
- List<String> addrs = config.getMsgBusAddress();
-
- assertEquals(2, addrs.size());
- assertEquals(0, addrs.get(0).compareToIgnoreCase("host1.onap.com:3904"));
- assertEquals(0, addrs.get(1).compareToIgnoreCase("host2.onap.com:3904"));
- }
-
- @Test
- public void testDecryptPassword() {
- String password = "youshallnotpass";
- ModelLoaderConfig config =
- createObfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, password);
- assertEquals(password, config.getPassword());
- }
-
- @Test
- public void testDecryptKeystorePassword() {
- String password = "youshallnotpass";
- ModelLoaderConfig config =
- createObfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, password);
- assertEquals(password, config.getKeyStorePassword());
- }
-
- @Test
- public void testDecryptAAIAuthenticationPassword() {
- String password = "myvoiceismypassword";
- ModelLoaderConfig config =
- createObfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, password);
- assertEquals(password, config.getAaiAuthenticationPassword());
- }
-
- @Test
- public void testDecryptAAIKeystorePassword() {
- String password = "myvoiceismypassword";
- ModelLoaderConfig config = createObfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_KEYSTORE_PASSWORD, password);
- assertEquals(password, config.getAaiKeyStorePassword());
- }
-
- @Test
- public void testAaiBaseUrl() {
- String url = "http://localhost:1234/";
- Properties props = new Properties();
- props.put(ModelLoaderConfig.PROP_AAI_BASE_URL, url);
- ModelLoaderConfig config = new ModelLoaderConfig(props, null);
- assertEquals(url, config.getAaiBaseUrl());
- }
-
- @Test
- public void testDecryptBabelKeystorePassword() {
- String password = "babelpassword";
- ModelLoaderConfig config = createObfuscatedTestConfig(ModelLoaderConfig.PROP_BABEL_KEYSTORE_PASSWORD, password);
- assertEquals(password, config.getBabelKeyStorePassword());
- }
-
- @Test
- public void testBabelKeystorePath() {
- String root = "path_to_keystore";
- String path = "relative_keystore_path";
- Properties props = new Properties();
- props.put(ModelLoaderConfig.PROP_BABEL_KEYSTORE_FILE, path);
- ModelLoaderConfig config = new ModelLoaderConfig(props, root);
- assertEquals(root + File.separator + path, config.getBabelKeyStorePath());
- }
-
- @Test
- public void testBabelBaseUrl() {
- String url = "http://localhost/";
- Properties props = new Properties();
- props.put(ModelLoaderConfig.PROP_BABEL_BASE_URL, url);
- ModelLoaderConfig config = new ModelLoaderConfig(props, null);
- assertEquals(url, config.getBabelBaseUrl());
- }
-
- @Test
- public void testBabelGenerateArtifactsUrl() {
- String url = "/path/to/the/resource";
- Properties props = new Properties();
- props.put(ModelLoaderConfig.PROP_BABEL_GENERATE_RESOURCE_URL, url);
- ModelLoaderConfig config = new ModelLoaderConfig(props, null);
- assertEquals(url, config.getBabelGenerateArtifactsUrl());
- }
-
- @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"));
- }
-
-
- /**
- * @param propertyName
- * @param propertyValue
- * @return a new ModelLoaderConfig object containing a single obfuscated property value
- */
- private ModelLoaderConfig createObfuscatedTestConfig(String propertyName, String propertyValue) {
- Properties props = new Properties();
- props.put(propertyName, Password.obfuscate(propertyValue));
- return new ModelLoaderConfig(props, null);
- }
-}
+/** + * ============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.config; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.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.Test; +import org.onap.aai.modelloader.restclient.AaiRestClient; +import org.onap.sdc.utils.ArtifactTypeEnum; + +/** + * Tests for ModelLoaderConfig class + * + */ +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 testMsgBusAddrs() { + Properties props = new Properties(); + props.setProperty("ml.distribution.MSG_BUS_ADDRESSES", "host1.onap.com:3904,host2.onap.com:3904"); + ModelLoaderConfig config = new ModelLoaderConfig(props, null); + + List<String> addrs = config.getMsgBusAddress(); + + assertEquals(2, addrs.size()); + assertEquals(0, addrs.get(0).compareToIgnoreCase("host1.onap.com:3904")); + assertEquals(0, addrs.get(1).compareToIgnoreCase("host2.onap.com:3904")); + } + + @Test + public void testDecryptPassword() { + String password = "youshallnotpass"; + ModelLoaderConfig config = + createObfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_PASSWORD, password); + assertEquals(password, config.getPassword()); + } + + @Test + public void testDecryptKeystorePassword() { + String password = "youshallnotpass"; + ModelLoaderConfig config = + createObfuscatedTestConfig(ModelLoaderConfig.PROP_ML_DISTRIBUTION_KEYSTORE_PASSWORD, password); + assertEquals(password, config.getKeyStorePassword()); + } + + @Test + public void testDecryptAAIAuthenticationPassword() { + String password = "myvoiceismypassword"; + ModelLoaderConfig config = + createObfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_AUTHENTICATION_PASSWORD, password); + assertEquals(password, config.getAaiAuthenticationPassword()); + } + + @Test + public void testDecryptAAIKeystorePassword() { + String password = "myvoiceismypassword"; + ModelLoaderConfig config = createObfuscatedTestConfig(ModelLoaderConfig.PROP_AAI_KEYSTORE_PASSWORD, password); + assertEquals(password, config.getAaiKeyStorePassword()); + } + + @Test + public void testAaiBaseUrl() { + String url = "http://localhost:1234/"; + Properties props = new Properties(); + props.put(ModelLoaderConfig.PROP_AAI_BASE_URL, url); + ModelLoaderConfig config = new ModelLoaderConfig(props, null); + assertEquals(url, config.getAaiBaseUrl()); + } + + @Test + public void testDecryptBabelKeystorePassword() { + String password = "babelpassword"; + ModelLoaderConfig config = createObfuscatedTestConfig(ModelLoaderConfig.PROP_BABEL_KEYSTORE_PASSWORD, password); + assertEquals(password, config.getBabelKeyStorePassword()); + } + + @Test + public void testBabelKeystorePath() { + String root = "path_to_keystore"; + String path = "relative_keystore_path"; + Properties props = new Properties(); + props.put(ModelLoaderConfig.PROP_BABEL_KEYSTORE_FILE, path); + ModelLoaderConfig config = new ModelLoaderConfig(props, root); + assertEquals(root + File.separator + path, config.getBabelKeyStorePath()); + } + + @Test + public void testBabelBaseUrl() { + String url = "http://localhost/"; + Properties props = new Properties(); + props.put(ModelLoaderConfig.PROP_BABEL_BASE_URL, url); + ModelLoaderConfig config = new ModelLoaderConfig(props, null); + assertEquals(url, config.getBabelBaseUrl()); + } + + @Test + public void testBabelGenerateArtifactsUrl() { + String url = "/path/to/the/resource"; + Properties props = new Properties(); + props.put(ModelLoaderConfig.PROP_BABEL_GENERATE_RESOURCE_URL, url); + ModelLoaderConfig config = new ModelLoaderConfig(props, null); + assertEquals(url, config.getBabelGenerateArtifactsUrl()); + } + + @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")); + } + + + /** + * @param propertyName + * @param propertyValue + * @return a new ModelLoaderConfig object containing a single obfuscated property value + */ + private ModelLoaderConfig createObfuscatedTestConfig(String propertyName, String propertyValue) { + Properties props = new Properties(); + props.put(propertyName, Password.obfuscate(propertyValue)); + return new ModelLoaderConfig(props, null); + } +} diff --git a/src/test/java/org/onap/aai/modelloader/entity/catalog/TestVnfImageException.java b/src/test/java/org/onap/aai/modelloader/entity/catalog/TestVnfImageException.java new file mode 100644 index 0000000..a41ddf9 --- /dev/null +++ b/src/test/java/org/onap/aai/modelloader/entity/catalog/TestVnfImageException.java @@ -0,0 +1,49 @@ +/** + * ============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.entity.catalog; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +/** + * Tests for NotificationDataImpl class + * + */ +public class TestVnfImageException { + + @Test + public void testConstructors() { + VnfImageException exception = new VnfImageException("id"); + assertThat(exception.getImageId(), is(equalTo("id"))); + + exception = new VnfImageException("id2", 1); + assertThat(exception.getImageId(), is(equalTo("id2"))); + assertThat(exception.getResultCode().get(), is(equalTo(1))); + + Exception e = new Exception("message"); + exception = new VnfImageException(e); + assertThat(exception.getImageId(), is(equalTo("message"))); + } + +} diff --git a/src/test/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandlerTest.java b/src/test/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandlerTest.java index aa75cd2..b6d4564 100644 --- a/src/test/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandlerTest.java +++ b/src/test/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandlerTest.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.catalog; diff --git a/src/test/java/org/onap/aai/modelloader/entity/model/ModelArtifactParserTest.java b/src/test/java/org/onap/aai/modelloader/entity/model/ModelArtifactParserTest.java index ec24acb..84a4313 100644 --- a/src/test/java/org/onap/aai/modelloader/entity/model/ModelArtifactParserTest.java +++ b/src/test/java/org/onap/aai/modelloader/entity/model/ModelArtifactParserTest.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.model; diff --git a/src/test/java/org/onap/aai/modelloader/entity/model/ModelSorterTest.java b/src/test/java/org/onap/aai/modelloader/entity/model/ModelSorterTest.java index d59ddf7..d1d54b7 100644 --- a/src/test/java/org/onap/aai/modelloader/entity/model/ModelSorterTest.java +++ b/src/test/java/org/onap/aai/modelloader/entity/model/ModelSorterTest.java @@ -1,29 +1,33 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.model; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertThat; import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; import java.util.List; import org.junit.Test; @@ -32,140 +36,101 @@ import org.onap.aai.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()); - + public void edgeEquality() throws BabelArtifactParsingException { + ModelArtifact model = buildTestModel(); + ModelSorter.Node nodeA = new ModelSorter.Node(model); + ModelSorter.Node nodeB = new ModelSorter.Node(model); + ModelSorter.Node nodeC = new ModelSorter.Node(model); + + ModelSorter.Edge edgeA = new ModelSorter.Edge(nodeA, nodeB); + ModelSorter.Edge edgeB = new ModelSorter.Edge(nodeA, nodeB); + ModelSorter.Edge edgeC = new ModelSorter.Edge(nodeB, nodeA); + ModelSorter.Edge edgeD = new ModelSorter.Edge(nodeA, nodeC); + + assertThat(edgeA, is(equalTo(edgeA))); + assertThat(edgeA, is(not(equalTo(null)))); + assertThat(edgeA, is(not(equalTo(model)))); + + assertThat(edgeA, is(equalTo(edgeB))); + assertThat(edgeA, is(not(equalTo(edgeC)))); + assertThat(edgeA, is(not(equalTo(edgeD)))); } @Test - public void singleModel() { - - List<Artifact> modelList = new ArrayList<Artifact>(); - - ModelArtifact model = new ModelArtifact(); - model.setModelInvariantId("aaa"); - model.setModelVerId("111"); - model.addDependentModelId("xyz|123"); - modelList.add(model); - - ModelSorter sorter = new ModelSorter(); - sorter = new ModelSorter(); - - List<Artifact> sortedList = sorter.sort(modelList); - assertNotNull(sortedList); - assertEquals(1, sortedList.size()); - + public void nodeEquality() throws BabelArtifactParsingException { + ModelArtifact model = buildTestModel(); + ModelSorter.Node nodeA = new ModelSorter.Node(model); + ModelSorter.Node nodeB = new ModelSorter.Node(model); + + assertThat(nodeA, is(equalTo(nodeA))); + assertThat(nodeA, is(not(equalTo(null)))); + assertThat(nodeA, is(not(equalTo(model)))); + + assertThat(nodeA, is(equalTo(nodeB))); + assertThat(nodeA.toString(), is(equalTo(nodeB.toString()))); + assertThat(nodeA, is(not(equalTo(new ModelSorter.Node(new ModelArtifact()))))); } - /** - * 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)); + public void noModels() throws BabelArtifactParsingException { + assertThat(new ModelSorter().sort(null), is(nullValue())); + assertThat(new ModelSorter().sort(Collections.emptyList()).size(), is(0)); } @Test - public void multipleModelsAndNamedQueries() { - - List<Artifact> modelList = new ArrayList<Artifact>(); - - ModelArtifact aaaa = new ModelArtifact(); - aaaa.setModelInvariantId("aaaa"); - aaaa.setModelVerId("1111"); - aaaa.addDependentModelId("cccc|2222"); - - NamedQueryArtifact nq1 = new NamedQueryArtifact(); - nq1.setNamedQueryUuid("nq1"); - nq1.addDependentModelId("aaaa|1111"); - - NamedQueryArtifact nq2 = new NamedQueryArtifact(); - nq2.setNamedQueryUuid("nq2"); - nq2.addDependentModelId("existing-model"); - - modelList.add(nq1); - modelList.add(nq2); - modelList.add(aaaa); - - ModelSorter sorter = new ModelSorter(); - sorter = new ModelSorter(); - - List<Artifact> sortedList = sorter.sort(modelList); - assertNotNull(sortedList); - assertEquals(3, sortedList.size()); + public void singleModel() throws BabelArtifactParsingException { + assertThat(new ModelSorter().sort(Arrays.asList(buildTestModel())).size(), is(1)); + } - System.out.println(sortedList.get(0) + "-" + sortedList.get(1) + "-" + sortedList.get(2)); - assertEquals(aaaa, sortedList.get(0)); - assertEquals(nq2, sortedList.get(1)); - assertEquals(nq1, sortedList.get(2)); + @Test + public void multipleModels() throws BabelArtifactParsingException { + Artifact a = buildTestModel("aaaa", "mvaaaa", "cccc|mvcccc"); + Artifact b = buildTestModel("bbbb", "mvbbbb", "aaaa|mvaaaa"); + Artifact c = buildTestModel("cccc", "mvcccc"); + List<Artifact> expected = Arrays.asList(c, a, b); + assertThat(new ModelSorter().sort(Arrays.asList(a, b, c)), is(expected)); } - @Test(expected = RuntimeException.class) - public void circularDependency() { + @Test + public void multipleModelsAndNamedQueries() throws BabelArtifactParsingException { + Artifact a = buildTestModel("aaaa", "1111", "cccc|2222"); + Artifact nq1 = buildTestNamedQuery("nq1", "aaaa|1111"); + Artifact nq2 = buildTestNamedQuery("nqw", "existing-model"); + List<Artifact> expected = Arrays.asList(a, nq2, nq1); + assertThat(new ModelSorter().sort(Arrays.asList(nq1, nq2, a)), is(expected)); + } + @Test(expected = BabelArtifactParsingException.class) + public void circularDependency() throws BabelArtifactParsingException { List<Artifact> modelList = new ArrayList<Artifact>(); + modelList.add(buildTestModel("aaaa", "1111", "bbbb|1111")); + modelList.add(buildTestModel("bbbb", "1111", "aaaa|1111")); + new ModelSorter().sort(modelList); + } - ModelArtifact aaaa = new ModelArtifact(); - aaaa.setModelInvariantId("aaaa"); - aaaa.setModelVerId("1111"); - aaaa.addDependentModelId("bbbb|1111"); - - ModelArtifact bbbb = new ModelArtifact(); - bbbb.setModelInvariantId("bbbb"); - bbbb.setModelVerId("1111"); - bbbb.addDependentModelId("aaaa|1111"); - - modelList.add(aaaa); - modelList.add(bbbb); + private ModelArtifact buildTestModel() { + return buildTestModel("aaa", "111", "xyz|123"); + } - ModelSorter sorter = new ModelSorter(); - sorter = new ModelSorter(); + private ModelArtifact buildTestModel(String id, String version) { + return buildTestModel(id, version, null); + } - List<Artifact> sortedList = sorter.sort(modelList); - assertNotNull(sortedList); - assertEquals(2, sortedList.size()); + private ModelArtifact buildTestModel(String id, String version, String dependentModel) { + ModelArtifact modelArtifact = new ModelArtifact(); + modelArtifact.setModelInvariantId(id); + modelArtifact.setModelVerId(version); + if (dependentModel != null) { + modelArtifact.addDependentModelId(dependentModel); + } + return modelArtifact; + } + private NamedQueryArtifact buildTestNamedQuery(String uuid, String modelId) { + NamedQueryArtifact nq = new NamedQueryArtifact(); + nq.setNamedQueryUuid(uuid); + nq.addDependentModelId(modelId); + return nq; } } diff --git a/src/test/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParserTest.java b/src/test/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParserTest.java index 4fd6d1e..fa2d2d7 100644 --- a/src/test/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParserTest.java +++ b/src/test/java/org/onap/aai/modelloader/entity/model/NamedQueryArtifactParserTest.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.entity.model; 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 new file mode 100644 index 0000000..82990de --- /dev/null +++ b/src/test/java/org/onap/aai/modelloader/entity/model/TestModelArtifactHandler.java @@ -0,0 +1,124 @@ +/** + * ============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.entity.model; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; +import javax.ws.rs.core.Response; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +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; + +/** + * Test the Model Artifact Handler using Mocks + * + */ +public class TestModelArtifactHandler { + + @Mock + private ModelLoaderConfig config; + + @Mock + private AaiRestClient aaiClient; + + @Before + public void setupMocks() { + MockitoAnnotations.initMocks(this); + } + + @Test + public void testEmptyLists() { + ModelArtifactHandler handler = new ModelArtifactHandler(config); + handler.pushArtifacts(Collections.emptyList(), "", Collections.emptyList(), aaiClient); + handler.rollback(Collections.emptyList(), "", aaiClient); + } + + @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); + } + + @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()); + + List<Artifact> artifacts = new ArrayList<>(); + Artifact artifact = new ModelArtifact(); + artifacts.add(artifact); + + ModelArtifactHandler handler = new ModelArtifactHandler(config); + boolean pushed = handler.pushArtifacts(artifacts, "", Collections.emptyList(), aaiClient); + assertThat(pushed, is(true)); + handler.rollback(artifacts, "", aaiClient); + } + + @Test + public void testPushNewModelsWithRollback() { + when(config.getAaiBaseUrl()).thenReturn(""); + 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()); + + OperationResult putResult = mock(OperationResult.class); + when(aaiClient.putResource(any(), any(), any(), any())).thenReturn(putResult); + when(putResult.getResultCode()).thenReturn(Response.Status.CREATED.getStatusCode()); + + List<Artifact> artifacts = new ArrayList<>(); + artifacts.add(new ModelArtifact()); + NamedQueryArtifact namedQueryArtifact = new NamedQueryArtifact(); + namedQueryArtifact.setNamedQueryUuid("fred"); + namedQueryArtifact.setModelNamespace("http://org.onap.aai.inventory/v13"); + artifacts.add(namedQueryArtifact); + + List<Artifact> completedArtifacts = new ArrayList<>(); + ModelArtifactHandler handler = new ModelArtifactHandler(config); + boolean pushed = handler.pushArtifacts(artifacts, "", completedArtifacts, aaiClient); + assertThat(pushed, is(true)); + handler.rollback(artifacts, "", aaiClient); + } +} + diff --git a/src/test/java/org/onap/aai/modelloader/extraction/ArtifactInfoExtractorTest.java b/src/test/java/org/onap/aai/modelloader/extraction/ArtifactInfoExtractorTest.java index 6de0945..8ae2c7e 100644 --- a/src/test/java/org/onap/aai/modelloader/extraction/ArtifactInfoExtractorTest.java +++ b/src/test/java/org/onap/aai/modelloader/extraction/ArtifactInfoExtractorTest.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.extraction; @@ -32,11 +32,10 @@ import java.util.List; import org.junit.After; import org.junit.Before; import org.junit.Test; -import org.onap.aai.modelloader.extraction.ArtifactInfoExtractor; import org.onap.aai.modelloader.fixture.ArtifactInfoBuilder; import org.onap.aai.modelloader.fixture.TestNotificationDataImpl; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; /** * Tests {@link ArtifactInfoExtractor} diff --git a/src/test/java/org/onap/aai/modelloader/fixture/ArtifactInfoBuilder.java b/src/test/java/org/onap/aai/modelloader/fixture/ArtifactInfoBuilder.java index 2540865..aa475f3 100644 --- a/src/test/java/org/onap/aai/modelloader/fixture/ArtifactInfoBuilder.java +++ b/src/test/java/org/onap/aai/modelloader/fixture/ArtifactInfoBuilder.java @@ -1,30 +1,29 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.fixture; import java.util.ArrayList; import java.util.List; - import org.onap.aai.modelloader.service.ArtifactInfoImpl; -import org.openecomp.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.IArtifactInfo; /** * This class builds an instance of IArtifactInfo for test purposes. diff --git a/src/test/java/org/onap/aai/modelloader/fixture/NotificationDataFixtureBuilder.java b/src/test/java/org/onap/aai/modelloader/fixture/NotificationDataFixtureBuilder.java index f51a941..44f59a3 100644 --- a/src/test/java/org/onap/aai/modelloader/fixture/NotificationDataFixtureBuilder.java +++ b/src/test/java/org/onap/aai/modelloader/fixture/NotificationDataFixtureBuilder.java @@ -1,30 +1,30 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.fixture; import java.util.ArrayList; import java.util.List; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IResourceInstance; /** * This class is responsible for building NotificationData for use in test classes. @@ -84,7 +84,7 @@ public class NotificationDataFixtureBuilder { private static void buildWithInvalidType() { buildService(INVALID_TYPE, NOTIFICATION_DATA_WITH_INVALID_TYPE); } - + private static void buildwithOneOfEach() { buildService(TOSCA_CSAR, NOTIFICATION_DATA_WITH_ONE_OF_EACH); @@ -139,7 +139,7 @@ public class NotificationDataFixtureBuilder { public static INotificationData getNotificationDataWithInvalidType() { return NOTIFICATION_DATA_WITH_INVALID_TYPE; } - + public static INotificationData getNotificationDataWithOneOfEach() { return NOTIFICATION_DATA_WITH_ONE_OF_EACH; } diff --git a/src/test/java/org/onap/aai/modelloader/fixture/ResourceInstanceBuilder.java b/src/test/java/org/onap/aai/modelloader/fixture/ResourceInstanceBuilder.java index b62519d..01e00f8 100644 --- a/src/test/java/org/onap/aai/modelloader/fixture/ResourceInstanceBuilder.java +++ b/src/test/java/org/onap/aai/modelloader/fixture/ResourceInstanceBuilder.java @@ -1,28 +1,28 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.fixture; import java.util.List; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.IResourceInstance; /** * This class builds an instance of IArtifactInfo for test purposes. diff --git a/src/test/java/org/onap/aai/modelloader/fixture/TestNotificationDataImpl.java b/src/test/java/org/onap/aai/modelloader/fixture/TestNotificationDataImpl.java index b26b0e3..a7defdf 100644 --- a/src/test/java/org/onap/aai/modelloader/fixture/TestNotificationDataImpl.java +++ b/src/test/java/org/onap/aai/modelloader/fixture/TestNotificationDataImpl.java @@ -1,29 +1,29 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.fixture; import java.util.List; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IResourceInstance; /** * This class is an implementation of INotificationData for test purposes. @@ -97,6 +97,5 @@ public class TestNotificationDataImpl implements INotificationData { } @Override - public void setWorkloadContext(String arg0) { - } + public void setWorkloadContext(String arg0) {} } diff --git a/src/test/java/org/onap/aai/modelloader/fixture/TestResourceInstanceImpl.java b/src/test/java/org/onap/aai/modelloader/fixture/TestResourceInstanceImpl.java index 9b5fb19..7eaebb5 100644 --- a/src/test/java/org/onap/aai/modelloader/fixture/TestResourceInstanceImpl.java +++ b/src/test/java/org/onap/aai/modelloader/fixture/TestResourceInstanceImpl.java @@ -1,28 +1,28 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.fixture; import java.util.List; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.IResourceInstance; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.IResourceInstance; /** * This class is an implementation of IResourceInstance for test purposes. diff --git a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManagerTest.java b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManagerTest.java index 0dcff32..9d6f3c4 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManagerTest.java +++ b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManagerTest.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; @@ -46,9 +46,8 @@ 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.util.ArtifactTestUtils; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.notification.INotificationData; /** * Tests {@link ArtifactDeploymentManager } @@ -94,10 +93,9 @@ public class ArtifactDeploymentManagerTest { manager = null; } - private List<BabelArtifact> setupTest(byte[] xml, INotificationData data) throws IOException { List<BabelArtifact> toscaArtifacts = new ArrayList<>(); - IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0); + org.onap.sdc.api.notification.IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0); BabelArtifact xmlArtifact = new BabelArtifact(artifactInfo.getArtifactName(), BabelArtifact.ArtifactType.MODEL, new String(xml)); 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 71cd8af..2c02487 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerTest.java +++ b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerTest.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; @@ -53,12 +53,12 @@ import org.onap.aai.modelloader.restclient.BabelServiceClient; import org.onap.aai.modelloader.restclient.BabelServiceClient.BabelServiceException; import org.onap.aai.modelloader.restclient.BabelServiceClientFactory; import org.onap.aai.modelloader.util.ArtifactTestUtils; -import org.openecomp.sdc.api.IDistributionClient; -import org.openecomp.sdc.api.notification.IArtifactInfo; -import org.openecomp.sdc.api.notification.INotificationData; -import org.openecomp.sdc.api.results.IDistributionClientDownloadResult; -import org.openecomp.sdc.impl.DistributionClientDownloadResultImpl; -import org.openecomp.sdc.utils.DistributionActionResultEnum; +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} diff --git a/src/test/java/org/onap/aai/modelloader/notification/BabelArtifactConverterTest.java b/src/test/java/org/onap/aai/modelloader/notification/BabelArtifactConverterTest.java index 533a37b..e9e6059 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/BabelArtifactConverterTest.java +++ b/src/test/java/org/onap/aai/modelloader/notification/BabelArtifactConverterTest.java @@ -1,26 +1,25 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.notification; -import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -29,12 +28,10 @@ import java.util.ArrayList; import java.util.List; import org.junit.Test; import org.onap.aai.babel.service.data.BabelArtifact; -import org.onap.aai.modelloader.entity.Artifact; -import org.onap.aai.modelloader.entity.ArtifactType; import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException; import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder; -import org.onap.aai.modelloader.util.ArtifactTestUtils; -import org.openecomp.sdc.api.notification.INotificationData; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; /** * Tests {@link BabelArtifactConverter} @@ -69,7 +66,7 @@ public class BabelArtifactConverterTest { private List<BabelArtifact> setupTest(byte[] xml, INotificationData data) throws IOException { List<BabelArtifact> toscaArtifacts = new ArrayList<>(); - org.openecomp.sdc.api.notification.IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0); + IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0); BabelArtifact xmlArtifact = new BabelArtifact(artifactInfo.getArtifactName(), BabelArtifact.ArtifactType.MODEL, new String(xml)); @@ -77,5 +74,4 @@ public class BabelArtifactConverterTest { return toscaArtifacts; } - } diff --git a/src/test/java/org/onap/aai/modelloader/notification/EventCallbackTest.java b/src/test/java/org/onap/aai/modelloader/notification/EventCallbackTest.java index bc88c85..57a4c09 100644 --- a/src/test/java/org/onap/aai/modelloader/notification/EventCallbackTest.java +++ b/src/test/java/org/onap/aai/modelloader/notification/EventCallbackTest.java @@ -1,116 +1,116 @@ -/**
- * ============LICENSE_START==========================================
- * org.onap.aai
- * ===================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ===================================================================
- * 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.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.verify;
-import static org.mockito.Mockito.when;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Properties;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.mockito.internal.util.reflection.Whitebox;
-import org.onap.aai.modelloader.config.ModelLoaderConfig;
-import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
-import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
-import org.openecomp.sdc.api.IDistributionClient;
-import org.openecomp.sdc.api.notification.INotificationData;
-
-/**
- * Tests {@link EventCallback}
- */
-public class EventCallbackTest {
-
- private static final String CONFIG_FILE = "model-loader.properties";
-
- private ModelLoaderConfig config;
- private Properties configProperties;
- private EventCallback eventCallback;
-
- private ArtifactDeploymentManager mockArtifactDeploymentManager;
- private ArtifactDownloadManager mockArtifactDownloadManager;
- private IDistributionClient mockDistributionClient;
-
- @Before
- public void setup() throws IOException {
- configProperties = new Properties();
- configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
- config = new ModelLoaderConfig(configProperties, null);
-
- mockArtifactDeploymentManager = mock(ArtifactDeploymentManager.class);
- mockArtifactDownloadManager = mock(ArtifactDownloadManager.class);
- mockDistributionClient = mock(IDistributionClient.class);
-
- eventCallback = new EventCallback(mockDistributionClient, config);
-
- Whitebox.setInternalState(eventCallback, "artifactDeploymentManager", mockArtifactDeploymentManager);
- Whitebox.setInternalState(eventCallback, "artifactDownloadManager", mockArtifactDownloadManager);
- }
-
- @After
- public void tearDown() {
- config = null;
- configProperties = null;
- eventCallback = null;
- mockArtifactDeploymentManager = null;
- mockArtifactDownloadManager = null;
- mockDistributionClient = null;
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void activateCallback_downloadFails() {
- INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
-
- when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),
- any(List.class), any(List.class))).thenReturn(false);
-
- eventCallback.activateCallback(data);
-
- verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),
- any(List.class), any(List.class));
- Mockito.verifyZeroInteractions(mockArtifactDeploymentManager);
- }
-
- @SuppressWarnings("unchecked")
- @Test
- public void activateCallback() throws BabelArtifactParsingException {
- INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
-
- when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),
- any(List.class), any(List.class))).thenReturn(true);
-
- when(mockArtifactDeploymentManager.deploy(any(INotificationData.class), any(List.class), any(List.class),
- any(List.class))).thenReturn(true);
-
- eventCallback.activateCallback(data);
-
- verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),
- any(List.class), any(List.class));
- verify(mockArtifactDeploymentManager).deploy(any(INotificationData.class), any(List.class), any(List.class),
- any(List.class));
- }
-}
+/** + * ============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.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.io.IOException; +import java.util.List; +import java.util.Properties; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mockito; +import org.mockito.internal.util.reflection.Whitebox; +import org.onap.aai.modelloader.config.ModelLoaderConfig; +import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException; +import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.notification.INotificationData; + +/** + * Tests {@link EventCallback} + */ +public class EventCallbackTest { + + private static final String CONFIG_FILE = "model-loader.properties"; + + private ModelLoaderConfig config; + private Properties configProperties; + private EventCallback eventCallback; + + private ArtifactDeploymentManager mockArtifactDeploymentManager; + private ArtifactDownloadManager mockArtifactDownloadManager; + private IDistributionClient mockDistributionClient; + + @Before + public void setup() throws IOException { + configProperties = new Properties(); + configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE)); + config = new ModelLoaderConfig(configProperties, null); + + mockArtifactDeploymentManager = mock(ArtifactDeploymentManager.class); + mockArtifactDownloadManager = mock(ArtifactDownloadManager.class); + mockDistributionClient = mock(IDistributionClient.class); + + eventCallback = new EventCallback(mockDistributionClient, config); + + Whitebox.setInternalState(eventCallback, "artifactDeploymentManager", mockArtifactDeploymentManager); + Whitebox.setInternalState(eventCallback, "artifactDownloadManager", mockArtifactDownloadManager); + } + + @After + public void tearDown() { + config = null; + configProperties = null; + eventCallback = null; + mockArtifactDeploymentManager = null; + mockArtifactDownloadManager = null; + mockDistributionClient = null; + } + + @Test + @SuppressWarnings("unchecked") + public void activateCallback_downloadFails() { + INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile(); + + when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class), + any(List.class), any(List.class))).thenReturn(false); + + eventCallback.activateCallback(data); + + verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class), + any(List.class), any(List.class)); + Mockito.verifyZeroInteractions(mockArtifactDeploymentManager); + } + + @SuppressWarnings("unchecked") + @Test + public void activateCallback() throws BabelArtifactParsingException { + INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile(); + + when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class), + any(List.class), any(List.class))).thenReturn(true); + + when(mockArtifactDeploymentManager.deploy(any(INotificationData.class), any(List.class), any(List.class), + any(List.class))).thenReturn(true); + + eventCallback.activateCallback(data); + + verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class), + any(List.class), any(List.class)); + verify(mockArtifactDeploymentManager).deploy(any(INotificationData.class), any(List.class), any(List.class), + any(List.class)); + } +} diff --git a/src/test/java/org/onap/aai/modelloader/notification/TestNotificationPublisher.java b/src/test/java/org/onap/aai/modelloader/notification/TestNotificationPublisher.java new file mode 100644 index 0000000..bc91b2f --- /dev/null +++ b/src/test/java/org/onap/aai/modelloader/notification/TestNotificationPublisher.java @@ -0,0 +1,86 @@ +/** + * ============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.mockito.Matchers.any; +import static org.mockito.Matchers.anyString; +import static org.mockito.Mockito.when; + +import org.junit.Before; +import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.consumer.IConfiguration; +import org.onap.sdc.api.notification.IArtifactInfo; +import org.onap.sdc.api.notification.INotificationData; +import org.onap.sdc.api.results.IDistributionClientResult; +import org.onap.sdc.utils.DistributionActionResultEnum; + +/** + * Test the Notification Publisher using Mocks + * + */ +public class TestNotificationPublisher { + + @Mock + private IDistributionClient client; + + @Mock + private INotificationData data; + + @Mock + private IArtifactInfo artifact; + + @Mock + private IConfiguration config; + + @Mock + private IDistributionClientResult clientResult; + + static { + System.setProperty("CONFIG_HOME", "src/test/resources"); + } + + @Before + public void setupMocks() { + MockitoAnnotations.initMocks(this); + when(client.getConfiguration()).thenReturn(config); + when(client.sendDownloadStatus(any())).thenReturn(clientResult); + when(client.sendComponentDoneStatus(any())).thenReturn(clientResult); + when(client.sendComponentDoneStatus(any(), anyString())).thenReturn(clientResult); + when(client.sendDeploymentStatus(any())).thenReturn(clientResult); + when(clientResult.getDistributionActionResult()).thenReturn(DistributionActionResultEnum.SUCCESS); + } + + @Test + public void testPublisher() { + NotificationPublisher publisher = new NotificationPublisher(); + publisher.publishDownloadSuccess(client, data, artifact); + publisher.publishDownloadFailure(client, data, artifact, ""); + publisher.publishComponentSuccess(client, data); + publisher.publishComponentFailure(client, data, ""); + publisher.publishDeploySuccess(client, data, artifact); + publisher.publishDeployFailure(client, data, artifact); + } + +} + diff --git a/src/test/java/org/onap/aai/modelloader/restclient/TestAaiServiceClient.java b/src/test/java/org/onap/aai/modelloader/restclient/TestAaiServiceClient.java new file mode 100644 index 0000000..96620ee --- /dev/null +++ b/src/test/java/org/onap/aai/modelloader/restclient/TestAaiServiceClient.java @@ -0,0 +1,106 @@ +/** + * ============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 java.io.IOException; +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.After; +import org.junit.Before; +import org.junit.Test; +import org.onap.aai.modelloader.config.ModelLoaderConfig; + +/** + * Local testing of the Babel service + * + */ +public class TestAaiServiceClient { + + private Server server; + private AaiRestClient aaiClient; + + @Before + public void startJetty() throws Exception { + server = new Server(8080); + server.setHandler(getMockHandler()); + server.start(); + + Properties props = new Properties(); + props.put("ml.aai.KEYSTORE_PASSWORD", "2244"); + ModelLoaderConfig config = new ModelLoaderConfig(props, "."); + aaiClient = new AaiRestClient(config); + } + + @After + public void stopJetty() throws Exception { + server.stop(); + } + + @Test + public void testBuildAaiRestClient() { + Properties props = new Properties(); + ModelLoaderConfig config = new ModelLoaderConfig(props, "."); + new AaiRestClient(config); + } + + @Test + public void testOperations() { + String url = "http://localhost"; + String transId = ""; + MediaType mediaType = MediaType.APPLICATION_JSON_TYPE; + aaiClient.getResource(url, "", mediaType); + aaiClient.deleteResource("http://localhost", transId, ""); + aaiClient.getAndDeleteResource(url, transId); + aaiClient.postResource(url, "", transId, mediaType); + aaiClient.putResource(url, "", transId, mediaType); + } + + + /** + * 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()); + request.setHandled(true); + } + }; + return handler; + } +} + diff --git a/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java b/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java index 974c034..b42fee4 100644 --- a/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java +++ b/src/test/java/org/onap/aai/modelloader/restclient/TestBabelServiceClient.java @@ -1,40 +1,57 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============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.hamcrest.CoreMatchers.equalTo; import static org.hamcrest.CoreMatchers.is; import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; +import com.google.gson.Gson; import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Paths; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.cert.CertificateException; +import java.util.ArrayList; import java.util.List; import java.util.Properties; -import org.junit.Ignore; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +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.After; +import org.junit.Before; +import org.junit.Test; import org.onap.aai.babel.service.data.BabelArtifact; import org.onap.aai.modelloader.config.ModelLoaderConfig; -import org.onap.aai.modelloader.restclient.BabelServiceClient; +import org.onap.aai.modelloader.restclient.BabelServiceClient.BabelServiceException; /** * Local testing of the Babel service @@ -42,27 +59,65 @@ import org.onap.aai.modelloader.restclient.BabelServiceClient; */ public class TestBabelServiceClient { - // Load properties from src/test/resources - protected static String CONFIG_FILE = "model-loader.properties"; + private Server server; + private String responseBody; - // This test requires a running Babel system. To test locally, annotate with org.junit.Test - @Ignore - public void testRestClient() throws Exception { // NOSONAR + { + List<BabelArtifact> response = new ArrayList<>(); + response.add(new BabelArtifact("", null, "")); + response.add(new BabelArtifact("", null, "")); + response.add(new BabelArtifact("", null, "")); + responseBody = new Gson().toJson(response); + } + + @Before + public void startJetty() throws Exception { + server = new Server(8080); + server.setHandler(getMockHandler()); + server.start(); + } + + @After + public void stopJetty() throws Exception { + server.stop(); + } + + @Test + public void testRestClient() throws UnrecoverableKeyException, KeyManagementException, NoSuchAlgorithmException, + KeyStoreException, CertificateException, IOException, BabelServiceException, URISyntaxException { Properties configProperties = new Properties(); - try { - configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE)); - } catch (IOException e) { - fail(); - } - BabelServiceClient client = new BabelServiceClient(new ModelLoaderConfig(configProperties, ".")); + configProperties.put("ml.babel.KEYSTORE_PASSWORD", "OBF:1vn21ugu1saj1v9i1v941sar1ugw1vo0"); + configProperties.put("ml.babel.BASE_URL", "http://localhost:8080/"); + configProperties.put("ml.babel.GENERATE_ARTIFACTS_URL", "generate"); + BabelServiceClient client = + new BabelServiceClientFactory().create(new ModelLoaderConfig(configProperties, ".")); List<BabelArtifact> result = client.postArtifact(readBytesFromFile("compressedArtifacts/service-VscpaasTest-csar.csar"), "service-Vscpass-Test", "1.0", "Test-Transaction-ID-BabelClient"); - assertThat(result.size(), is(equalTo(3))); } private byte[] readBytesFromFile(String resourceFile) throws IOException, URISyntaxException { return Files.readAllBytes(Paths.get(ClassLoader.getSystemResource(resourceFile).toURI())); } + + /** + * 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/xml;charset=utf-8"); + write(responseBody, response.getOutputStream()); + request.setHandled(true); + } + }; + return handler; + } } + diff --git a/src/test/java/org/onap/aai/modelloader/service/TestArtifactInfoImpl.java b/src/test/java/org/onap/aai/modelloader/service/TestArtifactInfoImpl.java new file mode 100644 index 0000000..366d5a5 --- /dev/null +++ b/src/test/java/org/onap/aai/modelloader/service/TestArtifactInfoImpl.java @@ -0,0 +1,123 @@ +/** + * ============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.service; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.Matchers.empty; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +/** + * Tests for NotificationDataImpl class + * + */ +public class TestArtifactInfoImpl { + + @Test + public void testGettersAndSetters() { + ArtifactInfoImpl info = new ArtifactInfoImpl(); + String artifactName = "testname"; + String artifactType = "test-type"; + String artifactVersion = "v1"; + String artifactDescription = "test description"; + + info.setArtifactName(artifactName); + assertThat(info.getArtifactName(), is(equalTo(artifactName))); + + info.setArtifactType(artifactType); + assertThat(info.getArtifactType(), is(equalTo(artifactType))); + + info.setArtifactVersion(artifactVersion); + assertThat(info.getArtifactVersion(), is(equalTo(artifactVersion))); + + info.setArtifactDescription(artifactDescription); + assertThat(info.getArtifactDescription(), is(equalTo(artifactDescription))); + + assertThat(info.getArtifactChecksum(), is(nullValue())); + assertThat(info.getArtifactTimeout(), is(nullValue())); + assertThat(info.getArtifactURL(), is(nullValue())); + assertThat(info.getArtifactUUID(), is(nullValue())); + assertThat(info.getGeneratedArtifact(), is(nullValue())); + assertThat(info.getRelatedArtifacts(), is(empty())); + } + + + @Test + public void testEquality() { + ArtifactInfoImpl info = new ArtifactInfoImpl(); + assertThat(info, is(not(equalTo(null)))); + assertThat(info, is(not(equalTo("")))); // NOSONAR + assertThat(info, is(equalTo(info))); + + ArtifactInfoImpl other = new ArtifactInfoImpl(); + assertThat(info, is(equalTo(other))); + assertThat(info.hashCode(), is(equalTo(other.hashCode()))); + + // Artifact Name + other.setArtifactName(""); + assertThat(info, is(not(equalTo(other)))); + + info.setArtifactName("1234"); + assertThat(info, is(not(equalTo(other)))); + + other.setArtifactName("1234"); + assertThat(info, is(equalTo(other))); + assertThat(info.hashCode(), is(equalTo(other.hashCode()))); + + // Artifact Type + other.setArtifactType(""); + assertThat(info, is(not(equalTo(other)))); + + info.setArtifactType("type"); + assertThat(info, is(not(equalTo(other)))); + + other.setArtifactType("type"); + assertThat(info, is(equalTo(other))); + assertThat(info.hashCode(), is(equalTo(other.hashCode()))); + + // Artifact Description + other.setArtifactDescription(""); + assertThat(info, is(not(equalTo(other)))); + + info.setArtifactDescription("type"); + assertThat(info, is(not(equalTo(other)))); + + other.setArtifactDescription("type"); + assertThat(info, is(equalTo(other))); + assertThat(info.hashCode(), is(equalTo(other.hashCode()))); + + // Artifact Version + other.setArtifactVersion(""); + assertThat(info, is(not(equalTo(other)))); + + info.setArtifactVersion("v1"); + assertThat(info, is(not(equalTo(other)))); + + other.setArtifactVersion("v1"); + assertThat(info, is(equalTo(other))); + assertThat(info.hashCode(), is(equalTo(other.hashCode()))); + } + +} diff --git a/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderApplication.java b/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderApplication.java new file mode 100644 index 0000000..0f3ed45 --- /dev/null +++ b/src/test/java/org/onap/aai/modelloader/service/TestModelLoaderApplication.java @@ -0,0 +1,41 @@ +/** + * ============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.service; + +import org.junit.Test; + +/** + * Tests for ModelLoaderApplication class + * + */ +public class TestModelLoaderApplication { + + static { + System.setProperty("CONFIG_HOME", "src/test/resources"); + } + + @Test + public void testServiceStarts() { + // The SDC Distribution Client is expected to fail to initialise. + ModelLoaderApplication.main(new String[0]); + } + +} diff --git a/src/test/java/org/onap/aai/modelloader/service/TestNotificationDataImpl.java b/src/test/java/org/onap/aai/modelloader/service/TestNotificationDataImpl.java new file mode 100644 index 0000000..395b1f3 --- /dev/null +++ b/src/test/java/org/onap/aai/modelloader/service/TestNotificationDataImpl.java @@ -0,0 +1,83 @@ +/** + * ============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.service; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.junit.Assert.assertThat; + +import org.junit.Test; + +/** + * Tests for NotificationDataImpl class + * + */ +public class TestNotificationDataImpl { + + @Test + public void testGettersAndSetters() { + NotificationDataImpl data = new NotificationDataImpl(); + String distributionId = "testid"; + String context = "testcontext"; + + data.setDistributionID(distributionId); + assertThat(data.getDistributionID(), is(equalTo(distributionId))); + + // Getters return empty data + assertThat(data.getArtifactMetadataByUUID(null), is(equalTo(null))); + assertThat(data.getServiceDescription(), is(equalTo(null))); + assertThat(data.getServiceInvariantUUID(), is(equalTo(null))); + assertThat(data.getServiceName(), is(equalTo(null))); + assertThat(data.getServiceUUID(), is(equalTo(null))); + assertThat(data.getServiceVersion(), is(equalTo(null))); + assertThat(data.getResources().size(), is(0)); + assertThat(data.getServiceArtifacts().size(), is(0)); + + // Unsupported method! + data.setWorkloadContext(context); + assertThat(data.getWorkloadContext(), is(equalTo(null))); + } + + + @Test + public void testEquality() { + NotificationDataImpl data = new NotificationDataImpl(); + assertThat(data, is(not(equalTo(null)))); + assertThat(data, is(not(equalTo("")))); // NOSONAR + assertThat(data, is(equalTo(data))); + + NotificationDataImpl other = new NotificationDataImpl(); + assertThat(data, is(equalTo(other))); + assertThat(data.hashCode(), is(equalTo(other.hashCode()))); + + other.setDistributionID(""); + assertThat(data, is(not(equalTo(other)))); + + data.setDistributionID("1234"); + assertThat(data, is(not(equalTo(other)))); + + other.setDistributionID("1234"); + assertThat(data, is(equalTo(other))); + assertThat(data.hashCode(), is(equalTo(other.hashCode()))); + } + +} diff --git a/src/test/java/org/onap/aai/modelloader/util/ArtifactTestUtils.java b/src/test/java/org/onap/aai/modelloader/util/ArtifactTestUtils.java index c7a1506..9b6ea06 100644 --- a/src/test/java/org/onap/aai/modelloader/util/ArtifactTestUtils.java +++ b/src/test/java/org/onap/aai/modelloader/util/ArtifactTestUtils.java @@ -1,22 +1,22 @@ /** - * ============LICENSE_START========================================== + * ============LICENSE_START======================================================= * org.onap.aai - * =================================================================== + * ================================================================================ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved. - * Copyright © 2017-2018 Amdocs - * =================================================================== + * 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 + * 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============================================ + * ============LICENSE_END========================================================= */ package org.onap.aai.modelloader.util; diff --git a/src/test/java/org/onap/aai/modelloader/util/JsonXmlConverterTest.java b/src/test/java/org/onap/aai/modelloader/util/JsonXmlConverterTest.java index 7a42edf..2271c57 100644 --- a/src/test/java/org/onap/aai/modelloader/util/JsonXmlConverterTest.java +++ b/src/test/java/org/onap/aai/modelloader/util/JsonXmlConverterTest.java @@ -1,79 +1,78 @@ -/**
- * ============LICENSE_START==========================================
- * org.onap.aai
- * ===================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ===================================================================
- * 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.util;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayInputStream;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import org.junit.Test;
-import org.onap.aai.modelloader.util.JsonXmlConverter;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-public class JsonXmlConverterTest {
-
- @Test
- public void testConversion() throws Exception {
- final String XML_MODEL_FILE = "src/test/resources/models/l3-network-widget.xml";
- final String JSON_MODEL_FILE = "src/test/resources/models/l3-network-widget.json";
-
- try {
- byte[] encoded = Files.readAllBytes(Paths.get(XML_MODEL_FILE));
- String originalXML = new String(encoded);
-
- assertFalse(JsonXmlConverter.isValidJson(originalXML));
-
- encoded = Files.readAllBytes(Paths.get(JSON_MODEL_FILE));
- String originalJSON = new String(encoded);
-
- assertTrue(JsonXmlConverter.isValidJson(originalJSON));
-
- 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();
-
- 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;
- }
- }
-
- assertTrue(modelVid.equals("3d560d81-57d0-438b-a2a1-5334dba0651a"));
- } catch (Exception e) {
- e.printStackTrace();
- assertTrue(false);
- }
- }
-}
+/** + * ============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.util; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayInputStream; +import java.nio.file.Files; +import java.nio.file.Paths; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import org.junit.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +public class JsonXmlConverterTest { + + @Test + public void testConversion() throws Exception { + final String XML_MODEL_FILE = "src/test/resources/models/l3-network-widget.xml"; + final String JSON_MODEL_FILE = "src/test/resources/models/l3-network-widget.json"; + + try { + byte[] encoded = Files.readAllBytes(Paths.get(XML_MODEL_FILE)); + String originalXML = new String(encoded); + + assertFalse(JsonXmlConverter.isValidJson(originalXML)); + + encoded = Files.readAllBytes(Paths.get(JSON_MODEL_FILE)); + String originalJSON = new String(encoded); + + assertTrue(JsonXmlConverter.isValidJson(originalJSON)); + + 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(); + + 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; + } + } + + assertTrue(modelVid.equals("3d560d81-57d0-438b-a2a1-5334dba0651a")); + } catch (Exception e) { + e.printStackTrace(); + assertTrue(false); + } + } +} |