summaryrefslogtreecommitdiffstats
path: root/ms/cds-sdc-listener/application/src/test/java/org
diff options
context:
space:
mode:
authorOleg Mitsura <oleg.mitsura@amdocs.com>2019-04-22 17:47:33 -0400
committerOleg Mitsura <oleg.mitsura@amdocs.com>2019-04-23 11:07:55 -0400
commitd5339481d3c3f24dd5faccb44dccd4addfd58499 (patch)
treedacae59a21608341fcce9cc0060399b15d487f47 /ms/cds-sdc-listener/application/src/test/java/org
parentf332e6ecd2c0a9f26451f977c941f03ed8ab84dc (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/cds-sdc-listener/application/src/test/java/org')
-rw-r--r--ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerClientTest.java80
-rw-r--r--ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfigurationTest.java48
-rw-r--r--ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcessorHandlerTest.java112
-rw-r--r--ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImplTest.java126
4 files changed, 0 insertions, 366 deletions
diff --git a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerClientTest.java b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerClientTest.java
deleted file mode 100644
index e980c24c6..000000000
--- a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerClientTest.java
+++ /dev/null
@@ -1,80 +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.cdssdclistener;
-
-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.cdssdclistener.client.CdsSdcListenerClient;
-import org.onap.ccsdk.cds.cdssdclistener.dto.CdsSdcListenerDto;
-import org.onap.ccsdk.cds.cdssdclistener.exceptions.CdsSdcListenerException;
-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 CdsSdcListenerClientTest {
-
- @Tested
- private CdsSdcListenerClient cdsSdcListenerClient;
-
- @Test
- public void testInitCdsClientSuccesfully(@Injectable IDistributionClient distributionClient,
- @Injectable CdsSdcListenerConfiguration configuration,
- @Injectable CdsSdcListenerNotificationCallback notification,
- @Injectable CdsSdcListenerDto cdsSdcListenerDto) throws CdsSdcListenerException {
-
- //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
- cdsSdcListenerClient.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/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfigurationTest.java b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfigurationTest.java
deleted file mode 100644
index f940db2aa..000000000
--- a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/CdsSdcListenerConfigurationTest.java
+++ /dev/null
@@ -1,48 +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.cdssdclistener;
-
-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(CdsSdcListenerConfiguration.class)
-@SpringBootTest(classes = {CdsSdcListenerConfigurationTest.class})
-public class CdsSdcListenerConfigurationTest {
-
- @Autowired
- private CdsSdcListenerConfiguration 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/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcessorHandlerTest.java b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcessorHandlerTest.java
deleted file mode 100644
index f700a7dd2..000000000
--- a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/handler/BluePrintProcessorHandlerTest.java
+++ /dev/null
@@ -1,112 +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.cdssdclistener.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.cdssdclistener.client.CdsSdcListenerAuthClientInterceptor;
-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, CdsSdcListenerAuthClientInterceptor.class})
-@SpringBootTest(classes = {BluePrintProcessorHandlerTest.class})
-public class BluePrintProcessorHandlerTest {
-
- @Autowired
- private BluePrintProcesssorHandler bluePrintProcesssorHandler;
-
- @Autowired
- private CdsSdcListenerAuthClientInterceptor cdsSdcListenerAuthClientInterceptor;
-
- @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/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImplTest.java b/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImplTest.java
deleted file mode 100644
index 359ee6cc4..000000000
--- a/ms/cds-sdc-listener/application/src/test/java/org/onap/ccsdk/cds/cdssdclistener/service/ListenerServiceImplTest.java
+++ /dev/null
@@ -1,126 +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.cdssdclistener.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.cdssdclistener.CdsSdcListenerConfiguration;
-import org.onap.ccsdk.cds.cdssdclistener.client.CdsSdcListenerAuthClientInterceptor;
-import org.onap.ccsdk.cds.cdssdclistener.dto.CdsSdcListenerDto;
-import org.onap.ccsdk.cds.cdssdclistener.handler.BluePrintProcesssorHandler;
-import org.onap.ccsdk.cds.cdssdclistener.status.CdsSdcListenerStatus;
-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({CdsSdcListenerAuthClientInterceptor.class,
- BluePrintProcesssorHandler.class, CdsSdcListenerDto.class, ListenerServiceImpl.class, CdsSdcListenerStatus.class,
- CdsSdcListenerConfiguration.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";
- }
- }
-}