*/
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;
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;
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 );
}
private InstanceIdWithSchemaNode toIdentifier( final String restconfInstance,
- final boolean toMountPointIdentifier ) {
+ final boolean toMountPointIdentifier ) {
this.checkPreconditions();
Iterable<String> split = Splitter.on( "/" ).split( restconfInstance );
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(
Predicate<Module> filter = new Predicate<Module>() {
@Override
- public boolean apply( Module m ) {
+ public boolean apply( final Module m ) {
return Objects.equal( m.getName(), moduleName );
}
};
final SchemaContext mountPointSchema = mountPoint.getSchemaContext();
Set<Module> 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() );
}
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 ) {
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;
}
SchemaContext schemaContext = mountPoint.getSchemaContext();
final Module moduleSchema = schemaContext.findModuleByNamespaceAndRevision(
- qname.getNamespace(), qname.getRevision() );
+ qname.getNamespace(), qname.getRevision() );
if( moduleSchema == null ) {
return null;
}
@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);
}
};
List<DataSchemaNode> 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();
@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);
}
};
List<DataSchemaNode> 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<DataSchemaNode> 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<DataSchemaNode> 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<DataSchemaNode> 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<DataSchemaNode> 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<DataSchemaNode> 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<DataSchemaNode> instances =
this.findInstanceDataChildrenByName(((DataNodeContainer) restconfContainer),
- Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
+ Draft02.RestConfModule.STREAMS_CONTAINER_SCHEMA_NODE);
return Iterables.getFirst(instances, null);
}
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,
if( strings.isEmpty() ) {
return new InstanceIdWithSchemaNode( builder.toInstance(),
- ((DataSchemaNode) parentNode), mountPoint );
+ ((DataSchemaNode) parentNode), mountPoint );
}
String head = strings.iterator().next();
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.",
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();
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.",
List<String> subList = strings.subList( 1, strings.size() );
return this.collectPathArguments( InstanceIdentifier.builder(), subList, moduleBehindMountPoint,
- mount, returnJustMountPoint );
+ mount, returnJustMountPoint );
}
Module module = null;
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.",
}
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<DataSchemaNode> 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(
}
this.addKeyValue( keyValues, listNode.getDataChildByName( key ),
- uriKeyValue, mountPoint );
+ uriKeyValue, mountPoint );
i++;
}
}
if( (targetNode instanceof DataNodeContainer) ) {
final List<String> 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 );
Predicate<DataSchemaNode> filter = new Predicate<DataSchemaNode>() {
@Override
- public boolean apply( DataSchemaNode node ) {
+ public boolean apply( final DataSchemaNode node ) {
return Objects.equal( node.getQName().getNamespace(), namespace );
}
};
}
public List<DataSchemaNode> findInstanceDataChildrenByName( final DataNodeContainer container,
- final String name ) {
+ final String name ) {
Preconditions.<DataNodeContainer> checkNotNull( container );
Preconditions.<String> checkNotNull( name );
Predicate<DataSchemaNode> filter = new Predicate<DataSchemaNode>() {
@Override
- public boolean apply( DataSchemaNode node ) {
+ public boolean apply( final DataSchemaNode node ) {
return Objects.equal( node.getQName().getLocalName(), name );
}
};
}
Iterable<ChoiceNode> choiceNodes = Iterables.<ChoiceNode> filter( container.getChildNodes(),
- ChoiceNode.class );
+ ChoiceNode.class );
final Function<ChoiceNode, Set<ChoiceCaseNode>> choiceFunction =
new Function<ChoiceNode, Set<ChoiceCaseNode>>() {
};
Iterable<Set<ChoiceCaseNode>> map = Iterables.<ChoiceNode, Set<ChoiceCaseNode>> transform(
- choiceNodes, choiceFunction );
+ choiceNodes, choiceFunction );
final Iterable<ChoiceCaseNode> allCases = Iterables.<ChoiceCaseNode> concat( map );
for( final ChoiceCaseNode caze : allCases ) {
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<QName, Object> map, final DataSchemaNode node,
- final String uriValue, final MountInstance mountPoint ) {
+ final String uriValue, final MountInstance mountPoint ) {
Preconditions.<String> checkNotNull( uriValue );
Preconditions.checkArgument( (node instanceof LeafSchemaNode) );
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 );
};
Optional<QName> namespace = FluentIterable.from( sorted )
- .transform( transform )
- .firstMatch( findFirst );
+ .transform( transform )
+ .firstMatch( findFirst );
return namespace.isPresent() ? QName.create( namespace.get(), node ) : null;
}
}
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 );
}
}
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: "
}
private CharSequence convertToRestconfIdentifier( final NodeIdentifier argument,
- final ContainerSchemaNode node ) {
+ final ContainerSchemaNode node ) {
StringBuilder builder = new StringBuilder();
builder.append( "/" );
QName nodeType = argument.getNodeType();
}
private CharSequence convertToRestconfIdentifier( final NodeIdentifierWithPredicates argument,
- final ListSchemaNode node ) {
+ final ListSchemaNode node ) {
QName nodeType = argument.getNodeType();
final CharSequence nodeIdentifier = this.toRestconfIdentifier( nodeType );
final Map<QName, Object> keyValues = argument.getKeyValues();
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;
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;
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;
Map<String, String> expErrorInfo;
- public ComplexErrorInfoVerifier( Map<String, String> expErrorInfo ) {
+ public ComplexErrorInfoVerifier( final Map<String, String> expErrorInfo ) {
this.expErrorInfo = expErrorInfo;
}
@Override
- public void verifyXML( Node errorInfoNode ) {
+ public void verifyXML( final Node errorInfoNode ) {
Map<String, String> mutableExpMap = Maps.newHashMap( expErrorInfo );
NodeList childNodes = errorInfoNode.getChildNodes();
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() );
}
}
}
@Override
- public void verifyJson( JsonElement errorInfoElement ) {
+ public void verifyJson( final JsonElement errorInfoElement ) {
assertTrue( "\"error-info\" Json element is not an Object",
errorInfoElement.isJsonObject() );
for( Entry<String,String> 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() ) {
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() );
}
}
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;
}
};
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 );
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 );
}
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 );
}
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
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
String errorInfo = "<address>1.2.3.4</address> <session-id>123</session-id>";
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
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 );
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 =
-// "<errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\">"+
-// " <error>" +
-// " <error-type>application</error-type>"+
-// " <error-tag>operation-failed</error-tag>"+
-// " <error-message>An error occurred</error-message>"+
-// " <error-info>" +
-// " <session-id>123</session-id>" +
-// " <address>1.2.3.4</address>" +
-// " </error-info>" +
-// " </error>" +
-// "</errors>";
-//
-// 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 =
+ // "<errors xmlns=\"urn:ietf:params:xml:ns:yang:ietf-restconf\">"+
+ // " <error>" +
+ // " <error-type>application</error-type>"+
+ // " <error-tag>operation-failed</error-tag>"+
+ // " <error-message>An error occurred</error-message>"+
+ // " <error-info>" +
+ // " <session-id>123</session-id>" +
+ // " <address>1.2.3.4</address>" +
+ // " </error-info>" +
+ // " </error>" +
+ // "</errors>";
+ //
+ // 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
String errorInfo = "<address>1.2.3.4</address> <session-id>123</session-id>";
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
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
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
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
// 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() );
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 );
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 );
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<String, String> actualErrorInfo = null;
}
else {
assertTrue( "\"error\" leaf Json element " + leafName +
- " is not a Primitive", leafElement.isJsonPrimitive() );
+ " is not a Primitive", leafElement.isJsonPrimitive() );
leafMap.put( leafName, leafElement.getAsString() );
}
}
}
- 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 );
}
}
}
- 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);
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 );
}
}
- 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() );