package org.opendaylight.yangtools.yang.common;
-import java.text.ParseException;
import java.text.SimpleDateFormat;
-import java.util.Date;
public final class SimpleDateFormatUtil {
*/
private static final String REVISION_SIMPLE_DATE = "yyyy-MM-dd";
- /**
- * default Yang date that is used when date is not present.
- */
- private static final String DEFAULT_DATE = "1970-01-01";
-
- /**
- * {@link SimpleDateFormatUtil#DEFAULT_DATE} for revision statement.
- */
- public static final Date DEFAULT_DATE_REV;
-
- static {
- final SimpleDateFormat simpleDateFormat = new SimpleDateFormat(REVISION_SIMPLE_DATE);
-
- try {
- DEFAULT_DATE_REV = simpleDateFormat.parse(DEFAULT_DATE);
- } catch (final ParseException e) {
- throw new ExceptionInInitializerError(e);
- }
- }
-
private SimpleDateFormatUtil() {
throw new UnsupportedOperationException("Utility class should not be instantiated");
}
final UnkeyedListNode hop = (UnkeyedListNode) transformedInput;
final Optional<DataContainerChild<? extends PathArgument, ?>> lrsBits = hop.getChild(0).getChild(
- NodeIdentifier.create(QName.create("foo", "1970-01-01", "lrs-bits")));
+ NodeIdentifier.create(QName.create("foo", "lrs-bits")));
final ImmutableSet<String> expectedValue = ImmutableSet.of("lookup", "rloc-probe", "strict");
assertEquals(expectedValue, lrsBits.get().getValue());
jsonParser.parse(new JsonReader(new StringReader(inputJson)));
fail("IllegalArgumentException should be thrown.");
} catch (IllegalArgumentException e) {
- assertEquals(e.getMessage(),
- "Node '(foo?revision=1970-01-01)lrs-bits' has already set its value to '[lookup]'");
+ assertEquals(e.getMessage(), "Node '(foo)lrs-bits' has already set its value to '[lookup]'");
}
}
}
\ No newline at end of file
import java.io.StringWriter;
import java.io.Writer;
import java.net.URI;
-import java.net.URISyntaxException;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
public class Bug7246Test {
private static final String NS = "my-namespace";
- private static final String REV = "1970-01-01";
@Test
public void test() throws Exception {
}
private static QName qN(final String localName) {
- return QName.create(NS, REV, localName);
+ return QName.create(NS, localName);
}
private static String normalizedNodeToJsonStreamTransformation(final SchemaContext schemaContext,
final SchemaPath path, final Writer writer, final NormalizedNode<?, ?> inputStructure)
- throws IOException, URISyntaxException {
+ throws IOException {
final NormalizedNodeStreamWriter jsonStream = JSONNormalizedNodeStreamWriter.createExclusiveWriter(
- JSONCodecFactory.getShared(schemaContext), path, new URI(NS),
+ JSONCodecFactory.getShared(schemaContext), path, URI.create(NS),
JsonWriterFactory.createJsonWriter(writer, 2));
final NormalizedNodeWriter nodeWriter = NormalizedNodeWriter.forStreamWriter(jsonStream);
nodeWriter.write(inputStructure);
@Test
public void testParsingAttributes() throws Exception {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResource("/bug8745/foo.yang");
- final QName contWithAttributes = QName.create("foo", "1970-01-01", "cont-with-attributes");
+ final QName contWithAttributes = QName.create("foo", "cont-with-attributes");
final ContainerSchemaNode contWithAttr = (ContainerSchemaNode) SchemaContextUtil.findDataSchemaNode(
schemaContext, SchemaPath.create(true, contWithAttributes));
@Test
public void test() throws Exception {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory("/bug8803");
- final SchemaPath topContPath = SchemaPath.create(true, QName.create("foo-ns", "1970-01-01", "top-cont"));
+ final SchemaPath topContPath = SchemaPath.create(true, QName.create("foo-ns", "top-cont"));
final SchemaNode dataSchemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext, topContPath);
assertTrue(dataSchemaNode instanceof ContainerSchemaNode);
final ContainerSchemaNode topContSchema = (ContainerSchemaNode) dataSchemaNode;
public void test() throws Exception {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResourceDirectory("/dom-reader-test");
final ContainerSchemaNode outerContainerSchema = (ContainerSchemaNode) SchemaContextUtil
- .findNodeInSchemaContext(schemaContext, ImmutableList.of(QName.create("foo-ns", "1970-01-01",
- "top-cont")));
+ .findNodeInSchemaContext(schemaContext, ImmutableList.of(QName.create("foo-ns", "top-cont")));
assertNotNull(outerContainerSchema);
// deserialization
@Before
public void setup() {
- bazModule = QNameModule.create(URI.create("baz-namespace"), QName.parseRevision("1970-01-01"));
+ bazModule = QNameModule.create(URI.create("baz-namespace"), null);
outerContainer = QName.create(bazModule, "outer-container");
private static QName myLeafInList3;
@BeforeClass
- public static void setup() throws Exception {
- fooModule = QNameModule.create(new URI("foo-namespace"), QName.parseRevision("1970-01-01"));
+ public static void setup() {
+ fooModule = QNameModule.create(URI.create("foo-namespace"), null);
parentContainer = QName.create(fooModule, "parent-container");
- bazModule = QNameModule.create(new URI("baz-namespace"), QName.parseRevision("1970-01-01"));
+ bazModule = QNameModule.create(URI.create("baz-namespace"), null);
outerContainer = QName.create(bazModule, "outer-container");
myContainer1 = QName.create(bazModule, "my-container-1");
private SchemaContext schemaContext;
@Before
- public void setUp() throws Exception {
- barModuleQName = QNameModule.create(new URI("bar"), QName.parseRevision("1970-01-01"));
+ public void setUp() {
+ barModuleQName = QNameModule.create(URI.create("bar"), null);
myContainer1 = QName.create(barModuleQName, "my-container-1");
myLeaf1 = QName.create(barModuleQName, "my-leaf-1");
myAnyXMLDataBar = QName.create(barModuleQName, "my-anyxml-data");
- fooModuleQName = QNameModule.create(new URI("foo"), QName.parseRevision("1970-01-01"));
+ fooModuleQName = QNameModule.create(URI.create("foo"), null);
myContainer2 = QName.create(fooModuleQName, "my-container-2");
innerContainer = QName.create(fooModuleQName, "inner-container");
myLeaf3 = QName.create(fooModuleQName, "my-leaf-3");
public class YangModeledAnyXMLSerializationTest extends XMLTestCase {
- private final QNameModule bazModuleQName;
- private final QName myAnyXMLDataBaz;
- private final QName bazQName;
- private final QName myContainer2QName;
+ private final QNameModule bazModuleQName = QNameModule.create(URI.create("baz"), null);
+ private final QName myAnyXMLDataBaz = QName.create(bazModuleQName, "my-anyxml-data");
+ private final QName bazQName = QName.create(bazModuleQName, "baz");
+ private final QName myContainer2QName = QName.create(bazModuleQName, "my-container-2");
private final SchemaContext schemaContext;
- public YangModeledAnyXMLSerializationTest() throws Exception {
- bazModuleQName = QNameModule.create(new URI("baz"), QName.parseRevision("1970-01-01"));
- bazQName = QName.create(bazModuleQName, "baz");
- myContainer2QName = QName.create(bazModuleQName, "my-container-2");
- myAnyXMLDataBaz = QName.create(bazModuleQName, "my-anyxml-data");
-
+ public YangModeledAnyXMLSerializationTest() {
schemaContext = YangParserTestUtils.parseYangResourceDirectory("/anyxml-support/serialization");
}
import java.io.FileNotFoundException;
import java.net.URI;
import java.net.URISyntaxException;
-import java.text.ParseException;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.data.api.codec.StringCodec;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
private static final Logger LOG = LoggerFactory.getLogger(StringPatternCheckingCodecTest.class);
@Test
- public void testStringPatternCheckingCodec() throws ReactorException, ParseException, URISyntaxException,
+ public void testStringPatternCheckingCodec() throws ReactorException, URISyntaxException,
FileNotFoundException {
final SchemaContext schemaContext = YangParserTestUtils.parseYangResource(
"/string-pattern-checking-codec-test.yang");
assertNotNull(schemaContext);
- final QNameModule testModuleQName = QNameModule.create(new URI("string-pattern-checking-codec-test"),
- SimpleDateFormatUtil.DEFAULT_DATE_REV);
+ final QNameModule testModuleQName = QNameModule.create(new URI("string-pattern-checking-codec-test"), null);
final Module testModule = schemaContext.findModules("string-pattern-checking-codec-test").iterator().next();
final ContainerSchemaNode testContainer = (ContainerSchemaNode) testModule.getDataChildByName(
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
private static final String FOO_NS = "foo";
private static final String BAR_NS = "bar";
private static final String BAZ_NS = "baz";
- private static final String REV = "1970-01-01";
@Test
- public void test() throws Exception {
+ public void test() {
final SchemaContext context = YangParserTestUtils.parseYangResourceDirectory("/bug7844");
assertNotNull(context);
final Map<QName, LeafRefContext> referencingChilds = leafRefContext.getReferencingChilds();
assertEquals(7, referencingChilds.size());
- final QNameModule bazQNameModule = QNameModule.create(new URI(BAZ_NS),
- SimpleDateFormatUtil.getRevisionFormat().parse(REV));
+ final QNameModule bazQNameModule = QNameModule.create(URI.create(BAZ_NS), null);
final LeafRefPath expectedPathToBazTarget = LeafRefPath.create(true,
new QNameWithPredicateImpl(bazQNameModule, "root", ImmutableList.of()),
new QNameWithPredicateImpl(bazQNameModule, "target", ImmutableList.of()));
assertLeafRef(referencingChilds.get(bar("my-leafref-in-bar")), expectedPathToBazTarget);
assertLeafRef(referencingChilds.get(bar("my-leafref-in-bar-2")), expectedPathToBazTarget);
- final QNameModule barQNameModule = QNameModule.create(new URI(BAR_NS),
- SimpleDateFormatUtil.getRevisionFormat().parse(REV));
+ final QNameModule barQNameModule = QNameModule.create(URI.create(BAR_NS), null);
final LeafRefPath expectedPathToBarTarget = LeafRefPath.create(true,
new QNameWithPredicateImpl(barQNameModule, "bar-target", ImmutableList.of()));
assertLeafRef(referencingChilds.get(foo("direct-leafref")), expectedPathToBarTarget);
}
private static QName foo(final String localName) {
- return QName.create(FOO_NS, REV, localName);
+ return QName.create(FOO_NS, localName);
}
private static QName bar(final String localName) {
- return QName.create(BAR_NS, REV, localName);
+ return QName.create(BAR_NS, localName);
}
private static QName baz(final String localName) {
- return QName.create(BAZ_NS, REV, localName);
+ return QName.create(BAZ_NS, localName);
}
}
public class SchemaUtilsTest {
private static final String NS = "my-namespace";
- private static final String REV = "1970-01-01";
@Test
public void test() throws Exception {
}
private static QName qN(final String localName) {
- return QName.create(NS, REV, localName);
+ return QName.create(NS, localName);
}
}
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableMap.Builder;
-import java.io.File;
import java.net.URI;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
private QNameModule foo;
@Before
- public void init() throws Exception {
- final File resourceFile = new File(Bug4295Test.class.getResource("/bug-4295/foo.yang")
- .toURI());
- context = YangParserTestUtils.parseYangFiles(resourceFile);
- foo = QNameModule.create(new URI("foo"), SimpleDateFormatUtil.getRevisionFormat().parse("1970-01-01"));
+ public void init() {
+ context = YangParserTestUtils.parseYangResource("/bug-4295/foo.yang");
+ foo = QNameModule.create(URI.create("foo"), null);
root = QName.create(foo, "root");
subRoot = QName.create(foo, "sub-root");
outerList = QName.create(foo, "outer-list");
import org.opendaylight.yangtools.yang.data.impl.schema.Builders;
import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
public class Bug8291Test {
private static final String NS = "foo";
- private static final String REV = "1970-01-01";
- private static final QName ROOT = QName.create(NS, REV, "root");
- private static final QName OUTER_LIST = QName.create(NS, REV, "outer-list");
- private static final QName OUTER_LIST_ID = QName.create(NS, REV, "id");
- private static final QName INNER_LIST = QName.create(NS, REV, "inner-list");
+ private static final QName ROOT = QName.create(NS, "root");
+ private static final QName OUTER_LIST = QName.create(NS, "outer-list");
+ private static final QName OUTER_LIST_ID = QName.create(NS, "id");
+ private static final QName INNER_LIST = QName.create(NS, "inner-list");
private SchemaContext schemaContext;
@Before
- public void init() throws ReactorException {
+ public void init() {
this.schemaContext = TestModel.createTestContext("/bug8291/foo.yang");
assertNotNull("Schema context must not be null.", this.schemaContext);
}
import static org.junit.Assert.fail;
import com.google.common.collect.ImmutableMap;
-import java.io.File;
import java.net.URI;
import java.util.Optional;
import org.junit.Before;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
private QName childOrdinaryLeaf;
@Before
- public void setup() throws Exception {
- final File resourceFile = new File(Bug4295Test.class.getResource("/ordered-list-modification-test.yang")
- .toURI());
- context = YangParserTestUtils.parseYangFiles(resourceFile);
- testModule = QNameModule.create(new URI("ordered-list-modification-test"),
- SimpleDateFormatUtil.getRevisionFormat().parse("1970-01-01"));
+ public void setup() {
+ context = YangParserTestUtils.parseYangResource("/ordered-list-modification-test.yang");
+ testModule = QNameModule.create(URI.create("ordered-list-modification-test"), null);
parentContainer = QName.create(testModule, "parent-container");
childContainer = QName.create(testModule, "child-container");
parentOrderedList = QName.create(testModule, "parent-ordered-list");
namespace bar;
prefix bar-mod;
- import baz { prefix baz-imp; revision-date 1970-01-01; }
+ import baz { prefix baz-imp; }
typedef bar-leafref {
type baz-imp:my-leafref;
namespace foo;
prefix foo-mod;
- import bar { prefix bar-imp; revision-date 1970-01-01; }
+ import bar { prefix bar-imp; }
leaf my-leaf {
type foo-leafref;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
-import java.util.Date;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
-import java.util.Optional;
import java.util.Set;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import org.apache.maven.project.MavenProject;
import org.apache.maven.repository.RepositorySystem;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier;
import org.opendaylight.yangtools.yang.model.repo.api.SourceIdentifier;
static SourceIdentifier moduleToIdentifier(final Module module) {
final QNameModule mod = module.getQNameModule();
- final Date rev = mod.getRevision();
- final Optional<String> optRev;
- if (SimpleDateFormatUtil.DEFAULT_DATE_REV.equals(rev)) {
- optRev = Optional.empty();
- } else {
- optRev = Optional.of(mod.getFormattedRevision());
- }
-
- return RevisionSourceIdentifier.create(module.getName(), optRev);
+ final String rev = mod.getFormattedRevision();
+ return rev != null ? RevisionSourceIdentifier.create(module.getName(), rev)
+ : RevisionSourceIdentifier.create(module.getName());
}
}
}
private void emitRevision(final Date date) {
- super.writer.startRevisionNode(date);
-
- //
- // FIXME: BUG-2444: FIXME: BUG-2444: BUG-2417: descriptionNode
- // //FIXME: BUG-2444: Optional
- // FIXME: BUG-2444: FIXME: BUG-2444: BUG-2417: referenceNode
- // //FIXME: BUG-2444: Optional
- super.writer.endNode();
+ if (date != null) {
+ super.writer.startRevisionNode(date);
+ // FIXME: BUG-2444: FIXME: BUG-2444: BUG-2417: descriptionNode
+ // //FIXME: BUG-2444: Optional
+ // FIXME: BUG-2444: FIXME: BUG-2444: BUG-2417: referenceNode
+ // //FIXME: BUG-2444: Optional
+ super.writer.endNode();
+ }
}
private void emitRevisionDateNode(@Nullable final Date date) {
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.common.YangConstants;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
* @return well-formed file name of YIN file as defined in RFC6020.
*/
public static String wellFormedYinName(final String name, final Date revision) {
- return wellFormedYinName(name, SimpleDateFormatUtil.getRevisionFormat().format(revision));
+ return revision == null ? wellFormedYinName(name, (String) null) :
+ wellFormedYinName(name, SimpleDateFormatUtil.getRevisionFormat().format(revision));
}
/**
* @return well-formed file name of YIN file as defined in RFC6020.
*/
public static String wellFormedYinName(final String name, final String revision) {
- return String.format("%s@%s.yin", Preconditions.checkNotNull(name), Preconditions.checkNotNull(revision));
+ if (revision == null) {
+ return name + YangConstants.RFC6020_YIN_FILE_EXTENSION;
+ }
+ return Preconditions.checkNotNull(name) + '@' + revision + YangConstants.RFC6020_YIN_FILE_EXTENSION;
}
/**
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
assertNotNull(output);
assertNotEquals(0, output.length());
- final Document doc = YinExportTestUtils
- .loadDocument(String.format("/bugs/bug2444/yin-effective-emitter/%s@%s.yin", module.getName(),
- SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision())));
+ final Document doc = YinExportTestUtils.loadDocument("/bugs/bug2444/yin-effective-emitter", module);
assertXMLEquals(doc, output);
} finally {
byteArrayOutputStream.close();
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.export.YinExportUtils;
assertNotNull(output);
assertNotEquals(0, output.length());
- final Document doc = YinExportTestUtils.loadDocument(String.format("/bugs/bug2444/yin/%s@%s.yin",
- module.getName(), SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision())));
- assertXMLEquals(doc, output);
+ final Document doc = YinExportTestUtils.loadDocument("/bugs/bug2444/yin", module);
+ assertXMLEquals(module.getName(), doc, output);
} finally {
byteArrayOutputStream.close();
bufferedOutputStream.close();
return builder.build();
}
- private static void assertXMLEquals(final Document expectedXMLDoc, final String output)
+ private static void assertXMLEquals(final String fileName, final Document expectedXMLDoc, final String output)
throws SAXException, IOException {
final String expected = YinExportTestUtils.toString(expectedXMLDoc.getDocumentElement());
final Diff diff = new Diff(expected, output);
diff.overrideElementQualifier(new ElementNameAndAttributeQualifier());
- XMLAssert.assertXMLEqual(diff, true);
+ XMLAssert.assertXMLEqual(fileName, diff, true);
}
}
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.opendaylight.yangtools.util.xml.UntrustedXML;
+import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
+import org.opendaylight.yangtools.yang.common.YangConstants;
+import org.opendaylight.yangtools.yang.model.api.Module;
import org.w3c.dom.Document;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
throw new UnsupportedOperationException("Utility class");
}
+ public static Document loadDocument(final String prefix, final Module module) throws IOException, SAXException {
+ final String fileName = module.getRevision() == null ? module.getName()
+ : module.getName() + '@' + SimpleDateFormatUtil.getRevisionFormat().format(module.getRevision());
+ return loadDocument(prefix + '/' + fileName + YangConstants.RFC6020_YIN_FILE_EXTENSION);
+ }
+
public static Document loadDocument(final String xmlPath) throws IOException, SAXException {
final InputStream resourceAsStream = SchemaContextEmitterTest.class.getResourceAsStream(xmlPath);
final Document currentConfigElement = readXmlToDocument(resourceAsStream);
prefix iy1;
yang-version 1;
- import action { prefix ac; revision-date 1970-01-01; }
+ import action { prefix ac; }
revision 1970-01-01;
}
prefix i;
yang-version 1.1;
- import action { description "txt"; reference "ref"; prefix ac; revision-date 1970-01-01; }
+ import action { description "txt"; reference "ref"; prefix ac; }
}
import deviation-target { prefix dev-tgt; revision-date 2017-01-20; reference "import ref"; description "import desc"; }
include submodule {
- revision-date 1970-01-01;
reference "include ref";
description "include desc";
}
<yang-version value="1.1"></yang-version>
<namespace uri="notification"></namespace>
<prefix value="n"></prefix>
- <revision date="1970-01-01"></revision>
<grouping name="grp">
<status value="current"></status>
<notification name="n5">
<status value="current"></status>
</container>
</notification>
-</module>
\ No newline at end of file
+</module>
<yang-version value="1" />
<import module="action">
<prefix value="ac" />
- <revision-date date="1970-01-01" />
</import>
<revision date="1970-01-01" />
</module>
<text>ref</text>
</reference>
<prefix value="ac" />
- <revision-date date="1970-01-01" />
</import>
</module>
</description>
</import>
<include module="submodule">
- <revision-date date="1970-01-01" />
<reference>
<text>include ref</text>
</reference>
public abstract class AbstractSchemaContext implements SchemaContext {
protected static final Comparator<Module> REVISION_COMPARATOR = (o1, o2) -> {
- if (o2.getRevision() == null) {
- return -1;
+ if (o1.getRevision() == null) {
+ return o2.getRevision() == null ? 0 : 1;
}
- return o2.getRevision().compareTo(o1.getRevision());
+ return o2.getRevision() == null ? -1 : o2.getRevision().compareTo(o1.getRevision());
};
protected static final TreeSet<Module> createModuleSet() {
*/
package org.opendaylight.yangtools.yang.model.util;
-import static org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil.DEFAULT_DATE_REV;
-
import com.google.common.annotations.Beta;
import com.google.common.collect.HashBasedTable;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.Map;
import java.util.Objects;
+import java.util.Optional;
import org.opendaylight.yangtools.util.TopologicalSort;
import org.opendaylight.yangtools.util.TopologicalSort.Node;
import org.opendaylight.yangtools.util.TopologicalSort.NodeImpl;
}
private static List<Node> sortInternal(final Iterable<Module> modules) {
- final Table<String, Date, ModuleNodeImpl> moduleGraph = createModuleGraph(modules);
+ final Table<String, Optional<Date>, ModuleNodeImpl> moduleGraph = createModuleGraph(modules);
return TopologicalSort.sort(new HashSet<>(moduleGraph.values()));
}
- private static Table<String, Date, ModuleNodeImpl> createModuleGraph(final Iterable<Module> builders) {
- final Table<String, Date, ModuleNodeImpl> moduleGraph = HashBasedTable.create();
+ private static Table<String, Optional<Date>, ModuleNodeImpl> createModuleGraph(final Iterable<Module> builders) {
+ final Table<String, Optional<Date>, ModuleNodeImpl> moduleGraph = HashBasedTable.create();
processModules(moduleGraph, builders);
processDependencies(moduleGraph, builders);
/**
* Extract module:revision from modules.
*/
- private static void processDependencies(final Table<String, Date, ModuleNodeImpl> moduleGraph,
+ private static void processDependencies(final Table<String, Optional<Date>, ModuleNodeImpl> moduleGraph,
final Iterable<Module> mmbs) {
final Map<URI, Module> allNS = new HashMap<>();
final Map<String, Date> imported = new HashMap<>();
final String fromName = module.getName();
final URI ns = module.getNamespace();
- Date fromRevision = module.getRevision();
+ final Date fromRevision = module.getRevision();
// check for existence of module with same namespace
final Module prev = allNS.putIfAbsent(ns, module);
}
}
- // no need to check if other Type of object, check is performed in
- // process modules
-
- if (fromRevision == null) {
- fromRevision = DEFAULT_DATE_REV;
- }
-
+ // no need to check if other Type of object, check is performed in process modules
for (final ModuleImport imprt : module.getImports()) {
final String toName = imprt.getModuleName();
- final Date toRevision = imprt.getRevision() == null ? DEFAULT_DATE_REV : imprt.getRevision();
-
- final ModuleNodeImpl from = moduleGraph.get(fromName, fromRevision);
+ final Date toRevision = imprt.getRevision();
+ final ModuleNodeImpl from = moduleGraph.get(fromName, Optional.ofNullable(fromRevision));
final ModuleNodeImpl to = getModuleByNameAndRevision(moduleGraph, fromName, fromRevision, toName,
toRevision);
*/
if (module.getYangVersion() == YangVersion.VERSION_1) {
final Date impRevision = imported.get(toName);
- if (impRevision != null && !impRevision.equals(toRevision)
- && !DEFAULT_DATE_REV.equals(impRevision) && !DEFAULT_DATE_REV.equals(toRevision)) {
+ if (impRevision != null && !impRevision.equals(toRevision) && toRevision != null) {
throw new IllegalArgumentException(String.format(
"Module:%s imported twice with different revisions:%s, %s", toName,
formatRevDate(impRevision), formatRevDate(toRevision)));
/**
* Get imported module by its name and revision from moduleGraph.
*/
- private static ModuleNodeImpl getModuleByNameAndRevision(final Table<String, Date, ModuleNodeImpl> moduleGraph,
+ private static ModuleNodeImpl getModuleByNameAndRevision(
+ final Table<String, Optional<Date>, ModuleNodeImpl> moduleGraph,
final String fromName, final Date fromRevision, final String toName, final Date toRevision) {
- final ModuleNodeImpl exact = moduleGraph.get(toName, toRevision);
+ final ModuleNodeImpl exact = moduleGraph.get(toName, Optional.ofNullable(toRevision));
if (exact != null) {
return exact;
}
// If revision is not specified in import, but module exists with different revisions, take first one
- if (DEFAULT_DATE_REV.equals(toRevision)) {
- final Map<Date, ModuleNodeImpl> modulerevs = moduleGraph.row(toName);
+ if (toRevision == null) {
+ final Map<Optional<Date>, ModuleNodeImpl> modulerevs = moduleGraph.row(toName);
if (!modulerevs.isEmpty()) {
final ModuleNodeImpl first = modulerevs.values().iterator().next();
/**
* Extract dependencies from modules to fill dependency graph.
*/
- private static void processModules(final Table<String, Date, ModuleNodeImpl> moduleGraph,
+ private static void processModules(final Table<String, Optional<Date>, ModuleNodeImpl> moduleGraph,
final Iterable<Module> modules) {
// Process nodes
for (final Module momb : modules) {
final String name = momb.getName();
- Date rev = momb.getRevision();
- if (rev == null) {
- rev = DEFAULT_DATE_REV;
- }
+ final Optional<Date> rev = Optional.ofNullable(momb.getRevision());
- final Map<Date, ModuleNodeImpl> revs = moduleGraph.row(name);
+ final Map<Optional<Date>, ModuleNodeImpl> revs = moduleGraph.row(name);
if (revs.containsKey(rev)) {
throw new IllegalArgumentException(String.format("Module:%s with revision:%s declared twice", name,
- formatRevDate(rev)));
+ formatRevDate(rev.orElse(null))));
}
- revs.put(rev, new ModuleNodeImpl(name, rev, momb));
+ revs.put(rev, new ModuleNodeImpl(name, rev.orElse(null), momb));
}
}
private static String formatRevDate(final Date rev) {
- return rev.equals(DEFAULT_DATE_REV) ? "default" : SimpleDateFormatUtil.getRevisionFormat().format(rev);
+ return rev == null ? "default" : SimpleDateFormatUtil.getRevisionFormat().format(rev);
}
private static final class ModuleNodeImpl extends NodeImpl {
import java.util.Optional;
import org.opendaylight.yangtools.concepts.SemVer;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
stmt.addContext(PreLinkageModuleNamespace.class, moduleName, stmt);
- Optional<Date> revisionDate = Optional.ofNullable(StmtContextUtils.getLatestRevision(
+ final Optional<Date> revisionDate = Optional.ofNullable(StmtContextUtils.getLatestRevision(
stmt.declaredSubstatements()));
- if (!revisionDate.isPresent()) {
- revisionDate = Optional.of(SimpleDateFormatUtil.DEFAULT_DATE_REV);
- }
-
final QNameModule qNameModule = QNameModule.create(moduleNs, revisionDate.orElse(null)).intern();
stmt.addToNs(ModuleCtxToModuleQName.class, stmt, qNameModule);
SourceException.throwIf(!moduleNs.isPresent(), stmt.getStatementSourceReference(),
"Namespace of the module [%s] is missing", stmt.getStatementArgument());
- Optional<Date> revisionDate = Optional.ofNullable(StmtContextUtils.getLatestRevision(
+ final Optional<Date> revisionDate = Optional.ofNullable(StmtContextUtils.getLatestRevision(
stmt.declaredSubstatements()));
- if (!revisionDate.isPresent()) {
- revisionDate = Optional.of(SimpleDateFormatUtil.DEFAULT_DATE_REV);
- }
-
final QNameModule qNameModule = QNameModule.create(moduleNs.get(), revisionDate.orElse(null)).intern();
final StmtContext<?, ModuleStatement, EffectiveStatement<String, ModuleStatement>> possibleDuplicateModule =
stmt.getFromNamespace(NamespaceToModule.class, qNameModule);
import java.util.Date;
import java.util.Optional;
import javax.annotation.Nonnull;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier;
import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
.addAny(YangStmtMapping.USES)
.addOptional(YangStmtMapping.YANG_VERSION)
.build();
- private static final Optional<Date> DEFAULT_REVISION = Optional.of(SimpleDateFormatUtil.DEFAULT_DATE_REV);
protected SubmoduleStatementImpl(final StmtContext<String, SubmoduleStatement, ?> context) {
super(context);
private static ModuleIdentifier getSubmoduleIdentifier(
final Mutable<String, SubmoduleStatement, EffectiveStatement<String, SubmoduleStatement>> stmt) {
final Date maybeDate = StmtContextUtils.getLatestRevision(stmt.declaredSubstatements());
- final Optional<Date> revisionDate = maybeDate != null ? Optional.of(maybeDate) : DEFAULT_REVISION;
final ModuleIdentifier submoduleIdentifier = ModuleIdentifierImpl.create(stmt.getStatementArgument(),
- revisionDate);
+ Optional.ofNullable(maybeDate));
return submoduleIdentifier;
}
*/
package org.opendaylight.yangtools.yang.parser.stmt.rfc6020.effective;
+import com.google.common.base.Verify;
import java.util.Objects;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.ModuleStatement;
import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
final StmtContext<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> ctx) {
super(ctx);
- final QNameModule module = ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx);
- if (module.getRevision() == null) {
- qnameModule = QNameModule.create(module.getNamespace(), SimpleDateFormatUtil.DEFAULT_DATE_REV).intern();
- } else {
- qnameModule = module;
- }
+ qnameModule = Verify.verifyNotNull(ctx.getFromNamespace(ModuleCtxToModuleQName.class, ctx));
}
@Override
import java.util.Objects;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.BelongsToStatement;
import org.opendaylight.yangtools.yang.model.api.stmt.SubmoduleStatement;
final QNameModule belongsToModuleQName = ctx.getFromNamespace(ModuleNameToModuleQName.class,
belongsToModuleName);
final RevisionEffectiveStatementImpl submoduleRevision = firstEffective(RevisionEffectiveStatementImpl.class);
- this.qnameModule = (submoduleRevision == null
- ? QNameModule.create(belongsToModuleQName.getNamespace(), SimpleDateFormatUtil.DEFAULT_DATE_REV)
- : QNameModule.create(belongsToModuleQName.getNamespace(), submoduleRevision.argument()))
- .intern();
+ this.qnameModule = QNameModule.create(belongsToModuleQName.getNamespace(),
+ submoduleRevision == null ? null : submoduleRevision.argument()).intern();
}
@Override
private static final String BAR_REV_2 = "1999-01-01";
private static final String BAR_REV_3 = "1970-01-01";
private static final String FOO_NS = "foo";
- private static final String FOO_REV = "1970-01-01";
@Test
public void testYang11() throws Exception {
}
private static QName foo(final String localName) {
- return QName.create(FOO_NS, FOO_REV, localName);
+ return QName.create(FOO_NS, localName);
}
private static QName bar1(final String localName) {
@Test
public void testSharedSchemaRepositoryWithSomeFeaturesSupported() throws Exception {
- final Set<QName> supportedFeatures = ImmutableSet.of(QName.create("foobar-namespace", "1970-01-01", "test-feature-1"));
+ final Set<QName> supportedFeatures = ImmutableSet.of(QName.create("foobar-namespace", "test-feature-1"));
final SharedSchemaRepository sharedSchemaRepository = new SharedSchemaRepository(
"shared-schema-repo-with-features-test");
public class Bug5410Test {
private static final String FOO_NS = "foo";
- private static final String FOO_REV = "1970-01-01";
@Test
public void testJavaRegexFromXSD() {
}
private static QName foo(final String localName) {
- return QName.create(FOO_NS, FOO_REV, localName);
+ return QName.create(FOO_NS, localName);
}
@SuppressWarnings("checkstyle:regexpSinglelineJava")
public class Bug6868Test {
private static final String FOO_NS = "foo";
- private static final String FOO_REV = "1970-01-01";
private static final String IMP_NS = "imp";
private static final String IMP_REV = "2017-01-09";
private static final Set<String> ALL_CONTAINERS = ImmutableSet.of("my-container-1", "my-container-2",
final Set<QName> supportedFeatures = new HashSet<>();
for (final String featureName : featureNames) {
if (featureName.indexOf(':') == -1) {
- supportedFeatures.add(QName.create(FOO_NS, FOO_REV, featureName));
+ supportedFeatures.add(QName.create(FOO_NS, featureName));
} else {
supportedFeatures
.add(QName.create(IMP_NS, IMP_REV, featureName.substring(featureName.indexOf(':') + 1)));
private static SchemaNode findNode(final SchemaContext context, final String localName) {
return SchemaContextUtil.findDataSchemaNode(context,
- SchemaPath.create(true, QName.create(FOO_NS, FOO_REV, localName)));
+ SchemaPath.create(true, QName.create(FOO_NS, localName)));
}
@Test
public class Bug6869Test {
private static final String FOO_NS = "foo";
- private static final String FOO_REV = "1970-01-01";
@Test
public void identityNoFeaureTest() throws Exception {
private static Set<QName> createFeaturesSet(final String... featureNames) {
final Set<QName> supportedFeatures = new HashSet<>();
for (final String featureName : featureNames) {
- supportedFeatures.add(QName.create(FOO_NS, FOO_REV, featureName));
+ supportedFeatures.add(QName.create(FOO_NS, featureName));
}
return ImmutableSet.copyOf(supportedFeatures);
private static SchemaNode findNode(final SchemaContext context, final Iterable<String> localNamesPath) {
final Iterable<QName> qNames = Iterables.transform(localNamesPath,
- localName -> QName.create(FOO_NS, FOO_REV, localName));
+ localName -> QName.create(FOO_NS, localName));
return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qNames, true));
}
public class Bug6870Test {
private static final String FOO_NS = "foo";
- private static final String FOO_REV = "1970-01-01";
@Test
public void valid11Test() throws Exception {
private static SchemaNode findNode(final SchemaContext context, final Iterable<String> localNamesPath) {
final Iterable<QName> qNames = Iterables.transform(localNamesPath,
- localName -> QName.create(FOO_NS, FOO_REV, localName));
+ localName -> QName.create(FOO_NS, localName));
return SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(qNames, true));
}
private static final String BAR_NS = "bar";
private static final String BAR_REV = "2017-01-11";
private static final String FOO_NS = "foo";
- private static final String FOO_REV = "1970-01-01";
@Test
public void yang11Test() throws Exception {
}
private static QName foo(final String localName) {
- return QName.create(FOO_NS, FOO_REV, localName);
+ return QName.create(FOO_NS, localName);
}
private static QName bar(final String localName) {
public class Bug6880Test {
private static final String FOO_NS = "foo";
- private static final String FOO_REV = "1970-01-01";
@Test
public void valid10Test() throws Exception {
assertNotNull(schemaContext);
final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(schemaContext,
- SchemaPath.create(true, QName.create(FOO_NS, FOO_REV, "my-leaf-list")));
+ SchemaPath.create(true, QName.create(FOO_NS, "my-leaf-list")));
assertTrue(findDataSchemaNode instanceof LeafListSchemaNode);
final LeafListSchemaNode myLeafList = (LeafListSchemaNode) findDataSchemaNode;
public class Bug6883Test {
private static final String FOO_NS = "foo";
- private static final String FOO_REV = "1970-01-01";
@Test
public void test() throws Exception {
private static AnyDataSchemaNode assertAnyData(final SchemaContext context, final Iterable<String> localNamesPath) {
final Iterable<QName> qNames = Iterables.transform(localNamesPath,
- localName -> QName.create(FOO_NS, FOO_REV, localName));
+ localName -> QName.create(FOO_NS, localName));
final SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context,
SchemaPath.create(qNames, true));
assertTrue(findDataSchemaNode instanceof AnyDataSchemaNode);
public class Bug6884Test {
private static final String FOO_NS = "foo";
- private static final String FOO_REV = "1970-01-01";
@Test
public void testYang11() throws Exception {
}
private static QName foo(final String localName) {
- return QName.create(FOO_NS, FOO_REV, localName);
+ return QName.create(FOO_NS, localName);
}
}
public class Bug6897Test {
private static final String FOO_NS = "foo";
- private static final String FOO_REV = "1970-01-01";
@Test
public void notificationsInDataContainersTest() throws Exception {
private static void assertContainsNotifications(final SchemaContext schemaContext, final String dataContainerName,
final String... notificationNames) {
- final DataSchemaNode dataChildByName = schemaContext.getDataChildByName(QName.create(FOO_NS, FOO_REV,
- dataContainerName));
+ final DataSchemaNode dataChildByName = schemaContext.getDataChildByName(
+ QName.create(FOO_NS, dataContainerName));
assertTrue(dataChildByName instanceof NotificationNodeContainer);
assertContainsNotifications((NotificationNodeContainer) dataChildByName, notificationNames);
}
notifications.forEach(n -> notificationQNames.add(n.getQName()));
for (final String notificationName : notificationNames) {
- assertTrue(notificationQNames.contains(QName.create(FOO_NS, FOO_REV, notificationName)));
+ assertTrue(notificationQNames.contains(QName.create(FOO_NS, notificationName)));
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Notification (foo?revision=1970-01-01)grp-notification is defined within an rpc, action, or another "
- + "notification"));
+ "Notification (foo)grp-notification is defined within an rpc, action, or another notification"));
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Leaf '(foo?revision=1970-01-01)enum-leaf' has default value 'two' marked with an if-feature "
- + "statement."));
+ "Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."));
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Leaf '(foo?revision=1970-01-01)enum-leaf' has default value 'two' marked with an if-feature "
- + "statement."));
+ "Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."));
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Leaf '(foo?revision=1970-01-01)enum-leaf' has default value 'two' marked with an if-feature "
- + "statement."));
+ "Leaf '(foo)enum-leaf' has default value 'two' marked with an if-feature statement."));
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Typedef '(foo?revision=1970-01-01)bits-typedef-2' has default value 'two' marked with an "
- + "if-feature statement."));
+ "Typedef '(foo)bits-typedef-2' has default value 'two' marked with an if-feature statement."));
}
}
fail("Test should fail due to invalid Yang 1.1");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Leaf '(foo?revision=1970-01-01)union-leaf' has default value 'two' marked with an if-feature "
- + "statement."));
+ "Leaf '(foo)union-leaf' has default value 'two' marked with an if-feature statement."));
}
}
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.AnyXmlSchemaNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
private static final StatementStreamSource AUGMENTED = sourceForResource("/stmt-test/augments/augmented.yang");
private static final StatementStreamSource ROOT = sourceForResource("/stmt-test/augments/aug-root.yang");
- private static final QNameModule ROOT_QNAME_MODULE = QNameModule.create(
- URI.create("root"), SimpleDateFormatUtil.DEFAULT_DATE_REV);
- private static final QNameModule AUGMENTED_QNAME_MODULE = QNameModule
- .create(URI.create("aug"), SimpleDateFormatUtil.DEFAULT_DATE_REV);
+ private static final QNameModule ROOT_QNAME_MODULE = QNameModule.create(URI.create("root"), null);
+ private static final QNameModule AUGMENTED_QNAME_MODULE = QNameModule.create(URI.create("aug"), null);
private final QName augParent1 = QName.create(AUGMENTED_QNAME_MODULE,
"aug-parent1");
"/stmt-test/augments/multiple-augment-incorrect2.yang");
@Test
- public void multipleAugmentsAndMultipleModulesTest() throws SourceException, ReactorException {
+ public void multipleAugmentsAndMultipleModulesTest() throws ReactorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
.newBuild();
addSources(reactor, MULTIPLE_AUGMENT_ROOT, MULTIPLE_AUGMENT_IMPORTED,
}
@Test
- public void multipleAugmentTest() throws SourceException, ReactorException {
+ public void multipleAugmentTest() throws ReactorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
.newBuild();
addSources(reactor, MULTIPLE_AUGMENT);
}
@Test(expected = SomeModifiersUnresolvedException.class)
- public void multipleAugmentIncorrectPathTest() throws SourceException, ReactorException {
+ public void multipleAugmentIncorrectPathTest() throws ReactorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
.newBuild();
addSources(reactor, MULTIPLE_AUGMENT_INCORRECT);
}
@Test(expected = SomeModifiersUnresolvedException.class)
- public void multipleAugmentIncorrectPathAndGrpTest() throws SourceException, ReactorException {
+ public void multipleAugmentIncorrectPathAndGrpTest() throws ReactorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
.newBuild();
addSources(reactor, MULTIPLE_AUGMENT_INCORRECT2);
}
@Test
- public void readAndParseYangFileTest() throws SourceException, ReactorException {
+ public void readAndParseYangFileTest() throws ReactorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
.newBuild();
addSources(reactor, AUGMENTED, ROOT);
import static org.junit.Assert.assertTrue;
import java.net.URI;
-import java.util.Date;
import java.util.List;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
public void test() throws Exception {
SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug3874");
- Date revision = QName.parseRevision("1970-01-01");
- QNameModule foo = QNameModule.create(new URI("foo"), revision);
+ QNameModule foo = QNameModule.create(new URI("foo"), null);
QName myContainer2QName = QName.create(foo, "my-container-2");
QName myAnyXmlDataQName = QName.create(foo, "my-anyxml-data");
DataSchemaNode dataChildByName = context.getDataChildByName(myAnyXmlDataQName);
assertTrue(dataChildByName instanceof YangModeledAnyXmlEffectiveStatementImpl);
- YangModeledAnyXmlEffectiveStatementImpl yangModeledAnyXml = (YangModeledAnyXmlEffectiveStatementImpl) dataChildByName;
+ YangModeledAnyXmlEffectiveStatementImpl yangModeledAnyXml =
+ (YangModeledAnyXmlEffectiveStatementImpl) dataChildByName;
- SchemaNode myContainer2 = SchemaContextUtil.findDataSchemaNode(context, SchemaPath.create(true, myContainer2QName));
+ SchemaNode myContainer2 = SchemaContextUtil.findDataSchemaNode(context,
+ SchemaPath.create(true, myContainer2QName));
assertTrue(myContainer2 instanceof ContainerSchemaNode);
assertEquals(myContainer2, yangModeledAnyXml.getSchemaOfAnyXmlData());
UnknownSchemaNode next = unknownSchemaNodes.iterator().next();
assertTrue(next instanceof AnyxmlSchemaLocationEffectiveStatementImpl);
- AnyxmlSchemaLocationEffectiveStatementImpl anyxmlSchemaLocationUnknownNode= (AnyxmlSchemaLocationEffectiveStatementImpl) next;
- assertEquals(SupportedExtensionsMapping.ANYXML_SCHEMA_LOCATION.getStatementName(), anyxmlSchemaLocationUnknownNode.getNodeType());
- assertEquals(SupportedExtensionsMapping.ANYXML_SCHEMA_LOCATION.getStatementName(), anyxmlSchemaLocationUnknownNode.getQName());
+ AnyxmlSchemaLocationEffectiveStatementImpl anyxmlSchemaLocationUnknownNode =
+ (AnyxmlSchemaLocationEffectiveStatementImpl) next;
+ assertEquals(SupportedExtensionsMapping.ANYXML_SCHEMA_LOCATION.getStatementName(),
+ anyxmlSchemaLocationUnknownNode.getNodeType());
+ assertEquals(SupportedExtensionsMapping.ANYXML_SCHEMA_LOCATION.getStatementName(),
+ anyxmlSchemaLocationUnknownNode.getQName());
}
}
Throwable rootCause = Throwables.getRootCause(e);
assertTrue(rootCause instanceof InferenceException);
final String message = rootCause.getMessage();
- assertTrue(message.startsWith("Type [(foo?revision=1970-01-01)"));
+ assertTrue(message.startsWith("Type [(foo)"));
assertTrue(message.contains("was not found"));
}
}
package org.opendaylight.yangtools.yang.stmt;
-import static org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil.DEFAULT_DATE_REV;
-
import com.google.common.collect.Range;
import java.io.File;
import java.net.URI;
final SchemaContext schemaContext = TestUtils.parseYangSources(extdef, stringWithExt);
final LeafSchemaNode leaf = (LeafSchemaNode) typesModule(schemaContext).getDataChildByName(
- QName.create(URI.create("urn:custom.types.demo"), DEFAULT_DATE_REV, "leaf-length-pattern-unknown"));
+ QName.create(URI.create("urn:custom.types.demo"), null, "leaf-length-pattern-unknown"));
// then
Assert.assertNotNull(leaf);
final SchemaContext schemaContext = TestUtils.parseYangSources(extdef, stringWithExt);
final LeafSchemaNode leaf = (LeafSchemaNode) typesModule(schemaContext).getDataChildByName(
- QName.create(URI.create("urn:custom.types.demo"), DEFAULT_DATE_REV, "leaf-length-unknown-pattern"));
+ QName.create(URI.create("urn:custom.types.demo"), null, "leaf-length-unknown-pattern"));
// then
Assert.assertNotNull(leaf);
final SchemaContext schemaContext = TestUtils.parseYangSources(extdef, stringWithExt);
final LeafSchemaNode leaf = (LeafSchemaNode) typesModule(schemaContext).getDataChildByName(
- QName.create(URI.create("urn:custom.types.demo"), DEFAULT_DATE_REV, "leaf-unknown-length-pattern"));
+ QName.create(URI.create("urn:custom.types.demo"), null, "leaf-unknown-length-pattern"));
// then
Assert.assertNotNull(leaf);
SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5396");
assertNotNull(context);
- QName root = QName.create("foo", "1970-01-01", "root");
- QName myLeaf2 = QName.create("foo", "1970-01-01", "my-leaf2");
+ QName root = QName.create("foo", "root");
+ QName myLeaf2 = QName.create("foo", "my-leaf2");
SchemaPath schemaPath = SchemaPath.create(true, root, myLeaf2);
SchemaNode findDataSchemaNode = SchemaContextUtil.findDataSchemaNode(context, schemaPath);
final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug5518");
assertNotNull(context);
- final DataSchemaNode dataChildByName = context.getDataChildByName(QName.create("foo", "1970-01-01", "root"));
+ final DataSchemaNode dataChildByName = context.getDataChildByName(QName.create("foo", "root"));
assertTrue(dataChildByName instanceof ContainerSchemaNode);
final ContainerSchemaNode root = (ContainerSchemaNode) dataChildByName;
final Set<MustDefinition> mustConstraints = root.getConstraints().getMustConstraints();
public class Bug6183Test {
private static final String FOO_NS = "foo";
- private static final String FOO_REV = "1970-01-01";
@Test
public void testYang10() throws Exception {
assertEquals(2, secondImplCaseContainer.getChildNodes().size());
assertTrue(getLeafSchemaNode(secondImplCaseContainer, "leaf-inside-second-container").isAugmenting());
- assertFalse(getLeafSchemaNode(secondImplCaseContainer, "declared-leaf-in-second-case-container").isAugmenting());
+ assertFalse(getLeafSchemaNode(secondImplCaseContainer, "declared-leaf-in-second-case-container")
+ .isAugmenting());
}
- private static ContainerSchemaNode getContainerSchemaNode(final DataNodeContainer parent, final String containerName) {
+ private static ContainerSchemaNode getContainerSchemaNode(final DataNodeContainer parent,
+ final String containerName) {
final DataSchemaNode dataChildByName = parent.getDataChildByName(foo(containerName));
assertTrue(dataChildByName instanceof ContainerSchemaNode);
return (ContainerSchemaNode) dataChildByName;
}
private static QName foo(final String localName) {
- return QName.create(FOO_NS, FOO_REV, localName);
+ return QName.create(FOO_NS, localName);
}
}
}
private static void verifyEnumTypedefinition(final SchemaContext context) {
- final DataSchemaNode dataChildByName = context.getDataChildByName(QName
- .create("foo", "1970-01-01", "enum-leaf"));
+ final DataSchemaNode dataChildByName = context.getDataChildByName(QName.create("foo", "enum-leaf"));
assertTrue(dataChildByName instanceof LeafSchemaNode);
final LeafSchemaNode enumLeaf = (LeafSchemaNode) dataChildByName;
final TypeDefinition<? extends TypeDefinition<?>> type = enumLeaf.getType();
}
private static void verifyBitsTypedefinition(final SchemaContext context) {
- final DataSchemaNode dataChildByName = context.getDataChildByName(QName
- .create("foo", "1970-01-01", "bits-leaf"));
+ final DataSchemaNode dataChildByName = context.getDataChildByName(QName.create("foo", "bits-leaf"));
assertTrue(dataChildByName instanceof LeafSchemaNode);
final LeafSchemaNode bitsLeaf = (LeafSchemaNode) dataChildByName;
final TypeDefinition<? extends TypeDefinition<?>> type = bitsLeaf.getType();
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
-import static org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil.DEFAULT_DATE_REV;
import static org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil.getRevisionFormat;
import java.text.ParseException;
@Test
public void tetststs() throws Exception {
- testRevision("withoutRevision", DEFAULT_DATE_REV, DEFAULT_DATE_REV);
+ testRevision("withoutRevision", null, null);
testRevision("withRevision", date, date);
- testRevision("importedModuleRevisionOnly", DEFAULT_DATE_REV, date);
- testRevision("moduleRevisionOnly", date, DEFAULT_DATE_REV);
+ testRevision("importedModuleRevisionOnly", null, date);
+ testRevision("moduleRevisionOnly", date, null);
}
private static void testRevision(final String path, final Date moduleRevision, final Date importedRevision)
public class Bug6771Test {
private static final String NS = "http://www.example.com/typedef-bug";
- private static final String REV = "1970-01-01";
- private static final QName ROOT = QName.create(NS, REV, "root");
- private static final QName CONT_B = QName.create(NS, REV, "container-b");
- private static final QName LEAF_CONT_B = QName.create(NS, REV, "leaf-container-b");
- private static final QName INNER_CONTAINER = QName.create(NS, REV, "inner-container");
+ private static final QName ROOT = QName.create(NS, "root");
+ private static final QName CONT_B = QName.create(NS, "container-b");
+ private static final QName LEAF_CONT_B = QName.create(NS, "leaf-container-b");
+ private static final QName INNER_CONTAINER = QName.create(NS, "inner-container");
@Test
public void augmentTest() throws Exception {
final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug6771/choice-case");
assertNotNull(context);
- final QName myChoice = QName.create(NS, REV, "my-choice");
- final QName caseOne = QName.create(NS, REV, "one");
- final QName caseTwo = QName.create(NS, REV, "two");
- final QName caseThree = QName.create(NS, REV, "three");
- final QName containerOne = QName.create(NS, REV, "container-one");
- final QName containerTwo = QName.create(NS, REV, "container-two");
- final QName containerThree = QName.create(NS, REV, "container-three");
+ final QName myChoice = QName.create(NS, "my-choice");
+ final QName caseOne = QName.create(NS, "one");
+ final QName caseTwo = QName.create(NS, "two");
+ final QName caseThree = QName.create(NS, "three");
+ final QName containerOne = QName.create(NS, "container-one");
+ final QName containerTwo = QName.create(NS, "container-two");
+ final QName containerThree = QName.create(NS, "container-three");
verifyLeafType(SchemaContextUtil.findDataSchemaNode(context,
SchemaPath.create(true, ROOT, myChoice, caseOne, containerOne, LEAF_CONT_B)));
public class Bug7037Test {
private static final String FOO_NS = "foo";
private static final String BAR_NS = "bar";
- private static final String REV = "1970-01-01";
@Test
public void test() throws Exception {
}
private static QName foo(final String localName) {
- return QName.create(FOO_NS, REV, localName);
+ return QName.create(FOO_NS, localName);
}
private static QName bar(final String localName) {
- return QName.create(BAR_NS, REV, localName);
+ return QName.create(BAR_NS, localName);
}
}
fail("Test should fail due to invalid yang model.");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
- + "Node name collision: '(foo?revision=1970-01-01)name' already declared"));
+ "Error in module 'foo': cannot add '(foo)name'. Node name collision: '(foo)name' already declared"));
}
}
fail("Test should fail due to invalid yang model.");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
- + "Node name collision: '(foo?revision=1970-01-01)name' already declared"));
+ "Error in module 'foo': cannot add '(foo)name'. Node name collision: '(foo)name' already declared"));
}
}
fail("Test should fail due to invalid yang model.");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
- + "Node name collision: '(foo?revision=1970-01-01)name' already declared"));
+ "Error in module 'foo': cannot add '(foo)name'. Node name collision: '(foo)name' already declared"));
}
}
fail("Test should fail due to invalid yang model.");
} catch (final SomeModifiersUnresolvedException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Error in module 'foo': cannot add '(foo?revision=1970-01-01)name'. "
- + "Node name collision: '(foo?revision=1970-01-01)name' already declared"));
+ "Error in module 'foo': cannot add '(foo)name'. Node name collision: '(foo)name' already declared"));
}
}
}
public class Bug7865Test {
private static final String NS = "foo";
- private static final String REV = "1970-01-01";
@Test
public void test() throws Exception {
}
private static QName foo(final String localName) {
- return QName.create(NS, REV, localName);
+ return QName.create(NS, localName);
}
}
public class Bug7879Test {
private static final String NS = "my-model-ns";
- private static final String REV = "1970-01-01";
@Test
public void test() throws Exception {
final SchemaContext context = TestUtils.parseYangSources("/bugs/bug7879");
assertNotNull(context);
- assertTrue(findNode(context, ImmutableList.of(qN("my-alarm"), qN("my-content"), qN("my-event-container"))) instanceof ContainerSchemaNode);
+ assertTrue(findNode(context, ImmutableList.of(qN("my-alarm"), qN("my-content"), qN("my-event-container")))
+ instanceof ContainerSchemaNode);
final SchemaNode myEventValueLeaf = findNode(context,
ImmutableList.of(qN("my-alarm"), qN("my-content"), qN("my-event-value")));
assertTrue(myEventValueLeaf instanceof LeafSchemaNode);
}
private static QName qN(final String localName) {
- return QName.create(NS, REV, localName);
+ return QName.create(NS, localName);
}
}
public class Bug8126Test {
private static final String FOO_NS = "foo";
private static final String BAR_NS = "bar";
- private static final String REV = "1970-01-01";
@Test
public void test() throws Exception {
assertNotNull(context);
assertTrue(findNode(context, ImmutableList.of(foo("root"), bar("my-container"), bar("my-choice"), bar("one"),
bar("one"), bar("mandatory-leaf"))) instanceof LeafSchemaNode);
- assertTrue(findNode(context, ImmutableList.of(foo("root"), bar("my-list"), bar("two"), bar("mandatory-leaf-2"))) instanceof LeafSchemaNode);
+ assertTrue(findNode(context, ImmutableList.of(foo("root"), bar("my-list"), bar("two"), bar("mandatory-leaf-2")))
+ instanceof LeafSchemaNode);
assertNull(findNode(context, ImmutableList.of(foo("root"), bar("mandatory-list"))));
- assertNull(findNode(context, ImmutableList.of(foo("root"), bar("mandatory-container"), bar("mandatory-choice"))));
+ assertNull(findNode(context, ImmutableList.of(foo("root"), bar("mandatory-container"),
+ bar("mandatory-choice"))));
assertNull(findNode(context,
ImmutableList.of(foo("root"), bar("mandatory-container-2"), bar("one"), bar("mandatory-leaf-3"))));
}
}
private static QName foo(final String localName) {
- return QName.create(FOO_NS, REV, localName);
+ return QName.create(FOO_NS, localName);
}
private static QName bar(final String localName) {
- return QName.create(BAR_NS, REV, localName);
+ return QName.create(BAR_NS, localName);
}
}
import java.util.Set;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.ModuleImport;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
final SchemaContext context = StmtTestUtils.parseYangSources("/bugs/bug8597");
assertNotNull(context);
- final Module foo = context.findModule("foo", SimpleDateFormatUtil.DEFAULT_DATE_REV).get();
+ final Module foo = context.findModule("foo", null).get();
final Set<ModuleImport> imports = foo.getImports();
for (final ModuleImport moduleImport : imports) {
public class Bug8922Test {
private static final String NS = "foo";
- private static final String REV = "1970-01-01";
@Test
public void testAllFeaturesSupported() throws Exception {
}
private static QName qN(final String localName) {
- return QName.create(NS, REV, localName);
+ return QName.create(NS, localName);
}
}
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.GroupingDefinition;
private static final StatementStreamSource SIMPLE_MODULE = sourceForResource(
"/stmt-test/effective-build/simple-module.yang");
- private static final QNameModule SIMPLE_MODULE_QNAME = QNameModule.create(
- URI.create("simple.yang"), SimpleDateFormatUtil.DEFAULT_DATE_REV);
+ private static final QNameModule SIMPLE_MODULE_QNAME = QNameModule.create(URI.create("simple.yang"), null);
private static final StatementStreamSource YANG_EXT = sourceForResource(
"/stmt-test/extensions/yang-ext.yang");
import java.net.URISyntaxException;
import java.util.Set;
import org.junit.Test;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.IdentitySchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
public void identityTest() throws SourceException, ReactorException,
URISyntaxException {
- CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
- .newBuild();
+ CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
reactor.addSources(IDENTITY_TEST);
SchemaContext result = reactor.buildEffective();
assertNotNull(result);
- Module module = result.findModule("identity-test", SimpleDateFormatUtil.DEFAULT_DATE_REV).get();
+ Module module = result.findModule("identity-test", null).get();
Set<IdentitySchemaNode> identities = module.getIdentities();
assertNotNull(identities);
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.common.YangVersion;
import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
private static final StatementStreamSource SUBMODULE = sourceForResource(
"/semantic-statement-parser/effective-module/submod.yang");
- private static final QNameModule ROOT_MODULE_QNAME = QNameModule.create(URI.create("root-ns"),
- SimpleDateFormatUtil.DEFAULT_DATE_REV);
+ private static final QNameModule ROOT_MODULE_QNAME = QNameModule.create(URI.create("root-ns"), null);
private static final QName cont = QName.create(ROOT_MODULE_QNAME, "cont");
private static final QName feature1 = QName.create(ROOT_MODULE_QNAME, "feature1");
import static org.opendaylight.yangtools.yang.stmt.StmtTestUtils.sourceForResource;
import java.net.URI;
-import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Set;
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.Module;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline;
"/stmt-test/submodules/submodule-to-submodule-1.yang");
@Test
- public void modulesAndSubmodulesSimpleReferencesTest()
- throws SourceException, ReactorException, URISyntaxException {
+ public void modulesAndSubmodulesSimpleReferencesTest() throws ReactorException {
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR
.newBuild();
reactor.addSources(ROOT_MODULE, IMPORTED_MODULE,
assertNotNull(sub1);
assertNotNull(sub2);
- assertEquals(QNameModule.create(new URI("root-module"),
- SimpleDateFormatUtil.DEFAULT_DATE_REV), sub1.getQNameModule());
- assertEquals(QNameModule.create(new URI("root-module"),
- SimpleDateFormatUtil.DEFAULT_DATE_REV), sub2.getQNameModule());
+ assertEquals(QNameModule.create(URI.create("root-module"), null), sub1.getQNameModule());
+ assertEquals(QNameModule.create(URI.create("root-module"), null), sub2.getQNameModule());
final Collection<DataSchemaNode> sub1ChildNodes = sub1.getChildNodes();
final Collection<DataSchemaNode> sub2ChildNodes = sub2.getChildNodes();
assertNotNull(sub1Submodule);
- assertEquals(QNameModule.create(new URI("root-module"),
- SimpleDateFormatUtil.DEFAULT_DATE_REV),
- sub1Submodule.getQNameModule());
+ assertEquals(QNameModule.create(URI.create("root-module"), null), sub1Submodule.getQNameModule());
final Collection<DataSchemaNode> sub1SubmoduleChildNodes = sub1Submodule.getChildNodes();
assertNotNull(sub1SubmoduleChildNodes);
assertEquals("desc", containerInRoot.getDescription());
}
- private static void findModulesSubTest(final SchemaContext result, final Module root, final Module imported)
- throws URISyntaxException {
- final Module foundRoot = result.findModule("root-module", SimpleDateFormatUtil.DEFAULT_DATE_REV).get();
- final Set<Module> foundRoots = result.findModules(new URI("root-module"));
- final Module foundRoot3 = result.findModule(new URI("root-module"), SimpleDateFormatUtil.DEFAULT_DATE_REV)
- .get();
+ private static void findModulesSubTest(final SchemaContext result, final Module root, final Module imported) {
+ final Module foundRoot = result.findModule("root-module", null).get();
+ final Set<Module> foundRoots = result.findModules(URI.create("root-module"));
+ final Module foundRoot3 = result.findModule(URI.create("root-module"), null).get();
assertNotNull(foundRoot);
assertNotNull(foundRoots);
assertEquals(root, foundRoot2);
assertEquals(root, foundRoot3);
- final Module foundImported = result.findModule("imported-module", SimpleDateFormatUtil.DEFAULT_DATE_REV).get();
- final Set<Module> foundImporteds = result.findModules(new URI("imported-module"));
- final Module foundImported3 = result.findModule(new URI("imported-module"),
- SimpleDateFormatUtil.DEFAULT_DATE_REV).get();
+ final Module foundImported = result.findModule("imported-module", null).get();
+ final Set<Module> foundImporteds = result.findModules(URI.create("imported-module"));
+ final Module foundImported3 = result.findModule(URI.create("imported-module"), null).get();
assertNotNull(foundImported);
assertNotNull(foundImporteds);
@Test
public void testSomeFeaturesSupported() throws ReactorException {
final Set<QName> supportedFeatures = ImmutableSet.of(
- QName.create("foo-namespace", "1970-01-01", "test-feature-1"),
- QName.create("foo-namespace", "1970-01-01", "test-feature-2"),
- QName.create("foo-namespace", "1970-01-01", "test-feature-3"),
- QName.create("bar-namespace", "1970-01-01", "imp-feature"));
+ QName.create("foo-namespace", "test-feature-1"),
+ QName.create("foo-namespace", "test-feature-2"),
+ QName.create("foo-namespace", "test-feature-3"),
+ QName.create("bar-namespace", "imp-feature"));
final CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
reactor.addSources(FOO_MODULE, BAR_MODULE);
final SchemaContext schemaContext = reactor.buildEffective();
assertNotNull(schemaContext);
- final Module testModule = schemaContext.findModules("foo").iterator().next();
- assertNotNull(testModule);
-
+ final Module testModule = schemaContext.findModule("foo", null).get();
assertEquals(9, testModule.getChildNodes().size());
final ContainerSchemaNode testContainerA = (ContainerSchemaNode) testModule.getDataChildByName(
"/import-revision-date-test/root-without-revision-date.yang");
private static final StatementStreamSource IMPORTED_WITH_DATE = sourceForResource(
"/import-revision-date-test/imported-module-with-revision-date.yang");
- private static final StatementStreamSource ROOT_WITH_1970_DATE = sourceForResource(
- "/import-revision-date-test/root-with-1970-revision-date.yang");
private static final StatementStreamSource ROOT_WITH_NO_DATE = sourceForResource(
"/import-revision-date-test/root-with-no-revision-date.yang");
private static final StatementStreamSource IMPORTED_WITH_NO_DATE = sourceForResource(
assertNotNull(result);
}
- @Test
- public void revision1970InRootOnlyTest() throws ReactorException {
- CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
- reactor.addSources(ROOT_WITH_1970_DATE, IMPORTED_WITHOUT_DATE);
-
- EffectiveModelContext result = reactor.build();
- assertNotNull(result);
- }
-
@Test
public void noRevisionInRootAndImportedTest() throws ReactorException {
CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
import org.opendaylight.yangtools.yang.parser.spi.meta.ModelProcessingPhase;
import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.parser.spi.meta.SomeModifiersUnresolvedException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.parser.spi.source.StatementStreamSource;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementReactor;
import org.opendaylight.yangtools.yang.parser.stmt.reactor.EffectiveModelContext;
private static final StatementStreamSource SUBMOD_ONLY_REV = sourceForResource("/revisions/submod-only-rev.yang");
private static final StatementStreamSource MOD_ONLY_ROOT = sourceForResource("/revisions/mod-only-root.yang");
private static final StatementStreamSource MOD_ONLY_REV = sourceForResource("/revisions/mod-only-rev.yang");
- private static final StatementStreamSource MOD_ONLY_1970_ROOT = sourceForResource("/revisions/mod-1970-root.yang");
- private static final StatementStreamSource MOD_ONLY_1970_REV = sourceForResource("/revisions/mod-1970-rev.yang");
private static final StatementStreamSource NOWHERE_ROOT = sourceForResource("/revisions/nowhere-root.yang");
private static final StatementStreamSource NOWHERE_REV = sourceForResource("/revisions/nowhere-rev.yang");
@Test
- public void revsEqualTest() throws SourceException, ReactorException {
+ public void revsEqualTest() throws ReactorException {
CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
addSources(reactor, EQUAL_REV, EQUAL_ROOT);
}
@Test
- public void revsUnequalTest() throws SourceException, ReactorException {
+ public void revsUnequalTest() throws ReactorException {
CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
addSources(reactor, UNEQUAL_REV, UNEQUAL_ROOT);
}
@Test
- public void revIncludeOnly() throws SourceException, ReactorException {
+ public void revIncludeOnly() throws ReactorException {
CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
addSources(reactor, SUBMOD_ONLY_REV, SUBMOD_ONLY_ROOT);
}
@Test
- public void revInModuleOnly() throws SourceException, ReactorException {
+ public void revInModuleOnly() throws ReactorException {
CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
addSources(reactor, MOD_ONLY_REV, MOD_ONLY_ROOT);
}
@Test
- public void rev1970InModuleOnlyTest() throws SourceException, ReactorException {
-
- CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
- addSources(reactor, MOD_ONLY_1970_REV, MOD_ONLY_1970_ROOT);
-
- EffectiveModelContext result = reactor.build();
- assertNotNull(result);
- }
-
- @Test
- public void revNowhereTest() throws SourceException, ReactorException {
+ public void revNowhereTest() throws ReactorException {
CrossSourceStatementReactor.BuildAction reactor = YangInferencePipeline.RFC6020_REACTOR.newBuild();
addSources(reactor, NOWHERE_REV, NOWHERE_ROOT);
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
private static void checkNetconfMonitoringModuleSimpleTest(final SchemaContext context,
final Date rev20130715, final QName dateTimeTypeDef_20130715) {
URI monitoringNS = URI.create("urn:ietf:params:xml:ns:yang:ietf-netconf-monitoring");
- final QNameModule monitoring_19700101 = QNameModule.create(monitoringNS, SimpleDateFormatUtil.DEFAULT_DATE_REV);
+ final QNameModule monitoring_19700101 = QNameModule.create(monitoringNS, null);
QName lockedTime = QName.create(monitoring_19700101, "locked-time");
- Module monitoringModule_19700101 = context.findModule("ietf-netconf-monitoring",
- SimpleDateFormatUtil.DEFAULT_DATE_REV).get();
+ Module monitoringModule_19700101 = context.findModule("ietf-netconf-monitoring", null).get();
DataSchemaNode leafLockedTime = monitoringModule_19700101.getDataChildByName(lockedTime);
assertNotNull(leafLockedTime);
final Throwable rootCause = Throwables.getRootCause(e);
assertTrue(rootCause instanceof InferenceException);
assertTrue(rootCause.getMessage().startsWith(
- "Augment target 'Absolute{path=[(urn:simple.container.demo?revision=1970-01-01)unknown]}' not found"));
+ "Augment target 'Absolute{path=[(urn:simple.container.demo)unknown]}' not found"));
}
}
fail("ReactorException should be thrown");
} catch (final ReactorException e) {
assertTrue(e.getCause().getMessage().contains("Error in module 'test4' in the refine of uses " +
- "'Relative{path=[(urn:simple.container.demo?revision=1970-01-01)node]}': can not perform refine of 'PRESENCE' for" +
+ "'Relative{path=[(urn:simple.container.demo)node]}': can not perform refine of 'PRESENCE' for" +
" the target 'LEAF_LIST'."));
}
}
fail("SourceException should be thrown");
} catch (final ReactorException e) {
final String expected = "Error in module 'container': cannot add '(urn:simple.container" +
- ".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" +
- ".demo?revision=1970-01-01)foo' already declared";
+ ".demo)foo'. Node name collision: '(urn:simple.container.demo)foo' already declared";
assertTrue(e.getCause().getMessage().contains(expected));
}
}
fail("SourceException should be thrown");
} catch (final ReactorException e) {
final String expected = "Error in module 'container-list': cannot add '(urn:simple.container" +
- ".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" +
- ".demo?revision=1970-01-01)foo' already declared";
+ ".demo)foo'. Node name collision: '(urn:simple.container.demo)foo' already declared";
assertTrue(e.getCause().getMessage().contains(expected));
}
}
fail("SourceException should be thrown");
} catch (final ReactorException e) {
final String expected = "Error in module 'container-leaf': cannot add '(urn:simple.container" +
- ".demo?revision=1970-01-01)foo'. Node name collision: '(urn:simple.container" +
- ".demo?revision=1970-01-01)foo' already declared";
+ ".demo)foo'. Node name collision: '(urn:simple.container.demo)foo' already declared";
assertTrue(e.getCause().getMessage().contains(expected));
}
}
fail("SourceException should be thrown");
} catch (final ReactorException e) {
assertTrue(e.getCause().getMessage().startsWith(
- "Duplicate name for typedef (urn:simple.container.demo?revision=1970-01-01)int-ext [at"));
+ "Duplicate name for typedef (urn:simple.container.demo)int-ext [at"));
}
}
TestUtils.loadModuleResources(getClass(), "/negative-scenario/invalid-list-key-def.yang");
fail("InferenceException should be thrown");
} catch (final ReactorException e) {
- final String expected = "Key 'rib-id' misses node 'rib-id' in list "
- + "'(invalid:list:key:def?revision=1970-01-01)application-map'";
+ final String expected = "Key 'rib-id' misses node 'rib-id' in list '(invalid:list:key:def)application-map'";
assertTrue(e.getCause().getMessage().startsWith(expected));
}
}
import org.junit.Test;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.common.QNameModule;
-import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
private static final StatementStreamSource TYPEFILE4 = sourceForResource(
"/semantic-statement-parser/identityreftest.yang");
- private static final QNameModule types2Module = QNameModule.create(URI.create("types2"),
- SimpleDateFormatUtil.DEFAULT_DATE_REV);
+ private static final QNameModule types2Module = QNameModule.create(URI.create("types2"), null);
private static final QName lfDecimal = QName.create(types2Module, "lf-decimal");
private static final QName lfMyString = QName.create(types2Module, "lf-my-string");
namespace foo;
prefix foo;
- import bar { prefix bar; revision-date 1970-01-01; }
+ import bar { prefix bar; }
extension foo-ext {
argument arg;
namespace bar;
prefix bar;
- import foo { prefix decimal64; revision-date 1970-01-01; }
+ import foo { prefix decimal64; }
decimal64:decimal64 decimal64;
}
namespace bar;
prefix bar;
- import foo { prefix foo; revision-date 1970-01-01; }
+ import foo { prefix foo; }
//valid augments (non-mandatory choice)
augment "/foo:root" {
+++ /dev/null
-module root-with-1970-revision-date {
- namespace "urn:opendaylight.org/root-with-1970-revision-date";
- prefix "root-1970-date";
-
- import imported-module-without-revision-date {
- prefix "imported-without-date";
- revision-date "1970-01-01";
- }
-
-}
\ No newline at end of file
+++ /dev/null
-submodule mod-1970-rev {
- belongs-to "mod-1970-root" {
- prefix mod-1970-root;
- }
-}
+++ /dev/null
-module mod-1970-root {
- namespace mod-1970-root;
- prefix mod-1970-root;
-
- include mod-1970-rev {
- revision-date "1970-01-01";
- }
-}
include sub-foo {
revision-date 2017-02-09;
}
- include sub-foo-2 {
- revision-date 1970-01-01;
- }
+ include sub-foo-2;
container root {
}
prefix foo;
}
- include sub-foo-2 {
- revision-date 1970-01-01;
- }
+ include sub-foo-2;
revision 2017-02-09;
include sub-foo {
revision-date 2017-02-09;
}
- include sub-foo-2 {
- revision-date 1970-01-01;
- }
+ include sub-foo-2;
container root {
}
namespace "multiple-augment-root";
prefix root;
- import multiple-augment-imported { prefix imp; revision-date 1970-01-01; }
+ import multiple-augment-imported { prefix imp; }
- include multiple-augment-submodule { revision-date 1970-01-01; }
+ include multiple-augment-submodule;
augment /imp:root-container/imp:container-from-grp1/imp:sub-container-from-grp1/imp:container-in-uses-augment/imp:sub-container-from-augment2 {
container sub-container-from-augment3 {
namespace "root-module";
prefix root;
- import imported-module { prefix imp; revision-date 1970-01-01; }
+ import imported-module { prefix imp; }
- include submodule-1 { revision-date 1970-01-01; }
- include submodule-2 { revision-date 1970-01-01; }
+ include submodule-1;
+ include submodule-2;
container container-in-root-module {
description "desc";
prefix root;
}
- include submodule-to-submodule-1 { revision-date 1970-01-01; }
+ include submodule-to-submodule-1;
container container-in-submodule-1 {
}
import com.google.common.collect.ImmutableList;
import java.util.Collection;
import java.util.Date;
-import java.util.Optional;
import java.util.Set;
import java.util.function.Predicate;
import org.opendaylight.yangtools.yang.common.QName;
qnameModule = InferenceException.throwIfNull(qnameModule, ctx.getStatementSourceReference(),
"Cannot resolve QNameModule for '%s'", value);
-
- final QNameModule resultQNameModule;
- if (qnameModule.getRevision() == null) {
- resultQNameModule = QNameModule.create(qnameModule.getNamespace(), SimpleDateFormatUtil.DEFAULT_DATE_REV)
- .intern();
- } else {
- resultQNameModule = qnameModule;
- }
-
- return ctx.getFromNamespace(QNameCacheNamespace.class, QName.create(resultQNameModule, localName));
+ return ctx.getFromNamespace(QNameCacheNamespace.class, QName.create(qnameModule, localName));
}
public static QNameModule getRootModuleQName(final StmtContext<?, ?, ?> ctx) {
}
checkArgument(qnameModule != null, "Failed to look up root QNameModule for %s", ctx);
- if (qnameModule.getRevision() != null) {
- return qnameModule;
- }
-
- return QNameModule.create(qnameModule.getNamespace(), SimpleDateFormatUtil.DEFAULT_DATE_REV).intern();
+ return qnameModule;
}
public static QNameModule getModuleQNameByPrefix(final StmtContext<?, ?, ?> ctx, final String prefix) {
final QNameModule qNameModule = root.getFromNamespace(ModuleCtxToModuleQName.class, root);
if (qNameModule != null) {
// creates SourceIdentifier for a module
+ if (qNameModule.getFormattedRevision() == null) {
+ return RevisionSourceIdentifier.create((String) root.getStatementArgument());
+ }
+
return RevisionSourceIdentifier.create((String) root.getStatementArgument(),
qNameModule.getFormattedRevision());
}
// creates SourceIdentifier for a submodule
- final Date revision = Optional.ofNullable(getLatestRevision(root.declaredSubstatements()))
- .orElse(SimpleDateFormatUtil.DEFAULT_DATE_REV);
- final String formattedRevision = SimpleDateFormatUtil.getRevisionFormat().format(revision);
- return RevisionSourceIdentifier.create((String) root.getStatementArgument(), formattedRevision);
+ final Date revision = getLatestRevision(root.declaredSubstatements());
+ return revision == null ? RevisionSourceIdentifier.create((String) root.getStatementArgument())
+ : RevisionSourceIdentifier.create((String) root.getStatementArgument(),
+ SimpleDateFormatUtil.getRevisionFormat().format(revision));
}
public static Date getLatestRevision(final Iterable<? extends StmtContext<?, ?, ?>> subStmts) {