2 * Copyright (c) 2015 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.model.export;
11 import java.io.FileOutputStream;
12 import java.util.HashSet;
14 import org.junit.jupiter.api.BeforeEach;
15 import org.junit.jupiter.api.Test;
16 import org.opendaylight.yangtools.yang.model.api.Module;
17 import org.opendaylight.yangtools.yang.model.api.source.SourceIdentifier;
18 import org.opendaylight.yangtools.yang.model.api.source.SourceRepresentation;
19 import org.opendaylight.yangtools.yang.model.repo.api.EffectiveModelContextFactory;
20 import org.opendaylight.yangtools.yang.model.repo.spi.PotentialSchemaSource;
21 import org.opendaylight.yangtools.yang.model.repo.spi.SchemaSourceListener;
22 import org.opendaylight.yangtools.yang.parser.repo.SharedSchemaRepository;
23 import org.opendaylight.yangtools.yang.parser.rfc7950.repo.TextToIRTransformer;
25 public class SimpleModuleTest {
26 private SharedSchemaRepository schemaRegistry;
27 private EffectiveModelContextFactory schemaContextFactory;
28 private Set<SourceIdentifier> allTestSources;
32 schemaRegistry = new SharedSchemaRepository("test");
33 final TextToIRTransformer astTransformer = TextToIRTransformer.create(schemaRegistry, schemaRegistry);
34 schemaRegistry.registerSchemaSourceListener(astTransformer);
36 schemaContextFactory = schemaRegistry.createEffectiveModelContextFactory();
37 allTestSources = new HashSet<>();
38 try (var reg = schemaRegistry.registerSchemaSourceListener(
39 new SchemaSourceListener() {
41 public void schemaSourceUnregistered(final PotentialSchemaSource<?> source) {
46 public void schemaSourceRegistered(final Iterable<PotentialSchemaSource<?>> sources) {
47 for (final PotentialSchemaSource<?> source : sources) {
48 allTestSources.add(source.getSourceIdentifier());
53 public void schemaSourceEncountered(final SourceRepresentation source) {
62 public void testGenerateAll() throws Exception {
63 testSetOfModules(allTestSources);
66 private void testSetOfModules(final Set<SourceIdentifier> source) throws Exception {
67 final var schemaContext = schemaContextFactory.createEffectiveModelContext(source).get();
68 final var outDir = new File("target/collection");
70 for (final Module module : schemaContext.getModules()) {
71 exportModule(module, outDir);
75 private static File exportModule(final Module module, final File outDir)
77 final var outFile = new File(outDir, YinExportUtils.wellFormedYinName(module.getName(), module.getRevision()));
78 try (var output = new FileOutputStream(outFile)) {
79 YinExportUtils.writeModuleAsYinText(module.asEffectiveStatement(), output);