Tests of codecs are included in codecs yangtools yang-data-codec-gson and yang-data-impl but we test codec on input data and also with presentation of Rest path.
* changed modifier of method getMediaType() to protected
* fix tests with method getMediaType()
* remove additional assertions
Change-Id: I211c2dc43690b663cada31deb3942e10fcc95366
Signed-off-by: ary <jatoth@cisco.com>
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.junit.Assert.assertNotNull;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.lang.reflect.Field;
import java.util.Collections;
import java.lang.reflect.Field;
import java.util.Collections;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedHashMap;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.controller.sal.rest.api.RestconfConstants;
import org.opendaylight.controller.sal.rest.impl.AbstractIdentifierAwareJaxRsProvider;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.controller.sal.rest.api.RestconfConstants;
import org.opendaylight.controller.sal.rest.impl.AbstractIdentifierAwareJaxRsProvider;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
- * sal-rest-connector
- * org.opendaylight.controller.sal.rest.impl.test.providers
+ * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
*/
public abstract class AbstractBodyReaderTest {
*/
public abstract class AbstractBodyReaderTest {
- protected final static ControllerContext controllerContext = ControllerContext.getInstance();
+ protected final static ControllerContext controllerContext = ControllerContext
+ .getInstance();
protected final MediaType mediaType;
private static Field uriField;
private static Field requestField;
protected final MediaType mediaType;
private static Field uriField;
private static Field requestField;
- public AbstractBodyReaderTest () throws NoSuchFieldException, SecurityException {
- uriField = AbstractIdentifierAwareJaxRsProvider.class.getDeclaredField("uriInfo");
+ public AbstractBodyReaderTest() throws NoSuchFieldException,
+ SecurityException {
+ uriField = AbstractIdentifierAwareJaxRsProvider.class
+ .getDeclaredField("uriInfo");
uriField.setAccessible(true);
uriField.setAccessible(true);
- requestField = AbstractIdentifierAwareJaxRsProvider.class.getDeclaredField("request");
+ requestField = AbstractIdentifierAwareJaxRsProvider.class
+ .getDeclaredField("request");
requestField.setAccessible(true);
mediaType = getMediaType();
}
requestField.setAccessible(true);
mediaType = getMediaType();
}
- abstract MediaType getMediaType();
+ protected abstract MediaType getMediaType();
- protected static SchemaContext schemaContextLoader(final String yangPath, final SchemaContext schemaContext) {
+ protected static SchemaContext schemaContextLoader(final String yangPath,
+ final SchemaContext schemaContext) {
return TestRestconfUtils.loadSchemaContext(yangPath, schemaContext);
}
protected static <T extends AbstractIdentifierAwareJaxRsProvider> void mockBodyReader(
return TestRestconfUtils.loadSchemaContext(yangPath, schemaContext);
}
protected static <T extends AbstractIdentifierAwareJaxRsProvider> void mockBodyReader(
- final String identifier, final T normalizedNodeProvider, final boolean isPost) throws NoSuchFieldException,
+ final String identifier, final T normalizedNodeProvider,
+ final boolean isPost) throws NoSuchFieldException,
SecurityException, IllegalArgumentException, IllegalAccessException {
final UriInfo uriInfoMock = mock(UriInfo.class);
SecurityException, IllegalArgumentException, IllegalAccessException {
final UriInfo uriInfoMock = mock(UriInfo.class);
- final MultivaluedMap<String, String> pathParm = new MultivaluedHashMap<>(1);
- pathParm.put(RestconfConstants.IDENTIFIER, Collections.singletonList(identifier));
+ final MultivaluedMap<String, String> pathParm = new MultivaluedHashMap<>(
+ 1);
+ pathParm.put(RestconfConstants.IDENTIFIER,
+ Collections.singletonList(identifier));
when(uriInfoMock.getPathParameters()).thenReturn(pathParm);
when(uriInfoMock.getPathParameters(false)).thenReturn(pathParm);
when(uriInfoMock.getPathParameters(true)).thenReturn(pathParm);
when(uriInfoMock.getPathParameters()).thenReturn(pathParm);
when(uriInfoMock.getPathParameters(false)).thenReturn(pathParm);
when(uriInfoMock.getPathParameters(true)).thenReturn(pathParm);
requestField.set(normalizedNodeProvider, request);
}
requestField.set(normalizedNodeProvider, request);
}
- protected static void checkMountPointNormalizedNodeContext(final NormalizedNodeContext nnContext) {
+ protected static void checkMountPointNormalizedNodeContext(
+ final NormalizedNodeContext nnContext) {
checkNormalizedNodeContext(nnContext);
assertNotNull(nnContext.getInstanceIdentifierContext().getMountPoint());
}
checkNormalizedNodeContext(nnContext);
assertNotNull(nnContext.getInstanceIdentifierContext().getMountPoint());
}
- protected static void checkNormalizedNodeContext(final NormalizedNodeContext nnContext) {
- assertNotNull(nnContext);
+ protected static void checkNormalizedNodeContext(
+ final NormalizedNodeContext nnContext) {
assertNotNull(nnContext.getData());
assertNotNull(nnContext.getData());
- assertNotNull(nnContext.getInstanceIdentifierContext());
- assertNotNull(nnContext.getInstanceIdentifierContext().getInstanceIdentifier());
- assertNotNull(nnContext.getInstanceIdentifierContext().getSchemaContext());
+ assertNotNull(nnContext.getInstanceIdentifierContext()
+ .getInstanceIdentifier());
+ assertNotNull(nnContext.getInstanceIdentifierContext()
+ .getSchemaContext());
assertNotNull(nnContext.getInstanceIdentifierContext().getSchemaNode());
}
}
assertNotNull(nnContext.getInstanceIdentifierContext().getSchemaNode());
}
}
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import com.google.common.base.Optional;
import java.io.InputStream;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import com.google.common.base.Optional;
+
- * sal-rest-connector
- * org.opendaylight.controller.sal.rest.impl.test.providers
+ * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
- * Created: Mar 11, 2015
+ * Created: Mar 11, 2015
*/
public class TestJsonBodyReader extends AbstractBodyReaderTest {
private final JsonNormalizedNodeBodyReader jsonBodyReader;
private static SchemaContext schemaContext;
*/
public class TestJsonBodyReader extends AbstractBodyReaderTest {
private final JsonNormalizedNodeBodyReader jsonBodyReader;
private static SchemaContext schemaContext;
- public TestJsonBodyReader () throws NoSuchFieldException, SecurityException {
+ public TestJsonBodyReader() throws NoSuchFieldException, SecurityException {
super();
jsonBodyReader = new JsonNormalizedNodeBodyReader();
}
@Override
super();
jsonBodyReader = new JsonNormalizedNodeBodyReader();
}
@Override
- MediaType getMediaType() {
+ protected MediaType getMediaType() {
return new MediaType(MediaType.APPLICATION_XML, null);
}
@BeforeClass
return new MediaType(MediaType.APPLICATION_XML, null);
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException, SecurityException {
- schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
+ public static void initialization() throws NoSuchFieldException,
+ SecurityException {
+ schemaContext = schemaContextLoader("/instanceidentifier/yang",
+ schemaContext);
schemaContext = schemaContextLoader("/modules", schemaContext);
schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
controllerContext.setSchemas(schemaContext);
schemaContext = schemaContextLoader("/modules", schemaContext);
schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
controllerContext.setSchemas(schemaContext);
@Test
public void moduleDataTest() throws Exception {
@Test
public void moduleDataTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName("cont");
final String uri = "instance-identifier-module:cont";
mockBodyReader(uri, jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/instanceidentifier/json/jsondata.json");
final String uri = "instance-identifier-module:cont";
mockBodyReader(uri, jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/instanceidentifier/json/jsondata.json");
- final NormalizedNodeContext returnValue = jsonBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
@Test
public void moduleSubContainerDataPutTest() throws Exception {
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
@Test
public void moduleSubContainerDataPutTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName("cont");
final String uri = "instance-identifier-module:cont/cont1";
mockBodyReader(uri, jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
final String uri = "instance-identifier-module:cont/cont1";
mockBodyReader(uri, jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
- final NormalizedNodeContext returnValue = jsonBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkNormalizedNodeContext(returnValue);
- checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, "cont1");
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue,
+ "cont1");
}
@Test
public void moduleSubContainerDataPostTest() throws Exception {
}
@Test
public void moduleSubContainerDataPostTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName("cont");
final String uri = "instance-identifier-module:cont";
mockBodyReader(uri, jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
final String uri = "instance-identifier-module:cont";
mockBodyReader(uri, jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
- final NormalizedNodeContext returnValue = jsonBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
mockBodyReader(uri, jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/invoke-rpc/json/rpc-input.json");
mockBodyReader(uri, jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyReader.class
.getResourceAsStream("/invoke-rpc/json/rpc-input.json");
- final NormalizedNodeContext returnValue = jsonBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
final ContainerNode inputNode = (ContainerNode) returnValue.getData();
checkNormalizedNodeContext(returnValue);
final ContainerNode inputNode = (ContainerNode) returnValue.getData();
- final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName.create(inputNode.getNodeType(), "cont"));
- final Optional<DataContainerChild<? extends PathArgument, ?>> contDataNode = inputNode.getChild(yangCont.getLastPathArgument());
+ final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName
+ .create(inputNode.getNodeType(), "cont"));
+ final Optional<DataContainerChild<? extends PathArgument, ?>> contDataNode = inputNode
+ .getChild(yangCont.getLastPathArgument());
assertTrue(contDataNode.isPresent());
assertTrue(contDataNode.get() instanceof ContainerNode);
assertTrue(contDataNode.isPresent());
assertTrue(contDataNode.get() instanceof ContainerNode);
- final YangInstanceIdentifier yangleaf = YangInstanceIdentifier.of(QName.create(inputNode.getNodeType(), "lf"));
- final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = ((ContainerNode)contDataNode.get()).getChild(yangleaf.getLastPathArgument());
+ final YangInstanceIdentifier yangleaf = YangInstanceIdentifier.of(QName
+ .create(inputNode.getNodeType(), "lf"));
+ final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = ((ContainerNode) contDataNode
+ .get()).getChild(yangleaf.getLastPathArgument());
assertTrue(leafDataNode.isPresent());
assertTrue(leafDataNode.isPresent());
- assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue().toString()));
+ assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue()
+ .toString()));
- private void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
+ private void checkExpectValueNormalizeNodeContext(
+ final DataSchemaNode dataSchemaNode,
final NormalizedNodeContext nnContext) {
checkExpectValueNormalizeNodeContext(dataSchemaNode, nnContext, null);
}
final NormalizedNodeContext nnContext) {
checkExpectValueNormalizeNodeContext(dataSchemaNode, nnContext, null);
}
- private void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
+ private void checkExpectValueNormalizeNodeContext(
+ final DataSchemaNode dataSchemaNode,
final NormalizedNodeContext nnContext, final String localQname) {
final NormalizedNodeContext nnContext, final String localQname) {
- YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier.of(dataSchemaNode.getQName());
+ YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier
+ .of(dataSchemaNode.getQName());
if (localQname != null && dataSchemaNode instanceof DataNodeContainer) {
if (localQname != null && dataSchemaNode instanceof DataNodeContainer) {
- final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode).getDataChildByName(localQname);
- dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent).node(child.getQName()).build();
- assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode().equals(child));
+ final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode)
+ .getDataChildByName(localQname);
+ dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent)
+ .node(child.getQName()).build();
+ assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode()
+ .equals(child));
- assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode().equals(dataSchemaNode));
+ assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode()
+ .equals(dataSchemaNode));
- assertTrue(nnContext.getInstanceIdentifierContext().getInstanceIdentifier().equals(dataNodeIdent));
- assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
+ assertTrue(nnContext.getInstanceIdentifierContext()
+ .getInstanceIdentifier().equals(dataNodeIdent));
+ assertNotNull(NormalizedNodes.findNode(nnContext.getData(),
+ dataNodeIdent));
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
import java.io.InputStream;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import com.google.common.base.Optional;
+
- * sal-rest-connector
- * org.opendaylight.controller.sal.rest.impl.test.providers
+ * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
- * Created: Mar 11, 2015
+ * Created: Mar 11, 2015
*/
public class TestJsonBodyReaderMountPoint extends AbstractBodyReaderTest {
private final JsonNormalizedNodeBodyReader jsonBodyReader;
private static SchemaContext schemaContext;
*/
public class TestJsonBodyReaderMountPoint extends AbstractBodyReaderTest {
private final JsonNormalizedNodeBodyReader jsonBodyReader;
private static SchemaContext schemaContext;
- public TestJsonBodyReaderMountPoint () throws NoSuchFieldException, SecurityException {
+ public TestJsonBodyReaderMountPoint() throws NoSuchFieldException,
+ SecurityException {
super();
jsonBodyReader = new JsonNormalizedNodeBodyReader();
}
@Override
super();
jsonBodyReader = new JsonNormalizedNodeBodyReader();
}
@Override
- MediaType getMediaType() {
+ protected MediaType getMediaType() {
return new MediaType(MediaType.APPLICATION_XML, null);
}
@BeforeClass
return new MediaType(MediaType.APPLICATION_XML, null);
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException, SecurityException {
- schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
+ public static void initialization() throws NoSuchFieldException,
+ SecurityException {
+ schemaContext = schemaContextLoader("/instanceidentifier/yang",
+ schemaContext);
schemaContext = schemaContextLoader("/modules", schemaContext);
schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
when(mountInstance.getSchemaContext()).thenReturn(schemaContext);
final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
schemaContext = schemaContextLoader("/modules", schemaContext);
schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
when(mountInstance.getSchemaContext()).thenReturn(schemaContext);
final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
- when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));
+ when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class)))
+ .thenReturn(Optional.of(mountInstance));
ControllerContext.getInstance().setMountService(mockMountService);
controllerContext.setSchemas(schemaContext);
ControllerContext.getInstance().setMountService(mockMountService);
controllerContext.setSchemas(schemaContext);
@Test
public void moduleDataTest() throws Exception {
@Test
public void moduleDataTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName("cont");
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
mockBodyReader(uri, jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/json/jsondata.json");
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
mockBodyReader(uri, jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/json/jsondata.json");
- final NormalizedNodeContext returnValue = jsonBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkMountPointNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
@Test
public void moduleSubContainerDataPutTest() throws Exception {
checkMountPointNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
@Test
public void moduleSubContainerDataPutTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName("cont");
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont/cont1";
mockBodyReader(uri, jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont/cont1";
mockBodyReader(uri, jsonBodyReader, false);
final InputStream inputStream = TestJsonBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
- final NormalizedNodeContext returnValue = jsonBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkMountPointNormalizedNodeContext(returnValue);
checkMountPointNormalizedNodeContext(returnValue);
- checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, "cont1");
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue,
+ "cont1");
}
@Test
public void moduleSubContainerDataPostTest() throws Exception {
}
@Test
public void moduleSubContainerDataPostTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName("cont");
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
mockBodyReader(uri, jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
mockBodyReader(uri, jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/json/json_sub_container.json");
- final NormalizedNodeContext returnValue = jsonBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkMountPointNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
checkMountPointNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
mockBodyReader(uri, jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyReaderMountPoint.class
.getResourceAsStream("/invoke-rpc/json/rpc-input.json");
mockBodyReader(uri, jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyReaderMountPoint.class
.getResourceAsStream("/invoke-rpc/json/rpc-input.json");
- final NormalizedNodeContext returnValue = jsonBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
final ContainerNode inputNode = (ContainerNode) returnValue.getData();
checkNormalizedNodeContext(returnValue);
final ContainerNode inputNode = (ContainerNode) returnValue.getData();
- final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName.create(inputNode.getNodeType(), "cont"));
- final Optional<DataContainerChild<? extends PathArgument, ?>> contDataNode = inputNode.getChild(yangCont.getLastPathArgument());
+ final YangInstanceIdentifier yangCont = YangInstanceIdentifier.of(QName
+ .create(inputNode.getNodeType(), "cont"));
+ final Optional<DataContainerChild<? extends PathArgument, ?>> contDataNode = inputNode
+ .getChild(yangCont.getLastPathArgument());
assertTrue(contDataNode.isPresent());
assertTrue(contDataNode.get() instanceof ContainerNode);
assertTrue(contDataNode.isPresent());
assertTrue(contDataNode.get() instanceof ContainerNode);
- final YangInstanceIdentifier yangleaf = YangInstanceIdentifier.of(QName.create(inputNode.getNodeType(), "lf"));
- final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = ((ContainerNode)contDataNode.get()).getChild(yangleaf.getLastPathArgument());
+ final YangInstanceIdentifier yangleaf = YangInstanceIdentifier.of(QName
+ .create(inputNode.getNodeType(), "lf"));
+ final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = ((ContainerNode) contDataNode
+ .get()).getChild(yangleaf.getLastPathArgument());
assertTrue(leafDataNode.isPresent());
assertTrue(leafDataNode.isPresent());
- assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue().toString()));
+ assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue()
+ .toString()));
- private void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
+ private void checkExpectValueNormalizeNodeContext(
+ final DataSchemaNode dataSchemaNode,
final NormalizedNodeContext nnContext) {
checkExpectValueNormalizeNodeContext(dataSchemaNode, nnContext, null);
}
final NormalizedNodeContext nnContext) {
checkExpectValueNormalizeNodeContext(dataSchemaNode, nnContext, null);
}
- protected void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
+ protected void checkExpectValueNormalizeNodeContext(
+ final DataSchemaNode dataSchemaNode,
final NormalizedNodeContext nnContext, final String localQname) {
final NormalizedNodeContext nnContext, final String localQname) {
- YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier.of(dataSchemaNode.getQName());
- final DOMMountPoint mountPoint = nnContext.getInstanceIdentifierContext().getMountPoint();
- final DataSchemaNode mountDataSchemaNode =
- mountPoint.getSchemaContext().getDataChildByName(dataSchemaNode.getQName());
+ YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier
+ .of(dataSchemaNode.getQName());
+ final DOMMountPoint mountPoint = nnContext
+ .getInstanceIdentifierContext().getMountPoint();
+ final DataSchemaNode mountDataSchemaNode = mountPoint
+ .getSchemaContext().getDataChildByName(
+ dataSchemaNode.getQName());
assertNotNull(mountDataSchemaNode);
if (localQname != null && dataSchemaNode instanceof DataNodeContainer) {
assertNotNull(mountDataSchemaNode);
if (localQname != null && dataSchemaNode instanceof DataNodeContainer) {
- final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode).getDataChildByName(localQname);
- dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent).node(child.getQName()).build();
- assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode().equals(child));
+ final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode)
+ .getDataChildByName(localQname);
+ dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent)
+ .node(child.getQName()).build();
+ assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode()
+ .equals(child));
} else {
assertTrue(mountDataSchemaNode.equals(dataSchemaNode));
}
} else {
assertTrue(mountDataSchemaNode.equals(dataSchemaNode));
}
- assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
+ assertNotNull(NormalizedNodes.findNode(nnContext.getData(),
+ dataNodeIdent));
package org.opendaylight.controller.sal.rest.impl.test.providers;
import static org.junit.Assert.assertTrue;
package org.opendaylight.controller.sal.rest.impl.test.providers;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.OutputStream;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
- * sal-rest-connector
- * org.opendaylight.controller.sal.rest.impl.test.providers
+ * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
- * Created: Mar 12, 2015
+ * Created: Mar 12, 2015
*/
public class TestJsonBodyWriter extends AbstractBodyReaderTest {
*/
public class TestJsonBodyWriter extends AbstractBodyReaderTest {
private final NormalizedNodeJsonBodyWriter jsonBodyWriter;
private static SchemaContext schemaContext;
private final NormalizedNodeJsonBodyWriter jsonBodyWriter;
private static SchemaContext schemaContext;
- public TestJsonBodyWriter () throws NoSuchFieldException, SecurityException {
+ public TestJsonBodyWriter() throws NoSuchFieldException, SecurityException {
super();
jsonBodyWriter = new NormalizedNodeJsonBodyWriter();
jsonBodyReader = new JsonNormalizedNodeBodyReader();
}
@Override
super();
jsonBodyWriter = new NormalizedNodeJsonBodyWriter();
jsonBodyReader = new JsonNormalizedNodeBodyReader();
}
@Override
- MediaType getMediaType() {
+ protected MediaType getMediaType() {
return new MediaType(MediaType.APPLICATION_XML, null);
}
@BeforeClass
return new MediaType(MediaType.APPLICATION_XML, null);
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException, SecurityException {
- schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
+ public static void initialization() throws NoSuchFieldException,
+ SecurityException {
+ schemaContext = schemaContextLoader("/instanceidentifier/yang",
+ schemaContext);
schemaContext = schemaContextLoader("/modules", schemaContext);
schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
controllerContext.setSchemas(schemaContext);
schemaContext = schemaContextLoader("/modules", schemaContext);
schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
controllerContext.setSchemas(schemaContext);
mockBodyReader(uri, jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyWriter.class
.getResourceAsStream("/invoke-rpc/json/rpc-output.json");
mockBodyReader(uri, jsonBodyReader, true);
final InputStream inputStream = TestJsonBodyWriter.class
.getResourceAsStream("/invoke-rpc/json/rpc-output.json");
- final NormalizedNodeContext returnValue = jsonBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = jsonBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
final OutputStream output = new ByteArrayOutputStream();
final OutputStream output = new ByteArrayOutputStream();
- jsonBodyWriter.writeTo(returnValue, null, null, null, mediaType, null, output);
+ jsonBodyWriter.writeTo(returnValue, null, null, null, mediaType, null,
+ output);
assertTrue(output.toString().contains("lf-test"));
}
}
assertTrue(output.toString().contains("lf-test"));
}
}
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import com.google.common.base.Optional;
import java.io.InputStream;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.XmlNormalizedNodeBodyReader;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.sal.rest.impl.XmlNormalizedNodeBodyReader;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import com.google.common.base.Optional;
+
- * sal-rest-connector
- * org.opendaylight.controller.sal.rest.impl.test.providers
+ * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
*/
public class TestXmlBodyReader extends AbstractBodyReaderTest {
private final XmlNormalizedNodeBodyReader xmlBodyReader;
private static SchemaContext schemaContext;
*/
public class TestXmlBodyReader extends AbstractBodyReaderTest {
private final XmlNormalizedNodeBodyReader xmlBodyReader;
private static SchemaContext schemaContext;
- public TestXmlBodyReader () throws NoSuchFieldException, SecurityException {
+ public TestXmlBodyReader() throws NoSuchFieldException, SecurityException {
super();
xmlBodyReader = new XmlNormalizedNodeBodyReader();
}
@Override
super();
xmlBodyReader = new XmlNormalizedNodeBodyReader();
}
@Override
- MediaType getMediaType() {
+ protected MediaType getMediaType() {
return new MediaType(MediaType.APPLICATION_XML, null);
}
@BeforeClass
return new MediaType(MediaType.APPLICATION_XML, null);
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException, SecurityException {
- schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
+ public static void initialization() throws NoSuchFieldException,
+ SecurityException {
+ schemaContext = schemaContextLoader("/instanceidentifier/yang",
+ schemaContext);
schemaContext = schemaContextLoader("/modules", schemaContext);
schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
controllerContext.setSchemas(schemaContext);
schemaContext = schemaContextLoader("/modules", schemaContext);
schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
controllerContext.setSchemas(schemaContext);
@Test
public void moduleDataTest() throws Exception {
@Test
public void moduleDataTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName("cont");
final String uri = "instance-identifier-module:cont";
mockBodyReader(uri, xmlBodyReader, false);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xmldata.xml");
final String uri = "instance-identifier-module:cont";
mockBodyReader(uri, xmlBodyReader, false);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xmldata.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
@Test
public void moduleSubContainerDataPutTest() throws Exception {
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
@Test
public void moduleSubContainerDataPutTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName("cont");
final String uri = "instance-identifier-module:cont/cont1";
mockBodyReader(uri, xmlBodyReader, false);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
final String uri = "instance-identifier-module:cont/cont1";
mockBodyReader(uri, xmlBodyReader, false);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkNormalizedNodeContext(returnValue);
- checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, "cont1");
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue,
+ "cont1");
}
@Test
public void moduleSubContainerDataPostTest() throws Exception {
}
@Test
public void moduleSubContainerDataPostTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName("cont");
final String uri = "instance-identifier-module:cont";
mockBodyReader(uri, xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
final String uri = "instance-identifier-module:cont";
mockBodyReader(uri, xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
checkNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
mockBodyReader(uri, xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/invoke-rpc/xml/rpc-input.xml");
mockBodyReader(uri, xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReader.class
.getResourceAsStream("/invoke-rpc/xml/rpc-input.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
final ContainerNode contNode = (ContainerNode) returnValue.getData();
checkNormalizedNodeContext(returnValue);
final ContainerNode contNode = (ContainerNode) returnValue.getData();
- final YangInstanceIdentifier yangleaf = YangInstanceIdentifier.of(QName.create(contNode.getNodeType(), "lf"));
- final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = contNode.getChild(yangleaf.getLastPathArgument());
+ final YangInstanceIdentifier yangleaf = YangInstanceIdentifier.of(QName
+ .create(contNode.getNodeType(), "lf"));
+ final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = contNode
+ .getChild(yangleaf.getLastPathArgument());
assertTrue(leafDataNode.isPresent());
assertTrue(leafDataNode.isPresent());
- assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue().toString()));
+ assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue()
+ .toString()));
- private void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
+ private void checkExpectValueNormalizeNodeContext(
+ final DataSchemaNode dataSchemaNode,
final NormalizedNodeContext nnContext) {
checkExpectValueNormalizeNodeContext(dataSchemaNode, nnContext, null);
}
final NormalizedNodeContext nnContext) {
checkExpectValueNormalizeNodeContext(dataSchemaNode, nnContext, null);
}
- private void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
+ private void checkExpectValueNormalizeNodeContext(
+ final DataSchemaNode dataSchemaNode,
final NormalizedNodeContext nnContext, final String localQname) {
final NormalizedNodeContext nnContext, final String localQname) {
- YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier.of(dataSchemaNode.getQName());
+ YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier
+ .of(dataSchemaNode.getQName());
if (localQname != null && dataSchemaNode instanceof DataNodeContainer) {
if (localQname != null && dataSchemaNode instanceof DataNodeContainer) {
- final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode).getDataChildByName(localQname);
- dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent).node(child.getQName()).build();
- assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode().equals(child));
+ final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode)
+ .getDataChildByName(localQname);
+ dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent)
+ .node(child.getQName()).build();
+ assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode()
+ .equals(child));
- assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode().equals(dataSchemaNode));
+ assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode()
+ .equals(dataSchemaNode));
- assertTrue(nnContext.getInstanceIdentifierContext().getInstanceIdentifier().equals(dataNodeIdent));
- assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
+ assertTrue(nnContext.getInstanceIdentifierContext()
+ .getInstanceIdentifier().equals(dataNodeIdent));
+ assertNotNull(NormalizedNodes.findNode(nnContext.getData(),
+ dataNodeIdent));
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import com.google.common.base.Optional;
import java.io.InputStream;
import java.io.InputStream;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import com.google.common.base.Optional;
+
- * sal-rest-connector
- * org.opendaylight.controller.sal.rest.impl.test.providers
+ * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
*/
public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest {
private final XmlNormalizedNodeBodyReader xmlBodyReader;
private static SchemaContext schemaContext;
*/
public class TestXmlBodyReaderMountPoint extends AbstractBodyReaderTest {
private final XmlNormalizedNodeBodyReader xmlBodyReader;
private static SchemaContext schemaContext;
- public TestXmlBodyReaderMountPoint () throws NoSuchFieldException, SecurityException {
+ public TestXmlBodyReaderMountPoint() throws NoSuchFieldException,
+ SecurityException {
super();
xmlBodyReader = new XmlNormalizedNodeBodyReader();
}
@Override
super();
xmlBodyReader = new XmlNormalizedNodeBodyReader();
}
@Override
- MediaType getMediaType() {
+ protected MediaType getMediaType() {
return new MediaType(MediaType.APPLICATION_XML, null);
}
@BeforeClass
return new MediaType(MediaType.APPLICATION_XML, null);
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException, SecurityException {
- schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
+ public static void initialization() throws NoSuchFieldException,
+ SecurityException {
+ schemaContext = schemaContextLoader("/instanceidentifier/yang",
+ schemaContext);
schemaContext = schemaContextLoader("/modules", schemaContext);
schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
when(mountInstance.getSchemaContext()).thenReturn(schemaContext);
final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
schemaContext = schemaContextLoader("/modules", schemaContext);
schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
when(mountInstance.getSchemaContext()).thenReturn(schemaContext);
final DOMMountPointService mockMountService = mock(DOMMountPointService.class);
- when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class))).thenReturn(Optional.of(mountInstance));
+ when(mockMountService.getMountPoint(any(YangInstanceIdentifier.class)))
+ .thenReturn(Optional.of(mountInstance));
ControllerContext.getInstance().setMountService(mockMountService);
controllerContext.setSchemas(schemaContext);
ControllerContext.getInstance().setMountService(mockMountService);
controllerContext.setSchemas(schemaContext);
@Test
public void moduleDataTest() throws Exception {
@Test
public void moduleDataTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName("cont");
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
mockBodyReader(uri, xmlBodyReader, false);
final InputStream inputStream = TestXmlBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/xml/xmldata.xml");
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
mockBodyReader(uri, xmlBodyReader, false);
final InputStream inputStream = TestXmlBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/xml/xmldata.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkMountPointNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
@Test
public void moduleSubContainerDataPutTest() throws Exception {
checkMountPointNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
@Test
public void moduleSubContainerDataPutTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName("cont");
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont/cont1";
mockBodyReader(uri, xmlBodyReader, false);
final InputStream inputStream = TestXmlBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont/cont1";
mockBodyReader(uri, xmlBodyReader, false);
final InputStream inputStream = TestXmlBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkMountPointNormalizedNodeContext(returnValue);
checkMountPointNormalizedNodeContext(returnValue);
- checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue, "cont1");
+ checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue,
+ "cont1");
}
@Test
public void moduleSubContainerDataPostTest() throws Exception {
}
@Test
public void moduleSubContainerDataPostTest() throws Exception {
- final DataSchemaNode dataSchemaNode = schemaContext.getDataChildByName("cont");
+ final DataSchemaNode dataSchemaNode = schemaContext
+ .getDataChildByName("cont");
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
mockBodyReader(uri, xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
final String uri = "instance-identifier-module:cont/yang-ext:mount/instance-identifier-module:cont";
mockBodyReader(uri, xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReaderMountPoint.class
.getResourceAsStream("/instanceidentifier/xml/xml_sub_container.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkMountPointNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
checkMountPointNormalizedNodeContext(returnValue);
checkExpectValueNormalizeNodeContext(dataSchemaNode, returnValue);
}
mockBodyReader(uri, xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReaderMountPoint.class
.getResourceAsStream("/invoke-rpc/xml/rpc-input.xml");
mockBodyReader(uri, xmlBodyReader, true);
final InputStream inputStream = TestXmlBodyReaderMountPoint.class
.getResourceAsStream("/invoke-rpc/xml/rpc-input.xml");
- final NormalizedNodeContext returnValue = xmlBodyReader
- .readFrom(null, null, null, mediaType, null, inputStream);
+ final NormalizedNodeContext returnValue = xmlBodyReader.readFrom(null,
+ null, null, mediaType, null, inputStream);
checkNormalizedNodeContext(returnValue);
final ContainerNode contNode = (ContainerNode) returnValue.getData();
checkNormalizedNodeContext(returnValue);
final ContainerNode contNode = (ContainerNode) returnValue.getData();
- final YangInstanceIdentifier yangleaf = YangInstanceIdentifier.of(QName.create(contNode.getNodeType(), "lf"));
- final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = contNode.getChild(yangleaf.getLastPathArgument());
+ final YangInstanceIdentifier yangleaf = YangInstanceIdentifier.of(QName
+ .create(contNode.getNodeType(), "lf"));
+ final Optional<DataContainerChild<? extends PathArgument, ?>> leafDataNode = contNode
+ .getChild(yangleaf.getLastPathArgument());
assertTrue(leafDataNode.isPresent());
assertTrue(leafDataNode.isPresent());
- assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue().toString()));
+ assertTrue("lf-test".equalsIgnoreCase(leafDataNode.get().getValue()
+ .toString()));
- private void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
+ private void checkExpectValueNormalizeNodeContext(
+ final DataSchemaNode dataSchemaNode,
final NormalizedNodeContext nnContext) {
checkExpectValueNormalizeNodeContext(dataSchemaNode, nnContext, null);
}
final NormalizedNodeContext nnContext) {
checkExpectValueNormalizeNodeContext(dataSchemaNode, nnContext, null);
}
- protected void checkExpectValueNormalizeNodeContext(final DataSchemaNode dataSchemaNode,
+ protected void checkExpectValueNormalizeNodeContext(
+ final DataSchemaNode dataSchemaNode,
final NormalizedNodeContext nnContext, final String localQname) {
final NormalizedNodeContext nnContext, final String localQname) {
- YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier.of(dataSchemaNode.getQName());
- final DOMMountPoint mountPoint = nnContext.getInstanceIdentifierContext().getMountPoint();
- final DataSchemaNode mountDataSchemaNode =
- mountPoint.getSchemaContext().getDataChildByName(dataSchemaNode.getQName());
+ YangInstanceIdentifier dataNodeIdent = YangInstanceIdentifier
+ .of(dataSchemaNode.getQName());
+ final DOMMountPoint mountPoint = nnContext
+ .getInstanceIdentifierContext().getMountPoint();
+ final DataSchemaNode mountDataSchemaNode = mountPoint
+ .getSchemaContext().getDataChildByName(
+ dataSchemaNode.getQName());
assertNotNull(mountDataSchemaNode);
if (localQname != null && dataSchemaNode instanceof DataNodeContainer) {
assertNotNull(mountDataSchemaNode);
if (localQname != null && dataSchemaNode instanceof DataNodeContainer) {
- final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode).getDataChildByName(localQname);
- dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent).node(child.getQName()).build();
- assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode().equals(child));
+ final DataSchemaNode child = ((DataNodeContainer) dataSchemaNode)
+ .getDataChildByName(localQname);
+ dataNodeIdent = YangInstanceIdentifier.builder(dataNodeIdent)
+ .node(child.getQName()).build();
+ assertTrue(nnContext.getInstanceIdentifierContext().getSchemaNode()
+ .equals(child));
} else {
assertTrue(mountDataSchemaNode.equals(dataSchemaNode));
}
} else {
assertTrue(mountDataSchemaNode.equals(dataSchemaNode));
}
- assertNotNull(NormalizedNodes.findNode(nnContext.getData(), dataNodeIdent));
+ assertNotNull(NormalizedNodes.findNode(nnContext.getData(),
+ dataNodeIdent));
package org.opendaylight.controller.sal.rest.impl.test.providers;
import static org.junit.Assert.assertTrue;
package org.opendaylight.controller.sal.rest.impl.test.providers;
import static org.junit.Assert.assertTrue;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MediaType;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import org.opendaylight.controller.md.sal.rest.common.TestRestconfUtils;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
- * sal-rest-connector
- * org.opendaylight.controller.sal.rest.impl.test.providers
+ * sal-rest-connector org.opendaylight.controller.sal.rest.impl.test.providers
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
*
*
*
* @author <a href="mailto:vdemcak@cisco.com">Vaclav Demcak</a>
*
- * Created: Mar 12, 2015
+ * Created: Mar 12, 2015
*/
public class TestXmlBodyWriter extends AbstractBodyReaderTest {
private final NormalizedNodeXmlBodyWriter xmlBodyWriter;
private static SchemaContext schemaContext;
*/
public class TestXmlBodyWriter extends AbstractBodyReaderTest {
private final NormalizedNodeXmlBodyWriter xmlBodyWriter;
private static SchemaContext schemaContext;
- public TestXmlBodyWriter () throws NoSuchFieldException, SecurityException {
+ public TestXmlBodyWriter() throws NoSuchFieldException, SecurityException {
super();
xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
}
@Override
super();
xmlBodyWriter = new NormalizedNodeXmlBodyWriter();
}
@Override
- MediaType getMediaType() {
+ protected MediaType getMediaType() {
return new MediaType(MediaType.APPLICATION_XML, null);
}
@BeforeClass
return new MediaType(MediaType.APPLICATION_XML, null);
}
@BeforeClass
- public static void initialization() throws NoSuchFieldException, SecurityException {
- schemaContext = schemaContextLoader("/instanceidentifier/yang", schemaContext);
+ public static void initialization() throws NoSuchFieldException,
+ SecurityException {
+ schemaContext = schemaContextLoader("/instanceidentifier/yang",
+ schemaContext);
schemaContext = schemaContextLoader("/modules", schemaContext);
schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
controllerContext.setSchemas(schemaContext);
schemaContext = schemaContextLoader("/modules", schemaContext);
schemaContext = schemaContextLoader("/invoke-rpc", schemaContext);
controllerContext.setSchemas(schemaContext);
public void rpcModuleInputTest() throws Exception {
final String uri = "invoke-rpc-module:rpc-test";
final String pathToInputFile = "/invoke-rpc/xml/rpc-output.xml";
public void rpcModuleInputTest() throws Exception {
final String uri = "invoke-rpc-module:rpc-test";
final String pathToInputFile = "/invoke-rpc/xml/rpc-output.xml";
- final NormalizedNodeContext nnContext =
- TestRestconfUtils.loadNormalizedContextFromXmlFile(pathToInputFile, uri);
+ final NormalizedNodeContext nnContext = TestRestconfUtils
+ .loadNormalizedContextFromXmlFile(pathToInputFile, uri);
final OutputStream output = new ByteArrayOutputStream();
final OutputStream output = new ByteArrayOutputStream();
- xmlBodyWriter.writeTo(nnContext, null, null, null, mediaType, null, output);
+ xmlBodyWriter.writeTo(nnContext, null, null, null, mediaType, null,
+ output);
assertTrue(output.toString().contains("lf-test"));
}
}
\ No newline at end of file
assertTrue(output.toString().contains("lf-test"));
}
}
\ No newline at end of file