diff options
author | Edyta Krukowska <edyta.krukowska@nokia.com> | 2020-12-23 11:50:55 +0100 |
---|---|---|
committer | Edyta Krukowska <edyta.krukowska@nokia.com> | 2020-12-28 08:48:30 +0100 |
commit | 2ca084cf51507724d771c15bb57997af35cbed75 (patch) | |
tree | 3d235590f35867d6e53afc35ef07e3a4ce415f86 | |
parent | 92611f550d49db759f6b5cdc98ca75274c446c61 (diff) |
Create IT for unregister from topic
Issue-ID: SDC-3417
Signed-off-by: Edyta Krukowska <edyta.krukowska@nokia.com>
Change-Id: I626fd71304a8a1eb3451bca51cb1077d0b2ac773
3 files changed, 48 insertions, 10 deletions
diff --git a/sdc-distribution-ci/src/main/java/org/onap/test/core/service/ClientInitializer.java b/sdc-distribution-ci/src/main/java/org/onap/test/core/service/ClientInitializer.java index 64e6a6f..72b47d7 100644 --- a/sdc-distribution-ci/src/main/java/org/onap/test/core/service/ClientInitializer.java +++ b/sdc-distribution-ci/src/main/java/org/onap/test/core/service/ClientInitializer.java @@ -50,4 +50,11 @@ public class ClientInitializer { log.info(SEPARATOR); } + public void stop() { + IDistributionClientResult stopResult = client.stop(); + log.info(SEPARATOR); + log.info(stopResult.getDistributionMessageResult()); + log.info(SEPARATOR); + } + } diff --git a/sdc-distribution-ci/src/test/java/org/onap/test/core/service/ClientInitializerTest.java b/sdc-distribution-ci/src/test/java/org/onap/test/core/service/ClientInitializerTest.java index e4c2241..40278b1 100644 --- a/sdc-distribution-ci/src/test/java/org/onap/test/core/service/ClientInitializerTest.java +++ b/sdc-distribution-ci/src/test/java/org/onap/test/core/service/ClientInitializerTest.java @@ -19,6 +19,7 @@ */ package org.onap.test.core.service; +import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; @@ -42,28 +43,37 @@ import static org.mockito.Mockito.verify; @ExtendWith(MockitoExtension.class) class ClientInitializerTest { + private static final int SUCCESSFUL_STOP_MSG_INDEX = 2; + private static final int SUCCESSFUL_UNREGISTER_MSG_INDEX = 3; + private static final int SUCCESSFUL_INIT_MSG_INDEX = 0; + private static final int SUCCESSFUL_DIST_MSG_INDEX = 3; + private ClientInitializer clientInitializer; - public static final int SUCCESSFUL_INIT_MSG_INDEX = 0; - public static final int SUCCESSFUL_DIST_MSG_INDEX = 3; @Container public GenericContainer mockDmaap = new GenericContainer("registry.gitlab.com/orange-opensource/lfn/onap/mock_servers/mock-dmaap:latest") .withNetworkMode("host"); @Container public GenericContainer mockSdc = new GenericContainer("registry.gitlab.com/orange-opensource/lfn/onap/mock_servers/mock-sdc:latest") - .dependsOn(mockDmaap) .withNetworkMode("host"); @Mock Logger log; - @Test - public void shouldRegisterToDmaapAfterClientInitialization() { - //given + @Mock + Logger distClientLog; + + @BeforeEach + public void initializeClient() { DistributionClientConfig clientConfig = new DistributionClientConfig(); List<ArtifactsValidator> validators = new ArrayList<>(); - DistributionClientImpl client = new DistributionClientImpl(); + DistributionClientImpl client = new DistributionClientImpl(distClientLog); ClientNotifyCallback callback = new ClientNotifyCallback(validators, client); - ClientInitializer clientInitializer = new ClientInitializer(clientConfig, callback, client); + clientInitializer = new ClientInitializer(clientConfig, callback, client); + } + + @Test + public void shouldRegisterToDmaapAfterClientInitialization() { + //given final ArgumentCaptor<String> exceptionCaptor = ArgumentCaptor.forClass(String.class); //when clientInitializer.log = log; @@ -75,4 +85,17 @@ class ClientInitializerTest { assertThat(allValues.get(SUCCESSFUL_DIST_MSG_INDEX)).isEqualTo("distribution client started successfuly"); } + @Test + public void shouldUnregisterAndStopClient() { + //given + final ArgumentCaptor<String> exceptionCaptor = ArgumentCaptor.forClass(String.class); + //when + clientInitializer.initialize(); + clientInitializer.stop(); + verify(distClientLog, Mockito.atLeastOnce()).info(exceptionCaptor.capture()); + List<String> allValues = exceptionCaptor.getAllValues(); + //then + assertThat(allValues.get(SUCCESSFUL_STOP_MSG_INDEX)).isEqualTo("stop DistributionClient"); + assertThat(allValues.get(SUCCESSFUL_UNREGISTER_MSG_INDEX)).isEqualTo("client unregistered from topics successfully"); + } }
\ No newline at end of file diff --git a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientImpl.java b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientImpl.java index 6e32b96..b719432 100644 --- a/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientImpl.java +++ b/sdc-distribution-client/src/main/java/org/onap/sdc/impl/DistributionClientImpl.java @@ -80,7 +80,7 @@ public class DistributionClientImpl implements IDistributionClient { private static final int POLLING_TIMEOUT_MULTIPLIER = 1000; private static final int TERMINATION_TIMEOUT = 60; - private static final Logger log = LoggerFactory.getLogger(DistributionClientImpl.class); + private final Logger log; private SdcConnectorClient asdcConnector; private ScheduledExecutorService executorPool = null; @@ -100,6 +100,14 @@ public class DistributionClientImpl implements IDistributionClient { private boolean isStarted; private boolean isTerminated; + public DistributionClientImpl() { + this(LoggerFactory.getLogger(DistributionClientImpl.class)); + } + + public DistributionClientImpl(Logger log) { + this.log = log; + } + @Override public IConfiguration getConfiguration() { return configuration; @@ -493,7 +501,7 @@ public class DistributionClientImpl implements IDistributionClient { DistributionActionResultEnum result = configurationValidator.validateConfiguration(conf, statusCallback); Configuration configuration = null; - if(result == DistributionActionResultEnum.SUCCESS) { + if (result == DistributionActionResultEnum.SUCCESS) { configuration = createConfiguration(conf); } else { DistributionClientResultImpl initResult = new DistributionClientResultImpl(result, "configuration is invalid: " + result.name()); |