Search in sources :

Example 36 with JavaSource

use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.

the class ExaminerEJBTest method testFindAndSetAttributesSetEJBPackageView.

@Test
public void testFindAndSetAttributesSetEJBPackageView() {
    JavaSource javaSource;
    String sourceCode;
    javaSource = JavaSourceFactory.getInstance().newJavaSource("MyTestClass");
    sourceCode = "public abstract class MyTestClass {\n" + "@EJB\n" + "PersonSessionBean bean;" + "}\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("PersonSessionBean", dependency.getJavaSourceTo().getName());
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) Test(org.junit.Test)

Example 37 with JavaSource

use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.

the class ExaminerEJBTest method testFindAndSetAttributesEJBWithParameter.

@Test
public void testFindAndSetAttributesEJBWithParameter() {
    JavaSource javaSource;
    String sourceCode;
    javaSource = JavaSourceFactory.getInstance().newJavaSource("AlbumServiceImpl");
    sourceCode = "@Stateless\n" + "@EJB(name = \"java:global/galleria/galleria-ejb/AlbumService\", beanInterface = AlbumService.class)\n" + "@RolesAllowed({ \"RegisteredUsers\" })\n" + "@TransactionAttribute(TransactionAttributeType.REQUIRED)\n" + "public class AlbumServiceImpl implements AlbumService\n" + "{\n" + "private static final Logger logger = LoggerFactory.getLogger(AlbumServiceImpl.class);\n" + " @Resource\n" + "	private SessionContext context;\n" + "	@EJB\n" + "	private UserRepository userRepository;\n" + "	@EJB(name = \"java:global/test/test-ejb/TestService\", beanInterface = TestService.class)\n" + "	private AlbumRepository albumRepository;\n" + "	@Override\n" + "	public Album createAlbum(Album album) throws AlbumException\n" + "	{\n" + "		validateAlbum(album);\n" + "		User user = findCurrentUser(CREATE_ALBUM_INTERNAL_ERROR);\n" + "		logger.debug(\"User's albums: {}\", user.getAlbums());\n" + "		if (user.getAlbums().contains(album))\n" + "		{\n" + "			logger.error(\"The album to be created, already exists.\");\n" + "			throw new AlbumException(DUPLICATE_ALBUM);\n" + "		}\n" + "		user.addToAlbums(album);\n" + "		Album createdAlbum = albumRepository.create(album);\n" + "		return createdAlbum;\n" + "	}\n";
    javaSource.setSourceCode(sourceCode);
    examiner.examine(javaSource);
    assertEquals(2, DependencyContainer.getInstance().getDependencies(javaSource).size());
    Dependency dependency;
    dependency = DependencyContainer.getInstance().getDependencies(javaSource).get(0);
    assertEquals(DependencyType.EJB, dependency.getDependencyType());
    assertEquals("AlbumServiceImpl", dependency.getJavaSourceFrom().getName());
    assertEquals("UserRepository", dependency.getJavaSourceTo().getName());
    dependency = DependencyContainer.getInstance().getDependencies(javaSource).get(1);
    assertEquals(DependencyType.EJB, dependency.getDependencyType());
    assertEquals("AlbumServiceImpl", dependency.getJavaSourceFrom().getName());
    assertEquals("AlbumRepository", dependency.getJavaSourceTo().getName());
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) Test(org.junit.Test)

Example 38 with JavaSource

use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.

the class ExaminerInjectTest method testFindAndSetAttributesSetInject.

@Test
public void testFindAndSetAttributesSetInject() {
    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" + "@Inject\n" + "TestClass testclass;\n" + "@Inject\n" + "Instance<TestClass2> testclass2;\n" + "@Inject\n" + "Event<TestClass3> testclass3;\n" + "@Inject\n" + "Instance<SnapshotCollector> snapshotCollectorInstance;\n" + "@Inject\n" + "protected void setEntityManager(EntityManager entityManager) {\n" + "        this.entityManager = entityManager;\n" + "}\n";
    javaSource.setSourceCode(sourceCode);
    examiner.examine(javaSource);
    assertEquals(2, DependencyContainer.getInstance().getDependencies(javaSource).size());
    Dependency dependency;
    dependency = DependencyContainer.getInstance().getDependencies(javaSource).get(0);
    assertEquals(DependencyType.INJECT, dependency.getDependencyType());
    assertEquals("MyTestClass", dependency.getJavaSourceFrom().getName());
    assertEquals("TestClass", dependency.getJavaSourceTo().getName());
    dependency = DependencyContainer.getInstance().getDependencies(javaSource).get(1);
    assertEquals(DependencyType.INJECT, 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 39 with JavaSource

use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.

the class ExaminerInjectTest method testFindEventNamedClass.

@Test
public void testFindEventNamedClass() {
    DependencyContainer.getInstance().clear();
    JavaSource javaSource;
    String sourceCode;
    javaSource = JavaSourceFactory.getInstance().newJavaSource("Events");
    sourceCode = "     @Stateless\n" + "public class Events {\n" + " @Inject\n" + " private EventValidator validator;\n" + " @Inject\n" + " private PrintingService ps;\n" + "    }\n";
    javaSource.setSourceCode(sourceCode);
    examiner.examine(javaSource);
    assertEquals(2, DependencyContainer.getInstance().getDependencies(javaSource).size());
    Dependency dependency;
    dependency = DependencyContainer.getInstance().getDependencies(javaSource).get(0);
    assertEquals(DependencyType.INJECT, dependency.getDependencyType());
    assertEquals("Events", dependency.getJavaSourceFrom().getName());
    assertEquals("EventValidator", dependency.getJavaSourceTo().getName());
    dependency = DependencyContainer.getInstance().getDependencies(javaSource).get(1);
    assertEquals(DependencyType.INJECT, dependency.getDependencyType());
    assertEquals("Events", dependency.getJavaSourceFrom().getName());
    assertEquals("PrintingService", dependency.getJavaSourceTo().getName());
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) Test(org.junit.Test)

Example 40 with JavaSource

use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.

the class ExaminerObservesTest method testObservesDuring.

@Test
public void testObservesDuring() {
    JavaSource javaSource;
    Dependency dependency;
    String sourceCode;
    javaSource = JavaSourceFactory.getInstance().newJavaSource("SnapshotEscalator");
    sourceCode = TestDataProvider.getTestSourceCodeBeforeBody() + "public void escalate(@Observes(during=BEFORE_COMPLETION) @Severity(Severity.Level.HEARTBEAT) Snapshot current) {\n" + "}\n";
    javaSource.setSourceCode(sourceCode);
    examiner.examine(javaSource);
    dependency = DependencyContainer.getInstance().getDependencies(javaSource).get(0);
    assertEquals(1, DependencyContainer.getInstance().getDependencies(javaSource).size());
    assertEquals(DependencyType.OBSERVES, dependency.getDependencyType());
    assertEquals("SnapshotEscalator", dependency.getJavaSourceFrom().getName());
    assertEquals("Snapshot", dependency.getJavaSourceTo().getName());
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) Test(org.junit.Test)

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