use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.
the class OrderingEqualityTest method testUserMap.
@Test
public void testUserMap() {
final UserMapNode firstMap = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).build();
final UserMapNode secondMap = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).build();
assertEquals(firstMap.asMap(), secondMap.asMap());
assertFalse(firstMap.equals(secondMap));
assertFalse(secondMap.equals(firstMap));
final UserMapNode thirdMap = Builders.orderedMapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).build();
assertEquals(secondMap.asMap(), thirdMap.asMap());
assertFalse(firstMap.equals(thirdMap));
assertTrue(secondMap.equals(thirdMap));
assertArrayEquals(secondMap.body().toArray(), thirdMap.body().toArray());
assertEquals(secondMap.hashCode(), thirdMap.hashCode());
// Although this map looks as secondMap, it is not equal
final SystemMapNode systemMap = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).build();
assertEquals(secondMap.asMap(), systemMap.asMap());
assertFalse(firstMap.equals(systemMap));
assertFalse(secondMap.equals(systemMap));
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project yangtools by opendaylight.
the class OrderingEqualityTest method testSystemMap.
@Test
public void testSystemMap() {
final SystemMapNode firstMap = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).build();
final SystemMapNode secondMap = Builders.mapBuilder().withNodeIdentifier(new NodeIdentifier(FOO)).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "two")).withChild(ImmutableNodes.leafNode(BAR, "two")).build()).withChild(Builders.mapEntryBuilder().withNodeIdentifier(NodeIdentifierWithPredicates.of(FOO, BAR, "one")).withChild(ImmutableNodes.leafNode(BAR, "one")).build()).build();
assertEquals(firstMap.asMap(), secondMap.asMap());
// Order does not matter
assertTrue(firstMap.equals(secondMap));
assertTrue(secondMap.equals(firstMap));
assertEquals(firstMap.hashCode(), secondMap.hashCode());
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project netconf by opendaylight.
the class RestconfDocumentedExceptionMapper method toResponse.
@Override
public Response toResponse(final RestconfDocumentedException exception) {
LOG.debug("In toResponse: {}", exception.getMessage());
final List<MediaType> mediaTypeList = new ArrayList<>();
if (headers.getMediaType() != null) {
mediaTypeList.add(headers.getMediaType());
}
mediaTypeList.addAll(headers.getAcceptableMediaTypes());
final MediaType mediaType = mediaTypeList.stream().filter(type -> !type.equals(MediaType.WILDCARD_TYPE)).findFirst().orElse(MediaType.APPLICATION_JSON_TYPE);
LOG.debug("Using MediaType: {}", mediaType);
final List<RestconfError> errors = exception.getErrors();
if (errors.isEmpty()) {
return Response.status(exception.getStatus()).type(MediaType.TEXT_PLAIN_TYPE).entity(" ").build();
}
final Status status = ErrorTags.statusOf(errors.iterator().next().getErrorTag());
final DataNodeContainer errorsSchemaNode = (DataNodeContainer) controllerContext.getRestconfModuleErrorsSchemaNode();
if (errorsSchemaNode == null) {
return Response.status(status).type(MediaType.TEXT_PLAIN_TYPE).entity(exception.getMessage()).build();
}
checkState(errorsSchemaNode instanceof ContainerSchemaNode, "Found Errors SchemaNode isn't ContainerNode");
final DataContainerNodeBuilder<NodeIdentifier, ContainerNode> errContBuild = SchemaAwareBuilders.containerBuilder((ContainerSchemaNode) errorsSchemaNode);
final List<DataSchemaNode> schemaList = ControllerContext.findInstanceDataChildrenByName(errorsSchemaNode, RestConfModule.ERROR_LIST_SCHEMA_NODE);
final DataSchemaNode errListSchemaNode = Iterables.getFirst(schemaList, null);
checkState(errListSchemaNode instanceof ListSchemaNode, "Found Error SchemaNode isn't ListSchemaNode");
final CollectionNodeBuilder<MapEntryNode, SystemMapNode> listErorsBuilder = SchemaAwareBuilders.mapBuilder((ListSchemaNode) errListSchemaNode);
for (final RestconfError error : errors) {
listErorsBuilder.withChild(toErrorEntryNode(error, errListSchemaNode));
}
errContBuild.withChild(listErorsBuilder.build());
final NormalizedNodeContext errContext = new NormalizedNodeContext(new InstanceIdentifierContext<>(ERRORS, (DataSchemaNode) errorsSchemaNode, null, controllerContext.getGlobalSchema()), errContBuild.build());
Object responseBody;
if (mediaType.getSubtype().endsWith("json")) {
responseBody = toJsonResponseBody(errContext, errorsSchemaNode);
} else {
responseBody = toXMLResponseBody(errContext, errorsSchemaNode);
}
return Response.status(status).type(mediaType).entity(responseBody).build();
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project netconf by opendaylight.
the class RestconfImpl method makeModuleMapNode.
private MapNode makeModuleMapNode(final Collection<? extends Module> modules) {
requireNonNull(modules);
final Module restconfModule = getRestconfModule();
final DataSchemaNode moduleSchemaNode = controllerContext.getRestconfModuleRestConfSchemaNode(restconfModule, RestConfModule.MODULE_LIST_SCHEMA_NODE);
checkState(moduleSchemaNode instanceof ListSchemaNode);
final CollectionNodeBuilder<MapEntryNode, SystemMapNode> listModuleBuilder = SchemaAwareBuilders.mapBuilder((ListSchemaNode) moduleSchemaNode);
for (final Module module : modules) {
listModuleBuilder.withChild(toModuleEntryNode(module, moduleSchemaNode));
}
return listModuleBuilder.build();
}
use of org.opendaylight.yangtools.yang.data.api.schema.SystemMapNode in project netconf by opendaylight.
the class CutDataToCorrectDepthTest method mapNode.
private static MapNode mapNode(final String localName, final MapEntryNode... entryNodes) {
final CollectionNodeBuilder<MapEntryNode, SystemMapNode> builder = Builders.mapBuilder();
builder.withNodeIdentifier(toIdentifier(localName));
for (final MapEntryNode mapEntryNode : entryNodes) {
builder.withChild(mapEntryNode);
}
return builder.build();
}
Aggregations