From: Igor Foltin Date: Wed, 1 Jun 2016 06:25:40 +0000 (+0200) Subject: Remove usage of deprecated yang parser classes X-Git-Tag: release/boron~121 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=43aec6ccec53fb64dd999db5448a740a62f62f12;p=yangtools.git Remove usage of deprecated yang parser classes - stop using deprecated classes related to the old yang parser - a little bit of code clean-up Change-Id: Iab22b89b31c4a10b62bf51e022d4dfa435f03426 Signed-off-by: Igor Foltin --- diff --git a/yang-validation-tool/pom.xml b/yang-validation-tool/pom.xml index fae8e23768..749c396c16 100644 --- a/yang-validation-tool/pom.xml +++ b/yang-validation-tool/pom.xml @@ -70,10 +70,6 @@ implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer"> org.opendaylight.yangtools.yang.validation.tool.Main - - org.opendaylight.yangtools.yang.validation.tool.retest.Main - true executable diff --git a/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/Main.java b/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/Main.java index 78ee8a535a..c3a48843bc 100644 --- a/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/Main.java +++ b/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/Main.java @@ -10,12 +10,10 @@ package org.opendaylight.yangtools.yang.validation.tool; import java.io.File; import java.net.URISyntaxException; import java.util.Arrays; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public final class Main { - private static final Logger LOG = LoggerFactory.getLogger(Main.class); private Main() { @@ -24,13 +22,12 @@ public final class Main { public static void main(final String[] args) throws URISyntaxException { final Params params = ParamsUtil.parseArgs(args, Params.getParser()); - final YangParserImpl yangParser = new YangParserImpl(); if (params.isValid()) { final File[] yangModels = params.getYangSourceDir().listFiles(); try { - yangParser.parseFiles(Arrays.asList(yangModels)); + TestUtils.parseYangSources(Arrays.asList(yangModels)); } catch (Exception e) { LOG.error("Yang files could not be parsed.", e); } diff --git a/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/Params.java b/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/Params.java index 205f54c331..5bc91bc050 100644 --- a/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/Params.java +++ b/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/Params.java @@ -9,6 +9,7 @@ package org.opendaylight.yangtools.yang.validation.tool; import java.io.File; import java.net.URISyntaxException; + import net.sourceforge.argparse4j.ArgumentParsers; import net.sourceforge.argparse4j.annotation.Arg; import net.sourceforge.argparse4j.inf.ArgumentParser; @@ -17,7 +18,7 @@ import org.slf4j.LoggerFactory; final class Params { - private static final Logger LOGGER = LoggerFactory.getLogger(Params.class); + private static final Logger LOG = LoggerFactory.getLogger(Params.class); @Arg(dest = "yang-source-dir") private File yangSourceDir; @@ -42,15 +43,15 @@ final class Params { return false; } if (!yangSourceDir.exists()) { - LOGGER.error("Yang source directory has to exist"); + LOG.error("Yang source directory has to exist"); return false; } if (!yangSourceDir.canRead()) { - LOGGER.error("Yang source directory has to be readable"); + LOG.error("Yang source directory has to be readable"); return false; } if (yangSourceDir.list().length == 0) { - LOGGER.error("Yang source directory {} doesn't contain any model", yangSourceDir.getPath()); + LOG.error("Yang source directory {} doesn't contain any model", yangSourceDir.getPath()); return false; } diff --git a/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/RetestUtils.java b/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/TestUtils.java similarity index 94% rename from yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/RetestUtils.java rename to yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/TestUtils.java index 2a9eda9e85..50931e1302 100644 --- a/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/RetestUtils.java +++ b/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/TestUtils.java @@ -6,7 +6,7 @@ * and is available at http://www.eclipse.org/legal/epl-v10.html */ -package org.opendaylight.yangtools.yang.validation.tool.retest; +package org.opendaylight.yangtools.yang.validation.tool; import java.io.File; import java.io.FileInputStream; @@ -21,9 +21,9 @@ import org.opendaylight.yangtools.yang.parser.stmt.reactor.CrossSourceStatementR import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangInferencePipeline; import org.opendaylight.yangtools.yang.parser.stmt.rfc6020.YangStatementSourceImpl; -public class RetestUtils { +public class TestUtils { - private RetestUtils() { + private TestUtils() { throw new UnsupportedOperationException("Utility class"); } diff --git a/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/Main.java b/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/Main.java deleted file mode 100644 index d5ce8281ba..0000000000 --- a/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/Main.java +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang.validation.tool.retest; - -import java.io.File; -import java.net.URISyntaxException; -import java.util.Arrays; - -public final class Main { - private Main() { - - } - - public static void main(final String[] args) throws URISyntaxException { - final Params params = ParamsUtil.parseArgs(args, Params.getParser()); - - if (params.isValid()) { - final File[] yangModels = params.getYangSourceDir().listFiles(); - - try { - RetestUtils.parseYangSources(Arrays.asList(yangModels)); - } catch (Exception e) { - - } - } - } -} diff --git a/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/Params.java b/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/Params.java deleted file mode 100644 index 269a5b0471..0000000000 --- a/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/Params.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang.validation.tool.retest; - -import java.io.File; -import java.net.URISyntaxException; - -import net.sourceforge.argparse4j.ArgumentParsers; -import net.sourceforge.argparse4j.annotation.Arg; -import net.sourceforge.argparse4j.inf.ArgumentParser; - -final class Params { - - @Arg(dest = "yang-source-dir") - private File yangSourceDir; - - static ArgumentParser getParser() throws URISyntaxException { - final ArgumentParser parser = ArgumentParsers.newArgumentParser("jar_file_name"); - parser.description("Validation Tool for Yang Models") - .formatUsage(); - - parser.addArgumentGroup("Required arguments") - .addArgument("--yang-source-dir") - .type(File.class) - .required(true) - .help("directory containing yang models which will be parsed") - .dest("yang-source-dir") - .metavar(""); - - return parser; - } - - public boolean isValid() { - if (yangSourceDir == null) { - return false; - } - if (!yangSourceDir.exists()) { - System.err.println("Yang source directory has to exist"); - return false; - } - if (!yangSourceDir.canRead()) { - System.err.println("Yang source directory has to be readable"); - return false; - } - if (yangSourceDir.list().length == 0) { - System.err.printf("Yang source directory '%s' does't contain any model%n", yangSourceDir.getPath()); - return false; - } - - return true; - } - - public File getYangSourceDir() { - return yangSourceDir; - } -} diff --git a/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/ParamsUtil.java b/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/ParamsUtil.java deleted file mode 100644 index bed5a15998..0000000000 --- a/yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/ParamsUtil.java +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang.validation.tool.retest; - -import net.sourceforge.argparse4j.inf.ArgumentParser; -import net.sourceforge.argparse4j.inf.ArgumentParserException; - -final class ParamsUtil { - private ParamsUtil() { - - } - - public static Params parseArgs(final String[] args, final ArgumentParser parser) { - final Params params = new Params(); - try { - parser.parseArgs(args, params); - return params; - } catch (final ArgumentParserException e) { - parser.handleError(e); - } - System.exit(1); - return null; - } -} diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/RandomPrefix.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/RandomPrefix.java deleted file mode 100644 index cc76f371ab..0000000000 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/RandomPrefix.java +++ /dev/null @@ -1,94 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang.data.impl.codec.xml.retest; - -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Preconditions; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import java.net.URI; -import java.util.Map; -import javax.xml.XMLConstants; -import javax.xml.namespace.NamespaceContext; - -/** - * @deprecated Used for interim testing, to be removed in near future. - */ -@Deprecated -class RandomPrefix { - // 32 characters, carefully chosen - private static final String LOOKUP = "abcdefghiknoprstABCDEFGHIKNOPRST"; - private static final int MASK = 0x1f; - private static final int SHIFT = 5; - - private int counter = 0; - - // BiMap to make values lookup faster - private final BiMap prefixes = HashBiMap.create(); - private final NamespaceContext context; - - RandomPrefix() { - this.context = null; - } - - RandomPrefix(final NamespaceContext context) { - this.context = Preconditions.checkNotNull(context); - } - - Iterable> getPrefixes() { - return prefixes.entrySet(); - } - - String encodePrefix(final URI namespace) { - String prefix = prefixes.get(namespace); - if (prefix != null) { - return prefix; - } - - do { - prefix = encode(counter); - counter++; - } while (alreadyUsedPrefix(prefix)); - - prefixes.put(namespace, prefix); - return prefix; - } - - private boolean alreadyUsedPrefix(final String prefix) { - if (context == null) { - return false; - } - - final String str = context.getNamespaceURI(prefix); - return !XMLConstants.NULL_NS_URI.equals(str); - } - - @VisibleForTesting - static int decode(final String str) { - int ret = 0; - for (char c : str.toCharArray()) { - int idx = LOOKUP.indexOf(c); - Preconditions.checkArgument(idx != -1, "Invalid string %s", str); - ret = (ret << SHIFT) + idx; - } - - return ret; - } - - @VisibleForTesting - static String encode(int num) { - final StringBuilder sb = new StringBuilder(); - - do { - sb.append(LOOKUP.charAt(num & MASK)); - num >>>= SHIFT; - } while (num != 0); - - return sb.reverse().toString(); - } -} diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/RandomPrefixInstanceIdentifierSerializer.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/RandomPrefixInstanceIdentifierSerializer.java deleted file mode 100644 index 5268216036..0000000000 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/RandomPrefixInstanceIdentifierSerializer.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang.data.impl.codec.xml.retest; - -import java.net.URI; -import java.util.Map; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.util.AbstractStringInstanceIdentifierCodec; -import org.opendaylight.yangtools.yang.data.util.DataSchemaContextTree; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; - -/** - * @deprecated Used for interim testing, to be removed in near future. - */ -@Deprecated -final class RandomPrefixInstanceIdentifierSerializer extends AbstractStringInstanceIdentifierCodec { - private final RandomPrefix prefixes = new RandomPrefix(); - private final DataSchemaContextTree schemaTree; - - - RandomPrefixInstanceIdentifierSerializer(final SchemaContext ctx) { - schemaTree = DataSchemaContextTree.from(ctx); - } - - Iterable> getPrefixes() { - return prefixes.getPrefixes(); - } - - @Override - protected String prefixForNamespace(final URI namespace) { - return prefixes.encodePrefix(namespace); - } - - @Override - protected QName createQName(final String prefix, final String localName) { - throw new UnsupportedOperationException("Not implemented"); - } - - @Override - protected DataSchemaContextTree getDataContextTree() { - return schemaTree; - } - -} diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlStreamUtils.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlStreamUtils.java deleted file mode 100644 index bad3552cb3..0000000000 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlStreamUtils.java +++ /dev/null @@ -1,276 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ - -package org.opendaylight.yangtools.yang.data.impl.codec.xml.retest; - -import com.google.common.annotations.Beta; -import com.google.common.annotations.VisibleForTesting; -import com.google.common.base.Optional; -import com.google.common.base.Preconditions; -import java.net.URI; -import java.util.Map.Entry; -import javax.annotation.Nonnull; -import javax.xml.stream.XMLStreamException; -import javax.xml.stream.XMLStreamWriter; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.common.QNameModule; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec; -import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlCodecProvider; -import org.opendaylight.yangtools.yang.model.api.LeafListSchemaNode; -import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode; -import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.model.api.SchemaNode; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.InstanceIdentifierTypeDefinition; -import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition; -import org.opendaylight.yangtools.yang.model.util.SchemaContextUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -/** - * Utility class for bridging JAXP Stream and YANG Data APIs. Note that the definition of this class by no means final - * and subject to change as more functionality is centralized here. - * - * @deprecated Used for interim testing, to be removed in near future. - */ -@Deprecated -@Beta -public class XmlStreamUtils { - private static final Logger LOG = LoggerFactory.getLogger(XmlStreamUtils.class); - private final XmlCodecProvider codecProvider; - private final Optional schemaContext; - - protected XmlStreamUtils(final XmlCodecProvider codecProvider) { - this(codecProvider, null); - } - - private XmlStreamUtils(final XmlCodecProvider codecProvider, final SchemaContext schemaContext) { - this.codecProvider = Preconditions.checkNotNull(codecProvider); - this.schemaContext = Optional.fromNullable(schemaContext); - } - - /** - * Create a new instance encapsulating a particular codec provider. - * - * @param codecProvider - * XML codec provider - * @return A new instance - */ - public static XmlStreamUtils create(final XmlCodecProvider codecProvider) { - return new XmlStreamUtils(codecProvider); - } - - /** - * Write an InstanceIdentifier into the output stream. Calling corresponding - * {@link XMLStreamWriter#writeStartElement(String)} and {@link XMLStreamWriter#writeEndElement()} is the - * responsibility of the caller. - * - * @param writer - * XML Stream writer - * @param id - * InstanceIdentifier - * @throws XMLStreamException XMLStreamException object - * - * @deprecated Use {@link #writeInstanceIdentifier(XMLStreamWriter, YangInstanceIdentifier)} instead. - */ - @Deprecated - public static void write(@Nonnull final XMLStreamWriter writer, @Nonnull final YangInstanceIdentifier id) - throws XMLStreamException { - Preconditions.checkNotNull(writer, "Writer may not be null"); - Preconditions.checkNotNull(id, "Variable should contain instance of instance identifier and can't be null"); - - final RandomPrefix prefixes = new RandomPrefix(); - final String str = XmlUtils.encodeIdentifier(prefixes, id); - writeNamespaceDeclarations(writer, prefixes.getPrefixes()); - writer.writeCharacters(str); - } - - @VisibleForTesting - static void writeAttribute(final XMLStreamWriter writer, final Entry attribute, - final RandomPrefix randomPrefix) throws XMLStreamException { - final QName key = attribute.getKey(); - final String prefix = randomPrefix.encodePrefix(key.getNamespace()); - writer.writeAttribute("xmlns:" + prefix, key.getNamespace().toString()); - writer.writeAttribute(prefix, key.getNamespace().toString(), key.getLocalName(), attribute.getValue()); - } - - /** - * Write a value into a XML stream writer. This method assumes the start and end of element is emitted by the - * caller. - * - * @param writer - * XML Stream writer - * @param schemaNode - * Schema node that describes the value - * @param value - * data value - * @param parent - * optional parameter of a module QName owning the leaf definition - * @throws XMLStreamException - * if an encoding problem occurs - */ - public void writeValue(@Nonnull final XMLStreamWriter writer, @Nonnull final SchemaNode schemaNode, - final Object value, final Optional parent) throws XMLStreamException { - if (value == null) { - LOG.debug("Value of {}:{} is null, not encoding it", schemaNode.getQName().getNamespace(), schemaNode - .getQName().getLocalName()); - return; - } - - Preconditions - .checkArgument( - schemaNode instanceof LeafSchemaNode || schemaNode instanceof LeafListSchemaNode, - "Unable to write value for node %s, only nodes of type: leaf and leaf-list can be written at this point", - schemaNode.getQName()); - - TypeDefinition type = schemaNode instanceof LeafSchemaNode ? ((LeafSchemaNode) schemaNode).getType() - : ((LeafListSchemaNode) schemaNode).getType(); - - TypeDefinition baseType = XmlUtils.resolveBaseTypeFrom(type); - - if (schemaContext.isPresent() && baseType instanceof LeafrefTypeDefinition) { - LeafrefTypeDefinition leafrefTypeDefinition = (LeafrefTypeDefinition) baseType; - baseType = SchemaContextUtil.getBaseTypeForLeafRef(leafrefTypeDefinition, schemaContext.get(), schemaNode); - } - - writeValue(writer, baseType, value, parent); - } - - public void writeValue(@Nonnull final XMLStreamWriter writer, @Nonnull final SchemaNode schemaNode, - final Object value) throws XMLStreamException { - writeValue(writer, schemaNode, value, Optional.absent()); - } - - public void writeValue(@Nonnull final XMLStreamWriter writer, @Nonnull final SchemaNode schemaNode, - final Object value, final QNameModule parent) throws XMLStreamException { - writeValue(writer, schemaNode, value, Optional.of(parent)); - } - - /** - * Write a value into a XML stream writer. This method assumes the start and end of element is emitted by the - * caller. - * - * @param writer - * XML Stream writer - * @param type - * data type. In case of leaf ref this should be the type of leaf being referenced - * @param value - * data value - * @param parent - * optional parameter of a module QName owning the leaf definition - * @throws XMLStreamException - * if an encoding problem occurs - */ - public void writeValue(@Nonnull final XMLStreamWriter writer, @Nonnull final TypeDefinition type, - final Object value, final Optional parent) throws XMLStreamException { - if (value == null) { - LOG.debug("Value of {}:{} is null, not encoding it", type.getQName().getNamespace(), type.getQName() - .getLocalName()); - return; - } - TypeDefinition baseType = XmlUtils.resolveBaseTypeFrom(type); - - if (baseType instanceof IdentityrefTypeDefinition) { - if (parent.isPresent()) { - write(writer, (IdentityrefTypeDefinition) baseType, value, parent); - } else { - write(writer, (IdentityrefTypeDefinition) baseType, value, Optional.absent()); - } - } else if (baseType instanceof InstanceIdentifierTypeDefinition) { - write(writer, (InstanceIdentifierTypeDefinition) baseType, value); - } else { - final TypeDefinitionAwareCodec codec = codecProvider.codecFor(type); - String text; - if (codec != null) { - try { - text = codec.serialize(value); - } catch (ClassCastException e) { - LOG.error("Provided node value {} did not have type {} required by mapping. Using stream instead.", - value, type, e); - text = String.valueOf(value); - } - } else { - LOG.error("Failed to find codec for {}, falling back to using stream", type); - text = String.valueOf(value); - } - writer.writeCharacters(text); - } - } - - public void writeValue(@Nonnull final XMLStreamWriter writer, @Nonnull final TypeDefinition type, - final Object value, final QNameModule parent) throws XMLStreamException { - writeValue(writer, type, value, Optional.of(parent)); - } - - public void writeValue(@Nonnull final XMLStreamWriter writer, @Nonnull final TypeDefinition type, - final Object value) throws XMLStreamException { - writeValue(writer, type, value, Optional.absent()); - } - - @VisibleForTesting - static void write(@Nonnull final XMLStreamWriter writer, @Nonnull final IdentityrefTypeDefinition type, - @Nonnull final Object value, final Optional parent) throws XMLStreamException { - if (value instanceof QName) { - final QName qname = (QName) value; - final String prefix = "x"; - - // in case parent is present and same as element namespace write value without namespace - if (parent.isPresent() && qname.getNamespace().equals(parent.get().getNamespace())) { - writer.writeCharacters(qname.getLocalName()); - } else { - final String ns = qname.getNamespace().toString(); - writer.writeNamespace(prefix, ns); - writer.writeCharacters(prefix + ':' + qname.getLocalName()); - } - - } else { - LOG.debug("Value of {}:{} is not a QName but {}", type.getQName().getNamespace(), type.getQName() - .getLocalName(), value.getClass()); - writer.writeCharacters(String.valueOf(value)); - } - } - - private void write(@Nonnull final XMLStreamWriter writer, @Nonnull final InstanceIdentifierTypeDefinition type, - @Nonnull final Object value) throws XMLStreamException { - if (value instanceof YangInstanceIdentifier) { - writeInstanceIdentifier(writer, (YangInstanceIdentifier) value); - } else { - LOG.warn("Value of {}:{} is not an InstanceIdentifier but {}", type.getQName().getNamespace(), type - .getQName().getLocalName(), value.getClass()); - writer.writeCharacters(String.valueOf(value)); - } - } - - public void writeInstanceIdentifier(final XMLStreamWriter writer, final YangInstanceIdentifier value) throws XMLStreamException { - if (schemaContext.isPresent()) { - RandomPrefixInstanceIdentifierSerializer iiCodec = new RandomPrefixInstanceIdentifierSerializer( - schemaContext.get()); - String serializedValue = iiCodec.serialize(value); - writeNamespaceDeclarations(writer, iiCodec.getPrefixes()); - writer.writeCharacters(serializedValue); - } else { - LOG.warn("Schema context not present in {}, serializing {} without schema.", this, value); - write(writer, value); - } - } - - private static void writeNamespaceDeclarations(final XMLStreamWriter writer, final Iterable> prefixes) - throws XMLStreamException { - for (Entry e : prefixes) { - final String ns = e.getKey().toString(); - final String p = e.getValue(); - writer.writeNamespace(p, ns); - } - } - - public static XmlStreamUtils create(final XmlCodecProvider codecProvider, final SchemaContext schemaContext) { - return new XmlStreamUtils(codecProvider, schemaContext); - } -} diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlUtils.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlUtils.java deleted file mode 100644 index c2d8ba3d52..0000000000 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlUtils.java +++ /dev/null @@ -1,83 +0,0 @@ -/* - * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang.data.impl.codec.xml.retest; - -import java.util.Map; -import javax.annotation.Nonnull; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeWithValue; -import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.PathArgument; -import org.opendaylight.yangtools.yang.data.impl.codec.TypeDefinitionAwareCodec; -import org.opendaylight.yangtools.yang.data.impl.codec.xml.XmlCodecProvider; -import org.opendaylight.yangtools.yang.model.api.TypeDefinition; - -/** - * Common XML-related utility methods, which are not specific to a particular JAXP API. - * - * @deprecated Used for interim testing, to be removed in near future. - */ -@Deprecated -public final class XmlUtils { - public static final XmlCodecProvider DEFAULT_XML_CODEC_PROVIDER = new XmlCodecProvider() { - @Override - public TypeDefinitionAwareCodec> codecFor(final TypeDefinition baseType) { - return TypeDefinitionAwareCodec.from(baseType); - } - }; - - private XmlUtils() { - } - - public static TypeDefinition resolveBaseTypeFrom(final @Nonnull TypeDefinition type) { - TypeDefinition superType = type; - while (superType.getBaseType() != null) { - superType = superType.getBaseType(); - } - return superType; - } - - /** - * - * @deprecated Use {@link RandomPrefixInstanceIdentifierSerializer} instead. - */ - @Deprecated - static String encodeIdentifier(final RandomPrefix prefixes, final YangInstanceIdentifier id) { - StringBuilder textContent = new StringBuilder(); - for (PathArgument pathArgument : id.getPathArguments()) { - textContent.append('/'); - - final QName nt = pathArgument.getNodeType(); - textContent.append(prefixes.encodePrefix(nt.getNamespace())); - textContent.append(':'); - textContent.append(nt.getLocalName()); - - if (pathArgument instanceof NodeIdentifierWithPredicates) { - Map predicates = ((NodeIdentifierWithPredicates) pathArgument).getKeyValues(); - - for (Map.Entry entry : predicates.entrySet()) { - final QName key = entry.getKey(); - textContent.append('['); - textContent.append(prefixes.encodePrefix(key.getNamespace())); - textContent.append(':'); - textContent.append(key.getLocalName()); - textContent.append("='"); - textContent.append(String.valueOf(entry.getValue())); - textContent.append("']"); - } - } else if (pathArgument instanceof NodeWithValue) { - textContent.append("[.='"); - textContent.append(((NodeWithValue) pathArgument).getValue()); - textContent.append("']"); - } - } - - return textContent.toString(); - } -} diff --git a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlStreamUtilsTest.java b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlStreamUtilsTest.java index a27595b32e..8ba53004fc 100644 --- a/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlStreamUtilsTest.java +++ b/yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlStreamUtilsTest.java @@ -57,7 +57,7 @@ public class XmlStreamUtilsTest { @BeforeClass public static void initialize() throws URISyntaxException, FileNotFoundException, ReactorException { - final File file = new File(org.opendaylight.yangtools.yang.data.impl.codec.xml.retest.XmlStreamUtils.class.getResource("/leafref-test.yang").toURI()); + final File file = new File(XmlStreamUtils.class.getResource("/leafref-test.yang").toURI()); schemaContext = TestUtils.parseYangSources(file); assertNotNull(schemaContext); assertEquals(1, schemaContext.getModules().size()); diff --git a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/TestUtils.java b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/TestUtils.java index 15987f2d45..0f675cea62 100644 --- a/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/TestUtils.java +++ b/yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/TestUtils.java @@ -27,7 +27,6 @@ import org.opendaylight.yangtools.yang.data.api.schema.NormalizedNode; import org.opendaylight.yangtools.yang.data.impl.schema.ImmutableNodes; import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder; import org.opendaylight.yangtools.yang.model.api.SchemaContext; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; 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; diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/ModuleDependencySortTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/ModuleDependencySortTest.java deleted file mode 100644 index 62468893ec..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/ModuleDependencySortTest.java +++ /dev/null @@ -1,205 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang.parser.util; - -import static org.hamcrest.CoreMatchers.containsString; -import static org.hamcrest.core.AnyOf.anyOf; -import static org.hamcrest.core.IsEqual.equalTo; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; -import static org.mockito.Mockito.doReturn; -import static org.mockito.Mockito.mock; -import com.google.common.collect.Sets; -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Arrays; -import java.util.Collections; -import java.util.Date; -import java.util.HashMap; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.Set; -import org.hamcrest.Matcher; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.ModuleImport; -import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder; -import org.opendaylight.yangtools.yang.parser.util.ModuleDependencySort.ModuleNodeImpl; -import org.opendaylight.yangtools.yang.parser.util.TopologicalSort.Edge; - -public class ModuleDependencySortTest { - private final DateFormat SIMPLE_DATE_FORMAT = new SimpleDateFormat("yyyy-MM-dd"); - private final ModuleBuilder a = mockModuleBuilder("a", null); - private final ModuleBuilder b = mockModuleBuilder("b", null); - private final ModuleBuilder c = mockModuleBuilder("c", null); - private final ModuleBuilder d = mockModuleBuilder("d", null); - - @Test - public void testValid() throws Exception { - - mockDependency(a, b); - mockDependency(b, c); - mockDependency(b, d); - - ModuleBuilder[] builders = new ModuleBuilder[] { d, b, c, a }; - - List l = ModuleDependencySort.sort(builders); - - assertDependencyGraph(ModuleDependencySort.createModuleGraph(ModuleOrModuleBuilder.fromAll( - Collections.emptySet(), Arrays.asList(builders)))); - - Matcher cOrD = anyOf(equalTo(c.getName()), equalTo(d.getName())); - - assertThat(l.get(0).getName(), cOrD); - assertThat(l.get(1).getName(), cOrD); - assertEquals(b.getName(), l.get(2).getName()); - assertEquals(a.getName(), l.get(3).getName()); - } - - @Test - public void testValidModule() throws Exception { - - Date rev = new Date(); - Module a = mockModule("a", rev); - Module b = mockModule("b", rev); - Module c = mockModule("c", rev); - - mockDependency(a, b); - mockDependency(b, c); - mockDependency(a, c); - - Module[] builders = new Module[] { a, b, c }; - - List l = ModuleDependencySort.sort(builders); - - assertEquals(c.getName(), l.get(0).getName()); - assertEquals(b.getName(), l.get(1).getName()); - assertEquals(a.getName(), l.get(2).getName()); - } - - @Test(expected = YangValidationException.class) - public void testModuleTwice() throws Exception { - ModuleBuilder a2 = mockModuleBuilder("a", null); - - ModuleBuilder[] builders = new ModuleBuilder[] { a, a2 }; - try { - ModuleDependencySort.sort(builders); - } catch (YangValidationException e) { - assertThat(e.getMessage(), containsString("Module:a with revision:default declared twice")); - throw e; - } - } - - @Test(expected = YangValidationException.class) - public void testImportNotExistingModule() throws Exception { - mockDependency(a, b); - - ModuleBuilder[] builders = new ModuleBuilder[] { a }; - try { - ModuleDependencySort.sort(builders); - } catch (YangValidationException e) { - assertThat(e.getMessage(), containsString("Not existing module imported:b:default by:a:default")); - throw e; - } - } - - @Test - public void testImportTwice() throws Exception { - mockDependency(a, b); - mockDependency(c, b); - - ModuleBuilder[] builders = new ModuleBuilder[] { a, b, c }; - ModuleDependencySort.sort(builders); - } - - @Test - public void testModuleTwiceWithDifferentRevs() throws Exception { - ModuleBuilder a2 = mockModuleBuilder("a", new Date()); - - ModuleBuilder[] builders = new ModuleBuilder[] { a, a2 }; - ModuleDependencySort.sort(builders); - } - - @Test(expected = YangValidationException.class) - public void testModuleTwice2() throws Exception { - Date rev = new Date(); - ModuleBuilder a2 = mockModuleBuilder("a", rev); - ModuleBuilder a3 = mockModuleBuilder("a", rev); - - ModuleBuilder[] builders = new ModuleBuilder[] { a, a2, a3 }; - try { - ModuleDependencySort.sort(builders); - } catch (YangValidationException e) { - assertThat(e.getMessage(), containsString("Module:a with revision:" + SIMPLE_DATE_FORMAT.format(rev) - + " declared twice")); - throw e; - } - } - - private static void assertDependencyGraph(final Map> moduleGraph) { - for (Entry> node : moduleGraph.entrySet()) { - String name = node.getKey(); - - // Expects only one module revision - - Set inEdges = node.getValue().values().iterator().next().getInEdges(); - Set outEdges = node.getValue().values().iterator().next().getOutEdges(); - - if (name.equals("a")) { - assertEdgeCount(inEdges, 0, outEdges, 1); - } else if (name.equals("b")) { - assertEdgeCount(inEdges, 1, outEdges, 2); - } else { - assertEdgeCount(inEdges, 1, outEdges, 0); - } - } - } - - private static void assertEdgeCount(final Set inEdges, final int i, final Set outEdges, final int j) { - assertEquals(i, inEdges.size()); - assertEquals(j, outEdges.size()); - } - - private static void mockDependency(final ModuleBuilder a, final ModuleBuilder b) { - ModuleImport imprt = mock(ModuleImport.class); - doReturn(b.getName()).when(imprt).getModuleName(); - doReturn(b.getName()).when(imprt).getPrefix(); - doReturn(b.getRevision()).when(imprt).getRevision(); - a.getImports().put(b.getName(), imprt); - } - - private static void mockDependency(final Module a, final Module b) { - ModuleImport imprt = mock(ModuleImport.class); - doReturn(b.getName()).when(imprt).getModuleName(); - doReturn(b.getRevision()).when(imprt).getRevision(); - a.getImports().add(imprt); - } - - private static ModuleBuilder mockModuleBuilder(final String name, final Date rev) { - ModuleBuilder a = mock(ModuleBuilder.class); - doReturn(name).when(a).getName(); - Map map = new HashMap<>(); - doReturn(map).when(a).getImports(); - if (rev != null) { - doReturn(rev).when(a).getRevision(); - } - return a; - } - - private static Module mockModule(final String name, final Date rev) { - Module a = mock(Module.class); - doReturn(name).when(a).getName(); - Set set = Sets.newHashSet(); - doReturn(set).when(a).getImports(); - if (rev != null) { - doReturn(rev).when(a).getRevision(); - } - return a; - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/RefineHolderTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/RefineHolderTest.java deleted file mode 100644 index 0357815419..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/RefineHolderTest.java +++ /dev/null @@ -1,238 +0,0 @@ -/* - * Copyright (c) 2014 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang.parser.util; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import com.google.common.base.Optional; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.model.util.MustDefinitionImpl; -import org.opendaylight.yangtools.yang.parser.builder.api.RefineBuilder; -import org.opendaylight.yangtools.yang.parser.builder.impl.RefineHolderImpl; -import org.opendaylight.yangtools.yang.parser.builder.impl.UnknownSchemaNodeBuilderImpl; - -/** - * @deprecated Pre-Beryllium implementation, scheduled for removal. - */ -@Deprecated -public class RefineHolderTest { - - private RefineHolderImpl rh; - private RefineHolderImpl rh1; - - @Before - public void init() { - rh = new RefineHolderImpl("module", 2104, "name"); - rh1 = new RefineHolderImpl("module", 2104, "name"); - } - - - @Test - public void testRefineEquality() { - // hashCode method test - assertEquals("rh should equals to itsefl", rh, rh); - assertFalse("rh shouldn't equal to null", rh.equals(null)); - assertFalse("rh shouldn't equal to object of other type", rh.equals(new String("str"))); - - assertEquals("rh1 should equals to rh", rh, rh1); - - RefineBuilder rh2 = new RefineHolderImpl("module", 2104, null); - assertFalse("rh shouldn't equal to rh2", rh2.equals(rh1)); - rh2 = new RefineHolderImpl("module", 2104, "name2"); - assertFalse("rh shouldn't equal to rh2", rh.equals(rh2)); - - assertEquals("Wrong hash code", 1557537141, rh.hashCode()); - } - - @Test - public void testConfigurationEqualsBranch() { - assertEquals("rh should equal to rh1", rh, rh1); - rh1.setConfiguration(false); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh.setConfiguration(false); - assertEquals("rh should equal to rh1", rh, rh1); - rh.setConfiguration(true); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh1.setConfiguration(true); - } - - @Test - public void testDefaultStrEqualsBranch() { - assertEquals("rh should equal to rh1", rh, rh1); - rh1.setDefaultStr("default string1"); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh.setDefaultStr("default string1"); - assertEquals("rh should equal to rh1", rh, rh1); - rh.setDefaultStr("default string"); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh1.setDefaultStr("default string"); - } - - @Test - public void testDescriptionEqualsBranch() { - assertEquals("rh should equal to rh1", rh, rh1); - rh1.setDescription("description1"); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh.setDescription("description1"); - assertEquals("rh should equal to rh1", rh, rh1); - rh.setDescription("description"); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh1.setDescription("description"); - } - - @Test - public void testMandatoryEqualsBranch() { - assertEquals("rh should equal to rh1", rh, rh1); - rh1.setMandatory(false); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh.setMandatory(false); - assertEquals("rh should equal to rh1", rh, rh1); - rh.setMandatory(true); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh1.setMandatory(true); - } - - @Test - public void testMaxElementsEqualsBranch() { - assertEquals("rh should equal to rh1", rh, rh1); - rh1.setMaxElements(5400); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh.setMaxElements(5400); - assertEquals("rh should equal to rh1", rh, rh1); - rh.setMaxElements(5435); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh1.setMaxElements(5435); - } - - @Test - public void testMinElementsEqualsBranch() { - assertEquals("rh should equal to rh1", rh, rh1); - rh1.setMinElements(16); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh.setMinElements(16); - assertEquals("rh should equal to rh1", rh, rh1); - rh.setMinElements(159); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh1.setMinElements(159); - } - - @Test - public void testMustEqualsBranch() { - assertEquals("rh should equal to rh1", rh, rh1); - rh1.setMust(MustDefinitionImpl.create("mustStr1", Optional.of("description1"), Optional.of("reference1"), - Optional.of("errorAppTag1"), Optional.of("errorMessage1"))); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh.setMust(MustDefinitionImpl.create("mustStr1", Optional.of("description1"), Optional.of("reference1"), - Optional.of("errorAppTag1"), Optional.of("errorMessage1"))); - assertEquals("rh should equal to rh1", rh, rh1); - rh.setMust(MustDefinitionImpl.create("mustStr", Optional.of("description"), Optional.of("reference"), - Optional.of("errorAppTag"), Optional.of("errorMessage"))); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh1.setMust(MustDefinitionImpl.create("mustStr", Optional.of("description"), Optional.of("reference"), - Optional.of("errorAppTag"), Optional.of("errorMessage"))); - } - - @Test - public void testPresenceEqualsBranch() { - assertEquals("rh should equal to rh1", rh, rh1); - rh1.setPresence(false); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh.setPresence(false); - assertEquals("rh should equal to rh1", rh, rh1); - rh.setPresence(true); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh1.setPresence(true); - } - - @Test - public void testReferenceEqualsBranch() { - assertEquals("rh should equal to rh1", rh, rh1); - rh1.setReference("reference1"); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh.setReference("reference1"); - assertEquals("rh should equal to rh1", rh, rh1); - rh.setReference("reference"); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh1.setReference("reference"); - } - - private static URI getUri(final String uri) { - URI simpleUri = null; - boolean instantionated = false; - try { - simpleUri = new URI(uri); - instantionated = true; - } catch (URISyntaxException e1) { - e1.printStackTrace(); - assertTrue("Uri instance wasn't created.", instantionated); - } - return simpleUri; - } - - @Test - public void testAddUnknownNodeBuilderEqualsBranch() { - URI simpleUri = null; - simpleUri = getUri("very:simple:URI"); - assertNotNull("URI can't be null", simpleUri); - - URI uriA = getUri("some:uriA"); - assertNotNull("URI can't be null", simpleUri); - QName qnameA = QName.create(uriA, new Date(5000000), "some nameA"); - QName qnameB = QName.create(uriA, new Date(6000000), "some nameB"); - List qnamesA = new ArrayList<>(); - List qnamesB = new ArrayList<>(); - qnamesA.add(qnameA); - qnamesB.add(qnameB); - SchemaPath schemaPathB = SchemaPath.create(qnamesB, true); - - UnknownSchemaNodeBuilderImpl usnb = new UnknownSchemaNodeBuilderImpl("usnb", 151, new QName(simpleUri, "tst"), schemaPathB); - UnknownSchemaNodeBuilderImpl usnb1 = new UnknownSchemaNodeBuilderImpl("usnb", 151, new QName(simpleUri, "tst"), schemaPathB); - - assertEquals("rh should equal to rh1", rh, rh1); - rh1.addUnknownNodeBuilder(usnb); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh.addUnknownNodeBuilder(usnb1); - assertEquals("rh should equal to rh1", rh, rh1); - } - - @Test - public void testParentEqualsBranch() { - URI simpleUriA = getUri("very:simple:URI:a"); - URI simpleUriB = getUri("very:simple:URI:b"); - - SchemaPath path = org.mockito.Mockito.mock(SchemaPath.class); - - UnknownSchemaNodeBuilderImpl usnbA = new UnknownSchemaNodeBuilderImpl("usnbA", 151, new QName(simpleUriA, "tst"), path); - UnknownSchemaNodeBuilderImpl usnbB = new UnknownSchemaNodeBuilderImpl("usnbB", 151, new QName(simpleUriB, "tst"), path); - UnknownSchemaNodeBuilderImpl usnbAParent = new UnknownSchemaNodeBuilderImpl("usnbAParent", 151, new QName(simpleUriA, - "tst"), path); - usnbA.setParent(usnbAParent); - - assertEquals("rh should equal to rh1", rh, rh1); - rh1.setParent(usnbB); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh.setParent(usnbB); - assertEquals("rh should equal to rh1", rh, rh1); - rh.setParent(usnbA); - assertFalse("rh shouldn't equal to rh1", rh.equals(rh1)); - rh1.setParent(usnbA); - - assertEquals("rh should equal to rh1", rh, rh1); - } - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug2219Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug2219Test.java deleted file mode 100644 index 5a3202b03e..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug2219Test.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang.stmt; - -import static org.junit.Assert.assertNotNull; - -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.common.QName; -import org.opendaylight.yangtools.yang.model.api.SchemaPath; -import org.opendaylight.yangtools.yang.parser.builder.api.TypeDefinitionBuilder; -import org.opendaylight.yangtools.yang.parser.builder.impl.CopyUtils; -import org.opendaylight.yangtools.yang.parser.builder.impl.IdentityrefTypeBuilder; -import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder; - -/** - * NPE is rised during use of CopyUtils.copy operation for IdentityrefTypeBuilder. - * NPE occours in private getData method in CopyUtils.java during QName.create. - * - * The reason for exception is the old.getQName returns null since IdentityrefTypeBuilder.getQName() - * by implementation returns always null. - * - */ -public class Bug2219Test { - - private ModuleBuilder moduleBuilder; - - @Before - public void init() { - moduleBuilder = new ModuleBuilder("test-module", "somePath"); - } - - @Test - public void testCopyIdentityrefTypeBuilder() { - final String typedefLocalName = "identity-ref-test-type"; - final QName typedefQname = QName.create(moduleBuilder.getNamespace(), moduleBuilder.getRevision(), typedefLocalName); - final SchemaPath typedefPath = SchemaPath.create(true, typedefQname); - final IdentityrefTypeBuilder typeBuilder = new IdentityrefTypeBuilder(moduleBuilder.getModuleName(), 12, - "base:parent-identity", typedefPath); - - final TypeDefinitionBuilder copy = CopyUtils.copy(typeBuilder, moduleBuilder, true); - assertNotNull(copy); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5712Test.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5712Test.java index bdfdc05297..46a9914a62 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5712Test.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5712Test.java @@ -11,21 +11,13 @@ package org.opendaylight.yangtools.yang.stmt; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; -import java.io.File; import java.io.FileNotFoundException; -import java.io.IOException; -import java.net.URI; import java.net.URISyntaxException; -import java.util.ArrayList; -import java.util.List; -import java.util.Set; import org.junit.Test; import org.opendaylight.yangtools.yang.common.QName; import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.api.TypeDefinition; -import org.opendaylight.yangtools.yang.model.parser.api.YangContextParser; -import org.opendaylight.yangtools.yang.parser.impl.YangParserImpl; import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException; import org.opendaylight.yangtools.yang.parser.spi.source.SourceException; @@ -56,32 +48,4 @@ public class Bug5712Test { TypeDefinition baseType = thing2.getBaseType(); assertEquals(QName.create("urn:opendaylight:bad", "2016-04-11", "thing"), baseType.getQName()); } - - @Test - public void testTypedefWithOldParser() throws URISyntaxException, IOException { - Set modules = loadModules(getClass().getResource("/bugs/bug5712").toURI()); - assertNotNull(modules); - assertEquals(1, modules.size()); - - checkThing2TypeDef(modules.iterator().next()); - } - - public static Set loadModules(final URI resourceDirectory) throws IOException { - return loadSchemaContext(resourceDirectory).getModules(); - } - - public static SchemaContext loadSchemaContext(final URI resourceDirectory) throws IOException { - final YangContextParser parser = new YangParserImpl(); - final File testDir = new File(resourceDirectory); - final String[] fileList = testDir.list(); - final List testFiles = new ArrayList<>(); - if (fileList == null) { - throw new FileNotFoundException(resourceDirectory.toString()); - } - for (String fileName : fileList) { - testFiles.add(new File(testDir, fileName)); - } - return parser.parseFiles(testFiles); - } - } diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ModuleIdentifierTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ModuleIdentifierTest.java deleted file mode 100644 index 5db2262ebf..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ModuleIdentifierTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang.stmt; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; - -import com.google.common.base.Optional; -import java.net.URI; -import java.net.URISyntaxException; -import java.util.Date; -import org.junit.Before; -import org.junit.Test; -import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; -import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleIdentifierImpl; - -public class ModuleIdentifierTest { - - private ModuleIdentifier moduleIdentifier; - private ModuleIdentifier moduleIdentifier2; - private ModuleIdentifier moduleIdentifier3; - private ModuleIdentifier moduleIdentifier4; - private ModuleIdentifier moduleIdentifier5; - - @Before - public void init() throws URISyntaxException { - Optional uri = Optional.of(new URI("testURI")); - Optional uri2 = Optional.of(new URI("testURI2")); - Optional revision = Optional.absent(); - moduleIdentifier = new ModuleIdentifierImpl("test-modulue", uri, revision); - moduleIdentifier2 = new ModuleIdentifierImpl("test-modulue2", uri, revision); - moduleIdentifier3 = moduleIdentifier; - moduleIdentifier4 = new ModuleIdentifierImpl("test-modulue", uri2, revision); - moduleIdentifier5 = new ModuleIdentifierImpl("test-modulue", uri, revision); - } - - @Test - public void testGetQNameModule() { - assertEquals(null, moduleIdentifier.getQNameModule().getRevision()); - } - - @Test - public void testGetRevision() { - assertEquals(null, moduleIdentifier.getRevision()); - } - - @Test - public void testGetName() { - assertEquals("test-modulue", moduleIdentifier.getName()); - } - - @Test - public void getNamespace() throws URISyntaxException { - assertEquals(new URI("testURI"), moduleIdentifier.getNamespace()); - } - - @Test - public void toStringTest() { - assertTrue(moduleIdentifier.toString().contains("ModuleIdentifier")); - } - - @Test - public void testHashCode() { - assertFalse(moduleIdentifier.hashCode() == moduleIdentifier2.hashCode()); - } - - @Test - public void testEquals() { - assertTrue(moduleIdentifier.equals(moduleIdentifier3)); - assertFalse(moduleIdentifier.equals(null)); - assertFalse(moduleIdentifier.equals("test")); - assertFalse(moduleIdentifier.equals(moduleIdentifier2)); - assertFalse(moduleIdentifier.equals(moduleIdentifier4)); - assertTrue(moduleIdentifier.equals(moduleIdentifier5)); - } -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SchemaContextTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SchemaContextTest.java deleted file mode 100644 index 18ac884e4c..0000000000 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SchemaContextTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (c) 2016 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.yangtools.yang.stmt; - -import static org.mockito.Mockito.doReturn; -import java.net.URI; -import java.net.URISyntaxException; -import java.text.ParseException; -import java.util.Collections; -import java.util.Date; -import java.util.Map; -import org.junit.Before; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import org.opendaylight.yangtools.yang.common.SimpleDateFormatUtil; -import org.opendaylight.yangtools.yang.model.api.Module; -import org.opendaylight.yangtools.yang.model.api.ModuleIdentifier; -//import org.opendaylight.yangtools.yang.parser.impl.SchemaContextImpl; - -public class SchemaContextTest { - @Mock - private Module oldModule; - - @Mock - private Module newModule; - - private Map sources; - - private URI ns; - private Date oldDate; - private Date newDate; - - @Before - public void setUp() throws ParseException, URISyntaxException { - MockitoAnnotations.initMocks(this); - - ns = new URI("http://abc"); - oldDate = SimpleDateFormatUtil.getRevisionFormat().parse("2014-07-20"); - newDate = SimpleDateFormatUtil.getRevisionFormat().parse("2014-07-22"); - - doReturn("abc").when(oldModule).getName(); - doReturn(oldDate).when(oldModule).getRevision(); - doReturn(ns).when(oldModule).getNamespace(); - doReturn("abc").when(newModule).getName(); - doReturn(newDate).when(newModule).getRevision(); - doReturn(ns).when(newModule).getNamespace(); - - sources = Collections.emptyMap(); - } - -// @Test -// public void testModuleOrdering() { -// SchemaContext sc; -// Module m; -// -// sc = SchemaContextImpl(ImmutableSet.of(newModule, oldModule), sources); -// m = sc.findModuleByName("abc", null); -// assertEquals(newDate, m.getRevision()); -// m = sc.findModuleByNamespaceAndRevision(ns, null); -// assertEquals(newDate, m.getRevision()); -// -// sc = new SchemaContextImpl(ImmutableSet.of(oldModule, newModule), sources); -// m = sc.findModuleByName("abc", null); -// assertEquals(newDate, m.getRevision()); -// m = sc.findModuleByNamespaceAndRevision(ns, null); -// assertEquals(newDate, m.getRevision()); -// } - - -} diff --git a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationTest.java b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationTest.java index 88be16d280..33b89beb2d 100644 --- a/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationTest.java +++ b/yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationTest.java @@ -30,8 +30,6 @@ import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Prefix_stmtContext import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Revision_date_stmtContext; import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.Status_argContext; import org.opendaylight.yangtools.antlrv4.code.gen.YangParser.StringContext; -//import org.opendaylight.yangtools.yang.parser.impl.BasicValidations; -//import org.opendaylight.yangtools.yang.parser.impl.ValidationUtil; import org.opendaylight.yangtools.yang.parser.impl.YangModelBasicValidationListener; import org.opendaylight.yangtools.yang.parser.util.YangValidationException;