8971ebde25c7d9ac2fbc697f731e7fa005416111
[ccsdk/cds.git] / ms / blueprintsprocessor / modules / inbounds / selfservice-api / src / test / kotlin / org / onap / ccsdk / cds / blueprintsprocessor / selfservice / api / BluePrintProcessingIntegrationTest.kt
1 /*
2  * Copyright © 2018-2019 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.cds.blueprintsprocessor.selfservice.api
18
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
33
34 class BluePrintProcessingIntegrationTest {
35
36     private val log = logger(BluePrintProcessingIntegrationTest::class)
37
38     /** This is Integration test sample, Do not enable this test case in server build, this is for local desktop testing*/
39     //@Test
40     fun integrationTestGrpcManagement() {
41         runBlocking {
42             val tokenAuthGrpcClientProperties = TokenAuthGrpcClientProperties().apply {
43                 host = "127.0.0.1"
44                 port = 50052
45                 type = GRPCLibConstants.TYPE_TOKEN_AUTH
46                 token = "Basic Y2NzZGthcHBzOmNjc2RrYXBwcw=="
47             }
48             val basicAuthGrpcClientService = TokenAuthGrpcClientService(tokenAuthGrpcClientProperties)
49             val channel = basicAuthGrpcClientService.channel()
50
51             val stub = BluePrintProcessingServiceGrpc.newStub(channel)
52             repeat(1) {
53                 val requestObs = stub.process(object : StreamObserver<ExecutionServiceOutput> {
54                     override fun onNext(executionServiceOuput: ExecutionServiceOutput) {
55                         log.info("onNext Received {}", executionServiceOuput)
56                     }
57
58                     override fun onError(error: Throwable) {
59                         log.error("Fail to process message", error)
60                     }
61
62                     override fun onCompleted() {
63                         log.info("Done")
64                     }
65                 })
66
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()
72
73                 val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json")
74                 val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder
75                 JsonFormat.parser().merge(jsonContent, payloadBuilder)
76
77                 val actionIdentifier = ActionIdentifiers.newBuilder()
78                         .setActionName("SampleScript")
79                         .setBlueprintName("sample-cba")
80                         .setBlueprintVersion("1.0.0")
81                         .build()
82
83                 val input = ExecutionServiceInput.newBuilder()
84                         .setCommonHeader(commonHeader)
85                         .setActionIdentifiers(actionIdentifier)
86                         .setPayload(payloadBuilder.build())
87                         .build()
88
89                 requestObs.onNext(input)
90                 requestObs.onCompleted()
91             }
92             delay(1000)
93             channel.shutdownNow()
94         }
95     }
96 }