From ab9cf2e3435ef127ffcba672c5601ff75417b216 Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Tue, 10 Jun 2014 11:15:04 +0200 Subject: [PATCH] BUG-272: cleanup sal-rest-connector Preparatory patch, expand wildcard imports to get rid of checkstyle failures. Save action added final keywords where appropriate. Change-Id: I269d373bed9fd83d3837f9ed4d3ff7fc105d7305 Signed-off-by: Robert Varga --- .../RestconfDocumentedExceptionMapper.java | 49 +- .../sal/restconf/impl/ControllerContext.java | 140 +++-- .../sal/restconf/impl/StructuredData.java | 4 +- .../WebSocketServerInitializer.java | 8 +- .../sal/restconf/impl/test/DummyFuture.java | 21 +- .../restconf/impl/test/DummyRpcResult.java | 11 +- .../sal/restconf/impl/test/DummyType.java | 5 +- .../restconf/impl/test/NormalizeNodeTest.java | 4 +- ...RestconfDocumentedExceptionMapperTest.java | 482 +++++++++--------- .../impl/test/structures/CompareLf.java | 3 +- .../restconf/impl/test/structures/Lst.java | 12 +- 11 files changed, 378 insertions(+), 361 deletions(-) diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfDocumentedExceptionMapper.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfDocumentedExceptionMapper.java index c13d593a8e..5f6909cea8 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfDocumentedExceptionMapper.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/rest/impl/RestconfDocumentedExceptionMapper.java @@ -8,6 +8,15 @@ package org.opendaylight.controller.sal.rest.impl; +import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERRORS_CONTAINER_QNAME; +import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_APP_TAG_QNAME; +import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_INFO_QNAME; +import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_LIST_QNAME; +import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_MESSAGE_QNAME; +import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_TAG_QNAME; +import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.ERROR_TYPE_QNAME; +import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.NAMESPACE; + import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.OutputStreamWriter; @@ -33,8 +42,6 @@ import javax.xml.transform.TransformerFactoryConfigurationError; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import static org.opendaylight.controller.sal.rest.api.Draft02.RestConfModule.*; - import org.opendaylight.controller.sal.restconf.impl.ControllerContext; import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException; import org.opendaylight.controller.sal.restconf.impl.RestconfError; @@ -70,7 +77,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper> errorNodes = ImmutableList.> builder(); @@ -116,7 +123,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper toDomNode( RestconfError error ) { + private Node toDomNode( final RestconfError error ) { CompositeNodeBuilder builder = ImmutableCompositeNode.builder(); builder.setQName( ERROR_LIST_QNAME ); @@ -209,7 +216,7 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper parseErrorInfo( String errorInfo ) { + private Node parseErrorInfo( final String errorInfo ) { if( Strings.isNullOrEmpty( errorInfo ) ) { return null; } @@ -226,19 +233,19 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper" ) - .append( errorInfo ).append( "" ).toString(); + .append( errorInfo ).append( "" ).toString(); Document doc = null; try { doc = factory.newDocumentBuilder().parse( - new InputSource( new StringReader( errorInfoWithRoot ) ) ); + new InputSource( new StringReader( errorInfoWithRoot ) ) ); } catch( Exception e ) { // TODO: what if the content is text that happens to contain invalid markup? Could // wrap in CDATA and try again. LOG.warn( "Error parsing restconf error-info, \"" + errorInfo + "\", as XML: " + - e.toString() ); + e.toString() ); return null; } @@ -263,8 +270,8 @@ public class RestconfDocumentedExceptionMapper implements ExceptionMapper builder, QName qname, - String value ) { + private void addLeaf( final CompositeNodeBuilder builder, final QName qname, + final String value ) { if( !Strings.isNullOrEmpty( value ) ) { builder.addLeaf( qname, value ); } diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java index ad740775cd..b0916f4500 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/ControllerContext.java @@ -7,19 +7,6 @@ */ package org.opendaylight.controller.sal.restconf.impl; -import com.google.common.base.Function; -import com.google.common.base.Objects; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; -import com.google.common.base.Splitter; -import com.google.common.base.Strings; -import com.google.common.collect.BiMap; -import com.google.common.collect.FluentIterable; -import com.google.common.collect.HashBiMap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URLDecoder; @@ -40,8 +27,6 @@ import org.opendaylight.controller.sal.core.api.mount.MountInstance; import org.opendaylight.controller.sal.core.api.mount.MountService; import org.opendaylight.controller.sal.rest.api.Draft02; import org.opendaylight.controller.sal.rest.impl.RestUtil; -import org.opendaylight.controller.sal.restconf.impl.InstanceIdWithSchemaNode; -import org.opendaylight.controller.sal.restconf.impl.RestCodec; import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag; import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType; import org.opendaylight.yangtools.concepts.Codec; @@ -69,6 +54,19 @@ import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.base.Function; +import com.google.common.base.Objects; +import com.google.common.base.Optional; +import com.google.common.base.Preconditions; +import com.google.common.base.Predicate; +import com.google.common.base.Splitter; +import com.google.common.base.Strings; +import com.google.common.collect.BiMap; +import com.google.common.collect.FluentIterable; +import com.google.common.collect.HashBiMap; +import com.google.common.collect.Iterables; +import com.google.common.collect.Lists; + public class ControllerContext implements SchemaContextListener { private final static Logger LOG = LoggerFactory.getLogger( ControllerContext.class ); @@ -127,7 +125,7 @@ public class ControllerContext implements SchemaContextListener { } private InstanceIdWithSchemaNode toIdentifier( final String restconfInstance, - final boolean toMountPointIdentifier ) { + final boolean toMountPointIdentifier ) { this.checkPreconditions(); Iterable split = Splitter.on( "/" ).split( restconfInstance ); @@ -149,7 +147,7 @@ public class ControllerContext implements SchemaContextListener { InstanceIdentifierBuilder builder = InstanceIdentifier.builder(); Module latestModule = this.getLatestModule( globalSchema, startModule ); InstanceIdWithSchemaNode iiWithSchemaNode = this.collectPathArguments( builder, pathArgs, - latestModule, null, toMountPointIdentifier ); + latestModule, null, toMountPointIdentifier ); if( iiWithSchemaNode == null ) { throw new RestconfDocumentedException( @@ -187,7 +185,7 @@ public class ControllerContext implements SchemaContextListener { Predicate filter = new Predicate() { @Override - public boolean apply( Module m ) { + public boolean apply( final Module m ) { return Objects.equal( m.getName(), moduleName ); } }; @@ -232,14 +230,14 @@ public class ControllerContext implements SchemaContextListener { final SchemaContext mountPointSchema = mountPoint.getSchemaContext(); Set moduleSchemas = mountPointSchema == null ? null : - mountPointSchema.findModuleByNamespace( namespace ); + mountPointSchema.findModuleByNamespace( namespace ); return moduleSchemas == null ? null : this.filterLatestModule( moduleSchemas ); } public Module findModuleByNameAndRevision( final QName module ) { this.checkPreconditions(); Preconditions.checkArgument( module != null && module.getLocalName() != null && - module.getRevision() != null ); + module.getRevision() != null ); return globalSchema.findModuleByName( module.getLocalName(), module.getRevision() ); } @@ -247,11 +245,11 @@ public class ControllerContext implements SchemaContextListener { public Module findModuleByNameAndRevision( final MountInstance mountPoint, final QName module ) { this.checkPreconditions(); Preconditions.checkArgument( module != null && module.getLocalName() != null && - module.getRevision() != null && mountPoint != null ); + module.getRevision() != null && mountPoint != null ); SchemaContext schemaContext = mountPoint.getSchemaContext(); return schemaContext == null ? null : - schemaContext.findModuleByName( module.getLocalName(), module.getRevision() ); + schemaContext.findModuleByName( module.getLocalName(), module.getRevision() ); } public DataNodeContainer getDataNodeContainerFor( final InstanceIdentifier path ) { @@ -354,7 +352,7 @@ public class ControllerContext implements SchemaContextListener { String module = this.uriToModuleName.get( qname.getNamespace() ); if( module == null ) { final Module moduleSchema = globalSchema.findModuleByNamespaceAndRevision( - qname.getNamespace(), qname.getRevision() ); + qname.getNamespace(), qname.getRevision() ); if( moduleSchema == null ) { return null; } @@ -378,7 +376,7 @@ public class ControllerContext implements SchemaContextListener { SchemaContext schemaContext = mountPoint.getSchemaContext(); final Module moduleSchema = schemaContext.findModuleByNamespaceAndRevision( - qname.getNamespace(), qname.getRevision() ); + qname.getNamespace(), qname.getRevision() ); if( moduleSchema == null ) { return null; } @@ -406,7 +404,7 @@ public class ControllerContext implements SchemaContextListener { @Override public boolean apply(final GroupingDefinition g) { return Objects.equal(g.getQName().getLocalName(), - Draft02.RestConfModule.ERRORS_GROUPING_SCHEMA_NODE); + Draft02.RestConfModule.ERRORS_GROUPING_SCHEMA_NODE); } }; @@ -416,12 +414,12 @@ public class ControllerContext implements SchemaContextListener { List instanceDataChildrenByName = this.findInstanceDataChildrenByName(restconfGrouping, - Draft02.RestConfModule.ERRORS_CONTAINER_SCHEMA_NODE); + Draft02.RestConfModule.ERRORS_CONTAINER_SCHEMA_NODE); return Iterables.getFirst(instanceDataChildrenByName, null); } - public DataSchemaNode getRestconfModuleRestConfSchemaNode( Module inRestconfModule, - String schemaNodeName ) { + public DataSchemaNode getRestconfModuleRestConfSchemaNode( final Module inRestconfModule, + final String schemaNodeName ) { Module restconfModule = inRestconfModule; if( restconfModule == null ) { restconfModule = getRestconfModule(); @@ -437,7 +435,7 @@ public class ControllerContext implements SchemaContextListener { @Override public boolean apply(final GroupingDefinition g) { return Objects.equal(g.getQName().getLocalName(), - Draft02.RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE); + Draft02.RestConfModule.RESTCONF_GROUPING_SCHEMA_NODE); } }; @@ -447,49 +445,49 @@ public class ControllerContext implements SchemaContextListener { List instanceDataChildrenByName = this.findInstanceDataChildrenByName(restconfGrouping, - Draft02.RestConfModule.RESTCONF_CONTAINER_SCHEMA_NODE); + Draft02.RestConfModule.RESTCONF_CONTAINER_SCHEMA_NODE); final DataSchemaNode restconfContainer = Iterables.getFirst(instanceDataChildrenByName, null); if (Objects.equal(schemaNodeName, Draft02.RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE)) { List instances = this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer), - Draft02.RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE); + Draft02.RestConfModule.OPERATIONS_CONTAINER_SCHEMA_NODE); return Iterables.getFirst(instances, null); } else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE)) { List instances = this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer), - Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE); + Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE); return Iterables.getFirst(instances, null); } else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE)) { List instances = this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer), - Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE); + Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE); final DataSchemaNode modules = Iterables.getFirst(instances, null); instances = this.findInstanceDataChildrenByName(((DataNodeContainer) modules), - Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE); + Draft02.RestConfModule.STREAM_LIST_SCHEMA_NODE); return Iterables.getFirst(instances, null); } else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE)) { List instances = this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer), - Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE); + Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE); return Iterables.getFirst(instances, null); } else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE)) { List instances = this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer), - Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE); + Draft02.RestConfModule.MODULES_CONTAINER_SCHEMA_NODE); final DataSchemaNode modules = Iterables.getFirst(instances, null); instances = this.findInstanceDataChildrenByName(((DataNodeContainer) modules), - Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE); + Draft02.RestConfModule.MODULE_LIST_SCHEMA_NODE); return Iterables.getFirst(instances, null); } else if(Objects.equal(schemaNodeName, Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE)) { List instances = this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer), - Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE); + Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE); return Iterables.getFirst(instances, null); } @@ -545,7 +543,7 @@ public class ControllerContext implements SchemaContextListener { private String toUriString( final Object object ) throws UnsupportedEncodingException { return object == null ? "" : - URLEncoder.encode( object.toString(), ControllerContext.URI_ENCODING_CHAR_SET ); + URLEncoder.encode( object.toString(), ControllerContext.URI_ENCODING_CHAR_SET ); } private InstanceIdWithSchemaNode collectPathArguments( final InstanceIdentifierBuilder builder, @@ -559,7 +557,7 @@ public class ControllerContext implements SchemaContextListener { if( strings.isEmpty() ) { return new InstanceIdWithSchemaNode( builder.toInstance(), - ((DataSchemaNode) parentNode), mountPoint ); + ((DataSchemaNode) parentNode), mountPoint ); } String head = strings.iterator().next(); @@ -569,7 +567,7 @@ public class ControllerContext implements SchemaContextListener { DataSchemaNode targetNode = null; if( !Strings.isNullOrEmpty( moduleName ) ) { if( Objects.equal( moduleName, ControllerContext.MOUNT_MODULE ) && - Objects.equal( nodeName, ControllerContext.MOUNT_NODE ) ) { + Objects.equal( nodeName, ControllerContext.MOUNT_NODE ) ) { if( mountPoint != null ) { throw new RestconfDocumentedException( "Restconf supports just one mount point in URI.", @@ -587,7 +585,7 @@ public class ControllerContext implements SchemaContextListener { if( mount == null ) { LOG.debug( "Instance identifier to missing mount point: {}", partialPath ); throw new RestconfDocumentedException( - "Mount point does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT ); + "Mount point does not exist.", ErrorType.PROTOCOL, ErrorTag.UNKNOWN_ELEMENT ); } final SchemaContext mountPointSchema = mount.getSchemaContext(); @@ -610,12 +608,12 @@ public class ControllerContext implements SchemaContextListener { final String moduleNameBehindMountPoint = toModuleName( strings.get( 1 ) ); if( moduleNameBehindMountPoint == null ) { throw new RestconfDocumentedException( - "First node after mount point in URI has to be in format \"moduleName:nodeName\"", - ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE ); + "First node after mount point in URI has to be in format \"moduleName:nodeName\"", + ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE ); } final Module moduleBehindMountPoint = this.getLatestModule( mountPointSchema, - moduleNameBehindMountPoint ); + moduleNameBehindMountPoint ); if( moduleBehindMountPoint == null ) { throw new RestconfDocumentedException( "\"" +moduleName + "\" module does not exist in mount point.", @@ -624,7 +622,7 @@ public class ControllerContext implements SchemaContextListener { List subList = strings.subList( 1, strings.size() ); return this.collectPathArguments( InstanceIdentifier.builder(), subList, moduleBehindMountPoint, - mount, returnJustMountPoint ); + mount, returnJustMountPoint ); } Module module = null; @@ -639,7 +637,7 @@ public class ControllerContext implements SchemaContextListener { else { SchemaContext schemaContext = mountPoint.getSchemaContext(); module = schemaContext == null ? null : - this.getLatestModule( schemaContext, moduleName ); + this.getLatestModule( schemaContext, moduleName ); if( module == null ) { throw new RestconfDocumentedException( "\"" + moduleName + "\" module does not exist in mount point.", @@ -648,23 +646,23 @@ public class ControllerContext implements SchemaContextListener { } targetNode = this.findInstanceDataChildByNameAndNamespace( - parentNode, nodeName, module.getNamespace() ); + parentNode, nodeName, module.getNamespace() ); if( targetNode == null ) { throw new RestconfDocumentedException( "URI has bad format. Possible reasons:\n" + - " 1. \"" + head + "\" was not found in parent data node.\n" + - " 2. \"" + head + "\" is behind mount point. Then it should be in format \"/" + - MOUNT + "/" + head + "\".", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE ); + " 1. \"" + head + "\" was not found in parent data node.\n" + + " 2. \"" + head + "\" is behind mount point. Then it should be in format \"/" + + MOUNT + "/" + head + "\".", ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE ); } } else { final List potentialSchemaNodes = - this.findInstanceDataChildrenByName( parentNode, nodeName ); + this.findInstanceDataChildrenByName( parentNode, nodeName ); if( potentialSchemaNodes.size() > 1 ) { final StringBuilder strBuilder = new StringBuilder(); for( final DataSchemaNode potentialNodeSchema : potentialSchemaNodes ) { strBuilder.append( " " ) - .append( potentialNodeSchema.getQName().getNamespace() ) - .append( "\n" ); + .append( potentialNodeSchema.getQName().getNamespace() ) + .append( "\n" ); } throw new RestconfDocumentedException( @@ -714,7 +712,7 @@ public class ControllerContext implements SchemaContextListener { } this.addKeyValue( keyValues, listNode.getDataChildByName( key ), - uriKeyValue, mountPoint ); + uriKeyValue, mountPoint ); i++; } } @@ -729,7 +727,7 @@ public class ControllerContext implements SchemaContextListener { if( (targetNode instanceof DataNodeContainer) ) { final List remaining = strings.subList( consumed, strings.size() ); return this.collectPathArguments( builder, remaining, - ((DataNodeContainer) targetNode), mountPoint, returnJustMountPoint ); + ((DataNodeContainer) targetNode), mountPoint, returnJustMountPoint ); } return new InstanceIdWithSchemaNode( builder.toInstance(), targetNode, mountPoint ); @@ -743,7 +741,7 @@ public class ControllerContext implements SchemaContextListener { Predicate filter = new Predicate() { @Override - public boolean apply( DataSchemaNode node ) { + public boolean apply( final DataSchemaNode node ) { return Objects.equal( node.getQName().getNamespace(), namespace ); } }; @@ -753,7 +751,7 @@ public class ControllerContext implements SchemaContextListener { } public List findInstanceDataChildrenByName( final DataNodeContainer container, - final String name ) { + final String name ) { Preconditions. checkNotNull( container ); Preconditions. checkNotNull( name ); @@ -769,7 +767,7 @@ public class ControllerContext implements SchemaContextListener { Predicate filter = new Predicate() { @Override - public boolean apply( DataSchemaNode node ) { + public boolean apply( final DataSchemaNode node ) { return Objects.equal( node.getQName().getLocalName(), name ); } }; @@ -785,7 +783,7 @@ public class ControllerContext implements SchemaContextListener { } Iterable choiceNodes = Iterables. filter( container.getChildNodes(), - ChoiceNode.class ); + ChoiceNode.class ); final Function> choiceFunction = new Function>() { @@ -796,7 +794,7 @@ public class ControllerContext implements SchemaContextListener { }; Iterable> map = Iterables.> transform( - choiceNodes, choiceFunction ); + choiceNodes, choiceFunction ); final Iterable allCases = Iterables. concat( map ); for( final ChoiceCaseNode caze : allCases ) { @@ -806,11 +804,11 @@ public class ControllerContext implements SchemaContextListener { public boolean isInstantiatedDataSchema( final DataSchemaNode node ) { return node instanceof LeafSchemaNode || node instanceof LeafListSchemaNode || - node instanceof ContainerSchemaNode || node instanceof ListSchemaNode; + node instanceof ContainerSchemaNode || node instanceof ListSchemaNode; } private void addKeyValue( final HashMap map, final DataSchemaNode node, - final String uriValue, final MountInstance mountPoint ) { + final String uriValue, final MountInstance mountPoint ) { Preconditions. checkNotNull( uriValue ); Preconditions.checkArgument( (node instanceof LeafSchemaNode) ); @@ -830,8 +828,8 @@ public class ControllerContext implements SchemaContextListener { if( decoded == null ) { throw new RestconfDocumentedException( - uriValue + " from URI can't be resolved. " + additionalInfo, - ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE ); + uriValue + " from URI can't be resolved. " + additionalInfo, + ErrorType.PROTOCOL, ErrorTag.INVALID_VALUE ); } map.put( node.getQName(), decoded ); @@ -888,8 +886,8 @@ public class ControllerContext implements SchemaContextListener { }; Optional namespace = FluentIterable.from( sorted ) - .transform( transform ) - .firstMatch( findFirst ); + .transform( transform ) + .firstMatch( findFirst ); return namespace.isPresent() ? QName.create( namespace.get(), node ) : null; } @@ -948,7 +946,7 @@ public class ControllerContext implements SchemaContextListener { } private CharSequence convertToRestconfIdentifier( final PathArgument argument, - final DataNodeContainer node ) { + final DataNodeContainer node ) { if( argument instanceof NodeIdentifier && node instanceof ContainerSchemaNode ) { return convertToRestconfIdentifier( (NodeIdentifier) argument, (ContainerSchemaNode) node ); } @@ -957,7 +955,7 @@ public class ControllerContext implements SchemaContextListener { } else if( argument != null && node != null ) { throw new IllegalArgumentException( - "Conversion of generic path argument is not supported" ); + "Conversion of generic path argument is not supported" ); } else { throw new IllegalArgumentException( "Unhandled parameter types: " @@ -966,7 +964,7 @@ public class ControllerContext implements SchemaContextListener { } private CharSequence convertToRestconfIdentifier( final NodeIdentifier argument, - final ContainerSchemaNode node ) { + final ContainerSchemaNode node ) { StringBuilder builder = new StringBuilder(); builder.append( "/" ); QName nodeType = argument.getNodeType(); @@ -975,7 +973,7 @@ public class ControllerContext implements SchemaContextListener { } private CharSequence convertToRestconfIdentifier( final NodeIdentifierWithPredicates argument, - final ListSchemaNode node ) { + final ListSchemaNode node ) { QName nodeType = argument.getNodeType(); final CharSequence nodeIdentifier = this.toRestconfIdentifier( nodeType ); final Map keyValues = argument.getKeyValues(); diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/StructuredData.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/StructuredData.java index 8c344a79da..231fe7e02e 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/StructuredData.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/restconf/impl/StructuredData.java @@ -9,7 +9,7 @@ package org.opendaylight.controller.sal.restconf.impl; import org.opendaylight.controller.sal.core.api.mount.MountInstance; import org.opendaylight.yangtools.yang.data.api.CompositeNode; -import org.opendaylight.yangtools.yang.model.api.*; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; public class StructuredData { @@ -17,7 +17,7 @@ public class StructuredData { private final DataSchemaNode schema; private final MountInstance mountPoint; - public StructuredData(CompositeNode data, DataSchemaNode schema, MountInstance mountPoint) { + public StructuredData(final CompositeNode data, final DataSchemaNode schema, final MountInstance mountPoint) { this.data = data; this.schema = schema; this.mountPoint = mountPoint; diff --git a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/websockets/WebSocketServerInitializer.java b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/websockets/WebSocketServerInitializer.java index 983cd9bda9..d188a029e7 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/websockets/WebSocketServerInitializer.java +++ b/opendaylight/md-sal/sal-rest-connector/src/main/java/org/opendaylight/controller/sal/streams/websockets/WebSocketServerInitializer.java @@ -1,6 +1,5 @@ package org.opendaylight.controller.sal.streams.websockets; -import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; import io.netty.channel.socket.SocketChannel; @@ -9,13 +8,12 @@ import io.netty.handler.codec.http.HttpServerCodec; /** * {@link WebSocketServerInitializer} is used to setup the - * {@link ChannelPipeline} of a {@link Channel}. + * {@link ChannelPipeline} of a {@link io.netty.channel.Channel}. */ -public class WebSocketServerInitializer extends - ChannelInitializer { +public class WebSocketServerInitializer extends ChannelInitializer { @Override - protected void initChannel(SocketChannel ch) throws Exception { + protected void initChannel(final SocketChannel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); pipeline.addLast("codec-http", new HttpServerCodec()); pipeline.addLast("aggregator", new HttpObjectAggregator(65536)); diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyFuture.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyFuture.java index f6664ed34d..22b34a4420 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyFuture.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyFuture.java @@ -7,7 +7,10 @@ */ package org.opendaylight.controller.sal.restconf.impl.test; -import java.util.concurrent.*; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; import org.opendaylight.controller.md.sal.common.api.TransactionStatus; import org.opendaylight.yangtools.yang.common.RpcResult; @@ -26,7 +29,7 @@ public class DummyFuture implements Future> { result = null; } - private DummyFuture(Builder builder) { + private DummyFuture(final Builder builder) { cancel = builder.cancel; isCancelled = builder.isCancelled; isDone = builder.isDone; @@ -38,7 +41,7 @@ public class DummyFuture implements Future> { } @Override - public boolean cancel(boolean mayInterruptIfRunning) { + public boolean cancel(final boolean mayInterruptIfRunning) { return cancel; } @@ -58,8 +61,8 @@ public class DummyFuture implements Future> { } @Override - public RpcResult get(long timeout, TimeUnit unit) throws InterruptedException, - ExecutionException, TimeoutException { + public RpcResult get(final long timeout, final TimeUnit unit) throws InterruptedException, + ExecutionException, TimeoutException { return result; } @@ -70,22 +73,22 @@ public class DummyFuture implements Future> { private boolean isDone; private RpcResult result; - public Builder cancel(boolean cancel) { + public Builder cancel(final boolean cancel) { this.cancel = cancel; return this; } - public Builder isCancelled(boolean isCancelled) { + public Builder isCancelled(final boolean isCancelled) { this.isCancelled = isCancelled; return this; } - public Builder isDone(boolean isDone) { + public Builder isDone(final boolean isDone) { this.isDone = isDone; return this; } - public Builder rpcResult(RpcResult result) { + public Builder rpcResult(final RpcResult result) { this.result = result; return this; } diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyRpcResult.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyRpcResult.java index acc5c00935..16d14842db 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyRpcResult.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyRpcResult.java @@ -9,7 +9,8 @@ package org.opendaylight.controller.sal.restconf.impl.test; import java.util.Collection; -import org.opendaylight.yangtools.yang.common.*; +import org.opendaylight.yangtools.yang.common.RpcError; +import org.opendaylight.yangtools.yang.common.RpcResult; public class DummyRpcResult implements RpcResult { @@ -23,7 +24,7 @@ public class DummyRpcResult implements RpcResult { errors = null; } - private DummyRpcResult(Builder builder) { + private DummyRpcResult(final Builder builder) { isSuccessful = builder.isSuccessful; result = builder.result; errors = builder.errors; @@ -49,17 +50,17 @@ public class DummyRpcResult implements RpcResult { private T result; private Collection errors; - public Builder isSuccessful(boolean isSuccessful) { + public Builder isSuccessful(final boolean isSuccessful) { this.isSuccessful = isSuccessful; return this; } - public Builder result(T result) { + public Builder result(final T result) { this.result = result; return this; } - public Builder errors(Collection errors) { + public Builder errors(final Collection errors) { this.errors = errors; return this; } diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyType.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyType.java index 9caaf6b83a..d90e9539c8 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyType.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/DummyType.java @@ -10,7 +10,10 @@ package org.opendaylight.controller.sal.restconf.impl.test; import java.util.List; import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.*; +import org.opendaylight.yangtools.yang.model.api.SchemaPath; +import org.opendaylight.yangtools.yang.model.api.Status; +import org.opendaylight.yangtools.yang.model.api.TypeDefinition; +import org.opendaylight.yangtools.yang.model.api.UnknownSchemaNode; public class DummyType implements TypeDefinition { QName dummyQName = TestUtils.buildQName("dummy type", "simple:uri", "2012-12-17"); diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/NormalizeNodeTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/NormalizeNodeTest.java index f5aa453fa2..158569af73 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/NormalizeNodeTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/NormalizeNodeTest.java @@ -7,7 +7,7 @@ */ package org.opendaylight.controller.sal.restconf.impl.test; -import static org.junit.Assert.*; +import static org.junit.Assert.assertNotNull; import java.net.URI; import java.net.URISyntaxException; @@ -50,7 +50,7 @@ public class NormalizeNodeTest extends YangAndXmlAndDataSchemaLoader { TestUtils.normalizeCompositeNode(prepareCnSn("normalize-node-module"), modules, schemaNodePath); } - private CompositeNode prepareCnSn(String namespace) { + private CompositeNode prepareCnSn(final String namespace) { URI uri = null; if (namespace != null) { try { diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java index fc5d7be724..3f984c293b 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/RestconfDocumentedExceptionMapperTest.java @@ -8,9 +8,15 @@ package org.opendaylight.controller.sal.restconf.impl.test; -import static org.junit.Assert.*; -import static org.mockito.Matchers.*; -import static org.mockito.Mockito.*; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; +import static org.mockito.Matchers.any; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.reset; +import static org.mockito.Mockito.when; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -21,8 +27,8 @@ import java.util.Arrays; import java.util.Iterator; import java.util.List; import java.util.Map; -import java.util.Set; import java.util.Map.Entry; +import java.util.Set; import javax.ws.rs.core.Application; import javax.ws.rs.core.MediaType; @@ -48,9 +54,9 @@ import org.opendaylight.controller.sal.rest.impl.StructuredDataToXmlProvider; import org.opendaylight.controller.sal.restconf.impl.ControllerContext; import org.opendaylight.controller.sal.restconf.impl.RestconfDocumentedException; import org.opendaylight.controller.sal.restconf.impl.RestconfError; -import org.opendaylight.controller.sal.restconf.impl.StructuredData; import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorTag; import org.opendaylight.controller.sal.restconf.impl.RestconfError.ErrorType; +import org.opendaylight.controller.sal.restconf.impl.StructuredData; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.Node; @@ -79,12 +85,12 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { Map expErrorInfo; - public ComplexErrorInfoVerifier( Map expErrorInfo ) { + public ComplexErrorInfoVerifier( final Map expErrorInfo ) { this.expErrorInfo = expErrorInfo; } @Override - public void verifyXML( Node errorInfoNode ) { + public void verifyXML( final Node errorInfoNode ) { Map mutableExpMap = Maps.newHashMap( expErrorInfo ); NodeList childNodes = errorInfoNode.getChildNodes(); @@ -93,9 +99,9 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { if( child instanceof Element ) { String expValue = mutableExpMap.remove( child.getNodeName() ); assertNotNull( "Found unexpected \"error-info\" child node: " + - child.getNodeName(), expValue ); + child.getNodeName(), expValue ); assertEquals( "Text content for \"error-info\" child node " + - child.getNodeName(), expValue, child.getTextContent() ); + child.getNodeName(), expValue, child.getTextContent() ); } } @@ -105,7 +111,7 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { } @Override - public void verifyJson( JsonElement errorInfoElement ) { + public void verifyJson( final JsonElement errorInfoElement ) { assertTrue( "\"error-info\" Json element is not an Object", errorInfoElement.isJsonObject() ); @@ -121,9 +127,9 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { for( Entry actual: actualErrorInfo.entrySet() ) { String expValue = mutableExpMap.remove( actual.getKey() ); assertNotNull( "Found unexpected \"error-info\" child node: " + - actual.getKey(), expValue ); + actual.getKey(), expValue ); assertEquals( "Text content for \"error-info\" child node " + - actual.getKey(), expValue, actual.getValue() ); + actual.getKey(), expValue, actual.getValue() ); } if( !mutableExpMap.isEmpty() ) { @@ -136,22 +142,22 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { String expTextContent; - public SimpleErrorInfoVerifier( String expErrorInfo ) { + public SimpleErrorInfoVerifier( final String expErrorInfo ) { this.expTextContent = expErrorInfo; } - void verifyContent( String actualContent ) { + void verifyContent( final String actualContent ) { assertNotNull( "Actual \"error-info\" text content is null", actualContent ); assertTrue( "", actualContent.contains( expTextContent ) ); } @Override - public void verifyXML( Node errorInfoNode ) { + public void verifyXML( final Node errorInfoNode ) { verifyContent( errorInfoNode.getTextContent() ); } @Override - public void verifyJson( JsonElement errorInfoElement ) { + public void verifyJson( final JsonElement errorInfoElement ) { verifyContent( errorInfoElement.getAsString() ); } } @@ -172,17 +178,17 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { NamespaceContext nsContext = new NamespaceContext() { @Override - public Iterator getPrefixes( String namespaceURI ) { + public Iterator getPrefixes( final String namespaceURI ) { return null; } @Override - public String getPrefix( String namespaceURI ) { + public String getPrefix( final String namespaceURI ) { return null; } @Override - public String getNamespaceURI( String prefix ) { + public String getNamespaceURI( final String prefix ) { return "ietf-restconf".equals( prefix ) ? Draft02.RestConfModule.NAMESPACE : null; } }; @@ -207,19 +213,19 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { protected Application configure() { ResourceConfig resourceConfig = new ResourceConfig(); resourceConfig = resourceConfig.registerInstances( mockRestConf, StructuredDataToXmlProvider.INSTANCE, - StructuredDataToJsonProvider.INSTANCE ); + StructuredDataToJsonProvider.INSTANCE ); resourceConfig.registerClasses( RestconfDocumentedExceptionMapper.class ); return resourceConfig; } - void stageMockEx( RestconfDocumentedException ex ) { + void stageMockEx( final RestconfDocumentedException ex ) { reset( mockRestConf ); when( mockRestConf.readOperationalData( any( String.class ) ) ).thenThrow( ex ); } - void testJsonResponse( RestconfDocumentedException ex, Status expStatus, ErrorType expErrorType, - ErrorTag expErrorTag, String expErrorMessage, String expErrorAppTag, - ErrorInfoVerifier errorInfoVerifier ) throws Exception { + void testJsonResponse( final RestconfDocumentedException ex, final Status expStatus, final ErrorType expErrorType, + final ErrorTag expErrorTag, final String expErrorMessage, final String expErrorAppTag, + final ErrorInfoVerifier errorInfoVerifier ) throws Exception { stageMockEx( ex ); @@ -228,51 +234,51 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { InputStream stream = verifyResponse( resp, MediaType.APPLICATION_JSON, expStatus ); verifyJsonResponseBody( stream, expErrorType, expErrorTag, expErrorMessage, - expErrorAppTag, errorInfoVerifier ); + expErrorAppTag, errorInfoVerifier ); } @Test public void testToJsonResponseWithMessageOnly() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error" ), Status.INTERNAL_SERVER_ERROR, - ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "mock error", null, null ); + ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "mock error", null, null ); // To test verification code -// String json = -// "{ errors: {" + -// " error: [{" + -// " error-tag : \"operation-failed\"" + -// " ,error-type : \"application\"" + -// " ,error-message : \"An error occurred\"" + -// " ,error-info : {" + -// " session-id: \"123\"" + -// " ,address: \"1.2.3.4\"" + -// " }" + -// " }]" + -// " }" + -// "}"; -// -// verifyJsonResponseBody( new java.io.StringBufferInputStream(json ), ErrorType.APPLICATION, -// ErrorTag.OPERATION_FAILED, "An error occurred", null, -// com.google.common.collect.ImmutableMap.of( "session-id", "123", "address", "1.2.3.4" ) ); + // String json = + // "{ errors: {" + + // " error: [{" + + // " error-tag : \"operation-failed\"" + + // " ,error-type : \"application\"" + + // " ,error-message : \"An error occurred\"" + + // " ,error-info : {" + + // " session-id: \"123\"" + + // " ,address: \"1.2.3.4\"" + + // " }" + + // " }]" + + // " }" + + // "}"; + // + // verifyJsonResponseBody( new java.io.StringBufferInputStream(json ), ErrorType.APPLICATION, + // ErrorTag.OPERATION_FAILED, "An error occurred", null, + // com.google.common.collect.ImmutableMap.of( "session-id", "123", "address", "1.2.3.4" ) ); } @Test public void testToJsonResponseWithInUseErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.IN_USE ), - Status.CONFLICT, ErrorType.PROTOCOL, - ErrorTag.IN_USE, "mock error", null, null ); + ErrorTag.IN_USE ), + Status.CONFLICT, ErrorType.PROTOCOL, + ErrorTag.IN_USE, "mock error", null, null ); } @Test public void testToJsonResponseWithInvalidValueErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.RPC, - ErrorTag.INVALID_VALUE ), - Status.BAD_REQUEST, ErrorType.RPC, - ErrorTag.INVALID_VALUE, "mock error", null, null ); + ErrorTag.INVALID_VALUE ), + Status.BAD_REQUEST, ErrorType.RPC, + ErrorTag.INVALID_VALUE, "mock error", null, null ); } @@ -280,9 +286,9 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { public void testToJsonResponseWithTooBigErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.TRANSPORT, - ErrorTag.TOO_BIG ), - Status.REQUEST_ENTITY_TOO_LARGE, ErrorType.TRANSPORT, - ErrorTag.TOO_BIG, "mock error", null, null ); + ErrorTag.TOO_BIG ), + Status.REQUEST_ENTITY_TOO_LARGE, ErrorType.TRANSPORT, + ErrorTag.TOO_BIG, "mock error", null, null ); } @@ -290,153 +296,153 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { public void testToJsonResponseWithMissingAttributeErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.MISSING_ATTRIBUTE ), - Status.BAD_REQUEST, ErrorType.PROTOCOL, - ErrorTag.MISSING_ATTRIBUTE, "mock error", null, null ); + ErrorTag.MISSING_ATTRIBUTE ), + Status.BAD_REQUEST, ErrorType.PROTOCOL, + ErrorTag.MISSING_ATTRIBUTE, "mock error", null, null ); } @Test public void testToJsonResponseWithBadAttributeErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.BAD_ATTRIBUTE ), - Status.BAD_REQUEST, ErrorType.PROTOCOL, - ErrorTag.BAD_ATTRIBUTE, "mock error", null, null ); + ErrorTag.BAD_ATTRIBUTE ), + Status.BAD_REQUEST, ErrorType.PROTOCOL, + ErrorTag.BAD_ATTRIBUTE, "mock error", null, null ); } @Test public void testToJsonResponseWithUnknownAttributeErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.UNKNOWN_ATTRIBUTE ), - Status.BAD_REQUEST, ErrorType.PROTOCOL, - ErrorTag.UNKNOWN_ATTRIBUTE, "mock error", null, null ); + ErrorTag.UNKNOWN_ATTRIBUTE ), + Status.BAD_REQUEST, ErrorType.PROTOCOL, + ErrorTag.UNKNOWN_ATTRIBUTE, "mock error", null, null ); } @Test public void testToJsonResponseWithBadElementErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.BAD_ELEMENT ), - Status.BAD_REQUEST, - ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT, "mock error", null, null ); + ErrorTag.BAD_ELEMENT ), + Status.BAD_REQUEST, + ErrorType.PROTOCOL, ErrorTag.BAD_ELEMENT, "mock error", null, null ); } @Test public void testToJsonResponseWithUnknownElementErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.UNKNOWN_ELEMENT ), - Status.BAD_REQUEST, ErrorType.PROTOCOL, - ErrorTag.UNKNOWN_ELEMENT, "mock error", null, null ); + ErrorTag.UNKNOWN_ELEMENT ), + Status.BAD_REQUEST, ErrorType.PROTOCOL, + ErrorTag.UNKNOWN_ELEMENT, "mock error", null, null ); } @Test public void testToJsonResponseWithUnknownNamespaceErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.UNKNOWN_NAMESPACE ), - Status.BAD_REQUEST, ErrorType.PROTOCOL, - ErrorTag.UNKNOWN_NAMESPACE, "mock error", null, null ); + ErrorTag.UNKNOWN_NAMESPACE ), + Status.BAD_REQUEST, ErrorType.PROTOCOL, + ErrorTag.UNKNOWN_NAMESPACE, "mock error", null, null ); } @Test public void testToJsonResponseWithMalformedMessageErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.MALFORMED_MESSAGE ), - Status.BAD_REQUEST, ErrorType.PROTOCOL, - ErrorTag.MALFORMED_MESSAGE, "mock error", null, null ); + ErrorTag.MALFORMED_MESSAGE ), + Status.BAD_REQUEST, ErrorType.PROTOCOL, + ErrorTag.MALFORMED_MESSAGE, "mock error", null, null ); } @Test public void testToJsonResponseWithAccessDeniedErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.ACCESS_DENIED ), - Status.FORBIDDEN, ErrorType.PROTOCOL, - ErrorTag.ACCESS_DENIED, "mock error", null, null ); + ErrorTag.ACCESS_DENIED ), + Status.FORBIDDEN, ErrorType.PROTOCOL, + ErrorTag.ACCESS_DENIED, "mock error", null, null ); } @Test public void testToJsonResponseWithLockDeniedErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.LOCK_DENIED ), - Status.CONFLICT, ErrorType.PROTOCOL, - ErrorTag.LOCK_DENIED, "mock error", null, null ); + ErrorTag.LOCK_DENIED ), + Status.CONFLICT, ErrorType.PROTOCOL, + ErrorTag.LOCK_DENIED, "mock error", null, null ); } @Test public void testToJsonResponseWithResourceDeniedErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.RESOURCE_DENIED ), - Status.CONFLICT, ErrorType.PROTOCOL, - ErrorTag.RESOURCE_DENIED, "mock error", null, null ); + ErrorTag.RESOURCE_DENIED ), + Status.CONFLICT, ErrorType.PROTOCOL, + ErrorTag.RESOURCE_DENIED, "mock error", null, null ); } @Test public void testToJsonResponseWithRollbackFailedErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.ROLLBACK_FAILED ), - Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL, - ErrorTag.ROLLBACK_FAILED, "mock error", null, null ); + ErrorTag.ROLLBACK_FAILED ), + Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL, + ErrorTag.ROLLBACK_FAILED, "mock error", null, null ); } @Test public void testToJsonResponseWithDataExistsErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.DATA_EXISTS ), - Status.CONFLICT, ErrorType.PROTOCOL, - ErrorTag.DATA_EXISTS, "mock error", null, null ); + ErrorTag.DATA_EXISTS ), + Status.CONFLICT, ErrorType.PROTOCOL, + ErrorTag.DATA_EXISTS, "mock error", null, null ); } @Test public void testToJsonResponseWithDataMissingErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.DATA_MISSING ), - Status.CONFLICT, ErrorType.PROTOCOL, - ErrorTag.DATA_MISSING, "mock error", null, null ); + ErrorTag.DATA_MISSING ), + Status.CONFLICT, ErrorType.PROTOCOL, + ErrorTag.DATA_MISSING, "mock error", null, null ); } @Test public void testToJsonResponseWithOperationNotSupportedErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.OPERATION_NOT_SUPPORTED ), - Status.NOT_IMPLEMENTED, ErrorType.PROTOCOL, - ErrorTag.OPERATION_NOT_SUPPORTED, "mock error", null, null ); + ErrorTag.OPERATION_NOT_SUPPORTED ), + Status.NOT_IMPLEMENTED, ErrorType.PROTOCOL, + ErrorTag.OPERATION_NOT_SUPPORTED, "mock error", null, null ); } @Test public void testToJsonResponseWithOperationFailedErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.OPERATION_FAILED ), - Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL, - ErrorTag.OPERATION_FAILED, "mock error", null, null ); + ErrorTag.OPERATION_FAILED ), + Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL, + ErrorTag.OPERATION_FAILED, "mock error", null, null ); } @Test public void testToJsonResponseWithPartialOperationErrorTag() throws Exception { testJsonResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.PARTIAL_OPERATION ), - Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL, - ErrorTag.PARTIAL_OPERATION, "mock error", null, null ); + ErrorTag.PARTIAL_OPERATION ), + Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL, + ErrorTag.PARTIAL_OPERATION, "mock error", null, null ); } @Test public void testToJsonResponseWithErrorAppTag() throws Exception { testJsonResponse( new RestconfDocumentedException( new RestconfError( - ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, - "mock error", "mock-app-tag" ) ), - Status.BAD_REQUEST, ErrorType.APPLICATION, - ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", null ); + ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, + "mock error", "mock-app-tag" ) ), + Status.BAD_REQUEST, ErrorType.APPLICATION, + ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", null ); } @Test @@ -456,10 +462,10 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { assertEquals( "\"error\" Json array element length", 2, arrayElement.size() ); verifyJsonErrorNode( arrayElement.get( 0 ), ErrorType.APPLICATION, ErrorTag.LOCK_DENIED, - "mock error1", null, null ); + "mock error1", null, null ); verifyJsonErrorNode( arrayElement.get( 1 ), ErrorType.RPC, ErrorTag.ROLLBACK_FAILED, - "mock error2", null, null ); + "mock error2", null, null ); } @Test @@ -467,12 +473,12 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { String errorInfo = "
1.2.3.4
123"; testJsonResponse( new RestconfDocumentedException( new RestconfError( - ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, - "mock error", "mock-app-tag", errorInfo ) ), - Status.BAD_REQUEST, ErrorType.APPLICATION, - ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", - new ComplexErrorInfoVerifier( ImmutableMap.of( - "session-id", "123", "address", "1.2.3.4" ) ) ); + ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, + "mock error", "mock-app-tag", errorInfo ) ), + Status.BAD_REQUEST, ErrorType.APPLICATION, + ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", + new ComplexErrorInfoVerifier( ImmutableMap.of( + "session-id", "123", "address", "1.2.3.4" ) ) ); } @Test @@ -480,14 +486,14 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { Exception cause = new Exception( "mock exception cause" ); testJsonResponse( new RestconfDocumentedException( "mock error", cause ), - Status.INTERNAL_SERVER_ERROR, ErrorType.APPLICATION, - ErrorTag.OPERATION_FAILED, "mock error", null, - new SimpleErrorInfoVerifier( cause.getMessage() ) ); + Status.INTERNAL_SERVER_ERROR, ErrorType.APPLICATION, + ErrorTag.OPERATION_FAILED, "mock error", null, + new SimpleErrorInfoVerifier( cause.getMessage() ) ); } - void testXMLResponse( RestconfDocumentedException ex, Status expStatus, ErrorType expErrorType, - ErrorTag expErrorTag, String expErrorMessage, - String expErrorAppTag, ErrorInfoVerifier errorInfoVerifier ) throws Exception + void testXMLResponse( final RestconfDocumentedException ex, final Status expStatus, final ErrorType expErrorType, + final ErrorTag expErrorTag, final String expErrorMessage, + final String expErrorAppTag, final ErrorInfoVerifier errorInfoVerifier ) throws Exception { stageMockEx( ex ); @@ -496,212 +502,212 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { InputStream stream = verifyResponse( resp, MediaType.APPLICATION_XML, expStatus ); verifyXMLResponseBody( stream, expErrorType, expErrorTag, expErrorMessage, - expErrorAppTag, errorInfoVerifier ); + expErrorAppTag, errorInfoVerifier ); } @Test public void testToXMLResponseWithMessageOnly() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error" ), Status.INTERNAL_SERVER_ERROR, - ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "mock error", null, null ); + ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "mock error", null, null ); // To test verification code -// String xml = -// ""+ -// " " + -// " application"+ -// " operation-failed"+ -// " An error occurred"+ -// " " + -// " 123" + -// "
1.2.3.4
" + -// "
" + -// "
" + -// "
"; -// -// verifyXMLResponseBody( new java.io.StringBufferInputStream(xml), ErrorType.APPLICATION, -// ErrorTag.OPERATION_FAILED, "An error occurred", null, -// com.google.common.collect.ImmutableMap.of( "session-id", "123", "address", "1.2.3.4" ) ); + // String xml = + // ""+ + // " " + + // " application"+ + // " operation-failed"+ + // " An error occurred"+ + // " " + + // " 123" + + // "
1.2.3.4
" + + // "
" + + // "
" + + // "
"; + // + // verifyXMLResponseBody( new java.io.StringBufferInputStream(xml), ErrorType.APPLICATION, + // ErrorTag.OPERATION_FAILED, "An error occurred", null, + // com.google.common.collect.ImmutableMap.of( "session-id", "123", "address", "1.2.3.4" ) ); } @Test public void testToXMLResponseWithInUseErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.IN_USE ), - Status.CONFLICT, ErrorType.PROTOCOL, - ErrorTag.IN_USE, "mock error", null, null ); + ErrorTag.IN_USE ), + Status.CONFLICT, ErrorType.PROTOCOL, + ErrorTag.IN_USE, "mock error", null, null ); } @Test public void testToXMLResponseWithInvalidValueErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.RPC, - ErrorTag.INVALID_VALUE ), - Status.BAD_REQUEST, ErrorType.RPC, - ErrorTag.INVALID_VALUE, "mock error", null, null ); + ErrorTag.INVALID_VALUE ), + Status.BAD_REQUEST, ErrorType.RPC, + ErrorTag.INVALID_VALUE, "mock error", null, null ); } @Test public void testToXMLResponseWithTooBigErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.TRANSPORT, - ErrorTag.TOO_BIG ), - Status.REQUEST_ENTITY_TOO_LARGE, ErrorType.TRANSPORT, - ErrorTag.TOO_BIG, "mock error", null, null ); + ErrorTag.TOO_BIG ), + Status.REQUEST_ENTITY_TOO_LARGE, ErrorType.TRANSPORT, + ErrorTag.TOO_BIG, "mock error", null, null ); } @Test public void testToXMLResponseWithMissingAttributeErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.MISSING_ATTRIBUTE ), - Status.BAD_REQUEST, ErrorType.PROTOCOL, - ErrorTag.MISSING_ATTRIBUTE, "mock error", null, null ); + ErrorTag.MISSING_ATTRIBUTE ), + Status.BAD_REQUEST, ErrorType.PROTOCOL, + ErrorTag.MISSING_ATTRIBUTE, "mock error", null, null ); } @Test public void testToXMLResponseWithBadAttributeErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.BAD_ATTRIBUTE ), - Status.BAD_REQUEST, ErrorType.PROTOCOL, - ErrorTag.BAD_ATTRIBUTE, "mock error", null, null ); + ErrorTag.BAD_ATTRIBUTE ), + Status.BAD_REQUEST, ErrorType.PROTOCOL, + ErrorTag.BAD_ATTRIBUTE, "mock error", null, null ); } @Test public void testToXMLResponseWithUnknownAttributeErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.UNKNOWN_ATTRIBUTE ), - Status.BAD_REQUEST, ErrorType.PROTOCOL, - ErrorTag.UNKNOWN_ATTRIBUTE, "mock error", null, null ); + ErrorTag.UNKNOWN_ATTRIBUTE ), + Status.BAD_REQUEST, ErrorType.PROTOCOL, + ErrorTag.UNKNOWN_ATTRIBUTE, "mock error", null, null ); } @Test public void testToXMLResponseWithBadElementErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.BAD_ELEMENT ), - Status.BAD_REQUEST, ErrorType.PROTOCOL, - ErrorTag.BAD_ELEMENT, "mock error", null, null ); + ErrorTag.BAD_ELEMENT ), + Status.BAD_REQUEST, ErrorType.PROTOCOL, + ErrorTag.BAD_ELEMENT, "mock error", null, null ); } @Test public void testToXMLResponseWithUnknownElementErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.UNKNOWN_ELEMENT ), - Status.BAD_REQUEST, ErrorType.PROTOCOL, - ErrorTag.UNKNOWN_ELEMENT, "mock error", null, null ); + ErrorTag.UNKNOWN_ELEMENT ), + Status.BAD_REQUEST, ErrorType.PROTOCOL, + ErrorTag.UNKNOWN_ELEMENT, "mock error", null, null ); } @Test public void testToXMLResponseWithUnknownNamespaceErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.UNKNOWN_NAMESPACE ), - Status.BAD_REQUEST, ErrorType.PROTOCOL, - ErrorTag.UNKNOWN_NAMESPACE, "mock error", null, null ); + ErrorTag.UNKNOWN_NAMESPACE ), + Status.BAD_REQUEST, ErrorType.PROTOCOL, + ErrorTag.UNKNOWN_NAMESPACE, "mock error", null, null ); } @Test public void testToXMLResponseWithMalformedMessageErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.MALFORMED_MESSAGE ), - Status.BAD_REQUEST, ErrorType.PROTOCOL, - ErrorTag.MALFORMED_MESSAGE, "mock error", null, null ); + ErrorTag.MALFORMED_MESSAGE ), + Status.BAD_REQUEST, ErrorType.PROTOCOL, + ErrorTag.MALFORMED_MESSAGE, "mock error", null, null ); } @Test public void testToXMLResponseWithAccessDeniedErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.ACCESS_DENIED ), - Status.FORBIDDEN, ErrorType.PROTOCOL, - ErrorTag.ACCESS_DENIED, "mock error", null, null ); + ErrorTag.ACCESS_DENIED ), + Status.FORBIDDEN, ErrorType.PROTOCOL, + ErrorTag.ACCESS_DENIED, "mock error", null, null ); } @Test public void testToXMLResponseWithLockDeniedErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.LOCK_DENIED ), - Status.CONFLICT, ErrorType.PROTOCOL, - ErrorTag.LOCK_DENIED, "mock error", null, null ); + ErrorTag.LOCK_DENIED ), + Status.CONFLICT, ErrorType.PROTOCOL, + ErrorTag.LOCK_DENIED, "mock error", null, null ); } @Test public void testToXMLResponseWithResourceDeniedErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.RESOURCE_DENIED ), - Status.CONFLICT, ErrorType.PROTOCOL, - ErrorTag.RESOURCE_DENIED, "mock error", null, null ); + ErrorTag.RESOURCE_DENIED ), + Status.CONFLICT, ErrorType.PROTOCOL, + ErrorTag.RESOURCE_DENIED, "mock error", null, null ); } @Test public void testToXMLResponseWithRollbackFailedErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.ROLLBACK_FAILED ), - Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL, - ErrorTag.ROLLBACK_FAILED, "mock error", null, null ); + ErrorTag.ROLLBACK_FAILED ), + Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL, + ErrorTag.ROLLBACK_FAILED, "mock error", null, null ); } @Test public void testToXMLResponseWithDataExistsErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.DATA_EXISTS ), - Status.CONFLICT, ErrorType.PROTOCOL, - ErrorTag.DATA_EXISTS, "mock error", null, null ); + ErrorTag.DATA_EXISTS ), + Status.CONFLICT, ErrorType.PROTOCOL, + ErrorTag.DATA_EXISTS, "mock error", null, null ); } @Test public void testToXMLResponseWithDataMissingErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.DATA_MISSING ), - Status.CONFLICT, ErrorType.PROTOCOL, - ErrorTag.DATA_MISSING, "mock error", null, null ); + ErrorTag.DATA_MISSING ), + Status.CONFLICT, ErrorType.PROTOCOL, + ErrorTag.DATA_MISSING, "mock error", null, null ); } @Test public void testToXMLResponseWithOperationNotSupportedErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.OPERATION_NOT_SUPPORTED ), - Status.NOT_IMPLEMENTED, ErrorType.PROTOCOL, - ErrorTag.OPERATION_NOT_SUPPORTED, "mock error", null, null ); + ErrorTag.OPERATION_NOT_SUPPORTED ), + Status.NOT_IMPLEMENTED, ErrorType.PROTOCOL, + ErrorTag.OPERATION_NOT_SUPPORTED, "mock error", null, null ); } @Test public void testToXMLResponseWithOperationFailedErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.OPERATION_FAILED ), - Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL, - ErrorTag.OPERATION_FAILED, "mock error", null, null ); + ErrorTag.OPERATION_FAILED ), + Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL, + ErrorTag.OPERATION_FAILED, "mock error", null, null ); } @Test public void testToXMLResponseWithPartialOperationErrorTag() throws Exception { testXMLResponse( new RestconfDocumentedException( "mock error", ErrorType.PROTOCOL, - ErrorTag.PARTIAL_OPERATION ), - Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL, - ErrorTag.PARTIAL_OPERATION, "mock error", null, null ); + ErrorTag.PARTIAL_OPERATION ), + Status.INTERNAL_SERVER_ERROR, ErrorType.PROTOCOL, + ErrorTag.PARTIAL_OPERATION, "mock error", null, null ); } @Test public void testToXMLResponseWithErrorAppTag() throws Exception { testXMLResponse( new RestconfDocumentedException( new RestconfError( - ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, - "mock error", "mock-app-tag" ) ), - Status.BAD_REQUEST, ErrorType.APPLICATION, - ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", null ); + ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, + "mock error", "mock-app-tag" ) ), + Status.BAD_REQUEST, ErrorType.APPLICATION, + ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", null ); } @Test @@ -709,12 +715,12 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { String errorInfo = "
1.2.3.4
123"; testXMLResponse( new RestconfDocumentedException( new RestconfError( - ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, - "mock error", "mock-app-tag", errorInfo ) ), - Status.BAD_REQUEST, ErrorType.APPLICATION, - ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", - new ComplexErrorInfoVerifier( ImmutableMap.of( - "session-id", "123", "address", "1.2.3.4" ) ) ); + ErrorType.APPLICATION, ErrorTag.INVALID_VALUE, + "mock error", "mock-app-tag", errorInfo ) ), + Status.BAD_REQUEST, ErrorType.APPLICATION, + ErrorTag.INVALID_VALUE, "mock error", "mock-app-tag", + new ComplexErrorInfoVerifier( ImmutableMap.of( + "session-id", "123", "address", "1.2.3.4" ) ) ); } @Test @@ -722,9 +728,9 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { Exception cause = new Exception( "mock exception cause" ); testXMLResponse( new RestconfDocumentedException( "mock error", cause ), - Status.INTERNAL_SERVER_ERROR, ErrorType.APPLICATION, - ErrorTag.OPERATION_FAILED, "mock error", null, - new SimpleErrorInfoVerifier( cause.getMessage() ) ); + Status.INTERNAL_SERVER_ERROR, ErrorType.APPLICATION, + ErrorTag.OPERATION_FAILED, "mock error", null, + new SimpleErrorInfoVerifier( cause.getMessage() ) ); } @Test @@ -744,10 +750,10 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { NodeList children = getXMLErrorList( doc, 2 ); verifyXMLErrorNode( children.item( 0 ), ErrorType.APPLICATION, ErrorTag.LOCK_DENIED, - "mock error1", null, null ); + "mock error1", null, null ); verifyXMLErrorNode( children.item( 1 ), ErrorType.RPC, ErrorTag.ROLLBACK_FAILED, - "mock error2", null, null ); + "mock error2", null, null ); } @Test @@ -756,13 +762,13 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { stageMockEx( new RestconfDocumentedException( "mock error" ) ); Response resp = target("/operational/foo") - .request().header( "Accept", MediaType.APPLICATION_JSON ).get(); + .request().header( "Accept", MediaType.APPLICATION_JSON ).get(); InputStream stream = verifyResponse( resp, MediaType.APPLICATION_JSON, - Status.INTERNAL_SERVER_ERROR ); + Status.INTERNAL_SERVER_ERROR ); verifyJsonResponseBody( stream, ErrorType.APPLICATION, ErrorTag.OPERATION_FAILED, "mock error", - null, null ); + null, null ); } @Test @@ -771,14 +777,14 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { // The StructuredDataToJsonProvider should throw a RestconfDocumentedException with no data when( mockRestConf.readOperationalData( any( String.class ) ) ) - .thenReturn( new StructuredData( null, null, null ) ); + .thenReturn( new StructuredData( null, null, null ) ); Response resp = target("/operational/foo").request( MediaType.APPLICATION_JSON ).get(); verifyResponse( resp, MediaType.TEXT_PLAIN, Status.NOT_FOUND ); } - InputStream verifyResponse( Response resp, String expMediaType, Status expStatus ) { + InputStream verifyResponse( final Response resp, final String expMediaType, final Status expStatus ) { assertEquals( "getMediaType", MediaType.valueOf( expMediaType ), resp.getMediaType() ); assertEquals( "getStatus", expStatus.getStatusCode(), resp.getStatus() ); @@ -788,19 +794,19 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { return stream; } - void verifyJsonResponseBody( InputStream stream, ErrorType expErrorType, ErrorTag expErrorTag, - String expErrorMessage, String expErrorAppTag, - ErrorInfoVerifier errorInfoVerifier ) throws Exception { + void verifyJsonResponseBody( final InputStream stream, final ErrorType expErrorType, final ErrorTag expErrorTag, + final String expErrorMessage, final String expErrorAppTag, + final ErrorInfoVerifier errorInfoVerifier ) throws Exception { JsonArray arrayElement = parseJsonErrorArrayElement( stream ); assertEquals( "\"error\" Json array element length", 1, arrayElement.size() ); verifyJsonErrorNode( arrayElement.get( 0 ), expErrorType, expErrorTag, expErrorMessage, - expErrorAppTag, errorInfoVerifier ); + expErrorAppTag, errorInfoVerifier ); } - private JsonArray parseJsonErrorArrayElement( InputStream stream ) throws IOException { + private JsonArray parseJsonErrorArrayElement( final InputStream stream ) throws IOException { ByteArrayOutputStream bos = new ByteArrayOutputStream(); ByteStreams.copy( stream, bos ); @@ -811,7 +817,7 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { try { rootElement = parser.parse( - new InputStreamReader( new ByteArrayInputStream( bos.toByteArray() ) ) ); + new InputStreamReader( new ByteArrayInputStream( bos.toByteArray() ) ) ); } catch( Exception e ) { throw new IllegalArgumentException( "Invalid JSON response:\n" + bos.toString(), e ); @@ -832,15 +838,15 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { JsonElement errorListElement = errorListEntrySet.iterator().next().getValue(); assertEquals( "\"errors\" child Json element name", "error", - errorListEntrySet.iterator().next().getKey() ); + errorListEntrySet.iterator().next().getKey() ); assertTrue( "\"error\" Json element is not an Array", errorListElement.isJsonArray() ); return errorListElement.getAsJsonArray(); } - void verifyJsonErrorNode( JsonElement errorEntryElement, ErrorType expErrorType, ErrorTag expErrorTag, - String expErrorMessage, String expErrorAppTag, - ErrorInfoVerifier errorInfoVerifier ) { + void verifyJsonErrorNode( final JsonElement errorEntryElement, final ErrorType expErrorType, final ErrorTag expErrorTag, + final String expErrorMessage, final String expErrorAppTag, + final ErrorInfoVerifier errorInfoVerifier ) { JsonElement errorInfoElement = null; Map actualErrorInfo = null; @@ -855,7 +861,7 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { } else { assertTrue( "\"error\" leaf Json element " + leafName + - " is not a Primitive", leafElement.isJsonPrimitive() ); + " is not a Primitive", leafElement.isJsonPrimitive() ); leafMap.put( leafName, leafElement.getAsString() ); } @@ -877,7 +883,7 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { } } - void verifyOptionalJsonLeaf( String actualValue, String expValue, String tagName ) { + void verifyOptionalJsonLeaf( final String actualValue, final String expValue, final String tagName ) { if( expValue != null ) { assertEquals( tagName, expValue, actualValue ); } @@ -886,20 +892,20 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { } } - void verifyXMLResponseBody( InputStream stream, ErrorType expErrorType, ErrorTag expErrorTag, - String expErrorMessage, String expErrorAppTag, - ErrorInfoVerifier errorInfoVerifier ) - throws Exception { + void verifyXMLResponseBody( final InputStream stream, final ErrorType expErrorType, final ErrorTag expErrorTag, + final String expErrorMessage, final String expErrorAppTag, + final ErrorInfoVerifier errorInfoVerifier ) + throws Exception { Document doc = parseXMLDocument( stream ); NodeList children = getXMLErrorList( doc, 1 ); verifyXMLErrorNode( children.item( 0 ), expErrorType, expErrorTag, expErrorMessage, - expErrorAppTag, errorInfoVerifier ); + expErrorAppTag, errorInfoVerifier ); } - private Document parseXMLDocument( InputStream stream ) throws IOException { + private Document parseXMLDocument( final InputStream stream ) throws IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); factory.setCoalescing(true); @@ -921,9 +927,9 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { return doc; } - void verifyXMLErrorNode( Node errorNode, ErrorType expErrorType, ErrorTag expErrorTag, - String expErrorMessage, String expErrorAppTag, - ErrorInfoVerifier errorInfoVerifier ) throws Exception { + void verifyXMLErrorNode( final Node errorNode, final ErrorType expErrorType, final ErrorTag expErrorTag, + final String expErrorMessage, final String expErrorAppTag, + final ErrorInfoVerifier errorInfoVerifier ) throws Exception { String errorType = (String)ERROR_TYPE.evaluate( errorNode, XPathConstants.STRING ); assertEquals( "error-type", expErrorType.getErrorTypeTag(), errorType ); @@ -945,19 +951,19 @@ public class RestconfDocumentedExceptionMapperTest extends JerseyTest { } } - void verifyOptionalXMLLeaf( Node fromNode, XPathExpression xpath, String expValue, - String tagName ) throws Exception { + void verifyOptionalXMLLeaf( final Node fromNode, final XPathExpression xpath, final String expValue, + final String tagName ) throws Exception { if( expValue != null ) { String actual = (String)xpath.evaluate( fromNode, XPathConstants.STRING ); assertEquals( tagName, expValue, actual ); } else { assertNull( "Found unexpected \"error\" leaf entry for: " + tagName, - xpath.evaluate( fromNode, XPathConstants.NODE ) ); + xpath.evaluate( fromNode, XPathConstants.NODE ) ); } } - NodeList getXMLErrorList( Node fromNode, int count ) throws Exception { + NodeList getXMLErrorList( final Node fromNode, final int count ) throws Exception { NodeList errorList = (NodeList)ERROR_LIST.evaluate( fromNode, XPathConstants.NODESET ); assertNotNull( "Root errors node is empty", errorList ); assertEquals( "Root errors node child count", count, errorList.getLength() ); diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/structures/CompareLf.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/structures/CompareLf.java index 34036edc05..12ab073202 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/structures/CompareLf.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/structures/CompareLf.java @@ -7,7 +7,8 @@ */ package org.opendaylight.controller.sal.restconf.impl.test.structures; -import static org.junit.Assert.*; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import org.junit.Test; diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/structures/Lst.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/structures/Lst.java index d4c7671c45..8eccf373b9 100644 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/structures/Lst.java +++ b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/test/structures/Lst.java @@ -7,17 +7,18 @@ */ package org.opendaylight.controller.sal.restconf.impl.test.structures; -import java.util.*; +import java.util.HashSet; +import java.util.Set; public class Lst extends YangElement { - private Set lstItems; + private final Set lstItems; - public Lst(String name) { + public Lst(final String name) { super(name); lstItems = new HashSet<>(); } - public Lst addLstItem(LstItem lstItem) { + public Lst addLstItem(final LstItem lstItem) { lstItem.setLstName(name); while (this.lstItems.contains(lstItem)) { lstItem.incNumOfEqualItems(); @@ -31,7 +32,7 @@ public class Lst extends YangElement { } @Override - public boolean equals(Object obj) { + public boolean equals(final Object obj) { if (this == obj) { return true; } @@ -59,5 +60,4 @@ public class Lst extends YangElement { result = prime * result + ((lstItems == null) ? 0 : lstItems.hashCode()); return result; } - } -- 2.36.6