From adcd4f2bc695840e9ecbc05003bc52c675f22fec Mon Sep 17 00:00:00 2001 From: KAPIL SINGAL Date: Fri, 22 Jan 2021 11:49:51 -0500 Subject: Renaming Files having BluePrint to have Blueprint Replacing BluePrint with Blueprint throughout Issue-ID: CCSDK-3098 Signed-off-by: KAPIL SINGAL Change-Id: Ibee8bad07ae7d9287073db2d4f2f2cd730fa8b96 --- .../SdcListenerNotificationCallback.java | 4 +- .../handler/BluePrintProcesssorHandler.java | 67 ----------- .../handler/BlueprintProcesssorHandler.java | 67 +++++++++++ .../cds/sdclistener/service/ListenerService.java | 4 +- .../sdclistener/service/ListenerServiceImpl.java | 20 ++-- .../handler/BluePrintProcessorHandlerTest.java | 124 --------------------- .../handler/BlueprintProcessorHandlerTest.java | 124 +++++++++++++++++++++ .../service/ListenerServiceImplTest.java | 12 +- 8 files changed, 211 insertions(+), 211 deletions(-) delete mode 100644 ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcesssorHandler.java create mode 100644 ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/handler/BlueprintProcesssorHandler.java delete mode 100644 ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcessorHandlerTest.java create mode 100644 ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/handler/BlueprintProcessorHandlerTest.java (limited to 'ms/sdclistener/application') diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerNotificationCallback.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerNotificationCallback.java index b8868325a..45fb36736 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerNotificationCallback.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/SdcListenerNotificationCallback.java @@ -122,13 +122,13 @@ public class SdcListenerNotificationCallback implements INotificationCallback { final String archivePath = cbaArchivePath.toString(); // Extract CBA archive from CSAR package and store it into local disk - csarFiles.forEach(file -> listenerService.extractBluePrint(file.getAbsolutePath(), archivePath)); + csarFiles.forEach(file -> listenerService.extractBlueprint(file.getAbsolutePath(), archivePath)); csarFiles.forEach(file -> FileUtil.deleteFile(file, csarArchivePath.toString())); } else { LOGGER.error("Could not able to read CSAR files from this location {}", csarArchivePath); } - listenerService.saveBluePrintToCdsDatabase(cbaArchivePath, sdcListenerDto.getManagedChannelForGrpc()); + listenerService.saveBlueprintToCdsDatabase(cbaArchivePath, sdcListenerDto.getManagedChannelForGrpc()); } } diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcesssorHandler.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcesssorHandler.java deleted file mode 100644 index b80dd260d..000000000 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcesssorHandler.java +++ /dev/null @@ -1,67 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.sdclistener.handler; - -import io.grpc.ManagedChannel; -import org.onap.ccsdk.cds.controllerblueprints.common.api.Status; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementOutput; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc.BluePrintManagementServiceBlockingStub; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.context.properties.ConfigurationProperties; -import org.springframework.stereotype.Component; - -@ConfigurationProperties("listenerservice") -@Component -public class BluePrintProcesssorHandler implements AutoCloseable { - - private static final Logger LOGGER = LoggerFactory.getLogger(BluePrintProcesssorHandler.class); - - private ManagedChannel channel; - - /** - * Sending CBA archive to CDS backend to store into its Database. - * - * @param request BluePrintManagementInput object holds CBA archive, its version and blueprints. - * @param managedChannel - ManagedChannel object helps to access the server or application end point. - * - * @return A response object - */ - public Status sendRequest(BluePrintUploadInput request, ManagedChannel managedChannel) { - LOGGER.info("Sending request to blueprint processor"); - - this.channel = managedChannel; - - final BluePrintManagementServiceBlockingStub syncStub = BluePrintManagementServiceGrpc.newBlockingStub(channel); - - // Send the request to CDS backend. - final BluePrintManagementOutput response = syncStub.uploadBlueprint(request); - - return response.getStatus(); - } - - @Override - public void close() { - if (channel != null) { - channel.shutdown(); - } - LOGGER.info("Stopping GRPC connection to CDS backend"); - } - -} diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/handler/BlueprintProcesssorHandler.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/handler/BlueprintProcesssorHandler.java new file mode 100644 index 000000000..41475cd6b --- /dev/null +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/handler/BlueprintProcesssorHandler.java @@ -0,0 +1,67 @@ +/* + * Copyright © 2019 Bell Canada + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.sdclistener.handler; + +import io.grpc.ManagedChannel; +import org.onap.ccsdk.cds.controllerblueprints.common.api.Status; +import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintManagementOutput; +import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintManagementServiceGrpc; +import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintManagementServiceGrpc.BlueprintManagementServiceBlockingStub; +import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintUploadInput; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.stereotype.Component; + +@ConfigurationProperties("listenerservice") +@Component +public class BlueprintProcesssorHandler implements AutoCloseable { + + private static final Logger LOGGER = LoggerFactory.getLogger(BlueprintProcesssorHandler.class); + + private ManagedChannel channel; + + /** + * Sending CBA archive to CDS backend to store into its Database. + * + * @param request BlueprintManagementInput object holds CBA archive, its version and blueprints. + * @param managedChannel - ManagedChannel object helps to access the server or application end point. + * + * @return A response object + */ + public Status sendRequest(BlueprintUploadInput request, ManagedChannel managedChannel) { + LOGGER.info("Sending request to blueprint processor"); + + this.channel = managedChannel; + + final BlueprintManagementServiceBlockingStub syncStub = BlueprintManagementServiceGrpc.newBlockingStub(channel); + + // Send the request to CDS backend. + final BlueprintManagementOutput response = syncStub.uploadBlueprint(request); + + return response.getStatus(); + } + + @Override + public void close() { + if (channel != null) { + channel.shutdown(); + } + LOGGER.info("Stopping GRPC connection to CDS backend"); + } + +} diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerService.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerService.java index 5fa3fb327..231054f06 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerService.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerService.java @@ -29,7 +29,7 @@ public interface ListenerService { * @param csarArchivePath The path where CSAR archive is stored. * @param cbaArchivePath The destination path where CBA will be stored. */ - void extractBluePrint(String csarArchivePath, String cbaArchivePath); + void extractBlueprint(String csarArchivePath, String cbaArchivePath); /** * Store the Zip file into CDS database. @@ -37,7 +37,7 @@ public interface ListenerService { * @param path path where zip file exists. * @param managedChannel To access the blueprint processor application end point */ - void saveBluePrintToCdsDatabase(Path path, ManagedChannel managedChannel); + void saveBlueprintToCdsDatabase(Path path, ManagedChannel managedChannel); /** * Extract and store the csar package to local disk. diff --git a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java index ee27a9475..1aebd74b8 100644 --- a/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java +++ b/ms/sdclistener/application/src/main/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImpl.java @@ -23,12 +23,12 @@ import org.apache.commons.io.IOUtils; import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers; import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader; import org.onap.ccsdk.cds.controllerblueprints.common.api.Status; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput; +import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintUploadInput; import org.onap.ccsdk.cds.controllerblueprints.management.api.FileChunk; import org.onap.ccsdk.cds.controllerblueprints.management.api.UploadAction; import org.onap.ccsdk.cds.sdclistener.client.SdcListenerAuthClientInterceptor; import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto; -import org.onap.ccsdk.cds.sdclistener.handler.BluePrintProcesssorHandler; +import org.onap.ccsdk.cds.sdclistener.handler.BlueprintProcesssorHandler; import org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus; import org.onap.ccsdk.cds.sdclistener.util.FileUtil; import org.onap.sdc.api.results.IDistributionClientDownloadResult; @@ -64,7 +64,7 @@ import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_OK; public class ListenerServiceImpl implements ListenerService { @Autowired - private BluePrintProcesssorHandler bluePrintProcesssorHandler; + private BlueprintProcesssorHandler bluePrintProcesssorHandler; @Autowired private SdcListenerAuthClientInterceptor sdcListenerAuthClientInterceptor; @@ -87,7 +87,7 @@ public class ListenerServiceImpl implements ListenerService { private static final Logger LOGGER = LoggerFactory.getLogger(ListenerServiceImpl.class); @Override - public void extractBluePrint(String csarArchivePath, String cbaArchivePath) { + public void extractBlueprint(String csarArchivePath, String cbaArchivePath) { int validPathCount = 0; final String distributionId = getDistributionId(); final String artifactUrl = getArtifactUrl(); @@ -101,7 +101,7 @@ public class ListenerServiceImpl implements ListenerService { validPathCount++; final String cbaArchiveName = Paths.get(fileName).getFileName().toString(); LOGGER.info("Storing the CBA archive {}", cbaArchiveName); - storeBluePrint(zipFile, cbaArchiveName, cbaStorageDir, entry); + storeBlueprint(zipFile, cbaArchiveName, cbaStorageDir, entry); } } @@ -121,7 +121,7 @@ public class ListenerServiceImpl implements ListenerService { } } - private void storeBluePrint(ZipFile zipFile, String fileName, Path cbaArchivePath, ZipEntry entry) { + private void storeBlueprint(ZipFile zipFile, String fileName, Path cbaArchivePath, ZipEntry entry) { Path targetLocation = cbaArchivePath.resolve(fileName); LOGGER.info("The target location for zip file is {}", targetLocation); File targetZipFile = new File(targetLocation.toString()); @@ -144,7 +144,7 @@ public class ListenerServiceImpl implements ListenerService { } @Override - public void saveBluePrintToCdsDatabase(Path cbaArchivePath, ManagedChannel channel) { + public void saveBlueprintToCdsDatabase(Path cbaArchivePath, ManagedChannel channel) { List zipFiles = FileUtil.getFilesFromDisk(cbaArchivePath); if (!zipFiles.isEmpty()) { prepareRequestForCdsBackend(zipFiles, channel, cbaArchivePath.toString()); @@ -193,7 +193,7 @@ public class ListenerServiceImpl implements ListenerService { files.forEach(zipFile -> { try { - final BluePrintUploadInput request = generateBluePrintUploadInputBuilder(zipFile, path); + final BlueprintUploadInput request = generateBlueprintUploadInputBuilder(zipFile, path); // Send request to CDS Backend. final Status responseStatus = bluePrintProcesssorHandler.sendRequest(request, managedChannel); @@ -219,11 +219,11 @@ public class ListenerServiceImpl implements ListenerService { }); } - private BluePrintUploadInput generateBluePrintUploadInputBuilder(File file, String path) throws IOException { + private BlueprintUploadInput generateBlueprintUploadInputBuilder(File file, String path) throws IOException { byte[] bytes = FileUtils.readFileToByteArray(file); FileChunk fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(bytes)).build(); FileUtil.deleteFile(file, path); - return BluePrintUploadInput.newBuilder() + return BlueprintUploadInput.newBuilder() .setCommonHeader(CommonHeader.newBuilder().setRequestId(UUID.randomUUID().toString()) .setSubRequestId(UUID.randomUUID().toString()).setOriginatorId("SDC-LISTENER").build()) .setActionIdentifiers( diff --git a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcessorHandlerTest.java b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcessorHandlerTest.java deleted file mode 100644 index 7cde45d9e..000000000 --- a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcessorHandlerTest.java +++ /dev/null @@ -1,124 +0,0 @@ -/* - * Copyright © 2019 Bell Canada - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.onap.ccsdk.cds.sdclistener.handler; - -import com.google.protobuf.ByteString; -import io.grpc.ManagedChannel; -import io.grpc.inprocess.InProcessChannelBuilder; -import io.grpc.inprocess.InProcessServerBuilder; -import io.grpc.stub.StreamObserver; -import io.grpc.testing.GrpcCleanupRule; -import org.apache.commons.io.FileUtils; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers; -import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader; -import org.onap.ccsdk.cds.controllerblueprints.common.api.Status; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementOutput; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintManagementServiceGrpc.BluePrintManagementServiceImplBase; -import org.onap.ccsdk.cds.controllerblueprints.management.api.BluePrintUploadInput; -import org.onap.ccsdk.cds.controllerblueprints.management.api.FileChunk; -import org.onap.ccsdk.cds.controllerblueprints.management.api.UploadAction; -import org.onap.ccsdk.cds.sdclistener.client.SdcListenerAuthClientInterceptor; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.junit4.SpringRunner; - -import java.io.File; -import java.io.IOException; -import java.nio.file.Paths; -import java.util.UUID; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -@RunWith(SpringRunner.class) -@EnableConfigurationProperties({BluePrintProcesssorHandler.class, SdcListenerAuthClientInterceptor.class}) -@SpringBootTest(classes = {BluePrintProcessorHandlerTest.class}) -public class BluePrintProcessorHandlerTest { - - @Autowired - private BluePrintProcesssorHandler bluePrintProcesssorHandler; - - @Autowired - private SdcListenerAuthClientInterceptor sdcListenerAuthClientInterceptor; - - @Rule - public GrpcCleanupRule grpcCleanup = new GrpcCleanupRule(); - - private static final String CBA_ARCHIVE = "src/test/resources/testcba.zip"; - private static final String SUCCESS_MSG = "Successfully uploaded CBA"; - private static final int SUCCESS_CODE = 200; - private ManagedChannel channel; - - @Before - public void setUp() throws IOException { - final BluePrintManagementServiceImplBase serviceImplBase = new BluePrintManagementServiceImplBase() { - @Override - public void uploadBlueprint(BluePrintUploadInput request, - StreamObserver responseObserver) { - responseObserver.onNext(getBluePrintManagementOutput()); - responseObserver.onCompleted(); - } - }; - - // Generate server name. - String serverName = InProcessServerBuilder.generateName(); - - // Create a server, add service, start, and register. - grpcCleanup.register(InProcessServerBuilder.forName(serverName).addService(serviceImplBase).directExecutor() - .build().start()); - - // Create a client channel. - channel = grpcCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build()); - } - - @Test - public void testApplicationEndPointSucess() throws IOException { - // Arrange - BluePrintUploadInput request = generateRequest(); - - // Act - Status output = bluePrintProcesssorHandler.sendRequest(request, channel); - - // Verify - assertEquals(SUCCESS_CODE, output.getCode()); - assertTrue(output.getMessage().contains(SUCCESS_MSG)); - } - - private BluePrintUploadInput generateRequest() throws IOException { - File file = Paths.get(CBA_ARCHIVE).toFile(); - byte[] bytes = FileUtils.readFileToByteArray(file); - FileChunk fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(bytes)).build(); - - return BluePrintUploadInput.newBuilder() - .setCommonHeader(CommonHeader.newBuilder().setRequestId(UUID.randomUUID().toString()) - .setSubRequestId(UUID.randomUUID().toString()).setOriginatorId("SDC-LISTENER").build()) - .setActionIdentifiers( - ActionIdentifiers.newBuilder().setActionName(UploadAction.PUBLISH.toString()).build()) - .setFileChunk(fileChunk).build(); - } - - private BluePrintManagementOutput getBluePrintManagementOutput() { - return BluePrintManagementOutput.newBuilder() - .setStatus(Status.newBuilder().setMessage(SUCCESS_MSG).setCode(200).build()).build(); - } - -} diff --git a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/handler/BlueprintProcessorHandlerTest.java b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/handler/BlueprintProcessorHandlerTest.java new file mode 100644 index 000000000..b48a98e15 --- /dev/null +++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/handler/BlueprintProcessorHandlerTest.java @@ -0,0 +1,124 @@ +/* + * Copyright © 2019 Bell Canada + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.onap.ccsdk.cds.sdclistener.handler; + +import com.google.protobuf.ByteString; +import io.grpc.ManagedChannel; +import io.grpc.inprocess.InProcessChannelBuilder; +import io.grpc.inprocess.InProcessServerBuilder; +import io.grpc.stub.StreamObserver; +import io.grpc.testing.GrpcCleanupRule; +import org.apache.commons.io.FileUtils; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.ccsdk.cds.controllerblueprints.common.api.ActionIdentifiers; +import org.onap.ccsdk.cds.controllerblueprints.common.api.CommonHeader; +import org.onap.ccsdk.cds.controllerblueprints.common.api.Status; +import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintManagementOutput; +import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintManagementServiceGrpc.BlueprintManagementServiceImplBase; +import org.onap.ccsdk.cds.controllerblueprints.management.api.BlueprintUploadInput; +import org.onap.ccsdk.cds.controllerblueprints.management.api.FileChunk; +import org.onap.ccsdk.cds.controllerblueprints.management.api.UploadAction; +import org.onap.ccsdk.cds.sdclistener.client.SdcListenerAuthClientInterceptor; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Paths; +import java.util.UUID; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +@RunWith(SpringRunner.class) +@EnableConfigurationProperties({BlueprintProcesssorHandler.class, SdcListenerAuthClientInterceptor.class}) +@SpringBootTest(classes = {BlueprintProcessorHandlerTest.class}) +public class BlueprintProcessorHandlerTest { + + @Autowired + private BlueprintProcesssorHandler bluePrintProcesssorHandler; + + @Autowired + private SdcListenerAuthClientInterceptor sdcListenerAuthClientInterceptor; + + @Rule + public GrpcCleanupRule grpcCleanup = new GrpcCleanupRule(); + + private static final String CBA_ARCHIVE = "src/test/resources/testcba.zip"; + private static final String SUCCESS_MSG = "Successfully uploaded CBA"; + private static final int SUCCESS_CODE = 200; + private ManagedChannel channel; + + @Before + public void setUp() throws IOException { + final BlueprintManagementServiceImplBase serviceImplBase = new BlueprintManagementServiceImplBase() { + @Override + public void uploadBlueprint(BlueprintUploadInput request, + StreamObserver responseObserver) { + responseObserver.onNext(getBlueprintManagementOutput()); + responseObserver.onCompleted(); + } + }; + + // Generate server name. + String serverName = InProcessServerBuilder.generateName(); + + // Create a server, add service, start, and register. + grpcCleanup.register(InProcessServerBuilder.forName(serverName).addService(serviceImplBase).directExecutor() + .build().start()); + + // Create a client channel. + channel = grpcCleanup.register(InProcessChannelBuilder.forName(serverName).directExecutor().build()); + } + + @Test + public void testApplicationEndPointSucess() throws IOException { + // Arrange + BlueprintUploadInput request = generateRequest(); + + // Act + Status output = bluePrintProcesssorHandler.sendRequest(request, channel); + + // Verify + assertEquals(SUCCESS_CODE, output.getCode()); + assertTrue(output.getMessage().contains(SUCCESS_MSG)); + } + + private BlueprintUploadInput generateRequest() throws IOException { + File file = Paths.get(CBA_ARCHIVE).toFile(); + byte[] bytes = FileUtils.readFileToByteArray(file); + FileChunk fileChunk = FileChunk.newBuilder().setChunk(ByteString.copyFrom(bytes)).build(); + + return BlueprintUploadInput.newBuilder() + .setCommonHeader(CommonHeader.newBuilder().setRequestId(UUID.randomUUID().toString()) + .setSubRequestId(UUID.randomUUID().toString()).setOriginatorId("SDC-LISTENER").build()) + .setActionIdentifiers( + ActionIdentifiers.newBuilder().setActionName(UploadAction.PUBLISH.toString()).build()) + .setFileChunk(fileChunk).build(); + } + + private BlueprintManagementOutput getBlueprintManagementOutput() { + return BlueprintManagementOutput.newBuilder() + .setStatus(Status.newBuilder().setMessage(SUCCESS_MSG).setCode(200).build()).build(); + } + +} diff --git a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java index 4179ccab0..2e55c8e25 100644 --- a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java +++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java @@ -29,7 +29,7 @@ import org.mockito.junit.MockitoRule; import org.onap.ccsdk.cds.sdclistener.SdcListenerConfiguration; import org.onap.ccsdk.cds.sdclistener.client.SdcListenerAuthClientInterceptor; import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto; -import org.onap.ccsdk.cds.sdclistener.handler.BluePrintProcesssorHandler; +import org.onap.ccsdk.cds.sdclistener.handler.BlueprintProcesssorHandler; import org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus; import org.onap.sdc.api.results.IDistributionClientDownloadResult; import org.onap.sdc.impl.mock.DistributionClientResultStubImpl; @@ -50,7 +50,7 @@ import static org.onap.ccsdk.cds.sdclistener.status.SdcListenerStatus.Notificati import static org.onap.sdc.utils.DistributionStatusEnum.COMPONENT_DONE_OK; @RunWith(SpringRunner.class) -@EnableConfigurationProperties({SdcListenerAuthClientInterceptor.class, BluePrintProcesssorHandler.class, +@EnableConfigurationProperties({SdcListenerAuthClientInterceptor.class, BlueprintProcesssorHandler.class, SdcListenerDto.class, ListenerServiceImpl.class, SdcListenerStatus.class, SdcListenerConfiguration.class}) @SpringBootTest(classes = {ListenerServiceImplTest.class}) public class ListenerServiceImplTest { @@ -90,9 +90,9 @@ public class ListenerServiceImplTest { } @Test - public void extractBluePrintSuccessfully() throws IOException { + public void extractBlueprintSuccessfully() throws IOException { // Act - listenerService.extractBluePrint(CSAR_SAMPLE, tempDirectoryPath.toString()); + listenerService.extractBlueprint(CSAR_SAMPLE, tempDirectoryPath.toString()); // Verify. String result = checkFileExists(tempDirectoryPath); @@ -100,7 +100,7 @@ public class ListenerServiceImplTest { } @Test - public void extractBluePrintFailure() { + public void extractBlueprintFailure() { // Arrange Mockito.when(listenerDto.getDistributionId()).thenReturn(DISTRIBUTION_ID); Mockito.when(listenerDto.getArtifactUrl()).thenReturn(URL); @@ -108,7 +108,7 @@ public class ListenerServiceImplTest { SDC_LISTENER_COMPONENT); // Act - listenerService.extractBluePrint(WRONG_CSAR_SAMPLE, tempDirectoryPath.toString()); + listenerService.extractBlueprint(WRONG_CSAR_SAMPLE, tempDirectoryPath.toString()); // Verify Mockito.verify(status).sendResponseBackToSdc(DISTRIBUTION_ID, COMPONENT_DONE_OK, null, URL, -- cgit 1.2.3-korg