import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.io.IOException;
-import java.net.URISyntaxException;
import java.util.List;
import org.junit.Test;
import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
-import org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl;
import org.opendaylight.mdsal.binding.model.api.Enumeration;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.model.api.MethodSignature;
import org.opendaylight.mdsal.binding.model.api.Type;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
-import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
-import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class GenEnumResolvingTest {
@Test
- public void testLeafEnumResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
- File ietfInterfaces = new File(getClass().getResource("/enum-test-models/ietf-interfaces@2012-11-15.yang")
- .toURI());
- File ianaIfTypeModel = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI());
-
- final SchemaContext context = YangParserTestUtils.parseYangFiles(ietfInterfaces, ianaIfTypeModel);
+ public void testLeafEnumResolving() {
+ final SchemaContext context = YangParserTestUtils.parseYangResources(GenEnumResolvingTest.class,
+ "/enum-test-models/ietf-interfaces@2012-11-15.yang", "/ietf/iana-if-type.yang");
assertTrue(context != null);
- final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
assertTrue(genTypes != null);
assertNotNull("Generated Interface cannot contain NULL reference for Method Signature Definitions!", methods);
- assertEquals("Expected count of method signature definitions is 15", 15, methods.size());
+ assertEquals("Expected count of method signature definitions is 16", 16, methods.size());
Enumeration ianaIfType = null;
for (final MethodSignature method : methods) {
if (method.getName().equals("getType")) {
}
@Test
- public void testTypedefEnumResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
- File ianaIfType = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(ianaIfType);
+ public void testTypedefEnumResolving() {
+ final SchemaContext context = YangParserTestUtils.parseYangResource("/ietf/iana-if-type.yang");
assertTrue(context != null);
- final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
assertTrue(genTypes != null);
assertEquals(1, genTypes.size());
}
@Test
- public void testLeafrefEnumResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
- File abstractTopology = new File(getClass().getResource("/enum-test-models/abstract-topology@2013-02-08.yang")
- .toURI());
- File ietfInterfaces = new File(getClass().getResource("/enum-test-models/ietf-interfaces@2012-11-15.yang")
- .toURI());
- File ianaIfType = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI());
-
- final SchemaContext context = YangParserTestUtils.parseYangFiles(abstractTopology, ietfInterfaces,
- ianaIfType);
+ public void testLeafrefEnumResolving() {
+ final SchemaContext context = YangParserTestUtils.parseYangResources(GenEnumResolvingTest.class,
+ "/enum-test-models/abstract-topology@2013-02-08.yang", "/enum-test-models/ietf-interfaces@2012-11-15.yang",
+ "/ietf/iana-if-type.yang");
assertNotNull(context);
- final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
assertNotNull(genTypes);
assertTrue(!genTypes.isEmpty());
Type operStatus = null;
final List<MethodSignature> methods = genInterface.getMethodDefinitions();
assertNotNull("Generated Type Interface cannot contain NULL reference to Enumeration types!", methods);
- assertEquals("Generated Type Interface MUST contain 5 Methods ", 5, methods.size());
+ assertEquals("Generated Type Interface MUST contain 6 Methods ", 6, methods.size());
for (final MethodSignature method : methods) {
if (method.getName().equals("getLinkUpDownTrapEnable")) {
linkUpDownTrapEnable = method.getReturnType();
assertNotNull("Expected Referenced Enum LinkUpDownTrapEnable, but was NULL!", linkUpDownTrapEnable);
assertTrue("Expected LinkUpDownTrapEnable of type Enumeration", linkUpDownTrapEnable instanceof Enumeration);
- assertEquals(linkUpDownTrapEnable.getPackageName(),
- "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev121115.interfaces.Interface");
+ assertEquals(
+ "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev121115.interfaces.Interface",
+ linkUpDownTrapEnable.getIdentifier().immediatelyEnclosingClass().get().toString());
assertNotNull("Expected Referenced Enum OperStatus, but was NULL!", operStatus);
assertTrue("Expected OperStatus of type Enumeration", operStatus instanceof Enumeration);
- assertEquals(operStatus.getPackageName(),
- "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev121115.interfaces.Interface");
+ assertEquals(
+ "org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.interfaces.rev121115.interfaces.Interface",
+ operStatus.getIdentifier().immediatelyEnclosingClass().get().toString());
}
}