Remove dependency on org.powermock (PowerMockito) 93/43493/1
authormark.j.leonard <mark.j.leonard@gmail.com>
Wed, 18 Apr 2018 10:17:11 +0000 (11:17 +0100)
committermark.j.leonard <mark.j.leonard@gmail.com>
Wed, 18 Apr 2018 10:22:16 +0000 (11:22 +0100)
Replace use of PowerMockito packages with the standard Mockito.
Create a BabelServiceClient Factory class to simplify mocking.
Remove duplicated "no mock" test classes that were not in fact free of
mocking. Add a dummy sample CSAR file for testing of artifact downloads.

Change-Id: Ib86f560e514e1efab0e2f732e494a032d555c7c3
Issue-ID: AAI-1049
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
18 files changed:
pom.xml
src/main/java/org/onap/aai/modelloader/notification/ArtifactDownloadManager.java
src/main/java/org/onap/aai/modelloader/notification/EventCallback.java
src/main/java/org/onap/aai/modelloader/restclient/AaiRestClient.java
src/main/java/org/onap/aai/modelloader/restclient/BabelServiceClientFactory.java [new file with mode: 0644]
src/main/java/org/onap/aai/modelloader/service/ModelLoaderService.java
src/test/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandlerTest.java
src/test/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandler_noMock_Test.java [deleted file]
src/test/java/org/onap/aai/modelloader/entity/model/AAIRestClientTest.java [deleted file]
src/test/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManagerMockTest.java [deleted file]
src/test/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManagerTest.java
src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerNoMockTest.java [deleted file]
src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerTest.java
src/test/java/org/onap/aai/modelloader/notification/BabelArtifactConverterTest.java
src/test/java/org/onap/aai/modelloader/notification/EventCallbackNoMockTest.java [deleted file]
src/test/java/org/onap/aai/modelloader/notification/EventCallbackTest.java
src/test/java/org/onap/aai/modelloader/restclient/TestAaiRestClient.java [deleted file]
src/test/resources/compressedArtifacts/service-VscpaasTest-csar.csar [new file with mode: 0644]

diff --git a/pom.xml b/pom.xml
index 8829d64..f45e580 100644 (file)
--- a/pom.xml
+++ b/pom.xml
@@ -48,7 +48,6 @@
                <commons-compress.version>1.14</commons-compress.version>
                <fasterxml.version>2.8.1</fasterxml.version>
                <mockito.version>1.10.19</mockito.version>
-               <powermock.version>1.6.2</powermock.version>
                <jsr311-api.version>1.1.1</jsr311-api.version>
                <jersey-client.version>1.18</jersey-client.version>
                <gson.version>2.7</gson.version>
                        <version>${mockito.version}</version>
                        <scope>test</scope>
                </dependency>
-               <dependency>
-                       <groupId>org.powermock</groupId>
-                       <artifactId>powermock-module-junit4</artifactId>
-                       <version>${powermock.version}</version>
-                       <scope>test</scope>
-               </dependency>
-               <dependency>
-                       <groupId>org.powermock</groupId>
-                       <artifactId>powermock-api-mockito</artifactId>
-                       <version>${powermock.version}</version>
-                       <scope>test</scope>
-               </dependency>
-               <dependency>
-                       <groupId>org.powermock</groupId>
-                       <artifactId>powermock-module-junit4-rule-agent</artifactId>
-                       <version>1.6.2</version>
-                       <scope>test</scope>
-                       <exclusions>
-                               <exclusion>
-                                       <artifactId>powermock-module-javaagent</artifactId>
-                                       <groupId>org.powermock</groupId>
-                               </exclusion>
-                       </exclusions>
-               </dependency>
                <dependency>
                        <groupId>org.javassist</groupId>
                        <artifactId>javassist</artifactId>
                                        <forceTags>true</forceTags>
                                </configuration>
                        </plugin>
-                       <plugin>
-                               <groupId>org.apache.maven.plugins</groupId>
-                               <artifactId>maven-dependency-plugin</artifactId>
-                               <version>2.8</version>
-                               <executions>
-                                       <execution>
-                                               <id>copy-agent</id>
-                                               <phase>process-test-classes</phase>
-                                               <goals>
-                                                       <goal>copy</goal>
-                                               </goals>
-                                               <configuration>
-                                                       <artifactItems>
-                                                               <artifactItem>
-                                                                       <groupId>org.powermock</groupId>
-                                                                       <artifactId>powermock-module-javaagent</artifactId>
-                                                                       <version>1.6.2</version>
-                                                                       <outputDirectory>${project.build.directory}/agents</outputDirectory>
-                                                                       <destFileName>powermock-javaagent.jar</destFileName>
-                                                               </artifactItem>
-                                                       </artifactItems>
-                                               </configuration>
-                                       </execution>
-                               </executions>
-                       </plugin>
                        <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-surefire-plugin</artifactId>
index bdd101e..3fa0b40 100644 (file)
@@ -26,7 +26,6 @@ import java.util.Base64;
 import java.util.List;
 import java.util.Map;
 import java.util.stream.Collectors;
-
 import org.onap.aai.babel.service.data.BabelArtifact;
 import org.onap.aai.babel.service.data.BabelArtifact.ArtifactType;
 import org.onap.aai.cl.api.Logger;
@@ -40,6 +39,7 @@ import org.onap.aai.modelloader.entity.model.IModelParser;
 import org.onap.aai.modelloader.entity.model.NamedQueryArtifactParser;
 import org.onap.aai.modelloader.extraction.InvalidArchiveException;
 import org.onap.aai.modelloader.restclient.BabelServiceClient;
+import org.onap.aai.modelloader.restclient.BabelServiceClientFactory;
 import org.onap.aai.modelloader.service.ModelLoaderMsgs;
 import org.openecomp.sdc.api.IDistributionClient;
 import org.openecomp.sdc.api.notification.IArtifactInfo;
@@ -66,10 +66,13 @@ public class ArtifactDownloadManager {
     private NotificationPublisher notificationPublisher;
     private BabelArtifactConverter babelArtifactConverter;
     private ModelLoaderConfig config;
+    private BabelServiceClientFactory clientFactory;
 
-    public ArtifactDownloadManager(IDistributionClient client, ModelLoaderConfig config) {
+    public ArtifactDownloadManager(IDistributionClient client, ModelLoaderConfig config,
+            BabelServiceClientFactory clientFactory) {
         this.client = client;
         this.config = config;
+        this.clientFactory = clientFactory;
     }
 
     /**
@@ -193,12 +196,12 @@ public class ArtifactDownloadManager {
         }
     }
 
-    private BabelServiceClient createBabelServiceClient(IArtifactInfo artifact, String serviceVersion)
+    BabelServiceClient createBabelServiceClient(IArtifactInfo artifact, String serviceVersion)
             throws ProcessToscaArtifactsException {
         BabelServiceClient babelClient;
         try {
             logger.debug(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Creating Babel client");
-            babelClient = new BabelServiceClient(config);
+            babelClient = clientFactory.create(config);
         } catch (Exception e) {
             logger.error(ModelLoaderMsgs.BABEL_REST_REQUEST_ERROR, e, "POST", config.getBabelBaseUrl(),
                     "Error posting artifact " + artifact.getArtifactName() + " " + serviceVersion + " to Babel: "
index 827ff81..fe6bf7b 100644 (file)
@@ -28,6 +28,7 @@ import org.onap.aai.cl.mdc.MdcContext;
 import org.onap.aai.modelloader.config.ModelLoaderConfig;
 import org.onap.aai.modelloader.entity.Artifact;
 import org.onap.aai.modelloader.extraction.ArtifactInfoExtractor;
+import org.onap.aai.modelloader.restclient.BabelServiceClientFactory;
 import org.onap.aai.modelloader.service.ModelLoaderMsgs;
 import org.openecomp.sdc.api.IDistributionClient;
 import org.openecomp.sdc.api.consumer.INotificationCallback;
@@ -58,8 +59,8 @@ public class EventCallback implements INotificationCallback {
         List<Artifact> catalogArtifacts = new ArrayList<>();
         List<Artifact> modelArtifacts = new ArrayList<>();
 
-        boolean success = getArtifactDownloadManager()
-                .downloadArtifacts(data, artifacts, modelArtifacts, catalogArtifacts);
+        boolean success =
+                getArtifactDownloadManager().downloadArtifacts(data, artifacts, modelArtifacts, catalogArtifacts);
 
         if (success) {
             success = getArtifactDeploymentManager().deploy(data, artifacts, modelArtifacts, catalogArtifacts);
@@ -75,13 +76,12 @@ public class EventCallback implements INotificationCallback {
         if (artifactDeploymentManager == null) {
             artifactDeploymentManager = new ArtifactDeploymentManager(client, config);
         }
-
         return artifactDeploymentManager;
     }
 
     private ArtifactDownloadManager getArtifactDownloadManager() {
         if (artifactDownloadManager == null) {
-            artifactDownloadManager = new ArtifactDownloadManager(client, config);
+            artifactDownloadManager = new ArtifactDownloadManager(client, config, new BabelServiceClientFactory());
         }
 
         return artifactDownloadManager;
index 7d2ab09..28cd671 100644 (file)
@@ -21,7 +21,6 @@
 package org.onap.aai.modelloader.restclient;
 
 import com.sun.jersey.core.util.MultivaluedMapImpl; // NOSONAR
-// import edu.emory.mathcs.backport.java.util.Collections;
 import java.io.IOException;
 import java.io.StringReader;
 import java.net.URI;
@@ -91,7 +90,7 @@ public class AaiRestClient {
      * @return operation result
      */
     public OperationResult putResource(String url, String payload, String transId, MediaType mediaType) {
-       logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_PAYLOAD, payload);
+        logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_PAYLOAD, payload);
         return setupClient().put(url, payload, buildHeaders(transId), mediaType, mediaType);
     }
 
@@ -106,7 +105,7 @@ public class AaiRestClient {
      * @return ClientResponse
      */
     public OperationResult postResource(String url, String payload, String transId, MediaType mediaType) {
-       logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_PAYLOAD, payload);
+        logger.info(ModelLoaderMsgs.AAI_REST_REQUEST_PAYLOAD, payload);
         return setupClient().post(url, payload, buildHeaders(transId), mediaType, mediaType);
     }
 
@@ -180,7 +179,6 @@ public class AaiRestClient {
      * @param transId
      * @return map of headers
      */
-    @SuppressWarnings("unchecked")
     private Map<String, List<String>> buildHeaders(String transId) {
         MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
         headers.put(HEADER_TRANS_ID, Collections.singletonList(transId));
diff --git a/src/main/java/org/onap/aai/modelloader/restclient/BabelServiceClientFactory.java b/src/main/java/org/onap/aai/modelloader/restclient/BabelServiceClientFactory.java
new file mode 100644 (file)
index 0000000..6ce4a60
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * ============LICENSE_START==========================================
+ * org.onap.aai
+ * ===================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ===================================================================
+ * 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.aai.modelloader.restclient;
+
+import java.io.IOException;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
+import org.onap.aai.modelloader.config.ModelLoaderConfig;
+
+public class BabelServiceClientFactory {
+
+    public BabelServiceClient create(ModelLoaderConfig config) throws UnrecoverableKeyException, KeyManagementException,
+            NoSuchAlgorithmException, KeyStoreException, CertificateException, IOException {
+        return new BabelServiceClient(config);
+    }
+
+}
index aa3481c..a4cc5d1 100644 (file)
@@ -39,6 +39,7 @@ import org.onap.aai.modelloader.entity.Artifact;
 import org.onap.aai.modelloader.notification.ArtifactDeploymentManager;
 import org.onap.aai.modelloader.notification.ArtifactDownloadManager;
 import org.onap.aai.modelloader.notification.EventCallback;
+import org.onap.aai.modelloader.restclient.BabelServiceClientFactory;
 import org.openecomp.sdc.api.IDistributionClient;
 import org.openecomp.sdc.api.notification.IArtifactInfo;
 import org.openecomp.sdc.api.notification.INotificationData;
@@ -196,8 +197,8 @@ public class ModelLoaderService implements ModelLoaderInterface {
 
                 logger.info(ModelLoaderMsgs.DISTRIBUTION_EVENT, "Generating xml models from test artifact");
 
-                new ArtifactDownloadManager(client, config).processToscaArtifacts(modelArtifacts, catalogArtifacts,
-                        csarFile, artifactInfo, "test-transaction-id", modelVersion);
+                new ArtifactDownloadManager(client, config, new BabelServiceClientFactory()).processToscaArtifacts(
+                        modelArtifacts, catalogArtifacts, csarFile, artifactInfo, "test-transaction-id", modelVersion);
 
                 List<IArtifactInfo> artifacts = new ArrayList<>();
                 artifacts.add(artifactInfo);
index addea78..aa75cd2 100644 (file)
-/**\r
- * ============LICENSE_START==========================================\r
- * org.onap.aai\r
- * ===================================================================\r
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.\r
- * Copyright © 2017-2018 Amdocs\r
- * ===================================================================\r
- * Licensed under the Apache License, Version 2.0 (the "License");\r
- * you may not use this file except in compliance with the License.\r
- * You may obtain a copy of the License at\r
- *\r
- *        http://www.apache.org/licenses/LICENSE-2.0\r
- *\r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS,\r
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
- * See the License for the specific language governing permissions and\r
- * limitations under the License.\r
- * ============LICENSE_END============================================\r
- */\r
-package org.onap.aai.modelloader.entity.catalog;\r
-\r
-import static org.junit.Assert.fail;\r
-\r
-import com.sun.jersey.api.client.ClientResponse;\r
-import java.io.IOException;\r
-import java.util.Properties;\r
-import javax.ws.rs.core.MediaType;\r
-import javax.ws.rs.core.Response;\r
-import org.junit.Test;\r
-import org.junit.runner.RunWith;\r
-import org.mockito.Mockito;\r
-import org.onap.aai.modelloader.config.ModelLoaderConfig;\r
-import org.onap.aai.modelloader.restclient.AaiRestClient;\r
-import org.onap.aai.restclient.client.OperationResult;\r
-import org.powermock.api.mockito.PowerMockito;\r
-import org.powermock.core.classloader.annotations.PrepareForTest;\r
-import org.powermock.modules.junit4.PowerMockRunner;\r
-\r
-@RunWith(PowerMockRunner.class)\r
-@PrepareForTest({VnfCatalogArtifactHandler.class, ClientResponse.class, AaiRestClient.class})\r
-public class VnfCatalogArtifactHandlerTest {\r
-\r
-    protected static String CONFIG_FILE = "model-loader.properties";\r
-\r
-    @Test\r
-    public void testWithMocks() throws Exception {\r
-\r
-        Properties configProperties = new Properties();\r
-        try {\r
-            configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));\r
-        } catch (IOException e) {\r
-            fail();\r
-        }\r
-        ModelLoaderConfig config = new ModelLoaderConfig(configProperties, null);\r
-        config.setModelVersion("11");\r
-\r
-        AaiRestClient mockRestClient = PowerMockito.mock(AaiRestClient.class);\r
-        PowerMockito.whenNew(AaiRestClient.class).withAnyArguments().thenReturn(mockRestClient);\r
-\r
-        // GET operation\r
-        OperationResult mockGetResp = PowerMockito.mock(OperationResult.class);\r
-\r
-        // @formatter:off\r
-        PowerMockito.when(mockGetResp.getResultCode())\r
-                .thenReturn(Response.Status.OK.getStatusCode())\r
-                .thenReturn(Response.Status.NOT_FOUND.getStatusCode())\r
-                .thenReturn(Response.Status.NOT_FOUND.getStatusCode())\r
-                .thenReturn(Response.Status.OK.getStatusCode());\r
-        // @formatter:on\r
-        PowerMockito.when(\r
-                mockRestClient.getResource(Mockito.anyString(), Mockito.anyString(), Mockito.any(MediaType.class)))\r
-                .thenReturn(mockGetResp);\r
-\r
-        // PUT operation\r
-        OperationResult mockPutResp = PowerMockito.mock(OperationResult.class);\r
-\r
-        PowerMockito.when(mockPutResp.getResultCode()).thenReturn(Response.Status.CREATED.getStatusCode());\r
-        PowerMockito.when(mockRestClient.putResource(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),\r
-                Mockito.any(MediaType.class))).thenReturn(mockPutResp);\r
-\r
-        // Example VNF Catalog with\r
-        VnfCatalogArtifactHandler vnfCAH = new VnfCatalogArtifactHandler(config);\r
-        String examplePath = "src/test/resources/imagedataexample.json";\r
-        /*\r
-         * byte[] encoded = Files.readAllBytes(Paths.get(examplePath)); List<Artifact> artifacts = new\r
-         * ArrayList<Artifact>(); artifacts.add(new VnfCatalogArtifact(new String(encoded, "utf-8")));\r
-         * \r
-         * assertTrue(vnfCAH.pushArtifacts(artifacts, "test", new ArrayList<Artifact>(), mockRestClient));\r
-         * \r
-         * // Only two of the VNF images should be pushed ArgumentCaptor<String> argument =\r
-         * ArgumentCaptor.forClass(String.class); AaiRestClient r = Mockito.verify(mockRestClient, Mockito.times(2));\r
-         * r.putResource(Mockito.anyString(), argument.capture(), Mockito.anyString(), Mockito.any(MediaType.class));\r
-         * assertTrue(argument.getAllValues().get(0).contains("3.16.9"));\r
-         * assertTrue(argument.getAllValues().get(0).contains("VM00"));\r
-         * assertTrue(argument.getAllValues().get(1).contains("3.16.1"));\r
-         * assertTrue(argument.getAllValues().get(1).contains("VM01"));\r
-         */\r
-    }\r
-}\r
+/**
+ * ============LICENSE_START==========================================
+ * org.onap.aai
+ * ===================================================================
+ * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
+ * Copyright © 2017-2018 Amdocs
+ * ===================================================================
+ * 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.aai.modelloader.entity.catalog;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Properties;
+import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.Response;
+import org.junit.Test;
+import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
+import org.onap.aai.modelloader.config.ModelLoaderConfig;
+import org.onap.aai.modelloader.entity.Artifact;
+import org.onap.aai.modelloader.restclient.AaiRestClient;
+import org.onap.aai.restclient.client.OperationResult;
+
+public class VnfCatalogArtifactHandlerTest {
+
+    protected static String CONFIG_FILE = "model-loader.properties";
+
+    @Test
+    public void testWithMocks() throws Exception {
+
+        Properties configProperties = new Properties();
+        try {
+            configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
+        } catch (IOException e) {
+            fail();
+        }
+        ModelLoaderConfig config = new ModelLoaderConfig(configProperties, null);
+        config.setModelVersion("11");
+
+        AaiRestClient mockRestClient = mock(AaiRestClient.class);
+
+        // GET operation
+        OperationResult mockGetResp = mock(OperationResult.class);
+
+        // @formatter:off
+        when(mockGetResp.getResultCode())
+                .thenReturn(Response.Status.OK.getStatusCode())
+                .thenReturn(Response.Status.NOT_FOUND.getStatusCode())
+                .thenReturn(Response.Status.NOT_FOUND.getStatusCode())
+                .thenReturn(Response.Status.OK.getStatusCode());
+        // @formatter:on
+        when(mockRestClient.getResource(Mockito.anyString(), Mockito.anyString(), Mockito.any(MediaType.class)))
+                .thenReturn(mockGetResp);
+
+        // PUT operation
+        OperationResult mockPutResp = mock(OperationResult.class);
+
+        when(mockPutResp.getResultCode()).thenReturn(Response.Status.CREATED.getStatusCode());
+        when(mockRestClient.putResource(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
+                Mockito.any(MediaType.class))).thenReturn(mockPutResp);
+
+        // Example VNF Catalog with
+        VnfCatalogArtifactHandler vnfCAH = new VnfCatalogArtifactHandler(config);
+        String examplePath = "src/test/resources/imagedataexample.json";
+        byte[] encoded = Files.readAllBytes(Paths.get(examplePath));
+        List<Artifact> artifacts = new ArrayList<Artifact>();
+        artifacts.add(new VnfCatalogArtifact(new String(encoded, "utf-8")));
+
+        assertTrue(vnfCAH.pushArtifacts(artifacts, "test", new ArrayList<Artifact>(), mockRestClient));
+
+        // Only two of the VNF images should be pushed
+        ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
+        AaiRestClient r = Mockito.verify(mockRestClient, Mockito.times(2));
+        r.putResource(Mockito.anyString(), argument.capture(), Mockito.anyString(), Mockito.any(MediaType.class));
+        assertTrue(argument.getAllValues().get(0).contains("3.16.9"));
+        assertTrue(argument.getAllValues().get(0).contains("VM00"));
+        assertTrue(argument.getAllValues().get(1).contains("3.16.1"));
+        assertTrue(argument.getAllValues().get(1).contains("VM01"));
+    }
+}
diff --git a/src/test/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandler_noMock_Test.java b/src/test/java/org/onap/aai/modelloader/entity/catalog/VnfCatalogArtifactHandler_noMock_Test.java
deleted file mode 100644 (file)
index a1ca794..0000000
+++ /dev/null
@@ -1,118 +0,0 @@
-/**
- * ============LICENSE_START==========================================
- * org.onap.aai
- * ===================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ===================================================================
- * 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.aai.modelloader.entity.catalog;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import com.sun.jersey.api.client.ClientResponse;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import org.junit.Test;
-import org.mockito.ArgumentCaptor;
-import org.mockito.Mockito;
-import org.onap.aai.modelloader.config.ModelLoaderConfig;
-import org.onap.aai.modelloader.entity.Artifact;
-import org.onap.aai.modelloader.restclient.AaiRestClient;
-import org.onap.aai.restclient.client.OperationResult;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-
-
-/**
- * No-Mock tests
- * 
- * Because Jacoco (and other coverage tools) can't cope with mocked classes under some circumstances, coverage is/was
- * falsely reported as < 50%. Hence these duplicated but non-mock tests to address this, for ONAP reasons.
- * 
- * @author andrewdo
- *
- */
-
-@PrepareForTest({VnfCatalogArtifactHandler.class, ClientResponse.class, AaiRestClient.class})
-public class VnfCatalogArtifactHandler_noMock_Test {
-
-    protected static String CONFIG_FILE = "model-loader.properties";
-
-
-    @Test
-    public void testWithOutMocks() throws Exception {
-
-        Properties configProperties = new Properties();
-        try {
-            configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
-        } catch (IOException e) {
-            fail();
-        }
-
-        ModelLoaderConfig config = new ModelLoaderConfig(configProperties, null);
-        config.setModelVersion("11");
-
-        AaiRestClient mockRestClient = PowerMockito.mock(AaiRestClient.class);
-        PowerMockito.whenNew(AaiRestClient.class).withAnyArguments().thenReturn(mockRestClient);
-
-        // GET operation
-        OperationResult mockGetResp = PowerMockito.mock(OperationResult.class);
-
-        // @formatter:off
-        PowerMockito.when(mockGetResp.getResultCode())
-                .thenReturn(Response.Status.OK.getStatusCode())
-                .thenReturn(Response.Status.NOT_FOUND.getStatusCode())
-                .thenReturn(Response.Status.NOT_FOUND.getStatusCode())
-                .thenReturn(Response.Status.OK.getStatusCode());
-        // @formatter:on
-        PowerMockito.when(
-                mockRestClient.getResource(Mockito.anyString(), Mockito.anyString(), Mockito.any(MediaType.class)))
-                .thenReturn(mockGetResp);
-
-        // PUT operation
-        OperationResult mockPutResp = PowerMockito.mock(OperationResult.class);
-
-        PowerMockito.when(mockPutResp.getResultCode()).thenReturn(Response.Status.CREATED.getStatusCode());
-        PowerMockito.when(mockRestClient.putResource(Mockito.anyString(), Mockito.anyString(), Mockito.anyString(),
-                Mockito.any(MediaType.class))).thenReturn(mockPutResp);
-
-        // Example VNF Catalog with
-        VnfCatalogArtifactHandler vnfCAH = new VnfCatalogArtifactHandler(config);
-        String examplePath = "src/test/resources/imagedataexample.json";
-        byte[] encoded = Files.readAllBytes(Paths.get(examplePath));
-        List<Artifact> artifacts = new ArrayList<Artifact>();
-        artifacts.add(new VnfCatalogArtifact(new String(encoded, "utf-8")));
-
-        assertTrue(vnfCAH.pushArtifacts(artifacts, "test", new ArrayList<Artifact>(), mockRestClient));
-
-        // Only two of the VNF images should be pushed
-        ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
-        AaiRestClient r = Mockito.verify(mockRestClient, Mockito.times(2));
-        r.putResource(Mockito.anyString(), argument.capture(), Mockito.anyString(), Mockito.any(MediaType.class));
-        assertTrue(argument.getAllValues().get(0).contains("3.16.9"));
-        assertTrue(argument.getAllValues().get(0).contains("VM00"));
-        assertTrue(argument.getAllValues().get(1).contains("3.16.1"));
-        assertTrue(argument.getAllValues().get(1).contains("VM01"));
-    }
-
-}
diff --git a/src/test/java/org/onap/aai/modelloader/entity/model/AAIRestClientTest.java b/src/test/java/org/onap/aai/modelloader/entity/model/AAIRestClientTest.java
deleted file mode 100644 (file)
index ecf37d1..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-/**
- * ============LICENSE_START==========================================
- * org.onap.aai
- * ===================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ===================================================================
- * 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.aai.modelloader.entity.model;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import com.sun.jersey.api.client.ClientHandlerException;
-import java.io.IOException;
-import java.security.KeyManagementException;
-import java.security.KeyStoreException;
-import java.security.NoSuchAlgorithmException;
-import java.security.UnrecoverableKeyException;
-import java.security.cert.CertificateException;
-import java.util.Properties;
-import javax.ws.rs.core.MediaType;
-import org.junit.Before;
-import org.junit.Test;
-import org.onap.aai.modelloader.config.ModelLoaderConfig;
-import org.onap.aai.modelloader.restclient.AaiRestClient;
-import org.onap.aai.modelloader.restclient.BabelServiceClient;
-import org.onap.aai.modelloader.restclient.BabelServiceClient.BabelServiceException;
-
-/**
- * No-Mock tests
- * 
- * Because Jacoco (and other coverage tools) can't cope with mocked classes under some circumstances, coverage is/was
- * falsely reported as < 50%. Hence these duplicated but non-mock tests to address this, for ONAP reasons.
- * 
- * This particular class is to help make up the remaining gaps in test coverage to 50%.
- * 
- * @author andrewdo
- *
- */
-
-
-public class AAIRestClientTest {
-
-    private static final String CONFIG_FILE = "model-loader.properties";
-
-    private ModelLoaderConfig config;
-    private Properties configProperties;
-
-    @Before
-    public void setup() throws IOException {
-        configProperties = new Properties();
-        configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
-        config = new ModelLoaderConfig(configProperties, null);
-    }
-
-    @Test
-    public void testRestClient() {
-
-        AaiRestClient arc = new AaiRestClient(config);
-
-        arc.deleteResource("testurl", "1", "xxx");
-
-        arc.getAndDeleteResource("testurl", "xxx");
-
-        arc.getResource("testurl", "xxx", MediaType.APPLICATION_ATOM_XML_TYPE);
-
-        arc.postResource("testurl", "payload", "xxx", MediaType.APPLICATION_ATOM_XML_TYPE);
-
-        arc.putResource("testurl", "payload", "xxx", MediaType.APPLICATION_ATOM_XML_TYPE);
-
-        try {
-            arc.wait(1);
-        } catch (Exception e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        }
-    }
-
-    @Test
-    public void testBabelClient() {
-
-        ModelLoaderConfig mockedConfig = mock(ModelLoaderConfig.class);
-
-        when(mockedConfig.getBabelKeyStorePath()).thenReturn(null);
-
-        try {
-
-            BabelServiceClient bsc = new BabelServiceClient(mockedConfig);
-
-            byte[] artifactPayload = new byte[11];
-
-            bsc.postArtifact(artifactPayload, "artifactName", "artifactVersion", "transactionId");
-
-
-        } catch (UnrecoverableKeyException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (KeyManagementException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (NoSuchAlgorithmException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (KeyStoreException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (CertificateException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (IOException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (BabelServiceException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-        } catch (ClientHandlerException e) {
-            // TODO Auto-generated catch block
-            e.printStackTrace();
-            System.out.println("This is expected!");
-        }
-
-
-    }
-}
diff --git a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManagerMockTest.java b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDeploymentManagerMockTest.java
deleted file mode 100644 (file)
index 396cc03..0000000
+++ /dev/null
@@ -1,274 +0,0 @@
-/**
- * ============LICENSE_START==========================================
- * org.onap.aai
- * ===================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ===================================================================
- * 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.aai.modelloader.notification;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.any;
-import static org.mockito.Matchers.eq;
-import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithCatalogFile;
-import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithOneOfEach;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.onap.aai.babel.service.data.BabelArtifact;
-import org.onap.aai.modelloader.config.ModelLoaderConfig;
-import org.onap.aai.modelloader.entity.Artifact;
-import org.onap.aai.modelloader.entity.catalog.VnfCatalogArtifact;
-import org.onap.aai.modelloader.entity.catalog.VnfCatalogArtifactHandler;
-import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
-import org.onap.aai.modelloader.entity.model.ModelArtifactHandler;
-import org.onap.aai.modelloader.extraction.InvalidArchiveException;
-import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
-import org.onap.aai.modelloader.util.ArtifactTestUtils;
-import org.openecomp.sdc.api.IDistributionClient;
-import org.openecomp.sdc.api.notification.INotificationData;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.reflect.Whitebox;
-
-/**
- * Tests {@link ArtifactDeploymentManager }
- */
-public class ArtifactDeploymentManagerMockTest {
-
-    private static final String CONFIG_FILE = "model-loader.properties";
-    private static final String SHOULD_HAVE_RETURNED_FALSE = "This should have returned false";
-
-    private Properties configProperties;
-    private ArtifactDeploymentManager manager;
-
-    private IDistributionClient mockDistributionClient;
-    private ModelArtifactHandler mockModelArtifactHandler;
-    private NotificationPublisher mockNotificationPublisher;
-    private VnfCatalogArtifactHandler mockVnfCatalogArtifactHandler;
-
-    @Before
-    public void setup() throws IOException {
-        configProperties = new Properties();
-        configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
-        ModelLoaderConfig config = new ModelLoaderConfig(configProperties, null);
-
-        mockDistributionClient = PowerMockito.mock(IDistributionClient.class);
-        mockModelArtifactHandler = PowerMockito.mock(ModelArtifactHandler.class);
-        mockNotificationPublisher = PowerMockito.mock(NotificationPublisher.class);
-        mockVnfCatalogArtifactHandler = PowerMockito.mock(VnfCatalogArtifactHandler.class);
-
-        manager = new ArtifactDeploymentManager(mockDistributionClient, config);
-
-        Whitebox.setInternalState(manager, mockModelArtifactHandler);
-        Whitebox.setInternalState(manager, mockNotificationPublisher);
-        Whitebox.setInternalState(manager, mockVnfCatalogArtifactHandler);
-    }
-
-    @After
-    public void tearDown() {
-        configProperties = null;
-        mockDistributionClient = null;
-        mockModelArtifactHandler = null;
-        mockNotificationPublisher = null;
-        mockVnfCatalogArtifactHandler = null;
-        manager = null;
-    }
-/*
-    @Test
-    public void deploy_csarDeploymentsFailed() throws IOException, BabelArtifactParsingException {
-        ArtifactTestUtils artifactTestUtils = new ArtifactTestUtils();
-        INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
-        byte[] xml = artifactTestUtils.loadResource("convertedYmls/AAI-SCP-Test-VSP-resource-1.0.xml");
-        List<BabelArtifact> toscaArtifacts = setupTest(xml, data);
-        List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
-
-        PowerMockito.when(
-                mockModelArtifactHandler.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
-                .thenReturn(false);
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data,
-                data.getServiceArtifacts().get(0));
-
-        assertFalse(SHOULD_HAVE_RETURNED_FALSE,
-                manager.deploy(data, data.getServiceArtifacts(), modelArtifacts, new ArrayList<>()));
-
-        Mockito.verify(mockModelArtifactHandler).pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(),
-                any());
-        Mockito.verify(mockVnfCatalogArtifactHandler, Mockito.never()).pushArtifacts(eq(modelArtifacts),
-                eq(data.getDistributionID()), any(), any());
-        Mockito.verify(mockModelArtifactHandler).rollback(eq(new ArrayList<Artifact>()), eq(data.getDistributionID()),
-                any());
-        Mockito.verify(mockVnfCatalogArtifactHandler, Mockito.never()).rollback(eq(new ArrayList<Artifact>()),
-                eq(data.getDistributionID()), any());
-        Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data,
-                data.getServiceArtifacts().get(0));
-    }
-*/
-    private List<BabelArtifact> setupTest(byte[] xml, INotificationData data) throws IOException {
-        List<BabelArtifact> toscaArtifacts = new ArrayList<>();
-        org.openecomp.sdc.api.notification.IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
-
-        BabelArtifact xmlArtifact =
-                new BabelArtifact(artifactInfo.getArtifactName(), BabelArtifact.ArtifactType.MODEL, new String(xml));
-        toscaArtifacts.add(xmlArtifact);
-
-        return toscaArtifacts;
-    }
-
-    @Test
-    public void deploy_catalogDeploymentsFailed()
-            throws IOException, BabelArtifactParsingException, InvalidArchiveException {
-        INotificationData data = getNotificationDataWithCatalogFile();
-
-        List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
-        catalogFiles.add(new VnfCatalogArtifact("Some catalog content"));
-
-        PowerMockito.when(mockModelArtifactHandler.pushArtifacts(any(), any(), any(), any())).thenReturn(true);
-        PowerMockito.when(mockVnfCatalogArtifactHandler.pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
-                any(), any())).thenReturn(false);
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data,
-                data.getServiceArtifacts().get(0));
-
-        assertFalse(SHOULD_HAVE_RETURNED_FALSE,
-                manager.deploy(data, data.getServiceArtifacts(), new ArrayList<>(), catalogFiles));
-
-        Mockito.verify(mockModelArtifactHandler).pushArtifacts(eq(new ArrayList<Artifact>()),
-                eq(data.getDistributionID()), any(), any());
-        Mockito.verify(mockVnfCatalogArtifactHandler).pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
-                any(), any());
-        Mockito.verify(mockModelArtifactHandler).rollback(eq(new ArrayList<Artifact>()), eq(data.getDistributionID()),
-                any());
-        Mockito.verify(mockVnfCatalogArtifactHandler).rollback(eq(new ArrayList<Artifact>()),
-                eq(data.getDistributionID()), any());
-        Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data,
-                data.getServiceArtifacts().get(0));
-    }
-
-/*
-    @Test
-    public void deploy_bothDeploymentsFailed()
-            throws IOException, BabelArtifactParsingException, InvalidArchiveException {
-        doFailedCombinedTests(false, false);
-    }
-*/
-/*
-    @Test
-    public void deploy_modelsFailedCatalogsOK()
-            throws IOException, BabelArtifactParsingException, InvalidArchiveException {
-        doFailedCombinedTests(false, true);
-    }
-*/
-/*
-    @Test
-    public void deploy_catalogsFailedModelsOK()
-            throws IOException, BabelArtifactParsingException, InvalidArchiveException {
-        doFailedCombinedTests(true, false);
-    }
-*/
-    private void doFailedCombinedTests(boolean modelsOK, boolean catalogsOK)
-            throws IOException, BabelArtifactParsingException, InvalidArchiveException {
-        INotificationData data = getNotificationDataWithOneOfEach();
-        ArtifactTestUtils artifactTestUtils = new ArtifactTestUtils();
-        byte[] xml = artifactTestUtils.loadResource("convertedYmls/AAI-SCP-Test-VSP-resource-1.0.xml");
-        List<BabelArtifact> toscaArtifacts = setupTest(xml, data);
-        List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
-
-        List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
-        catalogFiles.add(new VnfCatalogArtifact("Some catalog content"));
-
-        PowerMockito.when(mockVnfCatalogArtifactHandler.pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
-                any(), any())).thenReturn(catalogsOK);
-        PowerMockito.when(
-                mockModelArtifactHandler.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
-                .thenReturn(modelsOK);
-
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDeploySuccess(mockDistributionClient, data,
-                data.getServiceArtifacts().get(0));
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data,
-                data.getServiceArtifacts().get(0));
-
-        assertFalse(SHOULD_HAVE_RETURNED_FALSE,
-                manager.deploy(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles));
-
-        // Catalog artifacts are only pushed if models are successful.
-        Mockito.verify(mockModelArtifactHandler).pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(),
-                any());
-        if (modelsOK) {
-            Mockito.verify(mockVnfCatalogArtifactHandler).pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
-                    any(), any());
-        }
-
-        if (modelsOK && catalogsOK) {
-            Mockito.verify(mockNotificationPublisher).publishDeploySuccess(mockDistributionClient, data,
-                    data.getServiceArtifacts().get(0));
-            Mockito.verify(mockModelArtifactHandler, Mockito.never()).rollback(any(), any(), any());
-            Mockito.verify(mockVnfCatalogArtifactHandler, Mockito.never()).rollback(any(), any(), any());
-        } else {
-            Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data,
-                    data.getServiceArtifacts().get(0));
-            if (modelsOK) {
-                Mockito.verify(mockModelArtifactHandler).rollback(eq(new ArrayList<Artifact>()),
-                        eq(data.getDistributionID()), any());
-                Mockito.verify(mockVnfCatalogArtifactHandler).rollback(eq(new ArrayList<Artifact>()),
-                        eq(data.getDistributionID()), any());
-            } else {
-                Mockito.verify(mockModelArtifactHandler).rollback(eq(new ArrayList<Artifact>()),
-                        eq(data.getDistributionID()), any());
-                Mockito.verify(mockVnfCatalogArtifactHandler, Mockito.never()).rollback(any(), any(), any());
-            }
-        }
-    }
-
-/*
-    @Test
-    public void deploy_bothOK() throws IOException, BabelArtifactParsingException, InvalidArchiveException {
-        INotificationData data = getNotificationDataWithOneOfEach();
-        ArtifactTestUtils artifactTestUtils = new ArtifactTestUtils();
-        byte[] xml = artifactTestUtils.loadResource("convertedYmls/AAI-SCP-Test-VSP-resource-1.0.xml");
-        List<BabelArtifact> toscaArtifacts = setupTest(xml, data);
-        List<Artifact> modelArtifacts = new BabelArtifactConverter().convertToModel(toscaArtifacts);
-
-        List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
-        catalogFiles.add(new VnfCatalogArtifact("Some catalog content"));
-
-        PowerMockito.when(mockVnfCatalogArtifactHandler.pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
-                any(), any())).thenReturn(true);
-        PowerMockito.when(
-                mockModelArtifactHandler.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
-                .thenReturn(true);
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDeploySuccess(mockDistributionClient, data,
-                data.getServiceArtifacts().get(0));
-
-        assertTrue("This should have returned true",
-                manager.deploy(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles));
-
-        Mockito.verify(mockVnfCatalogArtifactHandler).pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
-                any(), any());
-        Mockito.verify(mockModelArtifactHandler).pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(),
-                any());
-        Mockito.verify(mockNotificationPublisher).publishDeploySuccess(mockDistributionClient, data,
-                data.getServiceArtifacts().get(0));
-        Mockito.verify(mockModelArtifactHandler, Mockito.never()).rollback(any(), any(), any());
-        Mockito.verify(mockVnfCatalogArtifactHandler, Mockito.never()).rollback(any(), any(), any());
-    }
-*/
-}
index 9fc0760..0dcff32 100644 (file)
@@ -23,6 +23,8 @@ package org.onap.aai.modelloader.notification;
 import static org.junit.Assert.assertFalse;
 import static org.mockito.Matchers.any;
 import static org.mockito.Matchers.eq;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithCatalogFile;
 import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithOneOfEach;
 
@@ -33,8 +35,8 @@ import java.util.Properties;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
 import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
 import org.onap.aai.babel.service.data.BabelArtifact;
 import org.onap.aai.modelloader.config.ModelLoaderConfig;
 import org.onap.aai.modelloader.entity.Artifact;
@@ -45,15 +47,12 @@ import org.onap.aai.modelloader.entity.model.ModelArtifactHandler;
 import org.onap.aai.modelloader.extraction.InvalidArchiveException;
 import org.onap.aai.modelloader.util.ArtifactTestUtils;
 import org.openecomp.sdc.api.IDistributionClient;
+import org.openecomp.sdc.api.notification.IArtifactInfo;
 import org.openecomp.sdc.api.notification.INotificationData;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.Whitebox;
 
 /**
  * Tests {@link ArtifactDeploymentManager }
  */
-@RunWith(PowerMockRunner.class)
 public class ArtifactDeploymentManagerTest {
 
     private static final String CONFIG_FILE = "model-loader.properties";
@@ -73,16 +72,16 @@ public class ArtifactDeploymentManagerTest {
         configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
         ModelLoaderConfig config = new ModelLoaderConfig(configProperties, null);
 
-        mockDistributionClient = PowerMockito.mock(IDistributionClient.class);
-        mockModelArtifactHandler = PowerMockito.mock(ModelArtifactHandler.class);
-        mockNotificationPublisher = PowerMockito.mock(NotificationPublisher.class);
-        mockVnfCatalogArtifactHandler = PowerMockito.mock(VnfCatalogArtifactHandler.class);
+        mockDistributionClient = mock(IDistributionClient.class);
+        mockModelArtifactHandler = mock(ModelArtifactHandler.class);
+        mockNotificationPublisher = mock(NotificationPublisher.class);
+        mockVnfCatalogArtifactHandler = mock(VnfCatalogArtifactHandler.class);
 
         manager = new ArtifactDeploymentManager(mockDistributionClient, config);
 
-        Whitebox.setInternalState(manager, mockModelArtifactHandler);
-        Whitebox.setInternalState(manager, mockNotificationPublisher);
-        Whitebox.setInternalState(manager, mockVnfCatalogArtifactHandler);
+        Whitebox.setInternalState(manager, "modelArtifactHandler", mockModelArtifactHandler);
+        Whitebox.setInternalState(manager, "notificationPublisher", mockNotificationPublisher);
+        Whitebox.setInternalState(manager, "vnfCatalogArtifactHandler", mockVnfCatalogArtifactHandler);
     }
 
     @After
@@ -98,7 +97,7 @@ public class ArtifactDeploymentManagerTest {
 
     private List<BabelArtifact> setupTest(byte[] xml, INotificationData data) throws IOException {
         List<BabelArtifact> toscaArtifacts = new ArrayList<>();
-        org.openecomp.sdc.api.notification.IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
+        IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
 
         BabelArtifact xmlArtifact =
                 new BabelArtifact(artifactInfo.getArtifactName(), BabelArtifact.ArtifactType.MODEL, new String(xml));
@@ -115,10 +114,10 @@ public class ArtifactDeploymentManagerTest {
         List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
         catalogFiles.add(new VnfCatalogArtifact("Some catalog content"));
 
-        PowerMockito.when(mockModelArtifactHandler.pushArtifacts(any(), any(), any(), any())).thenReturn(true);
-        PowerMockito.when(mockVnfCatalogArtifactHandler.pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
-                any(), any())).thenReturn(false);
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data,
+        when(mockModelArtifactHandler.pushArtifacts(any(), any(), any(), any())).thenReturn(true);
+        when(mockVnfCatalogArtifactHandler.pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()), any(), any()))
+                .thenReturn(false);
+        Mockito.doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data,
                 data.getServiceArtifacts().get(0));
 
         assertFalse(SHOULD_HAVE_RETURNED_FALSE,
@@ -136,7 +135,6 @@ public class ArtifactDeploymentManagerTest {
                 data.getServiceArtifacts().get(0));
     }
 
-
     private void doFailedCombinedTests(boolean modelsOK, boolean catalogsOK)
             throws IOException, BabelArtifactParsingException, InvalidArchiveException {
         INotificationData data = getNotificationDataWithOneOfEach();
@@ -148,15 +146,14 @@ public class ArtifactDeploymentManagerTest {
         List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
         catalogFiles.add(new VnfCatalogArtifact("Some catalog content"));
 
-        PowerMockito.when(mockVnfCatalogArtifactHandler.pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()),
-                any(), any())).thenReturn(catalogsOK);
-        PowerMockito.when(
-                mockModelArtifactHandler.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
+        when(mockVnfCatalogArtifactHandler.pushArtifacts(eq(catalogFiles), eq(data.getDistributionID()), any(), any()))
+                .thenReturn(catalogsOK);
+        when(mockModelArtifactHandler.pushArtifacts(eq(modelArtifacts), eq(data.getDistributionID()), any(), any()))
                 .thenReturn(modelsOK);
 
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDeploySuccess(mockDistributionClient, data,
+        Mockito.doNothing().when(mockNotificationPublisher).publishDeploySuccess(mockDistributionClient, data,
                 data.getServiceArtifacts().get(0));
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data,
+        Mockito.doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data,
                 data.getServiceArtifacts().get(0));
 
         assertFalse(SHOULD_HAVE_RETURNED_FALSE,
diff --git a/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerNoMockTest.java b/src/test/java/org/onap/aai/modelloader/notification/ArtifactDownloadManagerNoMockTest.java
deleted file mode 100644 (file)
index 01f41cf..0000000
+++ /dev/null
@@ -1,275 +0,0 @@
-/**
- * ============LICENSE_START==========================================
- * org.onap.aai
- * ===================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ===================================================================
- * 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.aai.modelloader.notification;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithInvalidType;
-import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithModelQuerySpec;
-import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithOneService;
-import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Properties;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Matchers;
-import org.mockito.Mockito;
-import org.onap.aai.babel.service.data.BabelArtifact;
-import org.onap.aai.modelloader.config.ModelLoaderConfig;
-import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
-import org.onap.aai.modelloader.restclient.BabelServiceClient;
-import org.onap.aai.modelloader.restclient.BabelServiceClient.BabelServiceException;
-import org.onap.aai.modelloader.util.ArtifactTestUtils;
-import org.openecomp.sdc.api.IDistributionClient;
-import org.openecomp.sdc.api.notification.IArtifactInfo;
-import org.openecomp.sdc.api.notification.INotificationData;
-import org.openecomp.sdc.api.results.IDistributionClientDownloadResult;
-import org.openecomp.sdc.impl.DistributionClientDownloadResultImpl;
-import org.openecomp.sdc.utils.DistributionActionResultEnum;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.reflect.Whitebox;
-
-/**
- * No-Mock tests
- * 
- * Because Jacoco (and other coverage tools) can't cope with mocked classes under some circumstances, coverage is/was
- * falsely reported as < 50%. Hence these duplicated but non-mock tests to address this, for ONAP reasons.
- * 
- * @author andrewdo
- *
- */
-
-/**
- * Tests {@link ArtifactDownloadManager}
- */
-@PowerMockIgnore({"sun.security.ssl.*", "javax.net.ssl.*"})
-@PrepareForTest({ArtifactDownloadManager.class})
-public class ArtifactDownloadManagerNoMockTest {
-
-    private static final String FALSE_SHOULD_HAVE_BEEN_RETURNED = "A value of 'false' should have been returned";
-    private static final String OOPS = "oops";
-    private static final String TRUE_SHOULD_HAVE_BEEN_RETURNED = "A value of 'true' should have been returned";
-
-    private ArtifactDownloadManager downloadManager;
-    private BabelServiceClient mockBabelClient;
-    private IDistributionClient mockDistributionClient;
-    private NotificationPublisher mockNotificationPublisher;
-    private BabelArtifactConverter mockBabelArtifactConverter;
-
-    @Before
-    public void setup() throws Exception {
-        mockBabelClient = PowerMockito.mock(BabelServiceClient.class);
-        mockDistributionClient = PowerMockito.mock(IDistributionClient.class);
-        mockNotificationPublisher = PowerMockito.mock(NotificationPublisher.class);
-        mockBabelArtifactConverter = PowerMockito.mock(BabelArtifactConverter.class);
-
-        Properties configProperties = new Properties();
-        configProperties.load(this.getClass().getClassLoader().getResourceAsStream("model-loader.properties"));
-        downloadManager =
-                new ArtifactDownloadManager(mockDistributionClient, new ModelLoaderConfig(configProperties, "."));
-
-        PowerMockito.whenNew(BabelServiceClient.class).withAnyArguments().thenReturn(mockBabelClient);
-
-        Whitebox.setInternalState(downloadManager, mockNotificationPublisher);
-        Whitebox.setInternalState(downloadManager, mockBabelArtifactConverter);
-    }
-
-    @After
-    public void tearDown() {
-        downloadManager = null;
-        mockDistributionClient = null;
-        mockNotificationPublisher = null;
-    }
-
-    @Test
-    public void downloadArtifacts_emptyListSupplied() {
-        List<org.onap.aai.modelloader.entity.Artifact> modelFiles = new ArrayList<>();
-        List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
-
-        assertTrue(TRUE_SHOULD_HAVE_BEEN_RETURNED, downloadManager
-                .downloadArtifacts(getNotificationDataWithOneService(), new ArrayList<>(), modelFiles, catalogFiles));
-
-        Mockito.verifyZeroInteractions(mockBabelClient, mockDistributionClient, mockNotificationPublisher,
-                mockBabelArtifactConverter);
-    }
-
-    @Test
-    public void downloadArtifacts_artifactDownloadFails() {
-        INotificationData data = getNotificationDataWithOneService();
-        IArtifactInfo artifact = data.getServiceArtifacts().get(0);
-        PowerMockito.when(mockDistributionClient.download(artifact))
-                .thenReturn(createDistributionClientDownloadResult(DistributionActionResultEnum.FAIL, OOPS, null));
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDownloadFailure(mockDistributionClient, data,
-                artifact, OOPS);
-
-        assertFalse(FALSE_SHOULD_HAVE_BEEN_RETURNED,
-                downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), null, null));
-
-        Mockito.verify(mockDistributionClient).download(artifact);
-        Mockito.verify(mockNotificationPublisher).publishDownloadFailure(mockDistributionClient, data, artifact, OOPS);
-
-        Mockito.verifyZeroInteractions(mockBabelClient, mockBabelArtifactConverter);
-    }
-
-    private IDistributionClientDownloadResult createDistributionClientDownloadResult(
-            DistributionActionResultEnum status, String message, byte[] payload) {
-        IDistributionClientDownloadResult downloadResult = new DistributionClientDownloadResultImpl(status, message);
-
-        ((DistributionClientDownloadResultImpl) downloadResult).setArtifactPayload(payload);
-
-        return downloadResult;
-    }
-
-
-    /**
-     * Test disabled as exception handling needs to be reworked
-     * 
-     * @throws IOException
-     */
-    @SuppressWarnings("unchecked")
-    @Test
-    public void downloadArtifacts_invalidToscaCsarFile() throws IOException, BabelServiceException {
-        INotificationData data = getNotificationDataWithToscaCsarFile();
-        IArtifactInfo artifact = data.getServiceArtifacts().get(0);
-        PowerMockito.when(mockDistributionClient.download(artifact)).thenReturn(createDistributionClientDownloadResult(
-                DistributionActionResultEnum.SUCCESS, null, "This is not a valid Tosca CSAR File".getBytes()));
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data,
-                artifact);
-        PowerMockito.when(mockBabelClient.postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(),
-                Matchers.anyString())).thenThrow(BabelServiceException.class);
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data,
-                artifact);
-
-        assertFalse(FALSE_SHOULD_HAVE_BEEN_RETURNED,
-                downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), null, null));
-
-        Mockito.verify(mockDistributionClient).download(artifact);
-        Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact);
-
-        Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifact);
-
-        Mockito.verifyZeroInteractions(mockBabelArtifactConverter);
-
-    }
-
-    @Test
-    public void downloadArtifacts_invalidModelQuerySpec() {
-        INotificationData data = getNotificationDataWithModelQuerySpec();
-        IArtifactInfo artifact = data.getServiceArtifacts().get(0);
-
-        List<org.onap.aai.modelloader.entity.Artifact> modelArtifacts = new ArrayList<>();
-
-        PowerMockito.when(mockDistributionClient.download(artifact)).thenReturn(createDistributionClientDownloadResult(
-                DistributionActionResultEnum.SUCCESS, null, "This is not a valid Model Query Spec".getBytes()));
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data,
-                artifact);
-
-        assertFalse(FALSE_SHOULD_HAVE_BEEN_RETURNED,
-                downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, null));
-
-        Mockito.verify(mockDistributionClient).download(artifact);
-        Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact);
-        Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifact);
-
-        Mockito.verifyZeroInteractions(mockBabelClient, mockBabelArtifactConverter);
-    }
-
-
-    private void setupValidDownloadCsarMocks(INotificationData data, IArtifactInfo artifactInfo,
-            ArtifactTestUtils artifactTestUtils) throws IOException, BabelServiceException {
-        PowerMockito.when(mockDistributionClient.download(artifactInfo))
-                .thenReturn(createDistributionClientDownloadResult(DistributionActionResultEnum.SUCCESS, null,
-                        artifactTestUtils.loadResource("compressedArtifacts/service-VscpaasTest-csar.csar")));
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data,
-                artifactInfo);
-        PowerMockito.when(mockBabelClient.postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(),
-                Matchers.anyString())).thenReturn(createBabelArtifacts());
-    }
-
-    private List<BabelArtifact> createBabelArtifacts() {
-        List<BabelArtifact> artifactList = new ArrayList<>();
-        artifactList.add(new BabelArtifact("ModelArtifact", BabelArtifact.ArtifactType.MODEL, "Some model payload"));
-        artifactList.add(new BabelArtifact("VNFCArtifact", BabelArtifact.ArtifactType.VNFCATALOG, "Some VNFC payload"));
-        return artifactList;
-    }
-
-    @Test
-    public void downloadArtifacts_validModelQuerySpec()
-            throws IOException, BabelServiceException, BabelArtifactParsingException {
-        ArtifactTestUtils artifactTestUtils = new ArtifactTestUtils();
-        INotificationData data = getNotificationDataWithModelQuerySpec();
-        IArtifactInfo artifact = data.getServiceArtifacts().get(0);
-        setupValidModelQuerySpecMocks(artifactTestUtils, data, artifact);
-
-        List<org.onap.aai.modelloader.entity.Artifact> modelFiles = new ArrayList<>();
-        List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
-        assertTrue(TRUE_SHOULD_HAVE_BEEN_RETURNED,
-                downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelFiles, catalogFiles));
-
-        assertTrue("There should have been some model artifacts", !modelFiles.isEmpty());
-        assertTrue("There should not have been any catalog artifacts", catalogFiles.isEmpty());
-
-        Mockito.verify(mockDistributionClient).download(artifact);
-        Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact);
-
-        Mockito.verifyZeroInteractions(mockBabelClient, mockBabelArtifactConverter);
-    }
-
-    private void setupValidModelQuerySpecMocks(ArtifactTestUtils artifactTestUtils, INotificationData data,
-            IArtifactInfo artifact) throws IOException {
-        PowerMockito.when(mockDistributionClient.download(artifact))
-                .thenReturn(createDistributionClientDownloadResult(DistributionActionResultEnum.SUCCESS, null,
-                        artifactTestUtils.loadResource("models/named-query-wan-connector.xml")));
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data,
-                artifact);
-    }
-
-
-
-    @Test
-    public void downloadArtifacts_invalidType()
-            throws IOException, BabelServiceException, BabelArtifactParsingException {
-        INotificationData data = getNotificationDataWithInvalidType();
-        IArtifactInfo artifact = data.getServiceArtifacts().get(0);
-
-        List<org.onap.aai.modelloader.entity.Artifact> catalogArtifacts = new ArrayList<>();
-
-        PowerMockito.when(mockDistributionClient.download(artifact)).thenReturn(createDistributionClientDownloadResult(
-                DistributionActionResultEnum.SUCCESS, null, "This content does not matter.".getBytes()));
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data,
-                artifact);
-
-        assertFalse(FALSE_SHOULD_HAVE_BEEN_RETURNED,
-                downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), null, catalogArtifacts));
-
-        Mockito.verify(mockDistributionClient).download(artifact);
-        Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact);
-        Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifact);
-
-        Mockito.verifyZeroInteractions(mockBabelClient, mockBabelArtifactConverter);
-    }
-}
index c4ba991..71cd8af 100644 (file)
@@ -22,26 +22,36 @@ package org.onap.aai.modelloader.notification;
 
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
 import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithInvalidType;
 import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithModelQuerySpec;
+import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithOneOfEach;
 import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithOneService;
 import static org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile;
 
 import java.io.IOException;
+import java.security.KeyManagementException;
+import java.security.KeyStoreException;
+import java.security.NoSuchAlgorithmException;
+import java.security.UnrecoverableKeyException;
+import java.security.cert.CertificateException;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Properties;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-import org.junit.runner.RunWith;
 import org.mockito.Matchers;
 import org.mockito.Mockito;
+import org.mockito.internal.util.reflection.Whitebox;
 import org.onap.aai.babel.service.data.BabelArtifact;
 import org.onap.aai.modelloader.config.ModelLoaderConfig;
 import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
 import org.onap.aai.modelloader.restclient.BabelServiceClient;
 import org.onap.aai.modelloader.restclient.BabelServiceClient.BabelServiceException;
+import org.onap.aai.modelloader.restclient.BabelServiceClientFactory;
 import org.onap.aai.modelloader.util.ArtifactTestUtils;
 import org.openecomp.sdc.api.IDistributionClient;
 import org.openecomp.sdc.api.notification.IArtifactInfo;
@@ -49,18 +59,10 @@ import org.openecomp.sdc.api.notification.INotificationData;
 import org.openecomp.sdc.api.results.IDistributionClientDownloadResult;
 import org.openecomp.sdc.impl.DistributionClientDownloadResultImpl;
 import org.openecomp.sdc.utils.DistributionActionResultEnum;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
-import org.powermock.reflect.Whitebox;
 
 /**
  * Tests {@link ArtifactDownloadManager}
  */
-@RunWith(PowerMockRunner.class)
-@PowerMockIgnore({"sun.security.ssl.*", "javax.net.ssl.*"})
-@PrepareForTest({ArtifactDownloadManager.class})
 public class ArtifactDownloadManagerTest {
 
     private static final String FALSE_SHOULD_HAVE_BEEN_RETURNED = "A value of 'false' should have been returned";
@@ -72,23 +74,24 @@ public class ArtifactDownloadManagerTest {
     private IDistributionClient mockDistributionClient;
     private NotificationPublisher mockNotificationPublisher;
     private BabelArtifactConverter mockBabelArtifactConverter;
+    private BabelServiceClientFactory mockClientFactory;
 
     @Before
     public void setup() throws Exception {
-        mockBabelClient = PowerMockito.mock(BabelServiceClient.class);
-        mockDistributionClient = PowerMockito.mock(IDistributionClient.class);
-        mockNotificationPublisher = PowerMockito.mock(NotificationPublisher.class);
-        mockBabelArtifactConverter = PowerMockito.mock(BabelArtifactConverter.class);
+        mockBabelClient = mock(BabelServiceClient.class);
+        mockDistributionClient = mock(IDistributionClient.class);
+        mockNotificationPublisher = mock(NotificationPublisher.class);
+        mockBabelArtifactConverter = mock(BabelArtifactConverter.class);
+        mockClientFactory = mock(BabelServiceClientFactory.class);
+        when(mockClientFactory.create(Mockito.any())).thenReturn(mockBabelClient);
 
         Properties configProperties = new Properties();
         configProperties.load(this.getClass().getClassLoader().getResourceAsStream("model-loader.properties"));
-        downloadManager =
-                new ArtifactDownloadManager(mockDistributionClient, new ModelLoaderConfig(configProperties, "."));
+        downloadManager = new ArtifactDownloadManager(mockDistributionClient,
+                new ModelLoaderConfig(configProperties, "."), mockClientFactory);
 
-        PowerMockito.whenNew(BabelServiceClient.class).withAnyArguments().thenReturn(mockBabelClient);
-
-        Whitebox.setInternalState(downloadManager, mockNotificationPublisher);
-        Whitebox.setInternalState(downloadManager, mockBabelArtifactConverter);
+        Whitebox.setInternalState(downloadManager, "notificationPublisher", mockNotificationPublisher);
+        Whitebox.setInternalState(downloadManager, "babelArtifactConverter", mockBabelArtifactConverter);
     }
 
     @After
@@ -114,10 +117,10 @@ public class ArtifactDownloadManagerTest {
     public void downloadArtifacts_artifactDownloadFails() {
         INotificationData data = getNotificationDataWithOneService();
         IArtifactInfo artifact = data.getServiceArtifacts().get(0);
-        PowerMockito.when(mockDistributionClient.download(artifact))
+        when(mockDistributionClient.download(artifact))
                 .thenReturn(createDistributionClientDownloadResult(DistributionActionResultEnum.FAIL, OOPS, null));
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDownloadFailure(mockDistributionClient, data,
-                artifact, OOPS);
+        doNothing().when(mockNotificationPublisher).publishDownloadFailure(mockDistributionClient, data, artifact,
+                OOPS);
 
         assertFalse(FALSE_SHOULD_HAVE_BEEN_RETURNED,
                 downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), null, null));
@@ -137,15 +140,19 @@ public class ArtifactDownloadManagerTest {
         return downloadResult;
     }
 
+    @Test
+    public void downloadArtifacts_noSuchAlgorithmExceptionFromCreatingBabelClient() throws Exception {
+        doCreateBabelClientFailureTest(NoSuchAlgorithmException.class);
+    }
+
     @SuppressWarnings("unchecked")
     private void doCreateBabelClientFailureTest(Class<? extends Throwable> exception) throws Exception {
-        PowerMockito.whenNew(BabelServiceClient.class).withAnyArguments().thenThrow(exception);
+        when(mockClientFactory.create(Mockito.any())).thenThrow(exception);
 
         INotificationData data = getNotificationDataWithToscaCsarFile();
         IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
         setupValidDownloadCsarMocks(data, artifactInfo, new ArtifactTestUtils());
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data,
-                artifactInfo);
+        doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifactInfo);
 
         assertFalse(FALSE_SHOULD_HAVE_BEEN_RETURNED,
                 downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), null, null));
@@ -157,9 +164,34 @@ public class ArtifactDownloadManagerTest {
         Mockito.verifyZeroInteractions(mockBabelArtifactConverter);
     }
 
+    @Test
+    public void downloadArtifacts_keyStoreExceptionFromCreatingBabelClient() throws Exception {
+        doCreateBabelClientFailureTest(KeyStoreException.class);
+    }
+
+    @Test
+    public void downloadArtifacts_certificateExceptionFromCreatingBabelClient() throws Exception {
+        doCreateBabelClientFailureTest(CertificateException.class);
+    }
+
+    @Test
+    public void downloadArtifacts_iOExceptionFromCreatingBabelClient() throws Exception {
+        doCreateBabelClientFailureTest(IOException.class);
+    }
+
+    @Test
+    public void downloadArtifacts_unrecoverableKeyExceptionFromCreatingBabelClient() throws Exception {
+        doCreateBabelClientFailureTest(UnrecoverableKeyException.class);
+    }
+
+    @Test
+    public void downloadArtifacts_keyManagementExceptionFromCreatingBabelClient() throws Exception {
+        doCreateBabelClientFailureTest(KeyManagementException.class);
+    }
+
     /**
      * Test disabled as exception handling needs to be reworked
-     * 
+     *
      * @throws IOException
      */
     @SuppressWarnings("unchecked")
@@ -167,14 +199,12 @@ public class ArtifactDownloadManagerTest {
     public void downloadArtifacts_invalidToscaCsarFile() throws IOException, BabelServiceException {
         INotificationData data = getNotificationDataWithToscaCsarFile();
         IArtifactInfo artifact = data.getServiceArtifacts().get(0);
-        PowerMockito.when(mockDistributionClient.download(artifact)).thenReturn(createDistributionClientDownloadResult(
+        when(mockDistributionClient.download(artifact)).thenReturn(createDistributionClientDownloadResult(
                 DistributionActionResultEnum.SUCCESS, null, "This is not a valid Tosca CSAR File".getBytes()));
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data,
-                artifact);
-        PowerMockito.when(mockBabelClient.postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(),
+        doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact);
+        when(mockBabelClient.postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(),
                 Matchers.anyString())).thenThrow(BabelServiceException.class);
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data,
-                artifact);
+        doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifact);
 
         assertFalse(FALSE_SHOULD_HAVE_BEEN_RETURNED,
                 downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), null, null));
@@ -196,10 +226,9 @@ public class ArtifactDownloadManagerTest {
 
         List<org.onap.aai.modelloader.entity.Artifact> modelArtifacts = new ArrayList<>();
 
-        PowerMockito.when(mockDistributionClient.download(artifact)).thenReturn(createDistributionClientDownloadResult(
+        when(mockDistributionClient.download(artifact)).thenReturn(createDistributionClientDownloadResult(
                 DistributionActionResultEnum.SUCCESS, null, "This is not a valid Model Query Spec".getBytes()));
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data,
-                artifact);
+        doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact);
 
         assertFalse(FALSE_SHOULD_HAVE_BEEN_RETURNED,
                 downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, null));
@@ -211,14 +240,35 @@ public class ArtifactDownloadManagerTest {
         Mockito.verifyZeroInteractions(mockBabelClient, mockBabelArtifactConverter);
     }
 
+    @Test
+    public void downloadArtifacts_validToscaCsarFile()
+            throws IOException, BabelServiceException, BabelArtifactParsingException {
+        INotificationData data = getNotificationDataWithToscaCsarFile();
+        IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
+
+        setupValidDownloadCsarMocks(data, artifactInfo, new ArtifactTestUtils());
+
+        List<org.onap.aai.modelloader.entity.Artifact> modelArtifacts = new ArrayList<>();
+        List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
+        assertTrue(TRUE_SHOULD_HAVE_BEEN_RETURNED,
+                downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles));
+
+        assertTrue("There should not have been any catalog files", catalogFiles.size() == 0);
+
+        Mockito.verify(mockDistributionClient).download(artifactInfo);
+        Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifactInfo);
+        Mockito.verify(mockBabelClient).postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(),
+                Matchers.anyString());
+        Mockito.verify(mockBabelArtifactConverter).convertToModel(Matchers.any());
+        Mockito.verify(mockBabelArtifactConverter).convertToCatalog(Matchers.any());
+    }
+
     private void setupValidDownloadCsarMocks(INotificationData data, IArtifactInfo artifactInfo,
             ArtifactTestUtils artifactTestUtils) throws IOException, BabelServiceException {
-        PowerMockito.when(mockDistributionClient.download(artifactInfo))
+        when(mockDistributionClient.download(artifactInfo))
                 .thenReturn(createDistributionClientDownloadResult(DistributionActionResultEnum.SUCCESS, null,
                         artifactTestUtils.loadResource("compressedArtifacts/service-VscpaasTest-csar.csar")));
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data,
-                artifactInfo);
-        PowerMockito.when(mockBabelClient.postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(),
+        when(mockBabelClient.postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(),
                 Matchers.anyString())).thenReturn(createBabelArtifacts());
     }
 
@@ -253,14 +303,76 @@ public class ArtifactDownloadManagerTest {
 
     private void setupValidModelQuerySpecMocks(ArtifactTestUtils artifactTestUtils, INotificationData data,
             IArtifactInfo artifact) throws IOException {
-        PowerMockito.when(mockDistributionClient.download(artifact))
+        when(mockDistributionClient.download(artifact))
                 .thenReturn(createDistributionClientDownloadResult(DistributionActionResultEnum.SUCCESS, null,
                         artifactTestUtils.loadResource("models/named-query-wan-connector.xml")));
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data,
-                artifact);
+        doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact);
     }
 
+    @Test
+    public void downloadArtifacts_validCsarAndModelFiles()
+            throws IOException, BabelServiceException, BabelArtifactParsingException {
+        ArtifactTestUtils artifactTestUtils = new ArtifactTestUtils();
+        INotificationData data = getNotificationDataWithOneOfEach();
+        List<IArtifactInfo> artifacts = new ArrayList<>();
+
+        IArtifactInfo serviceArtifact = data.getServiceArtifacts().get(0);
+        IArtifactInfo modelSpecArtifact = data.getResources().get(1).getArtifacts().get(0);
+
+        artifacts.add(serviceArtifact);
+        artifacts.add(modelSpecArtifact);
+
+        setupValidDownloadCsarMocks(data, serviceArtifact, artifactTestUtils);
+        setupValidModelQuerySpecMocks(artifactTestUtils, data, modelSpecArtifact);
+
+        List<org.onap.aai.modelloader.entity.Artifact> modelFiles = new ArrayList<>();
+        List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
+        assertTrue(TRUE_SHOULD_HAVE_BEEN_RETURNED,
+                downloadManager.downloadArtifacts(data, artifacts, modelFiles, catalogFiles));
+
+        Mockito.verify(mockDistributionClient).download(serviceArtifact);
+        Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, serviceArtifact);
+        Mockito.verify(mockBabelClient).postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(),
+                Matchers.anyString());
+        Mockito.verify(mockBabelArtifactConverter).convertToModel(Matchers.any());
+        Mockito.verify(mockBabelArtifactConverter).convertToCatalog(Matchers.any());
+
+        Mockito.verify(mockDistributionClient).download(modelSpecArtifact);
+        Mockito.verify(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data,
+                modelSpecArtifact);
+
+        Mockito.verifyNoMoreInteractions(mockBabelClient, mockBabelArtifactConverter);
+    }
+
+    @Test
+    @SuppressWarnings("unchecked")
+    public void activateCallback_toscaToModelConverterHasProcessToscaArtifactsException() throws Exception {
+        ArtifactTestUtils artifactTestUtils = new ArtifactTestUtils();
+        INotificationData data = getNotificationDataWithToscaCsarFile();
+        IArtifactInfo artifactInfo = data.getServiceArtifacts().get(0);
+
+        when(mockDistributionClient.download(artifactInfo))
+                .thenReturn(createDistributionClientDownloadResult(DistributionActionResultEnum.SUCCESS, null,
+                        artifactTestUtils.loadResource("compressedArtifacts/service-VscpaasTest-csar.csar")));
+        when(mockBabelArtifactConverter.convertToModel(Mockito.anyList()))
+                .thenThrow(BabelArtifactParsingException.class);
+        doNothing().when(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifactInfo);
+        when(mockBabelClient.postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(),
+                Matchers.anyString())).thenReturn(createBabelArtifacts());
+
+        List<org.onap.aai.modelloader.entity.Artifact> modelArtifacts = new ArrayList<>();
+        List<org.onap.aai.modelloader.entity.Artifact> catalogFiles = new ArrayList<>();
+        assertFalse(FALSE_SHOULD_HAVE_BEEN_RETURNED,
+                downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), modelArtifacts, catalogFiles));
 
+        assertTrue("There should not have been any catalog files", catalogFiles.size() == 0);
+
+        Mockito.verify(mockDistributionClient).download(artifactInfo);
+        Mockito.verify(mockNotificationPublisher).publishDeployFailure(mockDistributionClient, data, artifactInfo);
+        Mockito.verify(mockBabelClient).postArtifact(Matchers.any(), Matchers.anyString(), Matchers.anyString(),
+                Matchers.anyString());
+        Mockito.verify(mockBabelArtifactConverter).convertToModel(Matchers.any());
+    }
 
     @Test
     public void downloadArtifacts_invalidType()
@@ -270,10 +382,9 @@ public class ArtifactDownloadManagerTest {
 
         List<org.onap.aai.modelloader.entity.Artifact> catalogArtifacts = new ArrayList<>();
 
-        PowerMockito.when(mockDistributionClient.download(artifact)).thenReturn(createDistributionClientDownloadResult(
+        when(mockDistributionClient.download(artifact)).thenReturn(createDistributionClientDownloadResult(
                 DistributionActionResultEnum.SUCCESS, null, "This content does not matter.".getBytes()));
-        PowerMockito.doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data,
-                artifact);
+        doNothing().when(mockNotificationPublisher).publishDownloadSuccess(mockDistributionClient, data, artifact);
 
         assertFalse(FALSE_SHOULD_HAVE_BEEN_RETURNED,
                 downloadManager.downloadArtifacts(data, data.getServiceArtifacts(), null, catalogArtifacts));
index 026c1e3..533a37b 100644 (file)
@@ -20,6 +20,7 @@
  */
 package org.onap.aai.modelloader.notification;
 
+import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 import static org.junit.Assert.fail;
 
@@ -27,12 +28,13 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.List;
 import org.junit.Test;
-import org.mockito.Mockito;
 import org.onap.aai.babel.service.data.BabelArtifact;
+import org.onap.aai.modelloader.entity.Artifact;
+import org.onap.aai.modelloader.entity.ArtifactType;
 import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
 import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
+import org.onap.aai.modelloader.util.ArtifactTestUtils;
 import org.openecomp.sdc.api.notification.INotificationData;
-import org.powermock.api.mockito.PowerMockito;
 
 /**
  * Tests {@link BabelArtifactConverter}
@@ -49,7 +51,6 @@ public class BabelArtifactConverterTest {
     public void convert_emptyToscaFiles() throws BabelArtifactParsingException {
         assertTrue("Nothing should have been returned",
                 new BabelArtifactConverter().convertToModel(new ArrayList<>()).isEmpty());
-        PowerMockito.verifyStatic(Mockito.times(1));
     }
 
     @Test(expected = BabelArtifactParsingException.class)
diff --git a/src/test/java/org/onap/aai/modelloader/notification/EventCallbackNoMockTest.java b/src/test/java/org/onap/aai/modelloader/notification/EventCallbackNoMockTest.java
deleted file mode 100644 (file)
index 19110bf..0000000
+++ /dev/null
@@ -1,123 +0,0 @@
-/**
- * ============LICENSE_START==========================================
- * org.onap.aai
- * ===================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ===================================================================
- * 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.aai.modelloader.notification;
-
-import java.io.IOException;
-import java.util.List;
-import java.util.Properties;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-import org.mockito.Mockito;
-import org.onap.aai.modelloader.config.ModelLoaderConfig;
-import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;
-import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;
-import org.openecomp.sdc.api.IDistributionClient;
-import org.openecomp.sdc.api.notification.INotificationData;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.reflect.Whitebox;
-
-/**
- * No-Mock tests
- * 
- * Because Jacoco (and other coverage tools) can't cope with mocked classes under some circumstances, coverage is/was
- * falsely reported as < 50%. Hence these duplicated but non-mock tests to address this, for ONAP reasons.
- * 
- * @author andrewdo
- *
- */
-
-/**
- * Tests {@link EventCallback}
- */
-
-public class EventCallbackNoMockTest {
-
-    private static final String CONFIG_FILE = "model-loader.properties";
-
-    private ModelLoaderConfig config;
-    private Properties configProperties;
-    private EventCallback eventCallback;
-
-    private ArtifactDeploymentManager mockArtifactDeploymentManager;
-    private ArtifactDownloadManager mockArtifactDownloadManager;
-    private IDistributionClient mockDistributionClient;
-
-    @Before
-    public void setup() throws IOException {
-        configProperties = new Properties();
-        configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));
-        config = new ModelLoaderConfig(configProperties, null);
-
-        mockArtifactDeploymentManager = PowerMockito.mock(ArtifactDeploymentManager.class);
-        mockArtifactDownloadManager = PowerMockito.mock(ArtifactDownloadManager.class);
-        mockDistributionClient = PowerMockito.mock(IDistributionClient.class);
-
-        eventCallback = new EventCallback(mockDistributionClient, config);
-
-        Whitebox.setInternalState(eventCallback, mockArtifactDeploymentManager);
-        Whitebox.setInternalState(eventCallback, mockArtifactDownloadManager);
-    }
-
-    @After
-    public void tearDown() {
-        config = null;
-        configProperties = null;
-        eventCallback = null;
-        mockArtifactDeploymentManager = null;
-        mockArtifactDownloadManager = null;
-        mockDistributionClient = null;
-    }
-
-    @Test
-    @SuppressWarnings("unchecked")
-    public void activateCallback_downloadFails() {
-        INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
-
-        PowerMockito.when(mockArtifactDownloadManager.downloadArtifacts(Mockito.any(INotificationData.class),
-                Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class))).thenReturn(false);
-
-        eventCallback.activateCallback(data);
-
-        Mockito.verify(mockArtifactDownloadManager).downloadArtifacts(Mockito.any(INotificationData.class),
-                Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class));
-        Mockito.verifyZeroInteractions(mockArtifactDeploymentManager);
-    }
-
-    @SuppressWarnings("unchecked")
-    @Test
-    public void activateCallback() throws BabelArtifactParsingException {
-        INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();
-
-        PowerMockito.when(mockArtifactDownloadManager.downloadArtifacts(Mockito.any(INotificationData.class),
-                Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class))).thenReturn(true);
-
-        PowerMockito.when(mockArtifactDeploymentManager.deploy(Mockito.any(INotificationData.class),
-                Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class))).thenReturn(true);
-
-        eventCallback.activateCallback(data);
-
-        Mockito.verify(mockArtifactDownloadManager).downloadArtifacts(Mockito.any(INotificationData.class),
-                Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class));
-        Mockito.verify(mockArtifactDeploymentManager).deploy(Mockito.any(INotificationData.class),
-                Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class));
-    }
-}
index 0cc183d..bc88c85 100644 (file)
  */\r
 package org.onap.aai.modelloader.notification;\r
 \r
+import static org.mockito.Matchers.any;\r
+import static org.mockito.Mockito.mock;\r
+import static org.mockito.Mockito.verify;\r
+import static org.mockito.Mockito.when;\r
+\r
 import java.io.IOException;\r
 import java.util.List;\r
 import java.util.Properties;\r
 import org.junit.After;\r
 import org.junit.Before;\r
 import org.junit.Test;\r
-import org.junit.runner.RunWith;\r
 import org.mockito.Mockito;\r
+import org.mockito.internal.util.reflection.Whitebox;\r
 import org.onap.aai.modelloader.config.ModelLoaderConfig;\r
 import org.onap.aai.modelloader.entity.model.BabelArtifactParsingException;\r
 import org.onap.aai.modelloader.fixture.NotificationDataFixtureBuilder;\r
 import org.openecomp.sdc.api.IDistributionClient;\r
 import org.openecomp.sdc.api.notification.INotificationData;\r
-import org.powermock.api.mockito.PowerMockito;\r
-import org.powermock.modules.junit4.PowerMockRunner;\r
-import org.powermock.reflect.Whitebox;\r
 \r
 /**\r
  * Tests {@link EventCallback}\r
  */\r
-@RunWith(PowerMockRunner.class)\r
 public class EventCallbackTest {\r
 \r
     private static final String CONFIG_FILE = "model-loader.properties";\r
@@ -59,14 +60,14 @@ public class EventCallbackTest {
         configProperties.load(this.getClass().getClassLoader().getResourceAsStream(CONFIG_FILE));\r
         config = new ModelLoaderConfig(configProperties, null);\r
 \r
-        mockArtifactDeploymentManager = PowerMockito.mock(ArtifactDeploymentManager.class);\r
-        mockArtifactDownloadManager = PowerMockito.mock(ArtifactDownloadManager.class);\r
-        mockDistributionClient = PowerMockito.mock(IDistributionClient.class);\r
+        mockArtifactDeploymentManager = mock(ArtifactDeploymentManager.class);\r
+        mockArtifactDownloadManager = mock(ArtifactDownloadManager.class);\r
+        mockDistributionClient = mock(IDistributionClient.class);\r
 \r
         eventCallback = new EventCallback(mockDistributionClient, config);\r
 \r
-        Whitebox.setInternalState(eventCallback, mockArtifactDeploymentManager);\r
-        Whitebox.setInternalState(eventCallback, mockArtifactDownloadManager);\r
+        Whitebox.setInternalState(eventCallback, "artifactDeploymentManager", mockArtifactDeploymentManager);\r
+        Whitebox.setInternalState(eventCallback, "artifactDownloadManager", mockArtifactDownloadManager);\r
     }\r
 \r
     @After\r
@@ -84,14 +85,13 @@ public class EventCallbackTest {
     public void activateCallback_downloadFails() {\r
         INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();\r
 \r
-        PowerMockito.when(mockArtifactDownloadManager.downloadArtifacts(Mockito.any(INotificationData.class),\r
-                Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class)))\r
-                .thenReturn(false);\r
+        when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),\r
+                any(List.class), any(List.class))).thenReturn(false);\r
 \r
         eventCallback.activateCallback(data);\r
 \r
-        Mockito.verify(mockArtifactDownloadManager).downloadArtifacts(Mockito.any(INotificationData.class),\r
-                Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class));\r
+        verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),\r
+                any(List.class), any(List.class));\r
         Mockito.verifyZeroInteractions(mockArtifactDeploymentManager);\r
     }\r
 \r
@@ -100,20 +100,17 @@ public class EventCallbackTest {
     public void activateCallback() throws BabelArtifactParsingException {\r
         INotificationData data = NotificationDataFixtureBuilder.getNotificationDataWithToscaCsarFile();\r
 \r
-        PowerMockito.when(mockArtifactDownloadManager.downloadArtifacts(Mockito.any(INotificationData.class),\r
-                Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class)))\r
-                .thenReturn(true);\r
+        when(mockArtifactDownloadManager.downloadArtifacts(any(INotificationData.class), any(List.class),\r
+                any(List.class), any(List.class))).thenReturn(true);\r
 \r
-        PowerMockito\r
-                .when(mockArtifactDeploymentManager.deploy(Mockito.any(INotificationData.class),\r
-                        Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class)))\r
-                .thenReturn(true);\r
+        when(mockArtifactDeploymentManager.deploy(any(INotificationData.class), any(List.class), any(List.class),\r
+                any(List.class))).thenReturn(true);\r
 \r
         eventCallback.activateCallback(data);\r
 \r
-        Mockito.verify(mockArtifactDownloadManager).downloadArtifacts(Mockito.any(INotificationData.class),\r
-                Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class));\r
-        Mockito.verify(mockArtifactDeploymentManager).deploy(Mockito.any(INotificationData.class),\r
-                Mockito.any(List.class), Mockito.any(List.class), Mockito.any(List.class));\r
+        verify(mockArtifactDownloadManager).downloadArtifacts(any(INotificationData.class), any(List.class),\r
+                any(List.class), any(List.class));\r
+        verify(mockArtifactDeploymentManager).deploy(any(INotificationData.class), any(List.class), any(List.class),\r
+                any(List.class));\r
     }\r
 }\r
diff --git a/src/test/java/org/onap/aai/modelloader/restclient/TestAaiRestClient.java b/src/test/java/org/onap/aai/modelloader/restclient/TestAaiRestClient.java
deleted file mode 100644 (file)
index d3dab2e..0000000
+++ /dev/null
@@ -1,149 +0,0 @@
-/**
- * ============LICENSE_START==========================================
- * org.onap.aai
- * ===================================================================
- * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
- * Copyright © 2017-2018 Amdocs
- * ===================================================================
- * 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.aai.modelloader.restclient;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.IOException;
-import java.nio.file.Files;
-import java.nio.file.Paths;
-import java.util.Properties;
-import java.util.stream.IntStream;
-import java.util.stream.Stream;
-import javax.ws.rs.core.MediaType;
-import javax.ws.rs.core.Response;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import org.junit.Ignore;
-import org.onap.aai.modelloader.config.ModelLoaderConfig;
-import org.onap.aai.modelloader.entity.model.ModelArtifact;
-import org.onap.aai.modelloader.entity.model.ModelArtifactParser;
-import org.onap.aai.modelloader.restclient.AaiRestClient;
-import org.onap.aai.modelloader.entity.ArtifactType;
-import org.onap.aai.restclient.client.OperationResult;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-public class TestAaiRestClient {
-
-    // This test requires a running A&AI system. To test locally, annotate with org.junit.Test
-    @Ignore
-    public void testRestClient() throws Exception {
-        final String MODEL_FILE = "src/test/resources/models/l3-network-widget.xml";
-
-        Properties props = new Properties();
-        props.setProperty("ml.distribution.ARTIFACT_TYPES", "MODEL_INVENTORY_PROFILE,MODEL_QUERY_SPEC,VNF_CATALOG");
-        props.setProperty("ml.aai.BASE_URL", "https://localhost:8443");
-        props.setProperty("ml.aai.MODEL_URL", "/aai/v9/service-design-and-creation/models/model/");
-        props.setProperty("ml.aai.KEYSTORE_FILE", "aai-client-cert.p12");
-        props.setProperty("ml.aai.KEYSTORE_PASSWORD", "OBF:1i9a1u2a1unz1lr61wn51wn11lss1unz1u301i6o");
-
-        ModelLoaderConfig config = new ModelLoaderConfig(props, ".");
-
-        File xmlFile = new File(MODEL_FILE);
-        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
-        dbFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
-        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
-        Document doc = dBuilder.parse(xmlFile);
-
-        NodeList nodesList = doc.getDocumentElement().getChildNodes();
-
-        // Get the model IDs
-
-        // @formatter:off
-        String modelInvariantId =
-                getNodesStream(nodesList)
-                        .filter(childNode -> childNode.getNodeName().equals(ModelArtifactParser.MODEL_INVARIANT_ID))
-                        .findFirst()
-                        .map(Node::getTextContent)
-                        .orElse(null);
-
-        String modelId = getNodesStream(nodesList)
-                .flatMap(n -> getNodesStream(n.getChildNodes()))
-                .filter(childNode -> childNode.getNodeName().equals(ModelArtifactParser.MODEL_VER))
-                .findFirst()
-                .map(n -> n.getChildNodes().item(1).getTextContent())
-                .orElse(null);
-        // @formatter:on
-
-        try {
-            // Build the model artifact
-            ModelArtifact model = new ModelArtifact();
-            model.setModelInvariantId(modelInvariantId);
-            model.setModelVerId(modelId);
-            model.setPayload(readFile(MODEL_FILE));
-            model.setModelNamespace("http://org.openecomp.aai.inventory/v9");
-
-            AaiRestClient aaiClient = new AaiRestClient(config);
-
-            // GET model
-            OperationResult opResult =
-                    aaiClient.getResource(getURL(model, config), "example-trans-id-0", MediaType.APPLICATION_XML_TYPE);
-            assertTrue(opResult.getResultCode() == Response.Status.NOT_FOUND.getStatusCode());
-
-            // PUT the model
-            opResult = aaiClient.putResource(getURL(model, config), model.getPayload(), "example-trans-id-1",
-                    MediaType.APPLICATION_XML_TYPE);
-            assertTrue(opResult.getResultCode() == Response.Status.CREATED.getStatusCode());
-
-            // DELETE the model
-            opResult = aaiClient.getAndDeleteResource(getURL(model, config), "example-trans-id-3");
-            assertTrue(opResult.getResultCode() == Response.Status.NO_CONTENT.getStatusCode());
-        } catch (Exception e) {
-            e.printStackTrace();
-        }
-    }
-
-    private Stream<Node> getNodesStream(NodeList nodeList) {
-        return IntStream.range(0, nodeList.getLength()).mapToObj(nodeList::item);
-    }
-
-    static String readFile(String path) throws IOException {
-        byte[] encoded = Files.readAllBytes(Paths.get(path));
-        return new String(encoded);
-    }
-
-    private String getURL(ModelArtifact model, ModelLoaderConfig config) {
-        String baseURL = config.getAaiBaseUrl().trim();
-        String subURL = null;
-        if (model.getType().equals(ArtifactType.MODEL)) {
-            subURL = config.getAaiModelUrl(model.getModelNamespaceVersion()).trim();
-        } else {
-            subURL = config.getAaiNamedQueryUrl(model.getModelNamespaceVersion()).trim();
-        }
-
-        if ((!baseURL.endsWith("/")) && (!subURL.startsWith("/"))) {
-            baseURL = baseURL + "/";
-        }
-
-        if (baseURL.endsWith("/") && subURL.startsWith("/")) {
-            baseURL = baseURL.substring(0, baseURL.length() - 1);
-        }
-
-        if (!subURL.endsWith("/")) {
-            subURL = subURL + "/";
-        }
-
-        return baseURL + subURL + model.getModelInvariantId();
-    }
-}
diff --git a/src/test/resources/compressedArtifacts/service-VscpaasTest-csar.csar b/src/test/resources/compressedArtifacts/service-VscpaasTest-csar.csar
new file mode 100644 (file)
index 0000000..d7f505e
Binary files /dev/null and b/src/test/resources/compressedArtifacts/service-VscpaasTest-csar.csar differ