diff options
Diffstat (limited to 'appc-inbound/appc-interfaces-service/bundle/src/test')
2 files changed, 145 insertions, 0 deletions
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(); + } + +} |