2 * Copyright (c) 2017 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.javav2.java.api.generator;
10 import java.io.BufferedReader;
12 import java.io.FileReader;
13 import java.io.IOException;
14 import java.util.ArrayList;
15 import java.util.List;
16 import org.junit.Assert;
17 import org.junit.Test;
18 import org.opendaylight.mdsal.binding.javav2.generator.api.BindingGenerator;
19 import org.opendaylight.mdsal.binding.javav2.generator.impl.BindingGeneratorImpl;
20 import org.opendaylight.mdsal.binding.javav2.model.api.Type;
21 import org.opendaylight.yangtools.yang.model.api.SchemaContext;
22 import org.opendaylight.yangtools.yang.test.util.YangParserTestUtils;
23 import org.sonatype.plexus.build.incremental.BuildContext;
24 import org.sonatype.plexus.build.incremental.DefaultBuildContext;
26 public class GeneratorJavaFileTest {
29 public void generatedFilesTest() throws Exception {
30 final SchemaContext context = YangParserTestUtils.parseYangResourceDirectory("/base/with_import/");
31 final BindingGenerator bindingGenerator = new BindingGeneratorImpl(true);
32 final List<Type> types = bindingGenerator.generateTypes(context, context.getModules());
33 final BuildContext buildContext = new DefaultBuildContext();
34 final GeneratorJavaFile gjf = new GeneratorJavaFile(buildContext, types);
35 final File persistentSourcesDirectory =
36 new File(GeneratorJavaFileTest.class.getResource("/base").getPath());
37 final File generatedSourcesDirectory =
38 new File(GeneratorJavaFileTest.class.getResource("/base").getPath());
39 final List<File> generateToFile = gjf.generateToFile(generatedSourcesDirectory, persistentSourcesDirectory);
40 for (final File f : generateToFile) {
41 Assert.assertNotNull(f);
43 final List<String> files = new ArrayList<>();
44 final RuntimeException runtimeException = new RuntimeException();
45 for (final File file : generateToFile) {
46 BufferedReader br = null;
49 fr = new FileReader(file.getAbsolutePath());
50 br = new BufferedReader(fr);
51 final StringBuilder sb = new StringBuilder();
53 while ((currentLine = br.readLine()) != null) {
54 sb.append(currentLine).append('\n');
56 files.add(sb.toString());
57 } catch (final IOException e) {
58 throw new RuntimeException(e);
67 } catch (final IOException ex) {
68 runtimeException.addSuppressed(ex);
73 for (final String s : files) {
74 Assert.assertNotNull(s);
75 Assert.assertTrue(!s.isEmpty());
78 for (final File file2 : generateToFile) {