import org.opendaylight.restconf.restful.services.api.RestconfInvokeOperationsService;
/**
- * The URI hierarchy for the RESTCONF resources consists of an entry point container, 4 top-level resources, and 1
- * field.
+ * The URI hierarchy for the RESTCONF resources consists of an entry point
+ * container, 4 top-level resources, and 1 field.
* <ul>
* <li><b>/restconf</b> - {@link #getRoot()}
* <ul>
- * <li><b>/config</b> - {@link #readConfigurationData(String, UriInfo)}
- * {@link #updateConfigurationData(String, NormalizedNodeContext)}
- * {@link #createConfigurationData(NormalizedNodeContext, UriInfo)}
- * {@link #createConfigurationData(String, NormalizedNodeContext, UriInfo)}
+ * <li><b>/config</b> - {@link #readConfigurationData(String, UriInfo)}
+ * {@link #updateConfigurationData(String, NormalizedNodeContext, UriInfo)}
+ * {@link #createConfigurationData(NormalizedNodeContext, UriInfo)}
+ * {@link #createConfigurationData(String, NormalizedNodeContext, UriInfo)}
* {@link #deleteConfigurationData(String)}
* <li><b>/operational</b> - {@link #readOperationalData(String, UriInfo)}
* <li>/modules - {@link #getModules(UriInfo)}
* <ul>
* <li>/module
* </ul>
- * <li><b>/operations</b> - {@link #invokeRpc(String, NormalizedNodeContext, UriInfo)}
- * {@link #invokeRpc(String, NormalizedNodeContext, UriInfo)}
+ * <li><b>/operations</b> -
+ * {@link #invokeRpc(String, NormalizedNodeContext, UriInfo)}
+ * {@link #invokeRpc(String, NormalizedNodeContext, UriInfo)}
* <li>/version (field)
* </ul>
* </ul>
/**
* @deprecated do not use this method. It will be replaced by
- * {@link RestconfDataService#putData(String, NormalizedNodeContext)}
+ * {@link RestconfDataService#putData(String, NormalizedNodeContext, UriInfo)}
*/
@Deprecated
@PUT
@Path("/config/{identifier:.+}")
@Consumes({ Draft02.MediaTypes.DATA + JSON, Draft02.MediaTypes.DATA + XML, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_XML, MediaType.TEXT_XML })
- public Response updateConfigurationData(@Encoded @PathParam("identifier") String identifier, NormalizedNodeContext payload);
+ public Response updateConfigurationData(@Encoded @PathParam("identifier") String identifier,
+ NormalizedNodeContext payload, @Context UriInfo uriInfo);
/**
* @deprecated do not use this method. It will be replaced by
}
@Override
- public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload) {
- return this.restconf.updateConfigurationData(identifier, payload);
+ public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload,
+ final UriInfo uriInfo) {
+ return this.restconf.updateConfigurationData(identifier, payload, uriInfo);
}
@Override
import com.google.common.base.Optional;
import javax.annotation.Nonnull;
+import javax.ws.rs.core.UriInfo;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.yangtools.yang.common.OperationFailedException;
/**
* @author Thomas Pantelis
*/
+@Deprecated
public interface JSONRestconfService {
/**
* The data tree root path.
* @param payload the payload data in JSON format.
* @throws OperationFailedException if the request fails.
*/
- void put(String uriPath, @Nonnull String payload) throws OperationFailedException;
+ void put(String uriPath, @Nonnull String payload, UriInfo uriInfo) throws OperationFailedException;
/**
* Issues a restconf POST request to the configuration data store.
* @param payload the payload data in JSON format.
* @throws OperationFailedException if the request fails.
*/
- void post(String uriPath, @Nonnull String payload) throws OperationFailedException;
+ void post(String uriPath, @Nonnull String payload, UriInfo uriInfo) throws OperationFailedException;
/**
* Issues a restconf DELETE request to the configuration data store.
import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.CONFIGURATION;
import static org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType.OPERATIONAL;
-
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import org.opendaylight.yangtools.concepts.ListenerRegistration;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
+import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaPath;
import org.slf4j.Logger;
* - path of node
* @param payload
* - input data
+ * @param point
+ * @param insert
* @return wrapper of status and future of PUT
*/
public PutResult commitConfigurationDataPut(
- final SchemaContext globalSchema, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload) {
+ final SchemaContext globalSchema, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
+ final String insert, final String point) {
Preconditions.checkNotNull(globalSchema);
Preconditions.checkNotNull(path);
Preconditions.checkNotNull(payload);
final Status status = readDataViaTransaction(newReadWriteTransaction, CONFIGURATION, path) != null ? Status.OK
: Status.CREATED;
final CheckedFuture<Void, TransactionCommitFailedException> future = putDataViaTransaction(
- newReadWriteTransaction, CONFIGURATION, path, payload, globalSchema);
+ newReadWriteTransaction, CONFIGURATION, path, payload, globalSchema, insert, point);
return new PutResult(status, future);
}
* - path of node
* @param payload
* - input data
+ * @param point
+ * @param insert
* @return wrapper of status and future of PUT
*/
public PutResult commitMountPointDataPut(
- final DOMMountPoint mountPoint, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload) {
+ final DOMMountPoint mountPoint, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
+ final String insert, final String point) {
Preconditions.checkNotNull(mountPoint);
Preconditions.checkNotNull(path);
Preconditions.checkNotNull(payload);
final Status status = readDataViaTransaction(newReadWriteTransaction, CONFIGURATION, path) != null
? Status.OK : Status.CREATED;
final CheckedFuture<Void, TransactionCommitFailedException> future = putDataViaTransaction(
- newReadWriteTransaction, CONFIGURATION, path,
- payload, mountPoint.getSchemaContext());
+ newReadWriteTransaction, CONFIGURATION, path, payload, mountPoint.getSchemaContext(), insert,
+ point);
return new PutResult(status, future);
}
final String errMsg = "DOM data broker service isn't available for mount point " + path;
// POST configuration
public CheckedFuture<Void, TransactionCommitFailedException> commitConfigurationDataPost(
- final SchemaContext globalSchema, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload) {
+ final SchemaContext globalSchema, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
+ final String insert, final String point) {
checkPreconditions();
- return postDataViaTransaction(this.domDataBroker.newReadWriteTransaction(), CONFIGURATION, path, payload, globalSchema);
+ return postDataViaTransaction(this.domDataBroker.newReadWriteTransaction(), CONFIGURATION, path, payload,
+ globalSchema, insert, point);
}
public CheckedFuture<Void, TransactionCommitFailedException> commitConfigurationDataPost(
- final DOMMountPoint mountPoint, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload) {
+ final DOMMountPoint mountPoint, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
+ final String insert, final String point) {
final Optional<DOMDataBroker> domDataBrokerService = mountPoint.getService(DOMDataBroker.class);
if (domDataBrokerService.isPresent()) {
return postDataViaTransaction(domDataBrokerService.get().newReadWriteTransaction(), CONFIGURATION, path,
- payload, mountPoint.getSchemaContext());
+ payload, mountPoint.getSchemaContext(), insert, point);
}
final String errMsg = "DOM data broker service isn't available for mount point " + path;
LOG.warn(errMsg);
/**
* POST data and submit transaction {@link DOMDataReadWriteTransaction}
- * @return
*/
private CheckedFuture<Void, TransactionCommitFailedException> postDataViaTransaction(
final DOMDataReadWriteTransaction rWTransaction, final LogicalDatastoreType datastore,
- final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext) {
+ final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext,
+ final String insert, final String point) {
LOG.trace("POST {} via Restconf: {} with payload {}", datastore.name(), path, payload);
- postData(rWTransaction, datastore, path, payload, schemaContext);
+ postData(rWTransaction, datastore, path, payload, schemaContext, insert, point);
return rWTransaction.submit();
}
final DOMDataReadWriteTransaction rWTransaction, final LogicalDatastoreType datastore,
final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext) {
LOG.trace("POST {} within Restconf PATCH: {} with payload {}", datastore.name(), path, payload);
- postData(rWTransaction, datastore, path, payload, schemaContext);
+ postData(rWTransaction, datastore, path, payload, schemaContext, null, null);
}
- // FIXME: This is doing correct post for container and list children, not sure if this will work for choice case
private void postData(final DOMDataReadWriteTransaction rWTransaction, final LogicalDatastoreType datastore,
final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
- final SchemaContext schemaContext) {
+ final SchemaContext schemaContext, final String insert, final String point) {
+ if (insert == null) {
+ makeNormalPost(rWTransaction, datastore, path, payload, schemaContext);
+ } else {
+ final DataSchemaNode schemaNode = checkListAndOrderedType(schemaContext, path);
+ checkItemDoesNotExists(rWTransaction, datastore, path);
+ switch (insert) {
+ case "first":
+ if(schemaNode instanceof ListSchemaNode){
+ final OrderedMapNode readList =
+ (OrderedMapNode) this.readConfigurationData(path.getParent().getParent());
+ if ((readList == null) || readList.getValue().isEmpty()) {
+ simplePostPut(rWTransaction, datastore, path, payload, schemaContext);
+ } else {
+ rWTransaction.delete(datastore, path.getParent().getParent());
+ simplePostPut(rWTransaction, datastore, path, payload, schemaContext);
+ makeNormalPost(rWTransaction, datastore, path.getParent().getParent(), readList,
+ schemaContext);
+ }
+ } else {
+ final OrderedLeafSetNode readLeafList =
+ (OrderedLeafSetNode) readConfigurationData(path.getParent());
+ if ((readLeafList == null) || readLeafList.getValue().isEmpty()) {
+ simplePostPut(rWTransaction, datastore, path, payload, schemaContext);
+ } else {
+ rWTransaction.delete(datastore, path.getParent());
+ simplePostPut(rWTransaction, datastore, path, payload, schemaContext);
+ makeNormalPost(rWTransaction, datastore, path.getParent().getParent(), readLeafList,
+ schemaContext);
+ }
+ }
+ break;
+ case "last":
+ simplePostPut(rWTransaction, datastore, path, payload, schemaContext);
+ break;
+ case "before":
+ if(schemaNode instanceof ListSchemaNode){
+ final OrderedMapNode readList =
+ (OrderedMapNode) this.readConfigurationData(path.getParent().getParent());
+ if ((readList == null) || readList.getValue().isEmpty()) {
+ simplePostPut(rWTransaction, datastore, path, payload, schemaContext);
+ } else {
+ insertWithPointListPost(rWTransaction, datastore, path, payload, schemaContext, point,
+ readList,
+ true);
+ }
+ } else {
+ final OrderedLeafSetNode<?> readLeafList =
+ (OrderedLeafSetNode<?>) readConfigurationData(path.getParent());
+ if ((readLeafList == null) || readLeafList.getValue().isEmpty()) {
+ simplePostPut(rWTransaction, datastore, path, payload, schemaContext);
+ } else {
+ insertWithPointLeafListPost(rWTransaction, datastore, path, payload, schemaContext, point,
+ readLeafList, true);
+ }
+ }
+ break;
+ case "after":
+ if (schemaNode instanceof ListSchemaNode) {
+ final OrderedMapNode readList =
+ (OrderedMapNode) this.readConfigurationData(path.getParent().getParent());
+ if ((readList == null) || readList.getValue().isEmpty()) {
+ simplePostPut(rWTransaction, datastore, path, payload, schemaContext);
+ } else {
+ insertWithPointListPost(rWTransaction, datastore, path, payload, schemaContext, point,
+ readList,
+ false);
+ }
+ } else {
+ final OrderedLeafSetNode<?> readLeafList =
+ (OrderedLeafSetNode<?>) readConfigurationData(path.getParent());
+ if ((readLeafList == null) || readLeafList.getValue().isEmpty()) {
+ simplePostPut(rWTransaction, datastore, path, payload, schemaContext);
+ } else {
+ insertWithPointLeafListPost(rWTransaction, datastore, path, payload, schemaContext, point,
+ readLeafList, false);
+ }
+ }
+ break;
+ default:
+ throw new RestconfDocumentedException(
+ "Used bad value of insert parameter. Possible values are first, last, before or after, "
+ + "but was: " + insert);
+ }
+ }
+ }
+
+ private void insertWithPointLeafListPost(final DOMDataReadWriteTransaction rWTransaction,
+ final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
+ final SchemaContext schemaContext, final String point, final OrderedLeafSetNode<?> readLeafList,
+ final boolean before) {
+ rWTransaction.delete(datastore, path.getParent().getParent());
+ final InstanceIdentifierContext<?> instanceIdentifier =
+ ControllerContext.getInstance().toInstanceIdentifier(point);
+ int p = 0;
+ for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
+ if (nodeChild.getIdentifier().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
+ break;
+ }
+ p++;
+ }
+ if (!before) {
+ p++;
+ }
+ int h = 0;
+ final NormalizedNode<?, ?> emptySubtree =
+ ImmutableNodes.fromInstanceId(schemaContext, path.getParent().getParent());
+ rWTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
+ for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
+ if (h == p) {
+ checkItemDoesNotExists(rWTransaction, datastore, path);
+ simplePostPut(rWTransaction, datastore, path, payload, schemaContext);
+ }
+ final YangInstanceIdentifier childPath = path.getParent().getParent().node(nodeChild.getIdentifier());
+ checkItemDoesNotExists(rWTransaction, datastore, childPath);
+ rWTransaction.put(datastore, childPath, nodeChild);
+ h++;
+ }
+ }
+
+ private void insertWithPointListPost(final DOMDataReadWriteTransaction rWTransaction,
+ final LogicalDatastoreType datastore,
+ final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext,
+ final String point, final MapNode readList, final boolean before) {
+ rWTransaction.delete(datastore, path.getParent().getParent());
+ final InstanceIdentifierContext<?> instanceIdentifier =
+ ControllerContext.getInstance().toInstanceIdentifier(point);
+ int p = 0;
+ for (final MapEntryNode mapEntryNode : readList.getValue()) {
+ if (mapEntryNode.getIdentifier()
+ .equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
+ break;
+ }
+ p++;
+ }
+ if (!before) {
+ p++;
+ }
+ int h = 0;
+ final NormalizedNode<?, ?> emptySubtree =
+ ImmutableNodes.fromInstanceId(schemaContext, path.getParent().getParent());
+ rWTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
+ for (final MapEntryNode mapEntryNode : readList.getValue()) {
+ if (h == p) {
+ checkItemDoesNotExists(rWTransaction, datastore, path);
+ simplePostPut(rWTransaction, datastore, path, payload, schemaContext);
+ }
+ final YangInstanceIdentifier childPath = path.getParent().getParent().node(mapEntryNode.getIdentifier());
+ checkItemDoesNotExists(rWTransaction, datastore, childPath);
+ rWTransaction.put(datastore, childPath, mapEntryNode);
+ h++;
+ }
+ }
+
+ private DataSchemaNode checkListAndOrderedType(final SchemaContext ctx,
+ final YangInstanceIdentifier path) {
+ final YangInstanceIdentifier parent = path.getParent();
+ final DataSchemaContextNode<?> node = DataSchemaContextTree.from(ctx).getChild(parent);
+ final DataSchemaNode dataSchemaNode = node.getDataSchemaNode();
+
+ if (dataSchemaNode instanceof ListSchemaNode) {
+ if(!((ListSchemaNode) dataSchemaNode).isUserOrdered()) {
+ throw new RestconfDocumentedException("Insert parameter can be used only with ordered-by user list.");
+ }
+ return dataSchemaNode;
+ }
+ if (dataSchemaNode instanceof LeafListSchemaNode) {
+ if(!((LeafListSchemaNode) dataSchemaNode).isUserOrdered()) {
+ throw new RestconfDocumentedException("Insert parameter can be used only with ordered-by user leaf-list.");
+ }
+ return dataSchemaNode;
+ }
+ throw new RestconfDocumentedException("Insert parameter can be used only with list or leaf-list");
+ }
+
+ private void makeNormalPost(final DOMDataReadWriteTransaction rWTransaction, final LogicalDatastoreType datastore,
+ final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext) {
if (payload instanceof MapNode) {
final NormalizedNode<?, ?> emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path);
rWTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
checkItemDoesNotExists(rWTransaction, datastore, childPath);
rWTransaction.put(datastore, childPath, child);
}
- } else {
- checkItemDoesNotExists(rWTransaction, datastore, path);
+ } else if (payload instanceof LeafSetNode) {
+ final NormalizedNode<?, ?> emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path);
+ rWTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
ensureParentsByMerge(datastore, path, rWTransaction, schemaContext);
- rWTransaction.put(datastore, path, payload);
+ for (final LeafSetEntryNode<?> child : ((LeafSetNode<?>) payload).getValue()) {
+ final YangInstanceIdentifier childPath = path.node(child.getIdentifier());
+ checkItemDoesNotExists(rWTransaction, datastore, childPath);
+ rWTransaction.put(datastore, childPath, child);
+ }
+ } else {
+ simplePostPut(rWTransaction, datastore, path, payload, schemaContext);
}
}
+ private void simplePostPut(final DOMDataReadWriteTransaction rWTransaction, final LogicalDatastoreType datastore,
+ final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext) {
+ checkItemDoesNotExists(rWTransaction, datastore, path);
+ ensureParentsByMerge(datastore, path, rWTransaction, schemaContext);
+ rWTransaction.put(datastore, path, payload);
+ }
+
/**
* Check if item already exists. Throws error if it does NOT already exist.
* @param rWTransaction Current transaction
/**
* PUT data and submit {@link DOMDataReadWriteTransaction}
+ *
+ * @param point
+ * @param insert
*/
private CheckedFuture<Void, TransactionCommitFailedException> putDataViaTransaction(
final DOMDataReadWriteTransaction readWriteTransaction, final LogicalDatastoreType datastore,
- final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext) {
+ final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext,
+ final String insert, final String point) {
LOG.trace("Put {} via Restconf: {} with payload {}", datastore.name(), path, payload);
- putData(readWriteTransaction, datastore, path, payload, schemaContext);
+ putData(readWriteTransaction, datastore, path, payload, schemaContext, insert, point);
return readWriteTransaction.submit();
}
/**
* PUT data and do NOT submit {@link DOMDataReadWriteTransaction}
+ *
+ * @param insert
+ * @param point
*/
private void putDataWithinTransaction(
final DOMDataReadWriteTransaction writeTransaction, final LogicalDatastoreType datastore,
final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext) {
LOG.trace("Put {} within Restconf PATCH: {} with payload {}", datastore.name(), path, payload);
- putData(writeTransaction, datastore, path, payload, schemaContext);
+ putData(writeTransaction, datastore, path, payload, schemaContext, null, null);
}
// FIXME: This is doing correct put for container and list children, not sure if this will work for choice case
- private void putData(final DOMDataReadWriteTransaction writeTransaction, final LogicalDatastoreType datastore,
+ private void putData(final DOMDataReadWriteTransaction rWTransaction, final LogicalDatastoreType datastore,
+ final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext,
+ final String insert, final String point) {
+ if (insert == null) {
+ makePut(rWTransaction, datastore, path, payload, schemaContext);
+ } else {
+ final DataSchemaNode schemaNode = checkListAndOrderedType(schemaContext, path);
+ checkItemDoesNotExists(rWTransaction, datastore, path);
+ switch (insert) {
+ case "first":
+ if (schemaNode instanceof ListSchemaNode) {
+ final OrderedMapNode readList =
+ (OrderedMapNode) this.readConfigurationData(path.getParent());
+ if ((readList == null) || readList.getValue().isEmpty()) {
+ simplePut(datastore, path, rWTransaction, schemaContext, payload);
+ } else {
+ rWTransaction.delete(datastore, path.getParent());
+ simplePut(datastore, path, rWTransaction, schemaContext, payload);
+ makePut(rWTransaction, datastore, path.getParent(), readList, schemaContext);
+ }
+ } else {
+ final OrderedLeafSetNode<?> readLeafList =
+ (OrderedLeafSetNode<?>) readConfigurationData(path.getParent());
+ if ((readLeafList == null) || readLeafList.getValue().isEmpty()) {
+ simplePut(datastore, path, rWTransaction, schemaContext, payload);
+ } else {
+ rWTransaction.delete(datastore, path.getParent());
+ simplePut(datastore, path, rWTransaction, schemaContext, payload);
+ makePut(rWTransaction, datastore, path.getParent(), readLeafList,
+ schemaContext);
+ }
+ }
+ break;
+ case "last":
+ simplePut(datastore, path, rWTransaction, schemaContext, payload);
+ break;
+ case "before":
+ if (schemaNode instanceof ListSchemaNode) {
+ final OrderedMapNode readList =
+ (OrderedMapNode) this.readConfigurationData(path.getParent());
+ if ((readList == null) || readList.getValue().isEmpty()) {
+ simplePut(datastore, path, rWTransaction, schemaContext, payload);
+ } else {
+ insertWithPointListPut(rWTransaction, datastore, path, payload, schemaContext, point,
+ readList, true);
+ }
+ } else {
+ final OrderedLeafSetNode<?> readLeafList =
+ (OrderedLeafSetNode<?>) readConfigurationData(path.getParent());
+ if ((readLeafList == null) || readLeafList.getValue().isEmpty()) {
+ simplePut(datastore, path, rWTransaction, schemaContext, payload);
+ } else {
+ insertWithPointLeafListPut(rWTransaction, datastore, path, payload, schemaContext, point,
+ readLeafList, true);
+ }
+ }
+ break;
+ case "after":
+ if (schemaNode instanceof ListSchemaNode) {
+ final OrderedMapNode readList =
+ (OrderedMapNode) this.readConfigurationData(path.getParent());
+ if ((readList == null) || readList.getValue().isEmpty()) {
+ simplePut(datastore, path, rWTransaction, schemaContext, payload);
+ } else {
+ insertWithPointListPut(rWTransaction, datastore, path, payload, schemaContext, point,
+ readList, false);
+ }
+ } else {
+ final OrderedLeafSetNode<?> readLeafList =
+ (OrderedLeafSetNode<?>) readConfigurationData(path.getParent());
+ if ((readLeafList == null) || readLeafList.getValue().isEmpty()) {
+ simplePut(datastore, path, rWTransaction, schemaContext, payload);
+ } else {
+ insertWithPointLeafListPut(rWTransaction, datastore, path, payload, schemaContext, point,
+ readLeafList, false);
+ }
+ }
+ break;
+ default:
+ throw new RestconfDocumentedException(
+ "Used bad value of insert parameter. Possible values are first, last, before or after, "
+ + "but was: " + insert);
+ }
+ }
+ }
+
+ private void insertWithPointLeafListPut(final DOMDataReadWriteTransaction rWTransaction,
+ final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
+ final SchemaContext schemaContext, final String point, final OrderedLeafSetNode<?> readLeafList,
+ final boolean before) {
+ rWTransaction.delete(datastore, path.getParent());
+ final InstanceIdentifierContext<?> instanceIdentifier =
+ ControllerContext.getInstance().toInstanceIdentifier(point);
+ int p = 0;
+ for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
+ if (nodeChild.getIdentifier().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
+ break;
+ }
+ p++;
+ }
+ if (!before) {
+ p++;
+ }
+ int h = 0;
+ final NormalizedNode<?, ?> emptySubtree =
+ ImmutableNodes.fromInstanceId(schemaContext, path.getParent());
+ rWTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
+ for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
+ if (h == p) {
+ simplePut(datastore, path, rWTransaction, schemaContext, payload);
+ }
+ final YangInstanceIdentifier childPath = path.getParent().node(nodeChild.getIdentifier());
+ rWTransaction.put(datastore, childPath, nodeChild);
+ h++;
+ }
+ }
+
+ private void insertWithPointListPut(final DOMDataReadWriteTransaction rWTransaction,
+ final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
+ final SchemaContext schemaContext, final String point, final OrderedMapNode readList,
+ final boolean before) {
+ rWTransaction.delete(datastore, path.getParent());
+ final InstanceIdentifierContext<?> instanceIdentifier =
+ ControllerContext.getInstance().toInstanceIdentifier(point);
+ int p = 0;
+ for (final MapEntryNode mapEntryNode : readList.getValue()) {
+ if (mapEntryNode.getIdentifier().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
+ break;
+ }
+ p++;
+ }
+ if (!before) {
+ p++;
+ }
+ int h = 0;
+ final NormalizedNode<?, ?> emptySubtree =
+ ImmutableNodes.fromInstanceId(schemaContext, path.getParent());
+ rWTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
+ for (final MapEntryNode mapEntryNode : readList.getValue()) {
+ if (h == p) {
+ simplePut(datastore, path, rWTransaction, schemaContext, payload);
+ }
+ final YangInstanceIdentifier childPath = path.getParent().node(mapEntryNode.getIdentifier());
+ rWTransaction.put(datastore, childPath, mapEntryNode);
+ h++;
+ }
+ }
+
+ private void makePut(final DOMDataReadWriteTransaction writeTransaction, final LogicalDatastoreType datastore,
final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload, final SchemaContext schemaContext) {
if (payload instanceof MapNode) {
final NormalizedNode<?, ?> emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path);
writeTransaction.put(datastore, childPath, child);
}
} else {
- ensureParentsByMerge(datastore, path, writeTransaction, schemaContext);
- writeTransaction.put(datastore, path, payload);
+ simplePut(datastore, path, writeTransaction, schemaContext, payload);
}
}
+ private void simplePut(final LogicalDatastoreType datastore, final YangInstanceIdentifier path,
+ final DOMDataReadWriteTransaction writeTransaction, final SchemaContext schemaContext,
+ final NormalizedNode<?, ?> payload) {
+ ensureParentsByMerge(datastore, path, writeTransaction, schemaContext);
+ writeTransaction.put(datastore, path, payload);
+ }
+
private CheckedFuture<Void, TransactionCommitFailedException> deleteDataViaTransaction(
final DOMDataReadWriteTransaction readWriteTransaction, final LogicalDatastoreType datastore,
final YangInstanceIdentifier path) {
import java.nio.charset.StandardCharsets;
import java.util.List;
import javax.ws.rs.core.MediaType;
+import javax.ws.rs.core.UriInfo;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
import org.opendaylight.netconf.sal.rest.impl.NormalizedNodeJsonBodyWriter;
*
* @author Thomas Pantelis
*/
+@Deprecated
public class JSONRestconfServiceImpl implements JSONRestconfService, AutoCloseable {
private final static Logger LOG = LoggerFactory.getLogger(JSONRestconfServiceImpl.class);
private static final Annotation[] EMPTY_ANNOTATIONS = new Annotation[0];
@Override
- public void put(String uriPath, String payload) throws OperationFailedException {
+ public void put(final String uriPath, final String payload, final UriInfo uriInfo) throws OperationFailedException {
Preconditions.checkNotNull(payload, "payload can't be null");
LOG.debug("put: uriPath: {}, payload: {}", uriPath, payload);
- InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8));
- NormalizedNodeContext context = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, false);
+ final InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8));
+ final NormalizedNodeContext context = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, false);
LOG.debug("Parsed YangInstanceIdentifier: {}", context.getInstanceIdentifierContext().getInstanceIdentifier());
LOG.debug("Parsed NormalizedNode: {}", context.getData());
try {
- RestconfImpl.getInstance().updateConfigurationData(uriPath, context);
- } catch (Exception e) {
+ RestconfImpl.getInstance().updateConfigurationData(uriPath, context, uriInfo);
+ } catch (final Exception e) {
propagateExceptionAs(uriPath, e, "PUT");
}
}
@Override
- public void post(String uriPath, String payload) throws OperationFailedException {
+ public void post(final String uriPath, final String payload, final UriInfo uriInfo)
+ throws OperationFailedException {
Preconditions.checkNotNull(payload, "payload can't be null");
LOG.debug("post: uriPath: {}, payload: {}", uriPath, payload);
- InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8));
- NormalizedNodeContext context = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, true);
+ final InputStream entityStream = new ByteArrayInputStream(payload.getBytes(StandardCharsets.UTF_8));
+ final NormalizedNodeContext context = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, true);
LOG.debug("Parsed YangInstanceIdentifier: {}", context.getInstanceIdentifierContext().getInstanceIdentifier());
LOG.debug("Parsed NormalizedNode: {}", context.getData());
try {
- RestconfImpl.getInstance().createConfigurationData(uriPath, context, null);
- } catch (Exception e) {
+ RestconfImpl.getInstance().createConfigurationData(uriPath, context, uriInfo);
+ } catch (final Exception e) {
propagateExceptionAs(uriPath, e, "POST");
}
}
@Override
- public void delete(String uriPath) throws OperationFailedException {
+ public void delete(final String uriPath) throws OperationFailedException {
LOG.debug("delete: uriPath: {}", uriPath);
try {
RestconfImpl.getInstance().deleteConfigurationData(uriPath);
- } catch (Exception e) {
+ } catch (final Exception e) {
propagateExceptionAs(uriPath, e, "DELETE");
}
}
@Override
- public Optional<String> get(String uriPath, LogicalDatastoreType datastoreType) throws OperationFailedException {
+ public Optional<String> get(final String uriPath, final LogicalDatastoreType datastoreType) throws OperationFailedException {
LOG.debug("get: uriPath: {}", uriPath);
try {
readData = RestconfImpl.getInstance().readOperationalData(uriPath, null);
}
- Optional<String> result = Optional.of(toJson(readData));
+ final Optional<String> result = Optional.of(toJson(readData));
LOG.debug("get returning: {}", result.get());
return result;
- } catch (Exception e) {
+ } catch (final Exception e) {
if(!isDataMissing(e)) {
propagateExceptionAs(uriPath, e, "GET");
}
}
@Override
- public Optional<String> invokeRpc(String uriPath, Optional<String> input) throws OperationFailedException {
+ public Optional<String> invokeRpc(final String uriPath, final Optional<String> input) throws OperationFailedException {
Preconditions.checkNotNull(uriPath, "uriPath can't be null");
- String actualInput = input.isPresent() ? input.get() : null;
+ final String actualInput = input.isPresent() ? input.get() : null;
LOG.debug("invokeRpc: uriPath: {}, input: {}", uriPath, actualInput);
try {
NormalizedNodeContext outputContext;
if(actualInput != null) {
- InputStream entityStream = new ByteArrayInputStream(actualInput.getBytes(StandardCharsets.UTF_8));
- NormalizedNodeContext inputContext = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, true);
+ final InputStream entityStream = new ByteArrayInputStream(actualInput.getBytes(StandardCharsets.UTF_8));
+ final NormalizedNodeContext inputContext = JsonNormalizedNodeBodyReader.readFrom(uriPath, entityStream, true);
LOG.debug("Parsed YangInstanceIdentifier: {}", inputContext.getInstanceIdentifierContext()
.getInstanceIdentifier());
if(outputContext.getData() != null) {
output = toJson(outputContext);
}
- } catch (Exception e) {
+ } catch (final Exception e) {
propagateExceptionAs(uriPath, e, "RPC");
}
public void close() {
}
- private String toJson(NormalizedNodeContext readData) throws IOException {
- NormalizedNodeJsonBodyWriter writer = new NormalizedNodeJsonBodyWriter();
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ private String toJson(final NormalizedNodeContext readData) throws IOException {
+ final NormalizedNodeJsonBodyWriter writer = new NormalizedNodeJsonBodyWriter();
+ final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
writer.writeTo(readData, NormalizedNodeContext.class, null, EMPTY_ANNOTATIONS,
MediaType.APPLICATION_JSON_TYPE, null, outputStream );
return outputStream.toString(StandardCharsets.UTF_8.name());
}
- private boolean isDataMissing(Exception e) {
+ private boolean isDataMissing(final Exception e) {
boolean dataMissing = false;
if(e instanceof RestconfDocumentedException) {
- RestconfDocumentedException rde = (RestconfDocumentedException)e;
+ final RestconfDocumentedException rde = (RestconfDocumentedException)e;
if(!rde.getErrors().isEmpty()) {
if(rde.getErrors().get(0).getErrorTag() == ErrorTag.DATA_MISSING) {
dataMissing = true;
return dataMissing;
}
- private static void propagateExceptionAs(String uriPath, Exception e, String operation) throws OperationFailedException {
+ private static void propagateExceptionAs(final String uriPath, final Exception e, final String operation) throws OperationFailedException {
LOG.debug("Error for uriPath: {}", uriPath, e);
if(e instanceof RestconfDocumentedException) {
throw new OperationFailedException(String.format("%s failed for URI %s", operation, uriPath), e);
}
- private static RpcError[] toRpcErrors(List<RestconfError> from) {
- RpcError[] to = new RpcError[from.size()];
+ private static RpcError[] toRpcErrors(final List<RestconfError> from) {
+ final RpcError[] to = new RpcError[from.size()];
int i = 0;
- for(RestconfError e: from) {
+ for(final RestconfError e: from) {
to[i++] = RpcResultBuilder.newError(toRpcErrorType(e.getErrorType()), e.getErrorTag().getTagValue(),
e.getErrorMessage());
}
return to;
}
- private static ErrorType toRpcErrorType(RestconfError.ErrorType errorType) {
+ private static ErrorType toRpcErrorType(final RestconfError.ErrorType errorType) {
switch(errorType) {
case TRANSPORT: {
return ErrorType.TRANSPORT;
final CheckedFuture<DOMRpcResult, DOMRpcException> response;
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
final SchemaContext schemaContext;
+
if (mountPoint != null) {
final Optional<DOMRpcService> mountRpcServices = mountPoint.getService(DOMRpcService.class);
if ( ! mountRpcServices.isPresent()) {
}
@Override
- public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload) {
+ public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload,
+ final UriInfo uriInfo) {
+ boolean insert_used = false;
+ boolean point_used = false;
+ String insert = null;
+ String point = null;
+
+ for (final Entry<String, List<String>> entry : uriInfo.getQueryParameters().entrySet()) {
+ switch (entry.getKey()) {
+ case "insert":
+ if (!insert_used) {
+ insert_used = true;
+ insert = entry.getValue().iterator().next();
+ } else {
+ throw new RestconfDocumentedException("Insert parameter can be used only once.");
+ }
+ break;
+ case "point":
+ if (!point_used) {
+ point_used = true;
+ point = entry.getValue().iterator().next();
+ } else {
+ throw new RestconfDocumentedException("Point parameter can be used only once.");
+ }
+ break;
+ default:
+ throw new RestconfDocumentedException("Bad parameter for post: " + entry.getKey());
+ }
+ }
+
+ if (point_used && !insert_used) {
+ throw new RestconfDocumentedException("Point parameter can't be used without Insert parameter.");
+ }
+ if (point_used && (insert.equals("first") || insert.equals("last"))) {
+ throw new RestconfDocumentedException(
+ "Point parameter can be used only with 'after' or 'before' values of Insert parameter.");
+ }
+
Preconditions.checkNotNull(identifier);
+
final InstanceIdentifierContext<?> iiWithData = payload.getInstanceIdentifierContext();
validateInput(iiWithData.getSchemaNode(), payload);
while(true) {
if (mountPoint != null) {
- result = this.broker.commitMountPointDataPut(mountPoint, normalizedII, payload.getData());
+ result = this.broker.commitMountPointDataPut(mountPoint, normalizedII, payload.getData(), insert,
+ point);
} else {
result = this.broker.commitConfigurationDataPut(this.controllerContext.getGlobalSchema(), normalizedII,
- payload.getData());
+ payload.getData(), insert, point);
}
final CountDownLatch waiter = new CountDownLatch(1);
Futures.addCallback(result.getFutureOfPutData(), new FutureCallback<Void>() {
if (payload == null) {
throw new RestconfDocumentedException("Input is required.", ErrorType.PROTOCOL, ErrorTag.MALFORMED_MESSAGE);
}
-
- // FIXME: move this to parsing stage (we can have augmentation nodes here which do not have namespace)
-// final URI payloadNS = payload.getData().getNodeType().getNamespace();
-// if (payloadNS == null) {
-// throw new RestconfDocumentedException(
-// "Data has bad format. Root element node must have namespace (XML format) or module name(JSON format)",
-// ErrorType.PROTOCOL, ErrorTag.UNKNOWN_NAMESPACE);
-// }
-
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
final InstanceIdentifierContext<?> iiWithData = payload.getInstanceIdentifierContext();
final YangInstanceIdentifier normalizedII = iiWithData.getInstanceIdentifier();
+ boolean insert_used = false;
+ boolean point_used = false;
+ String insert = null;
+ String point = null;
+
+ for (final Entry<String, List<String>> entry : uriInfo.getQueryParameters().entrySet()) {
+ switch (entry.getKey()) {
+ case "insert":
+ if (!insert_used) {
+ insert_used = true;
+ insert = entry.getValue().iterator().next();
+ } else {
+ throw new RestconfDocumentedException("Insert parameter can be used only once.");
+ }
+ break;
+ case "point":
+ if (!point_used) {
+ point_used = true;
+ point = entry.getValue().iterator().next();
+ } else {
+ throw new RestconfDocumentedException("Point parameter can be used only once.");
+ }
+ break;
+ default:
+ throw new RestconfDocumentedException("Bad parameter for post: " + entry.getKey());
+ }
+ }
+
+ if (point_used && !insert_used) {
+ throw new RestconfDocumentedException("Point parameter can't be used without Insert parameter.");
+ }
+ if (point_used && (insert.equals("first") || insert.equals("last"))) {
+ throw new RestconfDocumentedException(
+ "Point parameter can be used only with 'after' or 'before' values of Insert parameter.");
+ }
+
CheckedFuture<Void, TransactionCommitFailedException> future;
if (mountPoint != null) {
- future = this.broker.commitConfigurationDataPost(mountPoint, normalizedII, payload.getData());
+ future = this.broker.commitConfigurationDataPost(mountPoint, normalizedII, payload.getData(), insert,
+ point);
} else {
future = this.broker.commitConfigurationDataPost(this.controllerContext.getGlobalSchema(), normalizedII,
- payload.getData());
+ payload.getData(), insert, point);
}
final CountDownLatch waiter = new CountDownLatch(1);
}
@Override
- public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload) {
+ public Response updateConfigurationData(final String identifier, final NormalizedNodeContext payload,
+ final UriInfo uriInfo) {
this.configPut.incrementAndGet();
Response response = null;
try {
- response = this.delegate.updateConfigurationData(identifier, payload);
+ response = this.delegate.updateConfigurationData(identifier, payload, uriInfo);
if (response.getStatus() == Status.OK.getStatusCode()) {
this.successPut.incrementAndGet();
}
}
@Override
- public Response putData(final String identifier, final NormalizedNodeContext payload) {
- return this.delegRestconfDataService.putData(identifier, payload);
+ public Response putData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
+ return this.delegRestconfDataService.putData(identifier, payload, uriInfo);
}
@Override
@Path("/data/{identifier:.+}")
@Consumes({ Draft17.MediaTypes.DATA + RestconfConstants.JSON, Draft17.MediaTypes.DATA, MediaType.APPLICATION_JSON,
MediaType.APPLICATION_XML, MediaType.TEXT_XML })
- Response putData(@Encoded @PathParam("identifier") String identifier, NormalizedNodeContext payload);
+ Response putData(@Encoded @PathParam("identifier") String identifier, NormalizedNodeContext payload,
+ @Context UriInfo uriInfo);
/**
* Create a data resource in target.
import com.google.common.base.Preconditions;
import java.text.SimpleDateFormat;
import java.util.Date;
+import java.util.List;
+import java.util.Map.Entry;
import java.util.TimeZone;
import javax.annotation.Nonnull;
import javax.ws.rs.core.Response;
}
@Override
- public Response putData(final String identifier, final NormalizedNodeContext payload) {
+ public Response putData(final String identifier, final NormalizedNodeContext payload, final UriInfo uriInfo) {
Preconditions.checkNotNull(payload);
+ boolean insert_used = false;
+ boolean point_used = false;
+ String insert = null;
+ String point = null;
+
+ for (final Entry<String, List<String>> entry : uriInfo.getQueryParameters().entrySet()) {
+ switch (entry.getKey()) {
+ case "insert":
+ if (!insert_used) {
+ insert_used = true;
+ insert = entry.getValue().iterator().next();
+ } else {
+ throw new RestconfDocumentedException("Insert parameter can be used only once.");
+ }
+ break;
+ case "point":
+ if (!point_used) {
+ point_used = true;
+ point = entry.getValue().iterator().next();
+ } else {
+ throw new RestconfDocumentedException("Point parameter can be used only once.");
+ }
+ break;
+ default:
+ throw new RestconfDocumentedException("Bad parameter for post: " + entry.getKey());
+ }
+ }
+
+ checkQueryParams(insert_used, point_used, insert);
+
final InstanceIdentifierContext<? extends SchemaNode> iid = payload
.getInstanceIdentifierContext();
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
payload.getInstanceIdentifierContext(), mountPoint, transactionChain);
- return PutDataTransactionUtil.putData(payload, ref, transactionNode);
+ return PutDataTransactionUtil.putData(payload, ref, transactionNode, insert, point);
+ }
+
+ private void checkQueryParams(final boolean insert_used, final boolean point_used, final String insert) {
+ if (point_used && !insert_used) {
+ throw new RestconfDocumentedException("Point parameter can't be used without Insert parameter.");
+ }
+ if (point_used && (insert.equals("first") || insert.equals("last"))) {
+ throw new RestconfDocumentedException(
+ "Point parameter can be used only with 'after' or 'before' values of Insert parameter.");
+ }
}
@Override
public Response postData(final NormalizedNodeContext payload, final UriInfo uriInfo) {
Preconditions.checkNotNull(payload);
+ boolean insert_used = false;
+ boolean point_used = false;
+ String insert = null;
+ String point = null;
+
+ for (final Entry<String, List<String>> entry : uriInfo.getQueryParameters().entrySet()) {
+ switch (entry.getKey()) {
+ case "insert":
+ if (!insert_used) {
+ insert_used = true;
+ insert = entry.getValue().iterator().next();
+ } else {
+ throw new RestconfDocumentedException("Insert parameter can be used only once.");
+ }
+ break;
+ case "point":
+ if (!point_used) {
+ point_used = true;
+ point = entry.getValue().iterator().next();
+ } else {
+ throw new RestconfDocumentedException("Point parameter can be used only once.");
+ }
+ break;
+ default:
+ throw new RestconfDocumentedException("Bad parameter for post: " + entry.getKey());
+ }
+ }
+
+ checkQueryParams(insert_used, point_used, insert);
+
final DOMMountPoint mountPoint = payload.getInstanceIdentifierContext().getMountPoint();
final DOMTransactionChain transactionChain;
final SchemaContextRef ref;
}
final TransactionVarsWrapper transactionNode = new TransactionVarsWrapper(
payload.getInstanceIdentifierContext(), mountPoint, transactionChain);
- return PostDataTransactionUtil.postData(uriInfo, payload, transactionNode, ref);
+ return PostDataTransactionUtil.postData(uriInfo, payload, transactionNode, ref, insert, point);
}
@Override
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
+import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
+import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
+import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.restconf.common.references.SchemaContextRef;
import org.opendaylight.restconf.restful.transaction.TransactionVarsWrapper;
import org.opendaylight.restconf.utils.parser.ParserIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
* - wrapper for transaction data
* @param schemaContextRef
* - reference to actual {@link SchemaContext}
+ * @param point
+ * @param insert
* @return {@link CheckedFuture}
*/
public static Response postData(final UriInfo uriInfo, final NormalizedNodeContext payload,
- final TransactionVarsWrapper transactionNode, final SchemaContextRef schemaContextRef) {
+ final TransactionVarsWrapper transactionNode, final SchemaContextRef schemaContextRef, final String insert,
+ final String point) {
final CheckedFuture<Void, TransactionCommitFailedException> future = submitData(
payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData(),
- transactionNode, schemaContextRef.get());
+ transactionNode, schemaContextRef.get(), insert, point);
final URI location = PostDataTransactionUtil.resolveLocation(uriInfo, transactionNode, schemaContextRef);
final ResponseFactory dataFactory = new ResponseFactory(null, location);
FutureCallbackTx.addCallback(future, RestconfDataServiceConstant.PostData.POST_TX_TYPE, dataFactory);
* - wrapper for data to transaction
* @param schemaContext
* - schema context of data
+ * @param point
+ * - query parameter
+ * @param insert
+ * - query parameter
* @return {@link CheckedFuture}
*/
private static CheckedFuture<Void, TransactionCommitFailedException> submitData(final YangInstanceIdentifier path,
final NormalizedNode<?, ?> data, final TransactionVarsWrapper transactionNode,
- final SchemaContext schemaContext) {
- final DOMTransactionChain transactionChain = transactionNode.getTransactionChain();
- final DOMDataReadWriteTransaction transaction = transactionChain.newReadWriteTransaction();
+ final SchemaContext schemaContext, final String insert, final String point) {
+ final DOMTransactionChain domTransactionChain = transactionNode.getTransactionChain();
+ final DOMDataReadWriteTransaction newReadWriteTransaction = domTransactionChain.newReadWriteTransaction();
+ if (insert == null) {
+ makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ return newReadWriteTransaction.submit();
+ } else {
+ final DataSchemaNode schemaNode = PutDataTransactionUtil.checkListAndOrderedType(schemaContext, path);
+ switch (insert) {
+ case "first":
+ if (schemaNode instanceof ListSchemaNode) {
+ final NormalizedNode<?, ?> readData =
+ PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
+ schemaNode);
+ final OrderedMapNode readList = (OrderedMapNode) readData;
+ if ((readList == null) || readList.getValue().isEmpty()) {
+ makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ return newReadWriteTransaction.submit();
+ } else {
+ newReadWriteTransaction.delete(LogicalDatastoreType.CONFIGURATION,
+ path.getParent().getParent());
+ simplePost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path, data,
+ schemaContext, domTransactionChain);
+ makePost(path, readData, schemaContext, domTransactionChain,
+ newReadWriteTransaction);
+ return newReadWriteTransaction.submit();
+ }
+ } else {
+ final NormalizedNode<?, ?> readData =
+ PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain, schemaNode);
+
+ final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
+ if ((readLeafList == null) || readLeafList.getValue().isEmpty()) {
+ makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ return newReadWriteTransaction.submit();
+ } else {
+ newReadWriteTransaction.delete(LogicalDatastoreType.CONFIGURATION,
+ path.getParent().getParent());
+ simplePost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path, data,
+ schemaContext, domTransactionChain);
+ makePost(path, readData, schemaContext, domTransactionChain, newReadWriteTransaction);
+ return newReadWriteTransaction.submit();
+ }
+ }
+ case "last":
+ makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ return newReadWriteTransaction.submit();
+ case "before":
+ if (schemaNode instanceof ListSchemaNode) {
+ final NormalizedNode<?, ?> readData =
+ PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
+ schemaNode);
+ final OrderedMapNode readList = (OrderedMapNode) readData;
+ if ((readList == null) || readList.getValue().isEmpty()) {
+ makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ return newReadWriteTransaction.submit();
+ } else {
+ insertWithPointListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path,
+ data, schemaContext, point, readList, true, domTransactionChain);
+ return newReadWriteTransaction.submit();
+ }
+ } else {
+ final NormalizedNode<?, ?> readData =
+ PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
+ schemaNode);
+
+ final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
+ if ((readLeafList == null) || readLeafList.getValue().isEmpty()) {
+ makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ return newReadWriteTransaction.submit();
+ } else {
+ insertWithPointLeafListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION,
+ path, data, schemaContext, point, readLeafList, true, domTransactionChain);
+ return newReadWriteTransaction.submit();
+ }
+ }
+ case "after":
+ if (schemaNode instanceof ListSchemaNode) {
+ final NormalizedNode<?, ?> readData =
+ PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
+ schemaNode);
+ final OrderedMapNode readList = (OrderedMapNode) readData;
+ if ((readList == null) || readList.getValue().isEmpty()) {
+ makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ return newReadWriteTransaction.submit();
+ } else {
+ insertWithPointListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path,
+ data, schemaContext, point, readList, false, domTransactionChain);
+ return newReadWriteTransaction.submit();
+ }
+ } else {
+ final NormalizedNode<?, ?> readData =
+ PutDataTransactionUtil.readList(path.getParent(), schemaContext, domTransactionChain,
+ schemaNode);
+
+ final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
+ if ((readLeafList == null) || readLeafList.getValue().isEmpty()) {
+ makePost(path, data, schemaContext, domTransactionChain, newReadWriteTransaction);
+ return newReadWriteTransaction.submit();
+ } else {
+ insertWithPointLeafListPost(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION,
+ path, data, schemaContext, point, readLeafList, true, domTransactionChain);
+ return newReadWriteTransaction.submit();
+ }
+ }
+ default:
+ throw new RestconfDocumentedException(
+ "Used bad value of insert parameter. Possible values are first, last, before or after, "
+ + "but was: " + insert);
+ }
+ }
+ }
+
+ private static void insertWithPointLeafListPost(final DOMDataReadWriteTransaction rWTransaction,
+ final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
+ final SchemaContext schemaContext, final String point, final OrderedLeafSetNode<?> readLeafList,
+ final boolean before, final DOMTransactionChain domTransactionChain) {
+ rWTransaction.delete(datastore, path.getParent().getParent());
+ final InstanceIdentifierContext<?> instanceIdentifier =
+ ControllerContext.getInstance().toInstanceIdentifier(point);
+ int p = 0;
+ for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
+ if (nodeChild.getIdentifier().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
+ break;
+ }
+ p++;
+ }
+ if (!before) {
+ p++;
+ }
+ int h = 0;
+ final NormalizedNode<?, ?> emptySubtree =
+ ImmutableNodes.fromInstanceId(schemaContext, path.getParent().getParent());
+ rWTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
+ for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
+ if (h == p) {
+ TransactionUtil.checkItemDoesNotExists(domTransactionChain, rWTransaction, datastore, path,
+ RestconfDataServiceConstant.PostData.POST_TX_TYPE);
+ rWTransaction.put(datastore, path, payload);
+ }
+ final YangInstanceIdentifier childPath = path.getParent().getParent().node(nodeChild.getIdentifier());
+ TransactionUtil.checkItemDoesNotExists(domTransactionChain, rWTransaction, datastore, childPath,
+ RestconfDataServiceConstant.PostData.POST_TX_TYPE);
+ rWTransaction.put(datastore, childPath, nodeChild);
+ h++;
+ }
+ }
+
+ private static void insertWithPointListPost(final DOMDataReadWriteTransaction rWTransaction,
+ final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
+ final SchemaContext schemaContext, final String point, final MapNode readList, final boolean before,
+ final DOMTransactionChain domTransactionChain) {
+ rWTransaction.delete(datastore, path.getParent().getParent());
+ final InstanceIdentifierContext<?> instanceIdentifier =
+ ControllerContext.getInstance().toInstanceIdentifier(point);
+ int p = 0;
+ for (final MapEntryNode mapEntryNode : readList.getValue()) {
+ if (mapEntryNode.getIdentifier().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
+ break;
+ }
+ p++;
+ }
+ if (!before) {
+ p++;
+ }
+ int h = 0;
+ final NormalizedNode<?, ?> emptySubtree =
+ ImmutableNodes.fromInstanceId(schemaContext, path.getParent().getParent());
+ rWTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
+ for (final MapEntryNode mapEntryNode : readList.getValue()) {
+ if (h == p) {
+ TransactionUtil.checkItemDoesNotExists(domTransactionChain, rWTransaction, datastore, path,
+ RestconfDataServiceConstant.PostData.POST_TX_TYPE);
+ rWTransaction.put(datastore, path, payload);
+ }
+ final YangInstanceIdentifier childPath = path.getParent().getParent().node(mapEntryNode.getIdentifier());
+ TransactionUtil.checkItemDoesNotExists(domTransactionChain, rWTransaction, datastore, childPath,
+ RestconfDataServiceConstant.PostData.POST_TX_TYPE);
+ rWTransaction.put(datastore, childPath, mapEntryNode);
+ h++;
+ }
+ }
+ private static void makePost(final YangInstanceIdentifier path, final NormalizedNode<?, ?> data,
+ final SchemaContext schemaContext, final DOMTransactionChain transactionChain,
+ final DOMDataReadWriteTransaction transaction) {
if (data instanceof MapNode) {
boolean merge = false;
for (final MapEntryNode child : ((MapNode) data).getValue()) {
TransactionUtil.ensureParentsByMerge(path, schemaContext, transaction);
transaction.put(LogicalDatastoreType.CONFIGURATION, path, data);
}
-
- return transaction.submit();
}
/**
return uriBuilder.build();
}
+
+ private static void simplePost(final DOMDataReadWriteTransaction rWTransaction,
+ final LogicalDatastoreType datastore, final YangInstanceIdentifier path, final NormalizedNode<?, ?> payload,
+ final SchemaContext schemaContext, final DOMTransactionChain transactionChain) {
+ TransactionUtil.checkItemDoesNotExists(transactionChain, rWTransaction, datastore, path,
+ RestconfDataServiceConstant.PostData.POST_TX_TYPE);
+ TransactionUtil.ensureParentsByMerge(path, schemaContext, rWTransaction);
+ rWTransaction.put(datastore, path, payload);
+ }
}
import javax.ws.rs.core.Response;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
+import org.opendaylight.controller.md.sal.dom.api.DOMDataReadWriteTransaction;
import org.opendaylight.controller.md.sal.dom.api.DOMDataWriteTransaction;
+import org.opendaylight.controller.md.sal.dom.api.DOMTransactionChain;
import org.opendaylight.netconf.md.sal.rest.common.RestconfValidationUtils;
+import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
import org.opendaylight.netconf.sal.restconf.impl.InstanceIdentifierContext;
import org.opendaylight.netconf.sal.restconf.impl.NormalizedNodeContext;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.LeafSetNode;
import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
+import org.opendaylight.yangtools.yang.data.api.schema.MapNode;
import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedLeafSetNode;
+import org.opendaylight.yangtools.yang.data.api.schema.OrderedMapNode;
+import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
+import org.opendaylight.yangtools.yang.data.util.DataSchemaContextNode;
+import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree;
+import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
+import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ListSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.SchemaNode;
* @param schemaCtxRef
* - reference to {@link SchemaContext}
* @param transactionNode
+ * - wrapper of variables for transaction
+ * @param point
+ * - query parameter
+ * @param insert
+ * - query parameter
* @return {@link CheckedFuture}
*/
public static Response putData(final NormalizedNodeContext payload,
- final SchemaContextRef schemaCtxRef, final TransactionVarsWrapper transactionNode) {
+ final SchemaContextRef schemaCtxRef, final TransactionVarsWrapper transactionNode, final String insert, final String point) {
final YangInstanceIdentifier path = payload.getInstanceIdentifierContext().getInstanceIdentifier();
final ResponseFactory responseFactory = new ResponseFactory(
ReadDataTransactionUtil.readData(RestconfDataServiceConstant.ReadData.CONFIG, transactionNode));
final CheckedFuture<Void, TransactionCommitFailedException> submitData = submitData(path, schemaCtxRef.get(),
- transactionNode.getTransactionChain().newWriteOnlyTransaction(), payload.getData());
+ transactionNode.getTransactionChain(), payload.getData(), insert, point);
FutureCallbackTx.addCallback(submitData, RestconfDataServiceConstant.PutData.PUT_TX_TYPE, responseFactory);
return responseFactory.build();
}
* - path of data
* @param schemaContext
* - {@link SchemaContext}
- * @param writeTx
+ * @param domTransactionChain
* - write transaction
* @param data
* - data
+ * @param point
+ * - query parameter
+ * @param insert
+ * - query parameter
* @return {@link CheckedFuture}
*/
private static CheckedFuture<Void, TransactionCommitFailedException> submitData(final YangInstanceIdentifier path,
- final SchemaContext schemaContext,
- final DOMDataWriteTransaction writeTx, final NormalizedNode<?, ?> data) {
+ final SchemaContext schemaContext, final DOMTransactionChain domTransactionChain,
+ final NormalizedNode<?, ?> data, final String insert, final String point) {
+ final DOMDataReadWriteTransaction newReadWriteTransaction = domTransactionChain.newReadWriteTransaction();
+ if (insert == null) {
+ return makePut(path, schemaContext, newReadWriteTransaction, data);
+ } else {
+ final DataSchemaNode schemaNode = checkListAndOrderedType(schemaContext, path);
+ switch (insert) {
+ case "first":
+ if (schemaNode instanceof ListSchemaNode) {
+ final NormalizedNode<?, ?> readData =
+ readList(path, schemaContext, domTransactionChain, schemaNode);
+ final OrderedMapNode readList = (OrderedMapNode) readData;
+ if ((readList == null) || readList.getValue().isEmpty()) {
+ return makePut(path, schemaContext, newReadWriteTransaction, data);
+ } else {
+ newReadWriteTransaction.delete(LogicalDatastoreType.CONFIGURATION, path.getParent());
+ simplePut(LogicalDatastoreType.CONFIGURATION, path, newReadWriteTransaction, schemaContext, data);
+ listPut(LogicalDatastoreType.CONFIGURATION, path.getParent(), newReadWriteTransaction, schemaContext,
+ readList);
+ return newReadWriteTransaction.submit();
+ }
+ } else {
+ final NormalizedNode<?, ?> readData =
+ readList(path, schemaContext, domTransactionChain, schemaNode);
+
+ final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
+ if ((readLeafList == null) || readLeafList.getValue().isEmpty()) {
+ return makePut(path, schemaContext, newReadWriteTransaction, data);
+ } else {
+ newReadWriteTransaction.delete(LogicalDatastoreType.CONFIGURATION, path.getParent());
+ simplePut(LogicalDatastoreType.CONFIGURATION, path, newReadWriteTransaction, schemaContext, data);
+ listPut(LogicalDatastoreType.CONFIGURATION, path.getParent(), newReadWriteTransaction, schemaContext,
+ readLeafList);
+ return newReadWriteTransaction.submit();
+ }
+ }
+ case "last":
+ return makePut(path, schemaContext, newReadWriteTransaction, data);
+ case "before":
+ if (schemaNode instanceof ListSchemaNode) {
+ final NormalizedNode<?, ?> readData =
+ readList(path, schemaContext, domTransactionChain, schemaNode);
+ final OrderedMapNode readList = (OrderedMapNode) readData;
+ if ((readList == null) || readList.getValue().isEmpty()) {
+ return makePut(path, schemaContext, newReadWriteTransaction, data);
+ } else {
+ insertWithPointListPut(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path, data,
+ schemaContext, point, readList, true);
+ return newReadWriteTransaction.submit();
+ }
+ } else {
+ final NormalizedNode<?, ?> readData =
+ readList(path, schemaContext, domTransactionChain, schemaNode);
+
+ final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
+ if ((readLeafList == null) || readLeafList.getValue().isEmpty()) {
+ return makePut(path, schemaContext, newReadWriteTransaction, data);
+ } else {
+ insertWithPointLeafListPut(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path, data,
+ schemaContext, point, readLeafList, true);
+ return newReadWriteTransaction.submit();
+ }
+ }
+ case "after":
+ if (schemaNode instanceof ListSchemaNode) {
+ final NormalizedNode<?, ?> readData =
+ readList(path, schemaContext, domTransactionChain, schemaNode);
+ final OrderedMapNode readList = (OrderedMapNode) readData;
+ if ((readList == null) || readList.getValue().isEmpty()) {
+ return makePut(path, schemaContext, newReadWriteTransaction, data);
+ } else {
+ insertWithPointListPut(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path, data,
+ schemaContext, point, readList, false);
+ return newReadWriteTransaction.submit();
+ }
+ } else {
+ final NormalizedNode<?, ?> readData =
+ readList(path, schemaContext, domTransactionChain, schemaNode);
+
+ final OrderedLeafSetNode<?> readLeafList = (OrderedLeafSetNode<?>) readData;
+ if ((readLeafList == null) || readLeafList.getValue().isEmpty()) {
+ return makePut(path, schemaContext, newReadWriteTransaction, data);
+ } else {
+ insertWithPointLeafListPut(newReadWriteTransaction, LogicalDatastoreType.CONFIGURATION, path, data,
+ schemaContext, point, readLeafList, true);
+ return newReadWriteTransaction.submit();
+ }
+ }
+ default:
+ throw new RestconfDocumentedException(
+ "Used bad value of insert parameter. Possible values are first, last, before or after, "
+ + "but was: " + insert);
+ }
+ }
+ }
+
+ public static NormalizedNode<?, ?> readList(final YangInstanceIdentifier path, final SchemaContext schemaContext,
+ final DOMTransactionChain domTransactionChain, final DataSchemaNode schemaNode) {
+ final InstanceIdentifierContext<?> iid = new InstanceIdentifierContext<SchemaNode>(
+ path.getParent(), schemaNode, null, schemaContext);
+ final TransactionVarsWrapper transactionNode =
+ new TransactionVarsWrapper(iid, null, domTransactionChain);
+ final NormalizedNode<?, ?> readData = ReadDataTransactionUtil
+ .readData(RestconfDataServiceConstant.ReadData.CONFIG, transactionNode);
+ return readData;
+ }
+
+ private static void insertWithPointLeafListPut(final DOMDataReadWriteTransaction rWTransaction,
+ final LogicalDatastoreType datastore, final YangInstanceIdentifier path,
+ final NormalizedNode<?, ?> data, final SchemaContext schemaContext, final String point,
+ final OrderedLeafSetNode<?> readLeafList, final boolean before) {
+ rWTransaction.delete(datastore, path.getParent());
+ final InstanceIdentifierContext<?> instanceIdentifier =
+ ControllerContext.getInstance().toInstanceIdentifier(point);
+ int p = 0;
+ for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
+ if (nodeChild.getIdentifier().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
+ break;
+ }
+ p++;
+ }
+ if (!before) {
+ p++;
+ }
+ int h = 0;
+ final NormalizedNode<?, ?> emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path.getParent());
+ rWTransaction.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
+ for (final LeafSetEntryNode<?> nodeChild : readLeafList.getValue()) {
+ if (h == p) {
+ simplePut(datastore, path, rWTransaction, schemaContext, data);
+ }
+ final YangInstanceIdentifier childPath = path.getParent().node(nodeChild.getIdentifier());
+ rWTransaction.put(datastore, childPath, nodeChild);
+ h++;
+ }
+ }
+
+ private static void insertWithPointListPut(final DOMDataReadWriteTransaction writeTx,
+ final LogicalDatastoreType datastore, final YangInstanceIdentifier path,
+ final NormalizedNode<?, ?> data, final SchemaContext schemaContext, final String point,
+ final OrderedMapNode readList, final boolean before) {
+ writeTx.delete(datastore, path.getParent());
+ final InstanceIdentifierContext<?> instanceIdentifier =
+ ControllerContext.getInstance().toInstanceIdentifier(point);
+ int p = 0;
+ for (final MapEntryNode mapEntryNode : readList.getValue()) {
+ if (mapEntryNode.getIdentifier().equals(instanceIdentifier.getInstanceIdentifier().getLastPathArgument())) {
+ break;
+ }
+ p++;
+ }
+ if (!before) {
+ p++;
+ }
+ int h = 0;
+ final NormalizedNode<?, ?> emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path.getParent());
+ writeTx.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
+ for (final MapEntryNode mapEntryNode : readList.getValue()) {
+ if (h == p) {
+ simplePut(datastore, path, writeTx, schemaContext, data);
+ }
+ final YangInstanceIdentifier childPath = path.getParent().node(mapEntryNode.getIdentifier());
+ writeTx.put(datastore, childPath, mapEntryNode);
+ h++;
+ }
+ }
+
+ private static void listPut(final LogicalDatastoreType datastore, final YangInstanceIdentifier path,
+ final DOMDataReadWriteTransaction writeTx, final SchemaContext schemaContext,
+ final OrderedLeafSetNode<?> payload) {
+ final NormalizedNode<?, ?> emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path);
+ writeTx.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
+ TransactionUtil.ensureParentsByMerge(path, schemaContext, writeTx);
+ for (final LeafSetEntryNode<?> child : ((LeafSetNode<?>) payload).getValue()) {
+ final YangInstanceIdentifier childPath = path.node(child.getIdentifier());
+ writeTx.put(datastore, childPath, child);
+ }
+ }
+
+ private static void listPut(final LogicalDatastoreType datastore, final YangInstanceIdentifier path,
+ final DOMDataReadWriteTransaction writeTx, final SchemaContext schemaContext,
+ final OrderedMapNode payload) {
+ final NormalizedNode<?, ?> emptySubtree = ImmutableNodes.fromInstanceId(schemaContext, path);
+ writeTx.merge(datastore, YangInstanceIdentifier.create(emptySubtree.getIdentifier()), emptySubtree);
+ TransactionUtil.ensureParentsByMerge(path, schemaContext, writeTx);
+ for (final MapEntryNode child : ((MapNode) payload).getValue()) {
+ final YangInstanceIdentifier childPath = path.node(child.getIdentifier());
+ writeTx.put(datastore, childPath, child);
+ }
+ }
+
+ private static void simplePut(final LogicalDatastoreType configuration, final YangInstanceIdentifier path,
+ final DOMDataReadWriteTransaction writeTx, final SchemaContext schemaContext,
+ final NormalizedNode<?, ?> data) {
+ TransactionUtil.ensureParentsByMerge(path, schemaContext, writeTx);
+ writeTx.put(LogicalDatastoreType.CONFIGURATION, path, data);
+ }
+
+ private static CheckedFuture<Void, TransactionCommitFailedException> makePut(final YangInstanceIdentifier path,
+ final SchemaContext schemaContext, final DOMDataWriteTransaction writeTx, final NormalizedNode<?, ?> data) {
TransactionUtil.ensureParentsByMerge(path, schemaContext, writeTx);
writeTx.put(LogicalDatastoreType.CONFIGURATION, path, data);
return writeTx.submit();
}
+
+ public static DataSchemaNode checkListAndOrderedType(final SchemaContext ctx, final YangInstanceIdentifier path) {
+ final YangInstanceIdentifier parent = path.getParent();
+ final DataSchemaContextNode<?> node = DataSchemaContextTree.from(ctx).getChild(parent);
+ final DataSchemaNode dataSchemaNode = node.getDataSchemaNode();
+
+ if (dataSchemaNode instanceof ListSchemaNode) {
+ if (!((ListSchemaNode) dataSchemaNode).isUserOrdered()) {
+ throw new RestconfDocumentedException("Insert parameter can be used only with ordered-by user list.");
+ }
+ return dataSchemaNode;
+ }
+ if (dataSchemaNode instanceof LeafListSchemaNode) {
+ if (!((LeafListSchemaNode) dataSchemaNode).isUserOrdered()) {
+ throw new RestconfDocumentedException(
+ "Insert parameter can be used only with ordered-by user leaf-list.");
+ }
+ return dataSchemaNode;
+ }
+ throw new RestconfDocumentedException("Insert parameter can be used only with list or leaf-list");
+ }
}
import java.net.URI;
import java.util.List;
import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
+import org.mockito.Mockito;
import org.opendaylight.controller.sal.restconf.impl.test.TestUtils;
import org.opendaylight.netconf.sal.restconf.impl.BrokerFacade;
import org.opendaylight.netconf.sal.restconf.impl.ControllerContext;
restconfImpl.setControllerContext(controllerContext);
final PutResult result = mock(PutResult.class);
when(brokerFacade.commitConfigurationDataPut(any(SchemaContext.class), any(YangInstanceIdentifier.class),
- any(NormalizedNode.class)))
+ any(NormalizedNode.class), Mockito.anyString(), Mockito.anyString()))
.thenReturn(result);
when(result.getFutureOfPutData()).thenReturn(mock(CheckedFuture.class));
when(result.getStatus()).thenReturn(Status.OK);
final NormalizedNodeContext testCompositeContext = new NormalizedNodeContext(new InstanceIdentifierContext<>(
null, testNodeSchemaNode, null, schemaContextTestModule), testNodeContainer.build());
- restconfImpl.updateConfigurationData(toUri(uriKey1, uriKey2), testCompositeContext);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ restconfImpl.updateConfigurationData(toUri(uriKey1, uriKey2), testCompositeContext, uriInfo);
}
public void putListDataWithWrapperTest(final String uriKey1, final String uriKey2, final String payloadKey1,
when(this.rwTransaction.read(LogicalDatastoreType.CONFIGURATION, this.instanceID)).thenReturn(readFuture);
final PutResult result = this.brokerFacade.commitConfigurationDataPut(mock(SchemaContext.class),
- this.instanceID, this.dummyNode);
+ this.instanceID, this.dummyNode, null, null);
final Future<Void> actualFuture = result.getFutureOfPutData();
when(this.rwTransaction.submit()).thenReturn(expFuture);
final CheckedFuture<Void, TransactionCommitFailedException> actualFuture = this.brokerFacade
- .commitConfigurationDataPost(mock(SchemaContext.class), this.instanceID, this.dummyNode);
+ .commitConfigurationDataPost(mock(SchemaContext.class), this.instanceID, this.dummyNode, null, null);
assertSame("commitConfigurationDataPost", expFuture, actualFuture);
.thenReturn(successFuture);
try {
// Schema context is only necessary for ensuring parent structure
- this.brokerFacade.commitConfigurationDataPost((SchemaContext) null, this.instanceID, this.dummyNode);
+ this.brokerFacade.commitConfigurationDataPost((SchemaContext) null, this.instanceID, this.dummyNode, null,
+ null);
} catch (final RestconfDocumentedException e) {
assertEquals("getErrorTag", RestconfError.ErrorTag.DATA_EXISTS, e.getErrors().get(0).getErrorTag());
throw e;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
+import java.util.HashSet;
import java.util.List;
import java.util.Map;
+import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriBuilder;
+import javax.ws.rs.core.UriInfo;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
*
* @author Thomas Pantelis
*/
+@Deprecated
public class JSONRestconfServiceImplTest {
static final String IETF_INTERFACES_NS = "urn:ietf:params:xml:ns:yang:ietf-interfaces";
static final String IETF_INTERFACES_VERSION = "2013-07-04";
public void testPut() throws Exception {
final PutResult result = mock(PutResult.class);
when(brokerFacade.commitConfigurationDataPut(notNull(SchemaContext.class),
- notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class))).thenReturn(result);
+ notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class), Mockito.anyString(),
+ Mockito.anyString())).thenReturn(result);
when(result.getFutureOfPutData())
.thenReturn(Futures.immediateCheckedFuture(null));
when(result.getStatus()).thenReturn(Status.OK);
final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
final String payload = loadData("/parts/ietf-interfaces_interfaces.json");
-
- this.service.put(uriPath, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ this.service.put(uriPath, payload, uriInfo);
final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
verify(brokerFacade).commitConfigurationDataPut(notNull(SchemaContext.class), capturedPath.capture(),
- capturedNode.capture());
+ capturedNode.capture(), Mockito.anyString(), Mockito.anyString());
verifyPath(capturedPath.getValue(), INTERFACES_QNAME, INTERFACE_QNAME,
new Object[]{INTERFACE_QNAME, NAME_QNAME, "eth0"});
final DOMMountPoint mockMountPoint = setupTestMountPoint();
final PutResult result = mock(PutResult.class);
when(brokerFacade.commitMountPointDataPut(notNull(DOMMountPoint.class),
- notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class))).thenReturn(result);
+ notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class), Mockito.anyString(),
+ Mockito.anyString())).thenReturn(result);
when(result.getFutureOfPutData()).thenReturn(Futures.immediateCheckedFuture(null));
when(result.getStatus()).thenReturn(Status.OK);
final String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont/cont1";
final String payload = loadData("/full-versions/testCont1Data.json");
- this.service.put(uriPath, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ this.service.put(uriPath, payload, uriInfo);
final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
verify(brokerFacade).commitMountPointDataPut(same(mockMountPoint), capturedPath.capture(),
- capturedNode.capture());
+ capturedNode.capture(), Mockito.anyString(), Mockito.anyString());
verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
@Test(expected = OperationFailedException.class)
public void testPutFailure() throws Throwable {
final PutResult result = mock(PutResult.class);
+
when(result.getFutureOfPutData())
.thenReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock")));
when(result.getStatus()).thenReturn(Status.OK);
when(brokerFacade.commitConfigurationDataPut(notNull(SchemaContext.class),
- notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class))).thenReturn(result);
+ notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class), Mockito.anyString(),
+ Mockito.anyString())).thenReturn(result);
final String uriPath = "ietf-interfaces:interfaces/interface/eth0";
final String payload = loadData("/parts/ietf-interfaces_interfaces.json");
- this.service.put(uriPath, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ this.service.put(uriPath, payload, uriInfo);
}
@SuppressWarnings("rawtypes")
@Test
public void testPost() throws Exception {
doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
- any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
+ any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class),
+ Mockito.anyString(), Mockito.anyString());
final String uriPath = null;
final String payload = loadData("/parts/ietf-interfaces_interfaces_absolute_path.json");
- this.service.post(uriPath, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ final UriBuilder uriBuilder = UriBuilder.fromPath("");
+ Mockito.when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder);
+ this.service.post(uriPath, payload, uriInfo);
final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
verify(brokerFacade).commitConfigurationDataPost(notNull(SchemaContext.class), capturedPath.capture(),
- capturedNode.capture());
+ capturedNode.capture(), Mockito.anyString(), Mockito.anyString());
verifyPath(capturedPath.getValue(), INTERFACES_QNAME);
public void testPostBehindMountPoint() throws Exception {
final DOMMountPoint mockMountPoint = setupTestMountPoint();
doReturn(Futures.immediateCheckedFuture(null)).when(brokerFacade).commitConfigurationDataPost(
- notNull(DOMMountPoint.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class));
+ notNull(DOMMountPoint.class), notNull(YangInstanceIdentifier.class), notNull(NormalizedNode.class),
+ Mockito.anyString(), Mockito.anyString());
final String uriPath = "ietf-interfaces:interfaces/yang-ext:mount/test-module:cont";
final String payload = loadData("/full-versions/testCont1Data.json");
- this.service.post(uriPath, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ final UriBuilder uriBuilder = UriBuilder.fromPath("");
+ Mockito.when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder);
+ this.service.post(uriPath, payload, uriInfo);
final ArgumentCaptor<YangInstanceIdentifier> capturedPath = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
final ArgumentCaptor<NormalizedNode> capturedNode = ArgumentCaptor.forClass(NormalizedNode.class);
verify(brokerFacade).commitConfigurationDataPost(same(mockMountPoint), capturedPath.capture(),
- capturedNode.capture());
+ capturedNode.capture(), Mockito.anyString(), Mockito.anyString());
verifyPath(capturedPath.getValue(), TEST_CONT_QNAME, TEST_CONT1_QNAME);
public void testPostFailure() throws Throwable {
doReturn(Futures.immediateFailedCheckedFuture(new TransactionCommitFailedException("mock"))).when(brokerFacade)
.commitConfigurationDataPost(any(SchemaContext.class), any(YangInstanceIdentifier.class),
- any(NormalizedNode.class));
+ any(NormalizedNode.class), Mockito.anyString(), Mockito.anyString());
final String uriPath = null;
final String payload = loadData("/parts/ietf-interfaces_interfaces_absolute_path.json");
- this.service.post(uriPath, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ final UriBuilder uriBuilder = UriBuilder.fromPath("");
+ Mockito.when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder);
+ this.service.post(uriPath, payload, uriInfo);
}
@Test
import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Test;
+import org.mockito.Mockito;
import org.opendaylight.netconf.sal.rest.api.Draft02;
import org.opendaylight.netconf.sal.rest.api.RestconfService;
import org.opendaylight.netconf.sal.rest.impl.JsonNormalizedNodeBodyReader;
final String uriPrefix = "/config/";
final String uriPath = "ietf-interfaces:interfaces";
final String uri = uriPrefix + uriPath;
- when(restconfService.updateConfigurationData(eq(uriPath), any(NormalizedNodeContext.class))).thenReturn(null);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ when(restconfService.updateConfigurationData(eq(uriPath), any(NormalizedNodeContext.class), uriInfo))
+ .thenReturn(null);
put(uri, null, Draft02.MediaTypes.DATA + JSON, jsonData);
- verify(restconfService, times(1)).updateConfigurationData(eq(uriPath), any(NormalizedNodeContext.class));
+ verify(restconfService, times(1)).updateConfigurationData(eq(uriPath), any(NormalizedNodeContext.class),
+ uriInfo);
put(uri, null, Draft02.MediaTypes.DATA + XML, xmlData);
- verify(restconfService, times(2)).updateConfigurationData(eq(uriPath), any(NormalizedNodeContext.class));
+ verify(restconfService, times(2)).updateConfigurationData(eq(uriPath), any(NormalizedNodeContext.class),
+ uriInfo);
put(uri, null, MediaType.APPLICATION_JSON, jsonData);
- verify(restconfService, times(3)).updateConfigurationData(eq(uriPath), any(NormalizedNodeContext.class));
+ verify(restconfService, times(3)).updateConfigurationData(eq(uriPath), any(NormalizedNodeContext.class),
+ uriInfo);
put(uri, null, MediaType.APPLICATION_XML, xmlData);
- verify(restconfService, times(4)).updateConfigurationData(eq(uriPath), any(NormalizedNodeContext.class));
+ verify(restconfService, times(4)).updateConfigurationData(eq(uriPath), any(NormalizedNodeContext.class),
+ uriInfo);
put(uri, null, MediaType.TEXT_XML, xmlData);
- verify(restconfService, times(5)).updateConfigurationData(eq(uriPath), any(NormalizedNodeContext.class));
+ verify(restconfService, times(5)).updateConfigurationData(eq(uriPath), any(NormalizedNodeContext.class),
+ uriInfo);
put(uri, "fooMediaType", MediaType.TEXT_XML, xmlData);
- verify(restconfService, times(6)).updateConfigurationData(eq(uriPath), any(NormalizedNodeContext.class));
+ verify(restconfService, times(6)).updateConfigurationData(eq(uriPath), any(NormalizedNodeContext.class),
+ uriInfo);
}
@Test
private int post(final String uri, final String acceptMediaType, final String contentTypeMediaType, final String data) {
if (acceptMediaType == null) {
- if (contentTypeMediaType == null || data == null) {
+ if ((contentTypeMediaType == null) || (data == null)) {
return target(uri).request().post(null).getStatus();
}
return target(uri).request().post(Entity.entity(data, contentTypeMediaType)).getStatus();
}
- if (contentTypeMediaType == null || data == null) {
+ if ((contentTypeMediaType == null) || (data == null)) {
return target(uri).request(acceptMediaType).post(null).getStatus();
}
return target(uri).request(acceptMediaType).post(Entity.entity(data, contentTypeMediaType)).getStatus();
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
+import org.mockito.Mockito;
import org.opendaylight.controller.md.sal.common.api.TransactionStatus;
import org.opendaylight.controller.md.sal.common.api.data.TransactionCommitFailedException;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
setSchemaControllerContext(schemaContextYangsIetf);
when(
brokerFacade.commitConfigurationDataPost(any(DOMMountPoint.class), any(YangInstanceIdentifier.class),
- any(NormalizedNode.class))).thenReturn(mock(CheckedFuture.class));
+ any(NormalizedNode.class), null, null)).thenReturn(mock(CheckedFuture.class));
final DOMMountPoint mountInstance = mock(DOMMountPoint.class);
when(mountInstance.getSchemaContext()).thenReturn(schemaContextTestModule);
final RpcResult<TransactionStatus> rpcResult = new DummyRpcResult.Builder<TransactionStatus>().result(
TransactionStatus.COMMITED).build();
- when(brokerFacade.commitConfigurationDataPost((SchemaContext)null, any(YangInstanceIdentifier.class), any(NormalizedNode.class)))
+ when(brokerFacade.commitConfigurationDataPost((SchemaContext) null, any(YangInstanceIdentifier.class),
+ any(NormalizedNode.class), null, null))
.thenReturn(mock(CheckedFuture.class));
final ArgumentCaptor<YangInstanceIdentifier> instanceIdCaptor = ArgumentCaptor.forClass(YangInstanceIdentifier.class);
// FIXME : NEVER test a nr. of call some service in complex test suite
// verify(brokerFacade, times(2))
verify(brokerFacade, times(1))
- .commitConfigurationDataPost((SchemaContext)null, instanceIdCaptor.capture(), compNodeCaptor.capture());
+ .commitConfigurationDataPost((SchemaContext) null, instanceIdCaptor.capture(), compNodeCaptor.capture(),
+ null, null);
// identifier = "[(urn:ietf:params:xml:ns:yang:test-interface?revision=2014-07-01)interfaces, (urn:ietf:params:xml:ns:yang:test-interface?revision=2014-07-01)block]";
assertEquals(identifier, ImmutableList.copyOf(instanceIdCaptor.getValue().getPathArguments()).toString());
}
public void createConfigurationDataNullTest() throws UnsupportedEncodingException {
initMocking();
- when(brokerFacade.commitConfigurationDataPost(any(SchemaContext.class), any(YangInstanceIdentifier.class),any(NormalizedNode.class)))
+ when(brokerFacade.commitConfigurationDataPost(any(SchemaContext.class), any(YangInstanceIdentifier.class),
+ any(NormalizedNode.class), Mockito.anyString(), Mockito.anyString()))
.thenReturn(Futures.<Void, TransactionCommitFailedException>immediateCheckedFuture(null));
//FIXME : find who is set schemaContext
import com.google.common.util.concurrent.CheckedFuture;
import com.google.common.util.concurrent.Futures;
+import java.util.HashSet;
+import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response.Status;
+import javax.ws.rs.core.UriInfo;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
mockingBrokerPut(iiCx.getInstanceIdentifier(), data);
- this.restconfService.updateConfigurationData(identifier, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ this.restconfService.updateConfigurationData(identifier, payload, uriInfo);
}
@Test
mockingBrokerPut(iiCx.getInstanceIdentifier(), data);
- this.restconfService.updateConfigurationData(identifier, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ this.restconfService.updateConfigurationData(identifier, payload, uriInfo);
}
@Test(expected=RestconfDocumentedException.class)
mockingBrokerPut(iiCx.getInstanceIdentifier(), data);
- this.restconfService.updateConfigurationData(identifier, payload);
+ final UriInfo uriInfo = Mockito.mock(UriInfo.class);
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(uriInfo.getQueryParameters()).thenReturn(value);
+ this.restconfService.updateConfigurationData(identifier, payload, uriInfo);
}
private void mockingBrokerPut(final YangInstanceIdentifier yii, final NormalizedNode<?, ?> data) {
final PutResult result = Mockito.mock(PutResult.class);
final CheckedFuture<Void, TransactionCommitFailedException> checkedFuture = Futures.immediateCheckedFuture(null);
- Mockito.when(this.brokerFacade.commitConfigurationDataPut(this.schemaCx, yii, data))
+ Mockito.when(this.brokerFacade.commitConfigurationDataPut(this.schemaCx, yii, data, null, null))
.thenReturn(result);
Mockito.when(result.getFutureOfPutData()).thenReturn(checkedFuture);
Mockito.when(result.getStatus()).thenReturn(Status.OK);
final PutResult result = mock(PutResult.class);
when(
brokerFacade.commitMountPointDataPut(any(DOMMountPoint.class), any(YangInstanceIdentifier.class),
- any(NormalizedNode.class))).thenReturn(result);
+ any(NormalizedNode.class), null, null)).thenReturn(result);
when(result.getFutureOfPutData()).thenReturn(dummyFuture);
when(result.getStatus()).thenReturn(Status.OK);
final CheckedFuture<Void, TransactionCommitFailedException> dummyFuture = Futures.immediateCheckedFuture(null);
final PutResult result = mock(PutResult.class);
doReturn(result).when(brokerFacade).commitMountPointDataPut(any(DOMMountPoint.class),
- any(YangInstanceIdentifier.class), any(NormalizedNode.class));
+ any(YangInstanceIdentifier.class), any(NormalizedNode.class), null, null);
when(result.getFutureOfPutData()).thenReturn(dummyFuture);
when(result.getStatus()).thenReturn(Status.OK);
doThrow(OptimisticLockFailedException.class).
when(brokerFacade).commitConfigurationDataPut(
- any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
+ any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class), null,
+ null);
assertEquals(500, put(uri, MediaType.APPLICATION_XML, xmlData));
doThrow(OptimisticLockFailedException.class).doReturn(mock(PutResult.class)).when(brokerFacade)
.commitConfigurationDataPut(any(SchemaContext.class), any(YangInstanceIdentifier.class),
- any(NormalizedNode.class));
+ any(NormalizedNode.class), null, null);
assertEquals(500, put(uri, MediaType.APPLICATION_XML, xmlData));
}
doThrow(TransactionCommitFailedException.class).
when(brokerFacade).commitConfigurationDataPut(
- any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
+ any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class), null,
+ null);
assertEquals(500, put(uri, MediaType.APPLICATION_XML, xmlData));
}
final PutResult putResMock = mock(PutResult.class);
if (noErrors) {
doReturn(putResMock).when(brokerFacade).commitConfigurationDataPut(
- any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
+ any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class), null, null);
} else {
doThrow(RestconfDocumentedException.class).when(brokerFacade).commitConfigurationDataPut(
- any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class));
+ any(SchemaContext.class), any(YangInstanceIdentifier.class), any(NormalizedNode.class), null, null);
}
}
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
-
import com.google.common.base.Optional;
import com.google.common.util.concurrent.Futures;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashSet;
import java.util.List;
import javax.ws.rs.core.MultivaluedHashMap;
+import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
import javax.ws.rs.core.UriInfo;
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
- containerPlayerQname = QName.create(baseQName, "player");
- leafQname = QName.create(baseQName, "gap");
+ final MultivaluedMap<String, String> value = Mockito.mock(MultivaluedMap.class);
+ Mockito.when(value.entrySet()).thenReturn(new HashSet<>());
+ Mockito.when(this.uriInfo.getQueryParameters()).thenReturn(value);
+
+ this.baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
+ this.containerPlayerQname = QName.create(this.baseQName, "player");
+ this.leafQname = QName.create(this.baseQName, "gap");
- final QName containerLibraryQName = QName.create(baseQName, "library");
- final QName listPlaylistQName = QName.create(baseQName, "playlist");
+ final QName containerLibraryQName = QName.create(this.baseQName, "library");
+ final QName listPlaylistQName = QName.create(this.baseQName, "playlist");
final LeafNode buildLeaf = Builders.leafBuilder()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(leafQname))
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(this.leafQname))
.withValue(0.2)
.build();
- buildPlayerCont = Builders.containerBuilder()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(containerPlayerQname))
+ this.buildPlayerCont = Builders.containerBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(this.containerPlayerQname))
.withChild(buildLeaf)
.build();
- buildLibraryCont = Builders.containerBuilder()
+ this.buildLibraryCont = Builders.containerBuilder()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(containerLibraryQName))
.build();
- buildPlaylistList = Builders.mapBuilder()
+ this.buildPlaylistList = Builders.mapBuilder()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(listPlaylistQName))
.build();
- buildBaseCont = Builders.containerBuilder()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(baseQName))
- .withChild(buildPlayerCont)
+ this.buildBaseCont = Builders.containerBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(this.baseQName))
+ .withChild(this.buildPlayerCont)
.build();
// config contains one child the same as in operational and one additional
- buildBaseContConfig = Builders.containerBuilder()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(baseQName))
- .withChild(buildPlayerCont)
- .withChild(buildLibraryCont)
+ this.buildBaseContConfig = Builders.containerBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(this.baseQName))
+ .withChild(this.buildPlayerCont)
+ .withChild(this.buildLibraryCont)
.build();
// operational contains one child the same as in config and one additional
- buildBaseContOperational = Builders.containerBuilder()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(baseQName))
- .withChild(buildPlayerCont)
- .withChild(buildPlaylistList)
+ this.buildBaseContOperational = Builders.containerBuilder()
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(this.baseQName))
+ .withChild(this.buildPlayerCont)
+ .withChild(this.buildPlaylistList)
.build();
- iidBase = YangInstanceIdentifier.builder()
- .node(baseQName)
+ this.iidBase = YangInstanceIdentifier.builder()
+ .node(this.baseQName)
.build();
- contextRef = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT));
- schemaNode = DataSchemaContextTree.from(contextRef.get()).getChild(iidBase).getDataSchemaNode();
+ this.contextRef = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT));
+ this.schemaNode = DataSchemaContextTree.from(this.contextRef.get()).getChild(this.iidBase).getDataSchemaNode();
final SchemaContextHandler schemaContextHandler = new SchemaContextHandler();
- schemaContextHandler.onGlobalContextUpdated(contextRef.get());
- dataService = new RestconfDataServiceImpl(schemaContextHandler, transactionChainHandler, mountPointServiceHandler);
- doReturn(domTransactionChain).when(transactionChainHandler).get();
- doReturn(read).when(domTransactionChain).newReadOnlyTransaction();
- doReturn(readWrite).when(domTransactionChain).newReadWriteTransaction();
- doReturn(write).when(domTransactionChain).newWriteOnlyTransaction();
- doReturn(mountPointService).when(mountPointServiceHandler).get();
- doReturn(Optional.of(mountPoint)).when(mountPointService).getMountPoint(any(YangInstanceIdentifier.class));
- doReturn(contextRef.get()).when(mountPoint).getSchemaContext();
- doReturn(Optional.of(mountDataBroker)).when(mountPoint).getService(DOMDataBroker.class);
- doReturn(transactionChain).when(mountDataBroker).createTransactionChain(any(TransactionChainListener.class));
- doReturn(read).when(transactionChain).newReadOnlyTransaction();
- doReturn(readWrite).when(transactionChain).newReadWriteTransaction();
+ schemaContextHandler.onGlobalContextUpdated(this.contextRef.get());
+ this.dataService = new RestconfDataServiceImpl(schemaContextHandler, this.transactionChainHandler, this.mountPointServiceHandler);
+ doReturn(this.domTransactionChain).when(this.transactionChainHandler).get();
+ doReturn(this.read).when(this.domTransactionChain).newReadOnlyTransaction();
+ doReturn(this.readWrite).when(this.domTransactionChain).newReadWriteTransaction();
+ doReturn(this.write).when(this.domTransactionChain).newWriteOnlyTransaction();
+ doReturn(this.mountPointService).when(this.mountPointServiceHandler).get();
+ doReturn(Optional.of(this.mountPoint)).when(this.mountPointService).getMountPoint(any(YangInstanceIdentifier.class));
+ doReturn(this.contextRef.get()).when(this.mountPoint).getSchemaContext();
+ doReturn(Optional.of(this.mountDataBroker)).when(this.mountPoint).getService(DOMDataBroker.class);
+ doReturn(this.transactionChain).when(this.mountDataBroker).createTransactionChain(any(TransactionChainListener.class));
+ doReturn(this.read).when(this.transactionChain).newReadOnlyTransaction();
+ doReturn(this.readWrite).when(this.transactionChain).newReadWriteTransaction();
}
@Test
public void testReadData() {
- doReturn(new MultivaluedHashMap<String, String>()).when(uriInfo).getQueryParameters();
- doReturn(Futures.immediateCheckedFuture(Optional.of(buildBaseCont))).when(read)
- .read(LogicalDatastoreType.CONFIGURATION, iidBase);
- doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(read).read(LogicalDatastoreType.OPERATIONAL, iidBase);
- final Response response = dataService.readData("example-jukebox:jukebox", uriInfo);
+ doReturn(new MultivaluedHashMap<String, String>()).when(this.uriInfo).getQueryParameters();
+ doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
+ .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(this.read).read(LogicalDatastoreType.OPERATIONAL, this.iidBase);
+ final Response response = this.dataService.readData("example-jukebox:jukebox", this.uriInfo);
assertNotNull(response);
assertEquals(200, response.getStatus());
- assertEquals(buildBaseCont, ((NormalizedNodeContext) response.getEntity()).getData());
+ assertEquals(this.buildBaseCont, ((NormalizedNodeContext) response.getEntity()).getData());
}
/**
*/
@Test
public void testReadDataMountPoint() {
- doReturn(new MultivaluedHashMap<String, String>()).when(uriInfo).getQueryParameters();
- doReturn(Futures.immediateCheckedFuture(Optional.of(buildBaseContConfig))).when(read)
- .read(LogicalDatastoreType.CONFIGURATION, iidBase);
- doReturn(Futures.immediateCheckedFuture(Optional.of(buildBaseContOperational))).when(read)
- .read(LogicalDatastoreType.OPERATIONAL, iidBase);
+ doReturn(new MultivaluedHashMap<String, String>()).when(this.uriInfo).getQueryParameters();
+ doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseContConfig))).when(this.read)
+ .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseContOperational))).when(this.read)
+ .read(LogicalDatastoreType.OPERATIONAL, this.iidBase);
- final Response response = dataService.readData(
- "example-jukebox:jukebox/yang-ext:mount/example-jukebox:jukebox", uriInfo);
+ final Response response = this.dataService.readData(
+ "example-jukebox:jukebox/yang-ext:mount/example-jukebox:jukebox", this.uriInfo);
assertNotNull(response);
assertEquals(200, response.getStatus());
final NormalizedNode<?, ?> data = ((NormalizedNodeContext) response.getEntity()).getData();
assertTrue(data instanceof ContainerNode);
assertEquals(3, ((ContainerNode) data).getValue().size());
- assertTrue(((ContainerNode) data).getChild(buildPlayerCont.getIdentifier()).isPresent());
- assertTrue(((ContainerNode) data).getChild(buildLibraryCont.getIdentifier()).isPresent());
- assertTrue(((ContainerNode) data).getChild(buildPlaylistList.getIdentifier()).isPresent());
+ assertTrue(((ContainerNode) data).getChild(this.buildPlayerCont.getIdentifier()).isPresent());
+ assertTrue(((ContainerNode) data).getChild(this.buildLibraryCont.getIdentifier()).isPresent());
+ assertTrue(((ContainerNode) data).getChild(this.buildPlaylistList.getIdentifier()).isPresent());
}
@Test(expected = RestconfDocumentedException.class)
public void testReadDataNoData() {
- doReturn(new MultivaluedHashMap<String, String>()).when(uriInfo).getQueryParameters();
- doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(read).read(LogicalDatastoreType.CONFIGURATION,
- iidBase);
- doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(read).read(LogicalDatastoreType.OPERATIONAL,
- iidBase);
- dataService.readData("example-jukebox:jukebox", uriInfo);
+ doReturn(new MultivaluedHashMap<String, String>()).when(this.uriInfo).getQueryParameters();
+ doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(this.read).read(LogicalDatastoreType.CONFIGURATION,
+ this.iidBase);
+ doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(this.read).read(LogicalDatastoreType.OPERATIONAL,
+ this.iidBase);
+ this.dataService.readData("example-jukebox:jukebox", this.uriInfo);
}
/**
final MultivaluedHashMap<String, String> parameters = new MultivaluedHashMap<>();
parameters.put("content", Collections.singletonList("config"));
- doReturn(parameters).when(uriInfo).getQueryParameters();
- doReturn(Futures.immediateCheckedFuture(Optional.of(buildBaseContConfig))).when(read)
- .read(LogicalDatastoreType.CONFIGURATION, iidBase);
- doReturn(Futures.immediateCheckedFuture(Optional.of(buildBaseContOperational))).when(read)
- .read(LogicalDatastoreType.OPERATIONAL, iidBase);
+ doReturn(parameters).when(this.uriInfo).getQueryParameters();
+ doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseContConfig))).when(this.read)
+ .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseContOperational))).when(this.read)
+ .read(LogicalDatastoreType.OPERATIONAL, this.iidBase);
- final Response response = dataService.readData("example-jukebox:jukebox", uriInfo);
+ final Response response = this.dataService.readData("example-jukebox:jukebox", this.uriInfo);
assertNotNull(response);
assertEquals(200, response.getStatus());
final NormalizedNode<?, ?> data = ((NormalizedNodeContext) response.getEntity()).getData();
// config data present
- assertTrue(((ContainerNode) data).getChild(buildPlayerCont.getIdentifier()).isPresent());
- assertTrue(((ContainerNode) data).getChild(buildLibraryCont.getIdentifier()).isPresent());
+ assertTrue(((ContainerNode) data).getChild(this.buildPlayerCont.getIdentifier()).isPresent());
+ assertTrue(((ContainerNode) data).getChild(this.buildLibraryCont.getIdentifier()).isPresent());
// state data absent
- assertFalse(((ContainerNode) data).getChild(buildPlaylistList.getIdentifier()).isPresent());
+ assertFalse(((ContainerNode) data).getChild(this.buildPlaylistList.getIdentifier()).isPresent());
}
/**
final MultivaluedHashMap<String, String> parameters = new MultivaluedHashMap<>();
parameters.put("content", Collections.singletonList("nonconfig"));
- doReturn(parameters).when(uriInfo).getQueryParameters();
- doReturn(Futures.immediateCheckedFuture(Optional.of(buildBaseContConfig))).when(read)
- .read(LogicalDatastoreType.CONFIGURATION, iidBase);
- doReturn(Futures.immediateCheckedFuture(Optional.of(buildBaseContOperational))).when(read)
- .read(LogicalDatastoreType.OPERATIONAL, iidBase);
+ doReturn(parameters).when(this.uriInfo).getQueryParameters();
+ doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseContConfig))).when(this.read)
+ .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseContOperational))).when(this.read)
+ .read(LogicalDatastoreType.OPERATIONAL, this.iidBase);
- final Response response = dataService.readData("example-jukebox:jukebox", uriInfo);
+ final Response response = this.dataService.readData("example-jukebox:jukebox", this.uriInfo);
assertNotNull(response);
assertEquals(200, response.getStatus());
final NormalizedNode<?, ?> data = ((NormalizedNodeContext) response.getEntity()).getData();
// state data present
- assertTrue(((ContainerNode) data).getChild(buildPlayerCont.getIdentifier()).isPresent());
- assertTrue(((ContainerNode) data).getChild(buildPlaylistList.getIdentifier()).isPresent());
+ assertTrue(((ContainerNode) data).getChild(this.buildPlayerCont.getIdentifier()).isPresent());
+ assertTrue(((ContainerNode) data).getChild(this.buildPlaylistList.getIdentifier()).isPresent());
// config data absent
- assertFalse(((ContainerNode) data).getChild(buildLibraryCont.getIdentifier()).isPresent());
+ assertFalse(((ContainerNode) data).getChild(this.buildLibraryCont.getIdentifier()).isPresent());
}
@Test
public void testPutData() {
- final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iidBase, schemaNode, null, contextRef.get());
- final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildBaseCont);
-
- doReturn(Futures.immediateCheckedFuture(Optional.of(buildBaseCont))).when(read)
- .read(LogicalDatastoreType.CONFIGURATION, iidBase);
- doNothing().when(write).put(LogicalDatastoreType.CONFIGURATION, iidBase, payload.getData());
- doReturn(Futures.immediateCheckedFuture(null)).when(write).submit();
- final Response response = dataService.putData(null, payload);
+ final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, null, this.contextRef.get());
+ final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildBaseCont);
+
+ doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
+ .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, payload.getData());
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+ final Response response = this.dataService.putData(null, payload, this.uriInfo);
assertNotNull(response);
assertEquals(200, response.getStatus());
}
final DOMDataBroker dataBroker = Mockito.mock(DOMDataBroker.class);
final DOMMountPoint mountPoint = Mockito.mock(DOMMountPoint.class);
doReturn(Optional.of(dataBroker)).when(mountPoint).getService(DOMDataBroker.class);
- doReturn(transactionChainHandler.get()).when(dataBroker).createTransactionChain(RestConnectorProvider.transactionListener);
- final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iidBase, schemaNode, mountPoint, contextRef.get());
- final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildBaseCont);
-
- doReturn(Futures.immediateCheckedFuture(Optional.of(buildBaseCont))).when(read)
- .read(LogicalDatastoreType.CONFIGURATION, iidBase);
- doNothing().when(write).put(LogicalDatastoreType.CONFIGURATION, iidBase, payload.getData());
- doReturn(Futures.immediateCheckedFuture(null)).when(write).submit();
- final Response response = dataService.putData(null, payload);
+ doReturn(this.transactionChainHandler.get()).when(dataBroker).createTransactionChain(RestConnectorProvider.transactionListener);
+ final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, mountPoint, this.contextRef.get());
+ final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildBaseCont);
+
+ doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
+ .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, payload.getData());
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+ final Response response = this.dataService.putData(null, payload, this.uriInfo);
assertNotNull(response);
assertEquals(200, response.getStatus());
}
@Test
public void testPostData() {
- final QName listQname = QName.create(baseQName, "playlist");
- final QName listKeyQname = QName.create(baseQName, "name");
+ final QName listQname = QName.create(this.baseQName, "playlist");
+ final QName listKeyQname = QName.create(this.baseQName, "name");
final YangInstanceIdentifier.NodeIdentifierWithPredicates nodeWithKey =
new YangInstanceIdentifier.NodeIdentifierWithPredicates(listQname, listKeyQname, "name of band");
final LeafNode<Object> content = Builders.leafBuilder()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create(baseQName, "name")))
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create(this.baseQName, "name")))
.withValue("name of band")
.build();
final LeafNode<Object> content2 = Builders.leafBuilder()
- .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create(baseQName, "description")))
+ .withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create(this.baseQName, "description")))
.withValue("band description")
.build();
final MapEntryNode mapEntryNode = Builders.mapEntryBuilder()
.withChild(mapEntryNode)
.build();
- doReturn(new MultivaluedHashMap<String, String>()).when(uriInfo).getQueryParameters();
- final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iidBase, null, null, contextRef.get());
+ doReturn(new MultivaluedHashMap<String, String>()).when(this.uriInfo).getQueryParameters();
+ final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(this.iidBase, null, null, this.contextRef.get());
final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildList);
- doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(read).read(LogicalDatastoreType.CONFIGURATION, iidBase);
+ doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(this.read).read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
final MapNode data = (MapNode) payload.getData();
final YangInstanceIdentifier.NodeIdentifierWithPredicates identifier = data.getValue().iterator().next().getIdentifier();
final YangInstanceIdentifier node = payload.getInstanceIdentifierContext().getInstanceIdentifier().node(identifier);
- doReturn(Futures.immediateCheckedFuture(false)).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
- doNothing().when(readWrite).put(LogicalDatastoreType.CONFIGURATION, node, payload.getData());
- doReturn(Futures.immediateCheckedFuture(null)).when(readWrite).submit();
- doReturn(UriBuilder.fromUri("http://localhost:8181/restconf/15/")).when(uriInfo).getBaseUriBuilder();
+ doReturn(Futures.immediateCheckedFuture(false)).when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
+ doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, payload.getData());
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+ doReturn(UriBuilder.fromUri("http://localhost:8181/restconf/15/")).when(this.uriInfo).getBaseUriBuilder();
- final Response response = dataService.postData(null, payload, uriInfo);
+ final Response response = this.dataService.postData(null, payload, this.uriInfo);
assertEquals(201, response.getStatus());
}
@Test
public void testDeleteData() {
- doNothing().when(readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidBase);
- doReturn(Futures.immediateCheckedFuture(null)).when(readWrite).submit();
- doReturn(Futures.immediateCheckedFuture(true)).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidBase);
- final Response response = dataService.deleteData("example-jukebox:jukebox");
+ doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+ doReturn(Futures.immediateCheckedFuture(true)).when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ final Response response = this.dataService.deleteData("example-jukebox:jukebox");
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
*/
@Test
public void testDeleteDataMountPoint() {
- doNothing().when(readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidBase);
- doReturn(Futures.immediateCheckedFuture(null)).when(readWrite).submit();
- doReturn(Futures.immediateCheckedFuture(true)).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidBase);
- final Response response = dataService.deleteData("example-jukebox:jukebox/yang-ext:mount/example-jukebox:jukebox");
+ doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+ doReturn(Futures.immediateCheckedFuture(true)).when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ final Response response = this.dataService.deleteData("example-jukebox:jukebox/yang-ext:mount/example-jukebox:jukebox");
assertNotNull(response);
assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());
}
@Test
public void testPatchData() throws Exception {
- final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iidBase, schemaNode, null, contextRef.get());
+ final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, null, this.contextRef.get());
final List<PATCHEntity> entity = new ArrayList<>();
- final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(iidBase)
- .node(containerPlayerQname)
- .node(leafQname)
+ final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(this.iidBase)
+ .node(this.containerPlayerQname)
+ .node(this.leafQname)
.build();
- entity.add(new PATCHEntity("create data", "CREATE", iidBase, buildBaseCont));
- entity.add(new PATCHEntity("replace data", "REPLACE", iidBase, buildBaseCont));
+ entity.add(new PATCHEntity("create data", "CREATE", this.iidBase, this.buildBaseCont));
+ entity.add(new PATCHEntity("replace data", "REPLACE", this.iidBase, this.buildBaseCont));
entity.add(new PATCHEntity("delete data", "DELETE", iidleaf));
final PATCHContext patch = new PATCHContext(iidContext, entity, "test patch id");
- doReturn(Futures.immediateCheckedFuture(Optional.of(buildBaseCont))).when(read)
- .read(LogicalDatastoreType.CONFIGURATION, iidBase);
- doNothing().when(write).put(LogicalDatastoreType.CONFIGURATION, iidBase, buildBaseCont);
- doReturn(Futures.immediateCheckedFuture(null)).when(write).submit();
- doNothing().when(readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
- doReturn(Futures.immediateCheckedFuture(null)).when(readWrite).submit();
- doReturn(Futures.immediateCheckedFuture(false)).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidBase);
- doReturn(Futures.immediateCheckedFuture(true)).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidleaf);
- final PATCHStatusContext status = dataService.patchData(patch, uriInfo);
+ doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
+ .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
+ doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+ doReturn(Futures.immediateCheckedFuture(false)).when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ doReturn(Futures.immediateCheckedFuture(true)).when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidleaf);
+ final PATCHStatusContext status = this.dataService.patchData(patch, this.uriInfo);
assertTrue(status.isOk());
assertEquals(3, status.getEditCollection().size());
assertEquals("replace data", status.getEditCollection().get(1).getEditId());
@Test
public void testPatchDataMountPoint() throws Exception {
final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(
- iidBase, schemaNode, mountPoint, contextRef.get());
+ this.iidBase, this.schemaNode, this.mountPoint, this.contextRef.get());
final List<PATCHEntity> entity = new ArrayList<>();
- final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(iidBase)
- .node(containerPlayerQname)
- .node(leafQname)
+ final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(this.iidBase)
+ .node(this.containerPlayerQname)
+ .node(this.leafQname)
.build();
- entity.add(new PATCHEntity("create data", "CREATE", iidBase, buildBaseCont));
- entity.add(new PATCHEntity("replace data", "REPLACE", iidBase, buildBaseCont));
+ entity.add(new PATCHEntity("create data", "CREATE", this.iidBase, this.buildBaseCont));
+ entity.add(new PATCHEntity("replace data", "REPLACE", this.iidBase, this.buildBaseCont));
entity.add(new PATCHEntity("delete data", "DELETE", iidleaf));
final PATCHContext patch = new PATCHContext(iidContext, entity, "test patch id");
- doReturn(Futures.immediateCheckedFuture(Optional.of(buildBaseCont))).when(read)
- .read(LogicalDatastoreType.CONFIGURATION, iidBase);
- doNothing().when(write).put(LogicalDatastoreType.CONFIGURATION, iidBase, buildBaseCont);
- doReturn(Futures.immediateCheckedFuture(null)).when(write).submit();
- doNothing().when(readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
- doReturn(Futures.immediateCheckedFuture(null)).when(readWrite).submit();
- doReturn(Futures.immediateCheckedFuture(false)).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidBase);
- doReturn(Futures.immediateCheckedFuture(true)).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidleaf);
+ doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
+ .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
+ doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+ doReturn(Futures.immediateCheckedFuture(false)).when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ doReturn(Futures.immediateCheckedFuture(true)).when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidleaf);
- final PATCHStatusContext status = dataService.patchData(patch, uriInfo);
+ final PATCHStatusContext status = this.dataService.patchData(patch, this.uriInfo);
assertTrue(status.isOk());
assertEquals(3, status.getEditCollection().size());
assertNull(status.getGlobalErrors());
broker.setAccessible(true);
broker.set(RestConnectorProvider.class, mock(DOMDataBroker.class));
- final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(iidBase, schemaNode, null, contextRef.get());
+ final InstanceIdentifierContext<? extends SchemaNode> iidContext = new InstanceIdentifierContext<>(this.iidBase, this.schemaNode, null, this.contextRef.get());
final List<PATCHEntity> entity = new ArrayList<>();
- final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(iidBase)
- .node(containerPlayerQname)
- .node(leafQname)
+ final YangInstanceIdentifier iidleaf = YangInstanceIdentifier.builder(this.iidBase)
+ .node(this.containerPlayerQname)
+ .node(this.leafQname)
.build();
- entity.add(new PATCHEntity("create data", "CREATE", iidBase, buildBaseCont));
+ entity.add(new PATCHEntity("create data", "CREATE", this.iidBase, this.buildBaseCont));
entity.add(new PATCHEntity("remove data", "REMOVE", iidleaf));
entity.add(new PATCHEntity("delete data", "DELETE", iidleaf));
final PATCHContext patch = new PATCHContext(iidContext, entity, "test patch id");
- doReturn(Futures.immediateCheckedFuture(Optional.of(buildBaseCont))).when(read)
- .read(LogicalDatastoreType.CONFIGURATION, iidBase);
- doNothing().when(write).put(LogicalDatastoreType.CONFIGURATION, iidBase, buildBaseCont);
- doReturn(Futures.immediateCheckedFuture(null)).when(write).submit();
- doNothing().when(readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
- doReturn(Futures.immediateCheckedFuture(null)).when(readWrite).submit();
- doReturn(Futures.immediateCheckedFuture(false)).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidBase);
- doReturn(Futures.immediateCheckedFuture(false)).when(readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidleaf);
- doReturn(true).when(readWrite).cancel();
- final PATCHStatusContext status = dataService.patchData(patch, uriInfo);
+ doReturn(Futures.immediateCheckedFuture(Optional.of(this.buildBaseCont))).when(this.read)
+ .read(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, this.iidBase, this.buildBaseCont);
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.write).submit();
+ doNothing().when(this.readWrite).delete(LogicalDatastoreType.CONFIGURATION, iidleaf);
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+ doReturn(Futures.immediateCheckedFuture(false)).when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iidBase);
+ doReturn(Futures.immediateCheckedFuture(false)).when(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, iidleaf);
+ doReturn(true).when(this.readWrite).cancel();
+ final PATCHStatusContext status = this.dataService.patchData(patch, this.uriInfo);
handler.set(RestConnectorProvider.class, null);
handler.setAccessible(false);
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
-
import com.google.common.util.concurrent.Futures;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, payload.getData());
doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain);
- final Response response = PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx);
+ final Response response =
+ PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx, null, null);
assertEquals(201, response.getStatus());
verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iid2);
verify(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
doNothing().when(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, payload.getData());
doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain);
- final Response response = PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx);
+ final Response response =
+ PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx, null, null);
assertEquals(201, response.getStatus());
verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, node);
verify(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, node, data.getValue().iterator().next());
payload.getData());
doReturn(Futures.immediateFailedCheckedFuture(new DOMException((short) 414, "Post request failed"))).when(this.readWrite).submit();
final TransactionVarsWrapper wrapper = new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain);
- final Response response = PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx);
+ final Response response =
+ PostDataTransactionUtil.postData(this.uriInfo, payload, wrapper, this.refSchemaCtx, null, null);
assertEquals(Response.Status.INTERNAL_SERVER_ERROR, response.getStatusInfo());
- verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, iid2);
+ verify(this.readWrite).exists(LogicalDatastoreType.CONFIGURATION, this.iid2);
verify(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
}
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.verify;
-
import com.google.common.base.Optional;
import com.google.common.util.concurrent.Futures;
import org.junit.Before;
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
- refSchemaCtx = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT));
- schema = refSchemaCtx.get();
+ this.refSchemaCtx = new SchemaContextRef(TestRestconfUtils.loadSchemaContext(PATH_FOR_NEW_SCHEMA_CONTEXT));
+ this.schema = this.refSchemaCtx.get();
final QName baseQName = QName.create("http://example.com/ns/example-jukebox", "2015-04-04", "jukebox");
final QName containerQname = QName.create(baseQName, "player");
final YangInstanceIdentifier.NodeIdentifierWithPredicates nodeWithKey2 =
new YangInstanceIdentifier.NodeIdentifierWithPredicates(listQname, listKeyQname, "name of band 2");
- iid = YangInstanceIdentifier.builder()
+ this.iid = YangInstanceIdentifier.builder()
.node(baseQName)
.node(containerQname)
.node(leafQname)
.build();
- schemaNode = DataSchemaContextTree.from(schema).getChild(iid).getDataSchemaNode();
+ this.schemaNode = DataSchemaContextTree.from(this.schema).getChild(this.iid).getDataSchemaNode();
- iid2 = YangInstanceIdentifier.builder()
+ this.iid2 = YangInstanceIdentifier.builder()
.node(baseQName)
.build();
- schemaNode2 = DataSchemaContextTree.from(schema).getChild(iid2).getDataSchemaNode();
+ this.schemaNode2 = DataSchemaContextTree.from(this.schema).getChild(this.iid2).getDataSchemaNode();
- iid3 = YangInstanceIdentifier.builder()
+ this.iid3 = YangInstanceIdentifier.builder()
.node(baseQName)
.node(listQname)
.node(nodeWithKey)
.build();
- schemaNode3 = DataSchemaContextTree.from(schema).getChild(iid3).getDataSchemaNode();
+ this.schemaNode3 = DataSchemaContextTree.from(this.schema).getChild(this.iid3).getDataSchemaNode();
- buildLeaf = Builders.leafBuilder()
+ this.buildLeaf = Builders.leafBuilder()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(leafQname))
.withValue(0.2)
.build();
final ContainerNode buildPlayerCont = Builders.containerBuilder()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(containerQname))
- .withChild(buildLeaf)
+ .withChild(this.buildLeaf)
.build();
- buildBaseCont = Builders.containerBuilder()
+ this.buildBaseCont = Builders.containerBuilder()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(baseQName))
.withChild(buildPlayerCont)
.build();
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(QName.create(baseQName, "description")))
.withValue("band description")
.build();
- buildListEntry = Builders.mapEntryBuilder()
+ this.buildListEntry = Builders.mapEntryBuilder()
.withNodeIdentifier(nodeWithKey)
.withChild(content)
.withChild(content2)
.build();
final MapNode buildList = Builders.mapBuilder()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(listQname))
- .withChild(buildListEntry)
+ .withChild(this.buildListEntry)
.withChild(buildListEntry2)
.build();
- buildBaseContWithList = Builders.containerBuilder()
+ this.buildBaseContWithList = Builders.containerBuilder()
.withNodeIdentifier(new YangInstanceIdentifier.NodeIdentifier(baseQName))
.withChild(buildList)
.build();
@Test
public void testValidInputData() throws Exception {
- final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
- final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildLeaf);
+ final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(this.iid, this.schemaNode, null, this.schema);
+ final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildLeaf);
PutDataTransactionUtil.validInputData(iidContext.getSchemaNode(), payload);
}
@Test
public void testValidTopLevelNodeName() throws Exception {
- InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
- NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildLeaf);
+ InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(this.iid, this.schemaNode, null, this.schema);
+ NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildLeaf);
PutDataTransactionUtil.validTopLevelNodeName(iidContext.getInstanceIdentifier(), payload);
- iidContext = new InstanceIdentifierContext<>(iid2, schemaNode2, null, schema);
- payload = new NormalizedNodeContext(iidContext, buildBaseCont);
+ iidContext = new InstanceIdentifierContext<>(this.iid2, this.schemaNode2, null, this.schema);
+ payload = new NormalizedNodeContext(iidContext, this.buildBaseCont);
PutDataTransactionUtil.validTopLevelNodeName(iidContext.getInstanceIdentifier(), payload);
}
@Test(expected = RestconfDocumentedException.class)
public void testValidTopLevelNodeNamePathEmpty() throws Exception {
- final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
- final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildLeaf);
+ final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(this.iid, this.schemaNode, null, this.schema);
+ final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildLeaf);
PutDataTransactionUtil.validTopLevelNodeName(YangInstanceIdentifier.EMPTY, payload);
}
@Test(expected = RestconfDocumentedException.class)
public void testValidTopLevelNodeNameWrongTopIdentifier() throws Exception {
- final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
- final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildLeaf);
- PutDataTransactionUtil.validTopLevelNodeName(iid.getAncestor(1), payload);
+ final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(this.iid, this.schemaNode, null, this.schema);
+ final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildLeaf);
+ PutDataTransactionUtil.validTopLevelNodeName(this.iid.getAncestor(1), payload);
}
@Test
public void testValidateListKeysEqualityInPayloadAndUri() throws Exception {
- final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid3, schemaNode3, null, schema);
- final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildListEntry);
+ final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(this.iid3, this.schemaNode3, null, this.schema);
+ final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildListEntry);
PutDataTransactionUtil.validateListKeysEqualityInPayloadAndUri(payload);
}
@Test
public void testPutContainerData() throws Exception {
- final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, schemaNode2, null, schema);
- final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildBaseCont);
-
- doReturn(readWrite).when(transactionChain).newReadWriteTransaction();
- doReturn(read).when(transactionChain).newReadOnlyTransaction();
- doReturn(write).when(transactionChain).newWriteOnlyTransaction();
- doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(read).read(LogicalDatastoreType.CONFIGURATION, iid2);
- doNothing().when(write).put(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(),
- payload.getData());
- doReturn(Futures.immediateCheckedFuture(null)).when(write).submit();
-
- PutDataTransactionUtil.putData(payload, refSchemaCtx,
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChain));
- verify(read).read(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier());
- verify(write).put(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(),
+ final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(this.iid2, this.schemaNode2, null, this.schema);
+ final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildBaseCont);
+
+ doReturn(this.readWrite).when(this.transactionChain).newReadWriteTransaction();
+ doReturn(this.read).when(this.transactionChain).newReadOnlyTransaction();
+ doReturn(this.write).when(this.transactionChain).newWriteOnlyTransaction();
+ doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(this.read).read(LogicalDatastoreType.CONFIGURATION, this.iid2);
+ doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(),
payload.getData());
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+
+ PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+ null);
+ verify(this.read).read(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier());
+ verify(this.readWrite).put(LogicalDatastoreType.CONFIGURATION,
+ payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
}
@Test
public void testPutleafData() throws Exception {
- final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid, schemaNode, null, schema);
- final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildLeaf);
-
- doReturn(readWrite).when(transactionChain).newReadWriteTransaction();
- doReturn(read).when(transactionChain).newReadOnlyTransaction();
- doReturn(write).when(transactionChain).newWriteOnlyTransaction();
- doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(read).read(LogicalDatastoreType.CONFIGURATION, iid);
- doNothing().when(write).put(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(),
- payload.getData());
- doReturn(Futures.immediateCheckedFuture(null)).when(write).submit();
-
- PutDataTransactionUtil.putData(payload, refSchemaCtx,
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChain));
- verify(read).read(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier());
- verify(write).put(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(),
+ final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(this.iid, this.schemaNode, null, this.schema);
+ final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildLeaf);
+
+ doReturn(this.readWrite).when(this.transactionChain).newReadWriteTransaction();
+ doReturn(this.read).when(this.transactionChain).newReadOnlyTransaction();
+ doReturn(this.write).when(this.transactionChain).newWriteOnlyTransaction();
+ doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(this.read).read(LogicalDatastoreType.CONFIGURATION, this.iid);
+ doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(),
payload.getData());
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+
+ PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+ null);
+ verify(this.read).read(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier());
+ verify(this.readWrite).put(LogicalDatastoreType.CONFIGURATION,
+ payload.getInstanceIdentifierContext().getInstanceIdentifier(), payload.getData());
}
@Test
public void testPutListData() throws Exception {
- final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(iid2, schemaNode2, null, schema);
- final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, buildBaseContWithList);
-
- doReturn(readWrite).when(transactionChain).newReadWriteTransaction();
- doReturn(read).when(transactionChain).newReadOnlyTransaction();
- doReturn(write).when(transactionChain).newWriteOnlyTransaction();
- doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(read).read(LogicalDatastoreType.CONFIGURATION, iid2);
- doNothing().when(write).put(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(),
+ final InstanceIdentifierContext<DataSchemaNode> iidContext = new InstanceIdentifierContext<>(this.iid2, this.schemaNode2, null, this.schema);
+ final NormalizedNodeContext payload = new NormalizedNodeContext(iidContext, this.buildBaseContWithList);
+
+ doReturn(this.readWrite).when(this.transactionChain).newReadWriteTransaction();
+ doReturn(this.read).when(this.transactionChain).newReadOnlyTransaction();
+ doReturn(this.write).when(this.transactionChain).newWriteOnlyTransaction();
+ doReturn(Futures.immediateCheckedFuture(Optional.absent())).when(this.read).read(LogicalDatastoreType.CONFIGURATION, this.iid2);
+ doNothing().when(this.write).put(LogicalDatastoreType.CONFIGURATION, payload.getInstanceIdentifierContext().getInstanceIdentifier(),
payload.getData());
- doReturn(Futures.immediateCheckedFuture(null)).when(write).submit();
- PutDataTransactionUtil.putData(payload, refSchemaCtx,
- new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, transactionChain));
- verify(read).read(LogicalDatastoreType.CONFIGURATION, iid2);
- verify(write).put(LogicalDatastoreType.CONFIGURATION, iid2, payload.getData());
+ doReturn(Futures.immediateCheckedFuture(null)).when(this.readWrite).submit();
+ PutDataTransactionUtil.putData(payload, this.refSchemaCtx,
+ new TransactionVarsWrapper(payload.getInstanceIdentifierContext(), null, this.transactionChain), null,
+ null);
+ verify(this.read).read(LogicalDatastoreType.CONFIGURATION, this.iid2);
+ verify(this.readWrite).put(LogicalDatastoreType.CONFIGURATION, this.iid2, payload.getData());
}
}
--- /dev/null
+module ordered-example {
+ namespace "ordered:example";
+ prefix "oex";
+
+ revision 2016-11-13 {
+ description
+ "Initial revision.";
+ }
+
+ container cont {
+ list playlist {
+ key name;
+
+ leaf name {
+ type string;
+ }
+ list song {
+ key index;
+ ordered-by user;
+
+ leaf index {
+ type uint32;
+ }
+ leaf id {
+ type instance-identifier;
+ mandatory true;
+ description
+ "Song identifier. Must identify an instance of
+ /songs-cont/songs/song-name.";
+ }
+ }
+ }
+ }
+
+ container songs-cont{
+ list songs{
+ key song-name;
+
+ leaf song-name{
+ type string;
+ }
+ }
+ }
+}
\ No newline at end of file