summaryrefslogtreecommitdiffstats
path: root/appc-event-listener
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-02-20 11:13:51 +0000
committerTakamune Cho <takamune.cho@att.com>2019-02-21 15:03:47 +0000
commit76dbfd952b3398bf7699c7a100c777b1881ed53e (patch)
tree44a1f896b0036670cc5bb2b557c0e3d94b1eaf6a /appc-event-listener
parent206c2d96a4ada3d60e68ac67539925fe5baa545b (diff)
Test coverage in LCM ProviderOperations
Added test cases Issue-ID: APPC-1462 Change-Id: I577bcbb1f1ea36fdddbe30b115710588472bd45c Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-event-listener')
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/GenericProviderOperationRequestFormatter.java4
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/ProviderOperations.java5
-rw-r--r--appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/LCM/operation/ProviderOperationsTest.java33
3 files changed, 38 insertions, 4 deletions
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/GenericProviderOperationRequestFormatter.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/GenericProviderOperationRequestFormatter.java
index 3dddd87a5..ca0f52ac7 100644
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/GenericProviderOperationRequestFormatter.java
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/GenericProviderOperationRequestFormatter.java
@@ -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
diff --git a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/ProviderOperations.java b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/ProviderOperations.java
index 39ad7b454..42206ec2e 100644
--- a/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/ProviderOperations.java
+++ b/appc-event-listener/appc-event-listener-bundle/src/main/java/org/onap/appc/listener/LCM/operation/ProviderOperations.java
@@ -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;
diff --git a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/LCM/operation/ProviderOperationsTest.java b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/LCM/operation/ProviderOperationsTest.java
index 36ef1ad37..b6ea54c09 100644
--- a/appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/LCM/operation/ProviderOperationsTest.java
+++ b/appc-event-listener/appc-event-listener-bundle/src/test/java/org/onap/appc/listener/LCM/operation/ProviderOperationsTest.java
@@ -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());
+ }
}