Test coverage in LCM ProviderOperations 25/78825/2
authorJoss Armstrong <joss.armstrong@ericsson.com>
Wed, 20 Feb 2019 11:13:51 +0000 (11:13 +0000)
committerTakamune Cho <takamune.cho@att.com>
Thu, 21 Feb 2019 15:03:47 +0000 (15:03 +0000)
Added test cases

Issue-ID: APPC-1462
Change-Id: I577bcbb1f1ea36fdddbe30b115710588472bd45c
Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/GenericProviderOperationRequestFormatter.java
appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/ProviderOperations.java
appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/LCM/operation/ProviderOperationsTest.java

index 3dddd87..ca0f52a 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -46,7 +48,7 @@ public class GenericProviderOperationRequestFormatter implements ProviderOperati
 
     @Override
     public String buildPath(URL url, String rpcName) {
-        return url.getPath() + ":"+rpcName;
+        return url.getPath() + ":" + rpcName;
     }
 
     @Override
index 39ad7b4..42206ec 100644 (file)
@@ -5,6 +5,8 @@
  * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved.
  * ================================================================================
  * Copyright (C) 2017 Amdocs
+ * ================================================================================
+ * Modifications Copyright (C) 2019 Ericsson
  * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -194,7 +196,7 @@ public class ProviderOperations {
     }
 
     @SuppressWarnings("deprecation")
-    private HttpClient getHttpClient() throws APPCException {
+    protected HttpClient getHttpClient() throws APPCException {
         HttpClient client;
         switch (url.getProtocol()) {
             case "https":
@@ -217,6 +219,7 @@ public class ProviderOperations {
                     ClientConnectionManager ccm = new ThreadSafeClientConnManager(params, registry);
                     client = new DefaultHttpClient(ccm, params);
                 } catch (Exception e) {
+                    LOG.error("Error getting HTTP Client", e);
                     client = new DefaultHttpClient();
                 }
                 break;
index 36ef1ad..b6ea54c 100644 (file)
@@ -27,10 +27,14 @@ import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertTrue;
-import static org.mockito.Matchers.anyString;
-
 import com.att.aft.dme2.internal.jersey.core.util.Base64;
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.databind.node.ObjectNode;
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
+import java.io.InputStream;
 import java.net.Socket;
 import java.net.SocketException;
 import java.security.KeyManagementException;
@@ -38,9 +42,14 @@ import java.security.KeyStore;
 import java.security.KeyStoreException;
 import java.security.NoSuchAlgorithmException;
 import java.security.UnrecoverableKeyException;
+import org.apache.http.HttpEntity;
+import org.apache.http.HttpResponse;
+import org.apache.http.StatusLine;
+import org.apache.http.client.HttpClient;
 import org.junit.Before;
 import org.junit.Test;
 import org.mockito.Mock;
+import org.mockito.Mockito;
 import org.onap.appc.exceptions.APPCException;
 import org.onap.appc.listener.LCM.operation.ProviderOperations.MySSLSocketFactory;
 
@@ -103,4 +112,24 @@ public class ProviderOperationsTest {
     }
 
     //TODO write some test cases for topologyDG method
+    @Test
+    public void testBuildPostRequest() throws JsonProcessingException, IOException, APPCException {
+        String jsonString = "{\"output\":{\"status\":{\"code\":\"200\",\"message\":\"TEST_MESSAGE\"}}}";
+        providerOperations = Mockito.spy(
+                new ProviderOperations("http://127.0.0.1", "test_user", "test_password"));
+        HttpClient httpClient = Mockito.mock(HttpClient.class);
+        HttpResponse httpResponse = Mockito.mock(HttpResponse.class);
+        StatusLine statusLine = Mockito.mock(StatusLine.class);
+        Mockito.when(statusLine.getStatusCode()).thenReturn(200);
+        Mockito.when(httpResponse.getStatusLine()).thenReturn(statusLine);
+        HttpEntity httpEntity = Mockito.mock(HttpEntity.class);
+        InputStream inputStream = new ByteArrayInputStream(jsonString.getBytes());
+        Mockito.when(httpEntity.getContent()).thenReturn(inputStream);
+        Mockito.when(httpResponse.getEntity()).thenReturn(httpEntity);
+        Mockito.when(httpClient.execute(Mockito.any())).thenReturn(httpResponse);
+        Mockito.when(providerOperations.getHttpClient()).thenReturn(httpClient);
+        ObjectMapper mapper = new ObjectMapper();
+        JsonNode jsonNode = mapper.readTree(jsonString);
+        assertEquals(ObjectNode.class, providerOperations.topologyDG(null, jsonNode).getClass());
+    }
 }