2 * Copyright (C) 2019 Bell Canada. All rights reserved.
4 * NOTICE: All the intellectual and technical concepts contained herein are
5 * proprietary to Bell Canada and are protected by trade secret or copyright law.
6 * Unauthorized copying of this file, via any medium is strictly prohibited.
9 package org.onap.ccsdk.cds.cdssdclistener.handler;
11 import static org.junit.Assert.assertEquals;
12 import static org.junit.Assert.assertTrue;
13 import com.google.protobuf.ByteString;
14 import io.grpc.ManagedChannel;
15 import io.grpc.inprocess.InProcessChannelBuilder;
16 import io.grpc.inprocess.InProcessServerBuilder;
17 import io.grpc.stub.StreamObserver;
18 import io.grpc.testing.GrpcCleanupRule;
20 import java.io.IOException;
21 import java.nio.file.Paths;
22 import org.apache.commons.io.FileUtils;
23 import org.junit.Before;
24 import org.junit.Rule;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.onap.ccsdk.cds.cdssdclistener.client.CdsSdcListenerAuthClientInterceptor;
28 import org.onap.ccsdk.cds.controllerblueprints.common.api.Status;
29 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementOutput;
30 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase;
31 import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput;
32 import org.onap.ccsdk.cds.controllerblueprints.management.api.FileChunk;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.boot.context.properties.EnableConfigurationProperties;
35 import org.springframework.boot.test.context.SpringBootTest;
36 import org.springframework.test.context.junit4.SpringRunner;
39 @RunWith(SpringRunner.class)
40 @EnableConfigurationProperties({BluePrintProcesssorHandler.class, CdsSdcListenerAuthClientInterceptor.class})
41 @SpringBootTest(classes = {BluePrintProcessorHandlerTest.class})
42 public class BluePrintProcessorHandlerTest {
45 private BluePrintProcesssorHandler bluePrintProcesssorHandler;
48 private CdsSdcListenerAuthClientInterceptor cdsSdcListenerAuthClientInterceptor;
51 public GrpcCleanupRule grpcCleanup = new GrpcCleanupRule();
53 private static final String CBA_ARCHIVE = "src/test/resources/testcba.zip";
54 private static final String SUCCESS_MSG = "Successfully uploaded CBA";
55 private static final int SUCCESS_CODE = 200;
56 private ManagedChannel channel;
59 public void setUp() throws IOException {
60 final BluePrintManagementServiceImplBase serviceImplBase = new BluePrintManagementServiceImplBase() {
62 public void uploadBlueprint(BluePrintUploadInput request,
63 StreamObserver<BluePrintManagementOutput> responseObserver) {
64 responseObserver.onNext(getBluePrintManagementOutput());
65 responseObserver.onCompleted();
69 // Generate server name.
70 String serverName = InProcessServerBuilder.generateName();
72 // Create a server, add service, start, and register.
74 InProcessServerBuilder.forName(serverName).addService(serviceImplBase).directExecutor().build().start());
76 // Create a client channel.
77 channel = grpcCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build());
81 public void testApplicationEndPointSucess() throws IOException {
83 BluePrintUploadInput request = generateRequest();
86 Status output = bluePrintProcesssorHandler.sendRequest(request, channel);
89 assertEquals(SUCCESS_CODE, output.getCode());
90 assertTrue(output.getMessage().contains(SUCCESS_MSG));
93 private BluePrintUploadInput generateRequest() throws IOException {
94 File file = Paths.get(CBA_ARCHIVE).toFile();
95 byte[] bytes = FileUtils.readFileToByteArray(file);
96 FileChunk fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(bytes)).build();
98 return BluePrintUploadInput.newBuilder().setFileChunk(fileChunk).build();
101 private BluePrintManagementOutput getBluePrintManagementOutput() {
102 return BluePrintManagementOutput.newBuilder()
103 .setStatus(Status.newBuilder().setMessage(SUCCESS_MSG).setCode(200).build())