2 * Copyright © 2018-2019 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.cds.blueprintsprocessor.selfservice.api
19 import com.google.protobuf.util.JsonFormat
20 import io.grpc.stub.StreamObserver
21 import kotlinx.coroutines.delay
22 import kotlinx.coroutines.runBlocking
23 import org.onap.ccsdk.cds.blueprintsprocessor.grpc.GRPCLibConstants
24 import org.onap.ccsdk.cds.blueprintsprocessor.grpc.TokenAuthGrpcClientProperties
25 import org.onap.ccsdk.cds.blueprintsprocessor.grpc.service.TokenAuthGrpcClientService
26 import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers
27 import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader
28 import org.onap.ccsdk.cds.controllerblueprints.core.logger
29 import org.onap.ccsdk.cds.controllerblueprints.core.utils.JacksonUtils
30 import org.onap.ccsdk.cds.controllerblueprints.processing.api.BluePrintProcessingServiceGrpc
31 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceInput
32 import org.onap.ccsdk.cds.controllerblueprints.processing.api.ExecutionServiceOutput
34 class BluePrintProcessingIntegrationTest {
36 private val log = logger(BluePrintProcessingIntegrationTest::class)
38 /** This is Integration test sample, Do not enable this test case in server build, this is for local desktop testing*/
40 fun integrationTestGrpcManagement() {
42 val tokenAuthGrpcClientProperties = TokenAuthGrpcClientProperties().apply {
45 type = GRPCLibConstants.TYPE_TOKEN_AUTH
46 token = "Basic Y2NzZGthcHBzOmNjc2RrYXBwcw=="
48 val basicAuthGrpcClientService = TokenAuthGrpcClientService(tokenAuthGrpcClientProperties)
49 val channel = basicAuthGrpcClientService.channel()
51 val stub = BluePrintProcessingServiceGrpc.newStub(channel)
53 val requestObs = stub.process(object : StreamObserver<ExecutionServiceOutput> {
54 override fun onNext(executionServiceOuput: ExecutionServiceOutput) {
55 log.info("onNext Received {}", executionServiceOuput)
58 override fun onError(error: Throwable) {
59 log.error("Fail to process message", error)
62 override fun onCompleted() {
67 val commonHeader = CommonHeader.newBuilder()
68 .setTimestamp("2012-04-23T18:25:43.511Z")
69 .setOriginatorId("System")
70 .setRequestId("1234-$it")
71 .setSubRequestId("1234-56").build()
73 val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json")
74 val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder
75 JsonFormat.parser().merge(jsonContent, payloadBuilder)
77 val actionIdentifier = ActionIdentifiers.newBuilder()
78 .setActionName("SampleScript")
79 .setBlueprintName("sample-cba")
80 .setBlueprintVersion("1.0.0")
83 val input = ExecutionServiceInput.newBuilder()
84 .setCommonHeader(commonHeader)
85 .setActionIdentifiers(actionIdentifier)
86 .setPayload(payloadBuilder.build())
89 requestObs.onNext(input)
90 requestObs.onCompleted()