2 * Copyright (c) 2016 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.mdsal.binding.java.api.generator.test;
10 import static org.junit.Assert.assertTrue;
12 import com.google.common.collect.ImmutableSet;
14 import java.io.IOException;
15 import java.net.URISyntaxException;
16 import java.util.Collections;
17 import java.util.List;
18 import org.junit.Before;
19 import org.junit.BeforeClass;
20 import org.opendaylight.mdsal.binding.generator.api.BindingGenerator;
21 import org.opendaylight.mdsal.binding.generator.impl.BindingGeneratorImpl;
22 import org.opendaylight.mdsal.binding.java.api.generator.GeneratorJavaFile;
23 import org.opendaylight.mdsal.binding.model.api.Type;
24 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
25 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
27 public abstract class BaseCompilationTest {
29 protected BindingGenerator bindingGenerator;
32 public static void createTestDirs() {
33 if (CompilationTestUtils.TEST_DIR.exists()) {
34 CompilationTestUtils.deleteTestDir(CompilationTestUtils.TEST_DIR);
36 assertTrue(CompilationTestUtils.GENERATOR_OUTPUT_DIR.mkdirs());
37 assertTrue(CompilationTestUtils.COMPILER_OUTPUT_DIR.mkdirs());
42 bindingGenerator = new BindingGeneratorImpl();
45 protected final void generateTestSources(final String resourceDirPath, final File sourcesOutputDir)
46 throws IOException, URISyntaxException {
47 final List<File> sourceFiles = CompilationTestUtils.getSourceFiles(resourceDirPath);
48 final SchemaContext context = YangParserTestUtils.parseYangFiles(sourceFiles);
49 final List<Type> types = bindingGenerator.generateTypes(context);
50 Collections.sort(types, (o1, o2) -> o2.getName().compareTo(o1.getName()));
51 final GeneratorJavaFile generator = new GeneratorJavaFile(ImmutableSet.copyOf(types));
52 generator.generateToFile(sourcesOutputDir);