cd871b4a8b0c411599ca7fc839af36a5c3f8f8ce
[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.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
39
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 {
46
47     private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java)!!
48
49     @get:Rule
50     val grpcServerRule = GrpcServerRule().directExecutor()
51
52     @Autowired
53     lateinit var bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler
54
55     @BeforeTest
56     fun init() {
57         // Create a server, add service, start, and register for automatic graceful shutdown.
58         grpcServerRule.serviceRegistry.addService(bluePrintProcessingGRPCHandler)
59     }
60
61     @Test
62     fun testSelfServiceGRPCHandler() {
63
64         val blockingStub = BluePrintProcessingServiceGrpc.newBlockingStub(grpcServerRule.channel)
65
66         val commonHeader = CommonHeader.newBuilder()
67                 .setTimestamp("2012-04-23T18:25:43.511Z")
68                 .setOriginatorId("System")
69                 .setRequestId("1234")
70                 .setSubRequestId("1234-56").build()
71
72         val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json")
73         val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder
74         JsonFormat.parser().merge(jsonContent, payloadBuilder)
75
76         val input = ExecutionServiceInput.newBuilder()
77                 .setCommonHeader(commonHeader)
78                 .setPayload(payloadBuilder.build())
79                 .build()
80
81         val response = blockingStub.process(input)
82         assertNotNull(response, "Response is null")
83     }
84
85 }