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());
}
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();
}
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());
}
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());
}
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());
}
Aggregations