Remove usage of deprecated yang parser classes 89/39689/4
authorIgor Foltin <ifoltin@cisco.com>
Wed, 1 Jun 2016 06:25:40 +0000 (08:25 +0200)
committerRobert Varga <nite@hq.sk>
Fri, 3 Jun 2016 17:59:12 +0000 (17:59 +0000)
- 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 <ifoltin@cisco.com>
20 files changed:
yang-validation-tool/pom.xml
yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/Main.java
yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/Params.java
yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/TestUtils.java [moved from yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/RetestUtils.java with 94% similarity]
yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/Main.java [deleted file]
yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/Params.java [deleted file]
yang-validation-tool/src/main/java/org/opendaylight/yangtools/yang/validation/tool/retest/ParamsUtil.java [deleted file]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/RandomPrefix.java [deleted file]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/RandomPrefixInstanceIdentifierSerializer.java [deleted file]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlStreamUtils.java [deleted file]
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/retest/XmlUtils.java [deleted file]
yang/yang-data-impl/src/test/java/org/opendaylight/yangtools/yang/data/impl/codec/xml/XmlStreamUtilsTest.java
yang/yang-data-jaxen/src/test/java/org/opendaylight/yangtools/yang/data/jaxen/TestUtils.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/ModuleDependencySortTest.java [deleted file]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/parser/util/RefineHolderTest.java [deleted file]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug2219Test.java [deleted file]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/Bug5712Test.java
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/ModuleIdentifierTest.java [deleted file]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/SchemaContextTest.java [deleted file]
yang/yang-parser-impl/src/test/java/org/opendaylight/yangtools/yang/stmt/YangModelValidationTest.java

index fae8e2376858724b0e020c373f59d637a473f68f..749c396c161d158b83ac126c56855ca7e8bed963 100644 (file)
                                     implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                     <mainClass>org.opendaylight.yangtools.yang.validation.tool.Main</mainClass>
                                 </transformer>
-                                <transformer
-                                    implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
-                                    <mainClass>org.opendaylight.yangtools.yang.validation.tool.retest.Main</mainClass>
-                                </transformer>
                             </transformers>
                             <shadedArtifactAttached>true</shadedArtifactAttached>
                             <shadedClassifierName>executable</shadedClassifierName>
index 78ee8a535a312ee33f8e2dcb5d3e02edf8e3b58e..c3a48843bc21cbfc2e7592ba4c461b7f0820a0e9 100644 (file)
@@ -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);
             }
index 205f54c3316e4a7a9d2bce287caee03be86e030f..5bc91bc0500c584c2ce3796fcad5ace3da63b79c 100644 (file)
@@ -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;
         }
 
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 2a9eda9e85c470829edaa39384a1c200d7c2db2a..50931e1302fb235fe4a8b7604e7165073d32e081 100644 (file)
@@ -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 (file)
index d5ce828..0000000
+++ /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 (file)
index 269a5b0..0000000
+++ /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 (file)
index bed5a15..0000000
+++ /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 (file)
index cc76f37..0000000
+++ /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<URI, String> prefixes = HashBiMap.create();
-    private final NamespaceContext context;
-
-    RandomPrefix() {
-        this.context = null;
-    }
-
-    RandomPrefix(final NamespaceContext context) {
-        this.context = Preconditions.checkNotNull(context);
-    }
-
-    Iterable<Map.Entry<URI, String>> 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 (file)
index 5268216..0000000
+++ /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<Map.Entry<URI, String>> 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 (file)
index bad3552..0000000
+++ /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> 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<QName, String> 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<QNameModule> 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<QNameModule> 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<Object, ?> 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<QNameModule> 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<Entry<URI, String>> prefixes)
-            throws XMLStreamException {
-        for (Entry<URI, String> 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 (file)
index c2d8ba3..0000000
+++ /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<Object, ? extends TypeDefinition<?>> 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<QName, Object> predicates = ((NodeIdentifierWithPredicates) pathArgument).getKeyValues();
-
-                for (Map.Entry<QName, Object> 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();
-    }
-}
index a27595b32ee279f11c5d37b6958b0578c45cbe60..8ba53004fcd26fe78b608221bc3f4230efa57162 100644 (file)
@@ -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());
index 15987f2d45cfde80825612c44949b9da334f4211..0f675cea623a9e8309fc0e8baa8153743ab9080d 100644 (file)
@@ -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 (file)
index 6246889..0000000
+++ /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<ModuleBuilder> l = ModuleDependencySort.sort(builders);
-
-        assertDependencyGraph(ModuleDependencySort.createModuleGraph(ModuleOrModuleBuilder.fromAll(
-                Collections.emptySet(), Arrays.asList(builders))));
-
-        Matcher<String> 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<Module> 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<String, Map<Date, ModuleNodeImpl>> moduleGraph) {
-        for (Entry<String, Map<Date, ModuleNodeImpl>> node : moduleGraph.entrySet()) {
-            String name = node.getKey();
-
-            // Expects only one module revision
-
-            Set<Edge> inEdges = node.getValue().values().iterator().next().getInEdges();
-            Set<Edge> 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<Edge> inEdges, final int i, final Set<Edge> 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<String, ModuleImport> 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<ModuleImport> 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 (file)
index 0357815..0000000
+++ /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<QName> qnamesA = new ArrayList<>();
-        List<QName> 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 (file)
index 5a3202b..0000000
+++ /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);
-    }
-}
index bdfdc05297560080e0d8962d6ca46fa6fbf4e56a..46a9914a62c0ed25ff04fd1e624b7b21ebacfaf2 100644 (file)
@@ -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<Module> modules = loadModules(getClass().getResource("/bugs/bug5712").toURI());
-        assertNotNull(modules);
-        assertEquals(1, modules.size());
-
-        checkThing2TypeDef(modules.iterator().next());
-    }
-
-    public static Set<Module> 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<File> 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 (file)
index 5db2262..0000000
+++ /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> uri = Optional.of(new URI("testURI"));
-        Optional<URI> uri2 = Optional.of(new URI("testURI2"));
-        Optional<Date> 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 (file)
index 18ac884..0000000
+++ /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<ModuleIdentifier, String> 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());
-//    }
-
-
-}
index 88be16d2805e95f108037f2fdf56f7a4a6c8e532..33b89beb2de5dd0b97de44b8428f3c9b24748579 100644 (file)
@@ -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;