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.controllerblueprints.core.utils.JacksonUtils
27 import org.onap.ccsdk.apps.controllerblueprints.processing.api.CommonHeader
28 import org.onap.ccsdk.apps.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc
29 import org.onap.ccsdk.apps.controllerblueprints.processing.api.ExecutionServiceInput
30 import org.slf4j.LoggerFactory
31 import org.springframework.beans.factory.annotation.Autowired
32 import org.springframework.test.context.ContextConfiguration
33 import org.springframework.test.context.TestPropertySource
34 import org.springframework.test.context.junit4.SpringRunner
35 import kotlin.test.BeforeTest
36 import kotlin.test.assertNotNull
38 @RunWith(SpringRunner::class)
39 @ContextConfiguration(classes = [BluePrintProcessingGRPCHandler::class, BluePrintCoreConfiguration::class])
40 @TestPropertySource(locations = ["classpath:application-test.properties"])
41 class BluePrintProcessingGRPCHandlerTest {
43 private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java)!!
46 val grpcServerRule = GrpcServerRule().directExecutor()
49 lateinit var bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler
53 // Create a server, add service, start, and register for automatic graceful shutdown.
54 grpcServerRule.serviceRegistry.addService(bluePrintProcessingGRPCHandler)
58 fun testSelfServiceGRPCHandler() {
60 val blockingStub = BluePrintProcessingServiceGrpc.newBlockingStub(grpcServerRule.channel)
62 val commonHeader = CommonHeader.newBuilder()
63 .setTimestamp("2012-04-23T18:25:43.511Z")
64 .setOriginatorId("System")
66 .setSubRequestId("1234-56").build()
68 val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json")
69 val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder
70 JsonFormat.parser().merge(jsonContent, payloadBuilder)
72 val input = ExecutionServiceInput.newBuilder()
73 .setCommonHeader(commonHeader)
74 .setPayload(payloadBuilder.build())
77 val response = blockingStub.process(input)
78 assertNotNull(response, "Response is null")