Removed usage of deprecated YangParserImpl from tests in mdsal project
[mdsal.git] / binding / mdsal-binding-generator-impl / src / test / java / org / opendaylight / yangtools / sal / binding / yang / types / TypeProviderImplTest.java
index 1742adcceea3d61801974eeffd8426d5d775cc64..6e22000f77c0390a3ecdfa4a3ac6c2953598d059 100644 (file)
@@ -1,23 +1,21 @@
 /*
- * Copyright (c) 2014 Cisco Systems, Inc. and others.  All rights reserved.
+ * 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.sal.binding.yang.types;
 
 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.io.File;
+import java.io.FileNotFoundException;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.NoSuchElementException;
 import org.junit.Rule;
 import org.junit.Test;
@@ -33,19 +31,20 @@ import org.opendaylight.yangtools.yang.model.api.Module;
 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
 import org.opendaylight.yangtools.yang.model.api.SchemaPath;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BinaryTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.BooleanTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.DecimalTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.EmptyTypeDefinition;
 import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition;
-import org.opendaylight.yangtools.yang.model.api.type.EnumTypeDefinition.EnumPair;
-import org.opendaylight.yangtools.yang.model.util.BinaryType;
-import org.opendaylight.yangtools.yang.model.util.BooleanType;
-import org.opendaylight.yangtools.yang.model.util.Decimal64;
-import org.opendaylight.yangtools.yang.model.util.EmptyType;
-import org.opendaylight.yangtools.yang.model.util.EnumerationType;
-import org.opendaylight.yangtools.yang.model.util.IdentityrefType;
-import org.opendaylight.yangtools.yang.model.util.StringType;
+import org.opendaylight.yangtools.yang.model.api.type.IdentityrefTypeDefinition;
+import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
+import org.opendaylight.yangtools.yang.model.util.type.BaseTypes;
+import org.opendaylight.yangtools.yang.model.util.type.IdentityrefTypeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.IdentitySchemaNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.LeafSchemaNodeBuilder;
 import org.opendaylight.yangtools.yang.parser.builder.impl.ModuleBuilder;
-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.util.YangValidationException;
 
 public class TypeProviderImplTest {
@@ -57,8 +56,7 @@ public class TypeProviderImplTest {
     public void testLeafRefRelativeSelfReference() throws Exception {
         File relative = new File(getClass().getResource("/leafref/leafref-relative-invalid.yang").toURI());
 
-        final YangParserImpl yangParser = new YangParserImpl();
-        final SchemaContext schemaContext = yangParser.parseFiles(Arrays.asList(relative));
+        final SchemaContext schemaContext = RetestUtils.parseYangSources(relative);
         final Module moduleRelative = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lrr")).iterator().next();
         final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
 
@@ -72,8 +70,7 @@ public class TypeProviderImplTest {
     public void testLeafRefAbsoluteSelfReference() throws Exception {
         File relative = new File(getClass().getResource("/leafref/leafref-absolute-invalid.yang").toURI());
 
-        final YangParserImpl yangParser = new YangParserImpl();
-        final SchemaContext schemaContext = yangParser.parseFiles(Arrays.asList(relative));
+        final SchemaContext schemaContext = RetestUtils.parseYangSources(relative);
         final Module moduleRelative = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lra")).iterator().next();
         final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
 
@@ -84,11 +81,10 @@ public class TypeProviderImplTest {
     }
 
     @Test
-    public void testLeafRefRelativeAndAbsoluteValidReference() throws URISyntaxException {
+    public void testLeafRefRelativeAndAbsoluteValidReference() throws URISyntaxException, SourceException, FileNotFoundException, ReactorException {
         File valid = new File(getClass().getResource("/leafref/leafref-valid.yang").toURI());
 
-        final YangParserImpl yangParser = new YangParserImpl();
-        final SchemaContext schemaContext = yangParser.parseFiles(Arrays.asList(valid));
+        final SchemaContext schemaContext = RetestUtils.parseYangSources(valid);
         final Module moduleValid = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lrv")).iterator().next();
         final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
 
@@ -108,17 +104,18 @@ public class TypeProviderImplTest {
     }
 
     @Test
-    public void testMethodsOfTypeProviderImpl() throws URISyntaxException {
-        final YangParserImpl yangParser = new YangParserImpl();
-        final File abstractTopology = new File(BaseYangTypes.class.getResource("/base-yang-types.yang")
+    public void testMethodsOfTypeProviderImpl() throws URISyntaxException, SourceException, FileNotFoundException, ReactorException {
+        final File abstractTopology = new File(getClass().getResource("/base-yang-types.yang")
                 .toURI());
-        final SchemaContext schemaContext = yangParser.parseFiles(Arrays.asList(abstractTopology));
+
+        final SchemaContext schemaContext = RetestUtils.parseYangSources(abstractTopology);
+
         final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
 
         final SchemaPath refTypePath = SchemaPath.create(true, QName.create("cont1"), QName.create("list1"));
         final GeneratedTypeBuilderImpl refType = new GeneratedTypeBuilderImpl("org.opendaylight.yangtools.test", "TestType");
         typeProvider.putReferencedType(refTypePath, refType);
-        final StringType stringType = StringType.getInstance();
+        final StringTypeDefinition stringType = BaseTypes.stringType();
         LeafSchemaNodeBuilder leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT);
         leafSchemaNodeBuilder.setType(stringType);
         LeafSchemaNode leafSchemaNode = leafSchemaNodeBuilder.build();
@@ -140,28 +137,28 @@ public class TypeProviderImplTest {
         assertEquals("\"default value\"", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "default value"));
 
         // binary type
-        final BinaryType binaryType = BinaryType.getInstance();
+        final BinaryTypeDefinition binaryType = BaseTypes.binaryType();
         leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT);
         leafSchemaNodeBuilder.setType(binaryType);
         leafSchemaNode = leafSchemaNodeBuilder.build();
         assertEquals("new byte[] {-45}", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "01"));
 
         // boolean type
-        final BooleanType booleanType = BooleanType.getInstance();
+        final BooleanTypeDefinition booleanType = BaseTypes.booleanType();
         leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT);
         leafSchemaNodeBuilder.setType(booleanType);
         leafSchemaNode = leafSchemaNodeBuilder.build();
         assertEquals("new java.lang.Boolean(\"false\")", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "false"));
 
         // decimal type
-        final Decimal64 decimalType = Decimal64.create(refTypePath, 4);
+        final DecimalTypeDefinition decimalType = BaseTypes.decimalTypeBuilder(refTypePath).setFractionDigits(4).build();
         leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT);
         leafSchemaNodeBuilder.setType(decimalType);
         leafSchemaNode = leafSchemaNodeBuilder.build();
         assertEquals("new java.math.BigDecimal(\"111\")", typeProvider.getTypeDefaultConstruction(leafSchemaNode, "111"));
 
         // empty type
-        final EmptyType emptyType = EmptyType.getInstance();
+        final EmptyTypeDefinition emptyType = BaseTypes.emptyType();
         leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT);
         leafSchemaNodeBuilder.setType(emptyType);
         leafSchemaNode = leafSchemaNodeBuilder.build();
@@ -169,7 +166,7 @@ public class TypeProviderImplTest {
 
         // enum type
         expException.expect(NoSuchElementException.class);
-        final EnumerationType enumType = EnumerationType.create(refTypePath, new ArrayList<EnumTypeDefinition.EnumPair>(), Optional.<EnumPair> absent());
+        final EnumTypeDefinition enumType =  BaseTypes.enumerationTypeBuilder(refTypePath).build();
         leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT);
         leafSchemaNodeBuilder.setType(enumType);
         leafSchemaNode = leafSchemaNodeBuilder.build();
@@ -182,7 +179,10 @@ public class TypeProviderImplTest {
         final ModuleBuilder testModBuilder = new ModuleBuilder("test-module", "/test");
         final IdentitySchemaNodeBuilder identityNodeBuilder = testModBuilder.addIdentity(QName.create("IdentityRefTest"), 111, SchemaPath.ROOT);
         final IdentitySchemaNode identitySchemaNode = identityNodeBuilder.build();
-        final IdentityrefType identityRef = IdentityrefType.create(refTypePath, identitySchemaNode);
+
+        final IdentityrefTypeBuilder identityRefBuilder = BaseTypes.identityrefTypeBuilder(refTypePath);
+        identityRefBuilder.setIdentity(identitySchemaNode);
+        final IdentityrefTypeDefinition identityRef =  identityRefBuilder.build();
         leafSchemaNodeBuilder = new LeafSchemaNodeBuilder("test-module", 111, QName.create("Cont1"), SchemaPath.ROOT);
         leafSchemaNodeBuilder.setType(identityRef);