data, DataSchemaContextTree.from(schemaContext).getRoot(),
YangInstanceIdentifierDeserializer.MainVarsWrapper.STARTING_OFFSET, schemaContext);
- checkValid(!data.isEmpty(), "Empty path is not valid", variables.getData(), variables.getOffset());
-
- if (!data.equals(String.valueOf(RestconfConstants.SLASH))) {
- while (!allCharsConsumed(variables)) {
- validArg(variables);
- final QName qname = prepareQName(variables);
-
- // this is the last identifier (input is consumed) or end of identifier (slash)
- if (allCharsConsumed(variables)
- || currentChar(variables.getOffset(), variables.getData()) == RestconfConstants.SLASH) {
- prepareIdentifier(qname, path, variables);
- path.add(variables.getCurrent().getIdentifier());
- } else if (currentChar(variables.getOffset(),
- variables.getData()) == ParserBuilderConstants.Deserializer.EQUAL) {
- if (nextContextNode(qname, path, variables).getDataSchemaNode() instanceof ListSchemaNode) {
- prepareNodeWithPredicates(qname, path, variables);
- } else {
- prepareNodeWithValue(qname, path, variables);
- }
+ while (!allCharsConsumed(variables)) {
+ validArg(variables);
+ final QName qname = prepareQName(variables);
+
+ // this is the last identifier (input is consumed) or end of identifier (slash)
+ if (allCharsConsumed(variables)
+ || currentChar(variables.getOffset(), variables.getData()) == RestconfConstants.SLASH) {
+ prepareIdentifier(qname, path, variables);
+ path.add(variables.getCurrent().getIdentifier());
+ } else if (currentChar(variables.getOffset(),
+ variables.getData()) == ParserBuilderConstants.Deserializer.EQUAL) {
+ if (nextContextNode(qname, path, variables).getDataSchemaNode() instanceof ListSchemaNode) {
+ prepareNodeWithPredicates(qname, path, variables);
} else {
- throw new IllegalArgumentException(
- "Bad char " + currentChar(variables.getOffset(), variables.getData()) + " on position "
- + variables.getOffset() + ".");
+ prepareNodeWithValue(qname, path, variables);
}
+ } else {
+ throw new IllegalArgumentException(
+ "Bad char " + currentChar(variables.getOffset(), variables.getData()) + " on position "
+ + variables.getOffset() + ".");
}
}
}
private static void validArg(final MainVarsWrapper variables) {
- checkValid(RestconfConstants.SLASH == currentChar(variables.getOffset(), variables.getData()),
- "Identifier must start with '/'.", variables.getData(), variables.getOffset());
- skipCurrentChar(variables);
- checkValid(!allCharsConsumed(variables), "Identifier cannot end with '/'.",
- variables.getData(), variables.getOffset());
+ // every identifier except of the first MUST start with slash
+ if (variables.getOffset() != MainVarsWrapper.STARTING_OFFSET) {
+ checkValid(RestconfConstants.SLASH == currentChar(variables.getOffset(), variables.getData()),
+ "Identifier must start with '/'.", variables.getData(), variables.getOffset());
+
+ // skip slash
+ skipCurrentChar(variables);
+
+ // check if slash is not also the last char in identifier
+ checkValid(!allCharsConsumed(variables), "Identifier cannot end with '/'.",
+ variables.getData(), variables.getOffset());
+ }
}
private static void skipCurrentChar(final MainVarsWrapper variables) {
public static String create(final SchemaContext schemaContext, final YangInstanceIdentifier data) {
final DataSchemaContextNode<?> current = DataSchemaContextTree.from(schemaContext).getRoot();
final MainVarsWrapper variables = new MainVarsWrapper(current);
-
- // for empty data return slash
- final StringBuilder path = (data.getPathArguments().size() == 0) ?
- new StringBuilder(String.valueOf(RestconfConstants.SLASH)) : new StringBuilder();
+ final StringBuilder path = new StringBuilder();
QNameModule parentModule = null;
for (int i = 0; i < data.getPathArguments().size(); i++) {
// append namespace before every node which is defined in other module than its parent
// condition is satisfied also for the first path argument
if (!arg.getNodeType().getModule().equals(parentModule)) {
- path.append(RestconfConstants.SLASH
- + prefixForNamespace(arg.getNodeType(), schemaContext)
- + ParserBuilderConstants.Deserializer.COLON);
+ // append slash if it is not the first path argument
+ if (path.length() > 0) {
+ path.append(RestconfConstants.SLASH);
+ }
+
+ path.append(prefixForNamespace(arg.getNodeType(), schemaContext));
+ path.append(ParserBuilderConstants.Deserializer.COLON);
} else {
path.append(RestconfConstants.SLASH);
}
import com.google.common.base.Optional;
import com.google.common.base.Preconditions;
import com.google.common.util.concurrent.CheckedFuture;
+import javax.annotation.Nonnull;
import org.opendaylight.controller.md.sal.common.api.data.LogicalDatastoreType;
import org.opendaylight.controller.md.sal.common.api.data.ReadFailedException;
import org.opendaylight.netconf.sal.restconf.impl.RestconfDocumentedException;
transactionNode.setLogicalDatastoreType(LogicalDatastoreType.CONFIGURATION);
final NormalizedNode<?, ?> configDataNode = readDataViaTransaction(transactionNode);
+ // if no data exists
+ if (stateDataNode == null && configDataNode == null) {
+ throw new RestconfDocumentedException(
+ "Request could not be completed because the relevant data model content does not exist",
+ ErrorType.PROTOCOL,
+ ErrorTag.DATA_MISSING);
+ }
+
+ // return config data
+ if (stateDataNode == null) {
+ return configDataNode;
+ }
+
+ // return state data
+ if (configDataNode == null) {
+ return stateDataNode;
+ }
+
+ // merge data from config and state
return mapNode(stateDataNode, configDataNode);
}
* @param configDataNode
* - data node of config data
*/
- private static void validPossibilityOfMergeNodes(final NormalizedNode<?, ?> stateDataNode,
- final NormalizedNode<?, ?> configDataNode) {
+ private static void validPossibilityOfMergeNodes(@Nonnull final NormalizedNode<?, ?> stateDataNode,
+ @Nonnull final NormalizedNode<?, ?> configDataNode) {
final QNameModule moduleOfStateData = stateDataNode.getIdentifier().getNodeType().getModule();
final QNameModule moduleOfConfigData = configDataNode.getIdentifier().getNodeType().getModule();
if (moduleOfStateData != moduleOfConfigData) {
import java.util.Date;
import java.util.Iterator;
import java.util.List;
+import javax.annotation.Nullable;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPoint;
import org.opendaylight.controller.md.sal.dom.api.DOMMountPointService;
import org.opendaylight.netconf.md.sal.rest.schema.SchemaExportContext;
* - {@link SchemaContext}
* @return {@link InstanceIdentifierContext}
*/
- public static InstanceIdentifierContext<?> toInstanceIdentifier(final String identifier,
+ public static InstanceIdentifierContext<?> toInstanceIdentifier(@Nullable final String identifier,
final SchemaContext schemaContext) {
final YangInstanceIdentifier deserialize;
- if (identifier.contains(RestconfConstants.MOUNT)) {
+ if (identifier != null && identifier.contains(RestconfConstants.MOUNT)) {
final String mountPointId = identifier.substring(0, identifier.indexOf("/" + RestconfConstants.MOUNT));
deserialize = IdentifierCodec.deserialize(mountPointId, schemaContext);
} else {
final StringBuilder pathBuilder = new StringBuilder();
while (componentIter.hasNext()) {
final String current = componentIter.next();
- pathBuilder.append("/");
- pathBuilder.append(current);
+
if (RestconfConstants.MOUNT.equals(current)) {
+ pathBuilder.append("/");
+ pathBuilder.append(RestconfConstants.MOUNT);
break;
}
+
+ if (pathBuilder.length() != 0) {
+ pathBuilder.append("/");
+ }
+
+ pathBuilder.append(current);
}
final InstanceIdentifierContext<?> point = ParserIdentifier
.toInstanceIdentifier(pathBuilder.toString(), schemaContext);
package org.opendaylight.restconf.parser;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Test;
public class IdentifierCodecTest {
private static final String URI_WITH_LIST_AND_LEAF =
- "/list-test:top/list1=%2C%27" + '"' + "%3A" + '"' + "%20%2F,,foo/list2=a,b/result";
- private static final String URI_WITH_LEAF_LIST = "/list-test:top/Y=x%3Ay";
+ "list-test:top/list1=%2C%27" + '"' + "%3A" + '"' + "%20%2F,,foo/list2=a,b/result";
+ private static final String URI_WITH_LEAF_LIST = "list-test:top/Y=x%3Ay";
private SchemaContext schemaContext;
}
/**
- * Positive test of serialization <code>YangInstanceIdentifier.EMPTY</code>. Single slash is
+ * Positive test of serialization <code>YangInstanceIdentifier.EMPTY</code>. Empty <code>String</code> is
* expected to be returned.
*/
@Test
public void codecSerializeEmptyTest () {
final String serialized = IdentifierCodec.serialize(YangInstanceIdentifier.EMPTY, this.schemaContext);
- assertEquals("Failed codec serialization test", "/", serialized);
+ assertTrue("Failed codec serialization test", serialized.isEmpty());
}
/**
import org.opendaylight.netconf.sal.restconf.impl.RestconfError;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
+import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
/**
@Test
public void deserializeContainerTest() {
final Iterable<YangInstanceIdentifier.PathArgument> result = YangInstanceIdentifierDeserializer
- .create(schemaContext, "/deserializer-test:contA");
+ .create(schemaContext, "deserializer-test:contA");
assertEquals("Result does not contains expected number of path arguments", 1, Iterables.size(result));
assertEquals("Not expected path argument",
@Test
public void deserializeContainerWithLeafTest() {
final Iterable<YangInstanceIdentifier.PathArgument> result = YangInstanceIdentifierDeserializer
- .create(schemaContext, "/deserializer-test:contA/leaf-A");
+ .create(schemaContext, "deserializer-test:contA/leaf-A");
assertEquals("Result does not contains expected number of path arguments", 2, Iterables.size(result));
@Test
public void deserializeContainerWithListWithLeafListTest() {
final Iterable<YangInstanceIdentifier.PathArgument> result = YangInstanceIdentifierDeserializer
- .create(schemaContext, "/deserializer-test:contA/list-A=100/leaf-list-AA=instance");
+ .create(schemaContext, "deserializer-test:contA/list-A=100/leaf-list-AA=instance");
assertEquals("Result does not contains expected number of path arguments", 5, Iterables.size(result));
@Test
public void deserializeListWithNoKeysTest() {
final Iterable<YangInstanceIdentifier.PathArgument> result = YangInstanceIdentifierDeserializer
- .create(schemaContext, "/deserializer-test:list-no-key");
+ .create(schemaContext, "deserializer-test:list-no-key");
assertEquals("Result does not contains expected number of path arguments", 2, Iterables.size(result));
@Test
public void deserializeListWithOneKeyTest() {
final Iterable<YangInstanceIdentifier.PathArgument> result = YangInstanceIdentifierDeserializer
- .create(schemaContext, "/deserializer-test:list-one-key=value");
+ .create(schemaContext, "deserializer-test:list-one-key=value");
assertEquals("Result does not contains expected number of path arguments", 2, Iterables.size(result));
values.put(QName.create(list, "enabled"), false);
final Iterable<YangInstanceIdentifier.PathArgument> result = YangInstanceIdentifierDeserializer
- .create(schemaContext, "/deserializer-test:list-multiple-keys=value,100,false");
+ .create(schemaContext, "deserializer-test:list-multiple-keys=value,100,false");
assertEquals("Result does not contains expected number of path arguments", 2, Iterables.size(result));
@Test
public void deserializeLeafListTest() {
final Iterable<YangInstanceIdentifier.PathArgument> result = YangInstanceIdentifierDeserializer
- .create(schemaContext, "/deserializer-test:leaf-list-0=true");
+ .create(schemaContext, "deserializer-test:leaf-list-0=true");
assertEquals("Result does not contains expected number of path arguments", 2, Iterables.size(result));
iterator.next().toString());
}
+ /**
+ * Test when empty <code>String</code> is supplied as an input. Test is expected to return empty result.
+ */
+ @Test
+ public void deserializeEmptyDataTest() {
+ final Iterable<PathArgument> result = YangInstanceIdentifierDeserializer.create(schemaContext, "");
+ assertTrue("Empty result expected", Iterables.isEmpty(result));
+ }
+
/**
* Negative test when supplied <code>SchemaContext</code> is null. Test is expected to fail with
* <code>NullPointerException</code>.
@Test
public void deserializeNullSchemaContextNegativeTest() {
thrown.expect(NullPointerException.class);
- YangInstanceIdentifierDeserializer.create(null, "/deserializer-test:contA");
+ YangInstanceIdentifierDeserializer.create(null, "deserializer-test:contA");
}
/**
YangInstanceIdentifierDeserializer.create(schemaContext, null);
}
- /**
- * Negative test when empty <code>String</code> is supplied as an input. Test is expected to fail with
- * <code>IllegalArgumentException</code>.
- */
- @Test
- public void deserializeEmptyDataNegativeTest() {
- thrown.expect(IllegalArgumentException.class);
- YangInstanceIdentifierDeserializer.create(schemaContext, "");
- }
-
/**
* Negative test when identifier is not followed by slash or equals. Test is expected to fail with
* <code>IllegalArgumentException</code>.
@Test
public void deserializeBadCharMissingSlashOrEqualNegativeTest() {
thrown.expect(IllegalArgumentException.class);
- YangInstanceIdentifierDeserializer.create(schemaContext, "/deserializer-test:cont*leaf-A");
- }
-
- /**
- * Negative test of validating identifier when identifier does not start with slash.
- * <code>IllegalArgumentException</code> is expected.
- */
- @Test
- public void deserializeNoBeginningSlashNegativeTest() {
- thrown.expect(IllegalArgumentException.class);
- YangInstanceIdentifierDeserializer.create(schemaContext, "deserializer-test:contA");
- }
-
- /**
- * Positive test of validating identifier when identifier contains slash only. Deserialization should return
- * empty result.
- */
- @Test
- public void validArgOnlySlashTest() {
- final Iterable<YangInstanceIdentifier.PathArgument> result = YangInstanceIdentifierDeserializer
- .create(schemaContext, "/");
- assertTrue("Result does not contains expected number of path arguments", Iterables.isEmpty(result));
+ YangInstanceIdentifierDeserializer.create(schemaContext, "deserializer-test:cont*leaf-A");
}
/**
@Test
public void validArgIdentifierContainerEndsWithSlashNegativeTest() {
thrown.expect(IllegalArgumentException.class);
- YangInstanceIdentifierDeserializer.create(schemaContext, "/deserializer-test:contA/");
+ YangInstanceIdentifierDeserializer.create(schemaContext, "deserializer-test:contA/");
}
/**
@Test
public void validArgIdentifierListEndsWithSlashLNegativeTest() {
thrown.expect(IllegalArgumentException.class);
- YangInstanceIdentifierDeserializer.create(schemaContext, "/deserializer-test:list-one-key=value/");
+ YangInstanceIdentifierDeserializer.create(schemaContext, "deserializer-test:list-one-key=value/");
}
/**
- * Negative test of creating <code>QName</code> when identifier is empty (example: '//'). Test is expected to fail
+ * Negative test of creating <code>QName</code> when identifier is empty (example: '/'). Test is expected to fail
* with <code>IllegalArgumentException</code>.
*/
@Test
public void prepareQnameEmptyIdentifierNegativeTest() {
thrown.expect(IllegalArgumentException.class);
- YangInstanceIdentifierDeserializer.create(schemaContext, "//");
+ YangInstanceIdentifierDeserializer.create(schemaContext, "/");
}
/**
@Test
public void prepareQnameTwoSlashesNegativeTest() {
thrown.expect(IllegalArgumentException.class);
- YangInstanceIdentifierDeserializer.create(schemaContext, "/deserializer-test:contA//leaf-A");
+ YangInstanceIdentifierDeserializer.create(schemaContext, "deserializer-test:contA//leaf-A");
}
/**
@Test
public void prepareQnameBuildPathNegativeTest() {
thrown.expect(IllegalArgumentException.class);
- YangInstanceIdentifierDeserializer.create(schemaContext, "/deserializer-test*contA");
+ YangInstanceIdentifierDeserializer.create(schemaContext, "deserializer-test*contA");
}
/**
@Test
public void prepareQnameNotExistingPrefixNegativeTest() {
thrown.expect(IllegalArgumentException.class);
- YangInstanceIdentifierDeserializer.create(schemaContext, "/not-existing:contA");
+ YangInstanceIdentifierDeserializer.create(schemaContext, "not-existing:contA");
}
/**
@Test
public void prepareQnameNotValidPrefixAndLocalNameNegativeTest() {
thrown.expect(IllegalArgumentException.class);
- YangInstanceIdentifierDeserializer.create(schemaContext, "/deserializer-test:*not-parsable-identifier");
+ YangInstanceIdentifierDeserializer.create(schemaContext, "deserializer-test:*not-parsable-identifier");
}
/**
@Test
public void prepareQnameErrorParsingNegativeTest() {
thrown.expect(StringIndexOutOfBoundsException.class);
- YangInstanceIdentifierDeserializer.create(schemaContext, "/deserializer-test:");
+ YangInstanceIdentifierDeserializer.create(schemaContext, "deserializer-test:");
}
/**
@Test
public void prepareQnameNotValidContainerNameNegativeTest() {
try {
- YangInstanceIdentifierDeserializer.create(schemaContext, "/deserializer-test:contA/leafB");
+ YangInstanceIdentifierDeserializer.create(schemaContext, "deserializer-test:contA/leafB");
fail("Test should fail due to unknown child node in container");
} catch (final RestconfDocumentedException e) {
assertEquals("Not expected error type",
@Test
public void prepareQnameNotValidListNameNegativeTest() {
try {
- YangInstanceIdentifierDeserializer.create(schemaContext, "/deserializer-test:list-no-key/disabled=false");
+ YangInstanceIdentifierDeserializer.create(schemaContext, "deserializer-test:list-no-key/disabled=false");
fail("Test should fail due to unknown child node in list");
} catch (final RestconfDocumentedException e) {
assertEquals("Not expected error type",
@Test
public void prepareIdentifierNotKeyedEntryNegativeTest() {
thrown.expect(IllegalArgumentException.class);
- YangInstanceIdentifierDeserializer.create(schemaContext, "/deserializer-test:list-one-key");
+ YangInstanceIdentifierDeserializer.create(schemaContext, "deserializer-test:list-one-key");
}
/**
public void deserializeKeysEndsWithComaNegativeTest() {
thrown.expect(IllegalArgumentException.class);
YangInstanceIdentifierDeserializer.create( schemaContext,
- "/deserializer-test:list-multiple-keys=value,100,false,");
+ "deserializer-test:list-multiple-keys=value,100,false,");
}
/**
values.put(QName.create(list, "enabled"), "");
final Iterable<YangInstanceIdentifier.PathArgument> result = YangInstanceIdentifierDeserializer.create(
- schemaContext, "/deserializer-test:list-multiple-keys=%3Afoo,,/string-value");
+ schemaContext, "deserializer-test:list-multiple-keys=%3Afoo,,/string-value");
assertEquals("Result does not contains expected number of path arguments", 3, Iterables.size(result));
public void notAllListKeysEncodedNegativeTest() {
try {
YangInstanceIdentifierDeserializer.create(
- schemaContext, "/deserializer-test:list-multiple-keys=%3Afoo/string-value");
+ schemaContext, "deserializer-test:list-multiple-keys=%3Afoo/string-value");
fail("Test should fail due to missing list key values");
} catch (final RestconfDocumentedException e) {
assertEquals("Not expected error type",
}
}
- /**
- * Negative test of preparing node with predicates when it is not possible to get <code>DataSchemaNode</code>.
- * Test is expected to fail with <code>NullPointerException</code>.
- */
- @Ignore
- @Test
- public void prepareNodeWithPredicatesNegativeTest() {}
-
/**
* Test URI with list where key value starts with, ends with or contains percent encoded characters.The encoded
* value should be complete also with not percent-encoded parts.
*/
@Test
public void percentEncodedKeyEndsWithNoPercentEncodedChars() {
- final String URI = "/deserializer-test:list-multiple-keys=%3Afoo,bar%3A,foo%3Abar";
+ final String URI = "deserializer-test:list-multiple-keys=%3Afoo,bar%3A,foo%3Abar";
final YangInstanceIdentifier result = YangInstanceIdentifier.create(
YangInstanceIdentifierDeserializer.create(schemaContext, URI));
values.put(QName.create(list, "enabled"), "");
final Iterable<YangInstanceIdentifier.PathArgument> result = YangInstanceIdentifierDeserializer
- .create(schemaContext, "/deserializer-test:list-multiple-keys=,,");
+ .create(schemaContext, "deserializer-test:list-multiple-keys=,,");
assertEquals("Result does not contains expected number of path arguments", 2, Iterables.size(result));
@Test
public void leafListMissingKeyNegativeTest() {
try {
- YangInstanceIdentifierDeserializer.create(schemaContext, "/deserializer-test:leaf-list-0=");
+ YangInstanceIdentifierDeserializer.create(schemaContext, "deserializer-test:leaf-list-0=");
fail("Test should fail due to missing instance value");
} catch (final RestconfDocumentedException e) {
assertEquals("Not expected error type",
@Test
public void deserializePartInOtherModuleTest() {
final Iterable<YangInstanceIdentifier.PathArgument> result = YangInstanceIdentifierDeserializer.create(
- schemaContext, "/deserializer-test-included:augmented-list=100/augmented-leaf");
+ schemaContext, "deserializer-test-included:augmented-list=100/augmented-leaf");
assertEquals("Result does not contains expected number of path arguments", 4, Iterables.size(result));
final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
assertEquals("Serialization not successful",
- "/serializer-test:contA", result);
+ "serializer-test:contA", result);
}
/**
.build();
final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
- assertEquals("Serialization not successful", "/serializer-test:contA/leaf-A", result);
+ assertEquals("Serialization not successful", "serializer-test:contA/leaf-A", result);
}
/**
final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
assertEquals("Serialization not successful",
- "/serializer-test:contA/list-A=100/leaf-list-AA=instance",
+ "serializer-test:contA/list-A=100/leaf-list-AA=instance",
result);
}
.build();
final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
- assertEquals("Serialization not successful", "/serializer-test:list-no-key", result);
+ assertEquals("Serialization not successful", "serializer-test:list-no-key", result);
}
/**
.build();
final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
- assertEquals("Serialization not successful", "/serializer-test:list-one-key=value", result);
+ assertEquals("Serialization not successful", "serializer-test:list-one-key=value", result);
}
/**
.node(list).nodeWithKey(list, values).build();
final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
- assertEquals("Serialization not successful", "/serializer-test:list-multiple-keys=value-1,2,true", result);
+ assertEquals("Serialization not successful", "serializer-test:list-multiple-keys=value-1,2,true", result);
}
/**
.build();
final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
- assertEquals("Serialization not successful", "/serializer-test:leaf-0", result);
+ assertEquals("Serialization not successful", "serializer-test:leaf-0", result);
}
/**
.build();
final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
- assertEquals("Serialization not successful", "/serializer-test:leaf-list-0=instance", result);
+ assertEquals("Serialization not successful", "serializer-test:leaf-list-0=instance", result);
}
/**
/**
* Test of serialization <code>YangInstanceIdentifier</code> to <code>String</code> when supplied
* <code>YangInstanceIdentifier</code> is <code>YangInstanceIdentifier.EMPTY</code>.
- * Single slash is expected as a return value.
+ * Empty <code>String</code> is expected as a return value.
*/
@Test
public void serializeEmptyDataTest() {
final String result = YangInstanceIdentifierSerializer.create(schemaContext, YangInstanceIdentifier.EMPTY);
- assertEquals("Empty identifier is expected", "/", result);
+ assertTrue("Empty identifier is expected", result.isEmpty());
}
/**
.build();
final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
- assertEquals("Serialization not successful", "/serializer-test:list-one-key=" + encoded, result);
+ assertEquals("Serialization not successful", "serializer-test:list-one-key=" + encoded, result);
}
/**
.build();
final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
- assertEquals("Serialization not successful", "/serializer-test:list-one-key=" + value, result);
+ assertEquals("Serialization not successful", "serializer-test:list-one-key=" + value, result);
}
/**
final String result = YangInstanceIdentifierSerializer.create(schemaContext, data);
assertEquals("Serialization not successful",
- "/serializer-test-included:augmented-list=100/serializer-test:augmented-leaf", result);
+ "serializer-test-included:augmented-list=100/serializer-test:augmented-leaf", result);
}
/**
import org.opendaylight.yangtools.yang.parser.util.NamedFileInputStream;
class RestconfModulesServiceTestUtils {
- static final String MOUNT_POINT = "/mount-point-1:cont/" + RestconfConstants.MOUNT + "/";
- static final String NOT_REGISTERED_MOUNT_POINT = "/mount-point-1:listA/" + RestconfConstants.MOUNT + "/";
+ static final String MOUNT_POINT = "mount-point-1:cont/" + RestconfConstants.MOUNT + "/";
+ static final String NOT_REGISTERED_MOUNT_POINT = "mount-point-1:listA/" + RestconfConstants.MOUNT + "/";
static final String TEST_MODULE = "module1/2014-01-01";
static final String NOT_EXISTING_MODULE = "not-existing/2016-01-01";
public class ParserIdentifierTest {
// mount point identifier + expected result
private static final String MOUNT_POINT_IDENT =
- "/mount-point:mount-container/point-number" + "/" + RestconfConstants.MOUNT;
+ "mount-point:mount-container/point-number" + "/" + RestconfConstants.MOUNT;
private static final String MOUNT_POINT_IDENT_RESULT =
"/(mount:point?revision=2016-06-02)mount-container/point-number";
// invalid mount point identifier
private static final String INVALID_MOUNT_POINT_IDENT =
- "/mount-point:point-number" + "/" + RestconfConstants.MOUNT;
+ "mount-point:point-number" + "/" + RestconfConstants.MOUNT;
// test identifier + expected result
private static final String TEST_IDENT =
- "/parser-identifier:cont1/cont2/listTest/list-in-grouping=name/leaf-A.B";
+ "parser-identifier:cont1/cont2/listTest/list-in-grouping=name/leaf-A.B";
private static final String TEST_IDENT_RESULT =
"/(parser:identifier?revision=2016-06-02)cont1/cont2/listTest/listTest/list-in-grouping/"
// test identifier with nodes defined in other modules using augmentation + expected result
private static final String TEST_IDENT_OTHERS =
- "/parser-identifier-included:list-1=name,2016-06-02/parser-identifier:augment-leaf";
+ "parser-identifier-included:list-1=name,2016-06-02/parser-identifier:augment-leaf";
private static final String TEST_IDENT_OTHERS_RESULT =
"/(parser:identifier:included?revision=2016-06-02)list-1/list-1"
// invalid test identifier
private static final String INVALID_TEST_IDENT =
- "/parser-identifier:cont2/listTest/list-in-grouping=name/leaf-A.B";
+ "parser-identifier:cont2/listTest/list-in-grouping=name/leaf-A.B";
// schema context with test modules
private SchemaContext schemaContext;
private static final String TEST_MODULE_NAME = "test-module";
private static final String TEST_MODULE_REVISION = "2016-06-02";
private static final String TEST_MODULE_NAMESPACE = "test:module";
- private static final String MOUNT_POINT_IDENT_WITHOUT_SLASH = MOUNT_POINT_IDENT.replaceFirst("/", "");
// mount point and mount point service
private DOMMountPoint mountPoint;
}
/**
- * Negative test of creating <code>InstanceIdentifierContext</code> when identifier is <code>null</code>. Test
- * fails expecting <code>NullPointerException</code>.
+ * Test of creating <code>InstanceIdentifierContext</code> when identifier is <code>null</code>.
+ * <code>{@link YangInstanceIdentifier#EMPTY}</code> should be returned.
*/
@Test
- public void toInstanceIdentifierNullIdentifierNegativeTest() {
- thrown.expect(NullPointerException.class);
- ParserIdentifier.toInstanceIdentifier(null, schemaContext);
+ public void toInstanceIdentifierNullIdentifierTest() {
+ final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(null, schemaContext);
+ assertEquals("Returned not expected identifier",
+ YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
}
/**
}
/**
- * Api path can contains single slash. <code>YangInstanceIdentifier.EMPTY</code> is expected to be returned.
+ * Api path can be empty. <code>YangInstanceIdentifier.EMPTY</code> is expected to be returned.
*/
@Test
- public void toInstanceIdentifierSlashIdentifierTest() {
- final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier("/", schemaContext);
+ public void toInstanceIdentifierEmptyIdentifierTest() {
+ final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier("", schemaContext);
assertEquals("Returned not expected identifier",
YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
}
/**
- * Api path can contains single slash. <code>YangInstanceIdentifier.EMPTY</code> is expected to be returned.
+ * Api path can be empty. <code>YangInstanceIdentifier.EMPTY</code> is expected to be returned.
* Test when identifier contains {@link RestconfConstants#MOUNT}.
*/
@Test
- public void toInstanceIdentifierSlashIdentifierMountPointTest() {
+ public void toInstanceIdentifierEmptyIdentifierMountPointTest() {
final InstanceIdentifierContext<?> context = ParserIdentifier.toInstanceIdentifier(
- "/" + "/" + RestconfConstants.MOUNT, schemaContext);
+ "" + "/" + RestconfConstants.MOUNT, schemaContext);
assertEquals("Returned not expected identifier",
YangInstanceIdentifier.EMPTY, context.getInstanceIdentifier());
}
- /**
- * Negative test of creating <code>InstanceIdentifierContext</code> with empty identifier.
- * <code>IllegalArgumentException</code> is expected.
- */
- @Test
- public void toInstanceIdentifierEmptyIdentifierNegativeTest() {
- thrown.expect(IllegalArgumentException.class);
- ParserIdentifier.toInstanceIdentifier("", schemaContext);
- }
-
- /**
- * Negative test of creating <code>InstanceIdentifierContext</code> from identifier containing
- * {@link RestconfConstants#MOUNT} when identifier part is empty. <code>IllegalArgumentException</code> is expected.
- */
- @Test
- public void toInstanceIdentifierMountPointEmptyIdentifierNegativeTest() {
- thrown.expect(IllegalArgumentException.class);
- ParserIdentifier.toInstanceIdentifier("/" + RestconfConstants.MOUNT, schemaContext);
- }
-
/**
* Negative test with invalid test identifier. Test should fail with <code>IllegalArgumentException</code>.
*/
public void toSchemaExportContextFromIdentifierMountPointTest() {
final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
schemaContext,
- MOUNT_POINT_IDENT_WITHOUT_SLASH + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
+ MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
mountPointService);
final Module module = exportContext.getModule();
public void toSchemaExportContextFromIdentifierMountPointNotFoundTest() {
final SchemaExportContext exportContext = ParserIdentifier.toSchemaExportContextFromIdentifier(
schemaContext,
- MOUNT_POINT_IDENT_WITHOUT_SLASH + "/" + "not-existing-module" + "/" + "2016-01-01",
+ MOUNT_POINT_IDENT + "/" + "not-existing-module" + "/" + "2016-01-01",
mountPointService);
assertNotNull("Export context should be parsed", exportContext);
try {
ParserIdentifier.toSchemaExportContextFromIdentifier(
schemaContext,
- MOUNT_POINT_IDENT_WITHOUT_SLASH + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME,
+ MOUNT_POINT_IDENT + "/" + TEST_MODULE_REVISION + "/" + TEST_MODULE_NAME,
mountPointService);
fail("Test should fail due to invalid identifier supplied");
}
}
- /**
- * Negative test of getting <code>SchemaExportContext</code> with identifier beginning with slash defining module
- * behind mount point. Test is expected to fail with <code>IllegalArgumentException</code>.
- */
- @Test
- public void toSchemaExportContextFromIdentifierMountPointBeginsWithSlashNegativeTest() {
- thrown.expect(IllegalArgumentException.class);
- ParserIdentifier.toSchemaExportContextFromIdentifier(
- schemaContext,
- MOUNT_POINT_IDENT + "/" + TEST_MODULE_NAME + "/" + TEST_MODULE_REVISION,
- mountPointService);
- }
-
/**
* Negative test of getting <code>SchemaExportContext</code> when supplied identifier is null.
* <code>NullPointerException</code> is expected. <code>DOMMountPointService</code> is not used.
thrown.expect(NullPointerException.class);
ParserIdentifier.toSchemaExportContextFromIdentifier(
null,
- MOUNT_POINT_IDENT_WITHOUT_SLASH
+ MOUNT_POINT_IDENT
+ "/"
+ TEST_MODULE_NAME
+ "/"
thrown.expect(NullPointerException.class);
ParserIdentifier.toSchemaExportContextFromIdentifier(
schemaContext,
- MOUNT_POINT_IDENT_WITHOUT_SLASH
+ MOUNT_POINT_IDENT
+ "/"
+ TEST_MODULE_NAME
+ "/"