2 * Copyright © 2017-2018 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.apps.blueprintsprocessor.selfservice.api
19 import com.google.protobuf.ByteString
20 import io.grpc.testing.GrpcServerRule
21 import org.apache.commons.io.FileUtils
24 import org.junit.runner.RunWith
25 import org.onap.ccsdk.apps.blueprintsprocessor.core.BluePrintCoreConfiguration
26 import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintManagementServiceGrpc
27 import org.onap.ccsdk.apps.controllerblueprints.management.api.BluePrintUploadInput
28 import org.onap.ccsdk.apps.controllerblueprints.management.api.CommonHeader
29 import org.onap.ccsdk.apps.controllerblueprints.management.api.FileChunk
30 import org.slf4j.LoggerFactory
31 import org.springframework.beans.factory.annotation.Autowired
32 import org.springframework.test.context.ContextConfiguration
33 import org.springframework.test.context.TestPropertySource
34 import org.springframework.test.context.junit4.SpringRunner
36 import java.nio.file.Paths
37 import kotlin.test.AfterTest
38 import kotlin.test.BeforeTest
39 import kotlin.test.assertNotNull
40 import kotlin.test.assertTrue
42 @RunWith(SpringRunner::class)
43 @ContextConfiguration(classes = [BluePrintManagementGRPCHandler::class, BluePrintCoreConfiguration::class])
44 @TestPropertySource(locations = ["classpath:application-test.properties"])
45 class BluePrintManagementGRPCHandlerTest {
47 private val log = LoggerFactory.getLogger(BluePrintProcessingGRPCHandlerTest::class.java)!!
50 val grpcServerRule = GrpcServerRule().directExecutor()
53 lateinit var bluePrintManagementGRPCHandler: BluePrintManagementGRPCHandler
57 // Create a server, add service, start, and register for automatic graceful shutdown.
58 grpcServerRule.serviceRegistry.addService(bluePrintManagementGRPCHandler)
63 FileUtils.deleteDirectory(File("./target/blueprints"))
67 fun testFileUpload() {
68 val blockingStub = BluePrintManagementServiceGrpc.newBlockingStub(grpcServerRule.channel)
70 val file = Paths.get("./src/test/resources/test-cba.zip").toFile()
71 assertTrue(file.exists(), "couldnt get file ${file.absolutePath}")
73 val commonHeader = CommonHeader.newBuilder()
74 .setTimestamp("2012-04-23T18:25:43.511Z")
75 .setOriginatorId("System")
77 .setSubRequestId("1234-56").build()
79 val fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(file.inputStream().readBytes()))
82 val input = BluePrintUploadInput.newBuilder()
83 .setCommonHeader(commonHeader)
84 .setBlueprintName("sample")
85 .setBlueprintVersion("1.0.0")
86 .setFileChunk(fileChunk)
89 val output = blockingStub.uploadBlueprint(input)
90 assertNotNull(output, "failed to get upload response")