use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.
the class ExaminerProducesTest method testFindAndSetAttributesStaticProduces.
@Test
public void testFindAndSetAttributesStaticProduces() {
JavaSource javaSource;
String sourceCode;
javaSource = JavaSourceFactory.getInstance().newJavaSource("LoggerProducer");
sourceCode = "package de.dasd.dasdas.utils.logging;\n" + "import javax.enterprise.inject.Produces;\n" + "import javax.enterprise.inject.spi.InjectionPoint;\n" + "import org.apache.commons.logging.Log;\n" + "import org.apache.commons.logging.LogFactory;\n" + "public class LoggerProducer {\n" + " @Produces\n" + " public static Log getLogger(InjectionPoint injectionPoint) {\n" + " Class<?> targetClass = injectionPoint.getMember().getDeclaringClass();\n" + " return LogFactory.getLog(targetClass);\n" + " }\n" + " private LoggerProducer() {\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.PRODUCES, dependency.getDependencyType());
assertEquals("LoggerProducer", dependency.getJavaSourceFrom().getName());
assertEquals("Log", dependency.getJavaSourceTo().getName());
}
use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.
the class JavaSourceContainerTest method testAddNullJavaSource.
@Test
public void testAddNullJavaSource() {
JavaSourceContainer.getInstance().clear();
JavaSource javaSource = null;
JavaSourceContainer.getInstance().add(javaSource);
assertEquals(0, JavaSourceContainer.getInstance().getJavaSources().size());
}
use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.
the class TestDataProvider method createSampleDependencies.
public static void createSampleDependencies() {
JavaSourceContainer.getInstance().clear();
DependencyContainer.getInstance().clear();
JavaSource producer = JavaSourceFactory.getInstance().newJavaSource("Producer");
JavaSourceContainer.getInstance().add(producer);
JavaSource product1 = JavaSourceFactory.getInstance().newJavaSource("Product1");
JavaSourceContainer.getInstance().add(product1);
JavaSource product2 = JavaSourceFactory.getInstance().newJavaSource("Product2");
JavaSourceContainer.getInstance().add(product2);
JavaSource product3 = JavaSourceFactory.getInstance().newJavaSource("Product3");
JavaSourceContainer.getInstance().add(product3);
JavaSource product4 = JavaSourceFactory.getInstance().newJavaSource("Product4");
JavaSourceContainer.getInstance().add(product4);
JavaSource instance1 = JavaSourceFactory.getInstance().newJavaSource("Instance1");
JavaSourceContainer.getInstance().add(instance1);
JavaSource instance2 = JavaSourceFactory.getInstance().newJavaSource("Instance2");
JavaSourceContainer.getInstance().add(instance2);
JavaSource instance3 = JavaSourceFactory.getInstance().newJavaSource("Instance3");
JavaSourceContainer.getInstance().add(instance3);
JavaSource instance4 = JavaSourceFactory.getInstance().newJavaSource("Instance4");
JavaSourceContainer.getInstance().add(instance4);
Dependency dProducer_Product1 = new Dependency(DependencyType.PRODUCES, producer, product1);
DependencyContainer.getInstance().add(dProducer_Product1);
Dependency dProducer_Product2 = new Dependency(DependencyType.PRODUCES, producer, product2);
DependencyContainer.getInstance().add(dProducer_Product2);
Dependency dProducer_Product3 = new Dependency(DependencyType.PRODUCES, producer, product3);
DependencyContainer.getInstance().add(dProducer_Product3);
Dependency dProducer_Product4 = new Dependency(DependencyType.PRODUCES, producer, product4);
DependencyContainer.getInstance().add(dProducer_Product4);
Dependency dProduct1_Instance1 = new Dependency(DependencyType.INSTANCE, instance1, product1);
DependencyContainer.getInstance().add(dProduct1_Instance1);
Dependency dProduct2_Instance2 = new Dependency(DependencyType.INSTANCE, instance2, product2);
DependencyContainer.getInstance().add(dProduct2_Instance2);
Dependency dProduct3_Instance3 = new Dependency(DependencyType.INSTANCE, instance3, product3);
DependencyContainer.getInstance().add(dProduct3_Instance3);
Dependency dProduct4_Instance4 = new Dependency(DependencyType.INSTANCE, instance4, product4);
DependencyContainer.getInstance().add(dProduct4_Instance4);
// Add some not relevant (direct connected) JavaSources
JavaSource notRelevant1 = JavaSourceFactory.getInstance().newJavaSource("NotRelevant1");
JavaSourceContainer.getInstance().add(notRelevant1);
JavaSource notRelevant2 = JavaSourceFactory.getInstance().newJavaSource("NotRelevant2");
JavaSourceContainer.getInstance().add(notRelevant2);
JavaSource notRelevant3 = JavaSourceFactory.getInstance().newJavaSource("NotRelevant3");
JavaSourceContainer.getInstance().add(notRelevant3);
Dependency dInject1_notRelevant1 = new Dependency(DependencyType.INSTANCE, instance1, notRelevant1);
DependencyContainer.getInstance().add(dInject1_notRelevant1);
Dependency dInject1_notRelevant2 = new Dependency(DependencyType.INSTANCE, instance1, notRelevant2);
DependencyContainer.getInstance().add(dInject1_notRelevant2);
Dependency dInject3_notRelevant1 = new Dependency(DependencyType.INSTANCE, instance3, notRelevant1);
DependencyContainer.getInstance().add(dInject3_notRelevant1);
Dependency dInject3_notRelevant3 = new Dependency(DependencyType.INSTANCE, instance3, notRelevant3);
DependencyContainer.getInstance().add(dInject3_notRelevant3);
}
use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.
the class DescriptionTest method testGenerateDescription2.
@Test
public void testGenerateDescription2() {
JavaSource javaSource;
String sourceCode;
// Produces
javaSource = JavaSourceFactory.getInstance().newJavaSource("Configurator");
sourceCode = "package org.lightfish.business.configuration.boundary;\n" + "import org.lightfish.business.configuration.entity.Configuration;\n" + "import java.util.Arrays;\n" + "import javax.annotation.PostConstruct;\n" + "import javax.ejb.Singleton;\n" + "import javax.enterprise.inject.Produces;\n" + "import javax.enterprise.inject.spi.InjectionPoint;\n" + "import javax.ejb.Startup;\n" + "import javax.inject.Inject;\n" + "import org.lightfish.business.configuration.control.ConfigurationStore;\n" + "@Startup\n" + "@Singleton\n" + "public class Configurator {\n" + " private Configuration configuration;\n" + " @Inject ConfigurationStore configurationStore;\n" + " @PostConstruct\n" + " public void initialize(){\n" + " this.configuration = configurationStore.retrieveConfiguration();\n" + " }\n" + " @Produces\n" + " public int getInteger(InjectionPoint ip) {\n" + " return Integer.parseInt(getString(ip));\n" + " }\n" + " @Produces\n" + " public boolean getBoolean(InjectionPoint ip) {\n" + " return Boolean.parseBoolean(getString(ip));\n" + " }\n" + " @Produces\n" + " public String getString(InjectionPoint ip) {\n" + " String name = ip.getMember().getName();\n" + " return this.configuration.get(name);\n" + " }\n" + " @Produces\n" + " public String[] getStringArray(InjectionPoint ip){\n" + " return asArray(getString(ip));\n" + " }\n" + " public String[] getStringArray(String key){\n" + " return asArray(getValue(key));\n" + " }\n" + " public String getValue(String key){\n" + " return this.configuration.get(key);\n" + " }\n" + " public String[] asArray(String value){\n" + " return value.split(\",\");\n" + " }\n" + "// public Map<String, String> getConfiguration() {\n" + "// return configuration;\n" + "// }\n" + " public int getValueAsInt(String interval) {\n" + " return Integer.parseInt(getValue(interval));\n" + " }\n" + " public void setValue(String key,int interval) {\n" + " this.setValue(key, String.valueOf(interval));\n" + " }\n" + " public void setValue(String key,boolean value) {\n" + " this.setValue(key, String.valueOf(value));\n" + " }\n" + " public void setValue(String key, String value) {\n" + " this.configuration.put(key, value);\n" + " configurationStore.save(configuration);\n" + " }\n" + " public void setArrayValue(String key, String[] values) {\n" + " StringBuilder sb = new StringBuilder();\n" + " for(String value:values){\n" + " if(sb.length()!=0){\n" + " sb.append(\",\");\n" + " }\n" + " sb.append(value);\n" + " }\n" + " this.setValue(key, String.valueOf(sb.toString()));\n" + " }\n" + "}\n";
javaSource.setSourceCode(sourceCode);
JavaSourceContainer.getInstance().add(javaSource);
JavaSourceInspector.getInstance().registerExaminer(new ExaminerInject());
JavaSourceInspector.getInstance().registerExaminer(new ExaminerProduces());
JavaSourceInspector.getInstance().examine();
String actual = Description.generateDescription(javaSource);
assertTrue(actual.indexOf("ConfigurationStore is injected") > 0);
assertTrue(actual.indexOf("Produces Integer") > 0);
assertTrue(actual.indexOf("Produces Boolean") > 0);
assertTrue(actual.indexOf("Produces String") > 0);
assertTrue(actual.indexOf("Produces String[]") > 0);
}
use of de.strullerbaumann.visualee.source.entity.JavaSource in project visualee by Thomas-S-B.
the class JPAExaminerTest method testFindAndSetAttributesIgnoreComments.
@Test
public void testFindAndSetAttributesIgnoreComments() {
ExaminerJPA jpaExaminer = new ExaminerJPA();
JavaSource javaSource;
String sourceCode;
javaSource = JavaSourceFactory.getInstance().newJavaSource("Cocktail");
sourceCode = "//@Entity\n" + "//@Access(AccessType.FIELD)\n" + "public class Cocktail implements Comparable<Cocktail>\n" + "{\n" + "// @Id\n" + "private String id;\n" + "private String name;\n" + "// @ManyToMany\n" + "private Set<CocktailZutat> zutaten = new HashSet<CocktailZutat>();\n" + "// @ManyToOne\n" + "private CocktailZutat basisZutat;\n" + "public Cocktail(String id, String name)\n" + "{\n" + "this.id = id;\n" + "this.name = name;\n" + "}\n";
javaSource.setSourceCode(sourceCode);
jpaExaminer.examine(javaSource);
assertEquals(0, DependencyContainer.getInstance().getDependencies(javaSource).size());
}
Aggregations