From 021d63c68b4d5fbb8cf5e34549d5b17bce488df3 Mon Sep 17 00:00:00 2001 From: "Singal, Kapil (ks220y)" Date: Tue, 4 Sep 2018 21:38:51 -0400 Subject: Blueprints Processor Default Resource Assignment Creating SDN Blueprints Processor Default Resource Assignment Processor Change-Id: Ib2475eb220218c95eda62b5cefe4eed38e9f756e Issue-ID: CCSDK-501 Signed-off-by: Singal, Kapil (ks220y) --- .../processor/DefaultResourceProcessorTest.java | 127 +++++++++++++++++++++ 1 file changed, 127 insertions(+) create mode 100644 blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DefaultResourceProcessorTest.java (limited to 'blueprints-processor/plugin/assignment-provider/src/test/java') 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 new file mode 100644 index 000000000..7e8d14201 --- /dev/null +++ b/blueprints-processor/plugin/assignment-provider/src/test/java/org/onap/ccsdk/config/assignment/processor/DefaultResourceProcessorTest.java @@ -0,0 +1,127 @@ +/* + * 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")); + + } + +} -- cgit 1.2.3-korg