use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.
the class ExaminerEJBTest method testFindAndSetAttributesSetEJB.
@Test
public void testFindAndSetAttributesSetEJB() {
JavaSource javaSource;
String sourceCode;
javaSource = JavaSourceFactory.getInstance().newJavaSource("MyTestClass");
sourceCode = "public abstract class MyTestClass<K, E extends SingleIdEntity<K>> implements CrudAccessor<K, E>, Serializable {\n" + "protected EntityManager entityManager;\n" + "private Class<E> entityClass;\n" + "@EJB\n" + "protected void setEntityManager(EntityManager entityManager) {\n" + " this.entityManager = entityManager;\n" + "}\n";
javaSource.setSourceCode(sourceCode);
examiner.examine(javaSource);
assertEquals(1, DependencyContainer.getInstance().getDependencies(javaSource).size());
Dependency dependency;
dependency = DependencyContainer.getInstance().getDependencies(javaSource).get(0);
assertEquals(DependencyType.EJB, dependency.getDependencyType());
assertEquals("MyTestClass", dependency.getJavaSourceFrom().getName());
assertEquals("EntityManager", dependency.getJavaSourceTo().getName());
}
use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.
the class ExaminerInjectTest method testFindAndSetAttributesInjectIgnoreQuotes.
@Test
// Deactivated exotic test and implemention
@Ignore
public void testFindAndSetAttributesInjectIgnoreQuotes() {
JavaSource javaSource;
String sourceCode;
javaSource = JavaSourceFactory.getInstance().newJavaSource("TestCDIServlet");
sourceCode = "public class TestCDIServlet extends HttpServlet {\n" + "@Inject UserTransaction ut;\n" + "protected void processRequest(HttpServletRequest request, HttpServletResponse response)\n" + "response.setContentType(\"text/html;charset=UTF-8\");\n" + "try (PrintWriter out = response.getWriter()) {\n" + "out.println(\"<title>UserTransaction obtained using @Inject</title>\");\n" + "out.println(\"<h1>UserTransaction obtained using @Inject</h1>\");\n" + "try {\n" + "} catch (NotSupportedException \n" + "| IllegalStateException ex) {\n" + "ex.printStackTrace(out);\n" + "}\n" + "}\n" + "}\n" + "}\n";
javaSource.setSourceCode(sourceCode);
examiner.examine(javaSource);
assertEquals(1, DependencyContainer.getInstance().getDependencies(javaSource).size());
Dependency dependency;
dependency = DependencyContainer.getInstance().getDependencies(javaSource).get(0);
assertEquals(DependencyType.INJECT, dependency.getDependencyType());
assertEquals("TestCDIServlet", dependency.getJavaSourceFrom().getName());
assertEquals("UserTransaction", dependency.getJavaSourceTo().getName());
// 1, ensure @Inject</title> and @Inject</h1> in the source are ignored
assertEquals(1, DependencyContainer.getInstance().getDependencies(javaSource).size());
}
use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.
the class ExaminerInjectTest method testFindAndSetAttributesInjectSetterWithAnnotations.
@Test
public void testFindAndSetAttributesInjectSetterWithAnnotations() {
JavaSource javaSource;
String sourceCode;
javaSource = JavaSourceFactory.getInstance().newJavaSource("ZeiterfassungEingabeModel");
sourceCode = "public class ZeiterfassungEingabeModel implements Serializable\n" + "{\n" + "@Inject\n" + "protected void setBuchungsMonat(@Current @Zeiterfassung Date buchungsMonat)\n" + "{\n";
javaSource.setSourceCode(sourceCode);
examiner.examine(javaSource);
assertEquals(1, DependencyContainer.getInstance().getDependencies(javaSource).size());
Dependency dependency;
dependency = DependencyContainer.getInstance().getDependencies(javaSource).get(0);
assertEquals(DependencyType.INJECT, dependency.getDependencyType());
assertEquals("ZeiterfassungEingabeModel", dependency.getJavaSourceFrom().getName());
assertEquals("Date", dependency.getJavaSourceTo().getName());
}
use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.
the class DependencyContainer method getFilteredJavaSources.
// TODO simplify
public Set<JavaSource> getFilteredJavaSources(DependencyFilter filter) {
Set<JavaSource> filteredJavaSources = new HashSet<>();
if (filter != null && filter.isDirectlyConnected()) {
DependencyType primaryType = filter.getFilterTypes().get(0);
for (Dependency d : getDependenciesOfType(primaryType)) {
JavaSource to = d.getJavaSourceTo();
List<Dependency> injects = new ArrayList<>();
for (DependencyType dFilter : filter.getFilterTypes()) {
if (!dFilter.equals(primaryType)) {
injects.addAll(findAllDependenciesWith(to, dFilter));
}
}
if (injects.size() > 0) {
filteredJavaSources.add(d.getJavaSourceFrom());
filteredJavaSources.add(to);
for (Dependency inject : injects) {
filteredJavaSources.add(inject.getJavaSourceFrom());
}
}
}
} else {
for (Dependency dependency : DEPENDENCIES) {
if (filter == null || filter.contains(dependency.getDependencyType())) {
filteredJavaSources.add(dependency.getJavaSourceFrom());
filteredJavaSources.add(dependency.getJavaSourceTo());
}
}
}
return filteredJavaSources;
}
use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.
the class Examiner method createDependency.
// ### TODO simplifizieren, Möglichkeit schaffen, dass neue JavaSourcen über eine Factory gebaut werden
// und dann kann man da den isOK an einer Stelle einbauen. Also new JavaSource suchen und diese in die Factory
// JavaSourceFactory.getForName(String className) oder so und die liefert null wenn gefiltert
// Schaffen das JAvaSOurce nicht direkt instanziiert werden kann siehe
// http://stackoverflow.com/questions/1326230/avoid-instantiating-a-class-in-java
protected void createDependency(String classNameIn, DependencyType type, JavaSource javaSource) {
// Need to convert primitives-names to wrapper-classnames (e.g. @Produces Integer xyz => @Inject int xyz
String className = cleanPrimitives(classNameIn);
JavaSource injectedJavaSource = JavaSourceContainer.getInstance().getJavaSourceByName(className);
if (injectedJavaSource == null) {
// Generate a new JavaSource, which is not explicit in the sources (e.g. Integer, String etc.)
// ### TODO injectedJavaSource = new JavaSource(className);
injectedJavaSource = JavaSourceFactory.getInstance().newJavaSource(className);
// ### TODO auch sollen keine Dummies mehr angelegt werden da soll der Filter auch greifen
if (injectedJavaSource != null) {
JavaSourceContainer.getInstance().add(injectedJavaSource);
if (isAValidClassName(className)) {
LogProvider.getInstance().debug("Created new JavaSource with name: " + className);
} else {
LogProvider.getInstance().debug("Created new JavaSource (type=" + type.name() + ") with a suspicious name: " + className + " - Found in " + javaSource.getFullClassName());
}
} else {
LogProvider.getInstance().debug("Didn't created new JavaSource, because of filter, with name: " + className);
}
}
// ### TODO Dependency nur anlegen, wenn JavaSource nicht gefiltert
if (injectedJavaSource != null) {
Dependency dependency = new Dependency(type, javaSource, injectedJavaSource);
DependencyContainer.getInstance().add(dependency);
}
}
Aggregations