Search in sources :

Example 6 with PatchContext

use of org.opendaylight.restconf.common.patch.PatchContext in project netconf by opendaylight.

the class BrokerFacadeTest method testPatchConfigurationDataWithinTransactionMountFail.

/**
 * Negative test for Patch operation when mounted device does not support {@link DOMDataBroker service.}
 * Patch operation should fail with global error.
 */
@Test
public void testPatchConfigurationDataWithinTransactionMountFail() throws Exception {
    final PatchContext patchContext = mock(PatchContext.class);
    final InstanceIdentifierContext<?> identifierContext = mock(InstanceIdentifierContext.class);
    final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
    final DOMDataBroker mountDataBroker = mock(DOMDataBroker.class);
    final DOMDataTreeReadWriteTransaction transaction = mock(DOMDataTreeReadWriteTransaction.class);
    doReturn(identifierContext).when(patchContext).getInstanceIdentifierContext();
    when(identifierContext.getMountPoint()).thenReturn(mountPoint);
    // missing broker on mounted device
    when(mountPoint.getService(DOMDataBroker.class)).thenReturn(Optional.empty());
    when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.empty());
    final PatchStatusContext status = this.brokerFacade.patchConfigurationDataWithinTransaction(patchContext);
    // assert not successful operation with error
    assertNotNull(status.getGlobalErrors());
    assertEquals(1, status.getGlobalErrors().size());
    assertEquals(ErrorType.APPLICATION, status.getGlobalErrors().get(0).getErrorType());
    assertEquals(ErrorTag.OPERATION_FAILED, status.getGlobalErrors().get(0).getErrorTag());
    assertFalse("Patch operation should fail on mounted device without Broker", status.isOk());
}
Also used : DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) PatchStatusContext(org.opendaylight.restconf.common.patch.PatchStatusContext) PatchContext(org.opendaylight.restconf.common.patch.PatchContext) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) DOMDataBroker(org.opendaylight.mdsal.dom.api.DOMDataBroker) Test(org.junit.Test)

Example 7 with PatchContext

use of org.opendaylight.restconf.common.patch.PatchContext in project netconf by opendaylight.

the class BrokerFacadeTest method testPatchConfigurationDataWithinTransactionMount.

/**
 * Test Patch method on mounted device with no data.
 */
@Test
public void testPatchConfigurationDataWithinTransactionMount() throws Exception {
    final PatchContext patchContext = mock(PatchContext.class);
    final InstanceIdentifierContext<?> identifierContext = mock(InstanceIdentifierContext.class);
    final DOMMountPoint mountPoint = mock(DOMMountPoint.class);
    final DOMDataBroker mountDataBroker = mock(DOMDataBroker.class);
    final DOMDataTreeReadWriteTransaction transaction = mock(DOMDataTreeReadWriteTransaction.class);
    when(patchContext.getData()).thenReturn(new ArrayList<>());
    doReturn(identifierContext).when(patchContext).getInstanceIdentifierContext();
    // return mount point with broker
    when(identifierContext.getMountPoint()).thenReturn(mountPoint);
    when(mountPoint.getService(DOMDataBroker.class)).thenReturn(Optional.of(mountDataBroker));
    when(mountPoint.getService(DOMSchemaService.class)).thenReturn(Optional.empty());
    when(mountDataBroker.newReadWriteTransaction()).thenReturn(transaction);
    doReturn(CommitInfo.emptyFluentFuture()).when(transaction).commit();
    final PatchStatusContext status = this.brokerFacade.patchConfigurationDataWithinTransaction(patchContext);
    // assert success
    assertTrue("Patch operation should be successful on mounted device", status.isOk());
}
Also used : DOMDataTreeReadWriteTransaction(org.opendaylight.mdsal.dom.api.DOMDataTreeReadWriteTransaction) PatchStatusContext(org.opendaylight.restconf.common.patch.PatchStatusContext) PatchContext(org.opendaylight.restconf.common.patch.PatchContext) DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) DOMDataBroker(org.opendaylight.mdsal.dom.api.DOMDataBroker) Test(org.junit.Test)

Example 8 with PatchContext

use of org.opendaylight.restconf.common.patch.PatchContext in project netconf by opendaylight.

the class TestJsonPatchBodyReader method modulePatchMergeOperationOnListTest.

/**
 * Test of Yang Patch merge operation on list. Test consists of two edit operations - replace and merge.
 */
@Test
public void modulePatchMergeOperationOnListTest() throws Exception {
    final String uri = "instance-identifier-patch-module:patch-cont/my-list1/leaf1";
    mockBodyReader(uri, jsonToPatchBodyReader, false);
    final InputStream inputStream = TestJsonBodyReader.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHMergeOperationOnList.json");
    final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
    checkPatchContext(returnValue);
}
Also used : PatchContext(org.opendaylight.restconf.common.patch.PatchContext) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 9 with PatchContext

use of org.opendaylight.restconf.common.patch.PatchContext in project netconf by opendaylight.

the class TestJsonPatchBodyReader method modulePatchSimpleLeafValueTest.

/**
 * Test reading simple leaf value.
 */
@Test
public void modulePatchSimpleLeafValueTest() throws Exception {
    final String uri = "instance-identifier-patch-module:patch-cont/my-list1/leaf1";
    mockBodyReader(uri, jsonToPatchBodyReader, false);
    final InputStream inputStream = TestJsonBodyReader.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHSimpleLeafValue.json");
    final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
    checkPatchContext(returnValue);
}
Also used : PatchContext(org.opendaylight.restconf.common.patch.PatchContext) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 10 with PatchContext

use of org.opendaylight.restconf.common.patch.PatchContext in project netconf by opendaylight.

the class TestJsonPatchBodyReader method modulePatchCompleteTargetInURITest.

/**
 * Test using Patch when target is completely specified in request URI and thus target leaf contains only '/' sign.
 */
@Test
public void modulePatchCompleteTargetInURITest() throws Exception {
    final String uri = "instance-identifier-patch-module:patch-cont";
    mockBodyReader(uri, jsonToPatchBodyReader, false);
    final InputStream inputStream = TestJsonBodyReader.class.getResourceAsStream("/instanceidentifier/json/jsonPATCHdataCompleteTargetInURI.json");
    final PatchContext returnValue = jsonToPatchBodyReader.readFrom(null, null, null, mediaType, null, inputStream);
    checkPatchContext(returnValue);
}
Also used : PatchContext(org.opendaylight.restconf.common.patch.PatchContext) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

PatchContext (org.opendaylight.restconf.common.patch.PatchContext)42 Test (org.junit.Test)36 InputStream (java.io.InputStream)31 PatchEntity (org.opendaylight.restconf.common.patch.PatchEntity)11 ArrayList (java.util.ArrayList)9 InstanceIdentifierContext (org.opendaylight.restconf.common.context.InstanceIdentifierContext)9 PatchStatusContext (org.opendaylight.restconf.common.patch.PatchStatusContext)7 AbstractBodyReaderTest (org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.AbstractBodyReaderTest)7 JsonBodyReaderTest (org.opendaylight.restconf.nb.rfc8040.jersey.providers.test.JsonBodyReaderTest)6 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)5 IOException (java.io.IOException)4 RestconfDocumentedException (org.opendaylight.restconf.common.errors.RestconfDocumentedException)4 MdsalRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.MdsalRestconfStrategy)4 NetconfRestconfStrategy (org.opendaylight.restconf.nb.rfc8040.rests.transactions.NetconfRestconfStrategy)4 URISyntaxException (java.net.URISyntaxException)3 WebApplicationException (javax.ws.rs.WebApplicationException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 XMLStreamException (javax.xml.stream.XMLStreamException)3 DefaultDOMRpcResult (org.opendaylight.mdsal.dom.spi.DefaultDOMRpcResult)3 Verify.verify (com.google.common.base.Verify.verify)2