From 280a0f6c73ab1c1aed9ee87fbd053d01d3838d70 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Wed, 12 Sep 2018 16:26:03 -0400 Subject: Controller Blueprints Nitrogen to Oxygen Migration Changing package structure from org.onap.ccsdk.config to org.onap.ccsdk.features Change-Id: I7d52b498f11ed892d547220cc4354298b6182c77 Issue-ID: CCSDK-560 Signed-off-by: Singal, Kapil (ks220y) --- .../processor/DBResourceProcessorTest.java | 231 ------------------ .../processor/DefaultResourceProcessorTest.java | 127 ---------- .../processor/InputResourceProcessorTest.java | 178 -------------- .../processor/MdsalResourceProcessorTest.java | 268 -------------------- .../service/ConfigAssignmentNodeTest.java | 246 ------------------- .../service/ConfigPreviewServiceTest.java | 111 --------- .../service/ConfigResourceAssignmentTestUtils.java | 182 -------------- .../service/ResourceAssignmentGenerationTest.java | 110 --------- .../service/ResourceAssignmentValidation.java | 94 ------- .../assignment/service/TopologicalSortingTest.java | 60 ----- .../processor/DBResourceProcessorTest.java | 232 ++++++++++++++++++ .../processor/DefaultResourceProcessorTest.java | 128 ++++++++++ .../processor/InputResourceProcessorTest.java | 179 ++++++++++++++ .../processor/MdsalResourceProcessorTest.java | 269 +++++++++++++++++++++ .../service/ConfigAssignmentNodeTest.java | 247 +++++++++++++++++++ .../service/ConfigPreviewServiceTest.java | 113 +++++++++ .../service/ConfigResourceAssignmentTestUtils.java | 183 ++++++++++++++ .../service/ResourceAssignmentGenerationTest.java | 111 +++++++++ .../service/ResourceAssignmentValidation.java | 95 ++++++++ .../assignment/service/TopologicalSortingTest.java | 60 +++++ .../service_templates/resource_assignment.json | 4 +- .../resource_assignment/resource_assignment.json | 4 +- .../vpe-201802-baseconfig.json | 4 +- 23 files changed, 1623 insertions(+), 1613 deletions(-) delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessorTest.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DefaultResourceProcessorTest.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessorTest.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessorTest.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentNodeTest.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java delete mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DBResourceProcessorTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DefaultResourceProcessorTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/InputResourceProcessorTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/MdsalResourceProcessorTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentNodeTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigPreviewServiceTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigResourceAssignmentTestUtils.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentGenerationTest.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentValidation.java create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/TopologicalSortingTest.java (limited to 'blueprints-processor/plugin/assignment-provider/src/test') diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessorTest.java deleted file mode 100644 index 5a704e995..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DBResourceProcessorTest.java +++ /dev/null @@ -1,231 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.processor; - -import static org.mockito.Matchers.any; -import java.io.File; -import java.nio.charset.Charset; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; -import org.onap.ccsdk.config.assignment.service.ConfigResourceAssignmentTestUtils; -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.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(MockitoJUnitRunner.class) -public class DBResourceProcessorTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(DBResourceProcessorTest.class); - - @Mock - private ConfigResourceService configResourceService; - - @SuppressWarnings("unchecked") - @Before - public void before() { - MockitoAnnotations.initMocks(this); - - try { - Mockito.doAnswer(new Answer() { - @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)); - - } catch (SvcLogicException e) { - e.printStackTrace(); - } - } - - @Test - public void testDbSimpleProcess() throws Exception { - logger.info(" ******************************* testDbSimpleProcess ***************************"); - - Mockito.doAnswer(new Answer>>() { - @Override - public List> answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - List> results = new ArrayList<>(); - if (args != null) { - logger.info("Query " + Arrays.asList(args)); - Map record = new HashMap<>(); - record.put("country", "US"); - results.add(record); - } - return results; - } - }).when(configResourceService).query(Matchers.anyString(), Matchers.>any()); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/db/resource-assignments-simple.json"), Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-simple.json"), - Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - dbResourceProcessor.process(inParams, ctx, componentContext); - - logger.info(" Context " + componentContext); - - } - - @Test - public void testDbComplexProcess() throws Exception { - logger.info(" ******************************* testDbComplexProcess ***************************"); - - Mockito.doAnswer(new Answer>>() { - @Override - public List> answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - List> results = new ArrayList<>(); - if (args != null) { - logger.info("Query " + Arrays.asList(args)); - Map record = new HashMap<>(); - record.put("db-country", "US"); - record.put("db-state", "NJ"); - results.add(record); - } - return results; - } - }).when(configResourceService).query(Matchers.anyString(), Matchers.>any()); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/db/resource-assignments-complex.json"), Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-complex.json"), - Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - String datatypeContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/dt-location.json"), - Charset.defaultCharset()); - ctx.setAttribute("data_types.dt-location", datatypeContent); - dbResourceProcessor.process(inParams, ctx, componentContext); - - } - - @Test - public void testDbArrayComplexProcess() throws Exception { - logger.info(" ******************************* testDbArrayComplexProcess ***************************"); - Mockito.doAnswer(new Answer>>() { - @Override - public List> answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - List> results = new ArrayList<>(); - if (args != null) { - logger.info("Query " + Arrays.asList(args)); - Map record = new HashMap<>(); - record.put("db-country", "US"); - record.put("db-state", "NJ"); - results.add(record); - - Map record2 = new HashMap<>(); - record2.put("db-country", "INDIA"); - record2.put("db-state", "TN"); - results.add(record2); - } - return results; - } - }).when(configResourceService).query(Matchers.anyString(), Matchers.>any()); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/db/resource-assignments-array.json"), Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-array.json"), - Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - String datatypeContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/dt-location.json"), - Charset.defaultCharset()); - ctx.setAttribute("data_types.dt-location", datatypeContent); - dbResourceProcessor.process(inParams, ctx, componentContext); - logger.info("Component Context = ({})", componentContext); - Assert.assertNotNull("faile dto populate Array Complex response ", componentContext); - - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DefaultResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DefaultResourceProcessorTest.java deleted file mode 100644 index 7e8d14201..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DefaultResourceProcessorTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.processor; - -import static org.mockito.Matchers.any; -import java.io.File; -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; -import org.onap.ccsdk.config.assignment.service.ConfigResourceAssignmentTestUtils; -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.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(MockitoJUnitRunner.class) -public class DefaultResourceProcessorTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(DefaultResourceProcessorTest.class); - - @Mock - private ConfigResourceService configResourceService; - - @SuppressWarnings("unchecked") - @Before - public void before() { - MockitoAnnotations.initMocks(this); - - try { - Mockito.doAnswer(new Answer() { - @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)); - - } catch (SvcLogicException e) { - e.printStackTrace(); - } - } - - @Test - public void testDefaultSimpleProcess() throws Exception { - logger.info(" ******************************* testDefaultSimpleProcess ***************************"); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/default/resource-assignments-simple.json"), - Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/default/default-simple.json"), Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - - DefaultResourceProcessor defaultResourceProcessor = new DefaultResourceProcessor(configResourceService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - defaultResourceProcessor.process(inParams, ctx, componentContext); - logger.trace(" componentContext " + componentContext); - - Assert.assertEquals("Failed to populate default country value ", "US", - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.country")); - Assert.assertEquals("Failed to populate default country value ", "US", - componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.country")); - - Assert.assertEquals("Failed to populate default port value ", 830, - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.port")); - Assert.assertEquals("Failed to populate default port value ", 830, - componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.port")); - - Assert.assertEquals("Failed to populate default voip-enabled value ", true, - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.voip-enabled")); - Assert.assertEquals("Failed to populate default voip-enabled value ", true, - componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.voip-enabled")); - - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessorTest.java deleted file mode 100644 index 2aabdb3d9..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/InputResourceProcessorTest.java +++ /dev/null @@ -1,178 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.processor; - -import static org.mockito.Matchers.any; -import java.io.File; -import java.nio.charset.Charset; -import java.util.Arrays; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; -import org.onap.ccsdk.config.assignment.service.ConfigResourceAssignmentTestUtils; -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.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.onap.ccsdk.sli.core.sli.SvcLogicException; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(MockitoJUnitRunner.class) -public class InputResourceProcessorTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(InputResourceProcessorTest.class); - - @Mock - private ConfigResourceService configResourceService; - - @SuppressWarnings("unchecked") - @Before - public void before() { - MockitoAnnotations.initMocks(this); - - try { - Mockito.doAnswer(new Answer() { - @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)); - - } catch (SvcLogicException e) { - e.printStackTrace(); - } - } - - @Test - public void testInputSimpleProcess() throws Exception { - logger.info(" ******************************* testInputSimpleProcess ***************************"); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/input/resource-assignments-simple.json"), - Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/default/default-simple.json"), Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - - InputResourceProcessor inputResourceProcessor = new InputResourceProcessor(configResourceService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - ctx.setAttribute("country", "US"); - ctx.setAttribute("port", "830"); - ctx.setAttribute("voip-enabled", "true"); - - inputResourceProcessor.process(inParams, ctx, componentContext); - logger.trace(" componentContext " + componentContext); - - Assert.assertEquals("Failed to populate default recipe country value ", "US", - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.country")); - Assert.assertEquals("Failed to populate default dictionary country value ", "US", - componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.country")); - - Assert.assertEquals("Failed to populate default recipe port value ", 830, - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.port")); - Assert.assertEquals("Failed to populate default dictionary port value ", 830, - componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.port")); - - Assert.assertEquals("Failed to populate default recipe voip-enabled value ", true, - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.voip-enabled")); - Assert.assertEquals("Failed to populate default dictionary voip-enabled value ", true, - componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.voip-enabled")); - - } - - @Test - public void testInputComplexProcess() throws Exception { - logger.info(" ******************************* testInputComplexProcess ***************************"); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/input/resource-assignments-complex.json"), - Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/input/input-complex.json"), Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - - InputResourceProcessor inputResourceProcessor = new InputResourceProcessor(configResourceService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - String datatypeContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/input/dt-location.json"), Charset.defaultCharset()); - ctx.setAttribute("data_types.dt-location", datatypeContent); - - String samplelocation = FileUtils.readFileToString( - new File("src/test/resources/mapping/input/sample-location.json"), Charset.defaultCharset()); - ctx.setAttribute("location", samplelocation); - - inputResourceProcessor.process(inParams, ctx, componentContext); - - logger.trace(" componentContext " + componentContext); - logger.trace(" Resource Mapping " + TransformationUtils.getJson(batchResourceAssignment, true)); - - Assert.assertNotNull("Failed to populate input recipe location value ", - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.location")); - Assert.assertNotNull("Failed to populate input dictionary location value ", - componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.location")); - - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessorTest.java deleted file mode 100644 index 2d651c836..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/MdsalResourceProcessorTest.java +++ /dev/null @@ -1,268 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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.processor; - -import java.io.File; -import java.nio.charset.Charset; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Matchers; -import org.mockito.Mock; -import org.mockito.Mockito; -import org.mockito.invocation.InvocationOnMock; -import org.mockito.runners.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; -import org.onap.ccsdk.config.assignment.service.ConfigResourceAssignmentTestUtils; -import org.onap.ccsdk.config.model.ConfigModelConstant; -import org.onap.ccsdk.config.model.data.ResourceAssignment; -import org.onap.ccsdk.config.model.data.dict.ResourceDefinition; -import org.onap.ccsdk.config.model.utils.TransformationUtils; -import org.onap.ccsdk.config.rest.adaptor.service.ConfigRestAdaptorService; -import org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(MockitoJUnitRunner.class) -public class MdsalResourceProcessorTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(MdsalResourceProcessorTest.class); - - @Mock - private ConfigRestAdaptorService configRestAdaptorService; - - @SuppressWarnings("unchecked") - @Before - public void before() { - - } - - @Test - @SuppressWarnings("unchecked") - public void testMdsalSimpleProcess() throws Exception { - logger.info(" ******************************* testMdsalSimpleProcess ***************************"); - - Mockito.doAnswer(new Answer() { - @Override - public String answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - String response = null; - if (args != null) { - response = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/simple-response.json"), - Charset.defaultCharset()); - logger.info(" Returning response :" + response); - } - return response; - } - }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), - Matchers.any(Class.class)); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/resource-assignments-simple.json"), - Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/mdsal-simple.json"), Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - MdsalResourceProcessor mdsalResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - mdsalResourceProcessor.process(inParams, ctx, componentContext); - - } - - @SuppressWarnings("unchecked") - @Test - public void testMDSALComplexProcess() throws Exception { - logger.info(" ******************************* testMDSALComplexProcess ***************************"); - - Mockito.doAnswer(new Answer() { - @Override - public String answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - String response = null; - if (args != null) { - response = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/complex-response.json"), - Charset.defaultCharset()); - } - return response; - } - }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), - Matchers.any(Class.class)); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/resource-assignments-complex.json"), - Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/mdsal-complex.json"), Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - MdsalResourceProcessor dbResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - String datatypeContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/dt-location.json"), Charset.defaultCharset()); - ctx.setAttribute("data_types.dt-location", datatypeContent); - dbResourceProcessor.process(inParams, ctx, componentContext); - - } - - @Test - @SuppressWarnings("unchecked") - public void testMDSALArrayComplexProcess() throws Exception { - logger.info(" ******************************* testMDSALArrayComplexProcess ***************************"); - - Mockito.doAnswer(new Answer() { - @Override - public String answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - String response = null; - if (args != null) { - response = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/array-complex-response.json"), - Charset.defaultCharset()); - } - return response; - } - }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), - Matchers.any(Class.class)); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/resource-assignments-array.json"), Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/mdsal-array.json"), Charset.defaultCharset()); - - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - MdsalResourceProcessor dbResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - String datatypeContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/dt-location.json"), Charset.defaultCharset()); - ctx.setAttribute("data_types.dt-location", datatypeContent); - dbResourceProcessor.process(inParams, ctx, componentContext); - logger.info("Component Context = ({})", componentContext); - Assert.assertNotNull("failed to populate Array Complex response ", componentContext); - - } - - @Test - @SuppressWarnings("unchecked") - public void testMDSALArraySimpleProcess() throws Exception { - logger.info(" ******************************* testMDSALArrayComplexProcess ***************************"); - - Mockito.doAnswer(new Answer() { - @Override - public String answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - String response = null; - if (args != null) { - response = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/array-complex-v4-assigned-response.json"), - Charset.defaultCharset()); - } - return response; - } - }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), - Matchers.any(Class.class)); - - String recipeName = "sample-recipe"; - - String resourceassignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/resource-assignments-complex-simple.json"), - Charset.defaultCharset()); - List batchResourceAssignment = - TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); - - String dictionaryContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/Mdsal/mdsal-array-v4iplist.json"), Charset.defaultCharset()); - Map dictionaries = - ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); - MdsalResourceProcessor mdsalResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); - Map componentContext = new HashMap<>(); - componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); - componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); - componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".service-instance-id", - "3c8d5a63-a793-4206-a67c-4b2e8e648196"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-network-role", - "sample"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-ipv4-ip-type", - "sample"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); - componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-vm-type", "sample"); - - Map inParams = new HashMap<>(); - SvcLogicContext ctx = new SvcLogicContext(); - // String datatypeContent = FileUtils.readFileToString(new - // File("src/test/resources/mapping/Mdsal/dt-v4-assigned-ip-list.json"), Charset.defaultCharset() ); - // ctx.setAttribute("data_types.dt-v4-assigned-ip-list", datatypeContent); - mdsalResourceProcessor.process(inParams, ctx, componentContext); - logger.info("Component Context = ({})", componentContext); - Assert.assertNotNull("failed to populate Array Complex response ", componentContext); - Assert.assertEquals("Compare String ", "10.66.1.152", - componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + ".v4-ip-prefix")); - - } - -} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentNodeTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentNodeTest.java deleted file mode 100644 index 9ad94dcd0..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigAssignmentNodeTest.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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 java.util.HashMap; -import java.util.Map; -import org.apache.commons.io.FileUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.sling.testing.mock.osgi.MockOsgi; -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.ConfigAssignmentConstants; -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.ConfigModelConstant; -import org.onap.ccsdk.config.model.service.ComponentNodeDelegate; -import org.onap.ccsdk.config.model.service.ComponentNodeService; -import org.onap.ccsdk.config.model.service.ComponentNodeServiceImpl; -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 org.onap.ccsdk.sli.core.sli.SvcLogicContext; -import org.osgi.framework.BundleContext; -import com.att.eelf.configuration.EELFLogger; -import com.att.eelf.configuration.EELFManager; - -@RunWith(MockitoJUnitRunner.class) -public class ConfigAssignmentNodeTest { - - private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentNodeTest.class); - - @Rule - public ExpectedException thrown = ExpectedException.none(); - - @Mock - private ConfigResourceService configResourceService; - - @Mock - private ConfigRestAdaptorService configRestAdaptorService; - - private ConfigModelService configModelService; - - private ComponentNodeService componentNodeService; - - private ConfigGeneratorService configGeneratorService; - - BundleContext bundleContext = MockOsgi.newBundleContext(); - - @SuppressWarnings("unchecked") - @Before - public void before() throws Exception { - MockitoAnnotations.initMocks(this); - /* - * ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(componentNodeService, - * configResourceService, configModelService, configRestAdaptorService, configGeneratorService); - * bundleContext.registerService(ConfigAssignmentNode.class, configAssignmentNode, null); - */ - } - - @Test - public void testResourceAssignment() throws Exception { - ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService); - - ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment"); - - ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService, - "assignments/empty-dictionary.json"); - - ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService); - - componentNodeService = - new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); - configModelService = new ConfigModelServiceImpl(configRestAdaptorService); - configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService); - - ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService, - configRestAdaptorService, configModelService, componentNodeService, configGeneratorService); - - String inputContent = FileUtils.readFileToString( - new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset()); - - Map inParams = new HashMap<>(); - inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "test"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "1234"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type"); - inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig"); - inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0"); - inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]"); - - // Populate the SvcContext ( Simulation) - SvcLogicContext svcLogicContext = new SvcLogicContext(); - Map context = new HashMap<>(); - context.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); - context = configModelService.prepareContext(context, inputContent, "vpe-201802-baseconfig", "1.0.0"); - context.forEach((key, value) -> svcLogicContext.setAttribute(key, value)); - - Map componentContext = new HashMap<>(); - configAssignmentNode.process(inParams, svcLogicContext, componentContext); - Assert.assertNotNull("Failed to get response status", svcLogicContext.getAttribute("test.status")); - - } - - @Test - public void testSimplePreview() throws Exception { - ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService); - - ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment"); - - ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService, - "assignments/empty-dictionary.json"); - - ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService); - - componentNodeService = - new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); - configModelService = new ConfigModelServiceImpl(configRestAdaptorService); - configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService); - - ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService, - configRestAdaptorService, configModelService, componentNodeService, configGeneratorService); - - String inputContent = FileUtils.readFileToString( - new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset()); - - Map inParams = new HashMap<>(); - inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "test"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "1234"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type"); - inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig"); - inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0"); - inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]"); - SvcLogicContext ctx = new SvcLogicContext(); - configAssignmentNode.process(inParams, ctx); - Assert.assertNotNull("Failed to get response mashed Content", - ctx.getAttribute("test.mashed-data.base-config-template")); - } - - @Test - public void testComplexPreview() throws Exception { - ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService); - - ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "vpe-201802-baseconfig"); - - ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService, - "service_templates/vpe-201802-baseconfig/dict.json"); - - ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService); - - componentNodeService = - new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); - configModelService = new ConfigModelServiceImpl(configRestAdaptorService); - configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService); - - ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService, - configRestAdaptorService, configModelService, componentNodeService, configGeneratorService); - - String inputContent = FileUtils.readFileToString( - new File("src/test/resources/service_templates/vpe-201802-baseconfig/input-complex.json"), - Charset.defaultCharset()); - - Map inParams = new HashMap<>(); - inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "complex-test"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "request-1234"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type"); - inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig"); - inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0"); - inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent); - inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]"); - SvcLogicContext ctx = new SvcLogicContext(); - configAssignmentNode.process(inParams, ctx); - Assert.assertNotNull("Failed to get response mashed Content", - ctx.getAttribute("complex-test.mashed-data.base-config-template")); - - } - - @Test - public void inputValidator() { - SvcLogicContext ctx = new SvcLogicContext(); - try { - - logger.info(" ******************************* inputValidator ***************************"); - String serviceTemplateContent = FileUtils.readFileToString( - new File("src/test/resources/service_templates/resource_assignment.json"), - Charset.defaultCharset()); - - String inputcontent = FileUtils.readFileToString( - new File("src/test/resources/service_templates/input/inputValidateTest.json"), - Charset.defaultCharset()); - - Map context = new HashMap<>(); - configModelService.prepareContext(context, inputcontent, serviceTemplateContent); - - // TransformationUtils.printMap(context); - - context.forEach((name, value) -> { - if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(value)) { - ctx.setAttribute(name, value); - } - }); - - ComponentNodeDelegate componentNodeDelegate = new ComponentNodeDelegate(componentNodeService); - Map inParams = new HashMap<>(); - inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "resource-assignment"); - componentNodeDelegate.process(inParams, ctx); - Assert.fail(); - } catch (Exception e) { - logger.error("Failed in inputValidator" + e.getMessage()); - logger.info("** ctx.getAttribute Check for **" + ctx.getAttribute("resource-assignment.error-message")); - } - - } - -} 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 deleted file mode 100644 index 75b7f2e28..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigPreviewServiceTest.java +++ /dev/null @@ -1,111 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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 deleted file mode 100644 index ee1c076ae..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ConfigResourceAssignmentTestUtils.java +++ /dev/null @@ -1,182 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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() { - @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() { - @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 configModelContents = new ArrayList<>(); - configModelContents.add(configModelContent); - - String velocityDir = ConfigResourceAssignmentTestUtils.class.getClassLoader() - .getResource("service_templates/" + serviceTemplateName + "/velocity").getPath(); - - Collection 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() { - @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() { - @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>() { - @Override - public List answer(InvocationOnMock invocationOnMock) throws Throwable { - Object[] args = invocationOnMock.getArguments(); - List 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 getMapfromJson(String content) { - try { - ObjectMapper mapper = new ObjectMapper(); - return mapper.readValue(content, new TypeReference>() {}); - } 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 deleted file mode 100644 index 3dc7da7eb..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentGenerationTest.java +++ /dev/null @@ -1,110 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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 assignments = - TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class); - if (assignments != null) { - Map 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 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 deleted file mode 100644 index d708404f5..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/ResourceAssignmentValidation.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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 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 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 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 deleted file mode 100644 index e4b7f5dee..000000000 --- a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/service/TopologicalSortingTest.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright © 2017-2018 AT&T Intellectual Property. - * Modifications Copyright © 2018 IBM. - * - * 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 assignments = - TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class); - if (assignments != null) { - SvcLogicContext ctx = new SvcLogicContext(); - ResourceAssignmentProcessor resourceAssignmentProcessor = - new ResourceAssignmentProcessor(assignments, ctx); - List> 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/java/org/onap/ccsdk/features/assignment/processor/DBResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DBResourceProcessorTest.java new file mode 100644 index 000000000..43a4881d5 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DBResourceProcessorTest.java @@ -0,0 +1,232 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.features.assignment.processor; + +import static org.mockito.Matchers.any; +import java.io.File; +import java.nio.charset.Charset; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; +import org.onap.ccsdk.features.assignment.processor.DBResourceProcessor; +import org.onap.ccsdk.features.assignment.service.ConfigResourceAssignmentTestUtils; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class DBResourceProcessorTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(DBResourceProcessorTest.class); + + @Mock + private ConfigResourceService configResourceService; + + @SuppressWarnings("unchecked") + @Before + public void before() { + MockitoAnnotations.initMocks(this); + + try { + Mockito.doAnswer(new Answer() { + @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)); + + } catch (SvcLogicException e) { + e.printStackTrace(); + } + } + + @Test + public void testDbSimpleProcess() throws Exception { + logger.info(" ******************************* testDbSimpleProcess ***************************"); + + Mockito.doAnswer(new Answer>>() { + @Override + public List> answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + List> results = new ArrayList<>(); + if (args != null) { + logger.info("Query " + Arrays.asList(args)); + Map record = new HashMap<>(); + record.put("country", "US"); + results.add(record); + } + return results; + } + }).when(configResourceService).query(Matchers.anyString(), Matchers.>any()); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/db/resource-assignments-simple.json"), Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-simple.json"), + Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + dbResourceProcessor.process(inParams, ctx, componentContext); + + logger.info(" Context " + componentContext); + + } + + @Test + public void testDbComplexProcess() throws Exception { + logger.info(" ******************************* testDbComplexProcess ***************************"); + + Mockito.doAnswer(new Answer>>() { + @Override + public List> answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + List> results = new ArrayList<>(); + if (args != null) { + logger.info("Query " + Arrays.asList(args)); + Map record = new HashMap<>(); + record.put("db-country", "US"); + record.put("db-state", "NJ"); + results.add(record); + } + return results; + } + }).when(configResourceService).query(Matchers.anyString(), Matchers.>any()); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/db/resource-assignments-complex.json"), Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-complex.json"), + Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + String datatypeContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/dt-location.json"), + Charset.defaultCharset()); + ctx.setAttribute("data_types.dt-location", datatypeContent); + dbResourceProcessor.process(inParams, ctx, componentContext); + + } + + @Test + public void testDbArrayComplexProcess() throws Exception { + logger.info(" ******************************* testDbArrayComplexProcess ***************************"); + Mockito.doAnswer(new Answer>>() { + @Override + public List> answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + List> results = new ArrayList<>(); + if (args != null) { + logger.info("Query " + Arrays.asList(args)); + Map record = new HashMap<>(); + record.put("db-country", "US"); + record.put("db-state", "NJ"); + results.add(record); + + Map record2 = new HashMap<>(); + record2.put("db-country", "INDIA"); + record2.put("db-state", "TN"); + results.add(record2); + } + return results; + } + }).when(configResourceService).query(Matchers.anyString(), Matchers.>any()); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/db/resource-assignments-array.json"), Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/db-array.json"), + Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + DBResourceProcessor dbResourceProcessor = new DBResourceProcessor(configResourceService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + String datatypeContent = FileUtils.readFileToString(new File("src/test/resources/mapping/db/dt-location.json"), + Charset.defaultCharset()); + ctx.setAttribute("data_types.dt-location", datatypeContent); + dbResourceProcessor.process(inParams, ctx, componentContext); + logger.info("Component Context = ({})", componentContext); + Assert.assertNotNull("faile dto populate Array Complex response ", componentContext); + + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DefaultResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DefaultResourceProcessorTest.java new file mode 100644 index 000000000..df3800387 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/DefaultResourceProcessorTest.java @@ -0,0 +1,128 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.features.assignment.processor; + +import static org.mockito.Matchers.any; +import java.io.File; +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; +import org.onap.ccsdk.features.assignment.processor.DefaultResourceProcessor; +import org.onap.ccsdk.features.assignment.service.ConfigResourceAssignmentTestUtils; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class DefaultResourceProcessorTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(DefaultResourceProcessorTest.class); + + @Mock + private ConfigResourceService configResourceService; + + @SuppressWarnings("unchecked") + @Before + public void before() { + MockitoAnnotations.initMocks(this); + + try { + Mockito.doAnswer(new Answer() { + @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)); + + } catch (SvcLogicException e) { + e.printStackTrace(); + } + } + + @Test + public void testDefaultSimpleProcess() throws Exception { + logger.info(" ******************************* testDefaultSimpleProcess ***************************"); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/default/resource-assignments-simple.json"), + Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/default/default-simple.json"), Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + + DefaultResourceProcessor defaultResourceProcessor = new DefaultResourceProcessor(configResourceService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + defaultResourceProcessor.process(inParams, ctx, componentContext); + logger.trace(" componentContext " + componentContext); + + Assert.assertEquals("Failed to populate default country value ", "US", + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.country")); + Assert.assertEquals("Failed to populate default country value ", "US", + componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.country")); + + Assert.assertEquals("Failed to populate default port value ", 830, + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.port")); + Assert.assertEquals("Failed to populate default port value ", 830, + componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.port")); + + Assert.assertEquals("Failed to populate default voip-enabled value ", true, + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.voip-enabled")); + Assert.assertEquals("Failed to populate default voip-enabled value ", true, + componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.voip-enabled")); + + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/InputResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/InputResourceProcessorTest.java new file mode 100644 index 000000000..cd0b7828e --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/InputResourceProcessorTest.java @@ -0,0 +1,179 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.features.assignment.processor; + +import static org.mockito.Matchers.any; +import java.io.File; +import java.nio.charset.Charset; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.MockitoAnnotations; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; +import org.onap.ccsdk.features.assignment.processor.InputResourceProcessor; +import org.onap.ccsdk.features.assignment.service.ConfigResourceAssignmentTestUtils; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.onap.ccsdk.sli.core.sli.SvcLogicException; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class InputResourceProcessorTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(InputResourceProcessorTest.class); + + @Mock + private ConfigResourceService configResourceService; + + @SuppressWarnings("unchecked") + @Before + public void before() { + MockitoAnnotations.initMocks(this); + + try { + Mockito.doAnswer(new Answer() { + @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)); + + } catch (SvcLogicException e) { + e.printStackTrace(); + } + } + + @Test + public void testInputSimpleProcess() throws Exception { + logger.info(" ******************************* testInputSimpleProcess ***************************"); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/input/resource-assignments-simple.json"), + Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/default/default-simple.json"), Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + + InputResourceProcessor inputResourceProcessor = new InputResourceProcessor(configResourceService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + ctx.setAttribute("country", "US"); + ctx.setAttribute("port", "830"); + ctx.setAttribute("voip-enabled", "true"); + + inputResourceProcessor.process(inParams, ctx, componentContext); + logger.trace(" componentContext " + componentContext); + + Assert.assertEquals("Failed to populate default recipe country value ", "US", + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.country")); + Assert.assertEquals("Failed to populate default dictionary country value ", "US", + componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.country")); + + Assert.assertEquals("Failed to populate default recipe port value ", 830, + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.port")); + Assert.assertEquals("Failed to populate default dictionary port value ", 830, + componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.port")); + + Assert.assertEquals("Failed to populate default recipe voip-enabled value ", true, + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.voip-enabled")); + Assert.assertEquals("Failed to populate default dictionary voip-enabled value ", true, + componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.voip-enabled")); + + } + + @Test + public void testInputComplexProcess() throws Exception { + logger.info(" ******************************* testInputComplexProcess ***************************"); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/input/resource-assignments-complex.json"), + Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/input/input-complex.json"), Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + + InputResourceProcessor inputResourceProcessor = new InputResourceProcessor(configResourceService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + String datatypeContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/input/dt-location.json"), Charset.defaultCharset()); + ctx.setAttribute("data_types.dt-location", datatypeContent); + + String samplelocation = FileUtils.readFileToString( + new File("src/test/resources/mapping/input/sample-location.json"), Charset.defaultCharset()); + ctx.setAttribute("location", samplelocation); + + inputResourceProcessor.process(inParams, ctx, componentContext); + + logger.trace(" componentContext " + componentContext); + logger.trace(" Resource Mapping " + TransformationUtils.getJson(batchResourceAssignment, true)); + + Assert.assertNotNull("Failed to populate input recipe location value ", + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + "sample-recipe.location")); + Assert.assertNotNull("Failed to populate input dictionary location value ", + componentContext.get(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + "sample-recipe.location")); + + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/MdsalResourceProcessorTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/MdsalResourceProcessorTest.java new file mode 100644 index 000000000..5f73f32e3 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/processor/MdsalResourceProcessorTest.java @@ -0,0 +1,269 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.features.assignment.processor; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.Matchers; +import org.mockito.Mock; +import org.mockito.Mockito; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.runners.MockitoJUnitRunner; +import org.mockito.stubbing.Answer; +import org.onap.ccsdk.features.assignment.processor.MdsalResourceProcessor; +import org.onap.ccsdk.features.assignment.service.ConfigResourceAssignmentTestUtils; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class MdsalResourceProcessorTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(MdsalResourceProcessorTest.class); + + @Mock + private ConfigRestAdaptorService configRestAdaptorService; + + @SuppressWarnings("unchecked") + @Before + public void before() { + + } + + @Test + @SuppressWarnings("unchecked") + public void testMdsalSimpleProcess() throws Exception { + logger.info(" ******************************* testMdsalSimpleProcess ***************************"); + + Mockito.doAnswer(new Answer() { + @Override + public String answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + String response = null; + if (args != null) { + response = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/simple-response.json"), + Charset.defaultCharset()); + logger.info(" Returning response :" + response); + } + return response; + } + }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), + Matchers.any(Class.class)); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/resource-assignments-simple.json"), + Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/mdsal-simple.json"), Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + MdsalResourceProcessor mdsalResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + mdsalResourceProcessor.process(inParams, ctx, componentContext); + + } + + @SuppressWarnings("unchecked") + @Test + public void testMDSALComplexProcess() throws Exception { + logger.info(" ******************************* testMDSALComplexProcess ***************************"); + + Mockito.doAnswer(new Answer() { + @Override + public String answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + String response = null; + if (args != null) { + response = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/complex-response.json"), + Charset.defaultCharset()); + } + return response; + } + }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), + Matchers.any(Class.class)); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/resource-assignments-complex.json"), + Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/mdsal-complex.json"), Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + MdsalResourceProcessor dbResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + String datatypeContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/dt-location.json"), Charset.defaultCharset()); + ctx.setAttribute("data_types.dt-location", datatypeContent); + dbResourceProcessor.process(inParams, ctx, componentContext); + + } + + @Test + @SuppressWarnings("unchecked") + public void testMDSALArrayComplexProcess() throws Exception { + logger.info(" ******************************* testMDSALArrayComplexProcess ***************************"); + + Mockito.doAnswer(new Answer() { + @Override + public String answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + String response = null; + if (args != null) { + response = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/array-complex-response.json"), + Charset.defaultCharset()); + } + return response; + } + }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), + Matchers.any(Class.class)); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/resource-assignments-array.json"), Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/mdsal-array.json"), Charset.defaultCharset()); + + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + MdsalResourceProcessor dbResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + String datatypeContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/dt-location.json"), Charset.defaultCharset()); + ctx.setAttribute("data_types.dt-location", datatypeContent); + dbResourceProcessor.process(inParams, ctx, componentContext); + logger.info("Component Context = ({})", componentContext); + Assert.assertNotNull("failed to populate Array Complex response ", componentContext); + + } + + @Test + @SuppressWarnings("unchecked") + public void testMDSALArraySimpleProcess() throws Exception { + logger.info(" ******************************* testMDSALArrayComplexProcess ***************************"); + + Mockito.doAnswer(new Answer() { + @Override + public String answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + String response = null; + if (args != null) { + response = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/array-complex-v4-assigned-response.json"), + Charset.defaultCharset()); + } + return response; + } + }).when(configRestAdaptorService).getResource(Matchers.anyString(), Matchers.anyString(), + Matchers.any(Class.class)); + + String recipeName = "sample-recipe"; + + String resourceassignmentContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/resource-assignments-complex-simple.json"), + Charset.defaultCharset()); + List batchResourceAssignment = + TransformationUtils.getListfromJson(resourceassignmentContent, ResourceAssignment.class); + + String dictionaryContent = FileUtils.readFileToString( + new File("src/test/resources/mapping/Mdsal/mdsal-array-v4iplist.json"), Charset.defaultCharset()); + Map dictionaries = + ConfigResourceAssignmentTestUtils.getMapfromJson(dictionaryContent); + MdsalResourceProcessor mdsalResourceProcessor = new MdsalResourceProcessor(configRestAdaptorService); + Map componentContext = new HashMap<>(); + componentContext.put(ConfigModelConstant.PROPERTY_RESOURCE_ASSIGNMENTS, batchResourceAssignment); + componentContext.put(ConfigModelConstant.PROPERTY_ACTION_NAME, recipeName); + componentContext.put(ConfigModelConstant.PROPERTY_TEMPLATE_NAME, "sample-template"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARIES, dictionaries); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".service-instance-id", + "3c8d5a63-a793-4206-a67c-4b2e8e648196"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-network-role", + "sample"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-ipv4-ip-type", + "sample"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".profile_name", "sample"); + componentContext.put(ConfigModelConstant.PROPERTY_DICTIONARY_KEY_DOT + recipeName + ".oam-vm-type", "sample"); + + Map inParams = new HashMap<>(); + SvcLogicContext ctx = new SvcLogicContext(); + // String datatypeContent = FileUtils.readFileToString(new + // File("src/test/resources/mapping/Mdsal/dt-v4-assigned-ip-list.json"), Charset.defaultCharset() ); + // ctx.setAttribute("data_types.dt-v4-assigned-ip-list", datatypeContent); + mdsalResourceProcessor.process(inParams, ctx, componentContext); + logger.info("Component Context = ({})", componentContext); + Assert.assertNotNull("failed to populate Array Complex response ", componentContext); + Assert.assertEquals("Compare String ", "10.66.1.152", + componentContext.get(ConfigModelConstant.PROPERTY_RECIPE_KEY_DOT + recipeName + ".v4-ip-prefix")); + + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentNodeTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentNodeTest.java new file mode 100644 index 000000000..41911e91d --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigAssignmentNodeTest.java @@ -0,0 +1,247 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.features.assignment.service; + +import java.io.File; +import java.nio.charset.Charset; +import java.util.HashMap; +import java.util.Map; +import org.apache.commons.io.FileUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.sling.testing.mock.osgi.MockOsgi; +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.features.assignment.ConfigAssignmentConstants; +import org.onap.ccsdk.features.assignment.service.ConfigAssignmentNode; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.generator.service.ConfigGeneratorService; +import org.onap.ccsdk.features.generator.service.ConfigGeneratorServiceImpl; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.service.ComponentNodeDelegate; +import org.onap.ccsdk.features.model.service.ComponentNodeService; +import org.onap.ccsdk.features.model.service.ComponentNodeServiceImpl; +import org.onap.ccsdk.features.model.service.ConfigModelService; +import org.onap.ccsdk.features.model.service.ConfigModelServiceImpl; +import org.onap.ccsdk.features.rest.adaptor.service.ConfigRestAdaptorService; +import org.onap.ccsdk.sli.core.sli.SvcLogicContext; +import org.osgi.framework.BundleContext; +import com.att.eelf.configuration.EELFLogger; +import com.att.eelf.configuration.EELFManager; + +@RunWith(MockitoJUnitRunner.class) +public class ConfigAssignmentNodeTest { + + private static EELFLogger logger = EELFManager.getInstance().getLogger(ConfigAssignmentNodeTest.class); + + @Rule + public ExpectedException thrown = ExpectedException.none(); + + @Mock + private ConfigResourceService configResourceService; + + @Mock + private ConfigRestAdaptorService configRestAdaptorService; + + private ConfigModelService configModelService; + + private ComponentNodeService componentNodeService; + + private ConfigGeneratorService configGeneratorService; + + BundleContext bundleContext = MockOsgi.newBundleContext(); + + @SuppressWarnings("unchecked") + @Before + public void before() throws Exception { + MockitoAnnotations.initMocks(this); + /* + * ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(componentNodeService, + * configResourceService, configModelService, configRestAdaptorService, configGeneratorService); + * bundleContext.registerService(ConfigAssignmentNode.class, configAssignmentNode, null); + */ + } + + @Test + public void testResourceAssignment() throws Exception { + ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService); + + ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment"); + + ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService, + "assignments/empty-dictionary.json"); + + ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService); + + componentNodeService = + new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); + configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService); + + ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService, + configRestAdaptorService, configModelService, componentNodeService, configGeneratorService); + + String inputContent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset()); + + Map inParams = new HashMap<>(); + inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "test"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "1234"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type"); + inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig"); + inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0"); + inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]"); + + // Populate the SvcContext ( Simulation) + SvcLogicContext svcLogicContext = new SvcLogicContext(); + Map context = new HashMap<>(); + context.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); + context = configModelService.prepareContext(context, inputContent, "vpe-201802-baseconfig", "1.0.0"); + context.forEach((key, value) -> svcLogicContext.setAttribute(key, value)); + + Map componentContext = new HashMap<>(); + configAssignmentNode.process(inParams, svcLogicContext, componentContext); + Assert.assertNotNull("Failed to get response status", svcLogicContext.getAttribute("test.status")); + + } + + @Test + public void testSimplePreview() throws Exception { + ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService); + + ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "resource_assignment"); + + ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService, + "assignments/empty-dictionary.json"); + + ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService); + + componentNodeService = + new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); + configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService); + + ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService, + configRestAdaptorService, configModelService, componentNodeService, configGeneratorService); + + String inputContent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/input/input.json"), Charset.defaultCharset()); + + Map inParams = new HashMap<>(); + inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "test"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "1234"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type"); + inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig"); + inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0"); + inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]"); + SvcLogicContext ctx = new SvcLogicContext(); + configAssignmentNode.process(inParams, ctx); + Assert.assertNotNull("Failed to get response mashed Content", + ctx.getAttribute("test.mashed-data.base-config-template")); + } + + @Test + public void testComplexPreview() throws Exception { + ConfigResourceAssignmentTestUtils.injectTransactionLogSaveMock(configResourceService); + + ConfigResourceAssignmentTestUtils.injectConfigModelMock(configRestAdaptorService, "vpe-201802-baseconfig"); + + ConfigResourceAssignmentTestUtils.injectResourceDictionaryMock(configRestAdaptorService, + "service_templates/vpe-201802-baseconfig/dict.json"); + + ConfigResourceAssignmentTestUtils.injectConfigResourceSaveMock(configResourceService); + + componentNodeService = + new ComponentNodeServiceImpl(bundleContext, configResourceService, configRestAdaptorService); + configModelService = new ConfigModelServiceImpl(configRestAdaptorService); + configGeneratorService = new ConfigGeneratorServiceImpl(configResourceService); + + ConfigAssignmentNode configAssignmentNode = new ConfigAssignmentNode(configResourceService, + configRestAdaptorService, configModelService, componentNodeService, configGeneratorService); + + String inputContent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/vpe-201802-baseconfig/input-complex.json"), + Charset.defaultCharset()); + + Map inParams = new HashMap<>(); + inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "complex-test"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_REQUEST_ID, "request-1234"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_ID, "resourceid-1234"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_RESOURCE_TYPE, "vnf-type"); + inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_NAME, "vpe-201802-baseconfig"); + inParams.put(ConfigModelConstant.SERVICE_TEMPLATE_KEY_ARTIFACT_VERSION, "1.0.0"); + inParams.put(ConfigModelConstant.PROPERTY_ACTION_NAME, "resource-assignment-action"); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_INPUT_DATA, inputContent); + inParams.put(ConfigAssignmentConstants.INPUT_PARAM_TEMPLATE_NAMES, "[\"base-config-template\"]"); + SvcLogicContext ctx = new SvcLogicContext(); + configAssignmentNode.process(inParams, ctx); + Assert.assertNotNull("Failed to get response mashed Content", + ctx.getAttribute("complex-test.mashed-data.base-config-template")); + + } + + @Test + public void inputValidator() { + SvcLogicContext ctx = new SvcLogicContext(); + try { + + logger.info(" ******************************* inputValidator ***************************"); + String serviceTemplateContent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/resource_assignment.json"), + Charset.defaultCharset()); + + String inputcontent = FileUtils.readFileToString( + new File("src/test/resources/service_templates/input/inputValidateTest.json"), + Charset.defaultCharset()); + + Map context = new HashMap<>(); + configModelService.prepareContext(context, inputcontent, serviceTemplateContent); + + // TransformationUtils.printMap(context); + + context.forEach((name, value) -> { + if (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(value)) { + ctx.setAttribute(name, value); + } + }); + + ComponentNodeDelegate componentNodeDelegate = new ComponentNodeDelegate(componentNodeService); + Map inParams = new HashMap<>(); + inParams.put(ConfigModelConstant.PROPERTY_SELECTOR, "resource-assignment"); + componentNodeDelegate.process(inParams, ctx); + Assert.fail(); + } catch (Exception e) { + logger.error("Failed in inputValidator" + e.getMessage()); + logger.info("** ctx.getAttribute Check for **" + ctx.getAttribute("resource-assignment.error-message")); + } + + } + +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigPreviewServiceTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigPreviewServiceTest.java new file mode 100644 index 000000000..1e0b4a299 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigPreviewServiceTest.java @@ -0,0 +1,113 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.features.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.features.assignment.data.ResourceAssignmentData; +import org.onap.ccsdk.features.assignment.service.ConfigPreviewService; +import org.onap.ccsdk.features.data.adaptor.domain.ConfigResource; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.generator.service.ConfigGeneratorService; +import org.onap.ccsdk.features.generator.service.ConfigGeneratorServiceImpl; +import org.onap.ccsdk.features.model.service.ConfigModelService; +import org.onap.ccsdk.features.model.service.ConfigModelServiceImpl; +import org.onap.ccsdk.features.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/features/assignment/service/ConfigResourceAssignmentTestUtils.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigResourceAssignmentTestUtils.java new file mode 100644 index 000000000..5ce2c9a1d --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ConfigResourceAssignmentTestUtils.java @@ -0,0 +1,183 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.features.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.features.data.adaptor.domain.ConfigResource; +import org.onap.ccsdk.features.data.adaptor.domain.TransactionLog; +import org.onap.ccsdk.features.data.adaptor.service.ConfigResourceService; +import org.onap.ccsdk.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.data.dict.ResourceDefinition; +import org.onap.ccsdk.features.model.domain.ConfigModel; +import org.onap.ccsdk.features.model.domain.ConfigModelContent; +import org.onap.ccsdk.features.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() { + @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() { + @Override + public org.onap.ccsdk.features.model.domain.ConfigModel answer(InvocationOnMock invocationOnMock) + throws Throwable { + Object[] args = invocationOnMock.getArguments(); + org.onap.ccsdk.features.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 configModelContents = new ArrayList<>(); + configModelContents.add(configModelContent); + + String velocityDir = ConfigResourceAssignmentTestUtils.class.getClassLoader() + .getResource("service_templates/" + serviceTemplateName + "/velocity").getPath(); + + Collection 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.features.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() { + @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() { + @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>() { + @Override + public List answer(InvocationOnMock invocationOnMock) throws Throwable { + Object[] args = invocationOnMock.getArguments(); + List 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 getMapfromJson(String content) { + try { + ObjectMapper mapper = new ObjectMapper(); + return mapper.readValue(content, new TypeReference>() {}); + } catch (Exception e) { + logger.info("getMapfromJson Exception ({})", e); + } + return null; + } +} diff --git a/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentGenerationTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentGenerationTest.java new file mode 100644 index 000000000..04147d90f --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentGenerationTest.java @@ -0,0 +1,111 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.features.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.features.model.ConfigModelConstant; +import org.onap.ccsdk.features.model.ValidTypes; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.utils.ResourceAssignmentUtils; +import org.onap.ccsdk.features.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 assignments = + TransformationUtils.getListfromJson(resourceAssignmentContents, ResourceAssignment.class); + if (assignments != null) { + Map 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 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/features/assignment/service/ResourceAssignmentValidation.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentValidation.java new file mode 100644 index 000000000..a3be02920 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/ResourceAssignmentValidation.java @@ -0,0 +1,95 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.features.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.features.model.ConfigModelException; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.model.utils.TransformationUtils; +import org.onap.ccsdk.features.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 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 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 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/features/assignment/service/TopologicalSortingTest.java b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/TopologicalSortingTest.java new file mode 100644 index 000000000..f6e8871a6 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/features/assignment/service/TopologicalSortingTest.java @@ -0,0 +1,60 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * Modifications Copyright © 2018 IBM. + * + * 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.features.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.features.assignment.processor.ResourceAssignmentProcessor; +import org.onap.ccsdk.features.model.data.ResourceAssignment; +import org.onap.ccsdk.features.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 assignments = + TransformationUtils.getListfromJson(resourceMapping, ResourceAssignment.class); + if (assignments != null) { + SvcLogicContext ctx = new SvcLogicContext(); + ResourceAssignmentProcessor resourceAssignmentProcessor = + new ResourceAssignmentProcessor(assignments, ctx); + List> 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/service_templates/resource_assignment.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment.json index 0e29fe160..cbea6a82c 100644 --- a/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment.json +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment.json @@ -139,7 +139,7 @@ "resource-assignment": { "type": "component-resource-assignment", "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { @@ -243,7 +243,7 @@ } }, "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment/resource_assignment.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment/resource_assignment.json index 6347f4223..4cbb8fa25 100644 --- a/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment/resource_assignment.json +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/resource_assignment/resource_assignment.json @@ -139,7 +139,7 @@ "resource-assignment": { "type": "component-resource-assignment", "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { @@ -245,7 +245,7 @@ } }, "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { diff --git a/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/vpe-201802-baseconfig/vpe-201802-baseconfig.json b/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/vpe-201802-baseconfig/vpe-201802-baseconfig.json index 20207a87b..7113b70c2 100644 --- a/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/vpe-201802-baseconfig/vpe-201802-baseconfig.json +++ b/blueprints-processor/plugin/assignment-provider/src/test/resources/service_templates/vpe-201802-baseconfig/vpe-201802-baseconfig.json @@ -224,7 +224,7 @@ "resource-assignment": { "type": "component-resource-assignment", "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { @@ -328,7 +328,7 @@ } }, "interfaces": { - "org-onap-ccsdk-config-assignment-service-ConfigAssignmentNode": { + "org-onap-ccsdk-features-assignment-service-ConfigAssignmentNode": { "operations": { "process": { "inputs": { -- cgit 1.2.3-korg