diff options
author | Oleg Mitsura <oleg.mitsura@amdocs.com> | 2019-04-22 17:47:33 -0400 |
---|---|---|
committer | Oleg Mitsura <oleg.mitsura@amdocs.com> | 2019-04-23 11:07:55 -0400 |
commit | d5339481d3c3f24dd5faccb44dccd4addfd58499 (patch) | |
tree | dacae59a21608341fcce9cc0060399b15d487f47 /ms/sdclistener/application/src/test | |
parent | f332e6ecd2c0a9f26451f977c941f03ed8ab84dc (diff) |
SDC Listner Docker touchup
1.Reworked Dockerization of SDC Listener to follow
application/distribution+parent style;
2.Renamed CDS-SDClistener to just SDCListener
Issue-ID: CCSDK-1145
Change-Id: I007373d3a48fb8eb7042150bdbb37fc7fec346b3
Signed-off-by: Oleg Mitsura <oleg.mitsura@amdocs.com>
Diffstat (limited to 'ms/sdclistener/application/src/test')
6 files changed, 366 insertions, 0 deletions
diff --git a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerClientTest.java b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerClientTest.java new file mode 100644 index 000000000..c9f2c5a39 --- /dev/null +++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerClientTest.java @@ -0,0 +1,80 @@ +/* + * 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; + +import mockit.Expectations; +import mockit.Injectable; +import mockit.Mock; +import mockit.MockUp; +import mockit.Tested; +import mockit.VerificationsInOrder; +import mockit.integration.junit4.JMockit; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.onap.ccsdk.cds.sdclistener.client.SdcListenerClient; +import org.onap.ccsdk.cds.sdclistener.dto.SdcListenerDto; +import org.onap.ccsdk.cds.sdclistener.exceptions.SdcListenerException; +import org.onap.sdc.api.IDistributionClient; +import org.onap.sdc.api.results.IDistributionClientResult; +import org.onap.sdc.impl.DistributionClientFactory; +import org.onap.sdc.impl.DistributionClientResultImpl; +import org.onap.sdc.utils.DistributionActionResultEnum; + +@RunWith(JMockit.class) +public class SdcListenerClientTest { + + @Tested + private SdcListenerClient sdcListenerClient; + + @Test + public void testInitCdsClientSuccesfully(@Injectable IDistributionClient distributionClient, + @Injectable SdcListenerConfiguration configuration, + @Injectable SdcListenerNotificationCallback notification, + @Injectable SdcListenerDto sdcListenerDto) throws SdcListenerException { + + //Arrange + new MockUp<DistributionClientFactory>() { + @Mock + public IDistributionClient createDistributionClient() { + return distributionClient; + } + }; + + new Expectations() {{ + distributionClient.init(configuration, notification); + result = getResult(); + }}; + + new Expectations() {{ + distributionClient.start(); + result = getResult(); + }}; + + // Act + sdcListenerClient.initSdcClient(); + + // Verify + new VerificationsInOrder() {{ + distributionClient.init(configuration, notification); + distributionClient.start(); + }}; + } + + public IDistributionClientResult getResult() { + return new DistributionClientResultImpl(DistributionActionResultEnum.SUCCESS, + DistributionActionResultEnum.SUCCESS.name()); + } +} diff --git a/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerConfigurationTest.java b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerConfigurationTest.java new file mode 100644 index 000000000..01ffe1ba9 --- /dev/null +++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/SdcListenerConfigurationTest.java @@ -0,0 +1,48 @@ +/* + * 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; + +import static org.junit.Assert.assertEquals; +import org.junit.Test; +import org.junit.runner.RunWith; +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; + +@RunWith(SpringRunner.class) +@EnableConfigurationProperties(SdcListenerConfiguration.class) +@SpringBootTest(classes = {SdcListenerConfigurationTest.class}) +public class SdcListenerConfigurationTest { + + @Autowired + private SdcListenerConfiguration listenerConfiguration; + + @Test + public void testCdsSdcListenerConfiguration() { + assertEquals(listenerConfiguration.getAsdcAddress(), "localhost:8443"); + assertEquals(listenerConfiguration.getMsgBusAddress().stream().findFirst().get(), "localhost"); + assertEquals(listenerConfiguration.getUser(), "vid"); + assertEquals(listenerConfiguration.getPassword(), "Kp8bJ4SXszM0WXlhak3eHlcse2gAw84vaoGGmJvUy2U"); + assertEquals(listenerConfiguration.getPollingInterval(), 15); + assertEquals(listenerConfiguration.getPollingTimeout(), 60); + assertEquals(listenerConfiguration.getRelevantArtifactTypes().stream().findFirst().get(), "TOSCA_CSAR"); + assertEquals(listenerConfiguration.getConsumerGroup(), "cds-id-local"); + assertEquals(listenerConfiguration.getEnvironmentName(), "AUTO"); + assertEquals(listenerConfiguration.getConsumerID(), "cds-id-local"); + assertEquals(listenerConfiguration.activateServerTLSAuth(), false); + } +} 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..ee20f8771 --- /dev/null +++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/handler/BluePrintProcessorHandlerTest.java @@ -0,0 +1,112 @@ +/* + * 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +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 java.io.File; +import java.io.IOException; +import java.nio.file.Paths; +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.sdclistener.client.SdcListenerAuthClientInterceptor; +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.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; + +@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<BluePrintManagementOutput> 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().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 new file mode 100644 index 000000000..f5ff2bdb8 --- /dev/null +++ b/ms/sdclistener/application/src/test/java/org/onap/ccsdk/cds/sdclistener/service/ListenerServiceImplTest.java @@ -0,0 +1,126 @@ +/* + * 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.service; + +import static junit.framework.TestCase.assertTrue; +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import org.apache.commons.io.FileUtils; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.TemporaryFolder; +import org.junit.runner.RunWith; +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.status.SdcListenerStatus; +import org.onap.sdc.api.results.IDistributionClientDownloadResult; +import org.onap.sdc.impl.mock.DistributionClientResultStubImpl; +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; + +@RunWith(SpringRunner.class) +@EnableConfigurationProperties({SdcListenerAuthClientInterceptor.class, + BluePrintProcesssorHandler.class, SdcListenerDto.class, ListenerServiceImpl.class, SdcListenerStatus.class, + SdcListenerConfiguration.class}) +@SpringBootTest(classes = {ListenerServiceImplTest.class}) +public class ListenerServiceImplTest { + + private static final String CSAR_SAMPLE = "src/test/resources/service-Testsvc140.csar"; + private static final String ZIP_FILE = ".zip"; + private static final String CSAR_FILE = ".csar"; + private String csarArchivePath; + private Path tempDirectoryPath; + + @Rule + public TemporaryFolder folder = new TemporaryFolder(); + + @Autowired + private ListenerServiceImpl listenerService; + + @Before + public void setup() { + csarArchivePath = folder.getRoot().toString(); + tempDirectoryPath = Paths.get(csarArchivePath, "cds-sdc-listener-test"); + } + @Test + public void extractBluePrintSuccessfully() throws IOException { + // Act + listenerService.extractBluePrint(CSAR_SAMPLE, tempDirectoryPath.toString()); + + // Verify + String result = checkFileExists(tempDirectoryPath); + assertTrue(result.contains(ZIP_FILE)); + } + + @Test + public void storeCsarArtifactToFileSuccessfully() throws IOException { + // Arrange + DistributionClientDownloadResultStubImpl resultStub = new DistributionClientDownloadResultStubImpl(); + + // Act + listenerService.extractCsarAndStore(resultStub, tempDirectoryPath.toString()); + + // Verify + String result = checkFileExists(tempDirectoryPath); + assertTrue(result.contains(CSAR_FILE)); + } + + private String checkFileExists(Path path) throws IOException { + return Files.walk(path) + .filter(Files::isRegularFile) + .map(Path::toFile) + .findAny() + .get() + .getName(); + } + + public byte[] convertFileToByteArray(File file) { + try { + return FileUtils.readFileToByteArray(file); + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public class DistributionClientDownloadResultStubImpl extends DistributionClientResultStubImpl implements + IDistributionClientDownloadResult { + + public DistributionClientDownloadResultStubImpl() { + } + + public byte[] getArtifactPayload() { + File file = Paths.get(CSAR_SAMPLE).toFile(); + return convertFileToByteArray(file); + } + + public String getArtifactName() { + return "MackArtifactName"; + } + + public String getArtifactFilename() { + return "MackArtifactName.csar"; + } + } +} diff --git a/ms/sdclistener/application/src/test/resources/service-Testsvc140.csar b/ms/sdclistener/application/src/test/resources/service-Testsvc140.csar Binary files differnew file mode 100644 index 000000000..4aa0de72b --- /dev/null +++ b/ms/sdclistener/application/src/test/resources/service-Testsvc140.csar diff --git a/ms/sdclistener/application/src/test/resources/testcba.zip b/ms/sdclistener/application/src/test/resources/testcba.zip Binary files differnew file mode 100644 index 000000000..c886fe6bc --- /dev/null +++ b/ms/sdclistener/application/src/test/resources/testcba.zip |