X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Frestful%2Futils%2FDeleteDataTransactionUtilTest.java;h=f38923d9522b00e73f1c27cc0f6385cb511d3dd0;hb=2945350314dfc6309d5aaf3bc5c08b6e7abaff95;hp=f867ab1d1a2eef09765f229139e42d7759be5e57;hpb=4bb43be2cbdd77a5f168d20be6a75b8512cae5c5;p=netconf.git diff --git a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/DeleteDataTransactionUtilTest.java b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/DeleteDataTransactionUtilTest.java index f867ab1d1a..f38923d952 100644 --- a/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/DeleteDataTransactionUtilTest.java +++ b/restconf/sal-rest-connector/src/test/java/org/opendaylight/restconf/restful/utils/DeleteDataTransactionUtilTest.java @@ -10,7 +10,6 @@ package org.opendaylight.restconf.restful.utils; import static org.junit.Assert.assertEquals; import static org.junit.Assert.fail; - import com.google.common.util.concurrent.Futures; import javax.ws.rs.core.Response; import javax.ws.rs.core.Response.Status; @@ -21,6 +20,7 @@ import org.mockito.Mockito; import org.mockito.MockitoAnnotations; import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType; import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction; +import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain; import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext; import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException; import org.opendaylight.netconf.sal.restconf.impl.RestconfError.ErrorTag; @@ -29,14 +29,19 @@ import org.opendaylight.restconf.restful.transaction.TransactionVarsWrapper; import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; public class DeleteDataTransactionUtilTest { - @Mock DOMDataReadWriteTransaction transaction; - @Mock InstanceIdentifierContext context; + @Mock + private DOMTransactionChain transactionChain; + @Mock + private InstanceIdentifierContext context; + @Mock + private DOMDataReadWriteTransaction readWrite; @Before public void init() throws Exception { MockitoAnnotations.initMocks(this); - Mockito.when(this.transaction.submit()).thenReturn(Futures.immediateCheckedFuture(null)); - Mockito.when(context.getInstanceIdentifier()).thenReturn(YangInstanceIdentifier.EMPTY); + Mockito.when(this.transactionChain.newReadWriteTransaction()).thenReturn(this.readWrite); + Mockito.when(this.readWrite.submit()).thenReturn(Futures.immediateCheckedFuture(null)); + Mockito.when(this.context.getInstanceIdentifier()).thenReturn(YangInstanceIdentifier.EMPTY); } /** @@ -45,12 +50,13 @@ public class DeleteDataTransactionUtilTest { @Test public void deleteData() throws Exception { // assert that data to delete exists - Mockito.when(this.transaction.exists(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY)) + Mockito.when(this.transactionChain.newReadWriteTransaction().exists(LogicalDatastoreType.CONFIGURATION, + YangInstanceIdentifier.EMPTY)) .thenReturn(Futures.immediateCheckedFuture(Boolean.TRUE)); // test final Response response = DeleteDataTransactionUtil.deleteData( - new TransactionVarsWrapper(this.context, null, this.transaction)); + new TransactionVarsWrapper(this.context, null, this.transactionChain)); // assert success assertEquals("Not expected response received", Status.OK.getStatusCode(), response.getStatus()); @@ -62,12 +68,13 @@ public class DeleteDataTransactionUtilTest { @Test public void deleteDataNegativeTest() throws Exception { // assert that data to delete does NOT exist - Mockito.when(this.transaction.exists(LogicalDatastoreType.CONFIGURATION, YangInstanceIdentifier.EMPTY)) + Mockito.when(this.transactionChain.newReadWriteTransaction().exists(LogicalDatastoreType.CONFIGURATION, + YangInstanceIdentifier.EMPTY)) .thenReturn(Futures.immediateCheckedFuture(Boolean.FALSE)); // test and assert error try { - DeleteDataTransactionUtil.deleteData(new TransactionVarsWrapper(this.context, null, this.transaction)); + DeleteDataTransactionUtil.deleteData(new TransactionVarsWrapper(this.context, null, this.transactionChain)); fail("Delete operation should fail due to missing data"); } catch (final RestconfDocumentedException e) { assertEquals(ErrorType.PROTOCOL, e.getErrors().get(0).getErrorType());