--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.service;\r
+\r
+import java.io.File;\r
+import java.nio.charset.Charset;\r
+import org.apache.commons.io.FileUtils;\r
+import org.junit.Assert;\r
+import org.junit.Before;\r
+import org.junit.Rule;\r
+import org.junit.Test;\r
+import org.junit.rules.ExpectedException;\r
+import org.junit.runner.RunWith;\r
+import org.mockito.Mock;\r
+import org.mockito.MockitoAnnotations;\r
+import org.mockito.runners.MockitoJUnitRunner;\r
+import org.onap.ccsdk.config.assignment.data.ResourceAssignmentData;\r
+import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource;\r
+import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;\r
+import org.onap.ccsdk.config.generator.service.ConfigGeneratorService;\r
+import org.onap.ccsdk.config.generator.service.ConfigGeneratorServiceImpl;\r
+import org.onap.ccsdk.config.model.service.ConfigModelService;\r
+import org.onap.ccsdk.config.model.service.ConfigModelServiceImpl;\r
+import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+\r
+@RunWith(MockitoJUnitRunner.class)\r
+public class ConfigPreviewServiceTest {\r
+ \r
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigPreviewServiceTest.class);\r
+ \r
+ @Rule\r
+ public ExpectedException thrown = ExpectedException.none();\r
+ \r
+ @Mock\r
+ private ConfigResourceService configResourceService;\r
+ \r
+ @Mock\r
+ private ConfigRestAdaptorService configRestAdaptorService;\r
+ \r
+ private ConfigModelService configModelService;\r
+ private ConfigGeneratorService configGeneratorService;\r
+ \r
+ @SuppressWarnings("unchecked")\r
+ @Before\r
+ public void before() throws Exception {\r
+ MockitoAnnotations.initMocks(this);\r
+ }\r
+ \r
+ @Test\r
+ public void testGenerateTemplateResourceMash() throws Exception {\r
+ \r
+ ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService);\r
+ \r
+ ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment");\r
+ \r
+ ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService,\r
+ "assignments/empty-dictionary.json");\r
+ \r
+ ConfigResource configResourceQuery = new ConfigResource();\r
+ configResourceQuery.setServiceTemplateVersion("sample-serviceTemplateName");\r
+ configResourceQuery.setServiceTemplateVersion("1.0.0");\r
+ configResourceQuery.setRecipeName("sample-action");\r
+ configResourceQuery.setResourceId("123-resourceId");\r
+ configResourceQuery.setResourceType("sample-resourceType");\r
+ configResourceQuery.setTemplateName("base-config-template");\r
+ String inputContent = FileUtils.readFileToString(\r
+ new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset());\r
+ configResourceQuery.setResourceData(inputContent);\r
+ \r
+ ConfigResourceAssignmentTestUtils.injectGetConfigResourceMock(configResourceService, configResourceQuery);\r
+ \r
+ configModelService = new ConfigModelServiceImpl(configRestAdaptorService);\r
+ configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService);\r
+ \r
+ ConfigPreviewService configPreviewService =\r
+ new ConfigPreviewService(configResourceService, configModelService, configGeneratorService);\r
+ \r
+ ResourceAssignmentData resourceAssignmentData = new ResourceAssignmentData();\r
+ resourceAssignmentData.setResourceId("123-resourceId");\r
+ resourceAssignmentData.setResourceType("sample-resourceType");\r
+ resourceAssignmentData.setServiceTemplateName("sample-serviceTemplateName");\r
+ resourceAssignmentData.setServiceTemplateVersion("1.0.0");\r
+ resourceAssignmentData.setActionName("sample-action");\r
+ \r
+ resourceAssignmentData = configPreviewService.generateTemplateResourceMash(resourceAssignmentData);\r
+ \r
+ Assert.assertNotNull("Failed to get GenerateTemplateResourceMash response.", resourceAssignmentData);\r
+ Assert.assertNotNull("Failed to get template mashed contents.",\r
+ resourceAssignmentData.getTemplatesMashedContents());\r
+ \r
+ Assert.assertNotNull("Failed to get base-config template mashed contents.",\r
+ resourceAssignmentData.getTemplatesMashedContents().get("base-config-template"));\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.service;\r
+\r
+import static org.mockito.Matchers.any;\r
+import static org.mockito.Matchers.anyString;\r
+import java.io.File;\r
+import java.nio.charset.Charset;\r
+import java.util.ArrayList;\r
+import java.util.Arrays;\r
+import java.util.Collection;\r
+import java.util.List;\r
+import java.util.Map;\r
+import org.apache.commons.io.FileUtils;\r
+import org.apache.commons.io.FilenameUtils;\r
+import org.apache.commons.io.IOUtils;\r
+import org.mockito.Matchers;\r
+import org.mockito.Mockito;\r
+import org.mockito.invocation.InvocationOnMock;\r
+import org.mockito.stubbing.Answer;\r
+import org.onap.ccsdk.config.data.adaptor.domain.ConfigResource;\r
+import org.onap.ccsdk.config.data.adaptor.domain.TransactionLog;\r
+import org.onap.ccsdk.config.data.adaptor.service.ConfigResourceService;\r
+import org.onap.ccsdk.config.model.ConfigModelConstant;\r
+import org.onap.ccsdk.config.model.data.dict.ResourceDefinition;\r
+import org.onap.ccsdk.config.model.domain.ConfigModel;\r
+import org.onap.ccsdk.config.model.domain.ConfigModelContent;\r
+import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import com.fasterxml.jackson.core.type.TypeReference;\r
+import com.fasterxml.jackson.databind.ObjectMapper;\r
+\r
+public class ConfigResourceAssignmentTestUtils {\r
+ \r
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigResourceAssignmentTestUtils.class);\r
+ \r
+ public static void injectTransactionLogSaveMock(ConfigResourceService configResourceService) throws Exception {\r
+ Mockito.doAnswer(new Answer<Void>() {\r
+ @Override\r
+ public Void answer(InvocationOnMock invocationOnMock) throws Throwable {\r
+ Object[] args = invocationOnMock.getArguments();\r
+ if (args != null) {\r
+ logger.trace("Transaction info " + Arrays.asList(args));\r
+ }\r
+ return null;\r
+ }\r
+ }).when(configResourceService).save(any(TransactionLog.class));\r
+ }\r
+ \r
+ public static void injectConfigModelMock(ConfigRestAdaptorService configRestAdaptorService,\r
+ String serviceTemplateName) throws Exception {\r
+ \r
+ Mockito.doAnswer(new Answer<ConfigModel>() {\r
+ @Override\r
+ public org.onap.ccsdk.config.model.domain.ConfigModel answer(InvocationOnMock invocationOnMock)\r
+ throws Throwable {\r
+ Object[] args = invocationOnMock.getArguments();\r
+ org.onap.ccsdk.config.model.domain.ConfigModel serviceArtifact = null;\r
+ if (args != null && args.length == 3) {\r
+ \r
+ logger.info("Artifact info " + Arrays.asList(args));\r
+ String modelContent = IOUtils.toString(\r
+ ConfigResourceAssignmentTestUtils.class.getClassLoader().getResourceAsStream(\r
+ "service_templates/" + serviceTemplateName + "/" + serviceTemplateName + ".json"),\r
+ Charset.defaultCharset());\r
+ \r
+ ConfigModelContent configModelContent = new ConfigModelContent();\r
+ configModelContent.setContent(modelContent);\r
+ configModelContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TOSCA_JSON);\r
+ \r
+ List<ConfigModelContent> configModelContents = new ArrayList<>();\r
+ configModelContents.add(configModelContent);\r
+ \r
+ String velocityDir = ConfigResourceAssignmentTestUtils.class.getClassLoader()\r
+ .getResource("service_templates/" + serviceTemplateName + "/velocity").getPath();\r
+ \r
+ Collection<File> templateFiles =\r
+ FileUtils.listFiles(new File(velocityDir), new String[] {"vtl"}, true);\r
+ logger.info("Template Files info " + templateFiles);\r
+ for (File templateFile : templateFiles) {\r
+ String templateContent = FileUtils.readFileToString(templateFile, Charset.defaultCharset());\r
+ ConfigModelContent configModelTemplateContent = new ConfigModelContent();\r
+ configModelTemplateContent.setContent(templateContent);\r
+ configModelTemplateContent.setName(FilenameUtils.getBaseName(templateFile.getName()));\r
+ configModelTemplateContent.setContentType(ConfigModelConstant.MODEL_CONTENT_TYPE_TEMPLATE);\r
+ configModelContents.add(configModelTemplateContent);\r
+ }\r
+ \r
+ serviceArtifact = new org.onap.ccsdk.config.model.domain.ConfigModel();\r
+ serviceArtifact.setArtifactName(String.valueOf(args[0]));\r
+ serviceArtifact.setArtifactVersion(String.valueOf(args[1]));\r
+ serviceArtifact.setPublished("Y");\r
+ serviceArtifact.setConfigModelContents(configModelContents);\r
+ }\r
+ \r
+ return serviceArtifact;\r
+ }\r
+ }).when(configRestAdaptorService).getResource(anyString(), anyString(), Matchers.any(Class.class));\r
+ }\r
+ \r
+ public static void injectResourceDictionaryMock(ConfigRestAdaptorService configRestAdaptorService,\r
+ String dictionaryFileName) throws Exception {\r
+ \r
+ Mockito.doAnswer(new Answer<String>() {\r
+ @Override\r
+ public String answer(InvocationOnMock invocationOnMock) throws Throwable {\r
+ Object[] args = invocationOnMock.getArguments();\r
+ String dictionaties = "[]";\r
+ if (args != null) {\r
+ logger.info("getResourceDictionaryByNames " + Arrays.asList(args));\r
+ dictionaties = IOUtils.toString(\r
+ ConfigAssignmentNodeTest.class.getClassLoader().getResourceAsStream(dictionaryFileName),\r
+ Charset.defaultCharset());\r
+ }\r
+ return dictionaties;\r
+ }\r
+ }).when(configRestAdaptorService).postResource(Matchers.any(), Matchers.any(), Matchers.any(),\r
+ Matchers.any(Class.class));\r
+ }\r
+ \r
+ public static void injectConfigResourceSaveMock(ConfigResourceService configResourceService) throws Exception {\r
+ Mockito.doAnswer(new Answer<ConfigResource>() {\r
+ @Override\r
+ public ConfigResource answer(InvocationOnMock invocationOnMock) throws Throwable {\r
+ Object[] args = invocationOnMock.getArguments();\r
+ ConfigResource configResource = null;\r
+ if (args != null) {\r
+ configResource = (ConfigResource) args[0];\r
+ logger.info("Config Resource Save info " + configResource);\r
+ return configResource;\r
+ }\r
+ return configResource;\r
+ }\r
+ }).when(configResourceService).saveConfigResource(any(ConfigResource.class));\r
+ }\r
+ \r
+ public static void injectGetConfigResourceMock(ConfigResourceService configResourceService,\r
+ ConfigResource configResource) throws Exception {\r
+ Mockito.doAnswer(new Answer<List<ConfigResource>>() {\r
+ @Override\r
+ public List<ConfigResource> answer(InvocationOnMock invocationOnMock) throws Throwable {\r
+ Object[] args = invocationOnMock.getArguments();\r
+ List<ConfigResource> configResources = new ArrayList<>();\r
+ if (args != null) {\r
+ configResources.add(configResource);\r
+ }\r
+ return configResources;\r
+ }\r
+ }).when(configResourceService).getConfigResource(any(ConfigResource.class));\r
+ }\r
+ \r
+ public static String getFileContent(String filePath) throws Exception {\r
+ return IOUtils.toString(ConfigResourceAssignmentTestUtils.class.getClassLoader().getResourceAsStream(filePath),\r
+ Charset.defaultCharset());\r
+ }\r
+ \r
+ public static Map<String, ResourceDefinition> getMapfromJson(String content) {\r
+ try {\r
+ ObjectMapper mapper = new ObjectMapper();\r
+ return mapper.readValue(content, new TypeReference<Map<String, ResourceDefinition>>() {});\r
+ } catch (Exception e) {\r
+ logger.info("getMapfromJson Exception ({})", e);\r
+ }\r
+ return null;\r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.service;\r
+\r
+import java.nio.charset.Charset;\r
+import java.util.HashMap;\r
+import java.util.List;\r
+import java.util.Map;\r
+import org.apache.commons.io.IOUtils;\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.onap.ccsdk.config.model.ConfigModelConstant;\r
+import org.onap.ccsdk.config.model.ValidTypes;\r
+import org.onap.ccsdk.config.model.data.ResourceAssignment;\r
+import org.onap.ccsdk.config.model.utils.ResourceAssignmentUtils;\r
+import org.onap.ccsdk.config.model.utils.TransformationUtils;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+import com.fasterxml.jackson.databind.JsonNode;\r
+\r
+public class ResourceAssignmentGenerationTest {\r
+ \r
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentGenerationTest.class);\r
+ \r
+ @Test\r
+ public void testResourceDataSetting() {\r
+ try {\r
+ logger.info(" **************** testResourceDataSetting *****************");\r
+ String resourceAssignmentContents = IOUtils.toString(TopologicalSortingTest.class.getClassLoader()\r
+ .getResourceAsStream("assignments/alltype-empty-value-mapping.json"), Charset.defaultCharset());\r
+ \r
+ List<ResourceAssignment> assignments =\r
+ TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class);\r
+ if (assignments != null) {\r
+ Map<String, Object> componentContext = new HashMap<>();\r
+ componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "sample-recipe");\r
+ for (ResourceAssignment resourceAssignment : assignments) {\r
+ if (resourceAssignment != null && resourceAssignment.getProperty() != null) {\r
+ String type = resourceAssignment.getProperty().getType();\r
+ Object value = null;\r
+ if (ValidTypes.DATA_TYPE_STRING.equals(type)) {\r
+ value = new String("abcdef");\r
+ } else if (ValidTypes.DATA_TYPE_INTEGER.equals(type)) {\r
+ value = new Integer(1234);\r
+ } else if (ValidTypes.DATA_TYPE_BOOLEAN.equals(type)) {\r
+ value = new Boolean(true);\r
+ } else if (ValidTypes.DATA_TYPE_LIST.equals(type)) {\r
+ String entityType = resourceAssignment.getProperty().getEntrySchema().getType();\r
+ if (ValidTypes.DATA_TYPE_STRING.equals(entityType)) {\r
+ value = "[\"abcd-array\"]";\r
+ } else {\r
+ String content = "[{\"name\" : \"abcd-array-complex\"}]";\r
+ JsonNode node = TransformationUtils.getJsonNodeForString(content);\r
+ value = node;\r
+ }\r
+ } else {\r
+ String content = "{\"name\" : \"abcd-complex\"}";\r
+ JsonNode node = TransformationUtils.getJsonNodeForString(content);\r
+ value = node;\r
+ }\r
+ ResourceAssignmentUtils.setResourceDataValue(componentContext, resourceAssignment, value);\r
+ }\r
+ }\r
+ String generatedData = ResourceAssignmentUtils.generateResourceDataForAssignments(assignments);\r
+ logger.trace("Generated Data " + generatedData);\r
+ \r
+ Assert.assertNotNull("Failed to generate resource data", generatedData);\r
+ }\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ @Test\r
+ public void testGenerateResourceData() {\r
+ try {\r
+ logger.info(" **************** testGenerateResourceData *****************");\r
+ String resourceAssignmentContents = IOUtils.toString(TopologicalSortingTest.class.getClassLoader()\r
+ .getResourceAsStream("assignments/alltype-mapping.json"), Charset.defaultCharset());\r
+ \r
+ List<ResourceAssignment> assignments =\r
+ TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class);\r
+ if (assignments != null) {\r
+ \r
+ String generatedData = ResourceAssignmentUtils.generateResourceDataForAssignments(assignments);\r
+ logger.trace("Generated Data " + generatedData);\r
+ \r
+ Assert.assertNotNull("Failed to generate resource data", generatedData);\r
+ }\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+}\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.service;\r
+\r
+import java.io.IOException;\r
+import java.nio.charset.Charset;\r
+import java.util.List;\r
+import org.apache.commons.io.IOUtils;\r
+import org.junit.Assert;\r
+import org.junit.Rule;\r
+import org.junit.Test;\r
+import org.junit.rules.ExpectedException;\r
+import org.onap.ccsdk.config.model.ConfigModelException;\r
+import org.onap.ccsdk.config.model.data.ResourceAssignment;\r
+import org.onap.ccsdk.config.model.utils.TransformationUtils;\r
+import org.onap.ccsdk.config.model.validator.ResourceAssignmentValidator;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+\r
+public class ResourceAssignmentValidation {\r
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(ResourceAssignmentValidation.class);\r
+ \r
+ @Rule\r
+ public final ExpectedException exception = ExpectedException.none();\r
+ \r
+ @Test\r
+ public void testValidateSuccess() {\r
+ try {\r
+ logger.info(" **************** testValidateSuccess *****************");\r
+ String resourceMapping = IOUtils.toString(\r
+ TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/success.json"),\r
+ Charset.defaultCharset());\r
+ \r
+ List<ResourceAssignment> assignments =\r
+ TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class);\r
+ if (assignments != null) {\r
+ ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments);\r
+ \r
+ boolean result = resourceAssignmentValidator.validateResourceAssignment();\r
+ Assert.assertTrue("Failed to Validate", result);\r
+ }\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+ @Test(expected = ConfigModelException.class)\r
+ public void testValidateDuplicate() throws IOException, ConfigModelException {\r
+ logger.info(" **************** testValidateDuplicate *****************");\r
+ String resourceMapping = IOUtils.toString(\r
+ TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/duplicate.json"),\r
+ Charset.defaultCharset());\r
+ \r
+ List<ResourceAssignment> assignments =\r
+ TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class);\r
+ if (assignments != null) {\r
+ ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments);\r
+ resourceAssignmentValidator.validateResourceAssignment();\r
+ }\r
+ \r
+ }\r
+ \r
+ @Test(expected = ConfigModelException.class)\r
+ public void testValidateCyclic() throws IOException, ConfigModelException {\r
+ logger.info(" **************** testValidateCyclic *****************");\r
+ String resourceMapping = IOUtils.toString(\r
+ TopologicalSortingTest.class.getClassLoader().getResourceAsStream("validation/cyclic.json"),\r
+ Charset.defaultCharset());\r
+ \r
+ List<ResourceAssignment> assignments =\r
+ TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class);\r
+ if (assignments != null) {\r
+ ResourceAssignmentValidator resourceAssignmentValidator = new ResourceAssignmentValidator(assignments);\r
+ \r
+ resourceAssignmentValidator.validateResourceAssignment();\r
+ }\r
+ \r
+ }\r
+}\r
--- /dev/null
+/*\r
+ * Copyright © 2017-2018 AT&T Intellectual Property.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except\r
+ * in compliance with the License. You may obtain a copy of the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software distributed under the License\r
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express\r
+ * or implied. See the License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+\r
+package org.onap.ccsdk.config.assignment.service;\r
+\r
+import java.nio.charset.Charset;\r
+import java.util.List;\r
+import org.apache.commons.io.IOUtils;\r
+import org.junit.Assert;\r
+import org.junit.Test;\r
+import org.onap.ccsdk.config.assignment.processor.ResourceAssignmentProcessor;\r
+import org.onap.ccsdk.config.model.data.ResourceAssignment;\r
+import org.onap.ccsdk.config.model.utils.TransformationUtils;\r
+import org.onap.ccsdk.sli.core.sli.SvcLogicContext;\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
+\r
+public class TopologicalSortingTest {\r
+ private static EELFLogger logger = EELFManager.getInstance().getLogger(TopologicalSortingTest.class);\r
+ \r
+ @Test\r
+ public void testBulkSequencingMapping() {\r
+ try {\r
+ logger.info(" **************** Bulk Sequencing Default *****************");\r
+ String resourceMapping = IOUtils.toString(\r
+ TopologicalSortingTest.class.getClassLoader().getResourceAsStream("mapping/dependency.json"),\r
+ Charset.defaultCharset());\r
+ \r
+ List<ResourceAssignment> assignments =\r
+ TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class);\r
+ if (assignments != null) {\r
+ SvcLogicContext ctx = new SvcLogicContext();\r
+ ResourceAssignmentProcessor resourceAssignmentProcessor =\r
+ new ResourceAssignmentProcessor(assignments, ctx);\r
+ List<List<ResourceAssignment>> sequenceBatchResourceAssignment = resourceAssignmentProcessor.process();\r
+ \r
+ Assert.assertNotNull("Failed to populate Sequence Bulk Mappings", sequenceBatchResourceAssignment);\r
+ Assert.assertNotEquals("Failed to populate Sequence Bulk Mappings size ",\r
+ (sequenceBatchResourceAssignment.size() > 0));\r
+ }\r
+ } catch (Exception e) {\r
+ e.printStackTrace();\r
+ }\r
+ }\r
+ \r
+}\r
--- /dev/null
+[\r
+ {\r
+ "name": "vnf-id-string",\r
+ "property": {\r
+ "required": true,\r
+ "type": "string"\r
+ },\r
+ "input-param": true,\r
+ "dictionary-name": "vnf-id-string",\r
+ "dictionary-source": "input",\r
+ "version": 0,\r
+ "status": "success",\r
+ "updated-by": "System"\r
+ },\r
+ {\r
+ "name": "vnf-id-integer",\r
+ "property": {\r
+ "required": true,\r
+ "type": "integer"\r
+ },\r
+ "input-param": true,\r
+ "dictionary-name": "vnf-id-integer",\r
+ "dictionary-source": "input",\r
+ "version": 0,\r
+ "status": "success",\r
+ "updated-by": "System"\r
+ },\r
+ {\r
+ "name": "vnf-boolean",\r
+ "property": {\r
+ "required": true,\r
+ "type": "boolean"\r
+ },\r
+ "input-param": true,\r
+ "dictionary-name": "vnf-boolean",\r
+ "dictionary-source": "input",\r
+ "version": 0,\r
+ "status": "success",\r
+ "updated-by": "System"\r
+ },\r
+ {\r
+ "name": "vnf-complex",\r
+ "property": {\r
+ "required": true,\r
+ "type": "dt-complex"\r
+ },\r
+ "input-param": true,\r
+ "dictionary-name": "vnf-complex",\r
+ "dictionary-source": "input",\r
+ "version": 0,\r
+ "status": "success",\r
+ "updated-by": "System"\r
+ },\r
+ {\r
+ "name": "vnf-id-array",\r
+ "property": {\r
+ "required": true,\r
+ "type": "list",\r
+ "entry_schema": {\r
+ "type": "string"\r
+ }\r
+ },\r
+ "input-param": true,\r
+ "dictionary-name": "vnf-id-array",\r
+ "dictionary-source": "input",\r
+ "version": 0,\r
+ "status": "success",\r
+ "updated-by": "System"\r
+ },\r
+ {\r
+ "name": "vnf-array-complex",\r
+ "property": {\r
+ "required": true,\r
+ "type": "list",\r
+ "entry_schema": {\r
+ "type": "dt-complex"\r
+ }\r
+ },\r
+ "input-param": true,\r
+ "dictionary-name": "vnf-array-complex",\r
+ "dictionary-source": "input",\r
+ "version": 0,\r
+ "status": "success",\r
+ "updated-by": "System"\r
+ }\r
+]\r
--- /dev/null
+[\r
+ {\r
+ "name": "vnf-id-string",\r
+ "property": {\r
+ "required": true,\r
+ "type": "string",\r
+ "value": "123456"\r
+ },\r
+ "input-param": true,\r
+ "dictionary-name": "vnf-id-string",\r
+ "dictionary-source": "input",\r
+ "version": 0,\r
+ "status": "success",\r
+ "updated-by": "System"\r
+ },\r
+ {\r
+ "name": "vnf-id-integer",\r
+ "property": {\r
+ "required": true,\r
+ "type": "integer",\r
+ "value": 123456\r
+ },\r
+ "input-param": true,\r
+ "dictionary-name": "vnf-id-integer",\r
+ "dictionary-source": "input",\r
+ "version": 0,\r
+ "status": "success",\r
+ "updated-by": "System"\r
+ },\r
+ {\r
+ "name": "vnf-boolean",\r
+ "property": {\r
+ "required": true,\r
+ "type": "boolean",\r
+ "value": true\r
+ },\r
+ "input-param": true,\r
+ "dictionary-name": "vnf-boolean",\r
+ "dictionary-source": "input",\r
+ "version": 0,\r
+ "status": "success",\r
+ "updated-by": "System"\r
+ },\r
+ {\r
+ "name": "vnf-complex",\r
+ "property": {\r
+ "required": true,\r
+ "type": "dt-complex",\r
+ "value": {\r
+ "name": "Brinda",\r
+ "location": "Madurai",\r
+ "count": 2\r
+ }\r
+ },\r
+ "input-param": true,\r
+ "dictionary-name": "vnf-complex",\r
+ "dictionary-source": "input",\r
+ "version": 0,\r
+ "status": "success",\r
+ "updated-by": "System"\r
+ },\r
+ {\r
+ "name": "vnf-id-array",\r
+ "property": {\r
+ "required": true,\r
+ "type": "list",\r
+ "entry_schema": {\r
+ "type": "string"\r
+ },\r
+ "value": [\r
+ "A",\r
+ "B",\r
+ "C"\r
+ ]\r
+ },\r
+ "input-param": true,\r
+ "dictionary-name": "vnf-id-array",\r
+ "dictionary-source": "input",\r
+ "version": 0,\r
+ "status": "success",\r
+ "updated-by": "System"\r
+ },\r
+ {\r
+ "name": "vnf-array-complex",\r
+ "property": {\r
+ "required": true,\r
+ "type": "list",\r
+ "entry_schema": {\r
+ "type": "dt-complex"\r
+ },\r
+ "value": [\r
+ {\r
+ "name": "A"\r
+ },\r
+ {\r
+ "name": "B"\r
+ },\r
+ {\r
+ "name": "C"\r
+ }\r
+ ]\r
+ },\r
+ "input-param": true,\r
+ "dictionary-name": "vnf-array-complex",\r
+ "dictionary-source": "input",\r
+ "version": 0,\r
+ "status": "success",\r
+ "updated-by": "System"\r
+ }\r
+]\r
--- /dev/null
+[]
\ No newline at end of file
--- /dev/null
+[\r
+ {\r
+ "name": "vnf-id",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "vnf-id",\r
+ "dictionary-source": "input",\r
+ "dependencies": []\r
+ },\r
+ {\r
+ "name": "service-instance-id",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "service-instance-id",\r
+ "dictionary-source": "input",\r
+ "dependencies": []\r
+ },\r
+ {\r
+ "name": "bundle-id",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "bundle-id",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "vnf-id"\r
+ ]\r
+ },\r
+ {\r
+ "name": "bundle-ip",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "bundle-ip",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "vnf-id"\r
+ ]\r
+ },\r
+ {\r
+ "name": "bundle-mac",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "bundle-mac",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "vnf-id",\r
+ "bundle-id"\r
+ ]\r
+ },\r
+ {\r
+ "name": "managed-ip",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "managed-ip",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "loopback-ip"\r
+ ]\r
+ },\r
+ {\r
+ "name": "vnf-name",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "vnf-name",\r
+ "dictionary-source": "input",\r
+ "dependencies": []\r
+ },\r
+ {\r
+ "name": "managed-ip1",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "managed-ip1",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "loopback-ip"\r
+ ]\r
+ },\r
+ {\r
+ "name": "loopback-ip",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "loopback-ip",\r
+ "dictionary-source": "db",\r
+ "dependencies": [\r
+ "bundle-mac",\r
+ "managed-ip1"\r
+ ]\r
+ }\r
+]\r
--- /dev/null
+[\r
+ {\r
+ "name": "vnf-id",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "vnf-id",\r
+ "dictionary-source": "input",\r
+ "dependencies": []\r
+ },\r
+ {\r
+ "name": "service-instance-id",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "service-instance-id",\r
+ "dictionary-source": "input",\r
+ "dependencies": []\r
+ },\r
+ {\r
+ "name": "bundle-id",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "bundle-id",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "vnf-id"\r
+ ]\r
+ },\r
+ {\r
+ "name": "bundle-ip",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "bundle-ip",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "vnf-id"\r
+ ]\r
+ },\r
+ {\r
+ "name": "bundle-mac",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "bundle-mac",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "vnf-id",\r
+ "bundle-id"\r
+ ]\r
+ },\r
+ {\r
+ "name": "bundle-mac",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "bundle-mac",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "loopback-ip"\r
+ ]\r
+ },\r
+ {\r
+ "name": "vnf-name",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "vnf-name",\r
+ "dictionary-source": "input",\r
+ "dependencies": []\r
+ },\r
+ {\r
+ "name": "managed-ip1",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "managed-ip1",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "loopback-ip"\r
+ ]\r
+ },\r
+ {\r
+ "name": "loopback-ip",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "loopback-ip",\r
+ "dictionary-source": "db",\r
+ "dependencies": [\r
+ "bundle-mac"\r
+ ]\r
+ }\r
+]\r
--- /dev/null
+[\r
+ {\r
+ "name": "vnf-id",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "vnf-id",\r
+ "dictionary-source": "input",\r
+ "dependencies": []\r
+ },\r
+ {\r
+ "name": "service-instance-id",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "service-instance-id",\r
+ "dictionary-source": "input",\r
+ "dependencies": []\r
+ },\r
+ {\r
+ "name": "bundle-id",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "bundle-id",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "vnf-id"\r
+ ]\r
+ },\r
+ {\r
+ "name": "bundle-ip",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "bundle-ip",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "vnf-id"\r
+ ]\r
+ },\r
+ {\r
+ "name": "bundle-mac",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "bundle-mac",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "vnf-id",\r
+ "bundle-id"\r
+ ]\r
+ },\r
+ {\r
+ "name": "managed-ip",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "managed-ip",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "loopback-ip"\r
+ ]\r
+ },\r
+ {\r
+ "name": "vnf-name",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string",\r
+ "required": true\r
+ },\r
+ "dictionary-name": "vnf-name",\r
+ "dictionary-source": "input",\r
+ "dependencies": []\r
+ },\r
+ {\r
+ "name": "managed-ip1",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "managed-ip1",\r
+ "dictionary-source": "mdsal",\r
+ "dependencies": [\r
+ "loopback-ip"\r
+ ]\r
+ },\r
+ {\r
+ "name": "loopback-ip",\r
+ "input-param": true,\r
+ "property": {\r
+ "type": "string"\r
+ },\r
+ "dictionary-name": "loopback-ip",\r
+ "dictionary-source": "db",\r
+ "dependencies": [\r
+ "bundle-mac"\r
+ ]\r
+ }\r
+]\r