diff options
Diffstat (limited to 'src/test/java/org/onap')
4 files changed, 228 insertions, 24 deletions
diff --git a/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java b/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java index 1a1621271..3f0a078bb 100644 --- a/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java +++ b/src/test/java/org/onap/clamp/clds/config/sdc/SdcSingleControllerConfigurationTest.java @@ -1,15 +1,15 @@ /*- * ============LICENSE_START======================================================= - * ONAP - SO + * ONAP CLAMP * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. 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. @@ -24,14 +24,11 @@ package org.onap.clamp.clds.config.sdc; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; -import com.fasterxml.jackson.core.JsonParseException; -import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; @@ -46,19 +43,19 @@ import org.onap.clamp.clds.util.ResourceFileUtil; */ public class SdcSingleControllerConfigurationTest { - private SdcSingleControllerConfiguration loadControllerConfiguration(String fileName, String sdcControllerName) - throws IOException { + public static SdcSingleControllerConfiguration loadControllerConfiguration(String fileName, + String sdcControllerName) throws IOException { JsonNode jsonNode = new ObjectMapper().readValue(ResourceFileUtil.getResourceAsStream(fileName), - JsonNode.class); + JsonNode.class); SdcSingleControllerConfiguration sdcSingleControllerConfiguration = new SdcSingleControllerConfiguration( - jsonNode, sdcControllerName); + jsonNode, sdcControllerName); return sdcSingleControllerConfiguration; } @Test public final void testTheInit() throws SdcParametersException, IOException { SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json", - "sdc-controller1"); + "sdc-controller1"); assertEquals("User", sdcConfig.getUser()); assertEquals("ThePassword", sdcConfig.getPassword()); assertEquals("consumerGroup", sdcConfig.getConsumerGroup()); @@ -78,7 +75,7 @@ public class SdcSingleControllerConfigurationTest { @Test(expected = SdcParametersException.class) public final void testAllRequiredParameters() throws IOException { SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-TLS.json", - "sdc-controller1"); + "sdc-controller1"); // No exception should be raised sdcConfig.testAllRequiredParameters(); sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-bad.json", "sdc-controller1"); @@ -86,10 +83,9 @@ public class SdcSingleControllerConfigurationTest { } @Test - public final void testAllRequiredParametersEmptyEncrypted() - throws IOException { + public final void testAllRequiredParametersEmptyEncrypted() throws IOException { SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration( - "clds/sdc-controller-config-empty-encrypted.json", "sdc-controller1"); + "clds/sdc-controller-config-empty-encrypted.json", "sdc-controller1"); sdcConfig.testAllRequiredParameters(); assertNull(sdcConfig.getKeyStorePassword()); } @@ -97,7 +93,7 @@ public class SdcSingleControllerConfigurationTest { @Test public final void testConsumerGroupWithNull() throws IOException { SdcSingleControllerConfiguration sdcConfig = loadControllerConfiguration("clds/sdc-controller-config-NULL.json", - "sdc-controller1"); + "sdc-controller1"); assertTrue(sdcConfig.getConsumerGroup() == null); } } diff --git a/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java b/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java index 4b632488a..0cab4b9d3 100644 --- a/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java +++ b/src/test/java/org/onap/clamp/clds/it/config/SdcControllersConfigurationItCase.java @@ -1,15 +1,15 @@ /*- * ============LICENSE_START======================================================= - * ONAP - SO + * ONAP CLAMP * ================================================================================ * Copyright (C) 2017 AT&T Intellectual Property. 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. @@ -56,7 +56,7 @@ public class SdcControllersConfigurationItCase { public void testGetAllDefinedControllers() throws IOException { loadFile("classpath:/clds/sdc-controllers-config.json"); Map<String, SdcSingleControllerConfiguration> mapResult = sdcControllersConfiguration - .getAllDefinedControllers(); + .getAllDefinedControllers(); assertTrue(mapResult.size() == 2); assertEquals("sdc-controller1", mapResult.get("sdc-controller1").getSdcControllerName()); assertEquals("sdc-controller2", mapResult.get("sdc-controller2").getSdcControllerName()); @@ -65,10 +65,10 @@ public class SdcControllersConfigurationItCase { @Test public void testGetSdcSingleControllerConfiguration() throws IOException { loadFile("classpath:/clds/sdc-controllers-config.json"); - assertEquals("sdc-controller1", sdcControllersConfiguration - .getSdcSingleControllerConfiguration("sdc-controller1").getSdcControllerName()); - assertEquals("sdc-controller2", sdcControllersConfiguration - .getSdcSingleControllerConfiguration("sdc-controller2").getSdcControllerName()); + assertEquals("sdc-controller1", + sdcControllersConfiguration.getSdcSingleControllerConfiguration("sdc-controller1").getSdcControllerName()); + assertEquals("sdc-controller2", + sdcControllersConfiguration.getSdcSingleControllerConfiguration("sdc-controller2").getSdcControllerName()); } @Test(expected = IOException.class) 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 new file mode 100644 index 000000000..9eaca5f73 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/it/sdc/controller/SdcSingleControllerItCase.java @@ -0,0 +1,108 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. 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. + * ============LICENSE_END============================================ + * =================================================================== + * + */ + +package org.onap.clamp.clds.it.sdc.controller; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import org.assertj.core.api.Assertions; +import org.junit.Before; +import org.junit.Test; +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.sdc.controller.SdcSingleController; +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.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class SdcSingleControllerItCase { + + private static final String SDC_FOLDER = "/tmp/csar-handler-tests"; + private static final String CSAR_ARTIFACT_NAME = "testArtifact.csar"; + private static final String SERVICE_UUID = "serviceUUID"; + private static final String RESOURCE1_UUID = "resource1UUID"; + private static final String RESOURCE1_INSTANCE_NAME = "sim-1802 0"; + private static final String RESOURCE1_INSTANCE_NAME_IN_CSAR = "sim18020"; + private static final String BLUEPRINT1_NAME = "FOI.Simfoimap223S0112.event_proc_bp.yaml"; + + @Autowired + private ClampProperties clampProp; + + private SdcSingleController sdcSingleController; + + private INotificationData buildFakeSdcNotification() { + // BUild what is needed for CSAR + IArtifactInfo serviceArtifact = Mockito.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); + 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); + 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); + Mockito.when(blueprintArtifact.getArtifactType()).thenReturn(CsarHandler.BLUEPRINT_TYPE); + List<IArtifactInfo> artifactsListForResource = new ArrayList<>(); + artifactsListForResource.add(blueprintArtifact); + Mockito.when(resource1.getArtifacts()).thenReturn(artifactsListForResource); + List<IResourceInstance> resourcesList = new ArrayList<>(); + resourcesList.add(resource1); + Mockito.when(notifData.getResources()).thenReturn(resourcesList); + return notifData; + } + + @Before + public void init() throws IOException { + sdcSingleController = new SdcSingleController(clampProp, Mockito.mock(CsarInstaller.class), + SdcSingleControllerConfigurationTest.loadControllerConfiguration("clds/sdc-controller-config-TLS.json", + "sdc-controller1"), + null) { + }; + } + + @Test + public void testTreatNotification() { + sdcSingleController.treatNotification(buildFakeSdcNotification()); + Assertions.assertThat(sdcSingleController.getNbOfNotificationsOngoing()).isEqualTo(0); + + } + +} diff --git a/src/test/java/org/onap/clamp/clds/model/sdc/SdcResourceBasicInfoTest.java b/src/test/java/org/onap/clamp/clds/model/sdc/SdcResourceBasicInfoTest.java new file mode 100644 index 000000000..119fd2181 --- /dev/null +++ b/src/test/java/org/onap/clamp/clds/model/sdc/SdcResourceBasicInfoTest.java @@ -0,0 +1,100 @@ +/*- + * ============LICENSE_START======================================================= + * ONAP CLAMP + * ================================================================================ + * Copyright (C) 2018 AT&T Intellectual Property. 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. + * ============LICENSE_END========================================================= + * Modifications copyright (c) 2018 Nokia + * ================================================================================ + * + */ + +package org.onap.clamp.clds.model.sdc; + +import org.assertj.core.api.Assertions; +import org.junit.Test; + +public class SdcResourceBasicInfoTest { + + @Test + public void testHashCode() { + SdcResourceBasicInfo sdc1a = new SdcResourceBasicInfo(); + SdcResourceBasicInfo sdc1b = new SdcResourceBasicInfo(); + SdcResourceBasicInfo sdc2 = new SdcResourceBasicInfo(); + sdc1a.setName("test1"); + sdc1a.setVersion("1.0"); + sdc1b.setName("test1"); + sdc1b.setVersion("2.0"); + sdc2.setName("test2"); + sdc2.setVersion("2.0"); + + Assertions.assertThat(sdc1a.hashCode()).isNotEqualTo(sdc1b.hashCode()); + Assertions.assertThat(sdc1b.hashCode()).isNotEqualTo(sdc2.hashCode()); + sdc1b.setVersion("1.0"); + Assertions.assertThat(sdc1a.hashCode()).isEqualTo(sdc1b.hashCode()); + + } + + @Test + public void testCompareTo() { + SdcResourceBasicInfo sdc1a = new SdcResourceBasicInfo(); + SdcResourceBasicInfo sdc1b = new SdcResourceBasicInfo(); + SdcResourceBasicInfo sdc2 = new SdcResourceBasicInfo(); + sdc1a.setName("test1"); + sdc1a.setVersion("1.0"); + sdc1b.setName("test1"); + sdc1b.setVersion("2.0"); + sdc2.setName("test2"); + sdc2.setVersion("2.0"); + + Assertions.assertThat(sdc1a.compareTo(sdc1b)).isEqualTo(-1); + Assertions.assertThat(sdc1b.compareTo(sdc1a)).isEqualTo(1); + Assertions.assertThat(sdc1a.compareTo(sdc1a)).isEqualTo(0); + Assertions.assertThat(sdc1a.compareTo(sdc2)).isEqualTo(-1); + } + + @Test + public void testEquals() { + SdcResourceBasicInfo sdc1a = new SdcResourceBasicInfo(); + SdcResourceBasicInfo sdc1b = new SdcResourceBasicInfo(); + SdcResourceBasicInfo sdc2 = new SdcResourceBasicInfo(); + sdc1a.setName("test1"); + sdc1a.setVersion("1.0"); + sdc1b.setName("test1"); + sdc1b.setVersion("2.0"); + sdc2.setName("test2"); + sdc2.setVersion("2.0"); + + Assertions.assertThat(sdc1a.equals(sdc1a)).isTrue(); + Assertions.assertThat(sdc1a.equals(sdc1b)).isFalse(); + + sdc1b.setVersion(null); + Assertions.assertThat(sdc1a.equals(sdc1b)).isFalse(); + sdc1b.setVersion("1.0"); + Assertions.assertThat(sdc1a.equals(sdc1b)).isTrue(); + sdc1a.setVersion(null); + sdc1b.setVersion(null); + Assertions.assertThat(sdc1a.equals(sdc1b)).isTrue(); + + sdc1b.setName(null); + Assertions.assertThat(sdc1a.equals(sdc1b)).isFalse(); + sdc1b.setName("test1"); + Assertions.assertThat(sdc1a.equals(sdc1b)).isTrue(); + sdc1a.setName(null); + sdc1b.setName(null); + Assertions.assertThat(sdc1a.equals(sdc1b)).isTrue(); + } + +} |