X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Ftest%2FRestPutOperationTest.java;h=3591bfb22bec85f90ef94215a30fdfbef5705784;hp=3284546dcbb32806563b2bb8b0959d7a3063a10d;hb=d206d27042eef2185c875f85cf6eac61a1bd77c4;hpb=48daeb11697dbb83f554b64fe8702e21de3e0a12 diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java index 3284546dcb..3591bfb22b 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestPutOperationTest.java @@ -16,19 +16,23 @@ import static org.mockito.Mockito.when; import com.google.common.base.Optional; import com.google.common.util.concurrent.CheckedFuture; + import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; + import javax.ws.rs.client.Entity; import javax.ws.rs.core.Application; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; + import org.glassfish.jersey.server.ResourceConfig; import org.glassfish.jersey.test.JerseyTest; import org.junit.BeforeClass; import org.junit.Test; +import org.opendaylight.controller.md.sal.common.api.data.OptimisticLockFailedException; import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException; import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint; import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService; @@ -158,6 +162,36 @@ public class RestPutOperationTest extends JerseyTest { assertEquals(200, put(uri, MediaType.APPLICATION_XML, xmlData3)); } + @Test + public void putWithOptimisticLockFailedException() throws UnsupportedEncodingException { + + String uri = "/config/ietf-interfaces:interfaces/interface/eth0"; + + doThrow(OptimisticLockFailedException.class). + when(brokerFacade).commitConfigurationDataPut( + any(YangInstanceIdentifier.class), any(NormalizedNode.class)); + + assertEquals(500, put(uri, MediaType.APPLICATION_XML, xmlData)); + + doThrow(OptimisticLockFailedException.class).doReturn(mock(CheckedFuture.class)). + when(brokerFacade).commitConfigurationDataPut( + any(YangInstanceIdentifier.class), any(NormalizedNode.class)); + + assertEquals(200, put(uri, MediaType.APPLICATION_XML, xmlData)); + } + + @Test + public void putWithTransactionCommitFailedException() throws UnsupportedEncodingException { + + String uri = "/config/ietf-interfaces:interfaces/interface/eth0"; + + doThrow(TransactionCommitFailedException.class). + when(brokerFacade).commitConfigurationDataPut( + any(YangInstanceIdentifier.class), any(NormalizedNode.class)); + + assertEquals(500, put(uri, MediaType.APPLICATION_XML, xmlData)); + } + private int put(String uri, String mediaType, String data) throws UnsupportedEncodingException { return target(uri).request(mediaType).put(Entity.entity(data, mediaType)).getStatus(); }