2 * Copyright © 2017-2018 AT&T Intellectual Property.
3 * Modifications Copyright © 2019 Bell Canada.
4 * Modifications Copyright © 2019 IBM.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 package org.onap.ccsdk.cds.blueprintsprocessor.selfservice.api
21 import com.google.protobuf.util.JsonFormat
22 import io.grpc.stub.StreamObserver
23 import io.grpc.testing.GrpcServerRule
24 import org.junit.Assert
27 import org.junit.runner.RunWith
28 import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers
29 import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader
30 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
31 import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc
32 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput
33 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput
34 import org.slf4j.LoggerFactory
35 import org.springframework.beans.factory.annotation.Autowired
36 import org.springframework.test.annotation.DirtiesContext
37 import org.springframework.test.context.ContextConfiguration
38 import org.springframework.test.context.TestPropertySource
39 import org.springframework.test.context.junit4.SpringRunner
40 import kotlin.test.BeforeTest
42 @RunWith(SpringRunner::class)
44 @ContextConfiguration(
45 classes = [SelfServiceApiTestConfiguration::class, TestDatabaseConfiguration::class,
46 ErrorCatalogTestConfiguration::class]
48 @TestPropertySource(locations = ["classpath:application-test.properties"])
49 class BluePrintProcessingGRPCHandlerTest {
51 private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java)
54 val grpcServerRule = GrpcServerRule().directExecutor()
57 lateinit var bluePrintProcessingGRPCHandler: BluePrintProcessingGRPCHandler
59 lateinit var requestObs: StreamObserver<ExecutionServiceInput>
63 grpcServerRule.serviceRegistry.addService(bluePrintProcessingGRPCHandler)
65 val blockingStub = BluePrintProcessingServiceGrpc.newStub(grpcServerRule.channel)
67 requestObs = blockingStub.process(object : StreamObserver<ExecutionServiceOutput> {
68 override fun onNext(executionServiceOuput: ExecutionServiceOutput) {
69 log.debug("onNext {}", executionServiceOuput)
70 if ("1234" == executionServiceOuput.commonHeader.requestId) {
72 "Failed to process request, \'actionIdentifiers.mode\' not specified. Valid value are: \'sync\' or \'async\'.",
73 executionServiceOuput.status.errorMessage
78 override fun onError(error: Throwable) {
79 log.debug("Fail to process message", error)
80 Assert.assertEquals("INTERNAL: Could not find blueprint : from database", error.message)
83 override fun onCompleted() {
90 fun testSelfServiceGRPCHandler() {
91 val commonHeader = CommonHeader.newBuilder()
92 .setTimestamp("2012-04-23T18:25:43.511Z")
93 .setOriginatorId("System")
95 .setSubRequestId("1234-56").build()
97 val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json")
98 val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder
99 JsonFormat.parser().merge(jsonContent, payloadBuilder)
101 val input = ExecutionServiceInput.newBuilder()
102 .setCommonHeader(commonHeader)
103 .setPayload(payloadBuilder.build())
106 requestObs.onNext(input)
108 val commonHeader2 = CommonHeader.newBuilder()
109 .setTimestamp("2012-04-23T18:25:43.511Z")
110 .setOriginatorId("System")
111 .setRequestId("2345")
112 .setSubRequestId("1234-56").build()
114 val actionIdentifier = ActionIdentifiers.newBuilder().setMode("sync").build()
116 val input2 = ExecutionServiceInput.newBuilder()
117 .setCommonHeader(commonHeader2)
118 .setActionIdentifiers(actionIdentifier)
119 .setPayload(payloadBuilder.build())
122 requestObs.onNext(input2)
124 requestObs.onCompleted()