aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap
diff options
context:
space:
mode:
authorm.kowalski3 <m.kowalski3@partner.samsung.com>2019-05-15 09:29:31 +0200
committerm.kowalski3 <m.kowalski3@partner.samsung.com>2019-05-15 15:37:35 +0200
commit3ec05a1093e6399c8e732cecfa1dfd5c50a8cb09 (patch)
treed5251ef608ecfae7f5d099d056803ec4b183075d /src/test/java/org/onap
parentb38821c4136369ef50680b24c55d76ec3898af54 (diff)
Improve test coverage in SdcSingleController
Change-Id: Ibbdbf890aef92f5fb3a37bc75a502591d6134147 Issue-ID: CLAMP-355 Signed-off-by: Marcin Kowalski <m.kowalski3@partner.samsung.com>
Diffstat (limited to 'src/test/java/org/onap')
-rw-r--r--src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java51
1 files changed, 45 insertions, 6 deletions
diff --git a/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java b/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java
index 55657c974..0f0ecaedc 100644
--- a/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java
+++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java
@@ -5,6 +5,8 @@
* Copyright (C) 2018 AT&T Intellectual Property. All rights
* reserved.
* ================================================================================
+ * Modifications Copyright (c) 2019 Samsung
+ * ================================================================================
* 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
@@ -23,9 +25,13 @@
package org.onap.clamp.clds.it.sdc.controller;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.mockito.Mockito.mock;
+import java.lang.reflect.Constructor;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
-
import org.assertj.core.api.Assertions;
import org.junit.Before;
import org.junit.Test;
@@ -33,12 +39,16 @@ import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.onap.clamp.clds.config.ClampProperties;
import org.onap.clamp.clds.config.sdc.SdcSingleControllerConfigurationTest;
+import org.onap.clamp.clds.exception.sdc.controller.SdcControllerException;
import org.onap.clamp.clds.sdc.controller.SdcSingleController;
+import org.onap.clamp.clds.sdc.controller.SdcSingleControllerStatus;
import org.onap.clamp.clds.sdc.controller.installer.CsarHandler;
import org.onap.clamp.clds.sdc.controller.installer.CsarInstaller;
import org.onap.sdc.api.notification.IArtifactInfo;
import org.onap.sdc.api.notification.INotificationData;
import org.onap.sdc.api.notification.IResourceInstance;
+import org.slf4j.MDC;
+import org.slf4j.spi.MDCAdapter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
@@ -59,24 +69,26 @@ public class SdcSingleControllerItCase {
private SdcSingleController sdcSingleController;
+ private CsarInstaller csarInstaller = mock(CsarInstaller.class);
+
private INotificationData buildFakeSdcNotification() {
// BUild what is needed for CSAR
- IArtifactInfo serviceArtifact = Mockito.mock(IArtifactInfo.class);
+ IArtifactInfo serviceArtifact = mock(IArtifactInfo.class);
Mockito.when(serviceArtifact.getArtifactType()).thenReturn(CsarHandler.CSAR_TYPE);
Mockito.when(serviceArtifact.getArtifactName()).thenReturn(CSAR_ARTIFACT_NAME);
List<IArtifactInfo> servicesList = new ArrayList<>();
servicesList.add(serviceArtifact);
- INotificationData notifData = Mockito.mock(INotificationData.class);
+ INotificationData notifData = mock(INotificationData.class);
Mockito.when(notifData.getServiceArtifacts()).thenReturn(servicesList);
// Build what is needed for UUID
Mockito.when(notifData.getServiceInvariantUUID()).thenReturn(SERVICE_UUID);
// Build fake resource with one artifact BLUEPRINT
- IResourceInstance resource1 = Mockito.mock(IResourceInstance.class);
+ IResourceInstance resource1 = mock(IResourceInstance.class);
Mockito.when(resource1.getResourceType()).thenReturn("VF");
Mockito.when(resource1.getResourceInvariantUUID()).thenReturn(RESOURCE1_UUID);
Mockito.when(resource1.getResourceInstanceName()).thenReturn(RESOURCE1_INSTANCE_NAME);
// Create a fake artifact for resource
- IArtifactInfo blueprintArtifact = Mockito.mock(IArtifactInfo.class);
+ IArtifactInfo blueprintArtifact = mock(IArtifactInfo.class);
Mockito.when(blueprintArtifact.getArtifactType()).thenReturn(CsarHandler.BLUEPRINT_TYPE);
List<IArtifactInfo> artifactsListForResource = new ArrayList<>();
artifactsListForResource.add(blueprintArtifact);
@@ -92,7 +104,7 @@ public class SdcSingleControllerItCase {
*/
@Before
public void init() {
- sdcSingleController = new SdcSingleController(clampProp, Mockito.mock(CsarInstaller.class),
+ sdcSingleController = new SdcSingleController(clampProp, csarInstaller,
SdcSingleControllerConfigurationTest.loadControllerConfiguration("clds/sdc-controller-config-TLS.json",
"sdc-controller1"),
null) {
@@ -101,9 +113,36 @@ public class SdcSingleControllerItCase {
@Test
public void testTreatNotification() {
+ //when
sdcSingleController.treatNotification(buildFakeSdcNotification());
+ //then
Assertions.assertThat(sdcSingleController.getNbOfNotificationsOngoing()).isEqualTo(0);
+ }
+ @Test
+ public void testCloseSdc() throws SdcControllerException {
+ //when
+ sdcSingleController.closeSdc();
+ //then
+ assertThat(sdcSingleController.getControllerStatus()).isEqualTo(SdcSingleControllerStatus.STOPPED);
}
+ @Test
+ public void testActivateCallback() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException, InstantiationException, ClassNotFoundException {
+ //given
+ MDCAdapter mdcAdapter = MDC.getMDCAdapter();
+ Class<?> innerClass = Class.forName("org.onap.clamp.clds.sdc.controller.SdcSingleController$SdcNotificationCallBack");
+ Constructor<?> constructor = innerClass.getDeclaredConstructor(SdcSingleController.class, SdcSingleController.class);
+ constructor.setAccessible(true);
+ Object child = constructor.newInstance(sdcSingleController,sdcSingleController);
+ Method method = child.getClass().getDeclaredMethod("activateCallback",INotificationData.class);
+ method.setAccessible(true);
+ //when
+ method.invoke(child,buildFakeSdcNotification());
+ //then
+ assertThat(mdcAdapter.get("ResponseCode")).isEqualTo("0");
+ assertThat(mdcAdapter.get("StatusCode")).isEqualTo("COMPLETE");
+ assertThat(mdcAdapter.get("ResponseDescription")).isEqualTo("SDC Notification received and processed successfully");
+ assertThat(mdcAdapter.get("ClassName")).isEqualTo(child.getClass().getName());
+ }
}