Search in sources :

Example 11 with Dependency

use of de.strullerbaumann.visualee.dependency.entity.Dependency in project visualee by Thomas-S-B.

the class JPAExaminerTest method testFindAndSetAttributesManyToOne.

@Test
public void testFindAndSetAttributesManyToOne() {
    ExaminerJPA jpaExaminer = new ExaminerJPA();
    JavaSource javaSource;
    Dependency dependency;
    String sourceCode;
    // Many to one
    javaSource = JavaSourceFactory.getInstance().newJavaSource("MyTestClass");
    sourceCode = TestDataProvider.getTestSourceCodeBeforeBody() + "@ManyToOne(cascade = { CascadeType.DETACH })\n" + "@JoinColumn(name = \"ALBUMID\", nullable = false)\n" + "@NotNull(groups = PersistenceConstraint.class)\n" + "private Album album;\n";
    javaSource.setSourceCode(sourceCode);
    jpaExaminer.examine(javaSource);
    dependency = DependencyContainer.getInstance().getDependencies(javaSource).get(0);
    assertEquals(1, DependencyContainer.getInstance().getDependencies(javaSource).size());
    assertEquals(DependencyType.MANY_TO_ONE, dependency.getDependencyType());
    assertEquals("MyTestClass", dependency.getJavaSourceFrom().getName());
    assertEquals("Album", dependency.getJavaSourceTo().getName());
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) Test(org.junit.Test)

Example 12 with Dependency

use of de.strullerbaumann.visualee.dependency.entity.Dependency in project visualee by Thomas-S-B.

the class Description method generateDescription.

public static String generateDescription(JavaSource javaSource) {
    StringBuilder description = new StringBuilder();
    description.append("<nobr>Package: ").append(javaSource.getPackagePath()).append("</nobr>");
    HashMap<DependencyType, StringBuilder> descriptionParts = new HashMap<>();
    for (DependencyType type : DependencyType.values()) {
        descriptionParts.put(type, new StringBuilder());
    }
    for (Dependency dependency : DependencyContainer.getInstance().getDependencies(javaSource)) {
        StringBuilder descriptionPart = descriptionParts.get(dependency.getDependencyType());
        assert descriptionPart != null : "Unknown DependencyType";
        descriptionPart.append("<br/><nobr>");
        String desc = DESCRIPTIONS.get(dependency.getDependencyType());
        desc = desc.replaceAll(JAVASOURCE_TO, dependency.getJavaSourceTo().toString());
        descriptionPart.append(desc);
        descriptionPart.append("</nobr>");
    }
    for (DependencyType type : descriptionParts.keySet()) {
        description.append(getDescriptionPart(type, descriptionParts.get(type).toString()));
    }
    return description.toString();
}
Also used : HashMap(java.util.HashMap) DependencyType(de.strullerbaumann.visualee.dependency.entity.DependencyType) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency)

Example 13 with Dependency

use of de.strullerbaumann.visualee.dependency.entity.Dependency in project visualee by Thomas-S-B.

the class DependencyContainerTest method testFindAllDependenciesWith.

@Test
public void testFindAllDependenciesWith() {
    TestDataProvider.createSampleDependencies();
    JavaSource producer = JavaSourceContainer.getInstance().getJavaSourceByName("Producer");
    JavaSource product1 = JavaSourceContainer.getInstance().getJavaSourceByName("Product1");
    Set<Dependency> foundedDependencies = DependencyContainer.getInstance().findAllDependenciesWith(producer, DependencyType.PRODUCES);
    assertEquals(4, foundedDependencies.size());
    foundedDependencies = DependencyContainer.getInstance().findAllDependenciesWith(producer, DependencyType.EVENT);
    assertEquals(0, foundedDependencies.size());
    foundedDependencies = DependencyContainer.getInstance().findAllDependenciesWith(product1, DependencyType.INSTANCE);
    assertEquals(1, foundedDependencies.size());
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) Test(org.junit.Test)

Example 14 with Dependency

use of de.strullerbaumann.visualee.dependency.entity.Dependency 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 15 with Dependency

use of de.strullerbaumann.visualee.dependency.entity.Dependency 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)

Aggregations

Dependency (de.strullerbaumann.visualee.dependency.entity.Dependency)33 JavaSource (de.strullerbaumann.visualee.source.entity.JavaSource)31 Test (org.junit.Test)28 DependencyType (de.strullerbaumann.visualee.dependency.entity.DependencyType)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 JsonArrayBuilder (javax.json.JsonArrayBuilder)1 JsonObjectBuilder (javax.json.JsonObjectBuilder)1 Ignore (org.junit.Ignore)1