aboutsummaryrefslogtreecommitdiffstats
path: root/appc-inbound/appc-design-services/provider/src
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-02-14 13:38:23 +0000
committerTakamune Cho <takamune.cho@att.com>2019-02-14 16:29:22 +0000
commit19bb17c4b16ee955cdec6db9ddc2af25845df062 (patch)
treee4f15ad6e22940d1c7725e73ea7f4d5f6ef5a119 /appc-inbound/appc-design-services/provider/src
parent6d9bedf2ed048a7715f0b6927683d904db9524b1 (diff)
Test coverage in XInterfaceService
Increased coverage from 68% to 100% Issue-ID: APPC-1436 Change-Id: If9f1670ba9955325bf938d7edf3d7d67bb48088c Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-inbound/appc-design-services/provider/src')
-rw-r--r--appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java53
-rw-r--r--appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/xinterface/XInterfaceServiceTest.java76
2 files changed, 104 insertions, 25 deletions
diff --git a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java
index 42f13243d..4e93af149 100644
--- a/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java
+++ b/appc-inbound/appc-design-services/provider/src/main/java/org/onap/appc/design/xinterface/XInterfaceService.java
@@ -31,31 +31,34 @@ import com.att.eelf.configuration.EELFManager;
import com.google.common.base.Strings;
public class XInterfaceService {
-
- private final EELFLogger log = EELFManager.getInstance().getLogger(XInterfaceService.class);
-
- public static XInterfaceService getInstance() {
- return new XInterfaceService();
- }
-
- public String execute(String action, String payload) throws Exception {
- // File targetFile = new File("/tmp/" + action + "-response.txt" );
- String interfaceResponse = null;
- try {
- if (Strings.isNullOrEmpty(payload))
- throw new Exception("Payload is null or empty..");
- if (DesignServiceConstants.GETINSTARDATA.equalsIgnoreCase(action)) {
- XResponseProcessor xResponseProcessor = new XResponseProcessor();
- interfaceResponse =
- xResponseProcessor.parseResponse(payload, DesignServiceConstants.GETINSTARDATA);
- } else {
- throw new Exception("No Such Action, Please enter valid Action");
- }
- } catch (Exception e) {
- e.printStackTrace();
- throw e;
+
+ private final EELFLogger log = EELFManager.getInstance().getLogger(XInterfaceService.class);
+
+ public static XInterfaceService getInstance() {
+ return new XInterfaceService();
+ }
+
+ public String execute(String action, String payload) throws Exception {
+ String interfaceResponse = null;
+ try {
+ if (Strings.isNullOrEmpty(payload))
+ throw new Exception("Payload is null or empty..");
+ if (DesignServiceConstants.GETINSTARDATA.equalsIgnoreCase(action)) {
+ XResponseProcessor xResponseProcessor = getXResponseProcessor();
+ interfaceResponse =
+ xResponseProcessor.parseResponse(payload, DesignServiceConstants.GETINSTARDATA);
+ } else {
+ throw new Exception("No Such Action, Please enter valid Action");
+ }
+ } catch (Exception e) {
+ log.error(e.getMessage());
+ throw e;
+ }
+ return interfaceResponse;
+ }
+
+ protected XResponseProcessor getXResponseProcessor() {
+ return new XResponseProcessor();
}
- return interfaceResponse;
- }
}
diff --git a/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/xinterface/XInterfaceServiceTest.java b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/xinterface/XInterfaceServiceTest.java
new file mode 100644
index 000000000..4e3f83fa3
--- /dev/null
+++ b/appc-inbound/appc-design-services/provider/src/test/java/org/onap/appc/design/xinterface/XInterfaceServiceTest.java
@@ -0,0 +1,76 @@
+/*
+ * ============LICENSE_START=======================================================
+ * ONAP : APPC
+ * ================================================================================
+ * 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.
+ * 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.appc.design.xinterface;
+
+import static org.junit.Assert.assertNull;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.ExpectedException;
+import org.mockito.Mockito;
+import org.onap.appc.design.services.util.DesignServiceConstants;
+
+public class XInterfaceServiceTest {
+
+ @Rule
+ public ExpectedException expectedEx = ExpectedException.none();
+
+ @Test
+ public void testExecute() throws Exception {
+ XInterfaceService service = Mockito.spy(new XInterfaceService());
+ XResponseProcessor processor = Mockito.mock(XResponseProcessor.class);
+ Mockito.when(processor.parseResponse(Mockito.anyString(), Mockito.anyString())).thenReturn(null);
+ Mockito.when(service.getXResponseProcessor()).thenReturn(processor);
+ assertNull(service.execute(DesignServiceConstants.GETINSTARDATA, "{}"));
+ }
+
+ @Test
+ public void testExecuteException() throws Exception {
+ XInterfaceService service = Mockito.spy(XInterfaceService.getInstance());
+ XResponseProcessor processor = Mockito.mock(XResponseProcessor.class);
+ Mockito.when(processor.parseResponse(Mockito.anyString(), Mockito.anyString())).thenThrow(new RuntimeException());
+ Mockito.when(service.getXResponseProcessor()).thenReturn(processor);
+ expectedEx.expect(RuntimeException.class);
+ service.execute(DesignServiceConstants.GETINSTARDATA, "{}");
+ }
+
+ @Test
+ public void testExecuteNullPayload() throws Exception {
+ XInterfaceService service = Mockito.spy(XInterfaceService.getInstance());
+ XResponseProcessor processor = Mockito.mock(XResponseProcessor.class);
+ Mockito.when(processor.parseResponse(Mockito.anyString(), Mockito.anyString())).thenThrow(new RuntimeException());
+ Mockito.when(service.getXResponseProcessor()).thenReturn(processor);
+ expectedEx.expect(Exception.class);
+ expectedEx.expectMessage("Payload is null or empty..");
+ service.execute(DesignServiceConstants.GETINSTARDATA, null);
+ }
+
+ @Test
+ public void testExecuteInvalidAction() throws Exception {
+ XInterfaceService service = Mockito.spy(XInterfaceService.getInstance());
+ XResponseProcessor processor = Mockito.mock(XResponseProcessor.class);
+ Mockito.when(processor.parseResponse(Mockito.anyString(), Mockito.anyString())).thenThrow(new RuntimeException());
+ Mockito.when(service.getXResponseProcessor()).thenReturn(processor);
+ expectedEx.expect(Exception.class);
+ expectedEx.expectMessage("No Such Action, Please enter valid Action");
+ service.execute("TEST", "{}");
+ }
+}