aboutsummaryrefslogtreecommitdiffstats
path: root/blueprints-processor
diff options
context:
space:
mode:
Diffstat (limited to 'blueprints-processor')
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java108
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java179
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java107
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java91
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java57
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/resources/assignments/alltype-empty-value-mapping.json86
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/resources/assignments/alltype-mapping.json110
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/resources/assignments/empty-dictionary.json1
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/resources/validation/cyclic.json111
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/resources/validation/duplicate.json110
-rw-r--r--blueprints-processor/plugin/assignment-provider/src/test/resources/validation/success.json110
11 files changed, 1070 insertions, 0 deletions
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java
new file mode 100644
index 000000000..4696fd281
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java
@@ -0,0 +1,108 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.config.assignment.service;
+
+import java.io.File;
+import java.nio.charset.Charset;
+import org.apache.commons.io.FileUtils;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+import org.mockito.MockitoAnnotations;
+import org.mockito.runners.MockitoJUnitRunner;
+import org.onap.ccsdk.config.assignment.data.ResourceAssignmentData;
+import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource;
+import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;
+import org.onap.ccsdk.config.generator.service.ConfigGeneratorService;
+import org.onap.ccsdk.config.generator.service.ConfigGeneratorServiceImpl;
+import org.onap.ccsdk.config.model.service.ConfigModelService;
+import org.onap.ccsdk.config.model.service.ConfigModelServiceImpl;
+import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+@RunWith(MockitoJUnitRunner.class)
+public class ConfigPreviewServiceTest {
+
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigPreviewServiceTest.class);
+
+ @Rule
+ public ExpectedException thrown = ExpectedException.none();
+
+ @Mock
+ private ConfigResourceService configResourceService;
+
+ @Mock
+ private ConfigRestAdaptorService configRestAdaptorService;
+
+ private ConfigModelService configModelService;
+ private ConfigGeneratorService configGeneratorService;
+
+ @SuppressWarnings("unchecked")
+ @Before
+ public void before() throws Exception {
+ MockitoAnnotations.initMocks(this);
+ }
+
+ @Test
+ public void testGenerateTemplateResourceMash() throws Exception {
+
+ ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService);
+
+ ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment");
+
+ ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService,
+ "assignments/empty-dictionary.json");
+
+ ConfigResource configResourceQuery = new ConfigResource();
+ configResourceQuery.setServiceTemplateVersion("sample-serviceTemplateName");
+ configResourceQuery.setServiceTemplateVersion("1.0.0");
+ configResourceQuery.setRecipeName("sample-action");
+ configResourceQuery.setResourceId("123-resourceId");
+ configResourceQuery.setResourceType("sample-resourceType");
+ configResourceQuery.setTemplateName("base-config-template");
+ String inputContent = FileUtils.readFileToString(
+ new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset());
+ configResourceQuery.setResourceData(inputContent);
+
+ ConfigResourceAssignmentTestUtils.injectGetConfigResourceMock(configResourceService, configResourceQuery);
+
+ configModelService = new ConfigModelServiceImpl(configRestAdaptorService);
+ configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService);
+
+ ConfigPreviewService configPreviewService =
+ new ConfigPreviewService(configResourceService, configModelService, configGeneratorService);
+
+ ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData();
+ resourceAssignmentData.setResourceId("123-resourceId");
+ resourceAssignmentData.setResourceType("sample-resourceType");
+ resourceAssignmentData.setServiceTemplateName("sample-serviceTemplateName");
+ resourceAssignmentData.setServiceTemplateVersion("1.0.0");
+ resourceAssignmentData.setActionName("sample-action");
+
+ resourceAssignmentData = configPreviewService.generateTemplateResourceMash(resourceAssignmentData);
+
+ Assert.assertNotNull("Failed to get GenerateTemplateResourceMash response.", resourceAssignmentData);
+ Assert.assertNotNull("Failed to get template mashed contents.",
+ resourceAssignmentData.getTemplatesMashedContents());
+
+ Assert.assertNotNull("Failed to get base-config template mashed contents.",
+ resourceAssignmentData.getTemplatesMashedContents().get("base-config-template"));
+ }
+}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java
new file mode 100644
index 000000000..f4ee969fb
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java
@@ -0,0 +1,179 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.config.assignment.service;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyString;
+import java.io.File;
+import java.nio.charset.Charset;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.io.FileUtils;
+import org.apache.commons.io.FilenameUtils;
+import org.apache.commons.io.IOUtils;
+import org.mockito.Matchers;
+import org.mockito.Mockito;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource;
+import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog;
+import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;
+import org.onap.ccsdk.config.model.ConfigModelConstant;
+import org.onap.ccsdk.config.model.data.dict.ResourceDefinition;
+import org.onap.ccsdk.config.model.domain.ConfigModel;
+import org.onap.ccsdk.config.model.domain.ConfigModelContent;
+import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.core.type.TypeReference;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+public class ConfigResourceAssignmentTestUtils {
+
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigResourceAssignmentTestUtils.class);
+
+ public static void injectTransactionLogSaveMock(ConfigResourceService configResourceService) throws Exception {
+ Mockito.doAnswer(new Answer<Void>() {
+ @Override
+ public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
+ Object[] args = invocationOnMock.getArguments();
+ if (args != null) {
+ logger.trace("Transaction info " + Arrays.asList(args));
+ }
+ return null;
+ }
+ }).when(configResourceService).save(any(TransactionLog.class));
+ }
+
+ public static void injectConfigModelMock(ConfigRestAdaptorService configRestAdaptorService,
+ String serviceTemplateName) throws Exception {
+
+ Mockito.doAnswer(new Answer<ConfigModel>() {
+ @Override
+ public org.onap.ccsdk.config.model.domain.ConfigModel answer(InvocationOnMock invocationOnMock)
+ throws Throwable {
+ Object[] args = invocationOnMock.getArguments();
+ org.onap.ccsdk.config.model.domain.ConfigModel serviceArtifact = null;
+ if (args != null && args.length == 3) {
+
+ logger.info("Artifact info " + Arrays.asList(args));
+ String modelContent = IOUtils.toString(
+ ConfigResourceAssignmentTestUtils.class.getClassLoader().getResourceAsStream(
+ "service_templates/" + serviceTemplateName + "/" + serviceTemplateName + ".json"),
+ Charset.defaultCharset());
+
+ ConfigModelContent configModelContent = new ConfigModelContent();
+ configModelContent.setContent(modelContent);
+ configModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON);
+
+ List<ConfigModelContent> configModelContents = new ArrayList<>();
+ configModelContents.add(configModelContent);
+
+ String velocityDir = ConfigResourceAssignmentTestUtils.class.getClassLoader()
+ .getResource("service_templates/" + serviceTemplateName + "/velocity").getPath();
+
+ Collection<File> templateFiles =
+ FileUtils.listFiles(new File(velocityDir), new String[] {"vtl"}, true);
+ logger.info("Template Files info " + templateFiles);
+ for (File templateFile : templateFiles) {
+ String templateContent = FileUtils.readFileToString(templateFile, Charset.defaultCharset());
+ ConfigModelContent configModelTemplateContent = new ConfigModelContent();
+ configModelTemplateContent.setContent(templateContent);
+ configModelTemplateContent.setName(FilenameUtils.getBaseName(templateFile.getName()));
+ configModelTemplateContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE);
+ configModelContents.add(configModelTemplateContent);
+ }
+
+ serviceArtifact = new org.onap.ccsdk.config.model.domain.ConfigModel();
+ serviceArtifact.setArtifactName(String.valueOf(args[0]));
+ serviceArtifact.setArtifactVersion(String.valueOf(args[1]));
+ serviceArtifact.setPublished("Y");
+ serviceArtifact.setConfigModelContents(configModelContents);
+ }
+
+ return serviceArtifact;
+ }
+ }).when(configRestAdaptorService).getResource(anyString(), anyString(), Matchers.any(Class.class));
+ }
+
+ public static void injectResourceDictionaryMock(ConfigRestAdaptorService configRestAdaptorService,
+ String dictionaryFileName) throws Exception {
+
+ Mockito.doAnswer(new Answer<String>() {
+ @Override
+ public String answer(InvocationOnMock invocationOnMock) throws Throwable {
+ Object[] args = invocationOnMock.getArguments();
+ String dictionaties = "[]";
+ if (args != null) {
+ logger.info("getResourceDictionaryByNames " + Arrays.asList(args));
+ dictionaties = IOUtils.toString(
+ ConfigAssignmentNodeTest.class.getClassLoader().getResourceAsStream(dictionaryFileName),
+ Charset.defaultCharset());
+ }
+ return dictionaties;
+ }
+ }).when(configRestAdaptorService).postResource(Matchers.any(), Matchers.any(), Matchers.any(),
+ Matchers.any(Class.class));
+ }
+
+ public static void injectConfigResourceSaveMock(ConfigResourceService configResourceService) throws Exception {
+ Mockito.doAnswer(new Answer<ConfigResource>() {
+ @Override
+ public ConfigResource answer(InvocationOnMock invocationOnMock) throws Throwable {
+ Object[] args = invocationOnMock.getArguments();
+ ConfigResource configResource = null;
+ if (args != null) {
+ configResource = (ConfigResource) args[0];
+ logger.info("Config Resource Save info " + configResource);
+ return configResource;
+ }
+ return configResource;
+ }
+ }).when(configResourceService).saveConfigResource(any(ConfigResource.class));
+ }
+
+ public static void injectGetConfigResourceMock(ConfigResourceService configResourceService,
+ ConfigResource configResource) throws Exception {
+ Mockito.doAnswer(new Answer<List<ConfigResource>>() {
+ @Override
+ public List<ConfigResource> answer(InvocationOnMock invocationOnMock) throws Throwable {
+ Object[] args = invocationOnMock.getArguments();
+ List<ConfigResource> configResources = new ArrayList<>();
+ if (args != null) {
+ configResources.add(configResource);
+ }
+ return configResources;
+ }
+ }).when(configResourceService).getConfigResource(any(ConfigResource.class));
+ }
+
+ public static String getFileContent(String filePath) throws Exception {
+ return IOUtils.toString(ConfigResourceAssignmentTestUtils.class.getClassLoader().getResourceAsStream(filePath),
+ Charset.defaultCharset());
+ }
+
+ public static Map<String, ResourceDefinition> getMapfromJson(String content) {
+ try {
+ ObjectMapper mapper = new ObjectMapper();
+ return mapper.readValue(content, new TypeReference<Map<String, ResourceDefinition>>() {});
+ } catch (Exception e) {
+ logger.info("getMapfromJson Exception ({})", e);
+ }
+ return null;
+ }
+}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java
new file mode 100644
index 000000000..e979ea3d1
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java
@@ -0,0 +1,107 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.config.assignment.service;
+
+import java.nio.charset.Charset;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import org.apache.commons.io.IOUtils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.ccsdk.config.model.ConfigModelConstant;
+import org.onap.ccsdk.config.model.ValidTypes;
+import org.onap.ccsdk.config.model.data.ResourceAssignment;
+import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils;
+import org.onap.ccsdk.config.model.utils.TransformationUtils;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import com.fasterxml.jackson.databind.JsonNode;
+
+public class ResourceAssignmentGenerationTest {
+
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentGenerationTest.class);
+
+ @Test
+ public void testResourceDataSetting() {
+ try {
+ logger.info(" **************** testResourceDataSetting *****************");
+ String resourceAssignmentContents = IOUtils.toString(TopologicalSortingTest.class.getClassLoader()
+ .getResourceAsStream("assignments/alltype-empty-value-mapping.json"), Charset.defaultCharset());
+
+ List<ResourceAssignment> assignments =
+ TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class);
+ if (assignments != null) {
+ Map<String, Object> componentContext = new HashMap<>();
+ componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "sample-recipe");
+ for (ResourceAssignment resourceAssignment : assignments) {
+ if (resourceAssignment != null && resourceAssignment.getProperty() != null) {
+ String type = resourceAssignment.getProperty().getType();
+ Object value = null;
+ if (ValidTypes.DATA_TYPE_STRING.equals(type)) {
+ value = new String("abcdef");
+ } else if (ValidTypes.DATA_TYPE_INTEGER.equals(type)) {
+ value = new Integer(1234);
+ } else if (ValidTypes.DATA_TYPE_BOOLEAN.equals(type)) {
+ value = new Boolean(true);
+ } else if (ValidTypes.DATA_TYPE_LIST.equals(type)) {
+ String entityType = resourceAssignment.getProperty().getEntrySchema().getType();
+ if (ValidTypes.DATA_TYPE_STRING.equals(entityType)) {
+ value = "[\"abcd-array\"]";
+ } else {
+ String content = "[{\"name\" : \"abcd-array-complex\"}]";
+ JsonNode node = TransformationUtils.getJsonNodeForString(content);
+ value = node;
+ }
+ } else {
+ String content = "{\"name\" : \"abcd-complex\"}";
+ JsonNode node = TransformationUtils.getJsonNodeForString(content);
+ value = node;
+ }
+ ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value);
+ }
+ }
+ String generatedData = ResourceAssignmentUtils.generateResourceDataForAssignments(assignments);
+ logger.trace("Generated Data " + generatedData);
+
+ Assert.assertNotNull("Failed to generate resource data", generatedData);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test
+ public void testGenerateResourceData() {
+ try {
+ logger.info(" **************** testGenerateResourceData *****************");
+ String resourceAssignmentContents = IOUtils.toString(TopologicalSortingTest.class.getClassLoader()
+ .getResourceAsStream("assignments/alltype-mapping.json"), Charset.defaultCharset());
+
+ List<ResourceAssignment> assignments =
+ TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class);
+ if (assignments != null) {
+
+ String generatedData = ResourceAssignmentUtils.generateResourceDataForAssignments(assignments);
+ logger.trace("Generated Data " + generatedData);
+
+ Assert.assertNotNull("Failed to generate resource data", generatedData);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java
new file mode 100644
index 000000000..0bf74b4c0
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java
@@ -0,0 +1,91 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.config.assignment.service;
+
+import java.io.IOException;
+import java.nio.charset.Charset;
+import java.util.List;
+import org.apache.commons.io.IOUtils;
+import org.junit.Assert;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.onap.ccsdk.config.model.ConfigModelException;
+import org.onap.ccsdk.config.model.data.ResourceAssignment;
+import org.onap.ccsdk.config.model.utils.TransformationUtils;
+import org.onap.ccsdk.config.model.validator.ResourceAssignmentValidator;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class ResourceAssignmentValidation {
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentValidation.class);
+
+ @Rule
+ public final ExpectedException exception = ExpectedException.none();
+
+ @Test
+ public void testValidateSuccess() {
+ try {
+ logger.info(" **************** testValidateSuccess *****************");
+ String resourceMapping = IOUtils.toString(
+ TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/success.json"),
+ Charset.defaultCharset());
+
+ List<ResourceAssignment> assignments =
+ TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class);
+ if (assignments != null) {
+ ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments);
+
+ boolean result = resourceAssignmentValidator.validateResourceAssignment();
+ Assert.assertTrue("Failed to Validate", result);
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Test(expected = ConfigModelException.class)
+ public void testValidateDuplicate() throws IOException, ConfigModelException {
+ logger.info(" **************** testValidateDuplicate *****************");
+ String resourceMapping = IOUtils.toString(
+ TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/duplicate.json"),
+ Charset.defaultCharset());
+
+ List<ResourceAssignment> assignments =
+ TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class);
+ if (assignments != null) {
+ ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments);
+ resourceAssignmentValidator.validateResourceAssignment();
+ }
+
+ }
+
+ @Test(expected = ConfigModelException.class)
+ public void testValidateCyclic() throws IOException, ConfigModelException {
+ logger.info(" **************** testValidateCyclic *****************");
+ String resourceMapping = IOUtils.toString(
+ TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/cyclic.json"),
+ Charset.defaultCharset());
+
+ List<ResourceAssignment> assignments =
+ TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class);
+ if (assignments != null) {
+ ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments);
+
+ resourceAssignmentValidator.validateResourceAssignment();
+ }
+
+ }
+}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java
new file mode 100644
index 000000000..1b05e4b0e
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java
@@ -0,0 +1,57 @@
+/*
+ * Copyright © 2017-2018 AT&T Intellectual Property.
+ *
+ * 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.
+ */
+
+package org.onap.ccsdk.config.assignment.service;
+
+import java.nio.charset.Charset;
+import java.util.List;
+import org.apache.commons.io.IOUtils;
+import org.junit.Assert;
+import org.junit.Test;
+import org.onap.ccsdk.config.assignment.processor.ResourceAssignmentProcessor;
+import org.onap.ccsdk.config.model.data.ResourceAssignment;
+import org.onap.ccsdk.config.model.utils.TransformationUtils;
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+
+public class TopologicalSortingTest {
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(TopologicalSortingTest.class);
+
+ @Test
+ public void testBulkSequencingMapping() {
+ try {
+ logger.info(" **************** Bulk Sequencing Default *****************");
+ String resourceMapping = IOUtils.toString(
+ TopologicalSortingTest.class.getClassLoader().getResourceAsStream("mapping/dependency.json"),
+ Charset.defaultCharset());
+
+ List<ResourceAssignment> assignments =
+ TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class);
+ if (assignments != null) {
+ SvcLogicContext ctx = new SvcLogicContext();
+ ResourceAssignmentProcessor resourceAssignmentProcessor =
+ new ResourceAssignmentProcessor(assignments, ctx);
+ List<List<ResourceAssignment>> sequenceBatchResourceAssignment = resourceAssignmentProcessor.process();
+
+ Assert.assertNotNull("Failed to populate Sequence Bulk Mappings", sequenceBatchResourceAssignment);
+ Assert.assertNotEquals("Failed to populate Sequence Bulk Mappings size ",
+ (sequenceBatchResourceAssignment.size() > 0));
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+}
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/assignments/alltype-empty-value-mapping.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/assignments/alltype-empty-value-mapping.json
new file mode 100644
index 000000000..a3d65927b
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/assignments/alltype-empty-value-mapping.json
@@ -0,0 +1,86 @@
+[
+ {
+ "name": "vnf-id-string",
+ "property": {
+ "required": true,
+ "type": "string"
+ },
+ "input-param": true,
+ "dictionary-name": "vnf-id-string",
+ "dictionary-source": "input",
+ "version": 0,
+ "status": "success",
+ "updated-by": "System"
+ },
+ {
+ "name": "vnf-id-integer",
+ "property": {
+ "required": true,
+ "type": "integer"
+ },
+ "input-param": true,
+ "dictionary-name": "vnf-id-integer",
+ "dictionary-source": "input",
+ "version": 0,
+ "status": "success",
+ "updated-by": "System"
+ },
+ {
+ "name": "vnf-boolean",
+ "property": {
+ "required": true,
+ "type": "boolean"
+ },
+ "input-param": true,
+ "dictionary-name": "vnf-boolean",
+ "dictionary-source": "input",
+ "version": 0,
+ "status": "success",
+ "updated-by": "System"
+ },
+ {
+ "name": "vnf-complex",
+ "property": {
+ "required": true,
+ "type": "dt-complex"
+ },
+ "input-param": true,
+ "dictionary-name": "vnf-complex",
+ "dictionary-source": "input",
+ "version": 0,
+ "status": "success",
+ "updated-by": "System"
+ },
+ {
+ "name": "vnf-id-array",
+ "property": {
+ "required": true,
+ "type": "list",
+ "entry_schema": {
+ "type": "string"
+ }
+ },
+ "input-param": true,
+ "dictionary-name": "vnf-id-array",
+ "dictionary-source": "input",
+ "version": 0,
+ "status": "success",
+ "updated-by": "System"
+ },
+ {
+ "name": "vnf-array-complex",
+ "property": {
+ "required": true,
+ "type": "list",
+ "entry_schema": {
+ "type": "dt-complex"
+ }
+ },
+ "input-param": true,
+ "dictionary-name": "vnf-array-complex",
+ "dictionary-source": "input",
+ "version": 0,
+ "status": "success",
+ "updated-by": "System"
+ }
+]
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/assignments/alltype-mapping.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/assignments/alltype-mapping.json
new file mode 100644
index 000000000..36909da99
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/assignments/alltype-mapping.json
@@ -0,0 +1,110 @@
+[
+ {
+ "name": "vnf-id-string",
+ "property": {
+ "required": true,
+ "type": "string",
+ "value": "123456"
+ },
+ "input-param": true,
+ "dictionary-name": "vnf-id-string",
+ "dictionary-source": "input",
+ "version": 0,
+ "status": "success",
+ "updated-by": "System"
+ },
+ {
+ "name": "vnf-id-integer",
+ "property": {
+ "required": true,
+ "type": "integer",
+ "value": 123456
+ },
+ "input-param": true,
+ "dictionary-name": "vnf-id-integer",
+ "dictionary-source": "input",
+ "version": 0,
+ "status": "success",
+ "updated-by": "System"
+ },
+ {
+ "name": "vnf-boolean",
+ "property": {
+ "required": true,
+ "type": "boolean",
+ "value": true
+ },
+ "input-param": true,
+ "dictionary-name": "vnf-boolean",
+ "dictionary-source": "input",
+ "version": 0,
+ "status": "success",
+ "updated-by": "System"
+ },
+ {
+ "name": "vnf-complex",
+ "property": {
+ "required": true,
+ "type": "dt-complex",
+ "value": {
+ "name": "Brinda",
+ "location": "Madurai",
+ "count": 2
+ }
+ },
+ "input-param": true,
+ "dictionary-name": "vnf-complex",
+ "dictionary-source": "input",
+ "version": 0,
+ "status": "success",
+ "updated-by": "System"
+ },
+ {
+ "name": "vnf-id-array",
+ "property": {
+ "required": true,
+ "type": "list",
+ "entry_schema": {
+ "type": "string"
+ },
+ "value": [
+ "A",
+ "B",
+ "C"
+ ]
+ },
+ "input-param": true,
+ "dictionary-name": "vnf-id-array",
+ "dictionary-source": "input",
+ "version": 0,
+ "status": "success",
+ "updated-by": "System"
+ },
+ {
+ "name": "vnf-array-complex",
+ "property": {
+ "required": true,
+ "type": "list",
+ "entry_schema": {
+ "type": "dt-complex"
+ },
+ "value": [
+ {
+ "name": "A"
+ },
+ {
+ "name": "B"
+ },
+ {
+ "name": "C"
+ }
+ ]
+ },
+ "input-param": true,
+ "dictionary-name": "vnf-array-complex",
+ "dictionary-source": "input",
+ "version": 0,
+ "status": "success",
+ "updated-by": "System"
+ }
+]
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/assignments/empty-dictionary.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/assignments/empty-dictionary.json
new file mode 100644
index 000000000..0637a088a
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/assignments/empty-dictionary.json
@@ -0,0 +1 @@
+[] \ No newline at end of file
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/validation/cyclic.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/validation/cyclic.json
new file mode 100644
index 000000000..fc6357f2d
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/validation/cyclic.json
@@ -0,0 +1,111 @@
+[
+ {
+ "name": "vnf-id",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "vnf-id",
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "service-instance-id",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "service-instance-id",
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "bundle-id",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "bundle-id",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "vnf-id"
+ ]
+ },
+ {
+ "name": "bundle-ip",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "bundle-ip",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "vnf-id"
+ ]
+ },
+ {
+ "name": "bundle-mac",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "bundle-mac",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "vnf-id",
+ "bundle-id"
+ ]
+ },
+ {
+ "name": "managed-ip",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "managed-ip",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "loopback-ip"
+ ]
+ },
+ {
+ "name": "vnf-name",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "vnf-name",
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "managed-ip1",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "managed-ip1",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "loopback-ip"
+ ]
+ },
+ {
+ "name": "loopback-ip",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "loopback-ip",
+ "dictionary-source": "db",
+ "dependencies": [
+ "bundle-mac",
+ "managed-ip1"
+ ]
+ }
+]
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/validation/duplicate.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/validation/duplicate.json
new file mode 100644
index 000000000..86909a6a4
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/validation/duplicate.json
@@ -0,0 +1,110 @@
+[
+ {
+ "name": "vnf-id",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "vnf-id",
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "service-instance-id",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "service-instance-id",
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "bundle-id",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "bundle-id",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "vnf-id"
+ ]
+ },
+ {
+ "name": "bundle-ip",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "bundle-ip",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "vnf-id"
+ ]
+ },
+ {
+ "name": "bundle-mac",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "bundle-mac",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "vnf-id",
+ "bundle-id"
+ ]
+ },
+ {
+ "name": "bundle-mac",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "bundle-mac",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "loopback-ip"
+ ]
+ },
+ {
+ "name": "vnf-name",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "vnf-name",
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "managed-ip1",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "managed-ip1",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "loopback-ip"
+ ]
+ },
+ {
+ "name": "loopback-ip",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "loopback-ip",
+ "dictionary-source": "db",
+ "dependencies": [
+ "bundle-mac"
+ ]
+ }
+]
diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/validation/success.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/validation/success.json
new file mode 100644
index 000000000..e08539c0d
--- /dev/null
+++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/validation/success.json
@@ -0,0 +1,110 @@
+[
+ {
+ "name": "vnf-id",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "vnf-id",
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "service-instance-id",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "service-instance-id",
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "bundle-id",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "bundle-id",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "vnf-id"
+ ]
+ },
+ {
+ "name": "bundle-ip",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "bundle-ip",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "vnf-id"
+ ]
+ },
+ {
+ "name": "bundle-mac",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "bundle-mac",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "vnf-id",
+ "bundle-id"
+ ]
+ },
+ {
+ "name": "managed-ip",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "managed-ip",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "loopback-ip"
+ ]
+ },
+ {
+ "name": "vnf-name",
+ "input-param": true,
+ "property": {
+ "type": "string",
+ "required": true
+ },
+ "dictionary-name": "vnf-name",
+ "dictionary-source": "input",
+ "dependencies": []
+ },
+ {
+ "name": "managed-ip1",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "managed-ip1",
+ "dictionary-source": "mdsal",
+ "dependencies": [
+ "loopback-ip"
+ ]
+ },
+ {
+ "name": "loopback-ip",
+ "input-param": true,
+ "property": {
+ "type": "string"
+ },
+ "dictionary-name": "loopback-ip",
+ "dictionary-source": "db",
+ "dependencies": [
+ "bundle-mac"
+ ]
+ }
+]