bug 496471: [designer][java][reverse] Java Reverse shall have JUnit
tests

- add base classes for testing. Tests fail because reversed elements are
created in predefined package, and searchPaths are not set accordingly.

https://bugs.eclipse.org/bugs/show_bug.cgi?id=496471
diff --git a/languages/java/org.eclipse.papyrus.designer.languages.java.reverse/test/org/eclipse/papyrus/designer/languages/java/reverse/tests/AbstractJavaReverseTest.java b/languages/java/org.eclipse.papyrus.designer.languages.java.reverse/test/org/eclipse/papyrus/designer/languages/java/reverse/tests/AbstractJavaReverseTest.java
new file mode 100644
index 0000000..f21167f
--- /dev/null
+++ b/languages/java/org.eclipse.papyrus.designer.languages.java.reverse/test/org/eclipse/papyrus/designer/languages/java/reverse/tests/AbstractJavaReverseTest.java
@@ -0,0 +1,32 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ * 
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   CEA LIST - Initial API and implementation
+ *   
+ *****************************************************************************/
+
+package org.eclipse.papyrus.designer.languages.java.reverse.tests;
+
+import org.eclipse.papyrus.designer.languages.java.reverse.javaparser.AbstractTest;
+
+/**
+ * @author dumoulin
+ *
+ */
+public class AbstractJavaReverseTest extends AbstractTest {
+
+	/**
+	 * Constructor.
+	 *
+	 */
+	public AbstractJavaReverseTest() {
+		// TODO Auto-generated constructor stub
+	}
+
+}
diff --git a/languages/java/org.eclipse.papyrus.designer.languages.java.reverse/test/org/eclipse/papyrus/designer/languages/java/reverse/tests/SimpleClassTest.java b/languages/java/org.eclipse.papyrus.designer.languages.java.reverse/test/org/eclipse/papyrus/designer/languages/java/reverse/tests/SimpleClassTest.java
new file mode 100644
index 0000000..1189131
--- /dev/null
+++ b/languages/java/org.eclipse.papyrus.designer.languages.java.reverse/test/org/eclipse/papyrus/designer/languages/java/reverse/tests/SimpleClassTest.java
@@ -0,0 +1,139 @@
+/*****************************************************************************
+ * Copyright (c) 2016 CEA LIST and others.
+ * 
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ *   CEA LIST - Initial API and implementation
+ *   
+ *****************************************************************************/
+
+package org.eclipse.papyrus.designer.languages.java.reverse.tests;
+
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Scanner;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.papyrus.designer.languages.java.reverse.jdt.JdtCompilationUnitAnalyzer;
+import org.eclipse.papyrus.designer.languages.java.reverse.umlparser.ClassifierCatalog;
+import org.eclipse.papyrus.designer.languages.java.reverse.umlparser.CompilationUnitAnalyser;
+import org.eclipse.uml2.uml.Class;
+import org.eclipse.uml2.uml.Operation;
+import org.eclipse.uml2.uml.Package;
+import org.eclipse.uml2.uml.Property;
+import org.eclipse.uml2.uml.UMLFactory;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * @author cedric dumoulin
+ *
+ */
+public class SimpleClassTest extends AbstractJavaReverseTest {
+
+	/**
+	 * @throws java.lang.Exception
+	 */
+	@BeforeClass
+	public static void setUpBeforeClass() throws Exception {
+	}
+
+	/**
+	 * @throws java.lang.Exception
+	 */
+	@AfterClass
+	public static void tearDownAfterClass() throws Exception {
+	}
+
+	/**
+	 * @throws java.lang.Exception
+	 */
+	@Before
+	public void setUp() throws Exception {
+	}
+
+	/**
+	 * @throws java.lang.Exception
+	 */
+	@After
+	public void tearDown() throws Exception {
+	}
+
+	@Test
+	public void test() throws IOException {
+		String[] filenames = {SimpleClass_class};
+		Package p = createRootPackage("name");
+		
+		ClassifierCatalog catalog = reverseJavaFile(p, filenames);
+		
+		// Test class reversed
+		Class c = (Class)catalog.getClassifier("org.eclipse.papyrus.designer.languages.java.reverse.classesundertest.SimpleClass");
+		assertNotNull("classifier created", c);
+		
+		// Test property created
+		Property property = c.getAttribute("x", null);
+		assertNotNull("Property 'x' created", property);
+		
+		Operation operation = c.getOwnedOperation("getX", null, null);
+		assertNotNull("Operation 'getX' created", operation);
+	}
+
+	/**
+	 * @param string
+	 * @return
+	 */
+	protected Package createRootPackage(String name) {
+		// TODO Auto-generated method stub
+		Package p = UMLFactory.eINSTANCE.createPackage();
+		p.setName(name);
+		
+		return p;
+	}
+
+	/**
+	 * @param p
+	 * @param filenames
+	 * @return
+	 * @throws IOException 
+	 */
+	protected ClassifierCatalog reverseJavaFile(Package rootPackage, String[] filenames) throws IOException {
+		// Create analyzer
+		String generatePackageName = "model";
+		List<String> searchPaths = new ArrayList<String>();
+		
+		JdtCompilationUnitAnalyzer analyser = new JdtCompilationUnitAnalyzer(rootPackage, generatePackageName, searchPaths);
+		
+		// reverse files
+		for( String filename : filenames ) {
+			InputStream inputStream = getJavaFileInputStream(filename);
+			Scanner scanner = new Scanner(inputStream,"UTF-8");
+			String str = scanner.useDelimiter("\\A").next();
+			scanner.close();
+
+			ASTParser parser = ASTParser.newParser(AST.JLS8);
+			parser.setSource(str.toCharArray());
+			parser.setKind(ASTParser.K_COMPILATION_UNIT);
+
+			final CompilationUnit cu = (CompilationUnit) parser.createAST(null);
+
+			analyser.processCompilationUnit(cu);
+		}
+		
+		
+		return analyser.getClassifierCatalog();
+	}
+
+}