aboutsummaryrefslogtreecommitdiffstats
path: root/appc-inbound/appc-interfaces-service/bundle
diff options
context:
space:
mode:
authorJoss Armstrong <joss.armstrong@ericsson.com>2019-01-23 15:09:18 +0000
committerTakamune Cho <takamune.cho@att.com>2019-01-23 18:28:08 +0000
commit0adcbc9caa0a01219952ad18e55dcf2b571e5418 (patch)
tree70e5e353e6a408066b9289f7c3a5c7b06916182e /appc-inbound/appc-interfaces-service/bundle
parent425988fd78defd866d2e02dc9523764be2ec0a51 (diff)
Test coverage in appc-interfaces-services package
Increased coverage from 0% to 100% Issue-ID: APPC-1354 Change-Id: Ifb8478104af432b5baf11d21e66f490dcd70b5a9 Signed-off-by: Joss Armstrong <joss.armstrong@ericsson.com>
Diffstat (limited to 'appc-inbound/appc-interfaces-service/bundle')
-rw-r--r--appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/InterfacesServiceProvider.java4
-rw-r--r--appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/InterfacesServiceProviderImpl.java10
-rw-r--r--appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/InterfacesServiceProviderImplTest.java84
-rw-r--r--appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/InterfacesServiceProviderTest.java61
4 files changed, 156 insertions, 3 deletions
diff --git a/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/InterfacesServiceProvider.java b/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/InterfacesServiceProvider.java
index a76e98fea..242f55f22 100644
--- a/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/InterfacesServiceProvider.java
+++ b/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/InterfacesServiceProvider.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.
@@ -39,7 +41,7 @@ public class InterfacesServiceProvider{
private final DataBroker dataBroker;
private final RpcProviderRegistry rpcProviderRegistry;
private RpcRegistration <InterfacesServiceService> serviceRegistration;
-
+
public InterfacesServiceProvider(final DataBroker dataBroker, RpcProviderRegistry rpcProviderRegistry) {
this.dataBroker = dataBroker;
this.rpcProviderRegistry = rpcProviderRegistry;
diff --git a/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/InterfacesServiceProviderImpl.java b/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/InterfacesServiceProviderImpl.java
index c2669cf98..52a97ffb0 100644
--- a/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/InterfacesServiceProviderImpl.java
+++ b/appc-inbound/appc-interfaces-service/bundle/src/main/java/org/onap/appc/interfaces/service/InterfacesServiceProviderImpl.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.
@@ -52,7 +54,7 @@ public class InterfacesServiceProviderImpl implements InterfacesServiceService{
String action = input.getRequest().getAction();
ResponseInfoBuilder responseInfoBuilder = new ResponseInfoBuilder();
ExecuteServiceOutputBuilder executeServicebuilder = new ExecuteServiceOutputBuilder();
- ServiceExecutor serviceExecutor = new ServiceExecutor();
+ ServiceExecutor serviceExecutor = getServiceExecutor();
StatusBuilder statusBuilder = new StatusBuilder();
try{
String response = serviceExecutor.execute(action, input.getRequest().getRequestData(), input.getRequest().getRequestDataType());
@@ -65,11 +67,15 @@ public class InterfacesServiceProviderImpl implements InterfacesServiceService{
log.error("Error" + e.getMessage());
e.printStackTrace();
statusBuilder.setCode("401");
- statusBuilder.setMessage("failuer");
+ statusBuilder.setMessage("failure");
}
executeServicebuilder.setResponseInfo(responseInfoBuilder.build());
executeServicebuilder.setStatus(statusBuilder.build());
RpcResult<ExecuteServiceOutput> result = RpcResultBuilder.<ExecuteServiceOutput>status(true).withResult(executeServicebuilder.build()).build();
return Futures.immediateFuture(result);
}
+
+ protected ServiceExecutor getServiceExecutor() {
+ return new ServiceExecutor();
+ }
}
diff --git a/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/InterfacesServiceProviderImplTest.java b/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/InterfacesServiceProviderImplTest.java
new file mode 100644
index 000000000..485ee754d
--- /dev/null
+++ b/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/InterfacesServiceProviderImplTest.java
@@ -0,0 +1,84 @@
+/*
+ * ============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.interfaces.service;
+
+import static org.junit.Assert.assertEquals;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.onap.appc.interfaces.service.executor.ServiceExecutor;
+import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.ExecuteServiceInput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.ExecuteServiceInputBuilder;
+import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.ExecuteServiceOutput;
+import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.request.info.Request;
+import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.request.info.RequestBuilder;
+import org.opendaylight.yangtools.yang.common.RpcResult;
+
+public class InterfacesServiceProviderImplTest {
+
+ @Test
+ public void testExecuteService() throws InterruptedException, ExecutionException {
+ InterfacesServiceProviderImpl impl = new InterfacesServiceProviderImpl();
+ RequestBuilder requestBuilder = new RequestBuilder();
+ String requestData = "{\"vnf-id\": \"vnf-id\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" :"
+ + " \"service-instance-id\",\"vnf-id\" : \"vnf-id\",\"vnfc-name\" : \"vnfc-name\",\"vf-module-id\" : \"vf-module-id\","
+ + "\"vserver-id\": \"vserver-id\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" :"
+ + " {\"service-instance-id\" : \"service-instance-id1\",\"vnf-id\" : \"vnf-id1\",\"vnfc-name\" : \"vnfc-name1\",\"vf-module-id\" :"
+ + " \"vf-module-id\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" :"
+ + " \"service-instance-id2\",\"vnf-id\" : \"vnf-id2\",\"vnfc-name\" : \"vnfc-name2\",\"vf-module-id\" : \"vf-module-id2\",\"vserver-id\":"
+ + " \"vserver-id2\"}}]}";
+ requestBuilder.setRequestData(requestData);
+ requestBuilder.setAction("isScopeOverlap");
+ Request request = requestBuilder.build();
+ ExecuteServiceInputBuilder inputBuilder = new ExecuteServiceInputBuilder();
+ inputBuilder.setRequest(request);
+ ExecuteServiceInput input = inputBuilder.build();
+ Future<RpcResult<ExecuteServiceOutput>> future = impl.executeService(input);
+ assertEquals("400", future.get().getResult().getStatus().getCode());
+ }
+
+ @Test
+ public void testExecuteServiceExceptionFlow() throws Exception {
+ InterfacesServiceProviderImpl impl = Mockito.spy(new InterfacesServiceProviderImpl());
+ RequestBuilder requestBuilder = new RequestBuilder();
+ String requestData = "{\"vnf-id\": \"vnf-id\",\"current-request\" :{\"action\" : \"Audit\",\"action-identifiers\" : {\"service-instance-id\" :"
+ + " \"service-instance-id\",\"vnf-id\" : \"vnf-id\",\"vnfc-name\" : \"vnfc-name\",\"vf-module-id\" : \"vf-module-id\","
+ + "\"vserver-id\": \"vserver-id\"}},\"in-progress-requests\" :[{\"action\" : \"HealthCheck\",\"action-identifiers\" :"
+ + " {\"service-instance-id\" : \"service-instance-id1\",\"vnf-id\" : \"vnf-id1\",\"vnfc-name\" : \"vnfc-name1\",\"vf-module-id\" :"
+ + " \"vf-module-id\",\"vserver-id\": \"vserver-id1\"}},{\"action\" : \"CheckLock\",\"action-identifiers\" : {\"service-instance-id\" :"
+ + " \"service-instance-id2\",\"vnf-id\" : \"vnf-id2\",\"vnfc-name\" : \"vnfc-name2\",\"vf-module-id\" : \"vf-module-id2\",\"vserver-id\":"
+ + " \"vserver-id2\"}}]}";
+ requestBuilder.setRequestData(requestData);
+ requestBuilder.setAction("isScopeOverlap");
+ Request request = requestBuilder.build();
+ ExecuteServiceInputBuilder inputBuilder = new ExecuteServiceInputBuilder();
+ inputBuilder.setRequest(request);
+ ExecuteServiceInput input = inputBuilder.build();
+ ServiceExecutor executorMock = Mockito.mock(ServiceExecutor.class);
+ Mockito.doThrow(new Exception()).when(executorMock).execute(Mockito.anyString(), Mockito.anyString(), Mockito.anyString());
+ Mockito.doReturn(executorMock).when(impl).getServiceExecutor();
+ Future<RpcResult<ExecuteServiceOutput>> future = impl.executeService(input);
+ assertEquals("401", future.get().getResult().getStatus().getCode());
+ }
+
+}
diff --git a/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/InterfacesServiceProviderTest.java b/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/InterfacesServiceProviderTest.java
new file mode 100644
index 000000000..58d63afb5
--- /dev/null
+++ b/appc-inbound/appc-interfaces-service/bundle/src/test/java/org/onap/appc/interfaces/service/InterfacesServiceProviderTest.java
@@ -0,0 +1,61 @@
+/*
+ * ============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.interfaces.service;
+
+import static org.junit.Assert.assertNotNull;
+import org.junit.Before;
+import org.junit.Test;
+import org.mockito.Mockito;
+import org.opendaylight.controller.md.sal.binding.api.DataBroker;
+import org.opendaylight.controller.sal.binding.api.RpcProviderRegistry;
+import org.opendaylight.controller.sal.binding.api.BindingAwareBroker.RpcRegistration;
+import org.opendaylight.yang.gen.v1.org.onap.appc.interfaces.service.rev170818.InterfacesServiceService;
+import org.powermock.reflect.Whitebox;
+
+public class InterfacesServiceProviderTest {
+
+ private DataBroker dataBroker = Mockito.mock(DataBroker.class);
+ private RpcProviderRegistry rpcRegistry = Mockito.mock(RpcProviderRegistry.class);
+ private RpcRegistration <InterfacesServiceService> serviceRegistration = (RpcRegistration <InterfacesServiceService>) Mockito.mock(RpcRegistration.class);
+ private InterfacesServiceProvider provider;
+
+ @Before
+ public void setup() {
+ provider = new InterfacesServiceProvider(dataBroker, rpcRegistry);
+ Mockito.doReturn(serviceRegistration).when(rpcRegistry).addRpcImplementation(Mockito.any(), Mockito.any());
+ }
+
+ @Test
+ public void testInit() {
+ provider.init();
+ RpcRegistration <InterfacesServiceService> serviceRegistration = Whitebox.getInternalState(provider, "serviceRegistration");
+ assertNotNull(serviceRegistration);
+ }
+
+ @Test
+ public void testClose() {
+ provider.init();
+ provider.close();
+ Mockito.verify(serviceRegistration).close();
+ }
+
+}