From 327b17ab250b4c17cf3f91f5e4cd9bffd89f3d1e Mon Sep 17 00:00:00 2001 From: Marcus G K Williams Date: Wed, 7 Mar 2018 18:17:22 -0800 Subject: Reduce log noise/warnings format to conventions Reduce build log warnings by formatting tests to ONAP code conventions (removing tabs etc.) Issue-ID: SO-368 Change-Id: I48c6d359b83617aebeb79db4e30c1d72d31f7eec Signed-off-by: Marcus G K Williams --- .../client/tests/ASDCGlobalControllerTest.java | 288 ++++++++++----------- 1 file changed, 143 insertions(+), 145 deletions(-) (limited to 'asdc-controller/src/test/java/org/openecomp/mso/asdc/client/tests/ASDCGlobalControllerTest.java') diff --git a/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/tests/ASDCGlobalControllerTest.java b/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/tests/ASDCGlobalControllerTest.java index 73c5456d29..93a23f8663 100644 --- a/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/tests/ASDCGlobalControllerTest.java +++ b/asdc-controller/src/test/java/org/openecomp/mso/asdc/client/tests/ASDCGlobalControllerTest.java @@ -23,6 +23,7 @@ package org.openecomp.mso.asdc.client.tests; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; @@ -55,159 +56,156 @@ import org.openecomp.mso.properties.MsoPropertiesException; import org.openecomp.mso.properties.MsoPropertiesFactory; - /** * THis class tests the ASDC Controller by using the ASDC Mock CLient - * - * */ public class ASDCGlobalControllerTest { - private static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); + private static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory(); + + private static String heatExample; + private static String heatExampleMD5HashBase64; + + private static INotificationData iNotif; + + private static IDistributionClientDownloadResult downloadResult; + private static IDistributionClientDownloadResult downloadCorruptedResult; + + private static IDistributionClientResult successfulClientInitResult; + private static IDistributionClientResult unsuccessfulClientInitResult; + + private static IArtifactInfo artifactInfo1; + + private static IResourceInstance resource1; + + public static final String ASDC_PROP = MsoJavaProperties.class.getClassLoader().getResource("mso.json").toString().substring(5); + public static final String ASDC_PROP2 = MsoJavaProperties.class.getClassLoader().getResource("mso2.json").toString().substring(5); + public static final String ASDC_PROP3 = MsoJavaProperties.class.getClassLoader().getResource("mso3.json").toString().substring(5); + public static final String ASDC_PROP_BAD = MsoJavaProperties.class.getClassLoader().getResource("mso-bad.json").toString().substring(5); + public static final String ASDC_PROP_WITH_NULL = MsoJavaProperties.class.getClassLoader().getResource("mso-with-NULL.json").toString().substring(5); + public static final String ASDC_PROP_WITH_DOUBLE = MsoJavaProperties.class.getClassLoader().getResource("mso-two-configs.json").toString().substring(5); + public static final String ASDC_PROP_WITH_DOUBLE2 = MsoJavaProperties.class.getClassLoader().getResource("mso-two-configs2.json").toString().substring(5); + + @BeforeClass + public static final void prepareMockNotification() throws MsoPropertiesException, IOException, URISyntaxException, NoSuchAlgorithmException, ArtifactInstallerException { + + heatExample = new String(Files.readAllBytes(Paths.get(ASDCGlobalControllerTest.class.getClassLoader().getResource("resource-examples/autoscaling.yaml").toURI()))); + MessageDigest md = MessageDigest.getInstance("MD5"); + byte[] md5Hash = md.digest(heatExample.getBytes()); + heatExampleMD5HashBase64 = Base64.encodeBase64String(md5Hash); + + iNotif = Mockito.mock(INotificationData.class); + + // Create fake ArtifactInfo + artifactInfo1 = Mockito.mock(IArtifactInfo.class); + Mockito.when(artifactInfo1.getArtifactChecksum()).thenReturn(ASDCGlobalControllerTest.heatExampleMD5HashBase64); + + Mockito.when(artifactInfo1.getArtifactName()).thenReturn("artifact1"); + Mockito.when(artifactInfo1.getArtifactType()).thenReturn(ASDCConfiguration.HEAT); + Mockito.when(artifactInfo1.getArtifactURL()).thenReturn("https://localhost:8080/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml"); + Mockito.when(artifactInfo1.getArtifactUUID()).thenReturn("UUID1"); + Mockito.when(artifactInfo1.getArtifactDescription()).thenReturn("testos artifact1"); + + // Now provision the NotificationData mock + List listArtifact = new ArrayList<>(); + listArtifact.add(artifactInfo1); + + // Create fake resource Instance + resource1 = Mockito.mock(IResourceInstance.class); + Mockito.when(resource1.getResourceType()).thenReturn("VF"); + Mockito.when(resource1.getResourceName()).thenReturn("resourceName"); + Mockito.when(resource1.getArtifacts()).thenReturn(listArtifact); + + List resources = new ArrayList<>(); + resources.add(resource1); + + Mockito.when(iNotif.getResources()).thenReturn(resources); + Mockito.when(iNotif.getDistributionID()).thenReturn("distributionID1"); + Mockito.when(iNotif.getServiceName()).thenReturn("serviceName1"); + Mockito.when(iNotif.getServiceUUID()).thenReturn("serviceNameUUID1"); + Mockito.when(iNotif.getServiceVersion()).thenReturn("1.0"); + + downloadResult = Mockito.mock(IDistributionClientDownloadResult.class); + Mockito.when(downloadResult.getArtifactPayload()).thenReturn(heatExample.getBytes()); + Mockito.when(downloadResult.getDistributionActionResult()).thenReturn(DistributionActionResultEnum.SUCCESS); + Mockito.when(downloadResult.getDistributionMessageResult()).thenReturn("Success"); + + downloadCorruptedResult = Mockito.mock(IDistributionClientDownloadResult.class); + Mockito.when(downloadCorruptedResult.getArtifactPayload()).thenReturn((heatExample + "badone").getBytes()); + Mockito.when(downloadCorruptedResult.getDistributionActionResult()).thenReturn(DistributionActionResultEnum.SUCCESS); + Mockito.when(downloadCorruptedResult.getDistributionMessageResult()).thenReturn("Success"); + + + // Mock now the ASDC distribution client behavior + successfulClientInitResult = Mockito.mock(IDistributionClientResult.class); + Mockito.when(successfulClientInitResult.getDistributionActionResult()).thenReturn(DistributionActionResultEnum.SUCCESS); + + unsuccessfulClientInitResult = Mockito.mock(IDistributionClientResult.class); + Mockito.when(unsuccessfulClientInitResult.getDistributionActionResult()).thenReturn(DistributionActionResultEnum.GENERAL_ERROR); + + } + + @Before + public final void initBeforeEachTest() throws MsoPropertiesException { + // load the config + msoPropertiesFactory.removeAllMsoProperties(); + msoPropertiesFactory.initializeMsoProperties(ASDCConfiguration.MSO_PROP_ASDC, ASDC_PROP); + } + + @AfterClass + public static final void kill() throws MsoPropertiesException { + + msoPropertiesFactory.removeMsoProperties(ASDCConfiguration.MSO_PROP_ASDC); + } + + @Test + public final void testUpdateControllersConfigIfNeeded() throws ASDCControllerException, ASDCParametersException, IOException, MsoPropertiesException { + + ASDCGlobalController asdcGlobalController = new ASDCGlobalController(); + assertTrue(asdcGlobalController.getControllers().size() == 0); + + // first init + assertTrue(asdcGlobalController.updateControllersConfigIfNeeded()); + assertTrue(asdcGlobalController.getControllers().size() == 1); + assertTrue(asdcGlobalController.getControllers().get("asdc-controller1") != null); + + // Add a second one + msoPropertiesFactory.removeAllMsoProperties(); + msoPropertiesFactory.initializeMsoProperties(ASDCConfiguration.MSO_PROP_ASDC, ASDC_PROP_WITH_DOUBLE); + assertTrue(asdcGlobalController.updateControllersConfigIfNeeded()); + assertTrue(asdcGlobalController.getControllers().size() == 2); + assertTrue(asdcGlobalController.getControllers().get("asdc-controller1") != null); + assertTrue(asdcGlobalController.getControllers().get("asdc-controller2") != null); + // Check that update does nothing + assertFalse(asdcGlobalController.updateControllersConfigIfNeeded()); + assertTrue(asdcGlobalController.getControllers().size() == 2); + + // Change the second one name + msoPropertiesFactory.removeAllMsoProperties(); + msoPropertiesFactory.initializeMsoProperties(ASDCConfiguration.MSO_PROP_ASDC, ASDC_PROP_WITH_DOUBLE2); + assertTrue(asdcGlobalController.updateControllersConfigIfNeeded()); + assertTrue(asdcGlobalController.getControllers().size() == 2); + assertTrue(asdcGlobalController.getControllers().get("asdc-controller1") != null); + assertTrue(asdcGlobalController.getControllers().get("asdc-controller2B") != null); + + + } + + @Test + public final void testCloseASDC() { + + ASDCGlobalController asdcGlobalController = new ASDCGlobalController(); + assertTrue(asdcGlobalController.getControllers().size() == 0); - private static String heatExample; - private static String heatExampleMD5HashBase64; + // first init + assertTrue(asdcGlobalController.updateControllersConfigIfNeeded()); + assertTrue(asdcGlobalController.getControllers().size() == 1); + assertTrue(asdcGlobalController.getControllers().get("asdc-controller1") != null); - private static INotificationData iNotif; + asdcGlobalController.closeASDC(); + assertTrue(asdcGlobalController.getControllers().size() == 0); - private static IDistributionClientDownloadResult downloadResult; - private static IDistributionClientDownloadResult downloadCorruptedResult; - private static IDistributionClientResult successfulClientInitResult; - private static IDistributionClientResult unsuccessfulClientInitResult; - - private static IArtifactInfo artifactInfo1; - - private static IResourceInstance resource1; - - public static final String ASDC_PROP = MsoJavaProperties.class.getClassLoader().getResource("mso.json").toString().substring(5); - public static final String ASDC_PROP2 = MsoJavaProperties.class.getClassLoader().getResource("mso2.json").toString().substring(5); - public static final String ASDC_PROP3 = MsoJavaProperties.class.getClassLoader().getResource("mso3.json").toString().substring(5); - public static final String ASDC_PROP_BAD = MsoJavaProperties.class.getClassLoader().getResource("mso-bad.json").toString().substring(5); - public static final String ASDC_PROP_WITH_NULL = MsoJavaProperties.class.getClassLoader().getResource("mso-with-NULL.json").toString().substring(5); - public static final String ASDC_PROP_WITH_DOUBLE = MsoJavaProperties.class.getClassLoader().getResource("mso-two-configs.json").toString().substring(5); - public static final String ASDC_PROP_WITH_DOUBLE2 = MsoJavaProperties.class.getClassLoader().getResource("mso-two-configs2.json").toString().substring(5); - - @BeforeClass - public static final void prepareMockNotification() throws MsoPropertiesException, IOException, URISyntaxException, NoSuchAlgorithmException, ArtifactInstallerException { - - heatExample = new String(Files.readAllBytes(Paths.get(ASDCGlobalControllerTest.class.getClassLoader().getResource("resource-examples/autoscaling.yaml").toURI()))); - MessageDigest md = MessageDigest.getInstance("MD5"); - byte[] md5Hash = md.digest(heatExample.getBytes()); - heatExampleMD5HashBase64 = Base64.encodeBase64String(md5Hash); - - iNotif= Mockito.mock(INotificationData.class); - - // Create fake ArtifactInfo - artifactInfo1 = Mockito.mock(IArtifactInfo.class); - Mockito.when(artifactInfo1.getArtifactChecksum()).thenReturn(ASDCGlobalControllerTest.heatExampleMD5HashBase64); - - Mockito.when(artifactInfo1.getArtifactName()).thenReturn("artifact1"); - Mockito.when(artifactInfo1.getArtifactType()).thenReturn(ASDCConfiguration.HEAT); - Mockito.when(artifactInfo1.getArtifactURL()).thenReturn("https://localhost:8080/v1/catalog/services/srv1/2.0/resources/aaa/1.0/artifacts/aaa.yml"); - Mockito.when(artifactInfo1.getArtifactUUID()).thenReturn("UUID1"); - Mockito.when(artifactInfo1.getArtifactDescription()).thenReturn("testos artifact1"); - - // Now provision the NotificationData mock - List listArtifact = new ArrayList<>(); - listArtifact.add(artifactInfo1); - - // Create fake resource Instance - resource1 = Mockito.mock (IResourceInstance.class); - Mockito.when (resource1.getResourceType ()).thenReturn ("VF"); - Mockito.when (resource1.getResourceName ()).thenReturn ("resourceName"); - Mockito.when (resource1.getArtifacts ()).thenReturn (listArtifact); - - List resources = new ArrayList<> (); - resources.add (resource1); - - Mockito.when(iNotif.getResources()).thenReturn(resources); - Mockito.when(iNotif.getDistributionID()).thenReturn("distributionID1"); - Mockito.when(iNotif.getServiceName()).thenReturn("serviceName1"); - Mockito.when(iNotif.getServiceUUID()).thenReturn("serviceNameUUID1"); - Mockito.when(iNotif.getServiceVersion()).thenReturn("1.0"); - - downloadResult = Mockito.mock(IDistributionClientDownloadResult.class); - Mockito.when(downloadResult.getArtifactPayload()).thenReturn(heatExample.getBytes()); - Mockito.when(downloadResult.getDistributionActionResult()).thenReturn(DistributionActionResultEnum.SUCCESS); - Mockito.when(downloadResult.getDistributionMessageResult()).thenReturn("Success"); - - downloadCorruptedResult = Mockito.mock(IDistributionClientDownloadResult.class); - Mockito.when(downloadCorruptedResult.getArtifactPayload()).thenReturn((heatExample+"badone").getBytes()); - Mockito.when(downloadCorruptedResult.getDistributionActionResult()).thenReturn(DistributionActionResultEnum.SUCCESS); - Mockito.when(downloadCorruptedResult.getDistributionMessageResult()).thenReturn("Success"); - - - // Mock now the ASDC distribution client behavior - successfulClientInitResult = Mockito.mock(IDistributionClientResult.class); - Mockito.when(successfulClientInitResult.getDistributionActionResult ()).thenReturn(DistributionActionResultEnum.SUCCESS); - - unsuccessfulClientInitResult = Mockito.mock(IDistributionClientResult.class); - Mockito.when(unsuccessfulClientInitResult.getDistributionActionResult ()).thenReturn(DistributionActionResultEnum.GENERAL_ERROR); - - } - - @Before - public final void initBeforeEachTest() throws MsoPropertiesException { - // load the config - msoPropertiesFactory.removeAllMsoProperties(); - msoPropertiesFactory.initializeMsoProperties(ASDCConfiguration.MSO_PROP_ASDC, ASDC_PROP); - } - - @AfterClass - public static final void kill () throws MsoPropertiesException { - - msoPropertiesFactory.removeMsoProperties(ASDCConfiguration.MSO_PROP_ASDC); - } - - @Test - public final void testUpdateControllersConfigIfNeeded() throws ASDCControllerException, ASDCParametersException, IOException, MsoPropertiesException { - - ASDCGlobalController asdcGlobalController = new ASDCGlobalController(); - assertTrue(asdcGlobalController.getControllers().size()==0); - - // first init - assertTrue(asdcGlobalController.updateControllersConfigIfNeeded()); - assertTrue(asdcGlobalController.getControllers().size()==1); - assertTrue(asdcGlobalController.getControllers().get("asdc-controller1") != null); - - // Add a second one - msoPropertiesFactory.removeAllMsoProperties(); - msoPropertiesFactory.initializeMsoProperties(ASDCConfiguration.MSO_PROP_ASDC, ASDC_PROP_WITH_DOUBLE); - assertTrue(asdcGlobalController.updateControllersConfigIfNeeded()); - assertTrue(asdcGlobalController.getControllers().size()==2); - assertTrue(asdcGlobalController.getControllers().get("asdc-controller1") != null); - assertTrue(asdcGlobalController.getControllers().get("asdc-controller2") != null); - // Check that update does nothing - assertFalse(asdcGlobalController.updateControllersConfigIfNeeded()); - assertTrue(asdcGlobalController.getControllers().size()==2); - - // Change the second one name - msoPropertiesFactory.removeAllMsoProperties(); - msoPropertiesFactory.initializeMsoProperties(ASDCConfiguration.MSO_PROP_ASDC, ASDC_PROP_WITH_DOUBLE2); - assertTrue(asdcGlobalController.updateControllersConfigIfNeeded()); - assertTrue(asdcGlobalController.getControllers().size()==2); - assertTrue(asdcGlobalController.getControllers().get("asdc-controller1") != null); - assertTrue(asdcGlobalController.getControllers().get("asdc-controller2B") != null); - - - } - - @Test - public final void testCloseASDC() { - - ASDCGlobalController asdcGlobalController = new ASDCGlobalController(); - assertTrue(asdcGlobalController.getControllers().size()==0); - - // first init - assertTrue(asdcGlobalController.updateControllersConfigIfNeeded()); - assertTrue(asdcGlobalController.getControllers().size()==1); - assertTrue(asdcGlobalController.getControllers().get("asdc-controller1") != null); - - asdcGlobalController.closeASDC(); - assertTrue(asdcGlobalController.getControllers().size()==0); - - - } + } } -- cgit 1.2.3-korg