@Test
public void testListGeneration() throws Exception {
final List<File> sourceFiles = getSourceFiles("/doc-gen");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
final Set<Module> modules = context.getModules();
final BasicCodeGenerator generator = new DocumentationGeneratorImpl();
Collection<File> generatedFiles = generator.generateSources(context, GENERATOR_OUTPUT_DIR, modules);
private static void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception {
final List<File> sourceFiles = getSourceFiles(resourceDirPath);
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
CodeGeneratorImpl codegen = new CodeGeneratorImpl();
codegen.setBuildContext(new DefaultBuildContext());
codegen.generateSources(context, sourcesOutputDir, context.getModules());
@Test
public void generateTestSourcesWithAdditionalConfig() throws Exception {
final List<File> sourceFiles = getSourceFiles("/yang-module-info");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
CodeGeneratorImpl codegen = new CodeGeneratorImpl();
codegen.setBuildContext(new DefaultBuildContext());
codegen.setResourceBaseDir(null);
@Test
public void testListGeneration() throws Exception {
final List<File> sourceFiles = getSourceFiles("/wadl-gen");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
final Set<Module> modules = context.getModules();
final BasicCodeGenerator generator = new WadlGenerator();
Collection<File> generatedWadlFiles = generator.generateSources(context, GENERATOR_OUTPUT_DIR, modules);
@Test
public void testListGenerationWithoutPath() throws Exception {
final List<File> sourceFiles = getSourceFiles("/wadl-gen");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
final Set<Module> modules = context.getModules();
final BasicCodeGenerator generator = new WadlGenerator();
Collection<File> generatedWadlFiles = generator.generateSources(context, null, modules);
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
-import java.io.File;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
*/
@Test
public void fromNormalizedNodeTest() throws Exception {
- final SchemaContext schemaCtx =
- YangParserTestUtils.parseYangFiles(new File(getClass().getResource("/test.yang").toURI()));
+ final SchemaContext schemaCtx = YangParserTestUtils.parseYangSource("/test.yang");
final NormalizedNode<?, ?> data = prepareData(schemaCtx, 42);
final Entry<InstanceIdentifier<?>, DataObject> fromNormalizedNode = fromNormalizedNode(data, schemaCtx);
*/
@Test
public void fromNormalizedNodeWithAnotherInputDataTest() throws Exception {
- final SchemaContext schemaCtx =
- YangParserTestUtils.parseYangFiles(new File(getClass().getResource("/test.yang").toURI()));
+ final SchemaContext schemaCtx = YangParserTestUtils.parseYangSource("/test.yang");
final NormalizedNode<?, ?> data = prepareData(schemaCtx, "42");
final Entry<InstanceIdentifier<?>, DataObject> fromNormalizedNode = fromNormalizedNode(data, schemaCtx);
@Test
public void AugmentationWithRelativeXPathTest() throws IOException, SourceException, ReactorException {
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull("context is null", context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
File ietfInterfaces = new File(getClass().getResource("/augment-test-models/ietf-interfaces@2012-11-15.yang")
.toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(abstractTopology, augmentTopology,
+ final SchemaContext context = YangParserTestUtils.parseYangSources(abstractTopology, augmentTopology,
augmentNetworkLink, augmentTopologyTunnels, ietfInterfaces);
assertNotNull("Schema Context is null", context);
import static org.junit.Assert.assertNotNull;
import java.io.File;
+import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import org.junit.BeforeClass;
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.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 BinaryTypeTest {
}
@Test
- public void binaryTypeTest() throws Exception {
- final SchemaContext context = YangParserTestUtils.parseYangFiles(yangModels);
+ public void binaryTypeTest() throws IOException, SourceException, ReactorException {
+ final SchemaContext context = YangParserTestUtils.parseYangSources(yangModels);
assertNotNull("context is null", context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+
import com.google.common.collect.ImmutableList;
import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.URISyntaxException;
import java.util.List;
import org.junit.Test;
+import org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl;
import org.opendaylight.mdsal.binding.model.api.GeneratedType;
import org.opendaylight.mdsal.binding.model.api.ParameterizedType;
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.test.util.YangParserTestUtils;
public class BindingGeneratorImplTest {
@Test
- public void isisTotpologyStatementParserTest() throws Exception {
- final File topo = new File(getClass().getResource("/isis-topology/network-topology@2013-10-21.yang").toURI());
- final File isis = new File(getClass().getResource("/isis-topology/isis-topology@2013-10-21.yang").toURI());
- final File l3 =
- new File(getClass().getResource("/isis-topology/l3-unicast-igp-topology@2013-10-21.yang").toURI());
+ public void isisTotpologyStatementParserTest() throws IOException,
+ URISyntaxException, ReactorException {
+ final InputStream topo = getClass().getResourceAsStream("/isis-topology/network-topology@2013-10-21.yang");
+ final InputStream isis = getClass().getResourceAsStream("/isis-topology/isis-topology@2013-10-21.yang");
+ final InputStream l3 = getClass().getResourceAsStream("/isis-topology/l3-unicast-igp-topology@2013-10-21.yang");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(ImmutableList.of(isis, l3, topo));
+ SchemaContext context = YangParserTestUtils.parseYangStreams(ImmutableList.of(isis, l3, topo));
assertNotNull(context);
- final List<Type> generateTypes = new BindingGeneratorImpl(false)
+ List<Type> generateTypes = new BindingGeneratorImpl(false)
.generateTypes(context);
assertFalse(generateTypes.isEmpty());
}
@Test
- public void choiceNodeGenerationTest() throws Exception {
- final File resourceFile = new File(getClass().getResource(
+ public void choiceNodeGenerationTest() throws IOException,
+ URISyntaxException, ReactorException {
+ File resourceFile = new File(getClass().getResource(
"/binding-generator-impl-test/choice-test.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(resourceFile);
+ SchemaContext context = YangParserTestUtils.parseYangSources(resourceFile);
- final List<Type> generateTypes = new BindingGeneratorImpl(false)
+ List<Type> generateTypes = new BindingGeneratorImpl(false)
.generateTypes(context);
GeneratedType choiceTestData = null;
GeneratedType myList2 = null;
GeneratedType myContainer2 = null;
- for (final Type type : generateTypes) {
+ for (Type type : generateTypes) {
switch (type.getName()) {
case "ChoiceTestData":
choiceTestData = (GeneratedType) type;
List<Type> implements1 = myContainer.getImplements();
Type childOfParamType = null;
- for (final Type type : implements1) {
+ for (Type type : implements1) {
if (type.getName().equals("ChildOf")) {
childOfParamType = ((ParameterizedType) type)
.getActualTypeArguments()[0];
implements1 = myList.getImplements();
childOfParamType = null;
- for (final Type type : implements1) {
+ for (Type type : implements1) {
if (type.getName().equals("ChildOf")) {
childOfParamType = ((ParameterizedType) type)
.getActualTypeArguments()[0];
implements1 = myContainer2.getImplements();
childOfParamType = null;
- for (final Type type : implements1) {
+ for (Type type : implements1) {
if (type.getName().equals("ChildOf")) {
childOfParamType = ((ParameterizedType) type)
.getActualTypeArguments()[0];
implements1 = myList2.getImplements();
childOfParamType = null;
- for (final Type type : implements1) {
+ for (Type type : implements1) {
if (type.getName().equals("ChildOf")) {
childOfParamType = ((ParameterizedType) type)
.getActualTypeArguments()[0];
}
@Test
- public void notificationGenerationTest() throws Exception {
- final File resourceFile = new File(getClass().getResource(
+ public void notificationGenerationTest() throws IOException, URISyntaxException, ReactorException {
+ File resourceFile = new File(getClass().getResource(
"/binding-generator-impl-test/notification-test.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(resourceFile);
+ SchemaContext context = YangParserTestUtils.parseYangSources(resourceFile);
- final List<Type> generateTypes = new BindingGeneratorImpl(false)
+ List<Type> generateTypes = new BindingGeneratorImpl(false)
.generateTypes(context);
GeneratedType foo = null;
- for (final Type type : generateTypes) {
+ for (Type type : generateTypes) {
if (type.getName().equals("Foo")) {
foo = (GeneratedType) type;
break;
Type childOf = null;
Type dataObject = null;
- final List<Type> impl = foo.getImplements();
- for (final Type type : impl) {
+ List<Type> impl = foo.getImplements();
+ for (Type type : impl) {
switch (type.getName()) {
case "ChildOf":
childOf = type;
public static void parseResources() throws IOException, SourceException, ReactorException {
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
File resourceFile = new File(getClass().getResource(
"/bug-4145/foo.yang").toURI());
- SchemaContext context = YangParserTestUtils.parseYangFiles(resourceFile);
+ SchemaContext context = YangParserTestUtils.parseYangSources(resourceFile);
List<Type> generateTypes = new BindingGeneratorImpl(false)
.generateTypes(context);
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
-import java.io.File;
+
+import java.io.FileNotFoundException;
+import java.net.URISyntaxException;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
+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.Type;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class Bug6135Test {
@Ignore
@Test
- public void bug6135Test() throws Exception {
- final SchemaContext context = YangParserTestUtils
- .parseYangFiles(new File(Bug6135Test.class.getResource("/bug-6135/foo.yang").toURI()));
+ public void bug6135Test() throws FileNotFoundException, ReactorException, URISyntaxException {
+ final SchemaContext context = YangParserTestUtils.parseYangSource("/bug-6135/foo.yang");
assertNotNull(context);
final List<Type> generateTypes = new BindingGeneratorImpl(false).generateTypes(context);
@Test
public void choiceCaseResolvingTypeTest() throws IOException, SourceException, ReactorException {
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull("context is null", context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
File co = new File(getClass().getResource("/controller-models/controller-openflow.yang").toURI());
File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(cn, co, ietfInetTypes);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(cn, co, ietfInetTypes);
assertNotNull("Schema Context is null", context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
File abstractTopology = new File(getClass().getResource("/typedef-of-typedef/typedef_of_typedef.yang").toURI());
File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(abstractTopology, ietfInetTypes);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(abstractTopology, ietfInetTypes);
assertNotNull("Schema Context is null", context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
.toURI());
File ianaIfTypeModel = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(ietfInterfaces, ianaIfTypeModel);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(ietfInterfaces, ianaIfTypeModel);
assertTrue(context != null);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
@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);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(ianaIfType);
assertTrue(context != null);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
final List<Type> genTypes = bindingGen.generateTypes(context);
.toURI());
File ianaIfType = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(abstractTopology, ietfInterfaces,
+ final SchemaContext context = YangParserTestUtils.parseYangSources(abstractTopology, ietfInterfaces,
ianaIfType);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI());
File ietfYangTypes = new File(getClass().getResource("/ietf/ietf-yang-types.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(abstractTopology, ietfInterfaces,
+ final SchemaContext context = YangParserTestUtils.parseYangSources(abstractTopology, ietfInterfaces,
ietfInetTypes, ietfYangTypes);
Set<Module> modules = context.getModules();
File ietfYangTypes = new File(getClass().getResource("/ietf/ietf-yang-types.yang").toURI());
File ianaIfType = new File(getClass().getResource("/ietf/iana-if-type.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(abstractTopology, ietfInterfaces,
+ final SchemaContext context = YangParserTestUtils.parseYangSources(abstractTopology, ietfInterfaces,
ietfInetTypes, ietfYangTypes, ianaIfType);
assertNotNull("Schema Context is null", context);
final Set<Module> modules = context.getModules();
public void testInnerClassCreationForBitsAndUnionsInLeafes() throws Exception {
final URI yangTypesPath = getClass().getResource("/bit_and_union_in_leaf.yang").toURI();
- final SchemaContext context = YangParserTestUtils.parseYangFiles(new File(yangTypesPath));
+ final SchemaContext context = YangParserTestUtils.parseYangSources(new File(yangTypesPath));
assertTrue(context != null);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
public void testGeneretedTypesBitsTest() throws Exception {
final URI yangTypesPath = getClass().getResource("/simple-bits-demo.yang").toURI();
- final SchemaContext context = YangParserTestUtils.parseYangFiles(new File(yangTypesPath));
+ final SchemaContext context = YangParserTestUtils.parseYangSources(new File(yangTypesPath));
assertTrue(context != null);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
import static org.junit.Assert.fail;
import java.io.File;
+import java.io.IOException;
import java.net.URI;
+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.GeneratedProperty;
import org.opendaylight.mdsal.binding.model.api.GeneratedTransferObject;
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 GeneratedTypesLeafrefTest {
@Test
- public void testLeafrefResolving() throws Exception {
- final File abstractTopology = new File(getClass().getResource(
+ public void testLeafrefResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
+ File abstractTopology = new File(getClass().getResource(
"/leafref-test-models/abstract-topology@2013-02-08.yang").toURI());
- final File ietfInterfaces = new File(getClass().getResource("/ietf/ietf-interfaces.yang").toURI());
- final File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI());
- final File ietfYangTypes = new File(getClass().getResource("/ietf/ietf-yang-types.yang").toURI());
+ File ietfInterfaces = new File(getClass().getResource("/ietf/ietf-interfaces.yang").toURI());
+ File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI());
+ File ietfYangTypes = new File(getClass().getResource("/ietf/ietf-yang-types.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(abstractTopology, ietfInterfaces,
+ final SchemaContext context = YangParserTestUtils.parseYangSources(abstractTopology, ietfInterfaces,
ietfInetTypes, ietfYangTypes);
assertNotNull(context);
assertEquals(4, context.getModules().size());
GeneratedTransferObject gtTunnelKey = null;
GeneratedType gtTopology = null;
for (final Type type : genTypes) {
- final String name = type.getName();
+ String name = type.getName();
if ("InterfaceKey".equals(name)) {
gtIfcKey = (GeneratedTransferObject) type;
} else if ("Interface".equals(name)) {
}
}
assertNotNull(condLeafref);
- final Type condLeafRT = condLeafref.getReturnType();
+ Type condLeafRT = condLeafref.getReturnType();
assertNotNull(condLeafRT);
assertEquals("java.lang.Object", condLeafRT.getFullyQualifiedName());
}
}
assertNotNull(ifcIdProp);
- final Type ifcIdPropType = ifcIdProp.getReturnType();
+ Type ifcIdPropType = ifcIdProp.getReturnType();
assertNotNull(ifcIdPropType);
assertEquals("java.lang.String", ifcIdPropType.getFullyQualifiedName());
}
}
assertNotNull(getIfcKey);
- final Type getIfcKeyType = getIfcKey.getReturnType();
+ Type getIfcKeyType = getIfcKey.getReturnType();
assertNotNull(getIfcKeyType);
assertNotSame("java.lang.Void", getIfcKeyType);
assertEquals("InterfaceKey", getIfcKeyType.getName());
assertNotNull(getHigherLayerIf);
- final Type getHigherLayerIfType = getHigherLayerIf.getReturnType();
+ Type getHigherLayerIfType = getHigherLayerIf.getReturnType();
assertNotNull(getHigherLayerIfType);
assertNotSame("java.lang.Void", getHigherLayerIfType);
assertEquals("List", getHigherLayerIfType.getName());
final List<MethodSignature> gtNetworkLinkMethods = gtNetworkLink.getMethodDefinitions();
assertNotNull(gtNetworkLinkMethods);
MethodSignature getIfc = null;
- for (final MethodSignature method : gtNetworkLinkMethods) {
+ for (MethodSignature method : gtNetworkLinkMethods) {
if (method.getName().equals("getInterface")) {
getIfc = method;
}
}
assertNotNull(getIfc);
- final Type getIfcType = getIfc.getReturnType();
+ Type getIfcType = getIfc.getReturnType();
assertNotNull(getIfcType);
assertNotSame("java.lang.Void", getIfcType);
assertEquals("String", getIfcType.getName());
final List<MethodSignature> gtSourceMethods = gtSource.getMethodDefinitions();
assertNotNull(gtSourceMethods);
MethodSignature getIdSource = null;
- for (final MethodSignature method : gtSourceMethods) {
+ for (MethodSignature method : gtSourceMethods) {
if (method.getName().equals("getId")) {
getIdSource = method;
}
}
assertNotNull(getIdSource);
- final Type getIdType = getIdSource.getReturnType();
+ Type getIdType = getIdSource.getReturnType();
assertNotNull(getIdType);
assertNotSame("java.lang.Void", getIdType);
assertEquals("Uri", getIdType.getName());
final List<MethodSignature> gtDestMethods = gtDest.getMethodDefinitions();
assertNotNull(gtDestMethods);
MethodSignature getIdDest = null;
- for (final MethodSignature method : gtDestMethods) {
+ for (MethodSignature method : gtDestMethods) {
if (method.getName().equals("getId")) {
getIdDest = method;
}
}
assertNotNull(getIdDest);
- final Type getIdDestType = getIdDest.getReturnType();
+ Type getIdDestType = getIdDest.getReturnType();
assertNotNull(getIdDestType);
assertNotSame("java.lang.Void", getIdDestType);
assertEquals("Uri", getIdDestType.getName());
final List<MethodSignature> gtTunnelMethods = gtTunnel.getMethodDefinitions();
assertNotNull(gtTunnelMethods);
MethodSignature getTunnelKey = null;
- for (final MethodSignature method : gtTunnelMethods) {
+ for (MethodSignature method : gtTunnelMethods) {
if (method.getName().equals("getKey")) {
getTunnelKey = method;
}
}
assertNotNull(getTunnelKey);
- final Type getTunnelKeyType = getTunnelKey.getReturnType();
+ Type getTunnelKeyType = getTunnelKey.getReturnType();
assertNotNull(getTunnelKeyType);
assertNotSame("java.lang.Void", getTunnelKeyType);
assertEquals("TunnelKey", getTunnelKeyType.getName());
}
}
assertNotNull(tunnelId);
- final Type tunnelIdType = tunnelId.getReturnType();
+ Type tunnelIdType = tunnelId.getReturnType();
assertNotNull(tunnelIdType);
assertNotSame("java.lang.Void", tunnelIdType);
assertEquals("Uri", tunnelIdType.getName());
}
@Test
- public void testLeafrefInvalidPathResolving() throws Exception {
+ public void testLeafrefInvalidPathResolving() throws URISyntaxException, IOException, SourceException, ReactorException {
final URI resource = getClass().getResource("/leafref-test-invalid-model/foo.yang").toURI();
assertNotNull(resource);
- final SchemaContext context = YangParserTestUtils.parseYangFiles(new File(resource));
+ final SchemaContext context = YangParserTestUtils.parseYangSources(new File(resource));
assertNotNull(context);
assertEquals(1, context.getModules().size());
try {
bindingGen.generateTypes(context);
fail("Expected IllegalArgumentException caused by invalid leafref path");
- } catch (final IllegalArgumentException e) {
- final String expected = "Failed to find leafref target";
+ } catch (IllegalArgumentException e) {
+ String expected = "Failed to find leafref target";
assertTrue(e.getMessage().contains(expected));
}
}
@Test
public void constantGenerationTest() throws IOException, SourceException, ReactorException {
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
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);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(abstractTopology, ietfInetTypes);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
@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);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testFile);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
@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);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testFile);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
@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);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testFile);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
@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);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testFile);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
@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);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testFile);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
*/
@Test
public void testIdentityrefYangBuiltInType() throws IOException, SourceException, ReactorException {
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
.toURI());
File ietfInetTypes = new File(TypeProviderIntegrationTest.class.getResource("/ietf/ietf-inet-types.yang")
.toURI());
- context = YangParserTestUtils.parseYangFiles(abstractTopology, ietfInetTypes);
+ context = YangParserTestUtils.parseYangSources(abstractTopology, ietfInetTypes);
assertNotNull(context);
}
public void unionTypeResolvingTest() throws Exception {
final File abstractTopology = new File(getClass().getResource("/union-test-models/abstract-topology.yang").toURI());
final File ietfInetTypes = new File(getClass().getResource("/ietf/ietf-inet-types.yang").toURI());
- final SchemaContext context = YangParserTestUtils.parseYangFiles(abstractTopology, ietfInetTypes);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(abstractTopology, ietfInetTypes);
assertNotNull("context is null", context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
@Test
public void unionTypedefLeafrefTest() throws Exception {
final File yang = new File(getClass().getResource("/leafref_typedef_union/bug8449.yang").toURI());
- final SchemaContext schemaContext = YangParserTestUtils.parseYangFiles(yang);
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(yang);
assertNotNull(schemaContext);
final List<Type> generateTypes = new BindingGeneratorImpl(false).generateTypes(schemaContext);
assertNotNull(generateTypes);
@Test
public void usesInGroupingDependenciesTest() throws IOException, SourceException, ReactorException {
List<File> testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-dependencies.yang");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
public void usesInCaseTest() throws IOException, SourceException, ReactorException {
List<File> testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-case.yang");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
public void usesInContainerTest() throws IOException, SourceException, ReactorException {
List<File> testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-container.yang");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
public void usesInGroupingTest() throws IOException, SourceException, ReactorException {
List<File> testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-grouping.yang");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
public void usesInListTest() throws IOException, SourceException, ReactorException {
List<File> testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-list.yang");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
public void usesInModulTest() throws IOException, SourceException, ReactorException {
List<File> testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-modul.yang");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
public void usesInRpcTest() throws IOException, SourceException, ReactorException {
List<File> testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-rpc.yang");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
public void usesInAugmentTest() throws IOException, SourceException, ReactorException {
List<File> testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-augment.yang");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
public void usesInNotification() throws IOException, SourceException, ReactorException {
List<File> testModels = loadTestResources("/uses-of-grouping/uses-of-grouping-notification.yang");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.io.File;
+import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Collections;
import org.opendaylight.yangtools.yang.model.api.type.StringTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.UnsignedIntegerTypeDefinition;
+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;
/**
private static BooleanTypeDefinition bool = null;
@BeforeClass
- public static void setup() throws Exception {
- final List<File> modelsToParse = Collections
- .singletonList(new File(BaseYangTypesTest.class.getResource("/base-yang-types.yang").toURI()));
- schemaContext = YangParserTestUtils.parseYangFiles(modelsToParse);
+ public static void setup() throws SourceException, ReactorException {
+ final List<InputStream> modelsToParse = Collections
+ .singletonList(BaseYangTypesTest.class.getResourceAsStream("/base-yang-types.yang"));
+ schemaContext = YangParserTestUtils.parseYangStreams(modelsToParse);
assertNotNull(schemaContext);
initTypeDefinitionsFromSchemaContext();
}
import static org.junit.Assert.assertNotNull;
import java.io.File;
+import java.io.FileNotFoundException;
import java.net.URI;
+import java.net.URISyntaxException;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
+import org.opendaylight.mdsal.binding.yang.types.TypeProviderImpl;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
import org.opendaylight.yangtools.yang.model.api.LeafSchemaNode;
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.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class Bug4621 {
public ExpectedException expectedEx = ExpectedException.none();
@Test
- public void bug4621test() throws Exception {
- final File file = new File(getClass().getResource("/bug-4621/foo.yang").toURI());
+ public void bug4621test() throws FileNotFoundException, ReactorException, URISyntaxException {
+ File file = new File(getClass().getResource("/bug-4621/foo.yang").toURI());
- final SchemaContext schemaContext = YangParserTestUtils.parseYangFiles(file);
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(file);
final Module moduleValid = schemaContext.findModuleByNamespace(new URI("foo")).iterator().next();
final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
final QName listNode = QName.create(moduleValid.getQNameModule(), "neighbor");
final QName leafrefNode = QName.create(moduleValid.getQNameModule(), "neighbor2-id");
- final DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName(listNode))
+ DataSchemaNode leafrefRel = ((ListSchemaNode) moduleValid.getDataChildByName(listNode))
.getDataChildByName(leafrefNode);
- final LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel;
- final TypeDefinition<?> leafTypeRel = leafRel.getType();
+ LeafSchemaNode leafRel = (LeafSchemaNode) leafrefRel;
+ TypeDefinition<?> leafTypeRel = leafRel.getType();
assertNotNull(typeProvider.javaTypeForSchemaDefinitionType(leafTypeRel, leafRel));
}
}
\ No newline at end of file
public void testLeafRefRelativeSelfReference() throws Exception {
File relative = new File(getClass().getResource("/leafref/leafref-relative-invalid.yang").toURI());
- final SchemaContext schemaContext = YangParserTestUtils.parseYangFiles(relative);
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(relative);
final Module moduleRelative = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lrr")).iterator()
.next();
final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
public void testLeafRefAbsoluteSelfReference() throws Exception {
File relative = new File(getClass().getResource("/leafref/leafref-absolute-invalid.yang").toURI());
- final SchemaContext schemaContext = YangParserTestUtils.parseYangFiles(relative);
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(relative);
final Module moduleRelative = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lra")).iterator()
.next();
final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
public void testLeafRefRelativeAndAbsoluteValidReference() throws Exception {
File valid = new File(getClass().getResource("/leafref/leafref-valid.yang").toURI());
- final SchemaContext schemaContext = YangParserTestUtils.parseYangFiles(valid);
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(valid);
final Module moduleValid = schemaContext.findModuleByNamespace(new URI("urn:xml:ns:yang:lrv")).iterator()
.next();
final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
public void testMethodsOfTypeProviderImpl() throws Exception {
final File abstractTopology = new File(getClass().getResource("/base-yang-types.yang").toURI());
- final SchemaContext schemaContext = YangParserTestUtils.parseYangFiles(abstractTopology);
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangSources(abstractTopology);
final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
*/
package org.opendaylight.mdsal.binding.yang.types;
-import java.io.File;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.List;
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;
/**
private static final String TEST_TYPE_PROVIDER_PATH = "/"+TEST_TYPE_PROVIDER_MODULE_NAME+".yang";
private static final String TEST_TYPE_PROVIDER_B_PATH = "/test-type-provider-b.yang";
- private static File getFile(final String resourceName) throws Exception {
- return new File(TypeProviderModel.class.getResource(resourceName).toURI());
+ private static InputStream getInputStream(final String resourceName) {
+ return TypeProviderModel.class.getResourceAsStream(resourceName);
}
- private static List<File> provideTestModelStreams() throws Exception {
- final List<File> arrayList = new ArrayList<>();
+ private static List<InputStream> provideTestModelStreams() {
+ final List<InputStream> arrayList = new ArrayList<>();
- arrayList.add(getFile(BASE_YANG_TYPES_PATH));
- arrayList.add(getFile(TEST_TYPE_PROVIDER_PATH));
- arrayList.add(getFile(TEST_TYPE_PROVIDER_B_PATH));
+ arrayList.add(getInputStream(BASE_YANG_TYPES_PATH));
+ arrayList.add(getInputStream(TEST_TYPE_PROVIDER_PATH));
+ arrayList.add(getInputStream(TEST_TYPE_PROVIDER_B_PATH));
return arrayList;
}
- public static SchemaContext createTestContext() throws Exception {
- return YangParserTestUtils.parseYangFiles(provideTestModelStreams());
+ public static SchemaContext createTestContext() throws SourceException, ReactorException {
+ return YangParserTestUtils.parseYangStreams(provideTestModelStreams());
}
}
import org.opendaylight.yangtools.yang.model.api.type.LeafrefTypeDefinition;
import org.opendaylight.yangtools.yang.model.api.type.RangeConstraint;
import org.opendaylight.yangtools.yang.model.api.type.UnionTypeDefinition;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
+import org.opendaylight.yangtools.yang.parser.spi.source.SourceException;
/**
* Test suite for testing public methods in TypeProviderImpl class
private SchemaNode schemaNode;
@Before
- public void setUp() throws Exception {
+ public void setUp() throws SourceException, ReactorException {
MockitoAnnotations.initMocks(this);
this.schemaContext = TypeProviderModel.createTestContext();
assertNotNull(this.schemaContext);
public void testBindingGeneratorUtilMethods() throws Exception {
List<File> testModels = loadTestResources("/module.yang");
- final Set<Module> modules = YangParserTestUtils.parseYangFiles(testModels).getModules();
+ final Set<Module> modules = YangParserTestUtils.parseYangSources(testModels).getModules();
String packageName = "";
Module module = null;
for (Module m : modules) {
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
final List<File> sourceFiles = CompilationTestUtils.getSourceFiles("/compilation/augment-uses-to-augment");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
generator.generateToFile(sourcesOutputDir);
private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception {
final List<File> sourceFiles = CompilationTestUtils.getSourceFiles(resourceDirPath);
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
generator.generateToFile(sourcesOutputDir);
private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception {
final List<File> sourceFiles = CompilationTestUtils.getSourceFiles(resourceDirPath);
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
generator.generateToFile(sourcesOutputDir);
private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception {
final List<File> sourceFiles = getSourceFiles(resourceDirPath);
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
generator.generateToFile(sourcesOutputDir);
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
final List<File> sourceFiles = getSourceFiles("/compilation/cascade-uses");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
generator.generateToFile(sourcesOutputDir);
@Test
public void compositeKeyClassTest() throws IOException, SourceException, ReactorException {
- final SchemaContext context = YangParserTestUtils.parseYangFiles(testModels);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(testModels);
assertNotNull(context);
final BindingGenerator bindingGen = new BindingGeneratorImpl(true);
private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception {
final List<File> sourceFiles = CompilationTestUtils.getSourceFiles(resourceDirPath);
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
Collections.sort(types, (o1, o2) -> o2.getName().compareTo(o1.getName()));
final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
final List<File> sourceFiles = getSourceFiles("/compilation/encoding-javadoc");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
generator.generateToFile(sourcesOutputDir);
private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception {
final List<File> sourceFiles = getSourceFiles(resourceDirPath);
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
generator.generateToFile(sourcesOutputDir);
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
final List<File> sourceFiles = CompilationTestUtils.getSourceFiles("/compilation/typedef");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
generator.generateToFile(sourcesOutputDir);
assertTrue("Failed to create test file '" + compiledOutputDir + "'", compiledOutputDir.mkdir());
final List<File> sourceFiles = getSourceFiles("/compilation/union-typedef");
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
final GeneratorJavaFile generator = new GeneratorJavaFile(new HashSet<>(types));
generator.generateToFile(sourcesOutputDir);
private void generateTestSources(final String resourceDirPath, final File sourcesOutputDir) throws Exception {
final List<File> sourceFiles = CompilationTestUtils.getSourceFiles(resourceDirPath);
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sourceFiles);
final List<Type> types = bindingGenerator.generateTypes(context);
final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
generator.generateToFile(sourcesOutputDir);
import static org.mockito.Mockito.when;
import com.google.common.base.Optional;
-import java.io.File;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
assertNotNull(generate);
generate.setAccessible(true);
- final SchemaContext context =
- YangParserTestUtils.parseYangFiles(new File(getClass().getResource("/generator/test.yang").toURI()));
+ final SchemaContext context = YangParserTestUtils.parseYangSource("/generator/test.yang");
final TypeProvider typeProvider = new TypeProviderImpl(context);
final Map<Module, ModuleContext> genCtx = new HashMap<>();
final Map<String, Map<String, GeneratedTypeBuilder>> genTypeBuilders = new HashMap<>();
assertNotNull(generate);
generate.setAccessible(true);
- final SchemaContext context = YangParserTestUtils
- .parseYangFiles(new File(getClass().getResource("/generator/test-augment.yang").toURI()));
+ final SchemaContext context = YangParserTestUtils.parseYangSource("/generator/test-augment.yang");
final TypeProvider typeProvider = new TypeProviderImpl(context);
final Map<Module, ModuleContext> genCtx = mock(Map.class);
final Collection<ModuleContext> moduleContexts = new ArrayList<>();
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
-import java.io.File;
+
import java.io.FileNotFoundException;
import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;
assertNotNull(generate);
generate.setAccessible(true);
- final SchemaContext schemaContext = YangParserTestUtils
- .parseYangFiles(new File(getClass().getResource("/generator/test-list.yang").toURI()));
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/generator/test-list.yang");
final ListSchemaNode containerSchemaNode =
(ListSchemaNode) schemaContext.getModules().iterator().next().getChildNodes().iterator().next();
final String fullyQualifiedName =
generate.setAccessible(true);
final SchemaContext schemaContext =
- YangParserTestUtils.parseYangFiles(
- new File(getClass().getResource("/base/test-leaf-with-description.yang").toURI()));
+ YangParserTestUtils.parseYangSource("/base/test-leaf-with-description.yang");
final LeafSchemaNode containerSchemaNode =
(LeafSchemaNode) schemaContext.getModules().iterator().next().getChildNodes().iterator().next();
final String fullyQualifiedName = "test.base.cont.with.leaf.MyList";
assertNotNull(generate);
generate.setAccessible(true);
- final SchemaContext schemaContext =
- YangParserTestUtils.parseYangFiles(new File(getClass().getResource("/base/test-module.yang").toURI()));
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/base/test-module.yang");
final Object[] args = { schemaContext.getModules().iterator().next(), true };
final String result = (String) generate.invoke(AuxiliaryGenUtils.class, args);
assertNotNull(generate);
generate.setAccessible(true);
- final SchemaContext schemaContext = YangParserTestUtils
- .parseYangFiles(new File(getClass().getResource("/base/test-rpc-and-notification.yang").toURI()));
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/base/test-rpc-and-notification.yang");
final Module module = schemaContext.getModules().iterator().next();
Set schemaNodes = new HashSet<>();
schemaNodes.add(module.getRpcs().iterator().next());
final GeneratedTypeBuilder typeBuilder =
new GeneratedTypeBuilderImpl("test.boolean.spc.def", "spec-type-def", new ModuleContext());
- final SchemaContext schemaContext =
- YangParserTestUtils.parseYangFiles(new File(getClass().getResource(yangPath).toURI()));
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangSource(yangPath);
final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
final LeafSchemaNode leafSchemaNode =
(LeafSchemaNode) schemaContext.getModules().iterator().next().getChildNodes().iterator().next();
final GeneratedTypeBuilder typeBuilder = new GeneratedTypeBuilderImpl("test.boolean.spc.def",
"spec-type-def", new ModuleContext());
- final SchemaContext schemaContext =
- YangParserTestUtils.parseYangFiles(new File(getClass().getResource("/base/test-union.yang").toURI()));
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/base/test-union.yang");
final TypeProviderImpl typeProvider = new TypeProviderImpl(schemaContext);
final LeafSchemaNode leafSchemaNode =
(LeafSchemaNode) schemaContext.getModules().iterator().next().getChildNodes().iterator().next();
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import java.io.File;
-import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
@Test
public void genTypesTypeDefTest() throws Exception {
final BindingGeneratorImpl bg = new BindingGeneratorImpl(false);
- final SchemaContext schemaContext = YangParserTestUtils
- .parseYangFiles(new File(getClass().getResource("/generator/test-typedef.yang").toURI()));
+ final SchemaContext schemaContext = YangParserTestUtils.parseYangSource("/generator/test-typedef.yang");
final List<Type> generateTypes = bg.generateTypes(schemaContext);
assertNotNull(generateTypes);
for (final Type genType : generateTypes) {
@Test
public void generatedTypesEnumTest() throws Exception {
final BindingGenerator bg = new BindingGeneratorImpl(false);
- final SchemaContext context = YangParserTestUtils
- .parseYangFiles(new File(getClass().getResource("/generator/apple-test.yang").toURI()));
+ final SchemaContext context = YangParserTestUtils.parseYangSource("/generator/apple-test.yang");
final List<Type> generateTypes = bg.generateTypes(context);
assertNotNull(generateTypes);
assertTrue(!generateTypes.isEmpty());
@Test
public void generatedTypesUsesEnumLeafTest() throws Exception {
final BindingGenerator bg = new BindingGeneratorImpl(false);
- final List<File> sources = new ArrayList<>();
- sources.add(new File(getClass().getResource("/uses-statement/test-uses-leaf-innertype-base.yang").toURI()));
- sources.add(new File(getClass().getResource("/uses-statement/test-uses-leaf-innertype.yang").toURI()));
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sources);
+ final List<String> sources = new ArrayList<>();
+ sources.add("/uses-statement/test-uses-leaf-innertype-base.yang");
+ sources.add("/uses-statement/test-uses-leaf-innertype.yang");
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sources);
final List<Type> generateTypes = bg.generateTypes(context);
assertNotNull(generateTypes);
assertTrue(!generateTypes.isEmpty());
@Test
public void generatedTypesUsesBitsLeafTest() throws Exception {
final BindingGenerator bg = new BindingGeneratorImpl(false);
- final List<File> sources = new ArrayList<>();
- sources.add(new File(getClass().getResource("/uses-statement/test-uses-leaf-innertype2-base.yang").toURI()));
- sources.add(new File(getClass().getResource("/uses-statement/test-uses-leaf-innertype2.yang").toURI()));
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sources);
+ final List<String> sources = new ArrayList<>();
+ sources.add("/uses-statement/test-uses-leaf-innertype2-base.yang");
+ sources.add("/uses-statement/test-uses-leaf-innertype2.yang");
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sources);
final List<Type> generateTypes = bg.generateTypes(context);
assertNotNull(generateTypes);
assertTrue(!generateTypes.isEmpty());
if (type.getName().equals("MyCont") && type.getPackageName()
.equals("org.opendaylight.mdsal.gen.javav2.urn.test.uses.leaf.innertype2.base.rev170809.data")) {
final GeneratedType gt = (GeneratedType) type;
- for (final MethodSignature methodSignature : gt.getMethodDefinitions()) {
+ for (MethodSignature methodSignature : gt.getMethodDefinitions()) {
if (methodSignature.getName().equals("getLeafBits")) {
assertEquals("LeafBits", methodSignature.getReturnType().getName());
}
if (type.getName().equals("MyCont") && type.getPackageName()
.equals("org.opendaylight.mdsal.gen.javav2.urn.test.uses.leaf.innertype2.rev170809.data")) {
final GeneratedType gt = (GeneratedType) type;
- for (final MethodSignature methodSignature : gt.getMethodDefinitions()) {
+ for (MethodSignature methodSignature : gt.getMethodDefinitions()) {
if (methodSignature.getName().equals("getLeafBits")) {
assertEquals("LeafBits", methodSignature.getReturnType().getName());
}
@Test
public void generatedTypesUsesUnionLeafTest() throws Exception {
final BindingGenerator bg = new BindingGeneratorImpl(false);
- final List<File> sources = new ArrayList<>();
- sources.add(new File(getClass().getResource("/uses-statement/test-uses-leaf-innertype2-base.yang").toURI()));
- sources.add(new File(getClass().getResource("/uses-statement/test-uses-leaf-innertype2.yang").toURI()));
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sources);
+ final List<String> sources = new ArrayList<>();
+ sources.add("/uses-statement/test-uses-leaf-innertype2-base.yang");
+ sources.add("/uses-statement/test-uses-leaf-innertype2.yang");
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sources);
final List<Type> generateTypes = bg.generateTypes(context);
assertNotNull(generateTypes);
assertTrue(!generateTypes.isEmpty());
if (type.getName().equals("MyCont") && type.getPackageName()
.equals("org.opendaylight.mdsal.gen.javav2.urn.test.uses.leaf.innertype2.base.rev170809.data")) {
final GeneratedType gt = (GeneratedType) type;
- for (final MethodSignature methodSignature : gt.getMethodDefinitions()) {
+ for (MethodSignature methodSignature : gt.getMethodDefinitions()) {
if (methodSignature.getName().equals("getLeafUnion")) {
assertEquals("LeafUnion", methodSignature.getReturnType().getName());
}
if (type.getName().equals("MyCont") && type.getPackageName()
.equals("org.opendaylight.mdsal.gen.javav2.urn.test.uses.leaf.innertype2.rev170809.data")) {
final GeneratedType gt = (GeneratedType) type;
- for (final MethodSignature methodSignature : gt.getMethodDefinitions()) {
+ for (MethodSignature methodSignature : gt.getMethodDefinitions()) {
if (methodSignature.getName().equals("getLeafUnion")) {
assertEquals("LeafUnion", methodSignature.getReturnType().getName());
}
@Test
public void generatedTypesUsesLeafTest() throws Exception {
final BindingGenerator bg = new BindingGeneratorImpl(false);
- final List<File> sources = new ArrayList<>();
- sources.add(new File(getClass().getResource("/uses-statement/test-uses-leaf-innertype2-base.yang").toURI()));
- sources.add(new File(getClass().getResource("/uses-statement/test-uses-leaf-innertype2.yang").toURI()));
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sources);
+ final List<String> sources = new ArrayList<>();
+ sources.add("/uses-statement/test-uses-leaf-innertype2-base.yang");
+ sources.add("/uses-statement/test-uses-leaf-innertype2.yang");
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sources);
final List<Type> generateTypes = bg.generateTypes(context);
assertNotNull(generateTypes);
assertTrue(!generateTypes.isEmpty());
if (type.getName().equals("MyCont") && type.getPackageName()
.equals("org.opendaylight.mdsal.gen.javav2.urn.test.uses.leaf.innertype2.base.rev170809.data")) {
final GeneratedType gt = (GeneratedType) type;
- for (final MethodSignature methodSignature : gt.getMethodDefinitions()) {
+ for (MethodSignature methodSignature : gt.getMethodDefinitions()) {
if (methodSignature.getName().equals("getLeafDecimal64")) {
assertEquals("BigDecimal", methodSignature.getReturnType().getName());
}
if (type.getName().equals("MyCont") && type.getPackageName()
.equals("org.opendaylight.mdsal.gen.javav2.urn.test.uses.leaf.innertype2.rev170809.data")) {
final GeneratedType gt = (GeneratedType) type;
- for (final MethodSignature methodSignature : gt.getMethodDefinitions()) {
+ for (MethodSignature methodSignature : gt.getMethodDefinitions()) {
if (methodSignature.getName().equals("getLeafDecimal64")) {
assertEquals("BigDecimal", methodSignature.getReturnType().getName());
}
@Test
public void generatedTypesUsesLeafInnertype3Test() throws Exception {
final BindingGenerator bg = new BindingGeneratorImpl(false);
- final List<File> sources = new ArrayList<>();
- sources.add(new File(getClass().getResource("/uses-statement/test-uses-leaf-innertype3-base.yang").toURI()));
- sources.add(new File(getClass().getResource("/uses-statement/test-uses-leaf-innertype3.yang").toURI()));
- final SchemaContext context = YangParserTestUtils.parseYangFiles(sources);
+ final List<String> sources = new ArrayList<>();
+ sources.add("/uses-statement/test-uses-leaf-innertype3-base.yang");
+ sources.add("/uses-statement/test-uses-leaf-innertype3.yang");
+ final SchemaContext context = YangParserTestUtils.parseYangSources(sources);
final List<Type> generateTypes = bg.generateTypes(context);
assertNotNull(generateTypes);
assertTrue(!generateTypes.isEmpty());
if (type.getName().equals("MyCont") && type.getPackageName()
.equals("org.opendaylight.mdsal.gen.javav2.urn.test.uses.leaf.innertype3.rev170809.data")) {
final GeneratedType gt = (GeneratedType) type;
- for (final MethodSignature methodSignature : gt.getMethodDefinitions()) {
+ for (MethodSignature methodSignature : gt.getMethodDefinitions()) {
if (methodSignature.getName().equals("getBandwidth")) {
assertEquals("Bandwidth", methodSignature.getReturnType().getName());
}
if (type.getName().equals("Open") && type.getPackageName()
.equals("org.opendaylight.mdsal.gen.javav2.urn.test.uses.leaf.innertype3.rev170809.data")) {
final GeneratedType gt = (GeneratedType) type;
- for (final MethodSignature methodSignature : gt.getMethodDefinitions()) {
+ for (MethodSignature methodSignature : gt.getMethodDefinitions()) {
if (methodSignature.getName().equals("getVersion")) {
assertEquals("ProtocolVersion", methodSignature.getReturnType().getName());
}
@Test
public void generatedTypesTest() throws Exception {
final BindingGenerator bg = new BindingGeneratorImpl(false);
- final SchemaContext context = YangParserTestUtils
- .parseYangFiles(new File(getClass().getResource("/generator/test-list.yang").toURI()));
+ final SchemaContext context = YangParserTestUtils.parseYangSource("/generator/test-list.yang");
final List<Type> generateTypes = bg.generateTypes(context);
assertNotNull(generateTypes);
@Test
public void generateTypesDescriptionsTest() throws Exception {
final BindingGenerator bg = new BindingGeneratorImpl(true);
- final SchemaContext context = YangParserTestUtils.parseYangFiles(getFiles("/base/with_import/"));
+ final SchemaContext context = YangParserTestUtils.parseYangSources("/base/with_import/");
assertNotNull(context);
final List<Type> generateTypes = bg.generateTypes(context, context.getModules());
@Test
public void generateTypesIdentityTest() throws Exception {
final BindingGenerator bg = new BindingGeneratorImpl(true);
- final SchemaContext context = YangParserTestUtils.parseYangFiles(getFiles("/identity/"));
+ final SchemaContext context = YangParserTestUtils.parseYangSources("/identity/");
assertNotNull(context);
final List<Type> generateTypes = bg.generateTypes(context, context.getModules());
}
}
- private File[] getFiles(final String path) throws URISyntaxException {
- return new File(getClass().getResource(path).toURI()).listFiles();
- }
-
private void testActualType(final GeneratedType t, final int[] test_i) {
MethodSignature methodSignature = null;
switch (t.getName()) {
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
-import java.io.File;
-import java.util.List;
import org.junit.Test;
import org.opendaylight.mdsal.binding.javav2.generator.api.BindingGenerator;
import org.opendaylight.mdsal.binding.javav2.model.api.Type;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
+import java.util.List;
public class Bug8542Test {
@Test
public void Bug8542Test() throws Exception {
final BindingGenerator bg = new BindingGeneratorImpl(false);
- final SchemaContext context = YangParserTestUtils
- .parseYangFiles(new File(getClass().getResource("/bug-8542/recursive-uses-augment.yang").toURI()));
+ final SchemaContext context = YangParserTestUtils.parseYangSource("/bug-8542/recursive-uses-augment.yang");
final List<Type> generateTypes = bg.generateTypes(context);
assertNotNull(generateTypes);
assertTrue(!generateTypes.isEmpty());
File foo = new File(getClass().getResource(
"/bug-8575/foo.yang").toURI());
- SchemaContext context = YangParserTestUtils.parseYangFiles(foo);
+ SchemaContext context = YangParserTestUtils.parseYangSources(foo);
final QName groupingQname = QName.create("foo", "2017-05-15", "A");
final QName containerQname = QName.create("foo", "2017-05-15", "A1");
import static org.junit.Assert.assertTrue;
import com.google.common.annotations.Beta;
-import java.io.File;
import java.io.FileNotFoundException;
import java.net.URISyntaxException;
-import java.net.URL;
import java.util.Iterator;
import java.util.Set;
import org.junit.Assert;
@Before
public void setup() throws URISyntaxException, ReactorException, FileNotFoundException {
- File[] listFiles = new File(getClass().getResource("/yang-template").toURI()).listFiles();
- this.modules = YangParserTestUtils.parseYangFiles(listFiles).getModules();
+ this.modules = YangParserTestUtils.parseYangSources("/yang-template").getModules();
}
@Test
@Test
public void generatedFilesTest() throws Exception {
- final File[] listFiles = new File(getClass().getResource("/base/with_import/").toURI()).listFiles();
- final SchemaContext context = YangParserTestUtils.parseYangFiles(listFiles);
+ final SchemaContext context = YangParserTestUtils.parseYangSources("/base/with_import/");
final BindingGenerator bindingGenerator = new BindingGeneratorImpl(true);
final List<Type> types = bindingGenerator.generateTypes(context, context.getModules());
final BuildContext buildContext = new DefaultBuildContext();
@Before
public void setup() throws URISyntaxException, FileNotFoundException, ReactorException {
- schemaContext = YangParserTestUtils.parseYangFiles(
+ schemaContext = YangParserTestUtils.parseYangSources(
new File(getClass().getResource("/yang/test-runtime.yang").toURI()));
myCont = (DataNodeContainer) schemaContext.getChildNodes().iterator().next();
brc = BindingRuntimeContext.create(GeneratedClassLoadingStrategy.getTCCLClassLoadingStrategy(), schemaContext);
@Before
public void setup() throws URISyntaxException, FileNotFoundException, ReactorException {
- schemaContext = YangParserTestUtils.parseYangFiles(
+ schemaContext = YangParserTestUtils.parseYangSources(
new File(getClass().getResource("/yang/test-runtime.yang").toURI()));
myCont = (DataNodeContainer) schemaContext.getChildNodes().iterator().next();
myChoice = (ChoiceSchemaNode) myCont.getChildNodes().iterator().next();
import static org.mockito.Mockito.verifyNoMoreInteractions;
import com.google.common.util.concurrent.Futures;
-import java.net.URISyntaxException;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableContainerNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
static {
try {
schemaContext = TestModel.createTestContext();
- } catch (final URISyntaxException e) {
+ } catch (final ReactorException e) {
LOG.error("Unable to create schema context for TestModel", e);
}
}
import static org.mockito.Mockito.verifyNoMoreInteractions;
import com.google.common.util.concurrent.ListenableFuture;
-import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableLeafNodeBuilder;
import org.opendaylight.yangtools.yang.data.impl.schema.builder.impl.ImmutableMapNodeBuilder;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
static {
try {
schemaContext = TestModel.createTestContext();
- } catch (final URISyntaxException e) {
+ } catch (final ReactorException e) {
LOG.error("Unable to create schema context for TestModel", e);
}
}
final DOMDataTreeListener mockedDataTreeListener = mock(DOMDataTreeListener.class);
doNothing().when(mockedDataTreeListener).onDataTreeChanged(anyCollection(), anyMap());
- final InMemoryDOMDataTreeShard testShard = InMemoryDOMDataTreeShard.create(TEST_ID, executor, 1);
+ InMemoryDOMDataTreeShard testShard = InMemoryDOMDataTreeShard.create(TEST_ID, executor, 1);
testShard.onGlobalContextUpdated(schemaContext);
final DOMDataTreeProducer regProducer = dataTreeService.createProducer(Collections.singleton(TEST_ID));
tx.createCursor(new DOMDataTreeIdentifier(LogicalDatastoreType.CONFIGURATION, oid1));
assertNotNull(cursor);
- final MapNode innerList = ImmutableMapNodeBuilder
+ MapNode innerList = ImmutableMapNodeBuilder
.create()
.withNodeIdentifier(new NodeIdentifier(TestModel.INNER_LIST_QNAME))
.build();
*/
package org.opendaylight.mdsal.dom.broker.util;
-import java.io.File;
-import java.net.URISyntaxException;
+import java.io.InputStream;
import java.util.Collections;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class TestModel {
YangInstanceIdentifier.builder(ANOTHER_SHARD_PATH).node(NEW_SHARD_LIST).build();
private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
- public static SchemaContext createTestContext() throws URISyntaxException {
- return YangParserTestUtils.parseYangFiles(Collections.singletonList(getFile()));
+ public static SchemaContext createTestContext() throws ReactorException {
+ return YangParserTestUtils.parseYangStreams(Collections.singletonList(getInputStream()));
}
- private static File getFile() throws URISyntaxException {
- return new File(TestModel.class.getResource(DATASTORE_TEST_YANG).toURI());
+ private static InputStream getInputStream() {
+ return TestModel.class.getResourceAsStream(DATASTORE_TEST_YANG);
}
}
import com.google.common.base.Optional;
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.MoreExecutors;
+import java.io.IOException;
import java.util.concurrent.ExecutionException;
import org.junit.Before;
import org.junit.Ignore;
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.model.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
public class InMemoryDataStoreTest {
private InMemoryDOMDataStore domStore;
@Before
- public void setupStore() throws Exception {
+ public void setupStore() throws IOException, YangSyntaxErrorException, ReactorException {
domStore = new InMemoryDOMDataStore("TEST", MoreExecutors.newDirectExecutorService());
schemaContext = TestModel.createTestContext();
domStore.onGlobalContextUpdated(schemaContext);
assertNotNull(domStore);
- final DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
+ DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
assertNotNull(readTx);
- final DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
+ DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
assertNotNull(writeTx);
/**
* Writes /test in writeTx.
*/
- final NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+ NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
writeTx.write(TestModel.TEST_PATH, testNode);
/**
* Reads /test from writeTx Read should return container.
*/
- final ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(TestModel.TEST_PATH);
+ ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(TestModel.TEST_PATH);
assertEquals("read: isPresent", true, writeTxContainer.get().isPresent());
assertEquals("read: data", testNode, writeTxContainer.get().get());
/**
* Reads /test from readTx Read should return Absent.
*/
- final ListenableFuture<Optional<NormalizedNode<?, ?>>> readTxContainer = readTx.read(TestModel.TEST_PATH);
+ ListenableFuture<Optional<NormalizedNode<?, ?>>> readTxContainer = readTx.read(TestModel.TEST_PATH);
assertEquals("read: isPresent", false, readTxContainer.get().isPresent());
}
@Test
public void testTransactionCommit() throws InterruptedException, ExecutionException {
- final DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
+ DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
assertNotNull(writeTx);
/**
* Writes /test in writeTx.
*/
- final NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
+ NormalizedNode<?, ?> testNode = ImmutableNodes.containerNode(TestModel.TEST_QNAME);
writeTx.write(TestModel.TEST_PATH, testNode);
/**
* Reads /test from writeTx Read should return container.
*/
- final ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(TestModel.TEST_PATH);
+ ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = writeTx.read(TestModel.TEST_PATH);
assertEquals("read: isPresent", true, writeTxContainer.get().isPresent());
assertEquals("read: data", testNode, writeTxContainer.get().get());
- final DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
+ DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
assertThreePhaseCommit(cohort);
- final Optional<NormalizedNode<?, ?>> afterCommitRead =
- domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
+ Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH)
+ .get();
assertEquals("After commit read: isPresent", true, afterCommitRead.isPresent());
assertEquals("After commit read: data", testNode, afterCommitRead.get());
}
@Test
public void testExistsForExistingData() throws Exception {
- final DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
+ DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
assertNotNull(writeTx);
- final ContainerNode containerNode = ImmutableContainerNodeBuilder.create()
+ ContainerNode containerNode = ImmutableContainerNodeBuilder.create()
.withNodeIdentifier(new NodeIdentifier(TestModel.TEST_QNAME))
.addChild(ImmutableNodes.mapNodeBuilder(TestModel.OUTER_LIST_QNAME)
.addChild(ImmutableNodes.mapEntry(TestModel.OUTER_LIST_QNAME,
assertEquals(Boolean.TRUE, exists.get());
- final DOMStoreThreePhaseCommitCohort ready = writeTx.ready();
+ DOMStoreThreePhaseCommitCohort ready = writeTx.ready();
ready.preCommit().get();
ready.commit().get();
- final DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
+ DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
assertNotNull(readTx);
exists =
@Test
public void testExistsForNonExistingData() throws Exception {
- final DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
+ DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
assertNotNull(writeTx);
ListenableFuture<Boolean> exists = writeTx.exists(TestModel.TEST_PATH);
assertEquals(Boolean.FALSE, exists.get());
- final DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
+ DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
assertNotNull(readTx);
exists =
@Test(expected = ReadFailedException.class)
public void testExistsThrowsReadFailedException() throws Exception {
- final DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
+ DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
assertNotNull(readTx);
readTx.close();
@Test(expected = ReadFailedException.class)
public void testReadWithReadOnlyTransactionClosed() throws Throwable {
- final DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
+ DOMStoreReadTransaction readTx = domStore.newReadOnlyTransaction();
assertNotNull(readTx);
readTx.close();
@Test(expected = ReadFailedException.class)
public void testReadWithReadOnlyTransactionFailure() throws Throwable {
- final DataTreeSnapshot mockSnapshot = Mockito.mock(DataTreeSnapshot.class);
+ DataTreeSnapshot mockSnapshot = Mockito.mock(DataTreeSnapshot.class);
Mockito.doThrow(new RuntimeException("mock ex")).when(mockSnapshot)
.readNode(Mockito.any(YangInstanceIdentifier.class));
- final DOMStoreReadTransaction readTx = SnapshotBackedTransactions.newReadTransaction("1", true, mockSnapshot);
+ DOMStoreReadTransaction readTx = SnapshotBackedTransactions.newReadTransaction("1", true, mockSnapshot);
doReadAndThrowEx(readTx);
}
@Test(expected = ReadFailedException.class)
public void testReadWithReadWriteTransactionClosed() throws Throwable {
- final DOMStoreReadTransaction readTx = domStore.newReadWriteTransaction();
+ DOMStoreReadTransaction readTx = domStore.newReadWriteTransaction();
assertNotNull(readTx);
readTx.close();
@Test(expected = ReadFailedException.class)
public void testReadWithReadWriteTransactionFailure() throws Throwable {
- final DataTreeSnapshot mockSnapshot = Mockito.mock(DataTreeSnapshot.class);
- final DataTreeModification mockModification = Mockito.mock(DataTreeModification.class);
+ DataTreeSnapshot mockSnapshot = Mockito.mock(DataTreeSnapshot.class);
+ DataTreeModification mockModification = Mockito.mock(DataTreeModification.class);
Mockito.doThrow(new RuntimeException("mock ex")).when(mockModification)
.readNode(Mockito.any(YangInstanceIdentifier.class));
Mockito.doReturn(mockModification).when(mockSnapshot).newModification();
@SuppressWarnings("unchecked")
- final TransactionReadyPrototype<String> mockReady = Mockito.mock(TransactionReadyPrototype.class);
- final DOMStoreReadTransaction readTx =
- SnapshotBackedTransactions.newReadWriteTransaction("1", false, mockSnapshot, mockReady);
+ TransactionReadyPrototype<String> mockReady = Mockito.mock(TransactionReadyPrototype.class);
+ DOMStoreReadTransaction readTx = SnapshotBackedTransactions.newReadWriteTransaction(
+ "1", false, mockSnapshot, mockReady);
doReadAndThrowEx(readTx);
}
private static void doReadAndThrowEx(final DOMStoreReadTransaction readTx) throws Throwable {
try {
readTx.read(TestModel.TEST_PATH).get();
- } catch (final ExecutionException e) {
+ } catch (ExecutionException e) {
throw e.getCause();
}
}
@Test(expected = IllegalStateException.class)
public void testWriteWithTransactionReady() throws Exception {
- final DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
+ DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
writeTx.ready();
@Test(expected = IllegalStateException.class)
public void testReadyWithTransactionAlreadyReady() throws Exception {
- final DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
+ DOMStoreWriteTransaction writeTx = domStore.newWriteOnlyTransaction();
writeTx.ready();
@Test
public void testTransactionAbort() throws InterruptedException, ExecutionException {
- final DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
+ DOMStoreReadWriteTransaction writeTx = domStore.newReadWriteTransaction();
assertNotNull(writeTx);
assertTestContainerWrite(writeTx);
- final DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
+ DOMStoreThreePhaseCommitCohort cohort = writeTx.ready();
assertTrue(cohort.canCommit().get().booleanValue());
cohort.preCommit().get();
cohort.abort().get();
- final Optional<NormalizedNode<?, ?>> afterCommitRead =
- domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH).get();
+ Optional<NormalizedNode<?, ?>> afterCommitRead = domStore.newReadOnlyTransaction().read(TestModel.TEST_PATH)
+ .get();
assertFalse(afterCommitRead.isPresent());
}
@Test
public void testTransactionChain() throws InterruptedException, ExecutionException {
- final DOMStoreTransactionChain txChain = domStore.createTransactionChain();
+ DOMStoreTransactionChain txChain = domStore.createTransactionChain();
assertNotNull(txChain);
/**
* We alocate new read-write transaction and write /test.
*/
- final DOMStoreReadWriteTransaction firstTx = txChain.newReadWriteTransaction();
+ DOMStoreReadWriteTransaction firstTx = txChain.newReadWriteTransaction();
assertTestContainerWrite(firstTx);
/**
* We alocate chained transaction - read transaction, note first one is
* still not commited to datastore.
*/
- final DOMStoreReadTransaction secondReadTx = txChain.newReadOnlyTransaction();
+ DOMStoreReadTransaction secondReadTx = txChain.newReadOnlyTransaction();
/**
* We test if we are able to read data from tx, read should not fail
* We alocate next transaction, which is still based on first one, but
* is read-write.
*/
- final DOMStoreReadWriteTransaction thirdDeleteTx = txChain.newReadWriteTransaction();
+ DOMStoreReadWriteTransaction thirdDeleteTx = txChain.newReadWriteTransaction();
/**
* We test existence of /test in third transaction container should
/**
* third transaction is sealed.
*/
- final DOMStoreThreePhaseCommitCohort thirdDeleteTxCohort = thirdDeleteTx.ready();
+ DOMStoreThreePhaseCommitCohort thirdDeleteTxCohort = thirdDeleteTx.ready();
/**
* We commit first transaction.
assertThreePhaseCommit(firstWriteTxCohort);
// Alocates store transacion
- final DOMStoreReadTransaction storeReadTx = domStore.newReadOnlyTransaction();
+ DOMStoreReadTransaction storeReadTx = domStore.newReadOnlyTransaction();
/**
* We verify transaction is commited to store, container should exists
* in datastore.
@Test
@Ignore
public void testTransactionConflict() throws InterruptedException, ExecutionException {
- final DOMStoreReadWriteTransaction txOne = domStore.newReadWriteTransaction();
- final DOMStoreReadWriteTransaction txTwo = domStore.newReadWriteTransaction();
+ DOMStoreReadWriteTransaction txOne = domStore.newReadWriteTransaction();
+ DOMStoreReadWriteTransaction txTwo = domStore.newReadWriteTransaction();
assertTestContainerWrite(txOne);
assertTestContainerWrite(txTwo);
private static Optional<NormalizedNode<?, ?>> assertTestContainerExists(final DOMStoreReadTransaction readTx)
throws InterruptedException, ExecutionException {
- final ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = readTx.read(TestModel.TEST_PATH);
+ ListenableFuture<Optional<NormalizedNode<?, ?>>> writeTxContainer = readTx.read(TestModel.TEST_PATH);
assertTrue(writeTxContainer.get().isPresent());
return writeTxContainer.get();
}
*/
package org.opendaylight.controller.md.sal.dom.store.impl;
-import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
import java.util.Collections;
import org.opendaylight.yangtools.yang.common.QName;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException;
+import org.opendaylight.yangtools.yang.parser.spi.meta.ReactorException;
import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
public class TestModel {
YangInstanceIdentifier.builder(TEST_PATH).node(OUTER_LIST_QNAME).build();
private static final String DATASTORE_TEST_YANG = "/odl-datastore-test.yang";
- public static SchemaContext createTestContext() throws Exception {
- return YangParserTestUtils.parseYangFiles(Collections.singletonList(getFile()));
+ public static SchemaContext createTestContext() throws IOException, YangSyntaxErrorException, ReactorException {
+ return YangParserTestUtils.parseYangStreams(Collections.singletonList(getInputStream()));
}
- private static File getFile() throws Exception {
- return new File(TestModel.class.getResource(DATASTORE_TEST_YANG).toURI());
+ private static InputStream getInputStream() {
+ return TestModel.class.getResourceAsStream(DATASTORE_TEST_YANG);
}
}