aboutsummaryrefslogtreecommitdiffstats
path: root/sdc-distribution-client/src/test/java/org/onap/sdc/impl
diff options
context:
space:
mode:
Diffstat (limited to 'sdc-distribution-client/src/test/java/org/onap/sdc/impl')
-rw-r--r--sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionClientDownloadResultTest.java55
-rw-r--r--sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionClientTest.java505
-rw-r--r--sdc-distribution-client/src/test/java/org/onap/sdc/impl/HeatParserTest.java139
-rw-r--r--sdc-distribution-client/src/test/java/org/onap/sdc/impl/NotificationConsumerTest.java352
4 files changed, 1051 insertions, 0 deletions
diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionClientDownloadResultTest.java b/sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionClientDownloadResultTest.java
new file mode 100644
index 0000000..d12d828
--- /dev/null
+++ b/sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionClientDownloadResultTest.java
@@ -0,0 +1,55 @@
+package org.onap.sdc.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.onap.sdc.utils.DistributionActionResultEnum;
+
+
+public class DistributionClientDownloadResultTest {
+
+ public static DistributionClientDownloadResultImpl distributionClientDownloadResult;
+
+ @BeforeClass
+ public static void init(){
+ distributionClientDownloadResult = new DistributionClientDownloadResultImpl(DistributionActionResultEnum.SUCCESS, "");
+ }
+
+ @Test
+ public void testNonHeaderFilename(){
+ distributionClientDownloadResult.setArtifactName("service-BkPerformanceSrvs-csar.csar");
+ assertEquals("service-BkPerformanceSrvs-csar.csar", distributionClientDownloadResult.getArtifactFilename());
+ }
+
+ @Test
+ public void testNullFilename(){
+ distributionClientDownloadResult.setArtifactName(null);
+ assertNull(distributionClientDownloadResult.getArtifactFilename());
+ }
+
+ @Test
+ public void testFilenameFromHeaderNoSpace(){
+ distributionClientDownloadResult.setArtifactName("attachment;filename=\"service-BkPerformanceSrvs-csar.csar\"");
+ assertEquals("service-BkPerformanceSrvs-csar.csar", distributionClientDownloadResult.getArtifactFilename());
+ }
+
+ @Test
+ public void testFilenameFromHeaderOneSpace(){
+ distributionClientDownloadResult.setArtifactName("attachment; filename=\"service-BkPerformanceSrvs-csar.csar\"");
+ assertEquals("service-BkPerformanceSrvs-csar.csar", distributionClientDownloadResult.getArtifactFilename());
+ }
+
+ @Test
+ public void testFilenameFromHeaderManySpaces(){
+ distributionClientDownloadResult.setArtifactName("attachment; filename=\"service-BkPerformanceSrvs-csar.csar\"");
+ assertEquals("service-BkPerformanceSrvs-csar.csar", distributionClientDownloadResult.getArtifactFilename());
+ }
+
+ @Test
+ public void testFilenameEmpty(){
+ distributionClientDownloadResult.setArtifactName("attachment; filename=\"\"");
+ assertEquals("", distributionClientDownloadResult.getArtifactFilename());
+ }
+}
diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionClientTest.java b/sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionClientTest.java
new file mode 100644
index 0000000..e2bad5a
--- /dev/null
+++ b/sdc-distribution-client/src/test/java/org/onap/sdc/impl/DistributionClientTest.java
@@ -0,0 +1,505 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doReturn;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.junit.After;
+import org.junit.Assert;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.sdc.utils.TestConfiguration;
+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.IVfModuleMetadata;
+import org.onap.sdc.api.results.IDistributionClientResult;
+import org.onap.sdc.http.SdcConnectorClient;
+import org.onap.sdc.http.TopicRegistrationResponse;
+import org.onap.sdc.utils.ArtifactTypeEnum;
+import org.onap.sdc.utils.ArtifactsUtils;
+import org.onap.sdc.utils.DistributionActionResultEnum;
+import org.onap.sdc.utils.TestNotificationCallback;
+import org.onap.sdc.utils.Wrapper;
+
+import com.att.nsa.apiClient.credentials.ApiCredential;
+import com.att.nsa.apiClient.http.HttpException;
+import com.att.nsa.cambria.client.CambriaClient.CambriaApiException;
+import com.att.nsa.cambria.client.CambriaIdentityManager;
+
+import fj.data.Either;
+
+public class DistributionClientTest {
+
+ static CambriaIdentityManager cc;
+ DistributionClientImpl client = Mockito.spy(new DistributionClientImpl());
+ IConfiguration testConfiguration = new TestConfiguration();
+ SdcConnectorClient connector = Mockito.mock(SdcConnectorClient.class);
+
+
+ @After
+ public void afterTest() {
+ client.stop();
+ }
+
+ @Test
+ public void validateConfigurationTest() {
+ DistributionActionResultEnum validationResult = client.validateAndInitConfiguration(new Wrapper<IDistributionClientResult>(), testConfiguration);
+ Assert.assertEquals(DistributionActionResultEnum.SUCCESS, validationResult);
+ Assert.assertEquals(testConfiguration.getPollingInterval(), client.configuration.getPollingInterval());
+ Assert.assertEquals(testConfiguration.getPollingTimeout(), client.configuration.getPollingTimeout());
+ }
+
+ @Test
+ public void validateConfigurationToDefaultTest() {
+ TestConfiguration userConfig = new TestConfiguration();
+ userConfig.setPollingInterval(1);
+ userConfig.setPollingTimeout(2);
+ DistributionActionResultEnum validationResult = client.validateAndInitConfiguration(new Wrapper<IDistributionClientResult>(), userConfig);
+ Assert.assertEquals(DistributionActionResultEnum.SUCCESS, validationResult);
+ assertEquals(15, client.configuration.getPollingInterval());
+ assertEquals(15, client.configuration.getPollingTimeout());
+ }
+
+ @Test
+ public void validateConfigurationFqdnTest() {
+
+ String[] validFqdns = { "myHostname", "myHostname:80", "myHostname:8080", "1.1.1.1", "1.1.1.1:8080", "ueb01hydc.it.open.com", "ueb01hydc.it.open.com:8080", "ueb01hydc.it", "my-good.and-simple.fqdn" };
+
+ String[] invalidFqdns = { "myHostname:808080", /* 70 letters */"abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghij", "not**good", "very#not#good#" };
+
+ boolean validationResult = true;
+
+ for (int i = 0; i < validFqdns.length; i++) {
+ validationResult = client.isValidFqdn(validFqdns[i]);
+ assertEquals("assertion failed for FQDN " + validFqdns[i] + " expected to be valid, actual invalid", true, validationResult);
+ }
+
+ for (int i = 0; i < invalidFqdns.length; i++) {
+ validationResult = client.isValidFqdn(invalidFqdns[i]);
+ assertEquals("assertion failed for FQDN " + invalidFqdns[i] + " expected to be invalid, actual valid", false, validationResult);
+ }
+
+ }
+
+ @Test
+ public void validateConfigurationPasswordTest() {
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ TestConfiguration testPassword = new TestConfiguration();
+ testPassword.setPassword(null);
+ DistributionActionResultEnum validationResult = client.validateAndInitConfiguration(errorWrapper, testPassword);
+ Assert.assertEquals(DistributionActionResultEnum.CONF_MISSING_PASSWORD, validationResult);
+
+ testPassword.setPassword("");
+ validationResult = client.validateAndInitConfiguration(errorWrapper, testPassword);
+ Assert.assertEquals(DistributionActionResultEnum.CONF_MISSING_PASSWORD, validationResult);
+
+ }
+
+ @Test
+ public void validateConfigurationUserTest() {
+ Wrapper<IDistributionClientResult> errorWrapper = new Wrapper<>();
+ TestConfiguration testUser = new TestConfiguration();
+ testUser.setUser(null);
+ DistributionActionResultEnum validationResult = client.validateAndInitConfiguration(errorWrapper, testUser);
+ Assert.assertEquals(DistributionActionResultEnum.CONF_MISSING_USERNAME, validationResult);
+
+ testUser.setUser("");
+ validationResult = client.validateAndInitConfiguration(errorWrapper, testUser);
+ Assert.assertEquals(DistributionActionResultEnum.CONF_MISSING_USERNAME, validationResult);
+
+ }
+
+ @Test
+ public void initWithMocksBadConfigurationTest() throws HttpException, CambriaApiException, IOException {
+
+
+ TopicRegistrationResponse topics = new TopicRegistrationResponse();
+ topics.setDistrNotificationTopicName("notificationTopic");
+ topics.setDistrStatusTopicName("statusTopic");
+ Either<TopicRegistrationResponse, DistributionClientResultImpl> topicsResult = Either.left(topics);
+ Mockito.when(connector.registerAsdcTopics(Mockito.any(ApiCredential.class))).thenReturn(topicsResult);
+
+ client.asdcConnector = connector;
+
+ // cambriaMock
+
+ CambriaIdentityManager cambriaMock = Mockito.mock(CambriaIdentityManager.class);
+ Mockito.when(cambriaMock.createApiKey(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(new ApiCredential("public", "secret"));
+ client.cambriaIdentityManager = cambriaMock;
+
+ // no password
+ TestConfiguration testPassword = new TestConfiguration();
+ testPassword.setPassword(null);
+ IDistributionClientResult validationResult = client.init(testPassword, new TestNotificationCallback());
+ Assert.assertEquals(DistributionActionResultEnum.CONF_MISSING_PASSWORD, validationResult.getDistributionActionResult());
+
+ testPassword.setPassword("");
+ validationResult = client.init(testPassword, new TestNotificationCallback());
+ Assert.assertEquals(DistributionActionResultEnum.CONF_MISSING_PASSWORD, validationResult.getDistributionActionResult());
+
+ // no username
+ TestConfiguration testUser = new TestConfiguration();
+ testUser.setUser(null);
+ validationResult = client.init(testUser, new TestNotificationCallback());
+ Assert.assertEquals(DistributionActionResultEnum.CONF_MISSING_USERNAME, validationResult.getDistributionActionResult());
+
+ testUser.setUser("");
+ validationResult = client.init(testUser, new TestNotificationCallback());
+ Assert.assertEquals(DistributionActionResultEnum.CONF_MISSING_USERNAME, validationResult.getDistributionActionResult());
+
+ // no ASDC server fqdn
+ TestConfiguration testServerFqdn = new TestConfiguration();
+ testServerFqdn.setAsdcAddress(null);
+ validationResult = client.init(testServerFqdn, new TestNotificationCallback());
+ Assert.assertEquals(DistributionActionResultEnum.CONF_MISSING_ASDC_FQDN, validationResult.getDistributionActionResult());
+
+ testServerFqdn.setAsdcAddress("");
+ validationResult = client.init(testServerFqdn, new TestNotificationCallback());
+ Assert.assertEquals(DistributionActionResultEnum.CONF_MISSING_ASDC_FQDN, validationResult.getDistributionActionResult());
+
+ testServerFqdn.setAsdcAddress("this##is##bad##fqdn");
+ validationResult = client.init(testServerFqdn, new TestNotificationCallback());
+ Assert.assertEquals(DistributionActionResultEnum.CONF_INVALID_ASDC_FQDN, validationResult.getDistributionActionResult());
+
+ // no consumerId
+ TestConfiguration testConsumerId = new TestConfiguration();
+ testConsumerId.setComsumerID(null);
+ validationResult = client.init(testConsumerId, new TestNotificationCallback());
+ Assert.assertEquals(DistributionActionResultEnum.CONF_MISSING_CONSUMER_ID, validationResult.getDistributionActionResult());
+
+ testConsumerId.setComsumerID("");
+ validationResult = client.init(testConsumerId, new TestNotificationCallback());
+ Assert.assertEquals(DistributionActionResultEnum.CONF_MISSING_CONSUMER_ID, validationResult.getDistributionActionResult());
+
+ // no environmentName
+ TestConfiguration testEnv = new TestConfiguration();
+ testEnv.setEnvironmentName(null);
+ validationResult = client.init(testEnv, new TestNotificationCallback());
+ Assert.assertEquals(DistributionActionResultEnum.CONF_MISSING_ENVIRONMENT_NAME, validationResult.getDistributionActionResult());
+
+ testEnv.setEnvironmentName("");
+ validationResult = client.init(testEnv, new TestNotificationCallback());
+ Assert.assertEquals(DistributionActionResultEnum.CONF_MISSING_ENVIRONMENT_NAME, validationResult.getDistributionActionResult());
+
+ Mockito.verify(client, Mockito.times(0)).getUEBServerList();
+ Mockito.verify(cambriaMock, Mockito.times(0)).createApiKey(Mockito.anyString(), Mockito.anyString());
+ Mockito.verify(connector, Mockito.times(0)).registerAsdcTopics(Mockito.any(ApiCredential.class));
+ }
+
+ @Test
+ public void initFailedConnectAsdcTest() throws HttpException, CambriaApiException, IOException {
+ // cambriaMock
+
+ CambriaIdentityManager cambriaMock = Mockito.mock(CambriaIdentityManager.class);
+ Mockito.when(cambriaMock.createApiKey(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(new ApiCredential("public", "secret"));
+ client.cambriaIdentityManager = cambriaMock;
+
+ TestConfiguration badAsdcConfig = new TestConfiguration();
+ badAsdcConfig.setAsdcAddress("badhost:8080");
+
+ IDistributionClientResult init = client.init(badAsdcConfig, new TestNotificationCallback());
+ assertEquals(DistributionActionResultEnum.ASDC_CONNECTION_FAILED, init.getDistributionActionResult());
+
+ badAsdcConfig = new TestConfiguration();
+ badAsdcConfig.setAsdcAddress("localhost:8181");
+
+ init = client.init(badAsdcConfig, new TestNotificationCallback());
+ assertEquals(DistributionActionResultEnum.ASDC_CONNECTION_FAILED, init.getDistributionActionResult());
+
+ }
+
+ @Test
+ public void getConfigurationTest() throws HttpException, CambriaApiException, IOException {
+ // connectorMock
+ mockArtifactTypeList();
+ TopicRegistrationResponse topics = new TopicRegistrationResponse();
+ topics.setDistrNotificationTopicName("notificationTopic");
+ topics.setDistrStatusTopicName("statusTopic");
+ Either<TopicRegistrationResponse, DistributionClientResultImpl> topicsResult = Either.left(topics);
+ Mockito.when(connector.registerAsdcTopics(Mockito.any(ApiCredential.class))).thenReturn(topicsResult);
+ IDistributionClientResult success = initSuccesResult();
+ Mockito.when(connector.unregisterTopics(Mockito.any(ApiCredential.class))).thenReturn(success);
+
+ client.asdcConnector = connector;
+
+ // cambriaMock
+
+ CambriaIdentityManager cambriaMock = Mockito.mock(CambriaIdentityManager.class);
+ Mockito.when(cambriaMock.createApiKey(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(new ApiCredential("public", "secret"));
+ client.cambriaIdentityManager = cambriaMock;
+
+ TestConfiguration badAsdcConfig = new TestConfiguration();
+ badAsdcConfig.setPollingInterval(-5);
+
+ IDistributionClientResult init = client.init(badAsdcConfig, new TestNotificationCallback());
+ assertEquals(DistributionActionResultEnum.SUCCESS, init.getDistributionActionResult());
+
+ String confString = client.getConfiguration().toString();
+ System.out.println(confString);
+
+ }
+
+ private IDistributionClientResult initSuccesResult() {
+ return new IDistributionClientResult() {
+
+ @Override
+ public String getDistributionMessageResult() {
+ return "success";
+ }
+
+ @Override
+ public DistributionActionResultEnum getDistributionActionResult() {
+ return DistributionActionResultEnum.SUCCESS;
+ }
+ };
+ }
+
+ @Test
+ public void initWithMocksTest() throws HttpException, CambriaApiException, IOException {
+
+ mockArtifactTypeList();
+
+ TopicRegistrationResponse topics = new TopicRegistrationResponse();
+ topics.setDistrNotificationTopicName("notificationTopic");
+ topics.setDistrStatusTopicName("statusTopic");
+ Either<TopicRegistrationResponse, DistributionClientResultImpl> topicsResult = Either.left(topics);
+ Mockito.when(connector.registerAsdcTopics(Mockito.any(ApiCredential.class))).thenReturn(topicsResult);
+ IDistributionClientResult success = initSuccesResult();
+ Mockito.when(connector.unregisterTopics(Mockito.any(ApiCredential.class))).thenReturn(success);
+
+ client.asdcConnector = connector;
+
+ // cambriaMock
+
+ CambriaIdentityManager cambriaMock = Mockito.mock(CambriaIdentityManager.class);
+ Mockito.when(cambriaMock.createApiKey(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(new ApiCredential("public", "secret"));
+ client.cambriaIdentityManager = cambriaMock;
+
+ IDistributionClientResult initResponse = client.init(testConfiguration, new TestNotificationCallback());
+ assertEquals(DistributionActionResultEnum.SUCCESS, initResponse.getDistributionActionResult());
+ Mockito.verify(client, Mockito.times(1)).getUEBServerList();
+ Mockito.verify(cambriaMock, Mockito.times(1)).createApiKey(Mockito.anyString(), Mockito.anyString());
+ Mockito.verify(connector, Mockito.times(1)).registerAsdcTopics(Mockito.any(ApiCredential.class));
+ System.out.println(initResponse);
+ }
+
+ private void mockArtifactTypeList() {
+ List<String> artifactTypes = new ArrayList<>();
+ for (ArtifactTypeEnum artifactType : ArtifactTypeEnum.values()) {
+ artifactTypes.add(artifactType.name());
+ }
+
+ final Either<List<String>, IDistributionClientResult> eitherArtifactTypes = Either.left(artifactTypes);
+ Mockito.when(connector.getValidArtifactTypesList()).thenReturn(eitherArtifactTypes);
+ }
+
+ @Test
+ public void testAlreadyInitTest() throws HttpException, CambriaApiException, IOException {
+ initWithMocksTest();
+ IDistributionClientResult initResponse = client.init(testConfiguration, new TestNotificationCallback());
+ assertEquals(DistributionActionResultEnum.DISTRIBUTION_CLIENT_ALREADY_INITIALIZED, initResponse.getDistributionActionResult());
+ }
+
+ @Test
+ public void initGetServerFailedTest() throws HttpException, CambriaApiException, IOException {
+
+ // connectorMock
+ IDistributionClientResult getServersResult = new DistributionClientResultImpl(DistributionActionResultEnum.ASDC_SERVER_PROBLEM, "problem");
+ Either<List<String>, IDistributionClientResult> serversResult = Either.right(getServersResult);
+ doReturn(serversResult).when(client).getUEBServerList();
+
+ TopicRegistrationResponse topics = new TopicRegistrationResponse();
+ topics.setDistrNotificationTopicName("notificationTopic");
+ topics.setDistrStatusTopicName("statusTopic");
+ Either<TopicRegistrationResponse, DistributionClientResultImpl> topicsResult = Either.left(topics);
+ Mockito.when(connector.registerAsdcTopics(Mockito.any(ApiCredential.class))).thenReturn(topicsResult);
+
+ client.asdcConnector = connector;
+
+ // cambriaMock
+
+ CambriaIdentityManager cambriaMock = Mockito.mock(CambriaIdentityManager.class);
+ Mockito.when(cambriaMock.createApiKey(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(new ApiCredential("public", "secret"));
+ client.cambriaIdentityManager = cambriaMock;
+
+ IDistributionClientResult initResponse = client.init(testConfiguration, new TestNotificationCallback());
+ assertEquals(DistributionActionResultEnum.ASDC_SERVER_PROBLEM, initResponse.getDistributionActionResult());
+
+ Mockito.verify(client, Mockito.times(1)).getUEBServerList();
+ Mockito.verify(cambriaMock, Mockito.times(0)).createApiKey(Mockito.anyString(), Mockito.anyString());
+ Mockito.verify(connector, Mockito.times(0)).registerAsdcTopics(Mockito.any(ApiCredential.class));
+
+ System.out.println(initResponse);
+ }
+
+ @Test
+ public void initCreateKeysFailedTest() throws HttpException, CambriaApiException, IOException {
+
+ // connectorMock
+ mockArtifactTypeList();
+
+ TopicRegistrationResponse topics = new TopicRegistrationResponse();
+ topics.setDistrNotificationTopicName("notificationTopic");
+ topics.setDistrStatusTopicName("statusTopic");
+ Either<TopicRegistrationResponse, DistributionClientResultImpl> topicsResult = Either.left(topics);
+ Mockito.when(connector.registerAsdcTopics(Mockito.any(ApiCredential.class))).thenReturn(topicsResult);
+
+ client.asdcConnector = connector;
+
+ // cambriaMock
+
+ CambriaIdentityManager cambriaMock = Mockito.mock(CambriaIdentityManager.class);
+ Mockito.when(cambriaMock.createApiKey(Mockito.any(String.class), Mockito.any(String.class))).thenThrow(new CambriaApiException("failure"));
+ client.cambriaIdentityManager = cambriaMock;
+
+ IDistributionClientResult initResponse = client.init(testConfiguration, new TestNotificationCallback());
+ assertEquals(DistributionActionResultEnum.UEB_KEYS_CREATION_FAILED, initResponse.getDistributionActionResult());
+
+ Mockito.verify(client, Mockito.times(1)).getUEBServerList();
+ Mockito.verify(cambriaMock, Mockito.times(1)).createApiKey(Mockito.anyString(), Mockito.anyString());
+ Mockito.verify(connector, Mockito.times(0)).registerAsdcTopics(Mockito.any(ApiCredential.class));
+ System.out.println(initResponse);
+ }
+
+ @Test
+ public void initRegistrationFailedTest() throws HttpException, CambriaApiException, IOException {
+
+ // connectorMock
+ mockArtifactTypeList();
+ DistributionClientResultImpl failureResult = new DistributionClientResultImpl(DistributionActionResultEnum.BAD_REQUEST, "Bad Request");
+ Either<TopicRegistrationResponse, DistributionClientResultImpl> topicsResult = Either.right(failureResult);
+ Mockito.when(connector.registerAsdcTopics(Mockito.any(ApiCredential.class))).thenReturn(topicsResult);
+
+ client.asdcConnector = connector;
+
+ // cambriaMock
+
+ CambriaIdentityManager cambriaMock = Mockito.mock(CambriaIdentityManager.class);
+ Mockito.when(cambriaMock.createApiKey(Mockito.any(String.class), Mockito.any(String.class))).thenReturn(new ApiCredential("public", "secret"));
+ client.cambriaIdentityManager = cambriaMock;
+
+ IDistributionClientResult initResponse = client.init(testConfiguration, new TestNotificationCallback());
+ assertEquals(DistributionActionResultEnum.BAD_REQUEST, initResponse.getDistributionActionResult());
+ Mockito.verify(client, Mockito.times(1)).getUEBServerList();
+ Mockito.verify(cambriaMock, Mockito.times(1)).createApiKey(Mockito.anyString(), Mockito.anyString());
+ Mockito.verify(connector, Mockito.times(1)).registerAsdcTopics(Mockito.any(ApiCredential.class));
+ System.out.println(initResponse);
+ }
+
+ @Test
+ public void testStartWithoutInit() {
+ IDistributionClientResult result = client.start();
+ assertTrue(result.getDistributionActionResult() == DistributionActionResultEnum.DISTRIBUTION_CLIENT_NOT_INITIALIZED);
+ }
+
+ private IArtifactInfo initArtifactInfo() {
+ ArtifactInfoImpl artifactInfo = new ArtifactInfoImpl();
+ artifactInfo.setArtifactURL("/sdc/v1/services/serviceName/0.1/artifacts/aaa.hh");
+ artifactInfo.setArtifactChecksum(ArtifactsUtils.getValidChecksum());
+ return artifactInfo;
+ }
+
+ // ########### TESTS TO ADD TO CI START ###########
+ /*public void createKeysTestCI() throws MalformedURLException, GeneralSecurityException {
+ validateConfigurationTest();
+ CambriaIdentityManager trueCambria = new CambriaClientBuilders.IdentityManagerBuilder().usingHttps().usingHosts(serverList).build();
+ client.cambriaIdentityManager = trueCambria;
+ DistributionClientResultImpl keysResult = client.createUebKeys();
+ Assert.assertEquals(DistributionActionResultEnum.SUCCESS, keysResult.getDistributionActionResult());
+ Assert.assertFalse(client.credential.getApiKey().isEmpty());
+ Assert.assertFalse(client.credential.getApiSecret().isEmpty());
+
+ System.out.println(keysResult);
+ System.out.println("keys: public=" + client.credential.getApiKey() + " | secret=" + client.credential.getApiSecret());
+ }
+*/
+ public void initTestCI() {
+ IDistributionClient distributionClient = DistributionClientFactory.createDistributionClient();
+ IDistributionClientResult init = distributionClient.init(testConfiguration, new TestNotificationCallback());
+ assertEquals(DistributionActionResultEnum.SUCCESS, init.getDistributionActionResult());
+
+ }
+
+ @Test
+ public void testDecodeVfModuleArtifact() throws IOException{
+ String vfModuleContent = getVFModuleExample();
+ List<IVfModuleMetadata> decodeVfModuleArtifact = client.decodeVfModuleArtifact(vfModuleContent.getBytes());
+ assertTrue(decodeVfModuleArtifact.size() == 1);
+ IVfModuleMetadata iVfModuleMetadata = decodeVfModuleArtifact.get(0);
+ assertTrue(iVfModuleMetadata.getArtifacts().size() == 11);
+ assertEquals(iVfModuleMetadata.getVfModuleModelName(), "Vccfdb..base_vDB_11032016..module-0");
+ }
+
+ private String getVFModuleExample() {
+ return "[\r\n" +
+ " {\r\n" +
+ " \"vfModuleModelName\": \"Vccfdb..base_vDB_11032016..module-0\",\r\n" +
+ " \"vfModuleModelInvariantUUID\": \"89bcc10e-84f9-475a-b7e3-bdac6cd2b31a\",\r\n" +
+ " \"vfModuleModelVersion\": \"1\",\r\n" +
+ " \"vfModuleModelUUID\": \"f7e1c7aa-cc7b-4dfc-b761-237e8063bd96\",\r\n" +
+ " \"GuguBubu\": true,\r\n" +
+ " \"isBase\": true,\r\n" +
+ " \"artifacts\": [\r\n" +
+ " \"68733000-7656-487c-aecb-040af96df5a5\",\r\n" +
+ " \"d3519bb4-be98-4c04-8815-4557379fdff3\",\r\n" +
+ " \"b445d84b-de23-4f0c-a0aa-8d794d85bebe\",\r\n" +
+ " \"52a6656a-63f4-4ae8-80f4-40febcaa15d6\",\r\n" +
+ " \"fdcf20b5-1bac-4da7-9e77-b0b565115027\",\r\n" +
+ " \"d3fcfd98-941c-4627-8b94-386dd3eab1ab\",\r\n" +
+ " \"bdd6c2b6-793b-49d7-8590-51e7d6998f69\",\r\n" +
+ " \"554a62b0-3a56-4c29-bc5e-23badf6da67f\",\r\n" +
+ " \"4b922d87-f2c9-44da-b933-57a91294fb42\",\r\n" +
+ " \"ad5cceda-0fa4-415e-b319-96f080e4b5c7\",\r\n" +
+ " \"8f4312f4-7be5-4d64-a3f5-564be7a0f01e\"\r\n" +
+ " ]\r\n" +
+ " }\r\n" +
+ "]";
+ }
+
+
+
+ public void connectorRegisterCI() {
+ SdcConnectorClient connector = new SdcConnectorClient();
+ connector.init(testConfiguration);
+
+ ApiCredential creds = new ApiCredential("publicKey", "secretKey");
+ Either<TopicRegistrationResponse, DistributionClientResultImpl> topicsFromAsdc = connector.registerAsdcTopics(creds);
+ assertTrue(topicsFromAsdc.isLeft());
+
+ }
+
+ public void downloadArtifactTestCI() {
+ SdcConnectorClient connector = new SdcConnectorClient();
+ connector.init(testConfiguration);
+ IArtifactInfo artifactInfo = initArtifactInfo();
+ connector.dowloadArtifact(artifactInfo);
+
+ }
+ // ########### TESTS TO ADD TO CI END ###########
+
+}
diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/HeatParserTest.java b/sdc-distribution-client/src/test/java/org/onap/sdc/impl/HeatParserTest.java
new file mode 100644
index 0000000..815d749
--- /dev/null
+++ b/sdc-distribution-client/src/test/java/org/onap/sdc/impl/HeatParserTest.java
@@ -0,0 +1,139 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.junit.Test;
+import org.onap.sdc.utils.heat.HeatParser;
+import org.onap.sdc.utils.heat.HeatParameter;
+import org.onap.sdc.utils.heat.HeatParameterConstraint;
+
+import com.google.common.base.Charsets;
+import com.google.common.io.Resources;
+
+public class HeatParserTest {
+
+ @Test
+ public void testParametersParsing() throws IOException{
+ String resourceName = "heatExample.yaml";
+ URL url = Resources.getResource(resourceName);
+ String heatFileContents = Resources.toString(url, Charsets.UTF_8);
+ assertNotNull("Didn't find "+resourceName, heatFileContents);
+
+ HeatParser heatParser = new HeatParser();
+ //Flat parameter entry
+ Map<String, HeatParameter> parameters = heatParser.getHeatParameters(heatFileContents);
+ HeatParameter heatParameter1 = parameters.get("image_name_1");
+ validateField("string", heatParameter1.getType(), "type");
+ validateField("Image Name", heatParameter1.getLabel(), "label");
+ validateField("SCOIMAGE Specify an image name for instance1", heatParameter1.getDescription(), "description");
+ validateField("cirros-0.3.1-x86_64", heatParameter1.getDefault(), "default");
+ validateField(null, heatParameter1.getConstraints(), "constraints");
+ validateField("false", heatParameter1.getHidden(), "hidden");
+
+
+ //Flat parameter entry with constraints
+ heatParameter1 = parameters.get("network_id");
+ validateField("string", heatParameter1.getType(), "type");
+ validateField("Network ID", heatParameter1.getLabel(), "label");
+ validateField("SCONETWORK Network to be used for the compute instance", heatParameter1.getDescription(), "description");
+ validateField(null, heatParameter1.getDefault(), "default");
+ validateField("true", heatParameter1.getHidden(), "hidden");
+
+ //Constraints
+ List<HeatParameterConstraint> constraints = heatParameter1.getConstraints();
+ assertEquals("Number of constraints", 6, constraints.size());
+
+ //Length
+ HeatParameterConstraint lengthConstraint = heatParameter1.getLengthConstraint();
+ assertNotNull(lengthConstraint);
+ Map<String, String> expectedMap = new HashMap<>();
+ expectedMap.put("min", "6");
+ expectedMap.put("max", "8");
+ validateField(expectedMap, lengthConstraint.getLength(), "length");
+ validateField("Password length must be between 6 and 8 characters.", lengthConstraint.getDescription(), "length description");
+
+ //Range
+ HeatParameterConstraint rangeConstraint = heatParameter1.getRangeConstraint();
+ assertNotNull(rangeConstraint);
+ validateField(expectedMap, rangeConstraint.getRange(), "range");
+ validateField("Range description", rangeConstraint.getDescription(), "range description");
+
+ //Allowed values
+ HeatParameterConstraint allowedValues = heatParameter1.getAllowedValuesConstraint();
+ assertNotNull(allowedValues);
+ List<String> expectedValues = new ArrayList<>();
+ expectedValues.add("m1.small");
+ expectedValues.add("m1.medium");
+ expectedValues.add("m1.large");
+ validateField(expectedValues, allowedValues.getAllowed_values(), "allowed_values");
+ validateField("Allowed values description", allowedValues.getDescription(), "allowed_values description");
+
+ //Allowed pattern
+ List<HeatParameterConstraint> allowedPatternList = heatParameter1.getAllowedPatternConstraint();
+ assertNotNull(allowedPatternList);
+ assertEquals("Allowed pattern list", 2, allowedPatternList.size());
+ HeatParameterConstraint allowedPattern = allowedPatternList.get(0);
+ validateField("[a-zA-Z0-9]+", allowedPattern.getAllowed_pattern(), "allowed_pattern");
+ validateField("Password must consist of characters and numbers only.", allowedPattern.getDescription(), "allowed_pattern description");
+ allowedPattern = allowedPatternList.get(1);
+ validateField("[A-Z]+[a-zA-Z0-9]*", allowedPattern.getAllowed_pattern(), "allowed_pattern");
+ validateField("Password must start with an uppercase character.", allowedPattern.getDescription(), "allowed_pattern description");
+
+ //Custom constraint
+ List<HeatParameterConstraint> customConstraintList = heatParameter1.getCustomConstraintConstraint();
+ assertNotNull(customConstraintList);
+ assertEquals("Custom constraint list", 1, customConstraintList.size());
+ HeatParameterConstraint customConstraint = customConstraintList.get(0);
+ validateField("nova.keypair", customConstraint.getCustom_constraint(), "custom_constraint");
+ validateField("Custom description", customConstraint.getDescription(), "custom_constraint description");
+ }
+
+ @Test
+ public void testParametersParsingInvalidYaml() throws IOException{
+ String invalidHeatFileContents = "just text";
+ HeatParser heatParser = new HeatParser();
+ //Flat parameter entry
+ Map<String, HeatParameter> parameters = heatParser.getHeatParameters(invalidHeatFileContents);
+ assertNull(parameters);
+ }
+
+ @Test
+ public void testParametersParsingNoParamteresSection() throws IOException{
+ String heatFileContentsNoParams = "heat_template_version: 2013-05-23\r\n\r\ndescription: Simple template to deploy a stack with two virtual machine instances";
+ HeatParser heatParser = new HeatParser();
+ //Flat parameter entry
+ Map<String, HeatParameter> parameters = heatParser.getHeatParameters(heatFileContentsNoParams);
+ assertNull(parameters);
+ }
+
+ private void validateField(Object expected, Object actual, String type){
+ assertEquals("Field of type "+type+":", expected, actual);
+ }
+}
diff --git a/sdc-distribution-client/src/test/java/org/onap/sdc/impl/NotificationConsumerTest.java b/sdc-distribution-client/src/test/java/org/onap/sdc/impl/NotificationConsumerTest.java
new file mode 100644
index 0000000..7603d0c
--- /dev/null
+++ b/sdc-distribution-client/src/test/java/org/onap/sdc/impl/NotificationConsumerTest.java
@@ -0,0 +1,352 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * sdc-distribution-client
+ * ================================================================================
+ * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.sdc.impl;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Queue;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeUnit;
+
+import org.eclipse.jetty.util.ArrayQueue;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.onap.sdc.utils.TestConfiguration;
+import org.onap.sdc.api.consumer.INotificationCallback;
+import org.onap.sdc.api.notification.INotificationData;
+import org.onap.sdc.api.results.IDistributionClientResult;
+import org.onap.sdc.utils.ArtifactTypeEnum;
+import org.onap.sdc.utils.DistributionActionResultEnum;
+import org.onap.sdc.utils.DistributionClientConstants;
+
+import com.att.nsa.cambria.client.CambriaConsumer;
+import com.google.gson.Gson;
+import com.google.gson.GsonBuilder;
+
+public class NotificationConsumerTest {
+ private CambriaConsumer cambriaConsumer = mock(CambriaConsumer.class);
+ private INotificationCallback clientCallback = spy(INotificationCallback.class);
+ private Queue<Iterable<String>> notificationsQueue = new ArrayQueue<>(100);
+ private DistributionClientImpl distributionClient = Mockito.spy(DistributionClientImpl.class);
+ private List<String> artifactsTypes = Arrays.asList(ArtifactTypeEnum.HEAT.name());
+ private List<Boolean> notificationStatusResults = new ArrayList<>();
+ final static IDistributionClientResult DISTRIBUTION_SUCCESS_RESULT = buildSuccessResult();
+
+ private NotificationConsumer createNotificationConsumer() {
+ return new NotificationConsumer(cambriaConsumer, clientCallback, artifactsTypes, distributionClient);
+ }
+
+ @Before
+ public void beforeTest() throws IOException {
+ Mockito.reset(clientCallback, distributionClient);
+ when(cambriaConsumer.fetch()).then(new Answer<Iterable<String>>() {
+ @Override
+ public Iterable<String> answer(InvocationOnMock invocation) throws Throwable {
+ if (!notificationsQueue.isEmpty()) {
+ return notificationsQueue.remove();
+ } else {
+ return new ArrayList<>();
+ }
+ }
+ });
+ when(distributionClient.sendNotificationStatus(Mockito.anyLong(), Mockito.anyString(), Mockito.any(ArtifactInfoImpl.class), Mockito.anyBoolean())).then(new Answer<IDistributionClientResult>() {
+ @Override
+ public IDistributionClientResult answer(InvocationOnMock invocation) throws Throwable {
+ boolean isNotified = (boolean) invocation.getArguments()[3];
+ notificationStatusResults.add(Boolean.valueOf(isNotified));
+ return DISTRIBUTION_SUCCESS_RESULT;
+ }
+ });
+
+ }
+
+ private static IDistributionClientResult buildSuccessResult() {
+ return new IDistributionClientResult() {
+
+ @Override
+ public String getDistributionMessageResult() {
+ return "";
+ }
+
+ @Override
+ public DistributionActionResultEnum getDistributionActionResult() {
+ return DistributionActionResultEnum.SUCCESS;
+ }
+ };
+ }
+
+ @Test
+ public void testNoNotifiactionsSent() throws InterruptedException {
+
+ ScheduledExecutorService executorPool = Executors.newScheduledThreadPool(DistributionClientConstants.POOL_SIZE);
+ executorPool.scheduleAtFixedRate(createNotificationConsumer(), 0, 100, TimeUnit.MILLISECONDS);
+
+ Thread.sleep(1000);
+ executorPool.shutdown();
+
+ Mockito.verify(clientCallback, Mockito.times(0)).activateCallback(Mockito.any(INotificationData.class));
+
+ }
+
+ @Test
+ public void testNonRelevantNotificationSent() throws InterruptedException {
+
+ simulateNotificationFromUEB(getAsdcServiceNotificationWithoutHeatArtifact());
+ Mockito.verify(clientCallback, Mockito.times(0)).activateCallback(Mockito.any(INotificationData.class));
+
+ }
+
+ @Test
+ public void testRelevantNotificationSent() throws InterruptedException {
+ simulateNotificationFromUEB(getAsdcServiceNotificationWithHeatArtifact());
+ Mockito.verify(clientCallback, Mockito.times(1)).activateCallback(Mockito.any(INotificationData.class));
+
+ }
+
+ @Test
+ public void testNonExistingArtifactsNotificationSent() throws InterruptedException {
+ simulateNotificationFromUEB(getAsdcNotificationWithNonExistentArtifact());
+ Mockito.verify(clientCallback, Mockito.times(1)).activateCallback(Mockito.any(INotificationData.class));
+
+ }
+
+ @Test
+ public void testNotificationStatusSent() throws InterruptedException {
+ simulateNotificationFromUEB(getAsdcServiceNotificationWithHeatArtifact());
+
+ Mockito.verify(distributionClient, Mockito.times(3)).sendNotificationStatus(Mockito.anyLong(), Mockito.anyString(), Mockito.any(ArtifactInfoImpl.class), Mockito.anyBoolean());
+ assertTrue(countInstances(notificationStatusResults, Boolean.TRUE) == 1);
+ assertTrue(countInstances(notificationStatusResults, Boolean.FALSE) == 2);
+ }
+
+ @Test
+ public void testNotificationRelatedArtifacts() throws InterruptedException {
+ List<String> artifactTypesTmp = new ArrayList<>();
+ for (ArtifactTypeEnum artifactTypeEnum : ArtifactTypeEnum.values()) {
+ artifactTypesTmp.add(artifactTypeEnum.name());
+ }
+ artifactsTypes = artifactTypesTmp;
+ simulateNotificationFromUEB(getAsdcServiceNotificationWithRelatedArtifacts());
+
+ Mockito.verify(distributionClient, Mockito.times(3)).sendNotificationStatus(Mockito.anyLong(), Mockito.anyString(), Mockito.any(ArtifactInfoImpl.class), Mockito.anyBoolean());
+ assertTrue(countInstances(notificationStatusResults, Boolean.TRUE) == 3);
+ assertTrue(countInstances(notificationStatusResults, Boolean.FALSE) == 0);
+ }
+
+ @Test
+ public void testNotificationStatusWithServiceArtifatcs() throws InterruptedException {
+ simulateNotificationFromUEB(getNotificationWithServiceArtifatcs());
+ Mockito.verify(distributionClient, Mockito.times(6)).sendNotificationStatus(Mockito.anyLong(), Mockito.anyString(), Mockito.any(ArtifactInfoImpl.class), Mockito.anyBoolean());
+ assertTrue(countInstances(notificationStatusResults, Boolean.TRUE) == 2);
+ assertTrue(countInstances(notificationStatusResults, Boolean.FALSE) == 4);
+
+ }
+
+ @Test
+ public final void testBuildCallbackNotificationLogicFlagIsFalse() {
+ NotificationConsumer consumer = createNotificationConsumer();
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ TestConfiguration testConfiguration = new TestConfiguration();
+ testConfiguration.setFilterInEmptyResources(false);
+ when(distributionClient.getConfiguration()).thenReturn(testConfiguration);
+ NotificationDataImpl notification = gson.fromJson(getNotificationWithMultipleResources(), NotificationDataImpl.class);
+ NotificationDataImpl notificationBuiltInClient = consumer.buildCallbackNotificationLogic(0, notification);
+ assertTrue(notificationBuiltInClient.getResources().size() == 1);
+ }
+
+ @Test
+ public final void testBuildCallbackNotificationLogicFlagIsTrue() {
+ NotificationConsumer consumer = createNotificationConsumer();
+ Gson gson = new GsonBuilder().setPrettyPrinting().create();
+ TestConfiguration testConfiguration = new TestConfiguration();
+ testConfiguration.setFilterInEmptyResources(true);
+ when(distributionClient.getConfiguration()).thenReturn(testConfiguration);
+ NotificationDataImpl notification = gson.fromJson(getNotificationWithMultipleResources(), NotificationDataImpl.class);
+ NotificationDataImpl notificationBuiltInClient = consumer.buildCallbackNotificationLogic(0, notification);
+ assertTrue(notificationBuiltInClient.getResources().size() == 2);
+ }
+
+ private void simulateNotificationFromUEB(final String notificationFromUEB) throws InterruptedException {
+ ScheduledExecutorService executorPool = Executors.newScheduledThreadPool(DistributionClientConstants.POOL_SIZE);
+ executorPool.scheduleAtFixedRate(createNotificationConsumer(), 0, 100, TimeUnit.MILLISECONDS);
+
+ Thread.sleep(200);
+
+ List<String> nonHeatNotification = Arrays.asList(notificationFromUEB);
+ notificationsQueue.add(nonHeatNotification);
+ Thread.sleep(800);
+ executorPool.shutdown();
+ }
+
+ private String getAsdcServiceNotificationWithHeatArtifact() {
+ return "{\"distributionID\" : \"bcc7a72e-90b1-4c5f-9a37-28dc3cd86416\",\r\n" + " \"serviceName\" : \"Testnotificationser1\",\r\n" + " \"serviceVersion\" : \"1.0\",\r\n"
+ + " \"serviceUUID\" : \"7f7f94f4-373a-4b71-a0e3-80ae2ba4eb5d\",\r\n" + " \"serviceDescription\" : \"TestNotificationVF1\",\r\n" + " \"resources\" : [{\r\n" + " \"resourceInstanceName\" : \"testnotificationvf11\",\r\n"
+ + " \"resourceName\" : \"TestNotificationVF1\",\r\n" + " \"resourceVersion\" : \"1.0\",\r\n" + " \"resoucreType\" : \"VF\",\r\n" + " \"resourceUUID\" : \"907e1746-9f69-40f5-9f2a-313654092a2d\",\r\n"
+ + " \"artifacts\" : [{\r\n" + " \"artifactName\" : \"sample-xml-alldata-1-1.xml\",\r\n" + " \"artifactType\" : \"YANG_XML\",\r\n"
+ + " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/sample-xml-alldata-1-1.xml\",\r\n"
+ + " \"artifactChecksum\" : \"MTUxODFkMmRlOTNhNjYxMGYyYTI1ZjA5Y2QyNWQyYTk\\u003d\",\r\n" + " \"artifactDescription\" : \"MyYang\",\r\n" + " \"artifactTimeout\" : 0,\r\n"
+ + " \"artifactUUID\" : \"0005bc4a-2c19-452e-be6d-d574a56be4d0\",\r\n" + " \"artifactVersion\" : \"1\"\r\n" + " }, {\r\n" + " \"artifactName\" : \"heat.yaml\",\r\n"
+ + " \"artifactType\" : \"HEAT\",\r\n" + " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/heat.yaml\",\r\n"
+ + " \"artifactChecksum\" : \"ODEyNjE4YTMzYzRmMTk2ODVhNTU2NTg3YWEyNmIxMTM\\u003d\",\r\n" + " \"artifactDescription\" : \"heat\",\r\n" + " \"artifactTimeout\" : 60,\r\n"
+ + " \"artifactUUID\" : \"8df6123c-f368-47d3-93be-1972cefbcc35\",\r\n" + " \"artifactVersion\" : \"1\"\r\n" + " }, {\r\n" + " \"artifactName\" : \"heat.env\",\r\n"
+ + " \"artifactType\" : \"HEAT_ENV\",\r\n" + " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/heat.env\",\r\n"
+ + " \"artifactChecksum\" : \"NGIzMjExZTM1NDc2NjBjOTQyMGJmMWNiMmU0NTE5NzM\\u003d\",\r\n" + " \"artifactDescription\" : \"Auto-generated HEAT Environment deployment artifact\",\r\n"
+ + " \"artifactTimeout\" : 0,\r\n" + " \"artifactUUID\" : \"ce65d31c-35c0-43a9-90c7-596fc51d0c86\",\r\n" + " \"artifactVersion\" : \"1\",\r\n"
+ + " \"generatedFromUUID\" : \"8df6123c-f368-47d3-93be-1972cefbcc35\"\r\n" + " }\r\n" + " ]\r\n" + " }\r\n" + " ]}";
+ }
+
+ private String getNotificationWithMultipleResources(){
+ return "{\"distributionID\" : \"bcc7a72e-90b1-4c5f-9a37-28dc3cd86416\",\r\n" +
+ " \"serviceName\" : \"Testnotificationser1\",\r\n" +
+ " \"serviceVersion\" : \"1.0\",\r\n" +
+ " \"serviceUUID\" : \"7f7f94f4-373a-4b71-a0e3-80ae2ba4eb5d\",\r\n" +
+ " \"serviceDescription\" : \"TestNotificationVF1\",\r\n" +
+ " \"resources\" : [{\r\n" +
+ " \"resourceInstanceName\" : \"testnotificationvf11\",\r\n" +
+ " \"resourceName\" : \"TestNotificationVF1\",\r\n" +
+ " \"resourceVersion\" : \"1.0\",\r\n" +
+ " \"resoucreType\" : \"VF\",\r\n" +
+ " \"resourceUUID\" : \"907e1746-9f69-40f5-9f2a-313654092a2d\",\r\n" +
+ " \"artifacts\" : [{\r\n" +
+ " \"artifactName\" : \"sample-xml-alldata-1-1.xml\",\r\n" +
+ " \"artifactType\" : \"YANG_XML\",\r\n" +
+ " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/sample-xml-alldata-1-1.xml\",\r\n" +
+ " \"artifactChecksum\" : \"MTUxODFkMmRlOTNhNjYxMGYyYTI1ZjA5Y2QyNWQyYTk\\u003d\",\r\n" +
+ " \"artifactDescription\" : \"MyYang\",\r\n" +
+ " \"artifactTimeout\" : 0,\r\n" +
+ " \"artifactUUID\" : \"0005bc4a-2c19-452e-be6d-d574a56be4d0\",\r\n" +
+ " \"artifactVersion\" : \"1\"\r\n" +
+ " }" +
+ " ]\r\n" +
+ " },\r\n" +
+ " {\r\n" +
+ " \"resourceInstanceName\" : \"testnotificationvf12\",\r\n" +
+ " \"resourceName\" : \"TestNotificationVF1\",\r\n" +
+ " \"resourceVersion\" : \"1.0\",\r\n" +
+ " \"resoucreType\" : \"VF\",\r\n" +
+ " \"resourceUUID\" : \"907e1746-9f69-40f5-9f2a-313654092a2e\",\r\n" +
+ " \"artifacts\" : [{\r\n" +
+ " \"artifactName\" : \"heat.yaml\",\r\n" +
+ " \"artifactType\" : \"HEAT\",\r\n" +
+ " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/heat.yaml\",\r\n" +
+ " \"artifactChecksum\" : \"ODEyNjE4YTMzYzRmMTk2ODVhNTU2NTg3YWEyNmIxMTM\\u003d\",\r\n" +
+ " \"artifactDescription\" : \"heat\",\r\n" +
+ " \"artifactTimeout\" : 60,\r\n" +
+ " \"artifactUUID\" : \"8df6123c-f368-47d3-93be-1972cefbcc35\",\r\n" +
+ " \"artifactVersion\" : \"1\"\r\n" +
+ " }" +
+ " ]\r\n" +
+ " }\r\n" +
+ " ]}";
+ }
+
+
+ private String getAsdcNotificationWithNonExistentArtifact() {
+ return "{\"distributionID\" : \"bcc7a72e-90b1-4c5f-9a37-28dc3cd86416\",\r\n" + " \"serviceName\" : \"Testnotificationser1\",\r\n" + " \"serviceVersion\" : \"1.0\",\r\n"
+ + " \"serviceUUID\" : \"7f7f94f4-373a-4b71-a0e3-80ae2ba4eb5d\",\r\n" + " \"serviceDescription\" : \"TestNotificationVF1\",\r\n" + " \"bugabuga\" : \"xyz\",\r\n" + " \"resources\" : [{\r\n"
+ + " \"resourceInstanceName\" : \"testnotificationvf11\",\r\n" + " \"resourceName\" : \"TestNotificationVF1\",\r\n" + " \"resourceVersion\" : \"1.0\",\r\n" + " \"resoucreType\" : \"VF\",\r\n"
+ + " \"resourceUUID\" : \"907e1746-9f69-40f5-9f2a-313654092a2d\",\r\n" + " \"artifacts\" : [{\r\n" + " \"artifactName\" : \"heat.yaml\",\r\n" + " \"artifactType\" : \"HEAT\",\r\n"
+ + " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/heat.yaml\",\r\n"
+ + " \"artifactChecksum\" : \"ODEyNjE4YTMzYzRmMTk2ODVhNTU2NTg3YWEyNmIxMTM\\u003d\",\r\n" + " \"artifactDescription\" : \"heat\",\r\n" + " \"artifactTimeout\" : 60,\r\n"
+ + " \"artifactUUID\" : \"8df6123c-f368-47d3-93be-1972cefbcc35\",\r\n" + " \"artifactBuga\" : \"8df6123c-f368-47d3-93be-1972cefbcc35\",\r\n" + " \"artifactVersion\" : \"1\"\r\n"
+ + " }, {\r\n" + " \"artifactName\" : \"buga.bug\",\r\n" + " \"artifactType\" : \"BUGA_BUGA\",\r\n"
+ + " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/heat.env\",\r\n"
+ + " \"artifactChecksum\" : \"NGIzMjExZTM1NDc2NjBjOTQyMGJmMWNiMmU0NTE5NzM\\u003d\",\r\n" + " \"artifactDescription\" : \"Auto-generated HEAT Environment deployment artifact\",\r\n"
+ + " \"artifactTimeout\" : 0,\r\n" + " \"artifactUUID\" : \"ce65d31c-35c0-43a9-90c7-596fc51d0c86\",\r\n" + " \"artifactVersion\" : \"1\",\r\n"
+ + " \"generatedFromUUID\" : \"8df6123c-f368-47d3-93be-1972cefbcc35\"\r\n" + " }\r\n" + " ]\r\n" + " }\r\n" + " ]}";
+ }
+
+ private String getAsdcServiceNotificationWithRelatedArtifacts() {
+ return "{\"distributionID\" : \"bcc7a72e-90b1-4c5f-9a37-28dc3cd86416\",\r\n" + " \"serviceName\" : \"Testnotificationser1\",\r\n" + " \"serviceVersion\" : \"1.0\",\r\n"
+ + " \"serviceUUID\" : \"7f7f94f4-373a-4b71-a0e3-80ae2ba4eb5d\",\r\n" + " \"serviceDescription\" : \"TestNotificationVF1\",\r\n" + " \"resources\" : [{\r\n" + " \"resourceInstanceName\" : \"testnotificationvf11\",\r\n"
+ + " \"resourceName\" : \"TestNotificationVF1\",\r\n" + " \"resourceVersion\" : \"1.0\",\r\n" + " \"resoucreType\" : \"VF\",\r\n" + " \"resourceUUID\" : \"907e1746-9f69-40f5-9f2a-313654092a2d\",\r\n"
+ + " \"artifacts\" : [{\r\n" + " \"artifactName\" : \"sample-xml-alldata-1-1.xml\",\r\n" + " \"artifactType\" : \"YANG_XML\",\r\n"
+ + " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/sample-xml-alldata-1-1.xml\",\r\n"
+ + " \"artifactChecksum\" : \"MTUxODFkMmRlOTNhNjYxMGYyYTI1ZjA5Y2QyNWQyYTk\\u003d\",\r\n" + " \"artifactDescription\" : \"MyYang\",\r\n" + " \"artifactTimeout\" : 0,\r\n"
+ + " \"artifactUUID\" : \"0005bc4a-2c19-452e-be6d-d574a56be4d0\",\r\n" + " \"artifactVersion\" : \"1\",\r\n" + " \"relatedArtifacts\" : [\r\n"
+ + " \"ce65d31c-35c0-43a9-90c7-596fc51d0c86\"\r\n" + " ]" + " }, {\r\n" + " \"artifactName\" : \"heat.yaml\",\r\n"
+ + " \"artifactType\" : \"HEAT\",\r\n" + " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/heat.yaml\",\r\n"
+ + " \"artifactChecksum\" : \"ODEyNjE4YTMzYzRmMTk2ODVhNTU2NTg3YWEyNmIxMTM\\u003d\",\r\n" + " \"artifactDescription\" : \"heat\",\r\n" + " \"artifactTimeout\" : 60,\r\n"
+ + " \"artifactUUID\" : \"8df6123c-f368-47d3-93be-1972cefbcc35\",\r\n" + " \"artifactVersion\" : \"1\", \r\n" + " \"relatedArtifacts\" : [\r\n"
+ + " \"0005bc4a-2c19-452e-be6d-d574a56be4d0\", \r\n" + " \"ce65d31c-35c0-43a9-90c7-596fc51d0c86\"\r\n" + " ]" + " }, {\r\n"
+ + " \"artifactName\" : \"heat.env\",\r\n" + " \"artifactType\" : \"HEAT_ENV\",\r\n"
+ + " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/heat.env\",\r\n"
+ + " \"artifactChecksum\" : \"NGIzMjExZTM1NDc2NjBjOTQyMGJmMWNiMmU0NTE5NzM\\u003d\",\r\n" + " \"artifactDescription\" : \"Auto-generated HEAT Environment deployment artifact\",\r\n"
+ + " \"artifactTimeout\" : 0,\r\n" + " \"artifactUUID\" : \"ce65d31c-35c0-43a9-90c7-596fc51d0c86\",\r\n" + " \"artifactVersion\" : \"1\",\r\n"
+ + " \"generatedFromUUID\" : \"8df6123c-f368-47d3-93be-1972cefbcc35\"\r\n" + " }\r\n" + " ]\r\n" + " }\r\n" + " ]}";
+ }
+
+ private String getAsdcServiceNotificationWithoutHeatArtifact() {
+ return "{" + " \"distributionID\" : \"5v1234d8-5b6d-42c4-7t54-47v95n58qb7\"," + " \"serviceName\" : \"srv1\"," + " \"serviceVersion\": \"2.0\"," + " \"serviceUUID\" : \"4e0697d8-5b6d-42c4-8c74-46c33d46624c\","
+ + " \"serviceArtifacts\":[" + " {" + " \"artifactName\" : \"ddd.yml\"," + " \"artifactType\" : \"DG_XML\"," + " \"artifactTimeout\" : \"65\","
+ + " \"artifactDescription\" : \"description\"," + " \"artifactURL\" :" + " \"/sdc/v1/catalog/services/srv1/2.0/resources/ddd/3.0/artifacts/ddd.xml\" ,"
+ + " \"resourceUUID\" : \"4e5874d8-5b6d-42c4-8c74-46c33d90drw\" ," + " \"checksum\" : \"15e389rnrp58hsw==\"" + " }" + " ]" + "}";
+ }
+
+ private String getNotificationWithServiceArtifatcs() {
+ return "{\r\n" + " \"distributionID\" : \"bcc7a72e-90b1-4c5f-9a37-28dc3cd86416\",\r\n" + " \"serviceName\" : \"Testnotificationser1\",\r\n" + " \"serviceVersion\" : \"1.0\",\r\n"
+ + " \"serviceUUID\" : \"7f7f94f4-373a-4b71-a0e3-80ae2ba4eb5d\",\r\n" + " \"serviceDescription\" : \"TestNotificationVF1\",\r\n" + " \"serviceArtifacts\" : [{\r\n" + " \"artifactName\" : \"sample-xml-alldata-1-1.xml\",\r\n"
+ + " \"artifactType\" : \"YANG_XML\",\r\n" + " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/sample-xml-alldata-1-1.xml\",\r\n"
+ + " \"artifactChecksum\" : \"MTUxODFkMmRlOTNhNjYxMGYyYTI1ZjA5Y2QyNWQyYTk\\u003d\",\r\n" + " \"artifactDescription\" : \"MyYang\",\r\n" + " \"artifactTimeout\" : 0,\r\n"
+ + " \"artifactUUID\" : \"0005bc4a-2c19-452e-be6d-d574a56be4d0\",\r\n" + " \"artifactVersion\" : \"1\"\r\n" + " }, {\r\n" + " \"artifactName\" : \"heat.yaml\",\r\n"
+ + " \"artifactType\" : \"HEAT\",\r\n" + " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/heat.yaml\",\r\n"
+ + " \"artifactChecksum\" : \"ODEyNjE4YTMzYzRmMTk2ODVhNTU2NTg3YWEyNmIxMTM\\u003d\",\r\n" + " \"artifactDescription\" : \"heat\",\r\n" + " \"artifactTimeout\" : 60,\r\n"
+ + " \"artifactUUID\" : \"8df6123c-f368-47d3-93be-1972cefbcc35\",\r\n" + " \"artifactVersion\" : \"1\"\r\n" + " }, {\r\n" + " \"artifactName\" : \"heat.env\",\r\n"
+ + " \"artifactType\" : \"HEAT_ENV\",\r\n" + " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/heat.env\",\r\n"
+ + " \"artifactChecksum\" : \"NGIzMjExZTM1NDc2NjBjOTQyMGJmMWNiMmU0NTE5NzM\\u003d\",\r\n" + " \"artifactDescription\" : \"Auto-generated HEAT Environment deployment artifact\",\r\n"
+ + " \"artifactTimeout\" : 0,\r\n" + " \"artifactUUID\" : \"ce65d31c-35c0-43a9-90c7-596fc51d0c86\",\r\n" + " \"artifactVersion\" : \"1\",\r\n"
+ + " \"generatedFromUUID\" : \"8df6123c-f368-47d3-93be-1972cefbcc35\"\r\n" + " }\r\n" + " ],\r\n" + " \"resources\" : [{\r\n" + " \"resourceInstanceName\" : \"testnotificationvf11\",\r\n"
+ + " \"resourceName\" : \"TestNotificationVF1\",\r\n" + " \"resourceVersion\" : \"1.0\",\r\n" + " \"resoucreType\" : \"VF\",\r\n" + " \"resourceUUID\" : \"907e1746-9f69-40f5-9f2a-313654092a2d\",\r\n"
+ + " \"artifacts\" : [{\r\n" + " \"artifactName\" : \"sample-xml-alldata-1-1.xml\",\r\n" + " \"artifactType\" : \"YANG_XML\",\r\n"
+ + " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/sample-xml-alldata-1-1.xml\",\r\n"
+ + " \"artifactChecksum\" : \"MTUxODFkMmRlOTNhNjYxMGYyYTI1ZjA5Y2QyNWQyYTk\\u003d\",\r\n" + " \"artifactDescription\" : \"MyYang\",\r\n" + " \"artifactTimeout\" : 0,\r\n"
+ + " \"artifactUUID\" : \"0005bc4a-2c19-452e-be6d-d574a56be4d0\",\r\n" + " \"artifactVersion\" : \"1\"\r\n" + " }, {\r\n" + " \"artifactName\" : \"heat.yaml\",\r\n"
+ + " \"artifactType\" : \"HEAT\",\r\n" + " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/heat.yaml\",\r\n"
+ + " \"artifactChecksum\" : \"ODEyNjE4YTMzYzRmMTk2ODVhNTU2NTg3YWEyNmIxMTM\\u003d\",\r\n" + " \"artifactDescription\" : \"heat\",\r\n" + " \"artifactTimeout\" : 60,\r\n"
+ + " \"artifactUUID\" : \"8df6123c-f368-47d3-93be-1972cefbcc35\",\r\n" + " \"artifactVersion\" : \"1\"\r\n" + " }, {\r\n" + " \"artifactName\" : \"heat.env\",\r\n"
+ + " \"artifactType\" : \"HEAT_ENV\",\r\n" + " \"artifactURL\" : \"/sdc/v1/catalog/services/Testnotificationser1/1.0/resourceInstances/testnotificationvf11/artifacts/heat.env\",\r\n"
+ + " \"artifactChecksum\" : \"NGIzMjExZTM1NDc2NjBjOTQyMGJmMWNiMmU0NTE5NzM\\u003d\",\r\n" + " \"artifactDescription\" : \"Auto-generated HEAT Environment deployment artifact\",\r\n"
+ + " \"artifactTimeout\" : 0,\r\n" + " \"artifactUUID\" : \"ce65d31c-35c0-43a9-90c7-596fc51d0c86\",\r\n" + " \"artifactVersion\" : \"1\",\r\n"
+ + " \"generatedFromUUID\" : \"8df6123c-f368-47d3-93be-1972cefbcc35\"\r\n" + " }\r\n" + " ]\r\n" + " }\r\n" + " ]\r\n" + "}";
+ }
+
+ private <T> int countInstances(List<T> list, T element) {
+ int count = 0;
+ for (T curr : list) {
+ if (curr.equals(element)) {
+ count++;
+ }
+ }
+ return count;
+ }
+}