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