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.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.model.api.MethodSignature;
import org.opendaylight.mdsal.binding.model.api.Type;
+import org.opendaylight.mdsal.binding.spec.naming.BindingMapping;
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 GeneratedTypesTest {
@Test
- public void testMultipleModulesResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
- File abstractTopology = new File(getClass().getResource("/abstract-topology.yang").toURI());
- File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI());
-
- final SchemaContext context = YangParserTestUtils.parseYangFiles(abstractTopology, ietfInetTypes);
+ public void testMultipleModulesResolving() {
+ final SchemaContext context = YangParserTestUtils.parseYangResources(GeneratedTypesTest.class,
+ "/abstract-topology.yang", "/ietf/ietf-inet-types.yang");
assertNotNull(context);
- final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
assertNotNull(genTypes);
}
@Test
- public void testContainerResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
- final File testFile = new File(getClass().getResource("/simple-container-demo.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testFile);
+ public void testContainerResolving() {
+ final SchemaContext context = YangParserTestUtils.parseYangResource("/simple-container-demo.yang");
assertNotNull(context);
- final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
assertNotNull(genTypes);
}
assertNotNull(simpleContainer);
assertNotNull(nestedContainer);
- assertEquals(3, simpleContainer.getMethodDefinitions().size());
- assertEquals(2, nestedContainer.getMethodDefinitions().size());
+ assertEquals(4, simpleContainer.getMethodDefinitions().size());
+ assertEquals(3, nestedContainer.getMethodDefinitions().size());
int getFooMethodCounter = 0;
int getBarMethodCounter = 0;
}
@Test
- public void testLeafListResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
- final File testFile = new File(getClass().getResource("/simple-leaf-list-demo.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testFile);
+ public void testLeafListResolving() {
+ final SchemaContext context = YangParserTestUtils.parseYangResource("/simple-leaf-list-demo.yang");
assertNotNull(context);
- final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
assertNotNull(genTypes);
}
assertNotNull(simpleContainer);
assertNotNull(nestedContainer);
- assertEquals(3, simpleContainer.getMethodDefinitions().size());
- assertEquals(2, nestedContainer.getMethodDefinitions().size());
+ assertEquals(4, simpleContainer.getMethodDefinitions().size());
+ assertEquals(3, nestedContainer.getMethodDefinitions().size());
int getFooMethodCounter = 0;
int getBarMethodCounter = 0;
String getBarMethodReturnTypeName = "";
String getNestedContainerReturnTypeName = "";
for (final MethodSignature method : simpleContainer.getMethodDefinitions()) {
+ if (method.isDefault()) {
+ continue;
+ }
if (method.getName().equals("getFoo")) {
getFooMethodCounter++;
getFooMethodReturnTypeName = method.getReturnType().getName();
}
@Test
- public void testListResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
- final File testFile = new File(getClass().getResource("/simple-list-demo.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testFile);
+ public void testListResolving() {
+ final SchemaContext context = YangParserTestUtils.parseYangResource("/simple-list-demo.yang");
assertNotNull(context);
- final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
assertNotNull(genTypes);
simpleListMethodsCount = genType.getMethodDefinitions().size();
final List<MethodSignature> methods = genType.getMethodDefinitions();
for (final MethodSignature method : methods) {
- if (method.getName().equals("getKey")) {
- getSimpleListKeyMethodCount++;
- getSimpleListKeyMethodReturnTypeName = method.getReturnType().getName();
- } else if (method.getName().equals("getListChildContainer")) {
- getListChildContainerMethodCount++;
- getListChildContainerMethodReturnTypeName = method.getReturnType().getName();
- } else if (method.getName().equals("getFoo")) {
- getFooMethodCount++;
- } else if (method.getName().equals("setFoo")) {
- setFooMethodCount++;
- } else if (method.getName().equals("getSimpleLeafList")) {
- getSimpleLeafListMethodCount++;
- } else if (method.getName().equals("setSimpleLeafList")) {
- setSimpleLeafListMethodCount++;
- } else if (method.getName().equals("getBar")) {
- getBarMethodCount++;
+ switch (method.getName()) {
+ case BindingMapping.IDENTIFIABLE_KEY_NAME:
+ getSimpleListKeyMethodCount++;
+ getSimpleListKeyMethodReturnTypeName = method.getReturnType().getName();
+ break;
+ case "getListChildContainer":
+ getListChildContainerMethodCount++;
+ getListChildContainerMethodReturnTypeName = method.getReturnType().getName();
+ break;
+ case "getFoo":
+ getFooMethodCount++;
+ break;
+ case "setFoo":
+ setFooMethodCount++;
+ break;
+ case "getSimpleLeafList":
+ getSimpleLeafListMethodCount++;
+ break;
+ case "setSimpleLeafList":
+ setSimpleLeafListMethodCount++;
+ break;
+ case "getBar":
+ getBarMethodCount++;
+ break;
+ default:
}
}
} else if (genType.getName().equals("ListChildContainer")) {
}
}
- assertEquals(1, listParentContainerMethodsCount);
- assertEquals(1, listChildContainerMethodsCount);
+ assertEquals(3, listParentContainerMethodsCount);
+ assertEquals(2, listChildContainerMethodsCount);
assertEquals(1, getSimpleListKeyMethodCount);
assertEquals(1, listKeyClassCount);
assertEquals(0, setSimpleLeafListMethodCount);
assertEquals(1, getBarMethodCount);
- assertEquals(6, simpleListMethodsCount);
+ assertEquals(7, simpleListMethodsCount);
}
@Test
- public void testListCompositeKeyResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
- final File testFile = new File(getClass().getResource("/list-composite-key.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testFile);
+ public void testListCompositeKeyResolving() {
+ final SchemaContext context = YangParserTestUtils.parseYangResource("/list-composite-key.yang");
assertNotNull(context);
- final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
assertNotNull(genTypes);
}
@Test
- public void testGeneratedTypes() throws URISyntaxException, IOException, SourceException, ReactorException {
- final File testFile = new File(getClass().getResource("/demo-topology.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testFile);
+ public void testGeneratedTypes() {
+ final SchemaContext context = YangParserTestUtils.parseYangResource("/demo-topology.yang");
assertNotNull(context);
- final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
+ final BindingGenerator bindingGen = new BindingGeneratorImpl();
final List<Type> genTypes = bindingGen.generateTypes(context);
assertNotNull(genTypes);