Search in sources :

Example 1 with PutResult

use of org.opendaylight.netconf.sal.restconf.impl.PutResult in project netconf by opendaylight.

the class RestPutConfigTest method mockingBrokerPut.

private void mockingBrokerPut(final YangInstanceIdentifier yii, final NormalizedNode data) {
    final PutResult result = Mockito.mock(PutResult.class);
    Mockito.when(this.brokerFacade.commitConfigurationDataPut(schemaContext, yii, data, null, null)).thenReturn(result);
    Mockito.doReturn(CommitInfo.emptyFluentFuture()).when(result).getFutureOfPutData();
    Mockito.when(result.getStatus()).thenReturn(Status.OK);
}
Also used : PutResult(org.opendaylight.netconf.sal.restconf.impl.PutResult)

Example 2 with PutResult

use of org.opendaylight.netconf.sal.restconf.impl.PutResult in project netconf by opendaylight.

the class JSONRestconfServiceImplTest method testPut.

@SuppressWarnings("rawtypes")
@Test
public void testPut() throws Exception {
    final PutResult result = mock(PutResult.class);
    when(brokerFacade.commitConfigurationDataPut(notNull(EffectiveModelContext.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class), isNull(), isNull())).thenReturn(result);
    doReturn(CommitInfo.emptyFluentFuture()).when(result).getFutureOfPutData();
    when(result.getStatus()).thenReturn(Status.OK);
    final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
    final String payload = loadData("/parts/ietf-interfaces_interfaces.json");
    this.service.put(uriPath, payload);
    final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
    final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
    verify(brokerFacade).commitConfigurationDataPut(notNull(EffectiveModelContext.class), capturedPath.capture(), capturedNode.capture(), isNull(), isNull());
    verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME, new Object[] { INTERFACE_QNAME, NAME_QNAME, "eth0" });
    assertTrue("Expected MapEntryNode. Actual " + capturedNode.getValue().getClass(), capturedNode.getValue() instanceof MapEntryNode);
    final MapEntryNode actualNode = (MapEntryNode) capturedNode.getValue();
    assertEquals("MapEntryNode node type", INTERFACE_QNAME, actualNode.getIdentifier().getNodeType());
    verifyLeafNode(actualNode, NAME_QNAME, "eth0");
    verifyLeafNode(actualNode, TYPE_QNAME, "ethernetCsmacd");
    verifyLeafNode(actualNode, ENABLED_QNAME, Boolean.FALSE);
    verifyLeafNode(actualNode, DESC_QNAME, "some interface");
}
Also used : CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) MapEntryNode(org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode) PutResult(org.opendaylight.netconf.sal.restconf.impl.PutResult) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 3 with PutResult

use of org.opendaylight.netconf.sal.restconf.impl.PutResult in project netconf by opendaylight.

the class JSONRestconfServiceImplTest method testPutBehindMountPoint.

@SuppressWarnings("rawtypes")
@Test
public void testPutBehindMountPoint() throws Exception {
    final PutResult result = mock(PutResult.class);
    when(brokerFacade.commitMountPointDataPut(notNull(DOMMountPoint.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class), isNull(), isNull())).thenReturn(result);
    doReturn(CommitInfo.emptyFluentFuture()).when(result).getFutureOfPutData();
    when(result.getStatus()).thenReturn(Status.OK);
    final String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont/cont1";
    final String payload = loadData("/full-versions/testCont1Data.json");
    this.service.put(uriPath, payload);
    final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
    final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
    verify(brokerFacade).commitMountPointDataPut(same(mockMountPoint), capturedPath.capture(), capturedNode.capture(), isNull(), isNull());
    verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
    assertTrue("Expected ContainerNode", capturedNode.getValue() instanceof ContainerNode);
    final ContainerNode actualNode = (ContainerNode) capturedNode.getValue();
    assertEquals("ContainerNode node type", TEST_CONT1_QNAME, actualNode.getIdentifier().getNodeType());
    verifyLeafNode(actualNode, TEST_LF11_QNAME, "lf11 data");
    verifyLeafNode(actualNode, TEST_LF12_QNAME, "lf12 data");
}
Also used : DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) ContainerNode(org.opendaylight.yangtools.yang.data.api.schema.ContainerNode) DataContainerNode(org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) PutResult(org.opendaylight.netconf.sal.restconf.impl.PutResult) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) Test(org.junit.Test)

Example 4 with PutResult

use of org.opendaylight.netconf.sal.restconf.impl.PutResult in project netconf by opendaylight.

the class JSONRestconfServiceImplTest method testPutFailure.

@Test(expected = OperationFailedException.class)
@SuppressWarnings("checkstyle:IllegalThrows")
public void testPutFailure() throws Throwable {
    final PutResult result = mock(PutResult.class);
    doReturn(immediateFailedFluentFuture(new TransactionCommitFailedException("mock"))).when(result).getFutureOfPutData();
    when(result.getStatus()).thenReturn(Status.OK);
    when(brokerFacade.commitConfigurationDataPut(notNull(EffectiveModelContext.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class), Mockito.anyString(), Mockito.anyString())).thenReturn(result);
    final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
    final String payload = loadData("/parts/ietf-interfaces_interfaces.json");
    this.service.put(uriPath, payload);
}
Also used : TransactionCommitFailedException(org.opendaylight.mdsal.common.api.TransactionCommitFailedException) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) PutResult(org.opendaylight.netconf.sal.restconf.impl.PutResult) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) EffectiveModelContext(org.opendaylight.yangtools.yang.model.api.EffectiveModelContext) Test(org.junit.Test)

Example 5 with PutResult

use of org.opendaylight.netconf.sal.restconf.impl.PutResult in project netconf by opendaylight.

the class RestPutOperationTest method testRpcResultCommitedToStatusCodesWithMountPoint.

@Test
public void testRpcResultCommitedToStatusCodesWithMountPoint() throws UnsupportedEncodingException, FileNotFoundException, URISyntaxException {
    final PutResult result = mock(PutResult.class);
    when(brokerFacade.commitMountPointDataPut(any(DOMMountPoint.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class), null, null)).thenReturn(result);
    doReturn(CommitInfo.emptyFluentFuture()).when(result).getFutureOfPutData();
    when(result.getStatus()).thenReturn(Status.OK);
    mockMountPoint();
    String uri = "/config/ietf-interfaces:interfaces/interface/0/yang-ext:mount/test-module:cont";
    assertEquals(200, put(uri, MediaType.APPLICATION_XML, xmlData2));
    uri = "/config/ietf-interfaces:interfaces/yang-ext:mount/test-module:cont";
    assertEquals(200, put(uri, MediaType.APPLICATION_XML, xmlData2));
}
Also used : DOMMountPoint(org.opendaylight.mdsal.dom.api.DOMMountPoint) NormalizedNode(org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode) PutResult(org.opendaylight.netconf.sal.restconf.impl.PutResult) YangInstanceIdentifier(org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier) JerseyTest(org.glassfish.jersey.test.JerseyTest) Test(org.junit.Test)

Aggregations

PutResult (org.opendaylight.netconf.sal.restconf.impl.PutResult)8 NormalizedNode (org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode)7 Test (org.junit.Test)6 YangInstanceIdentifier (org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier)6 EffectiveModelContext (org.opendaylight.yangtools.yang.model.api.EffectiveModelContext)4 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)3 DOMMountPoint (org.opendaylight.mdsal.dom.api.DOMMountPoint)3 JerseyTest (org.glassfish.jersey.test.JerseyTest)2 FluentFuture (com.google.common.util.concurrent.FluentFuture)1 Before (org.junit.Before)1 InOrder (org.mockito.InOrder)1 TransactionCommitFailedException (org.opendaylight.mdsal.common.api.TransactionCommitFailedException)1 BrokerFacade (org.opendaylight.netconf.sal.restconf.impl.BrokerFacade)1 ControllerContext (org.opendaylight.netconf.sal.restconf.impl.ControllerContext)1 ContainerNode (org.opendaylight.yangtools.yang.data.api.schema.ContainerNode)1 DataContainerNode (org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode)1 MapEntryNode (org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode)1