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=7fb3b598f1a347eb8921fe8f64338ccab12fd141;hb=e25f274098143d1171db8072a8b6091fb97b8e4a;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..7fb3b598f 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,7 +7,8 @@ */ package org.opendaylight.transportpce.tapi.topology; -import static org.junit.Assert.assertNull; +import static org.junit.jupiter.api.Assertions.assertNull; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; import com.google.common.util.concurrent.FluentFuture; @@ -16,12 +17,20 @@ import com.google.common.util.concurrent.ListenableFuture; import java.util.Optional; import java.util.concurrent.ExecutionException; import org.eclipse.jdt.annotation.NonNull; -import org.junit.Test; -import org.mockito.Mockito; +import org.junit.jupiter.api.Test; +import org.mockito.Mock; +import org.mockito.invocation.InvocationOnMock; +import org.mockito.stubbing.Answer; import org.opendaylight.mdsal.binding.api.DataBroker; import org.opendaylight.mdsal.binding.api.ReadTransaction; +import org.opendaylight.mdsal.common.api.CommitInfo; import org.opendaylight.mdsal.common.api.LogicalDatastoreType; -import org.opendaylight.transportpce.tapi.utils.TopologyDataUtils; +import org.opendaylight.transportpce.common.network.NetworkTransactionService; +import org.opendaylight.transportpce.tapi.TapiStringConstants; +import org.opendaylight.transportpce.tapi.utils.TapiContext; +import org.opendaylight.transportpce.tapi.utils.TapiLink; +import org.opendaylight.transportpce.tapi.utils.TapiLinkImpl; +import org.opendaylight.transportpce.tapi.utils.TapiTopologyDataUtils; 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; @@ -30,19 +39,42 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier; import org.opendaylight.yangtools.yang.common.RpcResult; public class TapiTopologyImplExceptionTest { + @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); + void getTopologyDetailsWithExceptionTest() throws InterruptedException, ExecutionException { + DataBroker dataBroker = mock(DataBroker.class); when(dataBroker.newReadOnlyTransaction()) - .thenReturn(new ReadTransactionMock()); + .thenReturn(new ReadTransactionMock()); + NetworkTransactionService networkTransactionService = mock(NetworkTransactionService.class); + Answer> answer = new Answer>() { - GetTopologyDetailsInput input = TopologyDataUtils.buildGetTopologyDetailsInput(TopologyUtils.T0_MULTILAYER); - TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(dataBroker); + @Override + public FluentFuture answer(InvocationOnMock invocation) throws Throwable { + return CommitInfo.emptyFluentFuture(); + } + + }; + when(networkTransactionService.commit()).then(answer); + tapiContext = new TapiContext(networkTransactionService); + tapiLink = new TapiLinkImpl(networkTransactionService); + + GetTopologyDetailsInput input = TapiTopologyDataUtils.buildGetTopologyDetailsInput( + TapiStringConstants.T0_MULTILAYER); + TapiTopologyImpl tapiTopoImpl = new TapiTopologyImpl(dataBroker, tapiContext, topologyUtils, tapiLink); ListenableFuture> result = tapiTopoImpl.getTopologyDetails(input); RpcResult rpcResult = result.get(); - Topology topology = rpcResult.getResult().getTopology(); - assertNull("Topology should be null", topology); + if (rpcResult.isSuccessful()) { + Topology topology = rpcResult.getResult().getTopology(); + assertNull(topology, "Topology should be null"); + } else { + assertNull(null, "Topology should be null"); + } } private class ReadTransactionMock implements ReadTransaction { @@ -55,13 +87,13 @@ public class TapiTopologyImplExceptionTest { @Override public @NonNull FluentFuture> read(@NonNull LogicalDatastoreType store, - @NonNull InstanceIdentifier path) { + @NonNull InstanceIdentifier path) { return FluentFuture.from(Futures.immediateFailedFuture(new InterruptedException())); } @Override public @NonNull FluentFuture exists(@NonNull LogicalDatastoreType store, - @NonNull InstanceIdentifier path) { + @NonNull InstanceIdentifier path) { // TODO Auto-generated method stub return null; } @@ -71,5 +103,4 @@ public class TapiTopologyImplExceptionTest { // TODO Auto-generated method stub } } - -} +} \ No newline at end of file