X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=tapi%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Ftapi%2Ftopology%2FTapiTopologyImplExceptionTest.java;h=4fc51dc7986924dbb6afc5ba03d4fde83f18c8e2;hb=b1b3bafd549bb501937cea5c976d5344608b6ed3;hp=3d7ca13ae37476bb70bf1b4ba20619dd7a0a6ab3;hpb=4b5caf037b5b61c5d53000d80e0273f833094fd5;p=transportpce.git diff --git a/tapi/src/test/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImplExceptionTest.java b/tapi/src/test/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImplExceptionTest.java index 3d7ca13ae..4fc51dc79 100644 --- a/tapi/src/test/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImplExceptionTest.java +++ b/tapi/src/test/java/org/opendaylight/transportpce/tapi/topology/TapiTopologyImplExceptionTest.java @@ -7,69 +7,63 @@ */ package org.opendaylight.transportpce.tapi.topology; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; import com.google.common.util.concurrent.FluentFuture; import com.google.common.util.concurrent.Futures; import com.google.common.util.concurrent.ListenableFuture; -import java.util.Optional; +import java.nio.charset.Charset; +import java.util.UUID; import java.util.concurrent.ExecutionException; -import org.eclipse.jdt.annotation.NonNull; -import org.junit.Test; -import org.mockito.Mockito; -import org.opendaylight.mdsal.binding.api.DataBroker; -import org.opendaylight.mdsal.binding.api.ReadTransaction; -import org.opendaylight.mdsal.common.api.LogicalDatastoreType; -import org.opendaylight.transportpce.tapi.utils.TopologyDataUtils; -import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsInput; -import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.GetTopologyDetailsOutput; -import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev181210.get.topology.details.output.Topology; -import org.opendaylight.yangtools.yang.binding.DataObject; -import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; +import org.opendaylight.mdsal.binding.api.RpcService; +import org.opendaylight.transportpce.common.network.NetworkTransactionService; +import org.opendaylight.transportpce.tapi.TapiStringConstants; +import org.opendaylight.transportpce.tapi.impl.rpc.GetTopologyDetailsImpl; +import org.opendaylight.transportpce.tapi.utils.TapiContext; +import org.opendaylight.transportpce.tapi.utils.TapiLink; +import org.opendaylight.transportpce.tapi.utils.TapiTopologyDataUtils; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.common.rev221121.Uuid; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyDetails; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyDetailsInput; +import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.topology.rev221121.GetTopologyDetailsOutput; +import org.opendaylight.yangtools.yang.common.ErrorType; import org.opendaylight.yangtools.yang.common.RpcResult; +@ExtendWith(MockitoExtension.class) public class TapiTopologyImplExceptionTest { + @Mock + private RpcService rpcService; + @Mock + private NetworkTransactionService networkTransactionService; + @Mock + private TapiContext tapiContext; + @Mock + private TopologyUtils topologyUtils; + @Mock + private TapiLink tapiLink; @Test - public void getTopologyDetailsWithExceptionTest() throws InterruptedException, ExecutionException { - DataBroker dataBroker = Mockito.mock(DataBroker.class); - when(dataBroker.newReadOnlyTransaction()) - .thenReturn(new ReadTransactionMock()); - - GetTopologyDetailsInput input = TopologyDataUtils.buildGetTopologyDetailsInput(TopologyUtils.T0_MULTILAYER); - TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(dataBroker); - ListenableFuture> result = tapiTopoImpl.getTopologyDetails(input); - RpcResult rpcResult = result.get(); - Topology topology = rpcResult.getResult().getTopology(); - assertNull("Topology should be null", topology); - } - - private class ReadTransactionMock implements ReadTransaction { - - @Override - public @NonNull Object getIdentifier() { - // TODO Auto-generated method stub - return null; - } - - @Override - public @NonNull FluentFuture> read(@NonNull LogicalDatastoreType store, - @NonNull InstanceIdentifier path) { - return FluentFuture.from(Futures.immediateFailedFuture(new InterruptedException())); - } - - @Override - public @NonNull FluentFuture exists(@NonNull LogicalDatastoreType store, - @NonNull InstanceIdentifier path) { - // TODO Auto-generated method stub - return null; - } - - @Override - public void close() { - // TODO Auto-generated method stub - } + void getTopologyDetailsWithExceptionTest() throws InterruptedException, ExecutionException { + when(networkTransactionService.read(any(), any())) + .thenReturn(FluentFuture.from(Futures.immediateFailedFuture(new InterruptedException()))); + when(rpcService.getRpc(GetTopologyDetails.class)) + .thenReturn(new GetTopologyDetailsImpl(tapiContext, topologyUtils, tapiLink, networkTransactionService)); + Uuid topologyUuid = new Uuid(UUID.nameUUIDFromBytes(TapiStringConstants.T0_MULTILAYER.getBytes( + Charset.forName("UTF-8"))).toString()); + GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput(topologyUuid); + ListenableFuture> result = rpcService + .getRpc(GetTopologyDetails.class).invoke(input); + assertFalse(result.get().isSuccessful(), "RpcResult is not successful"); + assertNull(result.get().getResult(), "RpcResult result should be null"); + assertEquals(ErrorType.RPC, result.get().getErrors().get(0).getErrorType()); + assertEquals("Error building topology", result.get().getErrors().get(0).getMessage()); } - -} +} \ No newline at end of file