From 3f83c10aa60ccecd020b06917de694ec11f544b0 Mon Sep 17 00:00:00 2001 From: "Muthuramalingam, Brinda Santh(bs2796)" Date: Thu, 15 Nov 2018 13:12:09 -0500 Subject: Blueprints Processor Microservice Implement Resource Resolution Processor Interface definitions. Change-Id: Ic2eb7915d48b9473639494ee9d159003bf56e81e Issue-ID: CCSDK-724 Signed-off-by: Muthuramalingam, Brinda Santh(bs2796) --- .../resolution/ResourceResolutionServiceTest.java | 88 -------------------- .../resolution/ResourceResolutionServiceTest.kt | 95 ++++++++++++++++++++++ .../src/test/resources/logback-test.xml | 35 ++++++++ 3 files changed, 130 insertions(+), 88 deletions(-) delete mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/test/java/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionServiceTest.java create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionServiceTest.kt create mode 100644 ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/logback-test.xml (limited to 'ms/blueprintsprocessor/functions/resource-resolution/src/test') diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/java/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionServiceTest.java b/ms/blueprintsprocessor/functions/resource-resolution/src/test/java/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionServiceTest.java deleted file mode 100644 index 0768c6099..000000000 --- a/ms/blueprintsprocessor/functions/resource-resolution/src/test/java/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionServiceTest.java +++ /dev/null @@ -1,88 +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.apps.blueprintsprocessor.services.resolution; - -import com.fasterxml.jackson.databind.node.ObjectNode; -import org.apache.commons.collections.CollectionUtils; -import org.apache.commons.io.FileUtils; -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionInput; -import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionOutput; -import org.onap.ccsdk.apps.blueprintsprocessor.core.factory.ResourceAssignmentProcessorFactory; -import org.onap.ccsdk.apps.blueprintsprocessor.services.resolution.processor.DefaultResourceAssignmentProcessor; -import org.onap.ccsdk.apps.blueprintsprocessor.services.resolution.processor.InputResourceAssignmentProcessor; -import org.onap.ccsdk.apps.blueprintsprocessor.services.resolution.processor.MDSALResourceAssignmentProcessor; -import org.onap.ccsdk.apps.blueprintsprocessor.services.resolution.processor.SdncResourceAssignmentProcessor; -import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils; -import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.test.context.ContextConfiguration; -import org.springframework.test.context.junit4.SpringRunner; - -import java.io.File; -import java.nio.charset.Charset; -import java.util.List; - -/** - * ResourceResolutionServiceTest - * - * @author Brinda Santh DATE : 8/15/2018 - */ -@RunWith(SpringRunner.class) -@ContextConfiguration(classes = {ResourceResolutionService.class, ResourceAssignmentProcessorFactory.class, - InputResourceAssignmentProcessor.class, DefaultResourceAssignmentProcessor.class, - SdncResourceAssignmentProcessor.class, MDSALResourceAssignmentProcessor.class}) -public class ResourceResolutionServiceTest { - private static Logger log = LoggerFactory.getLogger(ResourceResolutionServiceTest.class); - - @Autowired - private ResourceResolutionService resourceResolutionService; - - @Test - public void testResolveResource() throws Exception { - - Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService); - - String resourceResolutionInputContent = FileUtils.readFileToString( - new File("src/test/resources/payload/requests/sample-resourceresolution-request.json"), Charset.defaultCharset()); - - ResourceResolutionInput resourceResolutionInput = JacksonUtils.readValue(resourceResolutionInputContent, ResourceResolutionInput.class); - Assert.assertNotNull("failed to populate resourceResolutionInput request ", resourceResolutionInput); - - String resourceAssignmentContent = FileUtils.readFileToString( - new File("src/test/resources/mapping/db/resource-assignments-simple.json"), Charset.defaultCharset()); - List batchResourceAssignment = - JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment.class); - - Assert.assertTrue("failed to create ResourceAssignment from file", CollectionUtils.isNotEmpty(batchResourceAssignment)); - resourceResolutionInput.setResourceAssignments(batchResourceAssignment); - - ObjectNode inputContent = (ObjectNode) JacksonUtils.jsonNodeFromFile("src/test/resources/payload/inputs/input.json"); - Assert.assertNotNull("failed to populate input payload ", inputContent); - resourceResolutionInput.setPayload(inputContent); - log.info("ResourceResolutionInput : {}", JacksonUtils.getJson(resourceResolutionInput, true)); - - ResourceResolutionOutput resourceResolutionOutput = resourceResolutionService.resolveResource(resourceResolutionInput); - Assert.assertNotNull("failed to populate output", resourceResolutionOutput); - - } -} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionServiceTest.kt b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionServiceTest.kt new file mode 100644 index 000000000..a7d573c6c --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/kotlin/org/onap/ccsdk/apps/blueprintsprocessor/services/resolution/ResourceResolutionServiceTest.kt @@ -0,0 +1,95 @@ +/* + * Copyright © 2017-2018 AT&T Intellectual Property. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.apps.blueprintsprocessor.services.resolution + +import com.fasterxml.jackson.databind.node.ObjectNode +import org.apache.commons.collections.CollectionUtils +import org.apache.commons.io.FileUtils +import org.junit.Assert +import org.junit.Test +import org.junit.runner.RunWith +import org.onap.ccsdk.apps.blueprintsprocessor.core.api.data.ResourceResolutionInput +import org.onap.ccsdk.apps.blueprintsprocessor.core.factory.ResourceAssignmentProcessorFactory +import org.onap.ccsdk.apps.blueprintsprocessor.services.resolution.processor.DataBaseResourceAssignmentProcessor +import org.onap.ccsdk.apps.blueprintsprocessor.services.resolution.processor.DefaultResourceAssignmentProcessor +import org.onap.ccsdk.apps.blueprintsprocessor.services.resolution.processor.InputResourceAssignmentProcessor +import org.onap.ccsdk.apps.blueprintsprocessor.services.resolution.processor.SimpleRestResourceAssignmentProcessor +import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils +import org.onap.ccsdk.apps.controllerblueprints.resource.dict.ResourceAssignment +import org.slf4j.LoggerFactory +import org.springframework.beans.factory.annotation.Autowired +import org.springframework.test.context.ContextConfiguration +import org.springframework.test.context.junit4.SpringRunner +import java.io.File +import java.nio.charset.Charset +import kotlin.test.assertNotNull +import kotlin.test.assertTrue + +/** + * ResourceResolutionServiceTest + * + * @author Brinda Santh DATE : 8/15/2018 + */ +@RunWith(SpringRunner::class) +@ContextConfiguration(classes = [ResourceResolutionService::class, ResourceAssignmentProcessorFactory::class, + InputResourceAssignmentProcessor::class, DefaultResourceAssignmentProcessor::class, + DataBaseResourceAssignmentProcessor::class, SimpleRestResourceAssignmentProcessor::class]) +class ResourceResolutionServiceTest { + + private val log = LoggerFactory.getLogger(ResourceResolutionServiceTest::class.java) + + @Autowired + lateinit var resourceResolutionService: ResourceResolutionService + + + @Test + fun testRegisteredSource() { + val sources = resourceResolutionService.registeredResourceSources() + assertNotNull(sources, "failed to get registered sources") + assertTrue(sources.containsAll(arrayListOf("input", "default", "db", "mdsal")), "failed to get registered sources") + } + + @Test + @Throws(Exception::class) + fun testResolveResource() { + + Assert.assertNotNull("failed to create ResourceResolutionService", resourceResolutionService) + + val resourceResolutionInputContent = FileUtils.readFileToString( + File("src/test/resources/payload/requests/sample-resourceresolution-request.json"), Charset.defaultCharset()) + + val resourceResolutionInput = JacksonUtils.readValue(resourceResolutionInputContent, ResourceResolutionInput::class.java) + Assert.assertNotNull("failed to populate resourceResolutionInput request ", resourceResolutionInput) + + val resourceAssignmentContent = FileUtils.readFileToString( + File("src/test/resources/mapping/db/resource-assignments-simple.json"), Charset.defaultCharset()) + val batchResourceAssignment = JacksonUtils.getListFromJson(resourceAssignmentContent, ResourceAssignment::class.java) + + Assert.assertTrue("failed to create ResourceAssignment from file", CollectionUtils.isNotEmpty(batchResourceAssignment)) + resourceResolutionInput!!.resourceAssignments = batchResourceAssignment as MutableList + + val inputContent = JacksonUtils.jsonNodeFromFile("src/test/resources/payload/inputs/input.json") as ObjectNode + Assert.assertNotNull("failed to populate input payload ", inputContent) + resourceResolutionInput.payload = inputContent + log.info("ResourceResolutionInput : {}", JacksonUtils.getJson(resourceResolutionInput, true)) + + val resourceResolutionOutput = resourceResolutionService.resolveResource(resourceResolutionInput) + Assert.assertNotNull("failed to populate output", resourceResolutionOutput) + + } + +} diff --git a/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/logback-test.xml b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/logback-test.xml new file mode 100644 index 000000000..a816a06c5 --- /dev/null +++ b/ms/blueprintsprocessor/functions/resource-resolution/src/test/resources/logback-test.xml @@ -0,0 +1,35 @@ + + + + + + + %d{HH:mm:ss.SSS} %-5level %logger{100} - %msg%n + + + + + + + + + + + + + -- cgit 1.2.3-korg