Ejemplo n.º 1
0
  @Test
  public void testFindEvents() {
    DependencyContainer.getInstance().clear();
    JavaSource javaSource;
    String sourceCode;

    javaSource = new JavaSource("Events");
    sourceCode =
        "     @Stateless\n"
            + "public class Events {\n"
            + "    @PersistenceContext\n"
            + " private EntityManager em;\n"
            + " @Inject\n"
            + " private EventValidator validator;\n"
            + " @Inject\n"
            + " private PrintingService ps;\n"
            + " @Inject\n"
            + " Event<AirEvent> monitoring;\n"
            + " public List<AirEvent> getEvents() {\n"
            + "     return this.em.createNamedQuery(AirEvent.all).getResultList();\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.EVENT, dependency.getDependencyType());
    assertEquals("Events", dependency.getJavaSourceFrom().getName());
    assertEquals("AirEvent", dependency.getJavaSourceTo().getName());
  }
Ejemplo n.º 2
0
 public List<Dependency> getDependenciesOfType(DependencyType dependencyType) {
   List<Dependency> dependenciesOfType = new ArrayList<>();
   for (Dependency dependency : dependencies) {
     if (dependency.getDependencyType().equals(dependencyType)) {
       dependenciesOfType.add(dependency);
     }
   }
   return dependenciesOfType;
 }
Ejemplo n.º 3
0
 public List<Dependency> getDependencies(JavaSource javaSource) {
   List<Dependency> foundDependencies = new ArrayList<>();
   for (Dependency d : dependencies) {
     if (d.getJavaSourceFrom().equals(javaSource)) {
       foundDependencies.add(d);
     }
   }
   return foundDependencies;
 }
Ejemplo n.º 4
0
 Set<Dependency> findAllDependenciesWith(JavaSource javaSource, DependencyType dependencyType) {
   Set<Dependency> foundDependencies = new HashSet<>();
   for (Dependency dependency : getDependenciesOfType(dependencyType)) {
     if (dependency.getJavaSourceFrom().equals(javaSource)
         || dependency.getJavaSourceTo().equals(javaSource)) {
       foundDependencies.add(dependency);
     }
   }
   return foundDependencies;
 }
Ejemplo n.º 5
0
 // 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;
 }
Ejemplo n.º 6
0
  @Test
  public void testFindAndSetAttributesSetInstance() {
    DependencyContainer.getInstance().clear();
    JavaSource javaSource;
    String sourceCode;

    javaSource = new JavaSource("TunguskaGate");
    sourceCode =
        "@WebServlet(name = \"TunguskaGate\", urlPatterns = {\"/live/*\"}, asyncSupported = true)\n"
            + "public class TunguskaGate extends HttpServlet {\n"
            + "    @Inject @SnapshotDataCollector\n"
            + "    Event<BrowserWindow> events;\n"
            + "    private final static Logger LOG = Logger.getLogger(TunguskaGate.class.getName());\n"
            + "    @Override\n"
            + "    protected void doGet(HttpServletRequest request, HttpServletResponse response)\n"
            + "            throws ServletException, IOException {\n"
            + "        AsyncContext startAsync = request.startAsync();\n"
            + "        String channel = extractChannel(request.getRequestURI());\n"
            + "        LOG.info(\"Browser is requesting \" + channel);\n"
            + "        if(channel==null||channel.trim().isEmpty()){\n"
            + "            channel = MonitoringController.COMBINED_SNAPSHOT_NAME;\n"
            + "        }\n"
            + "        BrowserWindow browser = new BrowserWindow(startAsync,channel);\n"
            + "        LOG.info(\"Registering browser window(\"+ browser.hashCode() +\") for channel \" + channel);\n"
            + "        events.fire(browser);\n"
            + "        LOG.fine(\"Event sent\");\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.EVENT, dependency.getDependencyType());
    assertEquals("TunguskaGate", dependency.getJavaSourceFrom().getName());
    assertEquals("BrowserWindow", dependency.getJavaSourceTo().getName());
  }