Search in sources :

Example 1 with JavaSource

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

the class ExaminerObservesTest method testFindAndSetAttributesObserves.

@Test
public void testFindAndSetAttributesObserves() {
    JavaSource javaSource;
    Dependency dependency;
    String sourceCode;
    javaSource = JavaSourceFactory.getInstance().newJavaSource("SnapshotEscalator");
    sourceCode = TestDataProvider.getTestSourceCodeBeforeBody() + "public void escalate(@Observes @Severity(Severity.Level.HEARTBEAT) Snapshot current) {\n" + "List<Script> scripts = this.scripting.activeScripts();\n" + "try {\n" + "Bindings binding = this.scriptEngine.createBindings();\n" + "binding.put(\"current\", current);\n" + "Snapshot recent = this.recentSnapshots.get(current.getInstanceName());\n" + "binding.put(\"previous\", recent);\n" + "long start = System.currentTimeMillis();\n" + "} catch (Exception e) {\n" + "throw new IllegalStateException(\"Exception during script evaluation: \" + e, e);\n" + "}\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)

Example 2 with JavaSource

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

the class ExaminerObservesTest method testObservesNotify.

@Test
public void testObservesNotify() {
    JavaSource javaSource;
    Dependency dependency;
    String sourceCode;
    javaSource = JavaSourceFactory.getInstance().newJavaSource("SnapshotEscalator");
    sourceCode = TestDataProvider.getTestSourceCodeBeforeBody() + "public void escalate(@Observes(notifyObserver=IF_EXISTS) @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)

Example 3 with JavaSource

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

the class ExaminerResourceTest method testFindAndSetAttributesResourceMappedName.

@Test
public void testFindAndSetAttributesResourceMappedName() {
    JavaSource javaSource;
    Dependency dependency;
    String sourceCode;
    javaSource = JavaSourceFactory.getInstance().newJavaSource("SimplifiedMessageReceiver");
    sourceCode = "package de.x.y;\n" + "public class SimplifiedMessageReceiver {\n" + "@Resource(mappedName=\"java:global/jms/myQueue2\")\n" + "Queue myQueue;\n" + "}\n";
    javaSource.setSourceCode(sourceCode);
    examiner.examine(javaSource);
    dependency = DependencyContainer.getInstance().getDependencies(javaSource).get(0);
    assertEquals(1, DependencyContainer.getInstance().getDependencies(javaSource).size());
    assertEquals(DependencyType.RESOURCE, dependency.getDependencyType());
    assertEquals("SimplifiedMessageReceiver", dependency.getJavaSourceFrom().getName());
    assertEquals("Queue", dependency.getJavaSourceTo().getName());
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) Test(org.junit.Test)

Example 4 with JavaSource

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

the class ExaminerResourceTest method testFindAndSetAttributesResource.

@Test
public void testFindAndSetAttributesResource() {
    JavaSource javaSource;
    Dependency dependency;
    String sourceCode;
    javaSource = JavaSourceFactory.getInstance().newJavaSource("DatabaseConnectionProducer");
    sourceCode = "package de.gedoplan.buch.eedemos.cdi.producer;\n" + "import javax.annotation.Resource;\n" + "import javax.enterprise.context.ApplicationScoped;\n" + "import javax.enterprise.inject.Produces;\n" + "import javax.sql.DataSource;\n" + "@ApplicationScoped\n" + "public class DatabaseConnectionProducer\n" + "{\n" + "@Resource(lookup = \"jdbc/ee-demos\")\n" + "@Produces\n" + "private DataSource dataSource;\n" + "}\n";
    javaSource.setSourceCode(sourceCode);
    examiner.examine(javaSource);
    dependency = DependencyContainer.getInstance().getDependencies(javaSource).get(0);
    assertEquals(1, DependencyContainer.getInstance().getDependencies(javaSource).size());
    assertEquals(DependencyType.RESOURCE, dependency.getDependencyType());
    assertEquals("DatabaseConnectionProducer", dependency.getJavaSourceFrom().getName());
    assertEquals("DataSource", dependency.getJavaSourceTo().getName());
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) Dependency(de.strullerbaumann.visualee.dependency.entity.Dependency) Test(org.junit.Test)

Example 5 with JavaSource

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

the class JavaSourceContainerTest method testGetJavaSourceByName.

@Test
public void testGetJavaSourceByName() {
    JavaSourceContainer.getInstance().clear();
    JavaSource javaSource1 = JavaSourceFactory.getInstance().newJavaSource("DataPoint");
    JavaSourceContainer.getInstance().add(javaSource1);
    JavaSource javaSource2 = JavaSourceFactory.getInstance().newJavaSource("int");
    JavaSourceContainer.getInstance().add(javaSource2);
    JavaSource javaSource3 = JavaSourceFactory.getInstance().newJavaSource("MyTestClass");
    JavaSourceContainer.getInstance().add(javaSource3);
    assertNotNull(JavaSourceContainer.getInstance().getJavaSourceByName("MyTestClass"));
    assertEquals("MyTestClass", JavaSourceContainer.getInstance().getJavaSourceByName("MyTestClass").getName());
    assertNotNull(JavaSourceContainer.getInstance().getJavaSourceByName("int"));
    assertEquals("int", JavaSourceContainer.getInstance().getJavaSourceByName("int").getName());
    assertNotNull(JavaSourceContainer.getInstance().getJavaSourceByName("DataPoint"));
    assertEquals("DataPoint", JavaSourceContainer.getInstance().getJavaSourceByName("DataPoint").getName());
}
Also used : JavaSource(de.strullerbaumann.visualee.source.entity.JavaSource) 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