diff options
Diffstat (limited to 'plugins/reception-plugins/src/test/java')
3 files changed, 160 insertions, 2 deletions
diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestComponentDoneStatusMessage.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestComponentDoneStatusMessage.java new file mode 100644 index 00000000..75e32243 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestComponentDoneStatusMessage.java @@ -0,0 +1,61 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.sdc.utils.DistributionStatusEnum; + +public class TestComponentDoneStatusMessage { + + @Test + public void testComponentDoneStatusMessage_Success() { + final String consumerId = "dummyId"; + final String distributionId = "dummyDistribution"; + final long timestamp = System.currentTimeMillis(); + final ComponentDoneStatusMessageBuilder messageBuilder = + new ComponentDoneStatusMessageBuilder().setConsumerId(consumerId).setDistributionId(distributionId) + .setDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_OK).setTimestamp(timestamp); + final ComponentDoneStatusMessage message = new ComponentDoneStatusMessage(messageBuilder); + assertEquals("POLICY", message.getComponentName()); + assertEquals(consumerId, message.getConsumerID()); + assertEquals(distributionId, message.getDistributionID()); + assertEquals(DistributionStatusEnum.COMPONENT_DONE_OK, message.getStatus()); + assertEquals(timestamp, message.getTimestamp()); + } + + @Test + public void testComponentDoneStatusMessage_Failure() { + final String consumerId = "dummyId"; + final String distributionId = "dummyDistribution"; + final long timestamp = System.currentTimeMillis(); + final ComponentDoneStatusMessageBuilder messageBuilder = + new ComponentDoneStatusMessageBuilder().setConsumerId(consumerId).setDistributionId(distributionId) + .setDistributionStatus(DistributionStatusEnum.COMPONENT_DONE_ERROR).setTimestamp(timestamp); + final ComponentDoneStatusMessage message = new ComponentDoneStatusMessage(messageBuilder); + assertEquals("POLICY", message.getComponentName()); + assertEquals(consumerId, message.getConsumerID()); + assertEquals(distributionId, message.getDistributionID()); + assertEquals(DistributionStatusEnum.COMPONENT_DONE_ERROR, message.getStatus()); + assertEquals(timestamp, message.getTimestamp()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestDistributionStatusMessage.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestDistributionStatusMessage.java new file mode 100644 index 00000000..be127776 --- /dev/null +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestDistributionStatusMessage.java @@ -0,0 +1,65 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2018 Intel. All rights reserved. + * ================================================================================ + * 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. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.policy.distribution.reception.handling.sdc; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; +import org.onap.sdc.utils.DistributionStatusEnum; + +public class TestDistributionStatusMessage { + + @Test + public void testDistributionStatusMessage_Download() { + final String artifactUrl = "http://dummyurl"; + final String consumerId = "dummyId"; + final String distributionId = "dummyDistribution"; + final long timestamp = System.currentTimeMillis(); + + final DistributionStatusMessageBuilder messageBuilder = new DistributionStatusMessageBuilder() + .setArtifactUrl(artifactUrl).setConsumerId(consumerId).setDistributionId(distributionId) + .setDistributionStatus(DistributionStatusEnum.DOWNLOAD_OK).setTimestamp(timestamp); + final DistributionStatusMessage message = new DistributionStatusMessage(messageBuilder); + assertEquals(artifactUrl, message.getArtifactURL()); + assertEquals(consumerId, message.getConsumerID()); + assertEquals(distributionId, message.getDistributionID()); + assertEquals(DistributionStatusEnum.DOWNLOAD_OK, message.getStatus()); + assertEquals(timestamp, message.getTimestamp()); + } + + @Test + public void testDistributionStatusMessage_Deploy() { + final String artifactUrl = "http://dummyurl"; + final String consumerId = "dummyId"; + final String distributionId = "dummyDistribution"; + final long timestamp = System.currentTimeMillis(); + + final DistributionStatusMessageBuilder messageBuilder = new DistributionStatusMessageBuilder() + .setArtifactUrl(artifactUrl).setConsumerId(consumerId).setDistributionId(distributionId) + .setDistributionStatus(DistributionStatusEnum.DEPLOY_OK).setTimestamp(timestamp); + final DistributionStatusMessage message = new DistributionStatusMessage(messageBuilder); + assertEquals(artifactUrl, message.getArtifactURL()); + assertEquals(consumerId, message.getConsumerID()); + assertEquals(distributionId, message.getDistributionID()); + assertEquals(DistributionStatusEnum.DEPLOY_OK, message.getStatus()); + assertEquals(timestamp, message.getTimestamp()); + } +} diff --git a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java index a648f807..c4020a41 100644 --- a/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java +++ b/plugins/reception-plugins/src/test/java/org/onap/policy/distribution/reception/handling/sdc/TestSdcReceptionHandler.java @@ -110,6 +110,12 @@ public class TestSdcReceptionHandler { Mockito.when(distributionClient.init(any(), any())).thenReturn(successfulClientInitResult); Mockito.when(distributionClient.start()).thenReturn(successfulClientInitResult); Mockito.when(distributionClient.stop()).thenReturn(successfulClientInitResult); + Mockito.when(distributionClient.sendComponentDoneStatus(any())).thenReturn(successfulClientInitResult); + Mockito.when(distributionClient.sendComponentDoneStatus(any(), any())).thenReturn(successfulClientInitResult); + Mockito.when(distributionClient.sendDownloadStatus(any())).thenReturn(successfulClientInitResult); + Mockito.when(distributionClient.sendDownloadStatus(any(), any())).thenReturn(successfulClientInitResult); + Mockito.when(distributionClient.sendDeploymentStatus(any())).thenReturn(successfulClientInitResult); + Mockito.when(distributionClient.sendDeploymentStatus(any(), any())).thenReturn(successfulClientInitResult); Mockito.when(distributionClient.download(any())).thenReturn(successfulClientDownloadResult); Mockito.when(notificationData.getServiceArtifacts()).thenReturn(Arrays.asList(artifactInfo)); Mockito.when(artifactInfo.getArtifactName()).thenReturn(DUMMY_SERVICE_CSAR); @@ -118,6 +124,8 @@ public class TestSdcReceptionHandler { .thenReturn(DistributionActionResultEnum.SUCCESS); Mockito.when(successfulClientDownloadResult.getDistributionActionResult()) .thenReturn(DistributionActionResultEnum.SUCCESS); + Mockito.when(failureClientInitResult.getDistributionActionResult()) + .thenReturn(DistributionActionResultEnum.FAIL); } @@ -164,8 +172,6 @@ public class TestSdcReceptionHandler { public final void testStartSdcClient_Failure() throws PluginInitializationException { try { Mockito.when(distributionClient.start()).thenReturn(failureClientInitResult); - Mockito.when(failureClientInitResult.getDistributionActionResult()) - .thenReturn(DistributionActionResultEnum.FAIL); sypHandler.initializeReception(pssdConfigParameters.getName()); fail("Test must throw an exception here"); @@ -256,6 +262,32 @@ public class TestSdcReceptionHandler { assertEquals(0, policyForwarder.getNumberOfPoliciesReceived()); } + @Test + public void testSendDistributionStatusFailure() throws NoSuchFieldException, SecurityException, + IllegalArgumentException, IllegalAccessException, PluginInitializationException { + + Mockito.when(successfulClientDownloadResult.getDistributionActionResult()) + .thenReturn(DistributionActionResultEnum.FAIL); + Mockito.when(distributionClient.sendDownloadStatus(any(), any())).thenReturn(failureClientInitResult); + Mockito.when(distributionClient.sendDeploymentStatus(any(), any())).thenReturn(failureClientInitResult); + Mockito.when(distributionClient.sendComponentDoneStatus(any(), any())).thenReturn(failureClientInitResult); + + final DummyDecoder policyDecoder = new DummyDecoder(); + final Collection<PolicyDecoder<Csar, DummyPolicy>> policyDecoders = new ArrayList<>(); + policyDecoders.add(policyDecoder); + + final DummyPolicyForwarder policyForwarder = new DummyPolicyForwarder(); + final Collection<PolicyForwarder> policyForwarders = new ArrayList<>(); + policyForwarders.add(policyForwarder); + + setUpPlugins(sypHandler, policyDecoders, policyForwarders); + sypHandler.initializeReception(pssdConfigParameters.getName()); + sypHandler.activateCallback(notificationData); + + assertEquals(null, policyDecoder.getDecodedPolicy()); + assertEquals(0, policyForwarder.getNumberOfPoliciesReceived()); + } + private void setUpPlugins(final AbstractReceptionHandler receptionHandler, final Collection<PolicyDecoder<Csar, DummyPolicy>> decoders, final Collection<PolicyForwarder> forwarders) throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException, |