Search in sources :

Example 26 with JavaSource

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());
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) Test(org.junit.Test)

Example 27 with JavaSource

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());
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 28 with JavaSource

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());
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) Test(org.junit.Test)

Example 29 with JavaSource

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;
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) DependencyType(de.strullerbaumann.visualee.dependency.entity.DependencyType) ArrayList(java.util.ArrayList) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) HashSet(java.util.HashSet)

Example 30 with JavaSource

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);
    }
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency)

Aggregations

JavaSource (de.strullerbaumann.visualee.source.entity.JavaSource)50 Test (org.junit.Test)44 Dependency (de.strullerbaumann.visualee.dependency.entity.Dependency)31 Scanner (java.util.Scanner)5 DependencyType (de.strullerbaumann.visualee.dependency.entity.DependencyType)3 ArrayList (java.util.ArrayList)3 JsonArrayBuilder (javax.json.JsonArrayBuilder)2 JsonObjectBuilder (javax.json.JsonObjectBuilder)2 ExaminerInject (de.strullerbaumann.visualee.examiner.cdi.ExaminerInject)1 ExaminerProduces (de.strullerbaumann.visualee.examiner.cdi.ExaminerProduces)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 JsonArray (javax.json.JsonArray)1 JsonObject (javax.json.JsonObject)1 Ignore (org.junit.Ignore)1