private final ControllerContext salContext;
private static final Splitter SLASH_SPLITTER = Splitter.on("/");
- private static final Splitter AT_SPLITTER = Splitter.on("@");
private static final String MOUNT_ARG = ControllerContext.MOUNT;
public SchemaRetrievalServiceImpl(final ControllerContext controllerContext) {
}
private SchemaContext getMountSchemaContext(final String identifier) {
- final InstanceIdentifierContext mountContext = salContext.toMountPointIdentifier(identifier);
+ final InstanceIdentifierContext<?> mountContext = salContext.toMountPointIdentifier(identifier);
return mountContext.getSchemaContext();
}
package org.opendaylight.controller.sal.rest.impl;
-import com.google.common.base.Optional;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Request;
import javax.ws.rs.core.UriInfo;
return uriInfo.getPathParameters(false).getFirst(RestconfConstants.IDENTIFIER);
}
- protected final Optional<InstanceIdentifierContext> getIdentifierWithSchema() {
- return Optional.of(getInstanceIdentifierContext());
- }
-
- protected InstanceIdentifierContext getInstanceIdentifierContext() {
+ protected InstanceIdentifierContext<?> getInstanceIdentifierContext() {
return ControllerContext.getInstance().toInstanceIdentifier(getIdentifier());
}
final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws IOException,
WebApplicationException {
try {
- final InstanceIdentifierContext<?> path = getIdentifierWithSchema().get();
+ final InstanceIdentifierContext<?> path = getInstanceIdentifierContext();
if (entityStream.available() < 1) {
return new NormalizedNodeContext(path, null);
}
}
@Override
+ @Deprecated
public NormalizedNodeContext invokeRpc(final String identifier, final String noPayload, final UriInfo uriInfo) {
return restconf.invokeRpc(identifier, noPayload, uriInfo);
}
}
errContBuild.withChild(listErorsBuilder.build());
- final NormalizedNodeContext errContext = new NormalizedNodeContext(new InstanceIdentifierContext<DataSchemaNode>(null,
+ final NormalizedNodeContext errContext = new NormalizedNodeContext(new InstanceIdentifierContext<>(null,
(DataSchemaNode) errorsSchemaNode, null, context.getGlobalSchema()), errContBuild.build());
Object responseBody;
final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
NormalizedNode<?, ?> data = errorsNode.getData();
- final InstanceIdentifierContext<DataSchemaNode> context = (InstanceIdentifierContext<DataSchemaNode>) errorsNode.getInstanceIdentifierContext();
- final DataSchemaNode schema = context.getSchemaNode();
+ final InstanceIdentifierContext<?> context = errorsNode.getInstanceIdentifierContext();
+ final DataSchemaNode schema = (DataSchemaNode) context.getSchemaNode();
SchemaPath path = context.getSchemaNode().getPath();
final OutputStreamWriter outputWriter = new OutputStreamWriter(outStream, Charsets.UTF_8);
private Object toXMLResponseBody(final NormalizedNodeContext errorsNode, final DataNodeContainer errorsSchemaNode) {
- final InstanceIdentifierContext<DataSchemaNode> pathContext = (InstanceIdentifierContext<DataSchemaNode>) errorsNode.getInstanceIdentifierContext();
+ final InstanceIdentifierContext<?> pathContext = errorsNode.getInstanceIdentifierContext();
final ByteArrayOutputStream outStream = new ByteArrayOutputStream();
XMLStreamWriter xmlWriter;
*/
package org.opendaylight.controller.sal.rest.impl;
-import com.google.common.base.Optional;
import java.io.IOException;
import java.io.InputStream;
import java.lang.annotation.Annotation;
final MultivaluedMap<String, String> httpHeaders, final InputStream entityStream) throws IOException,
WebApplicationException {
try {
- final Optional<InstanceIdentifierContext> path = getIdentifierWithSchema();
+ final InstanceIdentifierContext<?> path = getInstanceIdentifierContext();
if (entityStream.available() < 1) {
// represent empty nopayload input
- return new NormalizedNodeContext(path.get(), null);
+ return new NormalizedNodeContext(path, null);
}
final DocumentBuilder dBuilder;
}
final Document doc = dBuilder.parse(entityStream);
- final NormalizedNode<?, ?> result = parse(path.get(),doc);
- return new NormalizedNodeContext(path.get(),result);
+ final NormalizedNode<?, ?> result = parse(path,doc);
+ return new NormalizedNodeContext(path,result);
} catch (final Exception e) {
LOG.debug("Error parsing xml input", e);
onGlobalContextUpdated(schemas);
}
- public InstanceIdentifierContext toInstanceIdentifier(final String restconfInstance) {
+ public InstanceIdentifierContext<?> toInstanceIdentifier(final String restconfInstance) {
return toIdentifier(restconfInstance, false);
}
return globalSchema;
}
- public InstanceIdentifierContext toMountPointIdentifier(final String restconfInstance) {
+ public InstanceIdentifierContext<?> toMountPointIdentifier(final String restconfInstance) {
return toIdentifier(restconfInstance, true);
}
- private InstanceIdentifierContext toIdentifier(final String restconfInstance, final boolean toMountPointIdentifier) {
+ private InstanceIdentifierContext<?> toIdentifier(final String restconfInstance, final boolean toMountPointIdentifier) {
checkPreconditions();
if(restconfInstance == null) {
final InstanceIdentifierBuilder builder = YangInstanceIdentifier.builder();
final Module latestModule = globalSchema.findModuleByName(startModule, null);
- final InstanceIdentifierContext iiWithSchemaNode = collectPathArguments(builder, pathArgs, latestModule, null,
+ final InstanceIdentifierContext<?> iiWithSchemaNode = collectPathArguments(builder, pathArgs, latestModule, null,
toMountPointIdentifier);
if (iiWithSchemaNode == null) {
return object == null ? "" : URLEncoder.encode(codec.serialize(object).toString(), ControllerContext.URI_ENCODING_CHAR_SET);
}
- private InstanceIdentifierContext collectPathArguments(final InstanceIdentifierBuilder builder,
+ private InstanceIdentifierContext<?> collectPathArguments(final InstanceIdentifierBuilder builder,
final List<String> strings, final DataNodeContainer parentNode, final DOMMountPoint mountPoint,
final boolean returnJustMountPoint) {
Preconditions.<List<String>> checkNotNull(strings);
if (returnJustMountPoint || strings.size() == 1) {
final YangInstanceIdentifier instance = YangInstanceIdentifier.builder().toInstance();
- return new InstanceIdentifierContext(instance, mountPointSchema, mount,mountPointSchema);
+ return new InstanceIdentifierContext<>(instance, mountPointSchema, mount,mountPointSchema);
}
final String moduleNameBehindMountPoint = toModuleName(strings.get(1));
return createContext(builder.build(), targetNode, mountPoint,mountPoint != null ? mountPoint.getSchemaContext() : globalSchema);
}
- private InstanceIdentifierContext createContext(final YangInstanceIdentifier instance, final DataSchemaNode dataSchemaNode,
+ private InstanceIdentifierContext<?> createContext(final YangInstanceIdentifier instance, final DataSchemaNode dataSchemaNode,
final DOMMountPoint mountPoint, final SchemaContext schemaContext) {
final YangInstanceIdentifier instanceIdentifier = new DataNormalizer(schemaContext).toNormalized(instance);
- return new InstanceIdentifierContext(instanceIdentifier, dataSchemaNode, mountPoint,schemaContext);
+ return new InstanceIdentifierContext<>(instanceIdentifier, dataSchemaNode, mountPoint,schemaContext);
}
public static DataSchemaNode findInstanceDataChildByNameAndNamespace(final DataNodeContainer container, final String name,
import java.net.URISyntaxException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.ArrayList;
-import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.DataContainerNodeAttrBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.api.ListNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
-import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.util.ExtendedType;
import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
}
}
- private static class TypeDef {
- public final TypeDefinition<? extends Object> typedef;
- public final QName qName;
-
- TypeDef(final TypeDefinition<? extends Object> typedef, final QName qName) {
- this.typedef = typedef;
- this.qName = qName;
- }
- }
-
- private final static RestconfImpl INSTANCE = new RestconfImpl();
+ private static final RestconfImpl INSTANCE = new RestconfImpl();
private static final int NOTIFICATION_PORT = 8181;
private static final int CHAR_NOT_FOUND = -1;
- private final static String MOUNT_POINT_MODULE_NAME = "ietf-netconf";
+ private static final String MOUNT_POINT_MODULE_NAME = "ietf-netconf";
- private final static SimpleDateFormat REVISION_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
+ private static final SimpleDateFormat REVISION_FORMAT = new SimpleDateFormat("yyyy-MM-dd");
- private final static String SAL_REMOTE_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote";
+ private static final String SAL_REMOTE_NAMESPACE = "urn:opendaylight:params:xml:ns:yang:controller:md:sal:remote";
- private final static String SAL_REMOTE_RPC_SUBSRCIBE = "create-data-change-event-subscription";
+ private static final String SAL_REMOTE_RPC_SUBSRCIBE = "create-data-change-event-subscription";
private BrokerFacade broker;
Builders.containerBuilder((ContainerSchemaNode) modulesSchemaNode);
moduleContainerBuilder.withChild(allModuleMap);
- return new NormalizedNodeContext(new InstanceIdentifierContext(null, modulesSchemaNode,
+ return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, modulesSchemaNode,
null, schemaContext), moduleContainerBuilder.build());
}
throw new RestconfDocumentedException(errMsg, ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE);
}
- final InstanceIdentifierContext mountPointIdentifier = controllerContext.toMountPointIdentifier(identifier);
+ final InstanceIdentifierContext<?> mountPointIdentifier = controllerContext.toMountPointIdentifier(identifier);
final DOMMountPoint mountPoint = mountPointIdentifier.getMountPoint();
final Set<Module> modules = controllerContext.getAllModules(mountPoint);
- final SchemaContext schemaContext = mountPoint.getSchemaContext();
final MapNode mountPointModulesMap = makeModuleMapNode(modules);
final Module restconfModule = getRestconfModule();
Builders.containerBuilder((ContainerSchemaNode) modulesSchemaNode);
moduleContainerBuilder.withChild(mountPointModulesMap);
- return new NormalizedNodeContext(new InstanceIdentifierContext(null, modulesSchemaNode,
+ return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, modulesSchemaNode,
mountPoint, controllerContext.getGlobalSchema()), moduleContainerBuilder.build());
}
DOMMountPoint mountPoint = null;
final SchemaContext schemaContext;
if (identifier.contains(ControllerContext.MOUNT)) {
- final InstanceIdentifierContext mountPointIdentifier = controllerContext.toMountPointIdentifier(identifier);
+ final InstanceIdentifierContext<?> mountPointIdentifier = controllerContext.toMountPointIdentifier(identifier);
mountPoint = mountPointIdentifier.getMountPoint();
module = controllerContext.findModuleByNameAndRevision(mountPoint, moduleNameAndRevision);
schemaContext = mountPoint.getSchemaContext();
restconfModule, Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE);
Preconditions.checkState(moduleSchemaNode instanceof ListSchemaNode);
- return new NormalizedNodeContext(new InstanceIdentifierContext(null, moduleSchemaNode, mountPoint,
+ return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, moduleSchemaNode, mountPoint,
schemaContext), moduleMap);
}
streamsContainerBuilder.withChild(listStreamsBuilder.build());
- return new NormalizedNodeContext(new InstanceIdentifierContext(null, streamsContainerSchemaNode, null,
+ return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, streamsContainerSchemaNode, null,
schemaContext), streamsContainerBuilder.build());
}
Set<Module> modules = null;
DOMMountPoint mountPoint = null;
if (identifier.contains(ControllerContext.MOUNT)) {
- final InstanceIdentifierContext mountPointIdentifier = controllerContext.toMountPointIdentifier(identifier);
+ final InstanceIdentifierContext<?> mountPointIdentifier = controllerContext.toMountPointIdentifier(identifier);
mountPoint = mountPointIdentifier.getMountPoint();
modules = controllerContext.getAllModules(mountPoint);
final SchemaContext schemaContext;
if (identifier.contains(ControllerContext.MOUNT)) {
// mounted RPC call - look up mount instance.
- final InstanceIdentifierContext mountPointId = controllerContext.toMountPointIdentifier(identifier);
+ final InstanceIdentifierContext<?> mountPointId = controllerContext.toMountPointIdentifier(identifier);
mountPoint = mountPointId.getMountPoint();
schemaContext = mountPoint.getSchemaContext();
final int startOfRemoteRpcName = identifier.lastIndexOf(ControllerContext.MOUNT)
resultNodeSchema = rpcDataSchemaNode.getDataChildByName(result.getResult().getNodeType());
}
- return new NormalizedNodeContext(new InstanceIdentifierContext(null, resultNodeSchema, mountPoint,
+ return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, resultNodeSchema, mountPoint,
schemaContext), resultData);
}
@Override
public NormalizedNodeContext readConfigurationData(final String identifier, final UriInfo uriInfo) {
- final InstanceIdentifierContext iiWithData = controllerContext.toInstanceIdentifier(identifier);
+ final InstanceIdentifierContext<?> iiWithData = controllerContext.toInstanceIdentifier(identifier);
final DOMMountPoint mountPoint = iiWithData.getMountPoint();
NormalizedNode<?, ?> data = null;
final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
return new NormalizedNodeContext(iiWithData, data);
}
+ // FIXME: Move this to proper place
+ @SuppressWarnings("unused")
private Integer parseDepthParameter(final UriInfo info) {
final String param = info.getQueryParameters(false).getFirst(UriParameters.DEPTH.toString());
if (Strings.isNullOrEmpty(param) || "unbounded".equals(param)) {
@Override
public NormalizedNodeContext readOperationalData(final String identifier, final UriInfo info) {
- final InstanceIdentifierContext iiWithData = controllerContext.toInstanceIdentifier(identifier);
+ final InstanceIdentifierContext<?> iiWithData = controllerContext.toInstanceIdentifier(identifier);
final DOMMountPoint mountPoint = iiWithData.getMountPoint();
NormalizedNode<?, ?> data = null;
final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
return new NormalizedNodeContext(iiWithData, data);
}
- private boolean parsePrettyPrintParameter(final UriInfo info) {
- final String param = info.getQueryParameters(false).getFirst(UriParameters.PRETTY_PRINT.toString());
- return Boolean.parseBoolean(param);
- }
-
@Override
public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload) {
Preconditions.checkNotNull(identifier);
- final InstanceIdentifierContext<DataSchemaNode> iiWithData =
- (InstanceIdentifierContext<DataSchemaNode>) payload.getInstanceIdentifierContext();
+ final InstanceIdentifierContext<?> iiWithData = payload.getInstanceIdentifierContext();
validateInput(iiWithData.getSchemaNode(), payload);
validateTopLevelNodeName(payload, iiWithData.getInstanceIdentifier());
* if key values or key count in payload and URI isn't equal
*
*/
- private void validateListKeysEqualityInPayloadAndUri(final InstanceIdentifierContext<DataSchemaNode> iiWithData,
+ private void validateListKeysEqualityInPayloadAndUri(final InstanceIdentifierContext<?> iiWithData,
final NormalizedNode<?, ?> payload) {
if (iiWithData.getSchemaNode() instanceof ListSchemaNode) {
final List<QName> keyDefinitions = ((ListSchemaNode) iiWithData.getSchemaNode()).getKeyDefinition();
if (payloadNodeQname.compareTo(yangIdent.getLastPathArgument().getNodeType()) > 0) {
return yangIdent;
}
- final InstanceIdentifierContext parentContext = payload.getInstanceIdentifierContext();
+ final InstanceIdentifierContext<?> parentContext = payload.getInstanceIdentifierContext();
final SchemaNode parentSchemaNode = parentContext.getSchemaNode();
if(parentSchemaNode instanceof DataNodeContainer) {
final DataNodeContainer cast = (DataNodeContainer) parentSchemaNode;
}
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
- final InstanceIdentifierContext<DataSchemaNode> iiWithData = (InstanceIdentifierContext<DataSchemaNode>) payload.getInstanceIdentifierContext();
+ final InstanceIdentifierContext<?> iiWithData = payload.getInstanceIdentifierContext();
final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
- final YangInstanceIdentifier resultII;
try {
if (mountPoint != null) {
broker.commitConfigurationDataPost(mountPoint, normalizedII, payload.getData()).checkedGet();
@Override
public Response deleteConfigurationData(final String identifier) {
- final InstanceIdentifierContext<DataSchemaNode> iiWithData = controllerContext.toInstanceIdentifier(identifier);
+ final InstanceIdentifierContext<?> iiWithData = controllerContext.toInstanceIdentifier(identifier);
final DOMMountPoint mountPoint = iiWithData.getMountPoint();
final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
return result;
}
- private boolean endsWithMountPoint(final String identifier) {
- return identifier.endsWith(ControllerContext.MOUNT) || identifier.endsWith(ControllerContext.MOUNT + "/");
- }
-
- private String addMountPointIdentifier(final String identifier) {
- final boolean endsWith = identifier.endsWith("/");
- if (endsWith) {
- return (identifier + ControllerContext.MOUNT);
- }
-
- return identifier + "/" + ControllerContext.MOUNT;
- }
-
- private TypeDef typeDefinition(final TypeDefinition<?> type, final QName nodeQName) {
- TypeDefinition<?> baseType = type;
- QName qName = nodeQName;
- while (baseType.getBaseType() != null) {
- if (baseType instanceof ExtendedType) {
- qName = baseType.getQName();
- }
- baseType = baseType.getBaseType();
- }
-
- return new TypeDef(baseType, qName);
-
- }
-
- private TypeDef typeDefinition(final DataSchemaNode node) {
- if (node instanceof LeafListSchemaNode) {
- return typeDefinition(((LeafListSchemaNode)node).getType(), node.getQName());
- } else if (node instanceof LeafSchemaNode) {
- return typeDefinition(((LeafSchemaNode)node).getType(), node.getQName());
- } else if (node instanceof AnyXmlSchemaNode) {
- return null;
- } else {
- throw new IllegalArgumentException("Unhandled parameter types: " + Arrays.<Object> asList(node).toString());
- }
- }
-
- private InstanceIdentifierContext normalizeInstanceIdentifierWithSchemaNode(
- final InstanceIdentifierContext iiWithSchemaNode) {
- return normalizeInstanceIdentifierWithSchemaNode(iiWithSchemaNode, false);
- }
-
- private InstanceIdentifierContext normalizeInstanceIdentifierWithSchemaNode(
- final InstanceIdentifierContext iiWithSchemaNode, final boolean unwrapLastListNode) {
- return new InstanceIdentifierContext(instanceIdentifierToReadableFormForNormalizeNode(
- iiWithSchemaNode.getInstanceIdentifier(), unwrapLastListNode), iiWithSchemaNode.getSchemaNode(),
- iiWithSchemaNode.getMountPoint(),iiWithSchemaNode.getSchemaContext());
- }
-
- private YangInstanceIdentifier instanceIdentifierToReadableFormForNormalizeNode(
- final YangInstanceIdentifier instIdentifier, final boolean unwrapLastListNode) {
- Preconditions.checkNotNull(instIdentifier, "Instance identifier can't be null");
- final List<PathArgument> result = new ArrayList<PathArgument>();
- final Iterator<PathArgument> iter = instIdentifier.getPathArguments().iterator();
- while (iter.hasNext()) {
- final PathArgument pathArgument = iter.next();
- if (pathArgument instanceof NodeIdentifierWithPredicates && (iter.hasNext() || unwrapLastListNode)) {
- result.add(new YangInstanceIdentifier.NodeIdentifier(pathArgument.getNodeType()));
- }
- result.add(pathArgument);
- }
- return YangInstanceIdentifier.create(result);
- }
-
- private boolean isDataContainerNode(final DataSchemaNode schemaNode) {
- if (schemaNode instanceof ContainerSchemaNode || schemaNode instanceof ListSchemaNode) {
- return true;
- }
- return false;
- }
-
public BigInteger getOperationalReceived() {
// TODO Auto-generated method stub
return null;
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import com.google.gson.stream.JsonReader;
-import com.google.gson.stream.JsonToken;
-import java.io.IOException;
-import java.io.StringReader;
-import java.util.Map;
-import java.util.Set;
-import org.junit.BeforeClass;
-import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
-import org.opendaylight.controller.sal.restconf.impl.test.structures.Cont;
-import org.opendaylight.controller.sal.restconf.impl.test.structures.Lf;
-import org.opendaylight.controller.sal.restconf.impl.test.structures.LfLst;
-import org.opendaylight.controller.sal.restconf.impl.test.structures.Lst;
-import org.opendaylight.controller.sal.restconf.impl.test.structures.LstItem;
-
-public class CnSnJsonBasicYangTypesTest extends YangAndXmlAndDataSchemaLoader {
-
- @BeforeClass
- public static void initialize() {
- dataLoad("/cnsn-to-json/simple-yang-types", 1, "simple-yang-types", "cont1");
- }
-
- private void verifyJsonOutputForEmptyData(final String jsonOutput) {
- assertNotNull(jsonOutput);
- final StringReader strReader = new StringReader(jsonOutput);
- final JsonReader jReader = new JsonReader(strReader);
-
- String exception = null;
- Cont dataFromJson = null;
- try {
- dataFromJson = jsonReadCont1(jReader);
- } catch (final IOException e) {
- exception = e.getMessage();
- }
-
- assertNotNull("Data structures from json are missing.", dataFromJson);
- checkDataFromJsonEmpty(dataFromJson);
-
- assertNull("Error during reading Json output: " + exception, exception);
- }
-
- private void verifyJsonOutput(final String jsonOutput) {
- assertNotNull(jsonOutput);
- final StringReader strReader = new StringReader(jsonOutput);
- final JsonReader jReader = new JsonReader(strReader);
-
- String exception = null;
- Cont dataFromJson = null;
- try {
- dataFromJson = jsonReadCont1(jReader);
- } catch (final IOException e) {
- exception = e.getMessage();
- }
-
- assertNotNull("Data structures from json are missing.", dataFromJson);
- checkDataFromJson(dataFromJson);
-
- assertNull("Error during reading Json output: " + exception, exception);
- }
-
- private Cont jsonReadCont1(final JsonReader jReader) throws IOException {
- jReader.beginObject();
- assertNotNull("cont1 is missing.", jReader.hasNext());
-
- Cont dataFromJson = new Cont(jReader.nextName());
- dataFromJson = jsonReadCont1Elements(jReader, dataFromJson);
-
- assertFalse("cont shouldn't have other element.", jReader.hasNext());
- jReader.endObject();
- return dataFromJson;
-
- }
-
- private Cont jsonReadCont1Elements(final JsonReader jReader, final Cont redData) throws IOException {
- jReader.beginObject();
- while (jReader.hasNext()) {
- final String keyName = jReader.nextName();
- if (keyName.equals("lf11")) {
- redData.addLf(new Lf(keyName, nextValue(jReader)));
- } else if (keyName.equals("lflst11")) {
- LfLst lfLst = new LfLst(keyName);
- lfLst = jsonReadLflstValues(jReader, lfLst);
- redData.addLfLst(lfLst);
- } else if (keyName.equals("lflst12")) {
- final LfLst lfLst = new LfLst(keyName);
- jsonReadLflstValues(jReader, lfLst);
- redData.addLfLst(lfLst);
- } else if (keyName.equals("lst11")) {
- Lst lst = new Lst(keyName);
- lst = jsonReadLst11(jReader, lst);
- redData.addLst(lst);
- } else {
- assertTrue("Key " + keyName + " doesn't exists in yang file.", false);
- }
- }
- jReader.endObject();
- return redData;
-
- }
-
- private Lst jsonReadLst11(final JsonReader jReader, final Lst lst) throws IOException {
- jReader.beginArray();
-
- while (jReader.hasNext()) {
- final LstItem lstItem = jsonReadLst11Elements(jReader);
- lst.addLstItem(lstItem);
- }
- jReader.endArray();
- return lst;
- }
-
- private LstItem jsonReadLst11Elements(final JsonReader jReader) throws IOException {
- final LstItem lstItem = new LstItem();
- jReader.beginObject();
- while (jReader.hasNext()) {
- final String keyName = jReader.nextName();
- if (keyName.equals("lf111")) {
- lstItem.addLf(new Lf(keyName, nextValue(jReader)));
- } else if (keyName.equals("lf112")) {
- lstItem.addLf(new Lf(keyName, nextValue(jReader)));
- } else if (keyName.equals("cont111")) {
- Cont cont = new Cont(keyName);
- cont = jsonReadCont111(jReader, cont);
- lstItem.addCont(cont);
- } else if (keyName.equals("lst111")) {
- Lst lst = new Lst(keyName);
- lst = jsonReadLst111(jReader, lst);
- lstItem.addLst(lst);
- } else if (keyName.equals("lst112")) {
- Lst lst = new Lst(keyName);
- lst = jsonReadLst112(jReader, lst);
- lstItem.addLst(lst);
- } else {
- assertTrue("Key " + keyName + " doesn't exists in yang file.", false);
- }
- }
- jReader.endObject();
- return lstItem;
- }
-
- private Lst jsonReadLst112(final JsonReader jReader, final Lst lst) throws IOException {
- jReader.beginArray();
- while (jReader.hasNext()) {
- final LstItem lstItem = jsonReadLst112Elements(jReader);
- lst.addLstItem(lstItem);
- }
- jReader.endArray();
- return lst;
- }
-
- private LstItem jsonReadLst112Elements(final JsonReader jReader) throws IOException {
- final LstItem lstItem = new LstItem();
- jReader.beginObject();
- if (jReader.hasNext()) {
- final String keyName = jReader.nextName();
- if (keyName.equals("lf1121")) {
- lstItem.addLf(new Lf(keyName, nextValue(jReader)));
- }
- }
- jReader.endObject();
- return lstItem;
-
- }
-
- private Lst jsonReadLst111(final JsonReader jReader, final Lst lst) throws IOException {
- jReader.beginArray();
- while (jReader.hasNext()) {
- final LstItem lstItem = jsonReadLst111Elements(jReader);
- lst.addLstItem(lstItem);
- }
- jReader.endArray();
- return lst;
- }
-
- private LstItem jsonReadLst111Elements(final JsonReader jReader) throws IOException {
- final LstItem lstItem = new LstItem();
- jReader.beginObject();
- if (jReader.hasNext()) {
- final String keyName = jReader.nextName();
- if (keyName.equals("lf1111")) {
- lstItem.addLf(new Lf(keyName, nextValue(jReader)));
- }
- }
- jReader.endObject();
- return lstItem;
- }
-
- private Object nextValue(final JsonReader jReader) throws IOException {
- if (jReader.peek().equals(JsonToken.NULL)) {
- jReader.nextNull();
- return null;
- } else if (jReader.peek().equals(JsonToken.NUMBER)) {
- return jReader.nextInt();
- } else {
- return jReader.nextString();
- }
- }
-
- private Cont jsonReadCont111(final JsonReader jReader, Cont cont) throws IOException {
- jReader.beginObject();
- cont = jsonReadCont111Elements(jReader, cont);
- jReader.endObject();
- return cont;
- }
-
- private Cont jsonReadCont111Elements(final JsonReader jReader, final Cont cont) throws IOException {
- while (jReader.hasNext()) {
- final String keyName = jReader.nextName();
- if (keyName.equals("lf1111")) {
- cont.addLf(new Lf(keyName, nextValue(jReader)));
- } else if (keyName.equals("lflst1111")) {
- LfLst lfLst = new LfLst(keyName);
- lfLst = jsonReadLflstValues(jReader, lfLst);
- cont.addLfLst(lfLst);
- } else if (keyName.equals("lst1111")) {
- Lst lst = new Lst(keyName);
- lst = jsonReadLst1111(jReader, lst);
- cont.addLst(lst);
- } else {
- assertTrue("Key " + keyName + " doesn't exists in yang file.", false);
- }
- }
- return cont;
-
- }
-
- private Lst jsonReadLst1111(final JsonReader jReader, final Lst lst) throws IOException {
- jReader.beginArray();
- while (jReader.hasNext()) {
- final LstItem lstItem = jsonReadLst1111Elements(jReader);
- lst.addLstItem(lstItem);
- }
- jReader.endArray();
- return lst;
- }
-
- private LstItem jsonReadLst1111Elements(final JsonReader jReader) throws IOException {
- jReader.beginObject();
- final LstItem lstItem = new LstItem();
- while (jReader.hasNext()) {
- final String keyName = jReader.nextName();
- if (keyName.equals("lf1111A") || keyName.equals("lf1111B")) {
- lstItem.addLf(new Lf(keyName, nextValue(jReader)));
- }
- }
- jReader.endObject();
- return lstItem;
- }
-
- private LfLst jsonReadLflstValues(final JsonReader jReader, final LfLst lfLst) throws IOException {
- jReader.beginArray();
- while (jReader.hasNext()) {
- lfLst.addLf(new Lf(nextValue(jReader)));
- }
- jReader.endArray();
- return lfLst;
- }
-
- private void checkDataFromJsonEmpty(final Cont dataFromJson) {
- assertTrue(dataFromJson.getLfs().isEmpty());
- assertTrue(dataFromJson.getLfLsts().isEmpty());
- assertTrue(dataFromJson.getConts().isEmpty());
-
- final Map<String, Lst> lsts = dataFromJson.getLsts();
- assertEquals(1, lsts.size());
- final Lst lst11 = lsts.get("lst11");
- assertNotNull(lst11);
- final Set<LstItem> lstItems = lst11.getLstItems();
- assertNotNull(lstItems);
-
- LstItem lst11_1 = null;
- LstItem lst11_2 = null;
- LstItem lst11_3 = null;
- for (final LstItem lstItem : lstItems) {
- if (lstItem.getLfs().get("lf111").getValue().equals(1)) {
- lst11_1 = lstItem;
- } else if (lstItem.getLfs().get("lf111").getValue().equals(2)) {
- lst11_2 = lstItem;
- } else if (lstItem.getLfs().get("lf111").getValue().equals(3)) {
- lst11_3 = lstItem;
- }
- }
-
- assertNotNull(lst11_1);
- assertNotNull(lst11_2);
- assertNotNull(lst11_3);
-
- // lst11_1
- assertTrue(lst11_1.getLfLsts().isEmpty());
- assertEquals(1, lst11_1.getLfs().size());
- assertEquals(1, lst11_1.getConts().size());
- assertEquals(1, lst11_1.getLsts().size());
- assertEquals(lst11_1.getLsts().get("lst111"), new Lst("lst111").addLstItem(new LstItem().addLf("lf1111", 35))
- .addLstItem(new LstItem().addLf("lf1111", 34)).addLstItem(new LstItem()).addLstItem(new LstItem()));
- assertEquals(lst11_1.getConts().get("cont111"), new Cont("cont111"));
- // : lst11_1
-
- // lst11_2
- assertTrue(lst11_2.getLfLsts().isEmpty());
- assertEquals(1, lst11_2.getLfs().size());
- assertEquals(1, lst11_2.getConts().size());
- assertEquals(1, lst11_2.getLsts().size());
-
- final Cont lst11_2_cont111 = lst11_2.getConts().get("cont111");
-
- // -cont111
- assertNotNull(lst11_2_cont111);
- assertTrue(lst11_2_cont111.getLfs().isEmpty());
- assertEquals(1, lst11_2_cont111.getLfLsts().size());
- assertEquals(1, lst11_2_cont111.getLsts().size());
- assertTrue(lst11_2_cont111.getConts().isEmpty());
-
- assertEquals(new LfLst("lflst1111").addLf(1024).addLf(4096), lst11_2_cont111.getLfLsts().get("lflst1111"));
- assertEquals(
- new Lst("lst1111").addLstItem(new LstItem().addLf("lf1111B", 4)).addLstItem(
- new LstItem().addLf("lf1111A", "lf1111A str12")), lst11_2_cont111.getLsts().get("lst1111"));
- // :-cont111
- assertEquals(lst11_2.getLsts().get("lst112"), new Lst("lst112").addLstItem(new LstItem()));
- // : lst11_2
-
- // lst11_3
- assertEquals(1, lst11_3.getLfs().size());
- assertTrue(lst11_3.getLfLsts().isEmpty());
- assertTrue(lst11_3.getLsts().isEmpty());
- assertTrue(lst11_3.getLsts().isEmpty());
-
- // -cont111
- final Cont lst11_3_cont111 = lst11_3.getConts().get("cont111");
- assertEquals(0, lst11_3_cont111.getLfs().size());
- assertEquals(0, lst11_3_cont111.getLfLsts().size());
- assertEquals(1, lst11_3_cont111.getLsts().size());
- assertTrue(lst11_3_cont111.getConts().isEmpty());
-
- assertEquals(new Lst("lst1111").addLstItem(new LstItem()).addLstItem(new LstItem()), lst11_3_cont111.getLsts()
- .get("lst1111"));
- // :-cont111
- // : lst11_3
-
- }
-
- private void checkDataFromJson(final Cont dataFromJson) {
- assertNotNull(dataFromJson.getLfs().get("lf11"));
- assertEquals(dataFromJson.getLfs().get("lf11"), new Lf("lf11", "lf"));
-
- LfLst lflst11 = null;
- LfLst lflst12 = null;
-
- lflst11 = dataFromJson.getLfLsts().get("lflst11");
- lflst12 = dataFromJson.getLfLsts().get("lflst12");
-
- assertNotNull(lflst11);
- assertNotNull(lflst12);
-
- assertEquals(3, lflst11.getLfs().size());
- assertTrue(lflst11.getLfs().contains(new Lf(55)));
- assertTrue(lflst11.getLfs().contains(new Lf(56)));
- assertTrue(lflst11.getLfs().contains(new Lf(57)));
-
- assertEquals(3, lflst12.getLfs().size());
- assertTrue(lflst12.getLfs().contains(new Lf("lflst12 str1")));
- assertTrue(lflst12.getLfs().contains(new Lf("lflst12 str2")));
- assertTrue(lflst12.getLfs().contains(new Lf("lflst12 str3")));
-
- assertEquals(1, dataFromJson.getLsts().size());
- final Lst lst11 = dataFromJson.getLsts().get("lst11");
- assertNotNull(lst11);
- assertEquals(2, lst11.getLstItems().size());
-
- LstItem lst11_1 = null;
- LstItem lst11_2 = null;
- for (final LstItem lstItem : lst11.getLstItems()) {
- final Lf lf = lstItem.getLfs().get("lf111");
- if (lf != null && lf.getValue().equals(140)) {
- lst11_1 = lstItem;
- } else if (lf != null && lf.getValue().equals(141)) {
- lst11_2 = lstItem;
- }
- }
-
- checkLst11_1(lst11_1);
- checkLst11_2(lst11_2);
- }
-
- private void checkLst11_2(final LstItem lst11_2) {
- assertNotNull(lst11_2);
- assertEquals(2, lst11_2.getLfs().size());
- assertEquals(1, lst11_2.getConts().size());
- assertEquals(2, lst11_2.getLsts().size());
-
- assertEquals(lst11_2.getLfs().get("lf112"), new Lf("lf112", "lf112 str2"));
-
- final Cont lst11_2_cont = lst11_2.getConts().get("cont111");
- assertEquals(0, lst11_2_cont.getConts().size());
- assertEquals(1, lst11_2_cont.getLfLsts().size());
- assertEquals(1, lst11_2_cont.getLfs().size());
- assertEquals(1, lst11_2_cont.getLsts().size());
-
- // cont111 check
- assertEquals(new Lf("lf1111", "lf1111 str2"), lst11_2_cont.getLfs().get("lf1111"));
- assertEquals(new LfLst("lflst1111").addLf(new Lf(2049)).addLf(new Lf(1025)).addLf(new Lf(4097)), lst11_2_cont
- .getLfLsts().get("lflst1111"));
-
- assertNotNull(lst11_2_cont.getLsts().get("lst1111"));
- checkLst1111(lst11_2_cont.getLsts().get("lst1111").getLstItems(), new Lf("lf1111A", "lf1111A str21"), new Lf(
- "lf1111B", 5), new Lf("lf1111A", "lf1111A str22"), new Lf("lf1111B", 8));
-
- checkLst11x(lst11_2.getLsts().get("lst111"), new LstItem().addLf(new Lf("lf1111", 55)),
- new LstItem().addLf(new Lf("lf1111", 56)));
- checkLst11x(lst11_2.getLsts().get("lst112"), new LstItem().addLf(new Lf("lf1121", "lf1121 str22")),
- new LstItem().addLf(new Lf("lf1121", "lf1121 str21")));
- }
-
- private void checkLst11_1(final LstItem lst11_1) {
- assertNotNull(lst11_1);
-
- assertEquals(2, lst11_1.getLfs().size());
- assertEquals(1, lst11_1.getConts().size());
- assertEquals(2, lst11_1.getLsts().size());
-
- assertEquals(lst11_1.getLfs().get("lf112"), new Lf("lf112", "lf112 str"));
-
- final Cont lst11_1_cont = lst11_1.getConts().get("cont111");
- assertEquals(0, lst11_1_cont.getConts().size());
- assertEquals(1, lst11_1_cont.getLfLsts().size());
- assertEquals(1, lst11_1_cont.getLfs().size());
- assertEquals(1, lst11_1_cont.getLsts().size());
-
- // cont111 check
- assertEquals(new Lf("lf1111", "lf1111 str"), lst11_1_cont.getLfs().get("lf1111"));
- assertEquals(new LfLst("lflst1111").addLf(new Lf(2048)).addLf(new Lf(1024)).addLf(new Lf(4096)), lst11_1_cont
- .getLfLsts().get("lflst1111"));
-
- assertNotNull(lst11_1_cont.getLsts().get("lst1111"));
- checkLst1111(lst11_1_cont.getLsts().get("lst1111").getLstItems(), new Lf("lf1111A", "lf1111A str11"), new Lf(
- "lf1111B", 4), new Lf("lf1111A", "lf1111A str12"), new Lf("lf1111B", 7));
-
- checkLst11x(lst11_1.getLsts().get("lst111"), new LstItem().addLf(new Lf("lf1111", 65)));
- checkLst11x(lst11_1.getLsts().get("lst112"), new LstItem().addLf(new Lf("lf1121", "lf1121 str11")));
- }
-
- private void checkLst11x(final Lst lst, final LstItem... lstItems) {
- assertNotNull(lst);
-
- final Lst requiredLst = new Lst(lst.getName());
- for (final LstItem lstItem : lstItems) {
- requiredLst.addLstItem(lstItem);
- }
-
- assertEquals(requiredLst, lst);
-
- }
-
- private void checkLst1111(final Set<LstItem> lstItems, final Lf lf11, final Lf lf12, final Lf lf21, final Lf lf22) {
- LstItem lst11_1_cont_lst1111_1 = null;
- LstItem lst11_1_cont_lst1111_2 = null;
- for (final LstItem lstItem : lstItems) {
- if (new LstItem().addLf(lf11).addLf(lf12).equals(lstItem)) {
- lst11_1_cont_lst1111_1 = lstItem;
- } else if (new LstItem().addLf(lf21).addLf(lf22).equals(lstItem)) {
- lst11_1_cont_lst1111_2 = lstItem;
- }
- }
-
- assertNotNull(lst11_1_cont_lst1111_1);
- assertNotNull(lst11_1_cont_lst1111_2);
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
-
-import java.util.List;
-import java.util.Set;
-import org.junit.BeforeClass;
-import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
-import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.model.api.ConstraintDefinition;
-import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
-import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
-import org.opendaylight.yangtools.yang.model.api.SchemaPath;
-import org.opendaylight.yangtools.yang.model.api.Status;
-import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode;
-import org.opendaylight.yangtools.yang.model.api.UsesNode;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class CnSnToJsonIncorrectTopLevelTest extends YangAndXmlAndDataSchemaLoader {
-
- private static final Logger LOG = LoggerFactory.getLogger(CnSnToJsonIncorrectTopLevelTest.class);
-
- @BeforeClass
- public static void initialize() {
- dataLoad("/cnsn-to-json/simple-data-types");
- }
-
- private class IncorrectDataSchema implements DataSchemaNode, DataNodeContainer {
-
- @Override
- public String getDescription() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public SchemaPath getPath() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public QName getQName() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public String getReference() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Status getStatus() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public List<UnknownSchemaNode> getUnknownSchemaNodes() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Set<DataSchemaNode> getChildNodes() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public DataSchemaNode getDataChildByName(final QName arg0) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public DataSchemaNode getDataChildByName(final String arg0) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Set<GroupingDefinition> getGroupings() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Set<TypeDefinition<?>> getTypeDefinitions() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public Set<UsesNode> getUses() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public ConstraintDefinition getConstraints() {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public boolean isAddedByUses() {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean isAugmenting() {
- // TODO Auto-generated method stub
- return false;
- }
-
- @Override
- public boolean isConfiguration() {
- // TODO Auto-generated method stub
- return false;
- }
-
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.sal.restconf.impl.cnsn.to.json.test;
-
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
-import org.junit.BeforeClass;
-import org.opendaylight.controller.sal.restconf.impl.test.YangAndXmlAndDataSchemaLoader;
-
-/**
- *
- * All tests are commented now because leafref isn't supported now
- *
- */
-
-public class CnSnToJsonLeafrefType extends YangAndXmlAndDataSchemaLoader {
-
- @BeforeClass
- public static void initialization() {
- dataLoad("/cnsn-to-json/leafref", 2, "main-module", "cont");
- }
-
- private void validateJson(final String regex, final String value) {
- assertNotNull(value);
- final Pattern ptrn = Pattern.compile(regex, Pattern.DOTALL);
- final Matcher mtch = ptrn.matcher(value);
- assertTrue(mtch.matches());
- }
-
-}
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.opendaylight.yangtools.yang.parser.builder.impl.ContainerSchemaNodeBuilder;
import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public class CnSnToJsonNotExistingLeafTypeTest extends YangAndXmlAndDataSchemaLoader {
- private static final Logger LOG = LoggerFactory.getLogger(CnSnToJsonNotExistingLeafTypeTest.class);
-
@BeforeClass
public static void initialize() {
dataLoad("/cnsn-to-json/simple-data-types");
}
+ @SuppressWarnings("unused")
private DataSchemaNode prepareDataSchemaNode() {
final ContainerSchemaNodeBuilder contBuild = new ContainerSchemaNodeBuilder("module", 1, TestUtils.buildQName("cont",
"simple:uri", "2012-12-17"), SchemaPath.create(true, QName.create("dummy")));
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+
import com.google.common.collect.Iterables;
import com.google.common.util.concurrent.CheckedFuture;
import java.io.FileNotFoundException;
testNodeContainer.withChild(leafKey2.build());
}
- final NormalizedNodeContext testCompositeContext = new NormalizedNodeContext(new InstanceIdentifierContext(
+ final NormalizedNodeContext testCompositeContext = new NormalizedNodeContext(new InstanceIdentifierContext<>(
null, testNodeSchemaNode, null, schemaContextTestModule), testNodeContainer.build());
restconfImpl.updateConfigurationData(toUri(uriKey1, uriKey2), testCompositeContext);
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;
import static org.mockito.Mockito.when;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
SchemaPath type = SchemaPath.create(true, qname);
- YangInstanceIdentifier instanceID = YangInstanceIdentifier.builder().node(qname).toInstance();
+ YangInstanceIdentifier instanceID = YangInstanceIdentifier.builder().node(qname).build();
@Mock
DOMDataReadOnlyTransaction rTransaction;
brokerFacade.readOperationalData(instanceID);
}
- @SuppressWarnings("unchecked")
@Test
public void testInvokeRpc() throws Exception {
final DOMRpcResult expResult = mock(DOMRpcResult.class);
@Ignore
@Test
public void testCommitConfigurationDataPut() {
+ @SuppressWarnings("unchecked")
final CheckedFuture<Void, TransactionCommitFailedException> expFuture = mock(CheckedFuture.class);
when(wTransaction.submit()).thenReturn(expFuture);
@Test
public void testCommitConfigurationDataPost() {
+ @SuppressWarnings("unchecked")
final CheckedFuture<Void, TransactionCommitFailedException> expFuture = mock(CheckedFuture.class);
final NormalizedNode<?, ?> dummyNode2 = createDummyNode("dummy:namespace2", "2014-07-01", "dummy local name2");
@Test
public void testCommitConfigurationDataDelete() {
+ @SuppressWarnings("unchecked")
final CheckedFuture<Void, TransactionCommitFailedException> expFuture = mock(CheckedFuture.class);
when(wTransaction.submit()).thenReturn(expFuture);
- final NormalizedNode<?, ?> dummyNode2 = createDummyNode("dummy:namespace2", "2014-07-01", "dummy local name2");
-
-
final CheckedFuture<Void, TransactionCommitFailedException> actualFuture = brokerFacade
.commitConfigurationDataDelete(instanceID);
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayInputStream;
import java.net.URI;
import java.net.URISyntaxException;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.when;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
contNode.withChild(lfNode);
container.withChild(contNode.build());
- return new NormalizedNodeContext(new InstanceIdentifierContext(null, rpcInputSchemaNode, null, schema), container.build());
+ return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, rpcInputSchemaNode, null, schema), container.build());
}
@Test
final DataContainerNodeAttrBuilder<NodeIdentifier, ContainerNode> containerBuilder =
Builders.containerBuilder(rpcInputSchemaNode);
- final NormalizedNodeContext payload = new NormalizedNodeContext(new InstanceIdentifierContext(null, rpcInputSchemaNode,
+ final NormalizedNodeContext payload = new NormalizedNodeContext(new InstanceIdentifierContext<>(null, rpcInputSchemaNode,
null, schemaContext), containerBuilder.build());
final BrokerFacade brokerFacade = mock(BrokerFacade.class);
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+
import com.google.common.util.concurrent.CheckedFuture;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
return resourceConfig;
}
+ @SuppressWarnings("unchecked")
@Test
public void deleteConfigStatusCodes() throws UnsupportedEncodingException {
final String uri = "/config/test-interface:interfaces";
@BeforeClass
public static void init() throws FileNotFoundException {
- SchemaContext schemaContextTestModule = TestUtils.loadSchemaContext("/common/augment/yang");
+ final SchemaContext schemaContextTestModule = TestUtils.loadSchemaContext("/common/augment/yang");
controllerContext.setSchemas(schemaContextTestModule);
}
@Test
public void augmentedNodesInUri() {
- InstanceIdentifierContext iiWithData = controllerContext.toInstanceIdentifier("main:cont/augment-main-a:cont1");
+ InstanceIdentifierContext<?> iiWithData = controllerContext.toInstanceIdentifier("main:cont/augment-main-a:cont1");
assertEquals("ns:augment:main:a", iiWithData.getSchemaNode().getQName().getNamespace().toString());
iiWithData = controllerContext.toInstanceIdentifier("main:cont/augment-main-b:cont1");
assertEquals("ns:augment:main:b", iiWithData.getSchemaNode().getQName().getNamespace().toString());
try {
controllerContext.toInstanceIdentifier("main:cont/cont1");
fail("Expected exception");
- } catch (RestconfDocumentedException e) {
+ } catch (final RestconfDocumentedException e) {
assertTrue(e.getErrors().get(0).getErrorMessage().contains("is added as augment from more than one module"));
}
}
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+
import com.google.common.base.Optional;
-import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import java.io.FileNotFoundException;
import java.io.UnsupportedEncodingException;
private static RestconfImpl restconfImpl;
private static SchemaContext schemaContextYangsIetf;
private static SchemaContext schemaContextTestModule;
+ @SuppressWarnings("rawtypes")
private static NormalizedNode answerFromGet;
private static SchemaContext schemaContextModules;
/**
* MountPoint test. URI represents mount point.
*/
+ @SuppressWarnings("unchecked")
@Test
public void getDataWithUrlMountPoint() throws UnsupportedEncodingException, URISyntaxException, ParseException {
when(brokerFacade.readConfigurationData(any(DOMMountPoint.class), any(YangInstanceIdentifier.class))).thenReturn(
* Slashes in URI behind mount point. lst1 element with key GigabitEthernet0%2F0%2F0%2F0 (GigabitEthernet0/0/0/0) is
* requested via GET HTTP operation. It is tested whether %2F character is replaced with simple / in
* InstanceIdentifier parameter in method
- * {@link BrokerFacade#readConfigurationDataBehindMountPoint(MountInstance, YangInstanceIdentifier)} which is called in
+ * {@link BrokerFacade#readConfigurationData(DOMMountPoint, YangInstanceIdentifier)} which is called in
* method {@link RestconfImpl#readConfigurationData}
*
* @throws ParseException
}
- private void prepareMockForModulesTest(final ControllerContext mockedControllerContext)
- throws FileNotFoundException {
- final SchemaContext schemaContext = TestUtils.loadSchemaContext("/modules");
- mockedControllerContext.setGlobalSchema(schemaContext);
- // when(mockedControllerContext.getGlobalSchema()).thenReturn(schemaContext);
- }
-
private int get(final String uri, final String mediaType) {
return target(uri).request(mediaType).get().getStatus();
}
type string;
}
*/
+ @SuppressWarnings("rawtypes")
private NormalizedNode prepareCnDataForMountPointTest(final boolean wrapToCont) throws URISyntaxException, ParseException {
final String testModuleDate = "2014-01-09";
final ContainerNode contChild = Builders
}
+ @SuppressWarnings("unchecked")
private void mockReadOperationalDataMethod() {
when(brokerFacade.readOperationalData(any(YangInstanceIdentifier.class))).thenReturn(answerFromGet);
}
+ @SuppressWarnings("unchecked")
private void mockReadConfigurationDataMethod() {
when(brokerFacade.readConfigurationData(any(YangInstanceIdentifier.class))).thenReturn(answerFromGet);
}
+ @SuppressWarnings("rawtypes")
private NormalizedNode prepareCnDataForSlashesBehindMountPointTest() throws ParseException {
return ImmutableMapEntryNodeBuilder
.create()
getDataWithInvalidDepthParameterTest(mockInfo);
}
+ @SuppressWarnings({"rawtypes", "unchecked"})
private void getDataWithInvalidDepthParameterTest(final UriInfo uriInfo) {
try {
final QName qNameDepth1Cont = QName.create("urn:nested:module", "2014-06-3", "depth1-cont");
}
}
+ @SuppressWarnings("unused")
private void verifyXMLResponse(final Response response, final NodeData nodeData) {
final Document doc = response.readEntity(Document.class);
// Document doc = TestUtils.loadDocumentFrom((InputStream) response.getEntity());
}
}
- private NodeData expectContainer(final String name, final NodeData... childData) {
- return new NodeData(name, Lists.newArrayList(childData));
- }
-
- private NodeData expectEmptyContainer(final String name) {
- return new NodeData(name, null);
- }
-
- private NodeData expectLeaf(final String name, final Object value) {
- return new NodeData(name, value);
- }
-
- private QName toNestedQName(final String localName) {
- return QName.create("urn:nested:module", "2014-06-3", localName);
- }
-
- private NodeData toCompositeNodeData(final QName key, final NodeData... childData) {
- return new NodeData(key, Lists.newArrayList(childData));
- }
-
- private NodeData toSimpleNodeData(final QName key, final Object value) {
- return new NodeData(key, value);
- }
-
}
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import static org.opendaylight.controller.sal.restconf.impl.test.RestOperationUtils.XML;
+
import com.google.common.base.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.util.concurrent.CheckedFuture;
restconfImpl.setControllerContext(context);
}
+ @SuppressWarnings("unchecked")
@Test
@Ignore /// xmlData* need netconf-yang
public void postDataViaUrlMountPoint() throws UnsupportedEncodingException {
assertEquals(400, post(uri, MediaType.APPLICATION_JSON, ""));
}
+ @SuppressWarnings("unchecked")
@Test
@Ignore //jenkins has problem with JerseyTest - we expecting problems with singletons ControllerContext as schemaContext holder
public void createConfigurationDataTest() throws UnsupportedEncodingException, ParseException {
.thenReturn(mock(CheckedFuture.class));
final ArgumentCaptor<YangInstanceIdentifier> instanceIdCaptor = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
+ @SuppressWarnings("rawtypes")
final ArgumentCaptor<NormalizedNode> compNodeCaptor = ArgumentCaptor.forClass(NormalizedNode.class);
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+
import com.google.common.base.Optional;
import com.google.common.util.concurrent.CheckedFuture;
import java.io.FileNotFoundException;
@Test
public void putConfigStatusCodesEmptyBody() throws UnsupportedEncodingException {
final String uri = "/config/ietf-interfaces:interfaces/interface/eth0";
+ @SuppressWarnings("unused")
final Response resp = target(uri).request(MediaType.APPLICATION_JSON).put(
Entity.entity("", MediaType.APPLICATION_JSON));
assertEquals(400, put(uri, MediaType.APPLICATION_JSON, ""));
public void testRpcResultCommitedToStatusCodesWithMountPoint() throws UnsupportedEncodingException,
FileNotFoundException, URISyntaxException {
+ @SuppressWarnings("unchecked")
final CheckedFuture<Void, TransactionCommitFailedException> dummyFuture = mock(CheckedFuture.class);
when(
@Test
public void putDataMountPointIntoHighestElement() throws UnsupportedEncodingException, URISyntaxException {
+ @SuppressWarnings("unchecked")
final CheckedFuture<Void, TransactionCommitFailedException> dummyFuture = mock(CheckedFuture.class);
when(
brokerFacade.commitConfigurationDataPut(any(DOMMountPoint.class), any(YangInstanceIdentifier.class),
@BeforeClass
public static void init() throws FileNotFoundException {
- Set<Module> allModules = TestUtils.loadModulesFrom("/full-versions/yangs");
+ final Set<Module> allModules = TestUtils.loadModulesFrom("/full-versions/yangs");
assertNotNull(allModules);
- SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules);
+ final SchemaContext schemaContext = TestUtils.loadSchemaContext(allModules);
controllerContext = spy(ControllerContext.getInstance());
controllerContext.setSchemas(schemaContext);
restconfImpl.setControllerContext(controllerContext);
}
+ @SuppressWarnings("unchecked")
@Test
public void testExample() throws FileNotFoundException, ParseException {
+ @SuppressWarnings("rawtypes")
+ final
NormalizedNode normalizedNodeData = TestUtils.prepareNormalizedNodeWithIetfInterfacesInterfacesData();
- BrokerFacade brokerFacade = mock(BrokerFacade.class);
+ final BrokerFacade brokerFacade = mock(BrokerFacade.class);
when(brokerFacade.readOperationalData(any(YangInstanceIdentifier.class))).thenReturn(normalizedNodeData);
assertEquals(normalizedNodeData,
brokerFacade.readOperationalData(null));
package org.opendaylight.controller.sal.restconf.impl.test;
import static org.junit.Assert.assertNotNull;
-import static org.mockito.Matchers.any;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
+
import com.google.common.base.Preconditions;
-import com.google.common.util.concurrent.CheckedFuture;
import java.io.BufferedReader;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.net.URISyntaxException;
import java.sql.Date;
import java.text.ParseException;
-import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
-import org.opendaylight.controller.sal.restconf.impl.BrokerFacade;
-import org.opendaylight.controller.sal.restconf.impl.ControllerContext;
-import org.opendaylight.controller.sal.restconf.impl.RestconfImpl;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
private static final Logger LOG = LoggerFactory.getLogger(TestUtils.class);
- private final static YangContextParser parser = new YangParserImpl();
+ private final static YangContextParser PARSER = new YangParserImpl();
private static Set<Module> loadModules(final String resourceDirectory) throws FileNotFoundException {
final File testDir = new File(resourceDirectory);
testFiles.add(new File(testDir, fileName));
}
}
- return parser.parseYangModels(testFiles);
+ return PARSER.parseYangModels(testFiles);
}
public static Set<Module> loadModulesFrom(final String yangPath) {
}
public static SchemaContext loadSchemaContext(final Set<Module> modules) {
- return parser.resolveSchemaContext(modules);
+ return PARSER.resolveSchemaContext(modules);
}
public static SchemaContext loadSchemaContext(final String resourceDirectory) throws FileNotFoundException {
- return parser.resolveSchemaContext(loadModulesFrom(resourceDirectory));
+ return PARSER.resolveSchemaContext(loadModulesFrom(resourceDirectory));
}
public static Module findModule(final Set<Module> modules, final String moduleName) {
return buildQName(name, "", null);
}
- private static void prepareMocksForRestconf(final Set<Module> modules, final RestconfImpl restconf) {
- final ControllerContext controllerContext = ControllerContext.getInstance();
- final BrokerFacade mockedBrokerFacade = mock(BrokerFacade.class);
-
- controllerContext.setSchemas(TestUtils.loadSchemaContext(modules));
-
- when(mockedBrokerFacade.commitConfigurationDataPut(any(YangInstanceIdentifier.class), any(NormalizedNode.class)))
- .thenReturn(mock(CheckedFuture.class));
-
- restconf.setControllerContext(controllerContext);
- restconf.setBroker(mockedBrokerFacade);
- }
-
public static String loadTextFile(final String filePath) throws IOException {
final FileReader fileReader = new FileReader(filePath);
final BufferedReader bufReader = new BufferedReader(fileReader);
public static YangInstanceIdentifier.NodeIdentifierWithPredicates getNodeIdentifierPredicate(final String localName,
final String namespace, final String revision, final String... keysAndValues) throws ParseException {
- final java.util.Date date = new SimpleDateFormat("yyyy-MM-dd").parse(revision);
if (keysAndValues.length % 2 != 0) {
new IllegalArgumentException("number of keys argument have to be divisible by 2 (map)");
}
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil.getRevisionFormat;
+
import java.io.FileNotFoundException;
import java.text.ParseException;
import java.util.Date;
+ scopeValue);
final UriInfo mockedUriInfo = mock(UriInfo.class);
+ @SuppressWarnings("unchecked")
final MultivaluedMap<String, String> mockedMultivaluedMap = mock(MultivaluedMap.class);
when(mockedMultivaluedMap.getFirst(eq("datastore"))).thenReturn(datastoreValue);
when(mockedMultivaluedMap.getFirst(eq("scope"))).thenReturn(scopeValue);
.withValue(scope)).build();
container.withChild(scopeNode);
- return new NormalizedNodeContext(new InstanceIdentifierContext(null, rpcInputSchemaNode, null, schema), container.build());
+ return new NormalizedNodeContext(new InstanceIdentifierContext<>(null, rpcInputSchemaNode, null, schema), container.build());
}
}
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 com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
@Test
public void testToInstanceIdentifierList() throws FileNotFoundException {
- InstanceIdentifierContext instanceIdentifier = controllerContext
+ InstanceIdentifierContext<?> instanceIdentifier = controllerContext
.toInstanceIdentifier("simple-nodes:userWithoutClass/foo");
assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "userWithoutClass");
@Test
public void testToInstanceIdentifierContainer() throws FileNotFoundException {
- final InstanceIdentifierContext instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:users");
+ final InstanceIdentifierContext<?> instanceIdentifier = controllerContext.toInstanceIdentifier("simple-nodes:users");
assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "users");
assertTrue(instanceIdentifier.getSchemaNode() instanceof ContainerSchemaNode);
assertEquals(2, ((ContainerSchemaNode) instanceIdentifier.getSchemaNode()).getChildNodes().size());
@Test
@Ignore //jenkins has problem with JerseyTest - we expecting problems with singletons ControllerContext as schemaContext holder
public void testToInstanceIdentifierChoice() throws FileNotFoundException {
- final InstanceIdentifierContext instanceIdentifier = controllerContext
+ final InstanceIdentifierContext<?> instanceIdentifier = controllerContext
.toInstanceIdentifier("simple-nodes:food/nonalcoholic");
assertEquals(instanceIdentifier.getSchemaNode().getQName().getLocalName(), "nonalcoholic");
}
@Test
public void testMountPointWithExternModul() throws FileNotFoundException {
initMountService(true);
- final InstanceIdentifierContext instanceIdentifier = controllerContext
+ final InstanceIdentifierContext<?> instanceIdentifier = controllerContext
.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/test-interface2:class/student/name");
assertEquals(
"[(urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)class, (urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)student, (urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)student[{(urn:ietf:params:xml:ns:yang:test-interface2?revision=2014-08-01)name=name}]]",
@Test
public void testMountPointWithoutExternModul() throws FileNotFoundException {
initMountService(true);
- final InstanceIdentifierContext instanceIdentifier = controllerContext
+ final InstanceIdentifierContext<?> instanceIdentifier = controllerContext
.toInstanceIdentifier("simple-nodes:users/yang-ext:mount/");
assertTrue(Iterables.isEmpty(instanceIdentifier.getInstanceIdentifier().getPathArguments()));
}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.sal.restconf.impl.test.structures;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-import org.junit.Test;
-
-public class CompareLf {
-
- @Test
- public void test() {
- Lf lf1 = new Lf("name", "value");
- Lf lf2 = new Lf("name", "value");
- Lf lf3 = new Lf("name1", "value");
- Lf lf4 = new Lf("name", "value1");
-
- assertTrue(lf1.equals(lf2));
- assertFalse(lf1.equals(lf3));
- assertFalse(lf1.equals(lf4));
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.sal.restconf.impl.test.structures;
-
-public class Cont extends LstItem {
- String name = null;
-
- public Cont(String name) {
- super();
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!this.getClass().equals(obj.getClass())) {
- return false;
- }
- if (!super.equals(obj)) {
- return false;
- }
- Cont cont = (Cont) obj;
- if (this.name == null) {
- if (cont.name != null) {
- return false;
- }
- } else if (!this.name.equals(cont.name)) {
- return false;
- }
- return true;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + ((this.name == null) ? 0 : this.name.hashCode());
- return result;
- }
-
- @Override
- public String toString() {
- return name;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.sal.restconf.impl.test.structures;
-
-public class Lf extends YangElement {
- private Object value;
- private int numOfEqualItems = 0;
-
- public Lf(String name, Object value) {
- super(name);
- this.value = value;
- }
-
- public Lf(Object value) {
- super("");
- this.value = value;
- }
-
- public Object getValue() {
- return value;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!this.getClass().equals(obj.getClass())) {
- return false;
- }
- if (!super.equals(obj)) {
- return false;
- }
- Lf lf = (Lf) obj;
- if (this.value == null) {
- if (lf.value != null) {
- return false;
- }
- } else if (!this.value.equals(lf.value)) {
- return false;
- }
- if (this.numOfEqualItems != lf.numOfEqualItems) {
- return false;
- }
- return true;
- }
-
- public void incNumOfEqualItems() {
- this.numOfEqualItems++;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + ((value == null) ? 0 : value.hashCode());
- result = prime * result + numOfEqualItems;
- return result;
- }
-
- @Override
- public String toString() {
- return super.toString() + ":" + value;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.sal.restconf.impl.test.structures;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class LfLst extends YangElement {
- Set<Lf> lfs;
-
- public LfLst(String name) {
- super(name);
- lfs = new HashSet<>();
- }
-
- public LfLst addLf(Object value) {
- return addLf(new Lf(value));
- }
-
- public LfLst addLf(Lf lf) {
- while (this.lfs.contains(lf)) {
- lf.incNumOfEqualItems();
- }
- this.lfs.add(lf);
- return this;
- }
-
- public Set<Lf> getLfs() {
- return lfs;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!this.getClass().equals(obj.getClass())) {
- return false;
- }
- if (!super.equals(obj)) {
- return false;
- }
- LfLst lfLst = (LfLst) obj;
- if (this.lfs == null) {
- if (lfLst.lfs != null) {
- return false;
- }
- } else if (!this.lfs.equals(lfLst.lfs)) {
- return false;
- }
- return true;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + ((lfs == null) ? 0 : lfs.hashCode());
- return result;
- }
-
- @Override
- public String toString() {
-
- return super.toString();
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.sal.restconf.impl.test.structures;
-
-import java.util.HashSet;
-import java.util.Set;
-
-public class Lst extends YangElement {
- private final Set<LstItem> lstItems;
-
- public Lst(final String name) {
- super(name);
- lstItems = new HashSet<>();
- }
-
- public Lst addLstItem(final LstItem lstItem) {
- lstItem.setLstName(name);
- while (this.lstItems.contains(lstItem)) {
- lstItem.incNumOfEqualItems();
- }
- this.lstItems.add(lstItem);
- return this;
- }
-
- public Set<LstItem> getLstItems() {
- return lstItems;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (this == obj) {
- return true;
- }
- if (!this.getClass().equals(obj.getClass())) {
- return false;
- }
- if (!super.equals(obj)) {
- return false;
- }
- Lst lst = (Lst) obj;
- if (this.lstItems == null) {
- if (lst.lstItems != null) {
- return false;
- }
- } else if (!this.lstItems.equals(lst.lstItems)) {
- return false;
- }
- return true;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = super.hashCode();
- result = prime * result + ((lstItems == null) ? 0 : lstItems.hashCode());
- return result;
- }
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.sal.restconf.impl.test.structures;
-
-import static org.junit.Assert.assertFalse;
-
-import java.util.HashMap;
-import java.util.Map;
-
-public class LstItem {
- String lstName;
- Map<String, Lf> lfs;
- Map<String, LfLst> lfLsts;
- Map<String, Lst> lsts;
- Map<String, Cont> conts;
- private int numOfEqualItems = 0;
-
- public LstItem() {
- lfs = new HashMap<>();
- conts = new HashMap<>();
- lfLsts = new HashMap<>();
- lsts = new HashMap<>();
- }
-
- public Map<String, Lst> getLsts() {
- return lsts;
- }
-
- public Map<String, Cont> getConts() {
- return conts;
- }
-
- public Map<String, LfLst> getLfLsts() {
- return lfLsts;
- }
-
- public Map<String, Lf> getLfs() {
- return lfs;
- }
-
- public String getLstName() {
- return lstName;
- }
-
- public LstItem addLf(Lf lf) {
- lfs.put(lf.getName(), lf);
- return this;
- }
-
- public LstItem addLf(String name, Object value) {
- lfs.put(name, new Lf(name, value));
- return this;
- }
-
- public void addLfLst(LfLst lfLst) {
- assertFalse("Found multiple leaf list elements for " + lfLst.getName(), lfLsts.containsKey(lfLst.getName()));
- lfLsts.put(lfLst.getName(), lfLst);
- }
-
- public void addLst(Lst lst) {
- assertFalse("Found multiple list elements for " + lst.getName(), lsts.containsKey(lst.getName()));
- lsts.put(lst.getName(), lst);
- }
-
- public void addCont(Cont cont) {
- conts.put(cont.getName(), cont);
- }
-
- public void incNumOfEqualItems() {
- this.numOfEqualItems++;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!this.getClass().equals(obj.getClass())) {
- return false;
- }
- LstItem lstItem = (LstItem) obj;
- if (this.conts == null) {
- if (lstItem.conts != null) {
- return false;
- }
- } else if (!this.conts.equals(lstItem.conts)) {
- return false;
- }
- if (this.lfs == null) {
- if (lstItem.lfs != null) {
- return false;
- }
- } else if (!this.lfs.equals(lstItem.lfs)) {
- return false;
- }
- if (this.lfLsts == null) {
- if (lstItem.lfLsts != null) {
- return false;
- }
- } else if (!this.lfLsts.equals(lstItem.lfLsts)) {
- return false;
- }
- if (this.lsts == null) {
- if (lstItem.lsts != null) {
- return false;
- }
- } else if (!this.lsts.equals(lstItem.lsts)) {
- return false;
- }
- if (this.numOfEqualItems != lstItem.numOfEqualItems) {
- return false;
- }
- return true;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((lfs == null) ? 0 : lfs.hashCode());
- result = prime * result + ((lfLsts == null) ? 0 : lfLsts.hashCode());
- result = prime * result + ((lsts == null) ? 0 : lsts.hashCode());
- result = prime * result + ((conts == null) ? 0 : conts.hashCode());
- result = prime * result + numOfEqualItems;
- return result;
- }
-
- @Override
- public String toString() {
- return "lst item of " + lstName;
- }
-
- public void setLstName(String name) {
- this.lstName = name;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.sal.restconf.impl.test.structures;
-
-public class YangElement {
- protected String name;
-
- protected YangElement(String name) {
- this.name = name;
- }
-
- public String getName() {
- return name;
- }
-
- @Override
- public boolean equals(Object obj) {
- if (this == obj) {
- return true;
- }
- if (!this.getClass().equals(obj.getClass())) {
- return false;
- }
- YangElement yangElement = (YangElement) obj;
- if (this.name == null) {
- if (yangElement.name != null) {
- return false;
- }
- } else if (!this.name.equals(yangElement.name)) {
- return false;
- }
- return true;
- }
-
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((name == null) ? 0 : name.hashCode());
- return result;
- }
-
- @Override
- public String toString() {
- return name;
- }
-
-}
+++ /dev/null
-/*
- * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,
- * and is available at http://www.eclipse.org/legal/epl-v10.html
- */
-package org.opendaylight.controller.sal.restconf.impl.xml.to.cnsn.test;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public class XmlLeafrefToCnSnTest {
- private static final Logger LOG = LoggerFactory.getLogger(XmlLeafrefToCnSnTest.class);
-
-}