2 * Copyright © 2017-2018 AT&T Intellectual Property.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
20 import com.google.protobuf.util.JsonFormat
21 import io.grpc.testing.GrpcServerRule
24 import org.junit.runner.RunWith
25 import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration
26 import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock.MockBluePrintCatalogService
27 import org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api.mock.MockBlueprintDGExecutionService
28 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
29 import org.onap.ccsdk.apps.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc
30 import org.onap.ccsdk.apps.controllerblueprints.processing.api.CommonHeader
31 import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput
32 import org.slf4j.LoggerFactory
33 import org.springframework.beans.factory.annotation.Autowired
34 import org.springframework.test.context.ContextConfiguration
35 import org.springframework.test.context.TestPropertySource
36 import org.springframework.test.context.junit4.SpringRunner
37 import kotlin.test.BeforeTest
38 import kotlin.test.assertNotNull
40 @RunWith(SpringRunner::class)
41 @ContextConfiguration(classes = [BluePrintProcessingGRPCHandler::class, ExecutionServiceHandler::class,
42 MockBlueprintDGExecutionService::class, MockBluePrintCatalogService::class,
43 BluePrintCoreConfiguration::class])
44 @TestPropertySource(locations = ["classpath:application-test.properties"])
45 class BluePrintProcessingGRPCHandlerTest {
47 private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java)!!
50 val grpcServerRule = GrpcServerRule().directExecutor()
53 lateinit var bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler
57 // Create a server, add service, start, and register for automatic graceful shutdown.
58 grpcServerRule.serviceRegistry.addService(bluePrintProcessingGRPCHandler)
62 fun testSelfServiceGRPCHandler() {
64 val blockingStub = BluePrintProcessingServiceGrpc.newBlockingStub(grpcServerRule.channel)
66 val commonHeader = CommonHeader.newBuilder()
67 .setTimestamp("2012-04-23T18:25:43.511Z")
68 .setOriginatorId("System")
70 .setSubRequestId("1234-56").build()
72 val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json")
73 val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder
74 JsonFormat.parser().merge(jsonContent, payloadBuilder)
76 val input = ExecutionServiceInput.newBuilder()
77 .setCommonHeader(commonHeader)
78 .setPayload(payloadBuilder.build())
81 val response = blockingStub.process(input)
82 assertNotNull(response, "Response is null")