Revert "Renaming Files having BluePrint to have Blueprint"
[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 import org.springframework.test.context.ContextConfiguration
34
35 @ContextConfiguration(
36     classes = [SelfServiceApiTestConfiguration::class, ErrorCatalogTestConfiguration::class]
37 )
38 class BluePrintProcessingIntegrationTest {
39
40     private val log = logger(BluePrintProcessingIntegrationTest::class)
41
42     /** This is Integration test sample, Do not enable this test case in server build, this is for local desktop testing*/
43     // @Test
44     fun integrationTestGrpcManagement() {
45         runBlocking {
46             val tokenAuthGrpcClientProperties = TokenAuthGrpcClientProperties().apply {
47                 host = "127.0.0.1"
48                 port = 50052
49                 type = GRPCLibConstants.TYPE_TOKEN_AUTH
50                 token = "Basic Y2NzZGthcHBzOmNjc2RrYXBwcw=="
51             }
52             val basicAuthGrpcClientService = TokenAuthGrpcClientService(tokenAuthGrpcClientProperties)
53             val channel = basicAuthGrpcClientService.channel()
54
55             val stub = BluePrintProcessingServiceGrpc.newStub(channel)
56             repeat(1) {
57                 val requestObs = stub.process(object : StreamObserver<ExecutionServiceOutput> {
58                     override fun onNext(executionServiceOuput: ExecutionServiceOutput) {
59                         log.info("onNext Received {}", executionServiceOuput)
60                     }
61
62                     override fun onError(error: Throwable) {
63                         log.error("Fail to process message", error)
64                     }
65
66                     override fun onCompleted() {
67                         log.info("Done")
68                     }
69                 })
70
71                 val commonHeader = CommonHeader.newBuilder()
72                     .setTimestamp("2012-04-23T18:25:43.511Z")
73                     .setOriginatorId("System")
74                     .setRequestId("1234-$it")
75                     .setSubRequestId("1234-56").build()
76
77                 val jsonContent = JacksonUtils.getClassPathFileContent("execution-input/sample-payload.json")
78                 val payloadBuilder = ExecutionServiceInput.newBuilder().payloadBuilder
79                 JsonFormat.parser().merge(jsonContent, payloadBuilder)
80
81                 val actionIdentifier = ActionIdentifiers.newBuilder()
82                     .setActionName("SampleScript")
83                     .setBlueprintName("sample-cba")
84                     .setBlueprintVersion("1.0.0")
85                     .build()
86
87                 val input = ExecutionServiceInput.newBuilder()
88                     .setCommonHeader(commonHeader)
89                     .setActionIdentifiers(actionIdentifier)
90                     .setPayload(payloadBuilder.build())
91                     .build()
92
93                 requestObs.onNext(input)
94                 requestObs.onCompleted()
95             }
96             delay(1000)
97             channel.shutdownNow()
98         }
99     }
100 }