2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 Bell Canada.
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
21 import com.google.protobuf.util.JsonFormat
22 import io.grpc.testing.GrpcServerRule
25 import org.junit.runner.RunWith
26 import org.onap.ccsdk.apps.controllerblueprints.core.utils.JacksonUtils
27 import org.onap.ccsdk.apps.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc
28 import org.onap.ccsdk.apps.controllerblueprints.processing.api.CommonHeader
29 import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput
30 import org.springframework.beans.factory.annotation.Autowired
31 import org.springframework.boot.autoconfigure.EnableAutoConfiguration
32 import org.springframework.context.annotation.ComponentScan
33 import org.springframework.test.annotation.DirtiesContext
34 import org.springframework.test.context.TestPropertySource
35 import org.springframework.test.context.junit4.SpringRunner
36 import kotlin.test.BeforeTest
37 import kotlin.test.assertNotNull
39 @RunWith(SpringRunner::class)
41 @EnableAutoConfiguration
42 @ComponentScan(basePackages = ["org.onap.ccsdk.apps.blueprintsprocessor", "org.onap.ccsdk.apps.controllerblueprints"])
43 @TestPropertySource(locations = ["classpath:application-test.properties"])
44 class BluePrintProcessingGRPCHandlerTest {
47 val grpcServerRule = GrpcServerRule().directExecutor()
50 lateinit var bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler
54 // Create a server, add service, start, and register for automatic graceful shutdown.
55 grpcServerRule.serviceRegistry.addService(bluePrintProcessingGRPCHandler)
59 fun testSelfServiceGRPCHandler() {
61 val blockingStub = BluePrintProcessingServiceGrpc.newBlockingStub(grpcServerRule.channel)
63 val commonHeader = CommonHeader.newBuilder()
64 .setTimestamp("2012-04-23T18:25:43.511Z")
65 .setOriginatorId("System")
67 .setSubRequestId("1234-56").build()
69 val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json")
70 val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder
71 JsonFormat.parser().merge(jsonContent, payloadBuilder)
73 val input = ExecutionServiceInput.newBuilder()
74 .setCommonHeader(commonHeader)
75 .setPayload(payloadBuilder.build())
78 val response = blockingStub.process(input)
79 assertNotNull(response, "Response is null")