6d5d633c94e10a8541b07d6d63e9d8b0e0fb8a3c
[ccsdk/cds.git] /
1 /*
2  * Copyright © 2017-2018 AT&T Intellectual Property.
3  *
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
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.onap.ccsdk.apps.blueprintsprocessor.selfservice.api
18
19
20 import com.google.protobuf.util.JsonFormat
21 import io.grpc.testing.GrpcServerRule
22 import org.junit.Rule
23 import org.junit.Test
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
37
38 @RunWith(SpringRunner::class)
39 @ContextConfiguration(classes = [BluePrintProcessingGRPCHandler::class, BluePrintCoreConfiguration::class])
40 @TestPropertySource(locations = ["classpath:application-test.properties"])
41 class BluePrintProcessingGRPCHandlerTest {
42
43     private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java)!!
44
45     @get:Rule
46     val grpcServerRule = GrpcServerRule().directExecutor()
47
48     @Autowired
49     lateinit var bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler
50
51     @BeforeTest
52     fun init() {
53         // Create a server, add service, start, and register for automatic graceful shutdown.
54         grpcServerRule.serviceRegistry.addService(bluePrintProcessingGRPCHandler)
55     }
56
57     @Test
58     fun testSelfServiceGRPCHandler() {
59
60         val blockingStub = BluePrintProcessingServiceGrpc.newBlockingStub(grpcServerRule.channel)
61
62         val commonHeader = CommonHeader.newBuilder()
63                 .setTimestamp("2012-04-23T18:25:43.511Z")
64                 .setOriginatorId("System")
65                 .setRequestId("1234")
66                 .setSubRequestId("1234-56").build()
67
68         val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json")
69         val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder
70         JsonFormat.parser().merge(jsonContent, payloadBuilder)
71
72         val input = ExecutionServiceInput.newBuilder()
73                 .setCommonHeader(commonHeader)
74                 .setPayload(payloadBuilder.build())
75                 .build()
76
77         val response = blockingStub.process(input)
78         assertNotNull(response, "Response is null")
79     }
80
81 }