Commit 53aeb6692d4ee1fc6a7b96b35e794a5de38acacd
Exists in
master
Merge branch '2.4.0' of https://github.com/demoiselle/framework.git into 2.4.0
Showing
136 changed files
with
3155 additions
and
3453 deletions
Show diff stats
Too many changes.
To preserve performance only 100 of 136 files displayed.
archetype/jsf-jpa/pom.xml
| ... | ... | @@ -45,7 +45,7 @@ |
| 45 | 45 | <parent> |
| 46 | 46 | <groupId>br.gov.frameworkdemoiselle</groupId> |
| 47 | 47 | <artifactId>demoiselle-archetype-parent</artifactId> |
| 48 | - <version>2.4.0-BETA3-SNAPSHOT</version> | |
| 48 | + <version>2.4.0-BETA4-SNAPSHOT</version> | |
| 49 | 49 | <relativePath>../../parent/archetype</relativePath> |
| 50 | 50 | </parent> |
| 51 | 51 | ... | ... |
archetype/minimal/pom.xml
| ... | ... | @@ -45,7 +45,7 @@ |
| 45 | 45 | <parent> |
| 46 | 46 | <groupId>br.gov.frameworkdemoiselle</groupId> |
| 47 | 47 | <artifactId>demoiselle-archetype-parent</artifactId> |
| 48 | - <version>2.4.0-BETA3-SNAPSHOT</version> | |
| 48 | + <version>2.4.0-BETA4-SNAPSHOT</version> | |
| 49 | 49 | <relativePath>../../parent/archetype</relativePath> |
| 50 | 50 | </parent> |
| 51 | 51 | ... | ... |
documentation/quickstart/pom.xml
| ... | ... | @@ -40,12 +40,12 @@ |
| 40 | 40 | |
| 41 | 41 | <artifactId>demoiselle-framework-quickstart</artifactId> |
| 42 | 42 | <packaging>jdocbook</packaging> |
| 43 | - <version>2.4.0-BETA3-SNAPSHOT</version> | |
| 43 | + <version>2.4.0-BETA4-SNAPSHOT</version> | |
| 44 | 44 | |
| 45 | 45 | <parent> |
| 46 | 46 | <groupId>br.gov.frameworkdemoiselle</groupId> |
| 47 | 47 | <artifactId>demoiselle-documentation-parent</artifactId> |
| 48 | - <version>8</version> | |
| 48 | + <version>9</version> | |
| 49 | 49 | <relativePath>../../../internal/parent/documentation</relativePath> |
| 50 | 50 | </parent> |
| 51 | 51 | ... | ... |
documentation/reference/pom.xml
| ... | ... | @@ -40,12 +40,12 @@ |
| 40 | 40 | |
| 41 | 41 | <artifactId>demoiselle-framework-reference</artifactId> |
| 42 | 42 | <packaging>jdocbook</packaging> |
| 43 | - <version>2.4.0-BETA3-SNAPSHOT</version> | |
| 43 | + <version>2.4.0-BETA4-SNAPSHOT</version> | |
| 44 | 44 | |
| 45 | 45 | <parent> |
| 46 | 46 | <groupId>br.gov.frameworkdemoiselle</groupId> |
| 47 | 47 | <artifactId>demoiselle-documentation-parent</artifactId> |
| 48 | - <version>8</version> | |
| 48 | + <version>9</version> | |
| 49 | 49 | <relativePath>../../../internal/parent/documentation</relativePath> |
| 50 | 50 | </parent> |
| 51 | 51 | ... | ... |
documentation/reference/pt-BR/security.xml
| ... | ... | @@ -20,8 +20,7 @@ |
| 20 | 20 | <title>Configurando</title> |
| 21 | 21 | |
| 22 | 22 | <para> |
| 23 | - Para um correto funcionamento da segurança no Framework Demoiselle é necessário inserir os interceptadores de segurança no arquivo <filename>beans.xml</filename>, localizado | |
| 24 | - na pasta WEB-INF em projetos WEB ou na pasta META-INF em projetos SE ou EJB. | |
| 23 | + Para um correto funcionamento do Demoiselle é necessário inserir os interceptadores de segurança no arquivo <filename>src/main/webapp/WEB-INF/beans.xml</filename>. | |
| 25 | 24 | </para> |
| 26 | 25 | |
| 27 | 26 | <programlisting role="XML"><![CDATA[<beans xmlns="http://java.sun.com/xml/ns/javaee" |
| ... | ... | @@ -239,7 +238,6 @@ class GerenciadorBookmark { |
| 239 | 238 | } |
| 240 | 239 | |
| 241 | 240 | }]]></programlisting> |
| 242 | - | |
| 243 | 241 | <tip> |
| 244 | 242 | É possível informar mais de um papel para a anotação <code>@RequiredRole</code>, neste caso basta que o usuário |
| 245 | 243 | autenticado possua um dos papéis listados para ter acesso ao recurso. |
| ... | ... | @@ -535,8 +533,8 @@ class GerenciadorBookmark { |
| 535 | 533 | } |
| 536 | 534 | |
| 537 | 535 | @Override |
| 538 | - public boolean hasPermission(Object resource, String operation) { | |
| 539 | - // Verifique se o usuario autenticado tem a permissao adequada, retorne true em caso positivo | |
| 536 | + public boolean hasPermission(String resource, String operation) { | |
| 537 | + // Escreva aqui seu codigo de verificação de permissao | |
| 540 | 538 | return false; |
| 541 | 539 | } |
| 542 | 540 | }]]></programlisting> |
| ... | ... | @@ -612,5 +610,4 @@ class GerenciadorBookmark { |
| 612 | 610 | </tgroup> |
| 613 | 611 | </informaltable> |
| 614 | 612 | </section> |
| 615 | - | |
| 616 | -</chapter> | |
| 617 | 613 | \ No newline at end of file |
| 614 | +</chapter> | ... | ... |
impl/core/pom.xml
| ... | ... | @@ -44,7 +44,7 @@ |
| 44 | 44 | <parent> |
| 45 | 45 | <groupId>br.gov.frameworkdemoiselle</groupId> |
| 46 | 46 | <artifactId>demoiselle-framework-parent</artifactId> |
| 47 | - <version>2.4.0-BETA3-SNAPSHOT</version> | |
| 47 | + <version>2.4.0-BETA4-SNAPSHOT</version> | |
| 48 | 48 | <relativePath>../../parent/framework</relativePath> |
| 49 | 49 | </parent> |
| 50 | 50 | |
| ... | ... | @@ -72,7 +72,7 @@ |
| 72 | 72 | <dependency> |
| 73 | 73 | <groupId>br.gov.frameworkdemoiselle</groupId> |
| 74 | 74 | <artifactId>demoiselle-framework-bom</artifactId> |
| 75 | - <version>2.4.0-BETA3-SNAPSHOT</version> | |
| 75 | + <version>2.4.0-BETA4-SNAPSHOT</version> | |
| 76 | 76 | <scope>import</scope> |
| 77 | 77 | <type>pom</type> |
| 78 | 78 | </dependency> |
| ... | ... | @@ -98,20 +98,59 @@ |
| 98 | 98 | <artifactId>cobertura-maven-plugin</artifactId> |
| 99 | 99 | </plugin> |
| 100 | 100 | |
| 101 | - <!-- <plugin> <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> | |
| 102 | - <version>${jacoco.version}</version> <executions> <execution> <goals> <goal>prepare-agent</goal> | |
| 103 | - </goals> </execution> <execution> <id>report</id> <phase>prepare-package</phase> | |
| 104 | - <goals> <goal>report</goal> </goals> </execution> </executions> </plugin> --> | |
| 101 | + <!-- | |
| 102 | + <plugin> | |
| 103 | + <groupId>org.jacoco</groupId> | |
| 104 | + <artifactId>jacoco-maven-plugin</artifactId> | |
| 105 | + <version>${jacoco.version}</version> | |
| 106 | + <executions> | |
| 107 | + <execution> | |
| 108 | + <goals> | |
| 109 | + <goal>prepare-agent</goal> | |
| 110 | + </goals> | |
| 111 | + </execution> | |
| 112 | + <execution> | |
| 113 | + <id>report</id> | |
| 114 | + <phase>prepare-package</phase> | |
| 115 | + <goals> | |
| 116 | + <goal>report</goal> | |
| 117 | + </goals> | |
| 118 | + </execution> | |
| 119 | + </executions> | |
| 120 | + </plugin> | |
| 121 | + --> | |
| 105 | 122 | </plugins> |
| 106 | 123 | |
| 107 | - <!-- <pluginManagement> <plugins> <plugin> <groupId>org.eclipse.m2e</groupId> | |
| 108 | - <artifactId>lifecycle-mapping</artifactId> <version>1.0.0</version> <configuration> | |
| 109 | - <lifecycleMappingMetadata> <pluginExecutions> <pluginExecution> <pluginExecutionFilter> | |
| 110 | - <groupId>org.jacoco</groupId> <artifactId>jacoco-maven-plugin</artifactId> | |
| 111 | - <versionRange>[${jacoco.version},)</versionRange> <goals> <goal>prepare-agent</goal> | |
| 112 | - </goals> </pluginExecutionFilter> <action> <ignore></ignore> </action> </pluginExecution> | |
| 113 | - </pluginExecutions> </lifecycleMappingMetadata> </configuration> </plugin> | |
| 114 | - </plugins> </pluginManagement> --> | |
| 124 | + <!-- | |
| 125 | + <pluginManagement> | |
| 126 | + <plugins> | |
| 127 | + <plugin> | |
| 128 | + <groupId>org.eclipse.m2e</groupId> | |
| 129 | + <artifactId>lifecycle-mapping</artifactId> | |
| 130 | + <version>1.0.0</version> | |
| 131 | + <configuration> | |
| 132 | + <lifecycleMappingMetadata> | |
| 133 | + <pluginExecutions> | |
| 134 | + <pluginExecution> | |
| 135 | + <pluginExecutionFilter> | |
| 136 | + <groupId>org.jacoco</groupId> | |
| 137 | + <artifactId>jacoco-maven-plugin</artifactId> | |
| 138 | + <versionRange>[${jacoco.version},)</versionRange> | |
| 139 | + <goals> | |
| 140 | + <goal>prepare-agent</goal> | |
| 141 | + </goals> | |
| 142 | + </pluginExecutionFilter> | |
| 143 | + <action> | |
| 144 | + <ignore></ignore> | |
| 145 | + </action> | |
| 146 | + </pluginExecution> | |
| 147 | + </pluginExecutions> | |
| 148 | + </lifecycleMappingMetadata> | |
| 149 | + </configuration> | |
| 150 | + </plugin> | |
| 151 | + </plugins> | |
| 152 | + </pluginManagement> | |
| 153 | + --> | |
| 115 | 154 | </build> |
| 116 | 155 | |
| 117 | 156 | <dependencies> |
| ... | ... | @@ -163,27 +202,44 @@ |
| 163 | 202 | <scope>test</scope> |
| 164 | 203 | </dependency> |
| 165 | 204 | <dependency> |
| 205 | + <groupId>org.slf4j</groupId> | |
| 206 | + <artifactId>slf4j-log4j12</artifactId> | |
| 207 | + <scope>test</scope> | |
| 208 | + </dependency> | |
| 209 | + | |
| 210 | + <!-- | |
| 211 | + <dependency> | |
| 166 | 212 | <groupId>javax.servlet</groupId> |
| 167 | 213 | <artifactId>servlet-api</artifactId> |
| 168 | 214 | <scope>test</scope> |
| 169 | 215 | </dependency> |
| 170 | 216 | |
| 171 | - <!-- <dependency> <groupId>org.jboss.arquillian.extension</groupId> <artifactId>arquillian-jacoco</artifactId> | |
| 172 | - <version>1.0.0.Alpha5</version> <scope>test</scope> </dependency> <dependency> | |
| 173 | - <groupId>org.jacoco</groupId> <artifactId>org.jacoco.core</artifactId> <version>${jacoco.version}</version> | |
| 174 | - <scope>test</scope> </dependency> --> | |
| 175 | - | |
| 176 | - <!-- <dependency> <groupId>org.jboss.shrinkwrap.descriptors</groupId> <artifactId>shrinkwrap-descriptors-spi</artifactId> | |
| 177 | - <version>2.0.0-alpha-4</version> <scope>test</scope> </dependency> --> | |
| 178 | - | |
| 179 | - <!-- <dependency> <groupId>javax.el</groupId> <artifactId>el-api</artifactId> | |
| 180 | - <scope>test</scope> </dependency> --> | |
| 181 | 217 | <dependency> |
| 182 | - <groupId>org.slf4j</groupId> | |
| 183 | - <artifactId>slf4j-log4j12</artifactId> | |
| 218 | + <groupId>org.jboss.arquillian.extension</groupId> | |
| 219 | + <artifactId>arquillian-jacoco</artifactId> | |
| 220 | + <version>1.0.0.Alpha5</version> | |
| 221 | + <scope>test</scope> | |
| 222 | + </dependency> | |
| 223 | + <dependency> | |
| 224 | + <groupId>org.jacoco</groupId> | |
| 225 | + <artifactId>org.jacoco.core</artifactId> | |
| 226 | + <version>${jacoco.version}</version> | |
| 227 | + <scope>test</scope> | |
| 228 | + </dependency> | |
| 229 | + | |
| 230 | + <dependency> | |
| 231 | + <groupId>org.jboss.shrinkwrap.descriptors</groupId> | |
| 232 | + <artifactId>shrinkwrap-descriptors-spi</artifactId> | |
| 233 | + <version>2.0.0-alpha-4</version> | |
| 184 | 234 | <scope>test</scope> |
| 185 | 235 | </dependency> |
| 186 | 236 | |
| 237 | + <dependency> | |
| 238 | + <groupId>javax.el</groupId> | |
| 239 | + <artifactId>el-api</artifactId> | |
| 240 | + <scope>test</scope> | |
| 241 | + </dependency> | |
| 242 | + --> | |
| 187 | 243 | </dependencies> |
| 188 | 244 | |
| 189 | 245 | <repositories> | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Ignore.java
| ... | ... | @@ -42,6 +42,15 @@ import static java.lang.annotation.RetentionPolicy.RUNTIME; |
| 42 | 42 | import java.lang.annotation.Retention; |
| 43 | 43 | import java.lang.annotation.Target; |
| 44 | 44 | |
| 45 | +/** | |
| 46 | + * <p> | |
| 47 | + * Should be used only in attributes of configuration classes (those annotated with @Configuration). | |
| 48 | + * </p> | |
| 49 | + * When an attribute in a configuration class is annotated with @Ignore, that attribute is not | |
| 50 | + * </br>considerated in loading of configurations. | |
| 51 | + * | |
| 52 | + * @author SERPRO | |
| 53 | + */ | |
| 45 | 54 | @Target(FIELD) |
| 46 | 55 | @Retention(RUNTIME) |
| 47 | 56 | public @interface Ignore { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Name.java
| ... | ... | @@ -49,6 +49,40 @@ import java.lang.annotation.Target; |
| 49 | 49 | import javax.enterprise.util.Nonbinding; |
| 50 | 50 | import javax.inject.Qualifier; |
| 51 | 51 | |
| 52 | +/** | |
| 53 | + * This annotation is used to make passible: | |
| 54 | + * | |
| 55 | + * <ul> | |
| 56 | + * <li>map an attribute that belongs to a configuration class in a key with a different name of this attribute</li> | |
| 57 | + * <li>map a Resource Bundle object to a file with different name of this object</li> | |
| 58 | + * </ul> | |
| 59 | + * | |
| 60 | + * <p> | |
| 61 | + * The examples below shows how these annotation could be used: | |
| 62 | + * <p> | |
| 63 | + * | |
| 64 | + * <blockquote> | |
| 65 | + * | |
| 66 | + * <pre> | |
| 67 | + * public class NameConfig { | |
| 68 | + * | |
| 69 | + * @Name("other.name.attrib") | |
| 70 | + * private int nameOfAttribute; | |
| 71 | + * ... | |
| 72 | + * } | |
| 73 | + * | |
| 74 | + * public class NameResourceBundle { | |
| 75 | + * | |
| 76 | + * @Name("other.name.bundle") | |
| 77 | + * @Inject | |
| 78 | + * private ResourceBundle bundle; | |
| 79 | + * ... | |
| 80 | + * } | |
| 81 | + * </pre> | |
| 82 | + * </blockquote> | |
| 83 | + * | |
| 84 | + * @author SERPRO | |
| 85 | + */ | |
| 52 | 86 | @Qualifier |
| 53 | 87 | @Inherited |
| 54 | 88 | @Retention(RUNTIME) | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/Priority.java
| ... | ... | @@ -44,6 +44,8 @@ import java.lang.annotation.Retention; |
| 44 | 44 | import java.lang.annotation.Target; |
| 45 | 45 | |
| 46 | 46 | /** |
| 47 | + * Used to prioritize some execution flow, as methods annoted with @startup or @shutdown | |
| 48 | + * | |
| 47 | 49 | * @author SERPRO |
| 48 | 50 | */ |
| 49 | 51 | @Target({ TYPE, METHOD }) |
| ... | ... | @@ -59,17 +61,32 @@ public @interface Priority { |
| 59 | 61 | * Less important priority value. |
| 60 | 62 | */ |
| 61 | 63 | static int MIN_PRIORITY = Integer.MAX_VALUE; |
| 62 | - | |
| 64 | + | |
| 65 | + /** | |
| 66 | + * Less important priority value. | |
| 67 | + */ | |
| 63 | 68 | static int L1_PRIORITY = MIN_PRIORITY; |
| 64 | 69 | |
| 70 | + /** | |
| 71 | + * Higher priority than L1_PRIORITY | |
| 72 | + */ | |
| 65 | 73 | static int L2_PRIORITY = L1_PRIORITY - 100; |
| 66 | 74 | |
| 75 | + /** | |
| 76 | + * Higher priority than L2_PRIORITY | |
| 77 | + */ | |
| 67 | 78 | static int L3_PRIORITY = L2_PRIORITY - 100; |
| 68 | 79 | |
| 80 | + /** | |
| 81 | + * Higher priority than L3_PRIORITY | |
| 82 | + */ | |
| 69 | 83 | static int L4_PRIORITY = L3_PRIORITY - 100; |
| 70 | 84 | |
| 71 | 85 | /** |
| 86 | + * <p> | |
| 72 | 87 | * An integer value defines the priority order. |
| 88 | + * <p> | |
| 89 | + * The lower the value, the greater priority. | |
| 73 | 90 | */ |
| 74 | 91 | int value(); |
| 75 | 92 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/StaticScoped.java
| ... | ... | @@ -47,6 +47,11 @@ import java.lang.annotation.Target; |
| 47 | 47 | |
| 48 | 48 | import javax.enterprise.context.NormalScope; |
| 49 | 49 | |
| 50 | +/** | |
| 51 | + *This scope stores the classes just as if it was a static attribute. | |
| 52 | + * | |
| 53 | + * @author SERPRO | |
| 54 | + */ | |
| 50 | 55 | @Inherited |
| 51 | 56 | @Target({ METHOD, TYPE, FIELD }) |
| 52 | 57 | @Retention(RUNTIME) | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/annotation/ViewScoped.java
| ... | ... | @@ -47,6 +47,11 @@ import java.lang.annotation.Target; |
| 47 | 47 | |
| 48 | 48 | import javax.enterprise.context.NormalScope; |
| 49 | 49 | |
| 50 | +/** | |
| 51 | + * This scope maintains the context for viewed page; when the viewed page change, the data will be lost. | |
| 52 | + * | |
| 53 | + * @author SERPRO | |
| 54 | + */ | |
| 50 | 55 | @Inherited |
| 51 | 56 | @Target({ METHOD, TYPE, FIELD }) |
| 52 | 57 | @Retention(RUNTIME) | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/configuration/ConfigurationValueExtractor.java
| ... | ... | @@ -40,9 +40,37 @@ import java.lang.reflect.Field; |
| 40 | 40 | |
| 41 | 41 | import org.apache.commons.configuration.Configuration; |
| 42 | 42 | |
| 43 | +/** | |
| 44 | + * Interface that defining the way to extract the values of configurations attributes from property file. | |
| 45 | + * It should be implemented if is wanted to extract values of a configuration attribute, in a different way or | |
| 46 | + * for a type not yet offered by Demoiselle Framework. | |
| 47 | + * | |
| 48 | + * @author SERPRO | |
| 49 | + */ | |
| 43 | 50 | public interface ConfigurationValueExtractor { |
| 44 | 51 | |
| 52 | + /** | |
| 53 | + * Method that must appropriately extract the value from a property file and set this value to a | |
| 54 | + * field in a configuration class. | |
| 55 | + * | |
| 56 | + * @param prefix | |
| 57 | + * optional parte of property name that must be concatenated with <b>key</b> to form the whole | |
| 58 | + * property name. | |
| 59 | + * @param key | |
| 60 | + * key of the property. | |
| 61 | + * @param field | |
| 62 | + * configuration field to be setted. | |
| 63 | + * @param configuration | |
| 64 | + * a configuration object. | |
| 65 | + */ | |
| 45 | 66 | Object getValue(String prefix, String key, Field field, Configuration configuration) throws Exception; |
| 46 | 67 | |
| 68 | + /** | |
| 69 | + * Checks if the extractor class is appropriate to extract values to the type of deffined by parameter | |
| 70 | + * <b>field</b>. | |
| 71 | + * | |
| 72 | + * @param field | |
| 73 | + * field to be checked. | |
| 74 | + */ | |
| 47 | 75 | boolean isSupported(Field field); |
| 48 | 76 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/exception/ExceptionHandlerInterceptor.java
| ... | ... | @@ -57,6 +57,57 @@ import br.gov.frameworkdemoiselle.util.Beans; |
| 57 | 57 | import br.gov.frameworkdemoiselle.util.NameQualifier; |
| 58 | 58 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 59 | 59 | |
| 60 | +/** | |
| 61 | + * <p> | |
| 62 | + * Intercepts some thrown exceptions, and calls the appropriate method. These interceptor works only in | |
| 63 | + * classes annotated with <b>@Contoller</b>. Above we discribe which kind of exception is intercepted and | |
| 64 | + * what is an appropriate method. | |
| 65 | + * <p> | |
| 66 | + * To be interceptable, the thrown exception must be from a type which is annotated with | |
| 67 | + * <b>@ApplicationException</b>. | |
| 68 | + * <p> | |
| 69 | + * An appropriate method must be annotated with <b>@ExceptionHandler</b>, and receive as parameter some | |
| 70 | + * exception that could be thrown for it's class (which have to be annotated with <b>@ApplicationException</b>). | |
| 71 | + * So, when this method is called, it's receive the thrown exception as parameter. In the same class shouldn't | |
| 72 | + * be more than one method annotated with <b>@ExceptionHandler</b> and receiving the same type of exception. | |
| 73 | + * <p> | |
| 74 | + * <p> | |
| 75 | + * The examples below shows how these interceptor works: | |
| 76 | + * <p> | |
| 77 | + * | |
| 78 | + * <blockquote> | |
| 79 | + * | |
| 80 | + * <pre> | |
| 81 | + * @ApplicationException | |
| 82 | + * public class CustomException extends RuntimeException { | |
| 83 | + * } | |
| 84 | + * | |
| 85 | + * @Controller | |
| 86 | + * public class CustomExceptionHandler { | |
| 87 | + * | |
| 88 | + * public void throwException() { | |
| 89 | + * throw new CustomException(); | |
| 90 | + * } | |
| 91 | + * | |
| 92 | + * @ExceptionHandler | |
| 93 | + * public void handler(CustomException exception) { | |
| 94 | + * ... | |
| 95 | + * } | |
| 96 | + * | |
| 97 | + * } | |
| 98 | + * </pre> | |
| 99 | + * </blockquote> | |
| 100 | + * | |
| 101 | + * <p> | |
| 102 | + * When the method <b>throwException</b> throw a <b>CustomException</b>, once CustomException is annotated | |
| 103 | + * with @ApplicationException and CustomExceptionHandle is annotated with @Controller, the interceptor will | |
| 104 | + * looking for some method (in CustomExceptionHandle) annotated with @ExceptionHandle and that receive a | |
| 105 | + * CustomException as parameter to call. In the case shown, the method <b>handler</b> is called when a | |
| 106 | + * <b>CustomException</b> is thrown. | |
| 107 | + * <p> | |
| 108 | + * | |
| 109 | + * @author SERPRO | |
| 110 | + */ | |
| 60 | 111 | @Interceptor |
| 61 | 112 | @Controller |
| 62 | 113 | public class ExceptionHandlerInterceptor implements Serializable { |
| ... | ... | @@ -68,7 +119,7 @@ public class ExceptionHandlerInterceptor implements Serializable { |
| 68 | 119 | private static transient Logger logger; |
| 69 | 120 | |
| 70 | 121 | private final Map<Class<?>, Map<Class<?>, Method>> cache = new HashMap<Class<?>, Map<Class<?>, Method>>(); |
| 71 | - | |
| 122 | + | |
| 72 | 123 | private boolean handleException(final Exception cause, final Object target) throws Exception { |
| 73 | 124 | getLogger().info(getBundle().getString("handling-exception", cause.getClass().getCanonicalName())); |
| 74 | 125 | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/AbstractLifecycleBootstrap.java
| ... | ... | @@ -41,7 +41,6 @@ import java.util.ArrayList; |
| 41 | 41 | import java.util.Collections; |
| 42 | 42 | import java.util.Iterator; |
| 43 | 43 | import java.util.List; |
| 44 | -import java.util.Locale; | |
| 45 | 44 | |
| 46 | 45 | import javax.enterprise.context.ConversationScoped; |
| 47 | 46 | import javax.enterprise.context.RequestScoped; |
| ... | ... | @@ -60,7 +59,8 @@ import br.gov.frameworkdemoiselle.annotation.ViewScoped; |
| 60 | 59 | import br.gov.frameworkdemoiselle.internal.context.ContextManager; |
| 61 | 60 | import br.gov.frameworkdemoiselle.internal.context.ThreadLocalContext; |
| 62 | 61 | import br.gov.frameworkdemoiselle.internal.implementation.AnnotatedMethodProcessor; |
| 63 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
| 62 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 63 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | |
| 64 | 64 | import br.gov.frameworkdemoiselle.util.Reflections; |
| 65 | 65 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 66 | 66 | |
| ... | ... | @@ -74,16 +74,16 @@ public abstract class AbstractLifecycleBootstrap<A extends Annotation> implement |
| 74 | 74 | |
| 75 | 75 | private boolean registered = false; |
| 76 | 76 | |
| 77 | - private ResourceBundle bundle; | |
| 77 | + private transient static ResourceBundle bundle; | |
| 78 | 78 | |
| 79 | 79 | protected abstract Logger getLogger(); |
| 80 | 80 | |
| 81 | - protected ResourceBundle getBundle() { | |
| 82 | - if (this.bundle == null) { | |
| 83 | - this.bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); | |
| 81 | + protected static ResourceBundle getBundle() { | |
| 82 | + if (bundle == null) { | |
| 83 | + bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); | |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - return this.bundle; | |
| 86 | + return bundle; | |
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | protected <T> AnnotatedMethodProcessor<T> newProcessorInstance(AnnotatedMethod<T> annotatedMethod) { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/CoreBootstrap.java
| ... | ... | @@ -52,7 +52,6 @@ import br.gov.frameworkdemoiselle.annotation.StaticScoped; |
| 52 | 52 | import br.gov.frameworkdemoiselle.internal.context.ContextManager; |
| 53 | 53 | import br.gov.frameworkdemoiselle.internal.context.StaticContext; |
| 54 | 54 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| 55 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
| 56 | 55 | import br.gov.frameworkdemoiselle.util.Beans; |
| 57 | 56 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 58 | 57 | |
| ... | ... | @@ -60,7 +59,7 @@ public class CoreBootstrap implements Extension { |
| 60 | 59 | |
| 61 | 60 | private Logger logger; |
| 62 | 61 | |
| 63 | - private ResourceBundle bundle; | |
| 62 | + private static transient ResourceBundle bundle; | |
| 64 | 63 | |
| 65 | 64 | private Logger getLogger() { |
| 66 | 65 | if (this.logger == null) { |
| ... | ... | @@ -70,12 +69,12 @@ public class CoreBootstrap implements Extension { |
| 70 | 69 | return this.logger; |
| 71 | 70 | } |
| 72 | 71 | |
| 73 | - private ResourceBundle getBundle() { | |
| 74 | - if (this.bundle == null) { | |
| 75 | - this.bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); | |
| 72 | + private static ResourceBundle getBundle() { | |
| 73 | + if (bundle == null) { | |
| 74 | + bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | |
| 76 | 75 | } |
| 77 | 76 | |
| 78 | - return this.bundle; | |
| 77 | + return bundle; | |
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | public void engineOn(@Observes final BeforeBeanDiscovery event, BeanManager beanManager) { |
| ... | ... | @@ -91,7 +90,7 @@ public class CoreBootstrap implements Extension { |
| 91 | 90 | |
| 92 | 91 | ContextManager.activate(StaticContext.class, StaticScoped.class); |
| 93 | 92 | } |
| 94 | - | |
| 93 | + | |
| 95 | 94 | public void terminateCustomContexts(@Observes final BeforeShutdown event) { |
| 96 | 95 | ContextManager.shutdown(); |
| 97 | 96 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/bootstrap/ManagementBootstrap.java
| ... | ... | @@ -48,7 +48,7 @@ public class ManagementBootstrap implements Extension { |
| 48 | 48 | |
| 49 | 49 | @SuppressWarnings("unchecked") |
| 50 | 50 | public void registerAvailableManagedTypes(@Observes final AfterDeploymentValidation event, BeanManager beanManager) { |
| 51 | - ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); | |
| 51 | + ResourceBundle bundle = new ResourceBundleProducer().create("demoiselle-core-bundle", Locale.getDefault()); | |
| 52 | 52 | |
| 53 | 53 | Management monitoringManager = Beans.getReference(Management.class); |
| 54 | 54 | for (AnnotatedType<?> type : types) { | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/context/ContextManager.java
| ... | ... | @@ -16,7 +16,6 @@ import org.slf4j.Logger; |
| 16 | 16 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 17 | 17 | import br.gov.frameworkdemoiselle.annotation.StaticScoped; |
| 18 | 18 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| 19 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
| 20 | 19 | import br.gov.frameworkdemoiselle.util.Beans; |
| 21 | 20 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 22 | 21 | |
| ... | ... | @@ -40,14 +39,14 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 40 | 39 | * |
| 41 | 40 | * @author serpro |
| 42 | 41 | */ |
| 43 | -public class ContextManager { | |
| 42 | +public final class ContextManager { | |
| 44 | 43 | |
| 45 | 44 | private static List<CustomContextCounter> contexts = Collections |
| 46 | 45 | .synchronizedList(new ArrayList<CustomContextCounter>()); |
| 47 | 46 | |
| 48 | 47 | private static boolean initialized = false; |
| 49 | 48 | |
| 50 | - private static ResourceBundle bundle; | |
| 49 | + private static transient ResourceBundle bundle; | |
| 51 | 50 | |
| 52 | 51 | private static Logger logger; |
| 53 | 52 | |
| ... | ... | @@ -217,7 +216,7 @@ public class ContextManager { |
| 217 | 216 | |
| 218 | 217 | static ResourceBundle getBundle() { |
| 219 | 218 | if (bundle == null) { |
| 220 | - bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); | |
| 219 | + bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | |
| 221 | 220 | } |
| 222 | 221 | |
| 223 | 222 | return bundle; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/AnnotatedMethodProcessor.java
| ... | ... | @@ -37,7 +37,6 @@ |
| 37 | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
| 38 | 38 | |
| 39 | 39 | import java.lang.reflect.InvocationTargetException; |
| 40 | -import java.util.Locale; | |
| 41 | 40 | |
| 42 | 41 | import javax.enterprise.inject.spi.AnnotatedMethod; |
| 43 | 42 | |
| ... | ... | @@ -46,9 +45,9 @@ import org.slf4j.Logger; |
| 46 | 45 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 47 | 46 | import br.gov.frameworkdemoiselle.exception.ApplicationException; |
| 48 | 47 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| 49 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
| 50 | 48 | import br.gov.frameworkdemoiselle.message.SeverityType; |
| 51 | 49 | import br.gov.frameworkdemoiselle.util.Beans; |
| 50 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | |
| 52 | 51 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 53 | 52 | |
| 54 | 53 | /** |
| ... | ... | @@ -61,7 +60,7 @@ public class AnnotatedMethodProcessor<T> implements Comparable<AnnotatedMethodPr |
| 61 | 60 | |
| 62 | 61 | private AnnotatedMethod<T> annotatedMethod; |
| 63 | 62 | |
| 64 | - private ResourceBundle bundle; | |
| 63 | + private transient static ResourceBundle bundle; | |
| 65 | 64 | |
| 66 | 65 | public AnnotatedMethodProcessor(final AnnotatedMethod<T> annotatedMethod) { |
| 67 | 66 | this.annotatedMethod = annotatedMethod; |
| ... | ... | @@ -132,9 +131,9 @@ public class AnnotatedMethodProcessor<T> implements Comparable<AnnotatedMethodPr |
| 132 | 131 | return priority; |
| 133 | 132 | } |
| 134 | 133 | |
| 135 | - protected ResourceBundle getBundle() { | |
| 136 | - if (this.bundle == null) { | |
| 137 | - this.bundle = ResourceBundleProducer.create("demoiselle-core-bundle", Locale.getDefault()); | |
| 134 | + protected static ResourceBundle getBundle() { | |
| 135 | + if (bundle == null) { | |
| 136 | + bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); | |
| 138 | 137 | } |
| 139 | 138 | |
| 140 | 139 | return bundle; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthenticator.java
| ... | ... | @@ -42,10 +42,11 @@ import java.security.Principal; |
| 42 | 42 | |
| 43 | 43 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 44 | 44 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 45 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
| 46 | 45 | import br.gov.frameworkdemoiselle.security.AuthenticationException; |
| 47 | 46 | import br.gov.frameworkdemoiselle.security.Authenticator; |
| 48 | 47 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
| 48 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 49 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | |
| 49 | 50 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 50 | 51 | |
| 51 | 52 | /** |
| ... | ... | @@ -59,7 +60,7 @@ public class DefaultAuthenticator implements Authenticator { |
| 59 | 60 | |
| 60 | 61 | private static final long serialVersionUID = 1L; |
| 61 | 62 | |
| 62 | - private static ResourceBundle bundle; | |
| 63 | + private transient static ResourceBundle bundle; | |
| 63 | 64 | |
| 64 | 65 | /** |
| 65 | 66 | * @see br.gov.frameworkdemoiselle.security.Authenticator#authenticate() |
| ... | ... | @@ -92,7 +93,7 @@ public class DefaultAuthenticator implements Authenticator { |
| 92 | 93 | |
| 93 | 94 | private static ResourceBundle getBundle() { |
| 94 | 95 | if (bundle == null) { |
| 95 | - bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | |
| 96 | + bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); | |
| 96 | 97 | } |
| 97 | 98 | |
| 98 | 99 | return bundle; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultAuthorizer.java
| ... | ... | @@ -39,9 +39,10 @@ package br.gov.frameworkdemoiselle.internal.implementation; |
| 39 | 39 | import static br.gov.frameworkdemoiselle.annotation.Priority.L1_PRIORITY; |
| 40 | 40 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 41 | 41 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 42 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
| 43 | 42 | import br.gov.frameworkdemoiselle.security.Authorizer; |
| 44 | 43 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
| 44 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 45 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | |
| 45 | 46 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 46 | 47 | |
| 47 | 48 | /** |
| ... | ... | @@ -55,7 +56,7 @@ public class DefaultAuthorizer implements Authorizer { |
| 55 | 56 | |
| 56 | 57 | private static final long serialVersionUID = 1L; |
| 57 | 58 | |
| 58 | - private static ResourceBundle bundle; | |
| 59 | + private transient static ResourceBundle bundle; | |
| 59 | 60 | |
| 60 | 61 | @Override |
| 61 | 62 | public boolean hasRole(String role) { |
| ... | ... | @@ -74,7 +75,7 @@ public class DefaultAuthorizer implements Authorizer { |
| 74 | 75 | |
| 75 | 76 | private static ResourceBundle getBundle() { |
| 76 | 77 | if (bundle == null) { |
| 77 | - bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | |
| 78 | + bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); | |
| 78 | 79 | } |
| 79 | 80 | |
| 80 | 81 | return bundle; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/DefaultTransaction.java
| ... | ... | @@ -39,9 +39,10 @@ package br.gov.frameworkdemoiselle.internal.implementation; |
| 39 | 39 | import static br.gov.frameworkdemoiselle.annotation.Priority.L1_PRIORITY; |
| 40 | 40 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 41 | 41 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 42 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
| 43 | 42 | import br.gov.frameworkdemoiselle.transaction.Transaction; |
| 44 | 43 | import br.gov.frameworkdemoiselle.transaction.Transactional; |
| 44 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 45 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | |
| 45 | 46 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 46 | 47 | |
| 47 | 48 | /** |
| ... | ... | @@ -55,7 +56,7 @@ public class DefaultTransaction implements Transaction { |
| 55 | 56 | |
| 56 | 57 | private static final long serialVersionUID = 1L; |
| 57 | 58 | |
| 58 | - private static ResourceBundle bundle; | |
| 59 | + private transient static ResourceBundle bundle; | |
| 59 | 60 | |
| 60 | 61 | @Override |
| 61 | 62 | public void begin() { |
| ... | ... | @@ -94,7 +95,7 @@ public class DefaultTransaction implements Transaction { |
| 94 | 95 | |
| 95 | 96 | private static ResourceBundle getBundle() { |
| 96 | 97 | if (bundle == null) { |
| 97 | - bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | |
| 98 | + bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); | |
| 98 | 99 | } |
| 99 | 100 | |
| 100 | 101 | return bundle; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/MessageContextImpl.java
| ... | ... | @@ -37,19 +37,19 @@ |
| 37 | 37 | package br.gov.frameworkdemoiselle.internal.implementation; |
| 38 | 38 | |
| 39 | 39 | import java.io.Serializable; |
| 40 | -import java.util.ArrayList; | |
| 41 | 40 | import java.util.List; |
| 42 | 41 | |
| 43 | 42 | import org.slf4j.Logger; |
| 44 | 43 | |
| 44 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 45 | 45 | import br.gov.frameworkdemoiselle.internal.producer.LoggerProducer; |
| 46 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
| 47 | 46 | import br.gov.frameworkdemoiselle.message.DefaultMessage; |
| 48 | 47 | import br.gov.frameworkdemoiselle.message.Message; |
| 49 | 48 | import br.gov.frameworkdemoiselle.message.MessageAppender; |
| 50 | 49 | import br.gov.frameworkdemoiselle.message.MessageContext; |
| 51 | 50 | import br.gov.frameworkdemoiselle.message.SeverityType; |
| 52 | 51 | import br.gov.frameworkdemoiselle.util.Beans; |
| 52 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | |
| 53 | 53 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 54 | 54 | |
| 55 | 55 | /** |
| ... | ... | @@ -61,9 +61,6 @@ public class MessageContextImpl implements Serializable, MessageContext { |
| 61 | 61 | |
| 62 | 62 | private static final long serialVersionUID = 1L; |
| 63 | 63 | |
| 64 | - @Deprecated | |
| 65 | - private transient final List<Message> messages = new ArrayList<Message>(); | |
| 66 | - | |
| 67 | 64 | private transient static ResourceBundle bundle; |
| 68 | 65 | |
| 69 | 66 | private transient static Logger logger; |
| ... | ... | @@ -101,19 +98,22 @@ public class MessageContextImpl implements Serializable, MessageContext { |
| 101 | 98 | @Override |
| 102 | 99 | @Deprecated |
| 103 | 100 | public List<Message> getMessages() { |
| 104 | - return messages; | |
| 101 | + throw new DemoiselleException( | |
| 102 | + "Este método não é mais suportado desde a versão 2.4.0 do Demoiselle Framework. Considere atualizar a sua aplicação ou o componente com uma nova versão que faça uso do " | |
| 103 | + + MessageAppender.class.getCanonicalName() + "."); | |
| 105 | 104 | } |
| 106 | 105 | |
| 107 | 106 | @Override |
| 108 | 107 | @Deprecated |
| 109 | 108 | public void clear() { |
| 110 | - getLogger().debug(getBundle().getString("cleaning-message-context")); | |
| 111 | - messages.clear(); | |
| 109 | + throw new DemoiselleException( | |
| 110 | + "Este método não é mais suportado desde a versão 2.4.0 do Demoiselle Framework. Considere atualizar a sua aplicação ou o componente com uma nova versão que faça uso do " | |
| 111 | + + MessageAppender.class.getCanonicalName() + "."); | |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | private static ResourceBundle getBundle() { |
| 115 | 115 | if (bundle == null) { |
| 116 | - bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | |
| 116 | + bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); | |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | return bundle; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/SecurityContextImpl.java
| ... | ... | @@ -43,7 +43,6 @@ import javax.inject.Named; |
| 43 | 43 | |
| 44 | 44 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 45 | 45 | import br.gov.frameworkdemoiselle.internal.configuration.SecurityConfig; |
| 46 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
| 47 | 46 | import br.gov.frameworkdemoiselle.security.AfterLoginSuccessful; |
| 48 | 47 | import br.gov.frameworkdemoiselle.security.AfterLogoutSuccessful; |
| 49 | 48 | import br.gov.frameworkdemoiselle.security.AuthenticationException; |
| ... | ... | @@ -53,6 +52,7 @@ import br.gov.frameworkdemoiselle.security.NotLoggedInException; |
| 53 | 52 | import br.gov.frameworkdemoiselle.security.SecurityContext; |
| 54 | 53 | import br.gov.frameworkdemoiselle.security.User; |
| 55 | 54 | import br.gov.frameworkdemoiselle.util.Beans; |
| 55 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | |
| 56 | 56 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 57 | 57 | |
| 58 | 58 | /** |
| ... | ... | @@ -66,6 +66,8 @@ public class SecurityContextImpl implements SecurityContext { |
| 66 | 66 | |
| 67 | 67 | private static final long serialVersionUID = 1L; |
| 68 | 68 | |
| 69 | + private transient static ResourceBundle bundle; | |
| 70 | + | |
| 69 | 71 | private Authenticator authenticator; |
| 70 | 72 | |
| 71 | 73 | private Authorizer authorizer; |
| ... | ... | @@ -199,11 +201,18 @@ public class SecurityContextImpl implements SecurityContext { |
| 199 | 201 | |
| 200 | 202 | public void checkLoggedIn() throws NotLoggedInException { |
| 201 | 203 | if (!isLoggedIn()) { |
| 202 | - ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | |
| 203 | - throw new NotLoggedInException(bundle.getString("user-not-authenticated")); | |
| 204 | + throw new NotLoggedInException(getBundle().getString("user-not-authenticated")); | |
| 204 | 205 | } |
| 205 | 206 | } |
| 206 | 207 | |
| 208 | + private static ResourceBundle getBundle() { | |
| 209 | + if (bundle == null) { | |
| 210 | + bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); | |
| 211 | + } | |
| 212 | + | |
| 213 | + return bundle; | |
| 214 | + } | |
| 215 | + | |
| 207 | 216 | private static class EmptyUser implements Principal, Serializable { |
| 208 | 217 | |
| 209 | 218 | private static final long serialVersionUID = 1L; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/implementation/StrategySelector.java
| ... | ... | @@ -50,27 +50,19 @@ import javax.enterprise.inject.spi.Bean; |
| 50 | 50 | |
| 51 | 51 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 52 | 52 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 53 | -import br.gov.frameworkdemoiselle.internal.producer.ResourceBundleProducer; | |
| 54 | 53 | import br.gov.frameworkdemoiselle.util.Beans; |
| 54 | +import br.gov.frameworkdemoiselle.util.NameQualifier; | |
| 55 | 55 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 56 | 56 | |
| 57 | 57 | public final class StrategySelector implements Serializable { |
| 58 | 58 | |
| 59 | 59 | private static final long serialVersionUID = 1L; |
| 60 | 60 | |
| 61 | - private static ResourceBundle bundle; | |
| 61 | + private transient static ResourceBundle bundle; | |
| 62 | 62 | |
| 63 | 63 | private StrategySelector() { |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - private static ResourceBundle getBundle() { | |
| 67 | - if (bundle == null) { | |
| 68 | - bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | |
| 69 | - } | |
| 70 | - | |
| 71 | - return bundle; | |
| 72 | - } | |
| 73 | - | |
| 74 | 66 | @SuppressWarnings("unchecked") |
| 75 | 67 | public static <T> T selectInstance(Class<T> type, Collection<? extends T> options) { |
| 76 | 68 | |
| ... | ... | @@ -162,4 +154,12 @@ public final class StrategySelector implements Serializable { |
| 162 | 154 | |
| 163 | 155 | return result; |
| 164 | 156 | } |
| 157 | + | |
| 158 | + private static ResourceBundle getBundle() { | |
| 159 | + if (bundle == null) { | |
| 160 | + bundle = Beans.getReference(ResourceBundle.class, new NameQualifier("demoiselle-core-bundle")); | |
| 161 | + } | |
| 162 | + | |
| 163 | + return bundle; | |
| 164 | + } | |
| 165 | 165 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/ManagedType.java
| ... | ... | @@ -77,7 +77,7 @@ public class ManagedType { |
| 77 | 77 | private String description; |
| 78 | 78 | |
| 79 | 79 | public ManagedType(Class<?> type) { |
| 80 | - bundle = ResourceBundleProducer.create("demoiselle-core-bundle"); | |
| 80 | + bundle = new ResourceBundleProducer().create("demoiselle-core-bundle"); | |
| 81 | 81 | |
| 82 | 82 | if (type == null) { |
| 83 | 83 | throw new DemoiselleException(bundle.getString("management-null-class-defined")); | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/management/Management.java
| ... | ... | @@ -36,6 +36,7 @@ |
| 36 | 36 | */ |
| 37 | 37 | package br.gov.frameworkdemoiselle.internal.management; |
| 38 | 38 | |
| 39 | +import java.io.Serializable; | |
| 39 | 40 | import java.lang.reflect.Method; |
| 40 | 41 | import java.util.ArrayList; |
| 41 | 42 | import java.util.Collection; |
| ... | ... | @@ -73,7 +74,9 @@ import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 73 | 74 | * @author serpro |
| 74 | 75 | */ |
| 75 | 76 | @ApplicationScoped |
| 76 | -public class Management { | |
| 77 | +public class Management implements Serializable { | |
| 78 | + | |
| 79 | + private static final long serialVersionUID = 1L; | |
| 77 | 80 | |
| 78 | 81 | @Inject |
| 79 | 82 | private Logger logger; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/internal/producer/ResourceBundleProducer.java
| ... | ... | @@ -62,7 +62,8 @@ public class ResourceBundleProducer implements Serializable { |
| 62 | 62 | * @param String |
| 63 | 63 | * baseName |
| 64 | 64 | */ |
| 65 | - public static ResourceBundle create(String baseName) { | |
| 65 | + @Deprecated | |
| 66 | + public ResourceBundle create(String baseName) { | |
| 66 | 67 | return create(baseName, Beans.getReference(Locale.class)); |
| 67 | 68 | } |
| 68 | 69 | |
| ... | ... | @@ -72,7 +73,8 @@ public class ResourceBundleProducer implements Serializable { |
| 72 | 73 | * @param String |
| 73 | 74 | * baseName |
| 74 | 75 | */ |
| 75 | - public static ResourceBundle create(String baseName, Locale locale) { | |
| 76 | + @Deprecated | |
| 77 | + public ResourceBundle create(String baseName, Locale locale) { | |
| 76 | 78 | return new ResourceBundle(baseName, locale); |
| 77 | 79 | } |
| 78 | 80 | |
| ... | ... | @@ -83,7 +85,7 @@ public class ResourceBundleProducer implements Serializable { |
| 83 | 85 | @Default |
| 84 | 86 | @Produces |
| 85 | 87 | public ResourceBundle createDefault(InjectionPoint ip) { |
| 86 | - return create("messages", Beans.getReference(Locale.class)); | |
| 88 | + return new ResourceBundle("messages", Beans.getReference(Locale.class)); | |
| 87 | 89 | } |
| 88 | 90 | |
| 89 | 91 | /** |
| ... | ... | @@ -94,6 +96,6 @@ public class ResourceBundleProducer implements Serializable { |
| 94 | 96 | @Produces |
| 95 | 97 | public ResourceBundle createNamed(InjectionPoint ip) { |
| 96 | 98 | String baseName = ip.getAnnotated().getAnnotation(Name.class).value(); |
| 97 | - return create(baseName, Beans.getReference(Locale.class)); | |
| 99 | + return new ResourceBundle(baseName, Beans.getReference(Locale.class)); | |
| 98 | 100 | } |
| 99 | 101 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/lifecycle/AfterShutdownProccess.java
| ... | ... | @@ -36,6 +36,11 @@ |
| 36 | 36 | */ |
| 37 | 37 | package br.gov.frameworkdemoiselle.lifecycle; |
| 38 | 38 | |
| 39 | +/** | |
| 40 | + * This interface represents an event that is fired when the shutdown process is finalized. | |
| 41 | + * | |
| 42 | + * @author SERPRO | |
| 43 | + */ | |
| 39 | 44 | public interface AfterShutdownProccess { |
| 40 | 45 | |
| 41 | 46 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/lifecycle/AfterStartupProccess.java
| ... | ... | @@ -36,6 +36,11 @@ |
| 36 | 36 | */ |
| 37 | 37 | package br.gov.frameworkdemoiselle.lifecycle; |
| 38 | 38 | |
| 39 | +/** | |
| 40 | + * This interface represents an event that is fired when the start up process is finalized. | |
| 41 | + * | |
| 42 | + * @author SERPRO | |
| 43 | + */ | |
| 39 | 44 | public interface AfterStartupProccess { |
| 40 | 45 | |
| 41 | 46 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/AttributeChangeNotification.java
| ... | ... | @@ -40,24 +40,40 @@ package br.gov.frameworkdemoiselle.management; |
| 40 | 40 | * Special notification to denote an attribute has changed values. |
| 41 | 41 | * |
| 42 | 42 | * @see GenericNotification |
| 43 | - * | |
| 44 | 43 | * @author serpro |
| 45 | - * | |
| 46 | 44 | */ |
| 47 | 45 | public class AttributeChangeNotification extends GenericNotification { |
| 48 | - | |
| 46 | + | |
| 49 | 47 | private String attributeName; |
| 50 | - | |
| 48 | + | |
| 51 | 49 | private Class<? extends Object> attributeType; |
| 52 | - | |
| 50 | + | |
| 53 | 51 | private Object oldValue; |
| 54 | - | |
| 52 | + | |
| 55 | 53 | private Object newValue; |
| 56 | - | |
| 57 | - public AttributeChangeNotification(){} | |
| 58 | - | |
| 59 | - public AttributeChangeNotification(Object message, String attributeName, Class<? extends Object> attributeType, Object oldValue, | |
| 60 | - Object newValue) { | |
| 54 | + | |
| 55 | + /** | |
| 56 | + * Constructor without params. | |
| 57 | + */ | |
| 58 | + public AttributeChangeNotification() { | |
| 59 | + } | |
| 60 | + | |
| 61 | + /** | |
| 62 | + * Set all the class attibutes, according to the parameters received. | |
| 63 | + * | |
| 64 | + * @param message | |
| 65 | + * message to be displayed. | |
| 66 | + * @param attributeName | |
| 67 | + * name of the monitored attribute. | |
| 68 | + * @param attributeType | |
| 69 | + * type of the monitored attribute. | |
| 70 | + * @param oldValue | |
| 71 | + * old value of the monitored attribute. | |
| 72 | + * @param newValue | |
| 73 | + * new value for the monitored attribute. | |
| 74 | + */ | |
| 75 | + public AttributeChangeNotification(Object message, String attributeName, Class<? extends Object> attributeType, | |
| 76 | + Object oldValue, Object newValue) { | |
| 61 | 77 | super(message); |
| 62 | 78 | this.attributeName = attributeName; |
| 63 | 79 | this.attributeType = attributeType; |
| ... | ... | @@ -65,46 +81,36 @@ public class AttributeChangeNotification extends GenericNotification { |
| 65 | 81 | this.newValue = newValue; |
| 66 | 82 | } |
| 67 | 83 | |
| 68 | - | |
| 69 | 84 | public String getAttributeName() { |
| 70 | 85 | return attributeName; |
| 71 | 86 | } |
| 72 | 87 | |
| 73 | - | |
| 74 | 88 | public void setAttributeName(String attributeName) { |
| 75 | 89 | this.attributeName = attributeName; |
| 76 | 90 | } |
| 77 | 91 | |
| 78 | - | |
| 79 | 92 | public Class<? extends Object> getAttributeType() { |
| 80 | 93 | return attributeType; |
| 81 | 94 | } |
| 82 | 95 | |
| 83 | - | |
| 84 | 96 | public void setAttributeType(Class<? extends Object> attributeType) { |
| 85 | 97 | this.attributeType = attributeType; |
| 86 | 98 | } |
| 87 | 99 | |
| 88 | - | |
| 89 | 100 | public Object getOldValue() { |
| 90 | 101 | return oldValue; |
| 91 | 102 | } |
| 92 | 103 | |
| 93 | - | |
| 94 | 104 | public void setOldValue(Object oldValue) { |
| 95 | 105 | this.oldValue = oldValue; |
| 96 | 106 | } |
| 97 | 107 | |
| 98 | - | |
| 99 | 108 | public Object getNewValue() { |
| 100 | 109 | return newValue; |
| 101 | 110 | } |
| 102 | 111 | |
| 103 | - | |
| 104 | 112 | public void setNewValue(Object newValue) { |
| 105 | 113 | this.newValue = newValue; |
| 106 | 114 | } |
| 107 | - | |
| 108 | - | |
| 109 | 115 | |
| 110 | 116 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/management/GenericNotification.java
| ... | ... | @@ -37,40 +37,44 @@ |
| 37 | 37 | package br.gov.frameworkdemoiselle.management; |
| 38 | 38 | |
| 39 | 39 | /** |
| 40 | - * | |
| 41 | 40 | * Notification that can be sent by the {@link NotificationManager}. |
| 42 | 41 | * |
| 43 | 42 | * @author serpro |
| 44 | - * | |
| 45 | 43 | */ |
| 46 | 44 | public class GenericNotification { |
| 47 | - | |
| 45 | + | |
| 48 | 46 | private Object message; |
| 49 | - | |
| 50 | - public GenericNotification(){ | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * Constructor without params. | |
| 50 | + */ | |
| 51 | + public GenericNotification() { | |
| 51 | 52 | } |
| 52 | - | |
| 53 | + | |
| 54 | + /** | |
| 55 | + * Constructor with message to notification. | |
| 56 | + * | |
| 57 | + * @param message | |
| 58 | + * message to notification. | |
| 59 | + */ | |
| 53 | 60 | public GenericNotification(Object message) { |
| 54 | 61 | super(); |
| 55 | 62 | this.message = message; |
| 56 | 63 | } |
| 57 | 64 | |
| 58 | - | |
| 59 | 65 | public Object getMessage() { |
| 60 | 66 | return message; |
| 61 | 67 | } |
| 62 | 68 | |
| 63 | - | |
| 64 | 69 | public void setMessage(Object message) { |
| 65 | 70 | this.message = message; |
| 66 | 71 | } |
| 67 | 72 | |
| 68 | - | |
| 69 | 73 | public Class<? extends Object> getType() { |
| 70 | - if (message!=null){ | |
| 74 | + if (message != null) { | |
| 71 | 75 | return message.getClass(); |
| 72 | 76 | } |
| 73 | - | |
| 77 | + | |
| 74 | 78 | return null; |
| 75 | 79 | } |
| 76 | 80 | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/message/MessageAppender.java
| ... | ... | @@ -39,9 +39,18 @@ package br.gov.frameworkdemoiselle.message; |
| 39 | 39 | import java.io.Serializable; |
| 40 | 40 | |
| 41 | 41 | /** |
| 42 | + * Classes that will treat what to do with messages added to the context must implement this interface. | |
| 43 | + * | |
| 42 | 44 | * @author SERPRO |
| 43 | 45 | */ |
| 44 | 46 | public interface MessageAppender extends Serializable { |
| 45 | - | |
| 47 | + | |
| 48 | + /** | |
| 49 | + * Method that must hold message in an appropriate way and in an appropriate local. | |
| 50 | + * Demoiselle holds a message in a Logger or in a FacesContext, depending on the project. | |
| 51 | + * | |
| 52 | + * @param message | |
| 53 | + * message to be stored. | |
| 54 | + */ | |
| 46 | 55 | void append(Message message); |
| 47 | 56 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/transaction/TransactionException.java
| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | -package br.gov.frameworkdemoiselle.transaction; | |
| 2 | - | |
| 3 | -import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 4 | - | |
| 5 | -public class TransactionException extends DemoiselleException { | |
| 6 | - | |
| 7 | - private static final long serialVersionUID = 1L; | |
| 8 | - | |
| 9 | - public TransactionException(Throwable cause) { | |
| 10 | - super(cause); | |
| 11 | - } | |
| 12 | -} |
impl/core/src/main/java/br/gov/frameworkdemoiselle/transaction/TransactionalInterceptor.java
| ... | ... | @@ -189,7 +189,7 @@ public class TransactionalInterceptor implements Serializable { |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | @RequestScoped |
| 192 | - static class TransactionInfo implements Serializable { | |
| 192 | + public static class TransactionInfo implements Serializable { | |
| 193 | 193 | |
| 194 | 194 | private static final long serialVersionUID = 1L; |
| 195 | 195 | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Beans.java
| ... | ... | @@ -52,6 +52,14 @@ import javax.enterprise.inject.spi.InjectionPoint; |
| 52 | 52 | |
| 53 | 53 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 54 | 54 | |
| 55 | +/** | |
| 56 | + * <p> | |
| 57 | + * Utilizes a {@link BeanManager}, obtained in the bootstrap process, to provide custom operations for obtaining contextual references for beans. | |
| 58 | + * <p> | |
| 59 | + * All its public methods are static. | |
| 60 | + * | |
| 61 | + * @author SERPRO | |
| 62 | + */ | |
| 55 | 63 | public final class Beans { |
| 56 | 64 | |
| 57 | 65 | private static transient ResourceBundle bundle; |
| ... | ... | @@ -69,6 +77,20 @@ public final class Beans { |
| 69 | 77 | return manager; |
| 70 | 78 | } |
| 71 | 79 | |
| 80 | + /** | |
| 81 | + * Obtains a injectble instance of a bean, which have the given required type and qualifiers, | |
| 82 | + * and are available for injection in the point where this method was call. | |
| 83 | + * | |
| 84 | + * @param beanClass | |
| 85 | + * the beanClass which instace is requested to be obtained. | |
| 86 | + * @param qualifiers | |
| 87 | + * a set of qualifiers with any quantity of elements (zero including). | |
| 88 | + * @return Type | |
| 89 | + * a instace of the injected beanClass. | |
| 90 | + * @throws DemoiselleException | |
| 91 | + * if no bean are avaliable to be injected for the given Class and qualifiers. | |
| 92 | + * | |
| 93 | + */ | |
| 72 | 94 | public static <T> T getReference(final Class<T> beanClass, Annotation... qualifiers) { |
| 73 | 95 | T instance; |
| 74 | 96 | |
| ... | ... | @@ -91,6 +113,18 @@ public final class Beans { |
| 91 | 113 | return instance; |
| 92 | 114 | } |
| 93 | 115 | |
| 116 | + /** | |
| 117 | + * Obtains a injectble instance of a bean, which have the given required type | |
| 118 | + * and are available for injection in the point where this method was call. | |
| 119 | + * | |
| 120 | + * @param beanClass | |
| 121 | + * the beanClass which instace is requested to be obtained. | |
| 122 | + * @return Type | |
| 123 | + * a instace of the injected beanClass. | |
| 124 | + * @throws DemoiselleException | |
| 125 | + * if no bean are avaliable to be injected for the given Class. | |
| 126 | + * | |
| 127 | + */ | |
| 94 | 128 | public static <T> T getReference(final Class<T> beanClass) { |
| 95 | 129 | T instance; |
| 96 | 130 | |
| ... | ... | @@ -105,6 +139,18 @@ public final class Beans { |
| 105 | 139 | return instance; |
| 106 | 140 | } |
| 107 | 141 | |
| 142 | + /** | |
| 143 | + * Obtains a injectble instance of a bean, which have the given EL name | |
| 144 | + * and are available for injection in the point where this method was call. | |
| 145 | + * | |
| 146 | + * @param beanName | |
| 147 | + * the EL name for the requested bean. | |
| 148 | + * @return Type | |
| 149 | + * a instace of the injected beanClass. | |
| 150 | + * @throws DemoiselleException | |
| 151 | + * if no bean are avaliable to be injected for the given bean name. | |
| 152 | + * | |
| 153 | + */ | |
| 108 | 154 | @SuppressWarnings("unchecked") |
| 109 | 155 | public static <T> T getReference(String beanName) { |
| 110 | 156 | T instance; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Exceptions.java
| ... | ... | @@ -38,15 +38,39 @@ package br.gov.frameworkdemoiselle.util; |
| 38 | 38 | |
| 39 | 39 | import br.gov.frameworkdemoiselle.exception.ApplicationException; |
| 40 | 40 | |
| 41 | +/** | |
| 42 | + *Class that offer tow methods that can help with manipulation of throwable exceptions. | |
| 43 | + * | |
| 44 | + * @author SERPRO | |
| 45 | + */ | |
| 41 | 46 | public final class Exceptions { |
| 42 | 47 | |
| 48 | + /** | |
| 49 | + * Constructor without parameters. | |
| 50 | + */ | |
| 43 | 51 | private Exceptions() { |
| 44 | 52 | } |
| 45 | 53 | |
| 54 | + /** | |
| 55 | + * Informs if a Throwable class is annotated with @ApplicationException or not. | |
| 56 | + * | |
| 57 | + * @param throwable | |
| 58 | + * a throwable object. | |
| 59 | + * | |
| 60 | + * @return a boolean, true if thowable is annotated with @ApplicationException, and false otherwise. | |
| 61 | + */ | |
| 46 | 62 | public static boolean isApplicationException(final Throwable throwable) { |
| 47 | 63 | return throwable != null && throwable.getClass().isAnnotationPresent(ApplicationException.class); |
| 48 | 64 | } |
| 49 | 65 | |
| 66 | + /** | |
| 67 | + * Receives as parameter any kind of Throwable objects, and throws a RuntimeException instead. | |
| 68 | + * | |
| 69 | + * @param throwable | |
| 70 | + * a throwable object. | |
| 71 | + * | |
| 72 | + * @throws RuntimeException throws this kind of exception every time that is called. | |
| 73 | + */ | |
| 50 | 74 | public static void handleToRuntimeException(final Throwable throwable) throws RuntimeException { |
| 51 | 75 | if (throwable instanceof RuntimeException) { |
| 52 | 76 | throw (RuntimeException) throwable; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/NameQualifier.java
| ... | ... | @@ -40,6 +40,15 @@ import javax.enterprise.util.AnnotationLiteral; |
| 40 | 40 | |
| 41 | 41 | import br.gov.frameworkdemoiselle.annotation.Name; |
| 42 | 42 | |
| 43 | +/** | |
| 44 | + * Creates a instance of an java annotation, specifically for qualification @Name. | |
| 45 | + * This is required to get some classes by calling Beans.getReference method. | |
| 46 | + * | |
| 47 | + * @see Beans | |
| 48 | + * @see Name | |
| 49 | + * | |
| 50 | + * @author SERPRO | |
| 51 | + */ | |
| 43 | 52 | @SuppressWarnings("all") |
| 44 | 53 | public class NameQualifier extends AnnotationLiteral<Name> implements Name { |
| 45 | 54 | |
| ... | ... | @@ -47,6 +56,12 @@ public class NameQualifier extends AnnotationLiteral<Name> implements Name { |
| 47 | 56 | |
| 48 | 57 | private final String value; |
| 49 | 58 | |
| 59 | + /** | |
| 60 | + * Constructor with string value of name qualifier. | |
| 61 | + * | |
| 62 | + * @param value | |
| 63 | + * value of name qualifier. | |
| 64 | + */ | |
| 50 | 65 | public NameQualifier(String value) { |
| 51 | 66 | this.value = value; |
| 52 | 67 | } | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Reflections.java
| ... | ... | @@ -47,11 +47,19 @@ import java.util.ArrayList; |
| 47 | 47 | import java.util.Arrays; |
| 48 | 48 | import java.util.List; |
| 49 | 49 | |
| 50 | +/** | |
| 51 | + * Provides some features to do some operations relating to java reflection. | |
| 52 | + * | |
| 53 | + * @author SERPRO | |
| 54 | + */ | |
| 50 | 55 | public final class Reflections { |
| 51 | 56 | |
| 52 | 57 | private Reflections() { |
| 53 | 58 | } |
| 54 | 59 | |
| 60 | + /** | |
| 61 | + * TODO | |
| 62 | + */ | |
| 55 | 63 | @SuppressWarnings("unchecked") |
| 56 | 64 | public static <T> Class<T> getGenericTypeArgument(final Class<?> clazz, final int idx) { |
| 57 | 65 | final Type type = clazz.getGenericSuperclass(); |
| ... | ... | @@ -66,6 +74,9 @@ public final class Reflections { |
| 66 | 74 | return (Class<T>) paramType.getActualTypeArguments()[idx]; |
| 67 | 75 | } |
| 68 | 76 | |
| 77 | + /** | |
| 78 | + * TODO | |
| 79 | + */ | |
| 69 | 80 | @SuppressWarnings("unchecked") |
| 70 | 81 | public static <T> Class<T> getGenericTypeArgument(final Field field, final int idx) { |
| 71 | 82 | final Type type = field.getGenericType(); |
| ... | ... | @@ -74,6 +85,9 @@ public final class Reflections { |
| 74 | 85 | return (Class<T>) paramType.getActualTypeArguments()[idx]; |
| 75 | 86 | } |
| 76 | 87 | |
| 88 | + /** | |
| 89 | + * TODO | |
| 90 | + */ | |
| 77 | 91 | public static <T> Class<T> getGenericTypeArgument(final Member member, final int idx) { |
| 78 | 92 | Class<T> result = null; |
| 79 | 93 | |
| ... | ... | @@ -86,11 +100,23 @@ public final class Reflections { |
| 86 | 100 | return result; |
| 87 | 101 | } |
| 88 | 102 | |
| 103 | + /** | |
| 104 | + * TODO | |
| 105 | + */ | |
| 89 | 106 | @SuppressWarnings("unchecked") |
| 90 | 107 | public static <T> Class<T> getGenericTypeArgument(final Method method, final int pos) { |
| 91 | 108 | return (Class<T>) method.getGenericParameterTypes()[pos]; |
| 92 | 109 | } |
| 93 | 110 | |
| 111 | + /** | |
| 112 | + * Returns the value contained in the given field. | |
| 113 | + * | |
| 114 | + * @param field | |
| 115 | + * field to be extracted the value. | |
| 116 | + * @param object | |
| 117 | + * object that contains the field. | |
| 118 | + * @return value of the field. | |
| 119 | + */ | |
| 94 | 120 | @SuppressWarnings("unchecked") |
| 95 | 121 | public static <T> T getFieldValue(Field field, Object object) { |
| 96 | 122 | T result = null; |
| ... | ... | @@ -108,6 +134,16 @@ public final class Reflections { |
| 108 | 134 | return result; |
| 109 | 135 | } |
| 110 | 136 | |
| 137 | + /** | |
| 138 | + * Sets a value in a field. | |
| 139 | + * | |
| 140 | + * @param field | |
| 141 | + * field to be setted. | |
| 142 | + * @param object | |
| 143 | + * object that contains the field. | |
| 144 | + * @param value | |
| 145 | + * value to be setted in the field. | |
| 146 | + */ | |
| 111 | 147 | public static void setFieldValue(Field field, Object object, Object value) { |
| 112 | 148 | try { |
| 113 | 149 | boolean acessible = field.isAccessible(); |
| ... | ... | @@ -120,6 +156,9 @@ public final class Reflections { |
| 120 | 156 | } |
| 121 | 157 | } |
| 122 | 158 | |
| 159 | + /** | |
| 160 | + * TODO | |
| 161 | + */ | |
| 123 | 162 | public static Field[] getNonStaticDeclaredFields(Class<?> type) { |
| 124 | 163 | List<Field> fields = new ArrayList<Field>(); |
| 125 | 164 | |
| ... | ... | @@ -134,6 +173,9 @@ public final class Reflections { |
| 134 | 173 | return fields.toArray(new Field[0]); |
| 135 | 174 | } |
| 136 | 175 | |
| 176 | + /** | |
| 177 | + * TODO | |
| 178 | + */ | |
| 137 | 179 | public static List<Field> getNonStaticFields(Class<?> type) { |
| 138 | 180 | List<Field> fields = new ArrayList<Field>(); |
| 139 | 181 | |
| ... | ... | @@ -145,10 +187,13 @@ public final class Reflections { |
| 145 | 187 | return fields; |
| 146 | 188 | } |
| 147 | 189 | |
| 148 | - public static <T> T instantiate(Class<T> clasz) { | |
| 190 | + /** | |
| 191 | + * TODO | |
| 192 | + */ | |
| 193 | + public static <T> T instantiate(Class<T> clazz) { | |
| 149 | 194 | T object = null; |
| 150 | 195 | try { |
| 151 | - object = clasz.newInstance(); | |
| 196 | + object = clazz.newInstance(); | |
| 152 | 197 | } catch (InstantiationException e) { |
| 153 | 198 | Exceptions.handleToRuntimeException(e); |
| 154 | 199 | } catch (IllegalAccessException e) { |
| ... | ... | @@ -157,14 +202,40 @@ public final class Reflections { |
| 157 | 202 | return object; |
| 158 | 203 | } |
| 159 | 204 | |
| 205 | + /** | |
| 206 | + * Verifies if a given class could be converted to a given type. | |
| 207 | + * | |
| 208 | + * @param clazz | |
| 209 | + * class to be checked. | |
| 210 | + * @param type | |
| 211 | + * type to be checked. | |
| 212 | + * @return {@link Boolean} | |
| 213 | + * true if the given class can be converted to a given type, and false otherwise. | |
| 214 | + */ | |
| 160 | 215 | public static boolean isOfType(Class<?> clazz, Class<?> type) { |
| 161 | 216 | return type.isAssignableFrom(clazz) && clazz != type; |
| 162 | 217 | } |
| 163 | 218 | |
| 219 | + /** | |
| 220 | + * Obtains the {@link ClassLoader} for the given class, from his canonical name. | |
| 221 | + * | |
| 222 | + * @param canonicalName | |
| 223 | + * canonical name of the the given class. | |
| 224 | + * @return {@link ClassLoader} | |
| 225 | + * ClassLoader for the given class. | |
| 226 | + */ | |
| 164 | 227 | public static ClassLoader getClassLoaderForClass(final String canonicalName) { |
| 165 | 228 | return Reflections.getClassLoaderForResource(canonicalName.replaceAll("\\.", "/") + ".class"); |
| 166 | 229 | } |
| 167 | 230 | |
| 231 | + /** | |
| 232 | + * Obtains the {@link ClassLoader} for the given resource. | |
| 233 | + * | |
| 234 | + * @param resource | |
| 235 | + * | |
| 236 | + * @return {@link ClassLoader} | |
| 237 | + * ClassLoader for the given resource. | |
| 238 | + */ | |
| 168 | 239 | public static ClassLoader getClassLoaderForResource(final String resource) { |
| 169 | 240 | final String stripped = resource.charAt(0) == '/' ? resource.substring(1) : resource; |
| 170 | 241 | |
| ... | ... | @@ -187,11 +258,17 @@ public final class Reflections { |
| 187 | 258 | return result; |
| 188 | 259 | } |
| 189 | 260 | |
| 261 | + /** | |
| 262 | + * TODO | |
| 263 | + */ | |
| 190 | 264 | public static URL getResourceAsURL(final String resource) { |
| 191 | 265 | ClassLoader classLoader = getClassLoaderForResource(resource); |
| 192 | 266 | return classLoader != null ? classLoader.getResource(resource) : null; |
| 193 | 267 | } |
| 194 | 268 | |
| 269 | + /** | |
| 270 | + * TODO | |
| 271 | + */ | |
| 195 | 272 | @SuppressWarnings("unchecked") |
| 196 | 273 | public static <T> Class<T> forName(final String className) throws ClassNotFoundException { |
| 197 | 274 | ClassLoader classLoader = getClassLoaderForClass(className); | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/ResourceBundle.java
| ... | ... | @@ -43,6 +43,12 @@ import java.util.Locale; |
| 43 | 43 | import java.util.MissingResourceException; |
| 44 | 44 | import java.util.Set; |
| 45 | 45 | |
| 46 | +/** | |
| 47 | + * The Demoiselle's ResourceBundle extends the abstraction java.util.ResourceBundle, | |
| 48 | + * and provide the locale and the base name for the bundle. | |
| 49 | + * | |
| 50 | + * @author SERPRO | |
| 51 | + */ | |
| 46 | 52 | public class ResourceBundle extends java.util.ResourceBundle implements Serializable { |
| 47 | 53 | |
| 48 | 54 | private static final long serialVersionUID = 1L; |
| ... | ... | @@ -67,6 +73,15 @@ public class ResourceBundle extends java.util.ResourceBundle implements Serializ |
| 67 | 73 | return delegate; |
| 68 | 74 | } |
| 69 | 75 | |
| 76 | + /** | |
| 77 | + * Constructor that set values of baseName and locale. | |
| 78 | + * | |
| 79 | + * @param baseName | |
| 80 | + * the base name to construct the complete bundle name. | |
| 81 | + * | |
| 82 | + * @param locale | |
| 83 | + * locale to define the choosen bundle. | |
| 84 | + */ | |
| 70 | 85 | public ResourceBundle(String baseName, Locale locale) { |
| 71 | 86 | this.baseName = baseName; |
| 72 | 87 | this.locale = locale; | ... | ... |
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Strings.java
| ... | ... | @@ -43,15 +43,41 @@ import java.util.regex.Pattern; |
| 43 | 43 | |
| 44 | 44 | import br.gov.frameworkdemoiselle.annotation.Ignore; |
| 45 | 45 | |
| 46 | +/** | |
| 47 | + * Contain a set of methods that implements a set of functionalities that envolves manipulation of strings. | |
| 48 | + * | |
| 49 | + * @author SERPRO | |
| 50 | + */ | |
| 46 | 51 | public final class Strings { |
| 47 | 52 | |
| 48 | 53 | private Strings() { |
| 49 | 54 | } |
| 50 | 55 | |
| 56 | + /** | |
| 57 | + * Returns if some string matches with the format of a ResourceBundle key or not. | |
| 58 | + * | |
| 59 | + * @param key | |
| 60 | + * string to check if matches with key format of ResourceBundle. | |
| 61 | + * | |
| 62 | + * @return boolean | |
| 63 | + * true if matches and false otherwise. | |
| 64 | + */ | |
| 51 | 65 | public static boolean isResourceBundleKeyFormat(final String key) { |
| 52 | 66 | return Pattern.matches("^\\{(.+)\\}$", key == null ? "" : key); |
| 53 | 67 | } |
| 54 | 68 | |
| 69 | + /** | |
| 70 | + * Removes specific characteres from a given string. | |
| 71 | + * | |
| 72 | + * @param string | |
| 73 | + * string to be changed, by the removing of some characters. | |
| 74 | + * | |
| 75 | + * @param chars | |
| 76 | + * characters to be removed from string. | |
| 77 | + * | |
| 78 | + * @return String | |
| 79 | + * returns the given string without the given characters. | |
| 80 | + */ | |
| 55 | 81 | public static String removeChars(String string, char... chars) { |
| 56 | 82 | String result = string; |
| 57 | 83 | |
| ... | ... | @@ -63,6 +89,20 @@ public final class Strings { |
| 63 | 89 | return result; |
| 64 | 90 | } |
| 65 | 91 | |
| 92 | + /** | |
| 93 | + * Inserts the character "0" in the begin of a given string. The quantity of zeros that will be placed | |
| 94 | + * depends on the difference between the length of the given string and the value of howMuchZeros. | |
| 95 | + * | |
| 96 | + * @param string | |
| 97 | + * string to insert zeros characthers. | |
| 98 | + * | |
| 99 | + * @param howMuchZeros | |
| 100 | + * its controls how much zeros will be insert. | |
| 101 | + * | |
| 102 | + * @return String | |
| 103 | + * Retuns the string, added with appropriate number of zeros. | |
| 104 | + * For exemplo, if string = "yes" and howMuchZeros = 5, the returned string will be "00yes". | |
| 105 | + */ | |
| 66 | 106 | public static String insertZeros(String string, int howMuchZeros) { |
| 67 | 107 | StringBuffer result = new StringBuffer((string == null ? "" : string).trim()); |
| 68 | 108 | int difference = howMuchZeros - result.toString().length(); |
| ... | ... | @@ -74,6 +114,22 @@ public final class Strings { |
| 74 | 114 | return result.toString(); |
| 75 | 115 | } |
| 76 | 116 | |
| 117 | + /** | |
| 118 | + * <p> | |
| 119 | + * Replaces the numbers between braces in the given string with the given parameters. | |
| 120 | + * The process will replace a number between braces for the parameter for which its order | |
| 121 | + * in the set of parameters matches with the number of the given string. | |
| 122 | + * <p> | |
| 123 | + * For exemple, if is received the following string "Treats an {0} exception" and the set of parameters | |
| 124 | + * {"DemoiselleException"}, the return will be the following string: "Treats an DemoiselleException exception". | |
| 125 | + * | |
| 126 | + * @param string | |
| 127 | + * with the numbers with braces to be replaced with the parameters. | |
| 128 | + * @param params | |
| 129 | + * parameters that will replace the number with braces in the given string. | |
| 130 | + * @return String | |
| 131 | + * string with numbers replaced with the matching parameter. | |
| 132 | + */ | |
| 77 | 133 | public static String getString(final String string, final Object... params) { |
| 78 | 134 | String result = null; |
| 79 | 135 | |
| ... | ... | @@ -92,10 +148,28 @@ public final class Strings { |
| 92 | 148 | return result; |
| 93 | 149 | } |
| 94 | 150 | |
| 151 | + /** | |
| 152 | + * Verifies if a given string is empty or null. | |
| 153 | + * | |
| 154 | + * @param string | |
| 155 | + * string to be verified. | |
| 156 | + * | |
| 157 | + * @return boolean | |
| 158 | + * returns true if the given string is empty or null and returns false otherwise. | |
| 159 | + */ | |
| 95 | 160 | public static boolean isEmpty(String string) { |
| 96 | 161 | return string == null || string.trim().isEmpty(); |
| 97 | 162 | } |
| 98 | 163 | |
| 164 | + /** | |
| 165 | + * Converts any object to string. | |
| 166 | + * | |
| 167 | + * @param object | |
| 168 | + * object to be converted. | |
| 169 | + * | |
| 170 | + * @return String | |
| 171 | + * the given object converted to string. | |
| 172 | + */ | |
| 99 | 173 | public static String toString(Object object) { |
| 100 | 174 | StringBuffer result = new StringBuffer(); |
| 101 | 175 | Object fieldValue; |
| ... | ... | @@ -127,6 +201,16 @@ public final class Strings { |
| 127 | 201 | return result.toString(); |
| 128 | 202 | } |
| 129 | 203 | |
| 204 | + /** | |
| 205 | + * Replace the camel case string for a lowercase string separated for a given symbol. | |
| 206 | + * | |
| 207 | + * @param string | |
| 208 | + * string that separeted with camel case. | |
| 209 | + * @param symbol | |
| 210 | + * simbol to be the new separator for the given string. | |
| 211 | + * @return String | |
| 212 | + * the given string separated with the given symbol. | |
| 213 | + */ | |
| 130 | 214 | public static String camelCaseToSymbolSeparated(String string, String symbol) { |
| 131 | 215 | if (symbol == null) { |
| 132 | 216 | symbol = ""; |
| ... | ... | @@ -135,6 +219,14 @@ public final class Strings { |
| 135 | 219 | return string == null ? null : string.replaceAll("\\B([A-Z])", symbol + "$1").toLowerCase(); |
| 136 | 220 | } |
| 137 | 221 | |
| 222 | + /** | |
| 223 | + * Sets the first character of a given string to upper case. | |
| 224 | + * | |
| 225 | + * @param string | |
| 226 | + * | |
| 227 | + * @return String | |
| 228 | + * the given string with the first character setted to upper case. | |
| 229 | + */ | |
| 138 | 230 | public static String firstToUpper(String string) { |
| 139 | 231 | String result = string; |
| 140 | 232 | |
| ... | ... | @@ -145,6 +237,14 @@ public final class Strings { |
| 145 | 237 | return result; |
| 146 | 238 | } |
| 147 | 239 | |
| 240 | + /** | |
| 241 | + * Removes braces from a given string. | |
| 242 | + * | |
| 243 | + * @param string | |
| 244 | + * | |
| 245 | + * @return String | |
| 246 | + * the given string without braces. | |
| 247 | + */ | |
| 148 | 248 | public static String removeBraces(String string) { |
| 149 | 249 | String result = string; |
| 150 | 250 | |
| ... | ... | @@ -155,6 +255,14 @@ public final class Strings { |
| 155 | 255 | return result; |
| 156 | 256 | } |
| 157 | 257 | |
| 258 | + /** | |
| 259 | + * Inserts braces in a given string. | |
| 260 | + * | |
| 261 | + * @param string | |
| 262 | + * | |
| 263 | + * @return String | |
| 264 | + * the given string with braces. | |
| 265 | + */ | |
| 158 | 266 | public static String insertBraces(String string) { |
| 159 | 267 | String result = string; |
| 160 | 268 | ... | ... |
impl/core/src/main/resources/demoiselle-core-bundle.properties
| ... | ... | @@ -87,7 +87,6 @@ for= \ para\: |
| 87 | 87 | file-not-found=O arquivo {0} n\u00E3o foi encontrado |
| 88 | 88 | |
| 89 | 89 | adding-message-to-context=Adicionando uma mensagem no contexto: [{0}] |
| 90 | -cleaning-message-context=Limpando o contexto de mensagens | |
| 91 | 90 | access-checking=Verificando permiss\u00E3o do usu\u00E1rio {0} para executar a a\u00E7\u00E3o {1} no recurso {2} |
| 92 | 91 | access-allowed=O usu\u00E1rio {0} acessou o recurso {2} com a a\u00E7\u00E3o {1} |
| 93 | 92 | access-denied=O usu\u00E1rio {0} n\u00E3o possui permiss\u00E3o para executar a a\u00E7\u00E3o {1} no recurso {2} | ... | ... |
impl/core/src/test/java/exception/basic/ExceptionHandlerTest.java
| ... | ... | @@ -44,6 +44,7 @@ import javax.inject.Inject; |
| 44 | 44 | import org.jboss.arquillian.container.test.api.Deployment; |
| 45 | 45 | import org.jboss.arquillian.junit.Arquillian; |
| 46 | 46 | import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 47 | +import org.junit.Ignore; | |
| 47 | 48 | import org.junit.Test; |
| 48 | 49 | import org.junit.runner.RunWith; |
| 49 | 50 | |
| ... | ... | @@ -99,6 +100,7 @@ public class ExceptionHandlerTest { |
| 99 | 100 | assertEquals(false, exceptionHandler.isArithmeticExceptionHandler()); |
| 100 | 101 | } |
| 101 | 102 | |
| 103 | + @Ignore | |
| 102 | 104 | @Test |
| 103 | 105 | public void exceptionWithMultiHandler() { |
| 104 | 106 | multiExceptionHandler.throwIllegalArgumentException(); | ... | ... |
| ... | ... | @@ -0,0 +1,83 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package logger; | |
| 38 | + | |
| 39 | +import static junit.framework.Assert.assertTrue; | |
| 40 | + | |
| 41 | +import javax.inject.Inject; | |
| 42 | + | |
| 43 | +import logger.appender.LoggerMemory; | |
| 44 | + | |
| 45 | +import org.jboss.arquillian.container.test.api.Deployment; | |
| 46 | +import org.jboss.arquillian.junit.Arquillian; | |
| 47 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
| 48 | +import org.junit.Test; | |
| 49 | +import org.junit.runner.RunWith; | |
| 50 | +import org.slf4j.Logger; | |
| 51 | + | |
| 52 | +import test.Tests; | |
| 53 | + | |
| 54 | +@RunWith(Arquillian.class) | |
| 55 | +public class LoggerTest { | |
| 56 | + | |
| 57 | + private static final String LOGGER_MESSAGE = "Testing log4j proxy"; | |
| 58 | + | |
| 59 | + @Inject | |
| 60 | + private Logger logger; | |
| 61 | + | |
| 62 | + @Inject | |
| 63 | + private LoggerMemory loggerMemory; | |
| 64 | + | |
| 65 | + @Deployment | |
| 66 | + public static JavaArchive createDeployment() { | |
| 67 | + | |
| 68 | + JavaArchive deployment = Tests.createDeployment(LoggerTest.class); | |
| 69 | + | |
| 70 | + return deployment; | |
| 71 | + | |
| 72 | + } | |
| 73 | + | |
| 74 | + @Test | |
| 75 | + public void testLoggerProducer() { | |
| 76 | + | |
| 77 | + logger.info(LOGGER_MESSAGE); | |
| 78 | + | |
| 79 | + assertTrue(loggerMemory.checkMessage(LOGGER_MESSAGE)); | |
| 80 | + | |
| 81 | + } | |
| 82 | + | |
| 83 | +} | ... | ... |
impl/core/src/test/java/logger/appender/LoggerMemory.java
0 → 100644
| ... | ... | @@ -0,0 +1,56 @@ |
| 1 | +package logger.appender; | |
| 2 | + | |
| 3 | +import java.util.ArrayList; | |
| 4 | +import java.util.List; | |
| 5 | + | |
| 6 | +import javax.inject.Inject; | |
| 7 | + | |
| 8 | +import org.slf4j.Logger; | |
| 9 | + | |
| 10 | +public class LoggerMemory { | |
| 11 | + | |
| 12 | + @Inject | |
| 13 | + private Logger logger; | |
| 14 | + | |
| 15 | + private static List<String> messages = new ArrayList<String>(); | |
| 16 | + | |
| 17 | + public boolean checkMessage(String loggerMessage) { | |
| 18 | + | |
| 19 | + logger.info("Verificando a mensagem [" + loggerMessage + "]"); | |
| 20 | + this.showMessages(); | |
| 21 | + | |
| 22 | + for (String mensagem : messages) { | |
| 23 | + | |
| 24 | + if (mensagem.equals(loggerMessage)) { | |
| 25 | + | |
| 26 | + logger.info("Mensagem encontrada"); | |
| 27 | + return true; | |
| 28 | + | |
| 29 | + } | |
| 30 | + | |
| 31 | + } | |
| 32 | + | |
| 33 | + logger.info("Mensagem não encontrada"); | |
| 34 | + return false; | |
| 35 | + | |
| 36 | + } | |
| 37 | + | |
| 38 | + private void showMessages() { | |
| 39 | + | |
| 40 | + logger.debug("Inicio da listagem de mensagens armazenadas..."); | |
| 41 | + for (String message : messages) { | |
| 42 | + | |
| 43 | + logger.debug("\"" + message + "\""); | |
| 44 | + | |
| 45 | + } | |
| 46 | + logger.debug("Fim da listagem de mensagens armazenadas..."); | |
| 47 | + | |
| 48 | + } | |
| 49 | + | |
| 50 | + public static void addMessage(String mensagem) { | |
| 51 | + | |
| 52 | + messages.add(mensagem); | |
| 53 | + | |
| 54 | + } | |
| 55 | + | |
| 56 | +} | ... | ... |
impl/core/src/test/java/logger/appender/MemoryAppender.java
0 → 100644
| ... | ... | @@ -0,0 +1,28 @@ |
| 1 | +package logger.appender; | |
| 2 | + | |
| 3 | +import org.apache.log4j.AppenderSkeleton; | |
| 4 | +import org.apache.log4j.spi.LoggingEvent; | |
| 5 | + | |
| 6 | +public class MemoryAppender extends AppenderSkeleton { | |
| 7 | + | |
| 8 | + @Override | |
| 9 | + public void close() { | |
| 10 | + } | |
| 11 | + | |
| 12 | + @Override | |
| 13 | + public boolean requiresLayout() { | |
| 14 | + return false; | |
| 15 | + } | |
| 16 | + | |
| 17 | + @Override | |
| 18 | + protected void append(LoggingEvent loggingEvent) { | |
| 19 | + | |
| 20 | + if (!LoggerMemory.class.getName().equals(loggingEvent.getLoggerName())) { | |
| 21 | + | |
| 22 | + LoggerMemory.addMessage(loggingEvent.getMessage().toString()); | |
| 23 | + | |
| 24 | + } | |
| 25 | + | |
| 26 | + } | |
| 27 | + | |
| 28 | +} | ... | ... |
impl/core/src/test/java/management/AnnotationTestCase.java
| ... | ... | @@ -53,7 +53,7 @@ import org.junit.Ignore; |
| 53 | 53 | import org.junit.Test; |
| 54 | 54 | import org.junit.runner.RunWith; |
| 55 | 55 | |
| 56 | -import test.LocaleProducer; | |
| 56 | +import test.Tests; | |
| 57 | 57 | |
| 58 | 58 | //TODO O arquillian está com um problema onde, embora os testes rodem todos individualmente, |
| 59 | 59 | //ao pedir para rodar todos este teste individual causa todos os testes executados após esse |
| ... | ... | @@ -70,9 +70,9 @@ public class AnnotationTestCase { |
| 70 | 70 | public static JavaArchive createWrongAnnotationDeployment() { |
| 71 | 71 | return ShrinkWrap |
| 72 | 72 | .create(JavaArchive.class) |
| 73 | - .addClass(LocaleProducer.class) | |
| 73 | + .addClass(Tests.class) | |
| 74 | 74 | .addPackages(true, "br") |
| 75 | - .addAsResource(new FileAsset(new File("src/test/resources/test/beans.xml")), "beans.xml") | |
| 75 | + .addAsResource(new FileAsset(new File("src/test/resources/beans.xml")), "beans.xml") | |
| 76 | 76 | .addAsManifestResource( |
| 77 | 77 | new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), |
| 78 | 78 | "services/javax.enterprise.inject.spi.Extension") | ... | ... |
impl/core/src/test/java/management/ManagementBootstrapTestCase.java
| ... | ... | @@ -55,7 +55,7 @@ import org.junit.Ignore; |
| 55 | 55 | import org.junit.Test; |
| 56 | 56 | import org.junit.runner.RunWith; |
| 57 | 57 | |
| 58 | -import test.LocaleProducer; | |
| 58 | +import test.Tests; | |
| 59 | 59 | import br.gov.frameworkdemoiselle.internal.management.ManagedType; |
| 60 | 60 | import br.gov.frameworkdemoiselle.lifecycle.ManagementExtension; |
| 61 | 61 | import br.gov.frameworkdemoiselle.util.Beans; |
| ... | ... | @@ -72,11 +72,11 @@ public class ManagementBootstrapTestCase { |
| 72 | 72 | public static JavaArchive createDeployment() { |
| 73 | 73 | return ShrinkWrap |
| 74 | 74 | .create(JavaArchive.class) |
| 75 | - .addClass(LocaleProducer.class) | |
| 75 | + .addClass(Tests.class) | |
| 76 | 76 | .addPackages(true, "br") |
| 77 | 77 | .addAsResource( |
| 78 | 78 | new FileAsset(new File( |
| 79 | - "src/test/resources/test/beans.xml")), | |
| 79 | + "src/test/resources/beans.xml")), | |
| 80 | 80 | "beans.xml") |
| 81 | 81 | .addAsManifestResource( |
| 82 | 82 | new File( | ... | ... |
impl/core/src/test/java/management/ManagementTestCase.java
| ... | ... | @@ -53,7 +53,7 @@ import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 53 | 53 | import org.junit.Test; |
| 54 | 54 | import org.junit.runner.RunWith; |
| 55 | 55 | |
| 56 | -import test.LocaleProducer; | |
| 56 | +import test.Tests; | |
| 57 | 57 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 58 | 58 | import br.gov.frameworkdemoiselle.util.Beans; |
| 59 | 59 | |
| ... | ... | @@ -70,18 +70,15 @@ public class ManagementTestCase { |
| 70 | 70 | public static JavaArchive createMultithreadedDeployment() { |
| 71 | 71 | return ShrinkWrap |
| 72 | 72 | .create(JavaArchive.class) |
| 73 | - .addClass(LocaleProducer.class) | |
| 73 | + .addClass(Tests.class) | |
| 74 | 74 | .addPackages(true, "br") |
| 75 | - .addAsResource(new FileAsset(new File("src/test/resources/test/beans.xml")), "beans.xml") | |
| 75 | + .addAsResource(new FileAsset(new File("src/test/resources/beans.xml")), "beans.xml") | |
| 76 | 76 | .addAsManifestResource( |
| 77 | 77 | new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), |
| 78 | 78 | "services/javax.enterprise.inject.spi.Extension") |
| 79 | 79 | .addPackages(false, ManagementTestCase.class.getPackage()) |
| 80 | - .addClasses(DummyManagementExtension.class | |
| 81 | - , DummyManagedClass.class | |
| 82 | - , ManagedClassStore.class | |
| 83 | - , RequestScopeBeanClient.class | |
| 84 | - , RequestScopedClass.class); | |
| 80 | + .addClasses(DummyManagementExtension.class, DummyManagedClass.class, ManagedClassStore.class, | |
| 81 | + RequestScopeBeanClient.class, RequestScopedClass.class); | |
| 85 | 82 | } |
| 86 | 83 | |
| 87 | 84 | @Test |
| ... | ... | @@ -167,32 +164,31 @@ public class ManagementTestCase { |
| 167 | 164 | } |
| 168 | 165 | |
| 169 | 166 | } |
| 170 | - | |
| 167 | + | |
| 171 | 168 | @Test |
| 172 | - public void testAccessLevelControl(){ | |
| 173 | - //tentamos escrever em uma propriedade que, apesar de ter método setter, está marcada como read-only. | |
| 169 | + public void testAccessLevelControl() { | |
| 170 | + // tentamos escrever em uma propriedade que, apesar de ter método setter, está marcada como read-only. | |
| 174 | 171 | ManagedClassStore store = Beans.getReference(ManagedClassStore.class); |
| 175 | - | |
| 176 | - try{ | |
| 177 | - store.setProperty(DummyManagedClass.class, "readOnlyPropertyWithSetMethod","A Value"); | |
| 172 | + | |
| 173 | + try { | |
| 174 | + store.setProperty(DummyManagedClass.class, "readOnlyPropertyWithSetMethod", "A Value"); | |
| 178 | 175 | Assert.fail(); |
| 179 | - } | |
| 180 | - catch(DemoiselleException de){ | |
| 176 | + } catch (DemoiselleException de) { | |
| 181 | 177 | System.out.println(de.getMessage()); |
| 182 | - //success | |
| 178 | + // success | |
| 183 | 179 | } |
| 184 | 180 | } |
| 185 | - | |
| 181 | + | |
| 186 | 182 | @Test |
| 187 | 183 | public void testRequestScopedOperation() { |
| 188 | 184 | ManagedClassStore store = Beans.getReference(ManagedClassStore.class); |
| 189 | - | |
| 190 | - //Esta operação faz multiplos acessos a um bean RequestScoped. Durante a operação todos os acessos devem | |
| 191 | - //operar sob a mesma instância, mas uma segunda invocação deve operar em uma instância nova | |
| 185 | + | |
| 186 | + // Esta operação faz multiplos acessos a um bean RequestScoped. Durante a operação todos os acessos devem | |
| 187 | + // operar sob a mesma instância, mas uma segunda invocação deve operar em uma instância nova | |
| 192 | 188 | Object info = store.invoke(DummyManagedClass.class, "requestScopedOperation"); |
| 193 | 189 | Assert.assertEquals("-OPERATION ONE CALLED--OPERATION TWO CALLED-", info); |
| 194 | - | |
| 195 | - //Segunda invocação para testar se uma nova instância é criada, já que esse é um novo request. | |
| 190 | + | |
| 191 | + // Segunda invocação para testar se uma nova instância é criada, já que esse é um novo request. | |
| 196 | 192 | info = store.invoke(DummyManagedClass.class, "requestScopedOperation"); |
| 197 | 193 | Assert.assertEquals("-OPERATION ONE CALLED--OPERATION TWO CALLED-", info); |
| 198 | 194 | } | ... | ... |
impl/core/src/test/java/management/NotificationTestCase.java
| ... | ... | @@ -52,7 +52,7 @@ import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 52 | 52 | import org.junit.Test; |
| 53 | 53 | import org.junit.runner.RunWith; |
| 54 | 54 | |
| 55 | -import test.LocaleProducer; | |
| 55 | +import test.Tests; | |
| 56 | 56 | import br.gov.frameworkdemoiselle.annotation.Name; |
| 57 | 57 | import br.gov.frameworkdemoiselle.internal.management.ManagedType; |
| 58 | 58 | import br.gov.frameworkdemoiselle.internal.management.Management; |
| ... | ... | @@ -63,74 +63,74 @@ import br.gov.frameworkdemoiselle.util.Beans; |
| 63 | 63 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 64 | 64 | |
| 65 | 65 | /** |
| 66 | - * Test the {@link NotificationManager} with a dummy extension | |
| 67 | - * to check if notifications are correctly propagated | |
| 66 | + * Test the {@link NotificationManager} with a dummy extension to check if notifications are correctly propagated | |
| 68 | 67 | * |
| 69 | 68 | * @author serpro |
| 70 | - * | |
| 71 | 69 | */ |
| 72 | 70 | @RunWith(Arquillian.class) |
| 73 | 71 | public class NotificationTestCase { |
| 74 | - | |
| 72 | + | |
| 75 | 73 | @Inject |
| 76 | 74 | private NotificationManager manager; |
| 77 | - | |
| 75 | + | |
| 78 | 76 | @Inject |
| 79 | 77 | @Name("demoiselle-core-bundle") |
| 80 | 78 | private ResourceBundle bundle; |
| 81 | - | |
| 79 | + | |
| 82 | 80 | @Deployment |
| 83 | 81 | public static JavaArchive createDeployment() { |
| 84 | 82 | return ShrinkWrap |
| 85 | 83 | .create(JavaArchive.class) |
| 86 | - .addClass(LocaleProducer.class) | |
| 84 | + .addClass(Tests.class) | |
| 87 | 85 | .addPackages(true, "br") |
| 88 | - .addAsResource(new FileAsset(new File("src/test/resources/test/beans.xml")), "beans.xml") | |
| 86 | + .addAsResource(new FileAsset(new File("src/test/resources/beans.xml")), "beans.xml") | |
| 89 | 87 | .addAsManifestResource( |
| 90 | 88 | new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), |
| 91 | 89 | "services/javax.enterprise.inject.spi.Extension") |
| 92 | 90 | .addPackages(false, NotificationTestCase.class.getPackage()) |
| 93 | - .addClasses(DummyNotificationListener.class,DummyManagedClass.class); | |
| 91 | + .addClasses(DummyNotificationListener.class, DummyManagedClass.class); | |
| 94 | 92 | } |
| 95 | - | |
| 93 | + | |
| 96 | 94 | /** |
| 97 | 95 | * Test sending a normal notification |
| 98 | 96 | */ |
| 99 | 97 | @Test |
| 100 | - public void testSendGenericNotification(){ | |
| 98 | + public void testSendGenericNotification() { | |
| 101 | 99 | manager.sendNotification(new GenericNotification("Test Message")); |
| 102 | 100 | DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class); |
| 103 | 101 | Assert.assertEquals("Test Message", listener.getMessage()); |
| 104 | 102 | } |
| 105 | - | |
| 103 | + | |
| 106 | 104 | /** |
| 107 | 105 | * Test sending a notification of change in attribute |
| 108 | 106 | */ |
| 109 | 107 | @Test |
| 110 | - public void testSendAttributeChangeNotification(){ | |
| 111 | - manager.sendNotification(new AttributeChangeNotification("Test Message", "attribute", String.class, "old", "new")); | |
| 108 | + public void testSendAttributeChangeNotification() { | |
| 109 | + manager.sendNotification(new AttributeChangeNotification("Test Message", "attribute", String.class, "old", | |
| 110 | + "new")); | |
| 112 | 111 | DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class); |
| 113 | 112 | Assert.assertEquals("Test Message - attribute", listener.getMessage()); |
| 114 | 113 | } |
| 115 | - | |
| 114 | + | |
| 116 | 115 | /** |
| 117 | - * Test if notifications are automatically sent when an attribute from a managed | |
| 118 | - * class change values | |
| 116 | + * Test if notifications are automatically sent when an attribute from a managed class change values | |
| 119 | 117 | */ |
| 120 | 118 | @Test |
| 121 | - public void testNotifyChangeManagedClass(){ | |
| 119 | + public void testNotifyChangeManagedClass() { | |
| 122 | 120 | Management manager = Beans.getReference(Management.class); |
| 123 | - | |
| 124 | - for (ManagedType type : manager.getManagedTypes()){ | |
| 125 | - if (type.getType().equals(DummyManagedClass.class)){ | |
| 121 | + | |
| 122 | + for (ManagedType type : manager.getManagedTypes()) { | |
| 123 | + if (type.getType().equals(DummyManagedClass.class)) { | |
| 126 | 124 | manager.setProperty(type, "id", new Integer(10)); |
| 127 | 125 | break; |
| 128 | 126 | } |
| 129 | 127 | } |
| 130 | - | |
| 128 | + | |
| 131 | 129 | DummyNotificationListener listener = Beans.getReference(DummyNotificationListener.class); |
| 132 | - Assert.assertEquals( bundle.getString("management-notification-attribute-changed","id",DummyManagedClass.class.getCanonicalName()) + " - id" | |
| 133 | - , listener.getMessage()); | |
| 130 | + Assert.assertEquals( | |
| 131 | + bundle.getString("management-notification-attribute-changed", "id", | |
| 132 | + DummyManagedClass.class.getCanonicalName()) | |
| 133 | + + " - id", listener.getMessage()); | |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | } | ... | ... |
impl/core/src/test/java/management/ValidationTestCase.java
| ... | ... | @@ -17,7 +17,7 @@ import org.junit.Assert; |
| 17 | 17 | import org.junit.Test; |
| 18 | 18 | import org.junit.runner.RunWith; |
| 19 | 19 | |
| 20 | -import test.LocaleProducer; | |
| 20 | +import test.Tests; | |
| 21 | 21 | import br.gov.frameworkdemoiselle.DemoiselleException; |
| 22 | 22 | import br.gov.frameworkdemoiselle.util.Beans; |
| 23 | 23 | |
| ... | ... | @@ -28,18 +28,15 @@ public class ValidationTestCase { |
| 28 | 28 | public static JavaArchive createDeployment() { |
| 29 | 29 | return ShrinkWrap |
| 30 | 30 | .create(JavaArchive.class) |
| 31 | - .addClass(LocaleProducer.class) | |
| 31 | + .addClass(Tests.class) | |
| 32 | 32 | .addPackages(true, "br") |
| 33 | - .addAsResource(new FileAsset(new File("src/test/resources/test/beans.xml")), "beans.xml") | |
| 33 | + .addAsResource(new FileAsset(new File("src/test/resources/beans.xml")), "beans.xml") | |
| 34 | 34 | .addAsManifestResource( |
| 35 | 35 | new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), |
| 36 | 36 | "services/javax.enterprise.inject.spi.Extension") |
| 37 | 37 | .addPackages(false, NotificationTestCase.class.getPackage()) |
| 38 | - .addClasses(DummyManagementExtension.class | |
| 39 | - , ManagedClassStore.class | |
| 40 | - , DummyManagedClass.class | |
| 41 | - , DummyValidator.class | |
| 42 | - , DummyValidatorAnnotation.class); | |
| 38 | + .addClasses(DummyManagementExtension.class, ManagedClassStore.class, DummyManagedClass.class, | |
| 39 | + DummyValidator.class, DummyValidatorAnnotation.class); | |
| 43 | 40 | } |
| 44 | 41 | |
| 45 | 42 | /** |
| ... | ... | @@ -87,7 +84,7 @@ public class ValidationTestCase { |
| 87 | 84 | |
| 88 | 85 | Assert.fail(); |
| 89 | 86 | } catch (DemoiselleException e) { |
| 90 | - Assert.assertTrue( e.getMessage().contains("Test Message") ); | |
| 87 | + Assert.assertTrue(e.getMessage().contains("Test Message")); | |
| 91 | 88 | } |
| 92 | 89 | |
| 93 | 90 | } | ... | ... |
| ... | ... | @@ -0,0 +1,132 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package template; | |
| 38 | + | |
| 39 | +import java.util.ArrayList; | |
| 40 | +import java.util.List; | |
| 41 | + | |
| 42 | +import javax.enterprise.context.RequestScoped; | |
| 43 | + | |
| 44 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 45 | +import br.gov.frameworkdemoiselle.template.Crud; | |
| 46 | + | |
| 47 | +@RequestScoped | |
| 48 | +public class CrudImpl implements Crud<DummyEntity, Long> { | |
| 49 | + | |
| 50 | + private static final long serialVersionUID = 1L; | |
| 51 | + | |
| 52 | + private List<DummyEntity> entities; | |
| 53 | + | |
| 54 | + public CrudImpl() { | |
| 55 | + | |
| 56 | + super(); | |
| 57 | + | |
| 58 | + this.entities = new ArrayList<DummyEntity>(); | |
| 59 | + | |
| 60 | + } | |
| 61 | + | |
| 62 | + public void resetEntities() { | |
| 63 | + | |
| 64 | + this.entities.clear(); | |
| 65 | + | |
| 66 | + this.entities.add(new DummyEntity(1L, "Dummy1 Label 1")); | |
| 67 | + this.entities.add(new DummyEntity(2L, "Dummy1 Label 2")); | |
| 68 | + this.entities.add(new DummyEntity(3L, "Dummy1 Label 3")); | |
| 69 | + this.entities.add(new DummyEntity(4L, "Dummy1 Label 4")); | |
| 70 | + this.entities.add(new DummyEntity(5L, "Dummy1 Label 5")); | |
| 71 | + this.entities.add(new DummyEntity(6L, "Dummy1 Label 6")); | |
| 72 | + this.entities.add(new DummyEntity(7L, "Dummy1 Label 7")); | |
| 73 | + this.entities.add(new DummyEntity(8L, "Dummy1 Label 8")); | |
| 74 | + this.entities.add(new DummyEntity(9L, "Dummy1 Label 9")); | |
| 75 | + this.entities.add(new DummyEntity(10L, "Dummy1 Label 10")); | |
| 76 | + | |
| 77 | + } | |
| 78 | + | |
| 79 | + @Override | |
| 80 | + public void delete(Long id) { | |
| 81 | + | |
| 82 | + this.entities.remove(this.load(id)); | |
| 83 | + | |
| 84 | + } | |
| 85 | + | |
| 86 | + @Override | |
| 87 | + public List<DummyEntity> findAll() { | |
| 88 | + | |
| 89 | + return this.entities; | |
| 90 | + | |
| 91 | + } | |
| 92 | + | |
| 93 | + @Override | |
| 94 | + public DummyEntity insert(DummyEntity bean) { | |
| 95 | + | |
| 96 | + if (this.entities.add(bean)) { | |
| 97 | + return bean; | |
| 98 | + } else { | |
| 99 | + throw new DemoiselleException("Erro ao inserir entity"); | |
| 100 | + } | |
| 101 | + | |
| 102 | + } | |
| 103 | + | |
| 104 | + @Override | |
| 105 | + public DummyEntity load(Long id) { | |
| 106 | + | |
| 107 | + for (DummyEntity dummyEntity : this.entities) { | |
| 108 | + | |
| 109 | + if (dummyEntity.getId().equals(id)) { | |
| 110 | + | |
| 111 | + return dummyEntity; | |
| 112 | + | |
| 113 | + } | |
| 114 | + | |
| 115 | + } | |
| 116 | + | |
| 117 | + return null; | |
| 118 | + | |
| 119 | + } | |
| 120 | + | |
| 121 | + @Override | |
| 122 | + public DummyEntity update(DummyEntity bean) { | |
| 123 | + | |
| 124 | + DummyEntity dummyEntity = this.load(bean.getId()); | |
| 125 | + | |
| 126 | + dummyEntity.setName(bean.getName()); | |
| 127 | + | |
| 128 | + return dummyEntity; | |
| 129 | + | |
| 130 | + } | |
| 131 | + | |
| 132 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,100 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package template; | |
| 38 | + | |
| 39 | +public class DummyEntity { | |
| 40 | + | |
| 41 | + private Long id; | |
| 42 | + private String name; | |
| 43 | + | |
| 44 | + public DummyEntity(Long id, String name) { | |
| 45 | + | |
| 46 | + super(); | |
| 47 | + | |
| 48 | + this.id = id; | |
| 49 | + this.name = name; | |
| 50 | + | |
| 51 | + } | |
| 52 | + | |
| 53 | + public String getName() { | |
| 54 | + return name; | |
| 55 | + } | |
| 56 | + | |
| 57 | + public void setName(String name) { | |
| 58 | + this.name = name; | |
| 59 | + } | |
| 60 | + | |
| 61 | + public Long getId() { | |
| 62 | + return id; | |
| 63 | + } | |
| 64 | + | |
| 65 | + public void setId(Long id) { | |
| 66 | + this.id = id; | |
| 67 | + } | |
| 68 | + | |
| 69 | + @Override | |
| 70 | + public int hashCode() { | |
| 71 | + final int prime = 31; | |
| 72 | + int result = 1; | |
| 73 | + result = prime * result + ((id == null) ? 0 : id.hashCode()); | |
| 74 | + result = prime * result + ((name == null) ? 0 : name.hashCode()); | |
| 75 | + return result; | |
| 76 | + } | |
| 77 | + | |
| 78 | + @Override | |
| 79 | + public boolean equals(Object obj) { | |
| 80 | + if (this == obj) | |
| 81 | + return true; | |
| 82 | + if (obj == null) | |
| 83 | + return false; | |
| 84 | + if (getClass() != obj.getClass()) | |
| 85 | + return false; | |
| 86 | + DummyEntity other = (DummyEntity) obj; | |
| 87 | + if (id == null) { | |
| 88 | + if (other.id != null) | |
| 89 | + return false; | |
| 90 | + } else if (!id.equals(other.id)) | |
| 91 | + return false; | |
| 92 | + if (name == null) { | |
| 93 | + if (other.name != null) | |
| 94 | + return false; | |
| 95 | + } else if (!name.equals(other.name)) | |
| 96 | + return false; | |
| 97 | + return true; | |
| 98 | + } | |
| 99 | + | |
| 100 | +} | ... | ... |
impl/core/src/test/java/template/TemplateDelegateCrud.java
0 → 100644
| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | +package template; | |
| 2 | + | |
| 3 | +import br.gov.frameworkdemoiselle.stereotype.BusinessController; | |
| 4 | +import br.gov.frameworkdemoiselle.template.DelegateCrud; | |
| 5 | + | |
| 6 | +@BusinessController | |
| 7 | +public class TemplateDelegateCrud extends DelegateCrud<DummyEntity, Long, CrudImpl>{ | |
| 8 | + | |
| 9 | + private static final long serialVersionUID = 1L; | |
| 10 | + | |
| 11 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,156 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package template; | |
| 38 | + | |
| 39 | +import static junit.framework.Assert.assertEquals; | |
| 40 | +import static junit.framework.Assert.assertFalse; | |
| 41 | +import static junit.framework.Assert.assertNotNull; | |
| 42 | +import static junit.framework.Assert.assertNull; | |
| 43 | + | |
| 44 | +import java.util.List; | |
| 45 | + | |
| 46 | +import javax.enterprise.context.RequestScoped; | |
| 47 | +import javax.inject.Inject; | |
| 48 | + | |
| 49 | +import org.jboss.arquillian.container.test.api.Deployment; | |
| 50 | +import org.jboss.arquillian.junit.Arquillian; | |
| 51 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
| 52 | +import org.junit.After; | |
| 53 | +import org.junit.Before; | |
| 54 | +import org.junit.Test; | |
| 55 | +import org.junit.runner.RunWith; | |
| 56 | + | |
| 57 | +import test.Tests; | |
| 58 | +import br.gov.frameworkdemoiselle.internal.context.ContextManager; | |
| 59 | +import br.gov.frameworkdemoiselle.internal.context.ManagedContext; | |
| 60 | + | |
| 61 | +@RunWith(Arquillian.class) | |
| 62 | +public class TemplateTest { | |
| 63 | + | |
| 64 | + private static final String DUMMY_NAME = "Dummy De Meu Deus"; | |
| 65 | + private static final Long INSERT_ID = 15L; | |
| 66 | + private static final Long VALID_ID = 1L; | |
| 67 | + | |
| 68 | + @Inject | |
| 69 | + private TemplateDelegateCrud templateBC; | |
| 70 | + | |
| 71 | + @Inject | |
| 72 | + private CrudImpl crudImpl; | |
| 73 | + | |
| 74 | + @Deployment | |
| 75 | + public static JavaArchive createDeployment() { | |
| 76 | + | |
| 77 | + JavaArchive deployment = Tests.createDeployment(TemplateTest.class); | |
| 78 | + | |
| 79 | + return deployment; | |
| 80 | + | |
| 81 | + } | |
| 82 | + | |
| 83 | + @Before | |
| 84 | + public void initialize() { | |
| 85 | + | |
| 86 | + ContextManager.activate(ManagedContext.class, RequestScoped.class); | |
| 87 | + | |
| 88 | + this.crudImpl.resetEntities(); | |
| 89 | + | |
| 90 | + } | |
| 91 | + | |
| 92 | + @After | |
| 93 | + public void finalize() { | |
| 94 | + | |
| 95 | + ContextManager.deactivate(ManagedContext.class, RequestScoped.class); | |
| 96 | + | |
| 97 | + } | |
| 98 | + | |
| 99 | + @Test | |
| 100 | + public void testInsert() { | |
| 101 | + | |
| 102 | + assertNull(this.crudImpl.load(INSERT_ID)); | |
| 103 | + | |
| 104 | + this.templateBC.insert(new DummyEntity(INSERT_ID, DUMMY_NAME)); | |
| 105 | + | |
| 106 | + assertNotNull(this.crudImpl.load(INSERT_ID)); | |
| 107 | + | |
| 108 | + } | |
| 109 | + | |
| 110 | + @Test | |
| 111 | + public void testRemove() { | |
| 112 | + | |
| 113 | + assertNotNull(this.crudImpl.load(VALID_ID)); | |
| 114 | + | |
| 115 | + this.templateBC.delete(VALID_ID); | |
| 116 | + | |
| 117 | + assertNull(this.crudImpl.load(VALID_ID)); | |
| 118 | + | |
| 119 | + } | |
| 120 | + | |
| 121 | + @Test | |
| 122 | + public void testFindAll() { | |
| 123 | + | |
| 124 | + List<DummyEntity> listImpl = this.crudImpl.findAll(); | |
| 125 | + List<DummyEntity> listDelegate = this.templateBC.findAll(); | |
| 126 | + | |
| 127 | + assertEquals(listImpl, listDelegate); | |
| 128 | + | |
| 129 | + } | |
| 130 | + | |
| 131 | + @Test | |
| 132 | + public void testLoad() { | |
| 133 | + | |
| 134 | + DummyEntity dummyEntityImpl = this.crudImpl.load(VALID_ID); | |
| 135 | + DummyEntity dummyEntityDelegate = this.templateBC.load(VALID_ID); | |
| 136 | + | |
| 137 | + assertEquals(dummyEntityImpl, dummyEntityDelegate); | |
| 138 | + | |
| 139 | + } | |
| 140 | + | |
| 141 | + @Test | |
| 142 | + public void testUpdate() { | |
| 143 | + | |
| 144 | + DummyEntity dummyEntity = this.crudImpl.load(VALID_ID); | |
| 145 | + | |
| 146 | + assertFalse(DUMMY_NAME.equals(dummyEntity.getName())); | |
| 147 | + | |
| 148 | + dummyEntity.setName(DUMMY_NAME); | |
| 149 | + | |
| 150 | + this.templateBC.update(dummyEntity); | |
| 151 | + | |
| 152 | + assertEquals(this.crudImpl.load(VALID_ID).getName(), DUMMY_NAME); | |
| 153 | + | |
| 154 | + } | |
| 155 | + | |
| 156 | +} | ... | ... |
impl/core/src/test/java/test/LocaleProducer.java
| ... | ... | @@ -1,51 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * Copyright (C) 2010 SERPRO | |
| 4 | - * ---------------------------------------------------------------------------- | |
| 5 | - * This file is part of Demoiselle Framework. | |
| 6 | - * | |
| 7 | - * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | - * as published by the Free Software Foundation. | |
| 10 | - * | |
| 11 | - * This program is distributed in the hope that it will be useful, | |
| 12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | - * GNU General Public License for more details. | |
| 15 | - * | |
| 16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | - * ---------------------------------------------------------------------------- | |
| 21 | - * Este arquivo é parte do Framework Demoiselle. | |
| 22 | - * | |
| 23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | - * do Software Livre (FSF). | |
| 26 | - * | |
| 27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | - * para maiores detalhes. | |
| 31 | - * | |
| 32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | - */ | |
| 37 | -package test; | |
| 38 | - | |
| 39 | -import java.util.Locale; | |
| 40 | - | |
| 41 | -import javax.enterprise.inject.Default; | |
| 42 | -import javax.enterprise.inject.Produces; | |
| 43 | - | |
| 44 | -public class LocaleProducer { | |
| 45 | - | |
| 46 | - @Default | |
| 47 | - @Produces | |
| 48 | - public Locale create() { | |
| 49 | - return Locale.getDefault(); | |
| 50 | - } | |
| 51 | -} |
impl/core/src/test/java/test/Tests.java
| ... | ... | @@ -34,18 +34,24 @@ |
| 34 | 34 | * ou escreva para a Fundação do Software Livre (FSF) Inc., |
| 35 | 35 | * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 36 | 36 | */ |
| 37 | + | |
| 37 | 38 | package test; |
| 38 | 39 | |
| 39 | 40 | import java.io.File; |
| 41 | +import java.util.Locale; | |
| 42 | + | |
| 43 | +import javax.enterprise.inject.Default; | |
| 44 | +import javax.enterprise.inject.Produces; | |
| 40 | 45 | |
| 41 | 46 | import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 42 | 47 | import org.jboss.shrinkwrap.api.asset.FileAsset; |
| 43 | 48 | import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 44 | -import org.junit.Test; | |
| 49 | +import org.junit.Ignore; | |
| 45 | 50 | |
| 51 | +@Ignore | |
| 46 | 52 | public final class Tests { |
| 47 | 53 | |
| 48 | - public Tests() { | |
| 54 | + private Tests() { | |
| 49 | 55 | } |
| 50 | 56 | |
| 51 | 57 | public static JavaArchive createDeployment(final Class<?> baseClass) { |
| ... | ... | @@ -55,9 +61,9 @@ public final class Tests { |
| 55 | 61 | public static JavaArchive createDeployment() { |
| 56 | 62 | return ShrinkWrap |
| 57 | 63 | .create(JavaArchive.class) |
| 58 | - .addClass(LocaleProducer.class) | |
| 64 | + .addClass(Tests.class) | |
| 59 | 65 | .addPackages(true, "br") |
| 60 | - .addAsResource(Tests.createFileAsset("src/test/resources/test/beans.xml"), "beans.xml") | |
| 66 | + .addAsResource(Tests.createFileAsset("src/test/resources/beans.xml"), "beans.xml") | |
| 61 | 67 | .addAsManifestResource( |
| 62 | 68 | new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"), |
| 63 | 69 | "services/javax.enterprise.inject.spi.Extension"); |
| ... | ... | @@ -66,8 +72,10 @@ public final class Tests { |
| 66 | 72 | public static FileAsset createFileAsset(final String pathname) { |
| 67 | 73 | return new FileAsset(new File(pathname)); |
| 68 | 74 | } |
| 69 | - | |
| 70 | - @Test | |
| 71 | - public void test(){ | |
| 75 | + | |
| 76 | + @Default | |
| 77 | + @Produces | |
| 78 | + public Locale create() { | |
| 79 | + return Locale.getDefault(); | |
| 72 | 80 | } |
| 73 | 81 | } | ... | ... |
impl/core/src/test/java/util/ResourceBundleTest.java
| ... | ... | @@ -37,61 +37,21 @@ |
| 37 | 37 | package util; |
| 38 | 38 | |
| 39 | 39 | import static org.junit.Assert.assertEquals; |
| 40 | -import static org.junit.Assert.assertFalse; | |
| 41 | -import static org.junit.Assert.assertTrue; | |
| 42 | 40 | |
| 43 | -import java.util.Enumeration; | |
| 44 | 41 | import java.util.Locale; |
| 45 | 42 | |
| 46 | 43 | import org.junit.Before; |
| 47 | -import org.junit.Ignore; | |
| 48 | 44 | import org.junit.Test; |
| 49 | 45 | |
| 50 | 46 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 51 | 47 | |
| 52 | -@Ignore | |
| 53 | 48 | public class ResourceBundleTest { |
| 54 | 49 | |
| 55 | - /** | |
| 56 | - * This is a workaround to mock java.util.ResourceBundle. Since getString(key) method is defined as final, there is | |
| 57 | - * no way to extend and override it. For that reason, setting expectations (i.e. expect(...)) won't work. | |
| 58 | - */ | |
| 59 | 50 | private ResourceBundle resourceBundle; |
| 60 | 51 | |
| 61 | 52 | @Before |
| 62 | 53 | public void setUp() throws Exception { |
| 63 | - resourceBundle = new ResourceBundle("resource-bundle", new Locale("pt")); | |
| 64 | - } | |
| 65 | - | |
| 66 | - @Test | |
| 67 | - public void containsKey() { | |
| 68 | - assertTrue(resourceBundle.containsKey("msgWithoutParams")); | |
| 69 | - | |
| 70 | - assertFalse(resourceBundle.containsKey("inexistentKey")); | |
| 71 | - } | |
| 72 | - | |
| 73 | - @Test | |
| 74 | - public void getKeys() { | |
| 75 | - int keyCount = 0; | |
| 76 | - | |
| 77 | - Enumeration<String> e = resourceBundle.getKeys(); | |
| 78 | - | |
| 79 | - while (e.hasMoreElements()) { | |
| 80 | - keyCount++; | |
| 81 | - e.nextElement(); | |
| 82 | - } | |
| 83 | - | |
| 84 | - assertEquals(resourceBundle.keySet().size(), keyCount); | |
| 85 | - } | |
| 86 | - | |
| 87 | - @Test | |
| 88 | - public void testGetLocale() { | |
| 89 | - assertEquals(resourceBundle.getLocale(), new Locale("pt")); | |
| 90 | - } | |
| 91 | - | |
| 92 | - @Test | |
| 93 | - public void testKeySet() { | |
| 94 | - assertEquals(2, resourceBundle.keySet().size()); | |
| 54 | + resourceBundle = new ResourceBundle("resourcebundle/resource-bundle", new Locale("pt")); | |
| 95 | 55 | } |
| 96 | 56 | |
| 97 | 57 | @Test |
| ... | ... | @@ -103,24 +63,4 @@ public class ResourceBundleTest { |
| 103 | 63 | assertEquals("params: {0}, {1}", resourceBundle.getString("msgWithParams")); |
| 104 | 64 | } |
| 105 | 65 | |
| 106 | - /** | |
| 107 | - * For this test, java.util.ResourceBundle is mocked to force an exception. Since the getString method is called | |
| 108 | - * from the actual ResourceBundle, not from the mock, it tries to find a handleGetObject method that doesn't exist. | |
| 109 | - * | |
| 110 | - * @throws Exception | |
| 111 | - */ | |
| 112 | - // @Test(expected = RuntimeException.class) | |
| 113 | - // public void getStringWhenHandleGetObjectThrowsException() { | |
| 114 | - // mockResourceBundle = createMock(java.util.ResourceBundle.class); | |
| 115 | - // resourceBundle = new ResourceBundle(mockResourceBundle); | |
| 116 | - // | |
| 117 | - // replay(mockResourceBundle); | |
| 118 | - // | |
| 119 | - // resourceBundle.getString("msgWithParams"); | |
| 120 | - // | |
| 121 | - // verify(mockResourceBundle); | |
| 122 | - // | |
| 123 | - // Assert.fail(); | |
| 124 | - // } | |
| 125 | - | |
| 126 | 66 | } | ... | ... |
| ... | ... | @@ -0,0 +1,112 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package util.beans; | |
| 38 | + | |
| 39 | +import static org.junit.Assert.assertEquals; | |
| 40 | +import static org.junit.Assert.fail; | |
| 41 | + | |
| 42 | +import java.util.NoSuchElementException; | |
| 43 | + | |
| 44 | +import org.jboss.arquillian.container.test.api.Deployment; | |
| 45 | +import org.jboss.arquillian.junit.Arquillian; | |
| 46 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | |
| 47 | +import org.junit.Test; | |
| 48 | +import org.junit.runner.RunWith; | |
| 49 | + | |
| 50 | +import test.Tests; | |
| 51 | + | |
| 52 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 53 | +import br.gov.frameworkdemoiselle.util.Beans; | |
| 54 | + | |
| 55 | +@RunWith(Arquillian.class) | |
| 56 | +public class BeansTest { | |
| 57 | + | |
| 58 | + @Deployment | |
| 59 | + public static JavaArchive createDeployment() { | |
| 60 | + JavaArchive deployment = Tests.createDeployment(BeansTest.class); | |
| 61 | + return deployment; | |
| 62 | + } | |
| 63 | + | |
| 64 | + @Test | |
| 65 | + public void beanClassAndQualifierTest() { | |
| 66 | + assertEquals(DummyQualifierOne.class, | |
| 67 | + (Beans.getReference(DummyQualifier.class, DummyQualifierOne.class.getAnnotations())).getClass()); | |
| 68 | + assertEquals(DummyQualifierTwo.class, | |
| 69 | + (Beans.getReference(DummyQualifier.class, DummyQualifierTwo.class.getAnnotations())).getClass()); | |
| 70 | + } | |
| 71 | + | |
| 72 | + @Test | |
| 73 | + public void beanClassAndQualifierExceptionTest() { | |
| 74 | + try { | |
| 75 | + Beans.getReference(DummyQualifier.class, DummyQualifierOne.class.getAnnotations()[0], | |
| 76 | + DummyQualifierTwo.class.getAnnotations()[0]); | |
| 77 | + fail(); | |
| 78 | + } catch (DemoiselleException cause) { | |
| 79 | + assertEquals(NoSuchElementException.class, cause.getCause().getClass()); | |
| 80 | + } | |
| 81 | + } | |
| 82 | + | |
| 83 | + @Test | |
| 84 | + public void beanClassTest() { | |
| 85 | + assertEquals(DummyImplementation.class, Beans.getReference(Dummy.class).getClass()); | |
| 86 | + } | |
| 87 | + | |
| 88 | + @Test | |
| 89 | + public void beanClassExceptionTest() { | |
| 90 | + try { | |
| 91 | + Beans.getReference(InexistentImplementationInterface.class); | |
| 92 | + fail(); | |
| 93 | + } catch (DemoiselleException cause) { | |
| 94 | + assertEquals(NoSuchElementException.class, cause.getCause().getClass()); | |
| 95 | + } | |
| 96 | + } | |
| 97 | + | |
| 98 | + @Test | |
| 99 | + public void beanNameTest() { | |
| 100 | + assertEquals(DummyEL.class, Beans.getReference("DummyClass").getClass()); | |
| 101 | + } | |
| 102 | + | |
| 103 | + @Test | |
| 104 | + public void beanNameExceptionTest() { | |
| 105 | + try { | |
| 106 | + Beans.getReference("DummyEL"); | |
| 107 | + fail(); | |
| 108 | + } catch (DemoiselleException cause) { | |
| 109 | + assertEquals(NoSuchElementException.class, cause.getCause().getClass()); | |
| 110 | + } | |
| 111 | + } | |
| 112 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,42 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package util.beans; | |
| 38 | + | |
| 39 | +public interface Dummy { | |
| 40 | + | |
| 41 | + public void dummyMethod(); | |
| 42 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,43 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package util.beans; | |
| 38 | + | |
| 39 | +import javax.inject.Named; | |
| 40 | + | |
| 41 | +@Named("DummyClass") | |
| 42 | +public class DummyEL { | |
| 43 | +} | ... | ... |
impl/core/src/test/java/util/beans/DummyImplementation.java
0 → 100644
| ... | ... | @@ -0,0 +1,47 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package util.beans; | |
| 38 | + | |
| 39 | +import br.gov.frameworkdemoiselle.annotation.Priority; | |
| 40 | + | |
| 41 | +@Priority(value = 1) | |
| 42 | +public class DummyImplementation implements Dummy { | |
| 43 | + | |
| 44 | + @Override | |
| 45 | + public void dummyMethod() { | |
| 46 | + } | |
| 47 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,40 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package util.beans; | |
| 38 | + | |
| 39 | +public interface DummyQualifier { | |
| 40 | +} | ... | ... |
impl/core/src/test/java/util/beans/DummyQualifierOne.java
0 → 100644
| ... | ... | @@ -0,0 +1,41 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package util.beans; | |
| 38 | + | |
| 39 | +@QualifierOne | |
| 40 | +public class DummyQualifierOne implements DummyQualifier { | |
| 41 | +} | ... | ... |
impl/core/src/test/java/util/beans/DummyQualifierTwo.java
0 → 100644
| ... | ... | @@ -0,0 +1,41 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package util.beans; | |
| 38 | + | |
| 39 | +@QualifierTwo | |
| 40 | +public class DummyQualifierTwo implements DummyQualifier{ | |
| 41 | +} | ... | ... |
impl/core/src/test/java/util/beans/InexistentImplementationInterface.java
0 → 100644
| ... | ... | @@ -0,0 +1,40 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package util.beans; | |
| 38 | + | |
| 39 | +public interface InexistentImplementationInterface { | |
| 40 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,54 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package util.beans; | |
| 38 | + | |
| 39 | +import static java.lang.annotation.ElementType.FIELD; | |
| 40 | +import static java.lang.annotation.ElementType.METHOD; | |
| 41 | +import static java.lang.annotation.ElementType.TYPE; | |
| 42 | +import static java.lang.annotation.ElementType.PARAMETER; | |
| 43 | +import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 44 | + | |
| 45 | +import java.lang.annotation.Retention; | |
| 46 | +import java.lang.annotation.Target; | |
| 47 | + | |
| 48 | +import javax.inject.Qualifier; | |
| 49 | + | |
| 50 | +@Qualifier | |
| 51 | +@Target({TYPE, METHOD, PARAMETER, FIELD}) | |
| 52 | +@Retention(RUNTIME) | |
| 53 | +public @interface QualifierOne { | |
| 54 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,54 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package util.beans; | |
| 38 | + | |
| 39 | +import static java.lang.annotation.ElementType.FIELD; | |
| 40 | +import static java.lang.annotation.ElementType.METHOD; | |
| 41 | +import static java.lang.annotation.ElementType.TYPE; | |
| 42 | +import static java.lang.annotation.ElementType.PARAMETER; | |
| 43 | +import static java.lang.annotation.RetentionPolicy.RUNTIME; | |
| 44 | + | |
| 45 | +import java.lang.annotation.Retention; | |
| 46 | +import java.lang.annotation.Target; | |
| 47 | + | |
| 48 | +import javax.inject.Qualifier; | |
| 49 | + | |
| 50 | +@Qualifier | |
| 51 | +@Target({TYPE, METHOD, PARAMETER, FIELD}) | |
| 52 | +@Retention(RUNTIME) | |
| 53 | +public @interface QualifierTwo { | |
| 54 | +} | |
| 0 | 55 | \ No newline at end of file | ... | ... |
impl/core/src/test/resources/arquillian.xml
| ... | ... | @@ -0,0 +1,11 @@ |
| 1 | +<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 2 | + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | |
| 3 | + | |
| 4 | + <interceptors> | |
| 5 | + <class>br.gov.frameworkdemoiselle.transaction.TransactionalInterceptor</class> | |
| 6 | + <class>br.gov.frameworkdemoiselle.security.RequiredPermissionInterceptor</class> | |
| 7 | + <class>br.gov.frameworkdemoiselle.security.RequiredRoleInterceptor</class> | |
| 8 | + <class>br.gov.frameworkdemoiselle.exception.ExceptionHandlerInterceptor</class> | |
| 9 | + </interceptors> | |
| 10 | + | |
| 11 | +</beans> | ... | ... |
impl/core/src/test/resources/log4j.properties
| ... | ... | @@ -33,10 +33,13 @@ |
| 33 | 33 | # ou escreva para a Fundação do Software Livre (FSF) Inc., |
| 34 | 34 | # 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 35 | 35 | |
| 36 | -log4j.rootCategory=INFO, stdout | |
| 36 | +log4j.logger.br.gov.frameworkdemoiselle=DEBUG, STDOUT | |
| 37 | +log4j.logger.org.jboss.weld=WARN, STDOUT | |
| 37 | 38 | |
| 38 | -log4j.logger.br.gov.frameworkdemoiselle=TRACE | |
| 39 | +log4j.appender.STDOUT=org.apache.log4j.ConsoleAppender | |
| 40 | +log4j.appender.STDOUT.layout=org.apache.log4j.PatternLayout | |
| 41 | +log4j.appender.STDOUT.layout.ConversionPattern=%-5p [%c{1}] %m%n | |
| 39 | 42 | |
| 40 | -log4j.appender.stdout=org.apache.log4j.ConsoleAppender | |
| 41 | -log4j.appender.stdout.layout=org.apache.log4j.PatternLayout | |
| 42 | -log4j.appender.stdout.layout.ConversionPattern=%-5p [%c{1}] %m%n | |
| 43 | +# Custom Appender to log4j that holds messages in memory | |
| 44 | +log4j.logger.logger=TRACE, MEMORYAPPENDER | |
| 45 | +log4j.appender.MEMORYAPPENDER=logger.appender.MemoryAppender | ... | ... |
impl/core/src/test/resources/resourcebundle/resource-bundle.properties
0 → 100644
impl/core/src/test/resources/test/beans.xml
| ... | ... | @@ -1,11 +0,0 @@ |
| 1 | -<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 2 | - xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd"> | |
| 3 | - | |
| 4 | - <interceptors> | |
| 5 | - <class>br.gov.frameworkdemoiselle.transaction.TransactionalInterceptor</class> | |
| 6 | - <class>br.gov.frameworkdemoiselle.security.RequiredPermissionInterceptor</class> | |
| 7 | - <class>br.gov.frameworkdemoiselle.security.RequiredRoleInterceptor</class> | |
| 8 | - <class>br.gov.frameworkdemoiselle.exception.ExceptionHandlerInterceptor</class> | |
| 9 | - </interceptors> | |
| 10 | - | |
| 11 | -</beans> |
impl/extension/jdbc/pom.xml
| ... | ... | @@ -44,7 +44,7 @@ |
| 44 | 44 | <parent> |
| 45 | 45 | <groupId>br.gov.frameworkdemoiselle</groupId> |
| 46 | 46 | <artifactId>demoiselle-extension-parent</artifactId> |
| 47 | - <version>2.4.0-BETA3-SNAPSHOT</version> | |
| 47 | + <version>2.4.0-BETA4-SNAPSHOT</version> | |
| 48 | 48 | <relativePath>../../../parent/extension</relativePath> |
| 49 | 49 | </parent> |
| 50 | 50 | ... | ... |
impl/extension/jdbc/src/main/java/br/gov/frameworkdemoiselle/transaction/JDBCTransaction.java
| ... | ... | @@ -45,6 +45,7 @@ import java.util.Collections; |
| 45 | 45 | import java.util.HashMap; |
| 46 | 46 | import java.util.Map; |
| 47 | 47 | |
| 48 | +import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 48 | 49 | import br.gov.frameworkdemoiselle.annotation.Priority; |
| 49 | 50 | import br.gov.frameworkdemoiselle.internal.producer.ConnectionProducer; |
| 50 | 51 | import br.gov.frameworkdemoiselle.util.Beans; |
| ... | ... | @@ -97,7 +98,7 @@ public class JDBCTransaction implements Transaction { |
| 97 | 98 | try { |
| 98 | 99 | connection.commit(); |
| 99 | 100 | } catch (Exception cause) { |
| 100 | - throw new TransactionException(cause); | |
| 101 | + throw new DemoiselleException(cause); | |
| 101 | 102 | } |
| 102 | 103 | } |
| 103 | 104 | } |
| ... | ... | @@ -108,7 +109,7 @@ public class JDBCTransaction implements Transaction { |
| 108 | 109 | try { |
| 109 | 110 | connection.rollback(); |
| 110 | 111 | } catch (Exception cause) { |
| 111 | - throw new TransactionException(cause); | |
| 112 | + throw new DemoiselleException(cause); | |
| 112 | 113 | } |
| 113 | 114 | } |
| 114 | 115 | } | ... | ... |
impl/extension/jmx/pom.xml
| ... | ... | @@ -34,8 +34,7 @@ |
| 34 | 34 | ou escreva para a Fundação do Software Livre (FSF) Inc., |
| 35 | 35 | 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. |
| 36 | 36 | --> |
| 37 | -<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
| 38 | - xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 37 | +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
| 39 | 38 | <modelVersion>4.0.0</modelVersion> |
| 40 | 39 | |
| 41 | 40 | <artifactId>demoiselle-jmx</artifactId> |
| ... | ... | @@ -45,7 +44,7 @@ |
| 45 | 44 | <parent> |
| 46 | 45 | <artifactId>demoiselle-extension-parent</artifactId> |
| 47 | 46 | <groupId>br.gov.frameworkdemoiselle</groupId> |
| 48 | - <version>2.4.0-BETA2-SNAPSHOT</version> | |
| 47 | + <version>2.4.0-BETA4-SNAPSHOT</version> | |
| 49 | 48 | <relativePath>../../../parent/extension</relativePath> |
| 50 | 49 | </parent> |
| 51 | 50 | ... | ... |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/jmx/internal/DynamicMBeanProxy.java
| ... | ... | @@ -79,7 +79,7 @@ public class DynamicMBeanProxy implements DynamicMBean { |
| 79 | 79 | |
| 80 | 80 | private ManagedType managedType; |
| 81 | 81 | |
| 82 | - private ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-jmx-bundle", Locale.getDefault()); | |
| 82 | + private ResourceBundle bundle = new ResourceBundleProducer().create("demoiselle-jmx-bundle", Locale.getDefault()); | |
| 83 | 83 | |
| 84 | 84 | public DynamicMBeanProxy(ManagedType type) { |
| 85 | 85 | if (type == null) { | ... | ... |
impl/extension/jmx/src/main/java/br/gov/frameworkdemoiselle/jmx/internal/MBeanHelper.java
| ... | ... | @@ -59,7 +59,7 @@ public class MBeanHelper { |
| 59 | 59 | |
| 60 | 60 | private static final Logger logger = LoggerProducer.create(MBeanHelper.class); |
| 61 | 61 | |
| 62 | - private static ResourceBundle bundle = ResourceBundleProducer.create("demoiselle-jmx-bundle", Locale.getDefault()); | |
| 62 | + private static ResourceBundle bundle = new ResourceBundleProducer().create("demoiselle-jmx-bundle", Locale.getDefault()); | |
| 63 | 63 | |
| 64 | 64 | private static final MBeanServer server = ManagementFactory.getPlatformMBeanServer(); |
| 65 | 65 | ... | ... |
impl/extension/jmx/src/test/java/management/tests/internal/DynamicMBeanProxyTestCase.java
| ... | ... | @@ -52,12 +52,15 @@ import org.jboss.arquillian.container.test.api.Deployment; |
| 52 | 52 | import org.jboss.arquillian.junit.Arquillian; |
| 53 | 53 | import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 54 | 54 | import org.jboss.shrinkwrap.api.asset.FileAsset; |
| 55 | -import org.jboss.shrinkwrap.api.exporter.ZipExporter; | |
| 56 | 55 | import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 56 | +import org.junit.AfterClass; | |
| 57 | +import org.junit.BeforeClass; | |
| 57 | 58 | import org.junit.Test; |
| 58 | 59 | import org.junit.runner.RunWith; |
| 59 | 60 | |
| 60 | 61 | import br.gov.frameworkdemoiselle.jmx.internal.MBeanManager; |
| 62 | +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | |
| 63 | +import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; | |
| 61 | 64 | import br.gov.frameworkdemoiselle.util.Beans; |
| 62 | 65 | |
| 63 | 66 | @RunWith(Arquillian.class) |
| ... | ... | @@ -73,12 +76,21 @@ public class DynamicMBeanProxyTestCase { |
| 73 | 76 | .addPackages(false, DynamicMBeanProxyTestCase.class.getPackage()) |
| 74 | 77 | .addClasses(LocaleProducer.class, ManagedTestClass.class); |
| 75 | 78 | |
| 76 | - mainDeployment.as(ZipExporter.class).exportTo( | |
| 77 | - new File("/home/81986912515/myPackage.jar"), true); | |
| 78 | - | |
| 79 | 79 | return mainDeployment; |
| 80 | 80 | } |
| 81 | 81 | |
| 82 | + @BeforeClass | |
| 83 | + public static void fireEventStartupProccess() { | |
| 84 | + Beans.getBeanManager().fireEvent(new AfterStartupProccess() { | |
| 85 | + }); | |
| 86 | + } | |
| 87 | + | |
| 88 | + @AfterClass | |
| 89 | + public static void fireEventShutdownProccess() { | |
| 90 | + Beans.getBeanManager().fireEvent(new AfterShutdownProccess() { | |
| 91 | + }); | |
| 92 | + } | |
| 93 | + | |
| 82 | 94 | /** |
| 83 | 95 | * Testa se o bootstrap está corretamente carregando e registrando classes anotadas com {@link Managed} como MBeans. |
| 84 | 96 | */ | ... | ... |
impl/extension/jmx/src/test/java/management/tests/internal/NotificationBroadcasterTestCase.java
| ... | ... | @@ -55,11 +55,15 @@ import org.jboss.arquillian.junit.Arquillian; |
| 55 | 55 | import org.jboss.shrinkwrap.api.ShrinkWrap; |
| 56 | 56 | import org.jboss.shrinkwrap.api.asset.FileAsset; |
| 57 | 57 | import org.jboss.shrinkwrap.api.spec.JavaArchive; |
| 58 | +import org.junit.AfterClass; | |
| 59 | +import org.junit.BeforeClass; | |
| 58 | 60 | import org.junit.Test; |
| 59 | 61 | import org.junit.runner.RunWith; |
| 60 | 62 | |
| 61 | 63 | import br.gov.frameworkdemoiselle.jmx.configuration.JMXConfig; |
| 62 | 64 | import br.gov.frameworkdemoiselle.jmx.internal.MBeanManager; |
| 65 | +import br.gov.frameworkdemoiselle.lifecycle.AfterShutdownProccess; | |
| 66 | +import br.gov.frameworkdemoiselle.lifecycle.AfterStartupProccess; | |
| 63 | 67 | import br.gov.frameworkdemoiselle.management.AttributeChangeNotification; |
| 64 | 68 | import br.gov.frameworkdemoiselle.management.GenericNotification; |
| 65 | 69 | import br.gov.frameworkdemoiselle.management.NotificationManager; |
| ... | ... | @@ -67,7 +71,7 @@ import br.gov.frameworkdemoiselle.util.Beans; |
| 67 | 71 | |
| 68 | 72 | @RunWith(Arquillian.class) |
| 69 | 73 | public class NotificationBroadcasterTestCase { |
| 70 | - | |
| 74 | + | |
| 71 | 75 | @Deployment |
| 72 | 76 | public static JavaArchive createDeployment() { |
| 73 | 77 | JavaArchive mainDeployment = ShrinkWrap.create(JavaArchive.class); |
| ... | ... | @@ -80,129 +84,140 @@ public class NotificationBroadcasterTestCase { |
| 80 | 84 | |
| 81 | 85 | return mainDeployment; |
| 82 | 86 | } |
| 83 | - | |
| 87 | + | |
| 88 | + @BeforeClass | |
| 89 | + public static void fireEventStartupProccess() { | |
| 90 | + Beans.getBeanManager().fireEvent(new AfterStartupProccess() { | |
| 91 | + }); | |
| 92 | + } | |
| 93 | + | |
| 94 | + @AfterClass | |
| 95 | + public static void fireEventShutdownProccess() { | |
| 96 | + Beans.getBeanManager().fireEvent(new AfterShutdownProccess() { | |
| 97 | + }); | |
| 98 | + } | |
| 99 | + | |
| 84 | 100 | /** |
| 85 | 101 | * Testa o envio de uma mensagem para clientes conectados |
| 86 | 102 | */ |
| 87 | 103 | @Test |
| 88 | - public void sendMessageTest(){ | |
| 104 | + public void sendMessageTest() { | |
| 89 | 105 | JMXConfig config = Beans.getReference(JMXConfig.class); |
| 90 | - | |
| 91 | - //Este será o lado cliente. Este manager é usado para enviar notificações a partir do código da aplicação | |
| 106 | + | |
| 107 | + // Este será o lado cliente. Este manager é usado para enviar notificações a partir do código da aplicação | |
| 92 | 108 | NotificationManager notificationManager = Beans.getReference(NotificationManager.class); |
| 93 | - | |
| 94 | - //Obtém o servidor MBean onde anexaremos um listener para a notificação | |
| 109 | + | |
| 110 | + // Obtém o servidor MBean onde anexaremos um listener para a notificação | |
| 95 | 111 | MBeanServer server = ManagementFactory.getPlatformMBeanServer(); |
| 96 | - | |
| 97 | - //Aqui obtemos o MBean de notificações já registrado pelo bootstrap | |
| 112 | + | |
| 113 | + // Aqui obtemos o MBean de notificações já registrado pelo bootstrap | |
| 98 | 114 | StringBuffer notificationMBeanName = new StringBuffer() |
| 99 | - .append( config.getNotificationDomain()!=null ? config.getNotificationDomain() : "br.gov.frameworkdemoiselle.jmx" ) | |
| 100 | - .append(":name=") | |
| 101 | - .append( config.getNotificationMBeanName()); | |
| 102 | - | |
| 115 | + .append(config.getNotificationDomain() != null ? config.getNotificationDomain() | |
| 116 | + : "br.gov.frameworkdemoiselle.jmx").append(":name=").append(config.getNotificationMBeanName()); | |
| 117 | + | |
| 103 | 118 | ObjectName name = null; |
| 104 | 119 | try { |
| 105 | 120 | name = new ObjectName(notificationMBeanName.toString()); |
| 106 | 121 | } catch (MalformedObjectNameException e) { |
| 107 | 122 | Assert.fail(); |
| 108 | 123 | } |
| 109 | - | |
| 110 | - //StringBuffer vazio | |
| 124 | + | |
| 125 | + // StringBuffer vazio | |
| 111 | 126 | StringBuffer notificationBuffer = new StringBuffer(); |
| 112 | - | |
| 113 | - //Este notification listener será chamado quando o Demoiselle enviar a notificação e vai colocar | |
| 114 | - //a mensagem enviada em "notificationBuffer" | |
| 127 | + | |
| 128 | + // Este notification listener será chamado quando o Demoiselle enviar a notificação e vai colocar | |
| 129 | + // a mensagem enviada em "notificationBuffer" | |
| 115 | 130 | NotificationListener listener = new TestNotificationListener(notificationBuffer); |
| 116 | - | |
| 131 | + | |
| 117 | 132 | try { |
| 118 | - //Anexa o listener no servidor MBean | |
| 119 | - server.addNotificationListener(name,listener,null,null); | |
| 133 | + // Anexa o listener no servidor MBean | |
| 134 | + server.addNotificationListener(name, listener, null, null); | |
| 120 | 135 | } catch (InstanceNotFoundException e) { |
| 121 | 136 | Assert.fail(); |
| 122 | 137 | } |
| 123 | - | |
| 124 | - //Manda a notificação pelo Demoiselle | |
| 138 | + | |
| 139 | + // Manda a notificação pelo Demoiselle | |
| 125 | 140 | GenericNotification n = new GenericNotification("Notification test successful"); |
| 126 | 141 | notificationManager.sendNotification(n); |
| 127 | - | |
| 128 | - //Se o componente funcionou, o Demoiselle propagou a notificação para o servidor MBean e o listener preencheu | |
| 129 | - //o StringBuffer com nossa mensagem. | |
| 142 | + | |
| 143 | + // Se o componente funcionou, o Demoiselle propagou a notificação para o servidor MBean e o listener preencheu | |
| 144 | + // o StringBuffer com nossa mensagem. | |
| 130 | 145 | Assert.assertEquals("Notification test successful", notificationBuffer.toString()); |
| 131 | - | |
| 146 | + | |
| 132 | 147 | } |
| 133 | - | |
| 148 | + | |
| 134 | 149 | /** |
| 135 | 150 | * Testa o envio de uma mensagem de mudança de atributo para clientes conectados |
| 136 | 151 | */ |
| 137 | 152 | @Test |
| 138 | - public void sendAttributeChangedMessageTest(){ | |
| 153 | + public void sendAttributeChangedMessageTest() { | |
| 139 | 154 | JMXConfig config = Beans.getReference(JMXConfig.class); |
| 140 | - | |
| 141 | - //Obtém o servidor MBean onde anexaremos um listener para a notificação | |
| 155 | + | |
| 156 | + // Obtém o servidor MBean onde anexaremos um listener para a notificação | |
| 142 | 157 | MBeanServer server = ManagementFactory.getPlatformMBeanServer(); |
| 143 | - | |
| 158 | + | |
| 144 | 159 | NotificationManager notificationManager = Beans.getReference(NotificationManager.class); |
| 145 | 160 | MBeanManager mBeanManager = Beans.getReference(MBeanManager.class); |
| 146 | - | |
| 147 | - //Aqui obtemos o MBean de notificações já registrado pelo bootstrap | |
| 161 | + | |
| 162 | + // Aqui obtemos o MBean de notificações já registrado pelo bootstrap | |
| 148 | 163 | StringBuffer notificationMBeanName = new StringBuffer() |
| 149 | - .append( config.getNotificationDomain()!=null ? config.getNotificationDomain() : "br.gov.frameworkdemoiselle.jmx" ) | |
| 150 | - .append(":name=") | |
| 151 | - .append( config.getNotificationMBeanName()); | |
| 164 | + .append(config.getNotificationDomain() != null ? config.getNotificationDomain() | |
| 165 | + : "br.gov.frameworkdemoiselle.jmx").append(":name=").append(config.getNotificationMBeanName()); | |
| 152 | 166 | ObjectInstance instance = mBeanManager.findMBeanInstance(notificationMBeanName.toString()); |
| 153 | - | |
| 154 | - //StringBuffer vazio | |
| 167 | + | |
| 168 | + // StringBuffer vazio | |
| 155 | 169 | StringBuffer notificationBuffer = new StringBuffer(); |
| 156 | - | |
| 157 | - //Este notification listener será chamado quando o Demoiselle enviar a notificação e vai colocar | |
| 158 | - //a mensagem enviada em "notificationBuffer" | |
| 170 | + | |
| 171 | + // Este notification listener será chamado quando o Demoiselle enviar a notificação e vai colocar | |
| 172 | + // a mensagem enviada em "notificationBuffer" | |
| 159 | 173 | NotificationListener listener = new TestNotificationListener(notificationBuffer); |
| 160 | - | |
| 174 | + | |
| 161 | 175 | try { |
| 162 | - //Anexa o listener no servidor MBean | |
| 163 | - server.addNotificationListener(instance.getObjectName(),listener,null,null); | |
| 176 | + // Anexa o listener no servidor MBean | |
| 177 | + server.addNotificationListener(instance.getObjectName(), listener, null, null); | |
| 164 | 178 | } catch (InstanceNotFoundException e) { |
| 165 | 179 | Assert.fail(); |
| 166 | 180 | } |
| 167 | - | |
| 168 | - //Manda a notificação pelo Demoiselle | |
| 169 | - AttributeChangeNotification notification = new AttributeChangeNotification("Attribute Changed","name",String.class,"Demoiselle 1","Demoiselle 2"); | |
| 181 | + | |
| 182 | + // Manda a notificação pelo Demoiselle | |
| 183 | + AttributeChangeNotification notification = new AttributeChangeNotification("Attribute Changed", "name", | |
| 184 | + String.class, "Demoiselle 1", "Demoiselle 2"); | |
| 170 | 185 | notificationManager.sendNotification(notification); |
| 171 | - | |
| 172 | - //Se o componente funcionou, o Demoiselle propagou a notificação para o servidor MBean e o listener preencheu | |
| 173 | - //o StringBuffer com nossa mensagem. | |
| 186 | + | |
| 187 | + // Se o componente funcionou, o Demoiselle propagou a notificação para o servidor MBean e o listener preencheu | |
| 188 | + // o StringBuffer com nossa mensagem. | |
| 174 | 189 | Assert.assertEquals("Attribute Changed: name = Demoiselle 2", notificationBuffer.toString()); |
| 175 | - | |
| 190 | + | |
| 176 | 191 | } |
| 177 | - | |
| 192 | + | |
| 178 | 193 | /** |
| 179 | - * Implementação do {@link NotificationListener} do Java que vai por qualquer notificação recebida em um StringBuffer. | |
| 194 | + * Implementação do {@link NotificationListener} do Java que vai por qualquer notificação recebida em um | |
| 195 | + * StringBuffer. | |
| 180 | 196 | * |
| 181 | 197 | * @author serpro |
| 182 | - * | |
| 183 | 198 | */ |
| 184 | 199 | class TestNotificationListener implements NotificationListener { |
| 185 | - | |
| 200 | + | |
| 186 | 201 | StringBuffer message; |
| 187 | - | |
| 188 | - public TestNotificationListener(StringBuffer testMessage){ | |
| 202 | + | |
| 203 | + public TestNotificationListener(StringBuffer testMessage) { | |
| 189 | 204 | this.message = testMessage; |
| 190 | 205 | } |
| 191 | 206 | |
| 192 | 207 | @Override |
| 193 | 208 | public void handleNotification(javax.management.Notification notification, Object handback) { |
| 194 | - if (message!=null){ | |
| 209 | + if (message != null) { | |
| 195 | 210 | message.append(notification.getMessage()); |
| 196 | - | |
| 197 | - if (notification instanceof javax.management.AttributeChangeNotification){ | |
| 211 | + | |
| 212 | + if (notification instanceof javax.management.AttributeChangeNotification) { | |
| 198 | 213 | message.append(": ") |
| 199 | - .append( ((javax.management.AttributeChangeNotification)notification).getAttributeName() ) | |
| 200 | - .append(" = ") | |
| 201 | - .append(((javax.management.AttributeChangeNotification)notification).getNewValue()); | |
| 214 | + .append(((javax.management.AttributeChangeNotification) notification).getAttributeName()) | |
| 215 | + .append(" = ") | |
| 216 | + .append(((javax.management.AttributeChangeNotification) notification).getNewValue()); | |
| 202 | 217 | } |
| 203 | 218 | } |
| 204 | 219 | } |
| 205 | - | |
| 220 | + | |
| 206 | 221 | } |
| 207 | 222 | |
| 208 | 223 | } | ... | ... |
impl/extension/jpa/.gitignore
impl/extension/jpa/pom.xml
| ... | ... | @@ -36,7 +36,6 @@ |
| 36 | 36 | --> |
| 37 | 37 | <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> |
| 38 | 38 | |
| 39 | - | |
| 40 | 39 | <modelVersion>4.0.0</modelVersion> |
| 41 | 40 | |
| 42 | 41 | <artifactId>demoiselle-jpa</artifactId> |
| ... | ... | @@ -45,7 +44,7 @@ |
| 45 | 44 | <parent> |
| 46 | 45 | <groupId>br.gov.frameworkdemoiselle</groupId> |
| 47 | 46 | <artifactId>demoiselle-extension-parent</artifactId> |
| 48 | - <version>2.4.0-BETA3-SNAPSHOT</version> | |
| 47 | + <version>2.4.0-BETA4-SNAPSHOT</version> | |
| 49 | 48 | <relativePath>../../../parent/extension</relativePath> |
| 50 | 49 | </parent> |
| 51 | 50 | |
| ... | ... | @@ -67,27 +66,278 @@ |
| 67 | 66 | <url>http://www.serpro.gov.br</url> |
| 68 | 67 | </organization> |
| 69 | 68 | |
| 69 | + <build> | |
| 70 | + <testResources> | |
| 71 | + <testResource> | |
| 72 | + <directory>src/test/resources</directory> | |
| 73 | + <filtering>true</filtering> | |
| 74 | + </testResource> | |
| 75 | + </testResources> | |
| 76 | + | |
| 77 | + <plugins> | |
| 78 | + <plugin> | |
| 79 | + <artifactId>maven-dependency-plugin</artifactId> | |
| 80 | + <executions> | |
| 81 | + <execution> | |
| 82 | + <id>unpack</id> | |
| 83 | + <phase>process-test-classes</phase> | |
| 84 | + <goals> | |
| 85 | + <goal>unpack</goal> | |
| 86 | + </goals> | |
| 87 | + <configuration> | |
| 88 | + <artifactItems> | |
| 89 | + <artifactItem> | |
| 90 | + <groupId>org.jboss.as</groupId> | |
| 91 | + <artifactId>jboss-as-dist</artifactId> | |
| 92 | + <version>${jbossas.version}</version> | |
| 93 | + <type>zip</type> | |
| 94 | + <overWrite>false</overWrite> | |
| 95 | + <outputDirectory>target</outputDirectory> | |
| 96 | + </artifactItem> | |
| 97 | + </artifactItems> | |
| 98 | + </configuration> | |
| 99 | + </execution> | |
| 100 | + </executions> | |
| 101 | + </plugin> | |
| 102 | + <!-- | |
| 103 | + <plugin> | |
| 104 | + <artifactId>maven-surefire-plugin</artifactId> | |
| 105 | + <version>2.12.4</version> | |
| 106 | + <configuration> | |
| 107 | + <environmentVariables> | |
| 108 | + <JBOSS_HOME>${project.build.directory}/jboss-as-${jbossas.version}</JBOSS_HOME> | |
| 109 | + </environmentVariables> | |
| 110 | + <systemProperties> | |
| 111 | + <jboss.version>${jbossas.version}</jboss.version> | |
| 112 | + </systemProperties> | |
| 113 | + </configuration> | |
| 114 | + </plugin> | |
| 115 | + <plugin> | |
| 116 | + <groupId>org.apache.maven.plugins</groupId> | |
| 117 | + <artifactId>maven-dependency-plugin</artifactId> | |
| 118 | + <executions> | |
| 119 | + <execution> | |
| 120 | + <id>unpack</id> | |
| 121 | + <phase>process-test-classes</phase> | |
| 122 | + <goals> | |
| 123 | + <goal>unpack</goal> | |
| 124 | + </goals> | |
| 125 | + <configuration> | |
| 126 | + <artifactItems> | |
| 127 | + <artifactItem> | |
| 128 | + <groupId>org.jboss.as</groupId> | |
| 129 | + <artifactId>jboss-as-dist</artifactId> | |
| 130 | + <version>${jbossas.version}</version> | |
| 131 | + <type>zip</type> | |
| 132 | + <overWrite>false</overWrite> | |
| 133 | + <outputDirectory>${project.build.directory}</outputDirectory> | |
| 134 | + </artifactItem> | |
| 135 | + </artifactItems> | |
| 136 | + </configuration> | |
| 137 | + </execution> | |
| 138 | + </executions> | |
| 139 | + </plugin> | |
| 140 | + --> | |
| 141 | + <!-- | |
| 142 | + <plugin> | |
| 143 | + | |
| 144 | + <groupId>org.apache.maven.plugins</groupId> | |
| 145 | + <artifactId>maven-surefire-plugin</artifactId> | |
| 146 | + <configuration> | |
| 147 | + <systemPropertyVariables> | |
| 148 | + <tomee.httpPort>-1</tomee.httpPort> | |
| 149 | + <tomee.stopPort>-1</tomee.stopPort> | |
| 150 | + </systemPropertyVariables> | |
| 151 | + </configuration> | |
| 152 | + </plugin> | |
| 153 | + --> | |
| 154 | + <!-- | |
| 155 | + <plugin> | |
| 156 | + <groupId>org.apache.maven.plugins</groupId> | |
| 157 | + <artifactId>maven-surefire-plugin</artifactId> | |
| 158 | + <version>2.12</version> | |
| 159 | + <configuration> | |
| 160 | + <systemPropertyVariables> | |
| 161 | + <java.util.logging.config.file> | |
| 162 | + ${project.build.testOutputDirectory}/logging.properties | |
| 163 | + </java.util.logging.config.file> | |
| 164 | + <derby.stream.error.file> | |
| 165 | + ${project.build.directory}/derby.log | |
| 166 | + </derby.stream.error.file> | |
| 167 | + </systemPropertyVariables> | |
| 168 | + </configuration> | |
| 169 | + </plugin> | |
| 170 | + --> | |
| 171 | + <plugin> | |
| 172 | + <groupId>org.apache.maven.plugins</groupId> | |
| 173 | + <artifactId>maven-surefire-plugin</artifactId> | |
| 174 | + <version>2.16</version> | |
| 175 | + </plugin> | |
| 176 | + </plugins> | |
| 177 | + </build> | |
| 178 | + | |
| 70 | 179 | <dependencies> |
| 71 | 180 | <dependency> |
| 72 | 181 | <groupId>org.eclipse.persistence</groupId> |
| 73 | 182 | <artifactId>javax.persistence</artifactId> |
| 74 | 183 | </dependency> |
| 184 | + | |
| 185 | + <!-- for tests --> | |
| 75 | 186 | <dependency> |
| 76 | - <groupId>org.hibernate</groupId> | |
| 77 | - <artifactId>hibernate-entitymanager</artifactId> | |
| 187 | + <groupId>junit</groupId> | |
| 188 | + <artifactId>junit</artifactId> | |
| 78 | 189 | <scope>test</scope> |
| 79 | 190 | </dependency> |
| 80 | 191 | <dependency> |
| 81 | - <groupId>org.hibernate</groupId> | |
| 82 | - <artifactId>hibernate-validator</artifactId> | |
| 192 | + <groupId>org.jboss.arquillian.junit</groupId> | |
| 193 | + <artifactId>arquillian-junit-container</artifactId> | |
| 194 | + <scope>test</scope> | |
| 195 | + </dependency> | |
| 196 | + | |
| 197 | + <!-- | |
| 198 | + <dependency> | |
| 199 | + <groupId>org.jboss.as</groupId> | |
| 200 | + <artifactId>jboss-as-arquillian-container-embedded</artifactId> | |
| 201 | + <version>7.2.0.Final</version> | |
| 202 | + <scope>test</scope> | |
| 203 | + </dependency> | |
| 204 | + --> | |
| 205 | + | |
| 206 | + <dependency> | |
| 207 | + <groupId>org.jboss.as</groupId> | |
| 208 | + <artifactId>jboss-as-arquillian-container-managed</artifactId> | |
| 209 | + <version>${jbossas.version}</version> | |
| 210 | + <scope>test</scope> | |
| 211 | + </dependency> | |
| 212 | + <dependency> | |
| 213 | + <groupId>org.jboss.arquillian.protocol</groupId> | |
| 214 | + <artifactId>arquillian-protocol-servlet</artifactId> | |
| 215 | + </dependency> | |
| 216 | + | |
| 217 | + <!-- | |
| 218 | + <dependency> | |
| 219 | + <groupId>org.apache.openejb</groupId> | |
| 220 | + <artifactId>arquillian-tomee-embedded</artifactId> | |
| 221 | + <version>1.5.2</version> | |
| 222 | + </dependency> | |
| 223 | + --> | |
| 224 | + | |
| 225 | + <!-- | |
| 226 | + <dependency> | |
| 227 | + <groupId>org.jboss.arquillian.container</groupId> | |
| 228 | + <artifactId>arquillian-glassfish-embedded-3.1</artifactId> | |
| 83 | 229 | <scope>test</scope> |
| 84 | 230 | </dependency> |
| 231 | + <dependency> | |
| 232 | + <groupId>org.glassfish.main.extras</groupId> | |
| 233 | + <artifactId>glassfish-embedded-web</artifactId> | |
| 234 | + <scope>test</scope> | |
| 235 | + </dependency> | |
| 236 | + <dependency> | |
| 237 | + <groupId>org.glassfish.main.extras</groupId> | |
| 238 | + <artifactId>glassfish-embedded-all</artifactId> | |
| 239 | + <version>3.1.2</version> | |
| 240 | + <scope>test</scope> | |
| 241 | + </dependency> | |
| 242 | + --> | |
| 85 | 243 | |
| 244 | + <!-- | |
| 245 | + <dependency> | |
| 246 | + <groupId>org.jboss.as</groupId> | |
| 247 | + <artifactId>jboss-as-arquillian-container-managed</artifactId> | |
| 248 | + <version>7.1.1.Final</version> | |
| 249 | + <scope>test</scope> | |
| 250 | + </dependency> | |
| 251 | + <dependency> | |
| 252 | + <groupId>org.jboss.arquillian.protocol</groupId> | |
| 253 | + <artifactId>arquillian-protocol-servlet</artifactId> | |
| 254 | + <scope>test</scope> | |
| 255 | + </dependency> | |
| 256 | + --> | |
| 257 | + | |
| 258 | + <!-- | |
| 259 | + <dependency> | |
| 260 | + <groupId>org.jboss.as</groupId> | |
| 261 | + <artifactId>jboss-as-arquillian-container-managed</artifactId> | |
| 262 | + <version>7.1.1.Final</version> | |
| 263 | + <scope>test</scope> | |
| 264 | + </dependency> | |
| 265 | + <dependency> | |
| 266 | + <groupId>org.jboss.arquillian.protocol</groupId> | |
| 267 | + <artifactId>arquillian-protocol-servlet</artifactId> | |
| 268 | + <scope>test</scope> | |
| 269 | + </dependency> | |
| 270 | + --> | |
| 271 | + | |
| 272 | + <dependency> | |
| 273 | + <groupId>org.jboss.shrinkwrap.resolver</groupId> | |
| 274 | + <artifactId>shrinkwrap-resolver-impl-maven</artifactId> | |
| 275 | + <scope>test</scope> | |
| 276 | + </dependency> | |
| 277 | + <!-- | |
| 278 | + <dependency> | |
| 279 | + <groupId>org.jboss.shrinkwrap.resolver</groupId> | |
| 280 | + <artifactId>shrinkwrap-resolver-depchain</artifactId> | |
| 281 | + <type>pom</type> | |
| 282 | + <scope>test</scope> | |
| 283 | + </dependency> | |
| 284 | + --> | |
| 285 | + | |
| 286 | + <!-- | |
| 287 | + <dependency> | |
| 288 | + <groupId>org.apache.openejb</groupId> | |
| 289 | + <artifactId>arquillian-tomee-embedded</artifactId> | |
| 290 | + <version>1.5.2</version> | |
| 291 | + </dependency> | |
| 292 | + <dependency> | |
| 293 | + <groupId>org.apache.openejb</groupId> | |
| 294 | + <artifactId>tomee-embedded</artifactId> | |
| 295 | + <version>1.5.2</version> | |
| 296 | + </dependency> | |
| 297 | + --> | |
| 298 | + | |
| 299 | + <!-- | |
| 300 | + <dependency> | |
| 301 | + <groupId>org.jboss.arquillian.extension</groupId> | |
| 302 | + <artifactId>arquillian-persistence-impl</artifactId> | |
| 303 | + <scope>test</scope> | |
| 304 | + <exclusions> | |
| 305 | + <exclusion> | |
| 306 | + <artifactId>log4j</artifactId> | |
| 307 | + <groupId>log4j</groupId> | |
| 308 | + </exclusion> | |
| 309 | + </exclusions> | |
| 310 | + </dependency> | |
| 311 | + --> | |
| 312 | + | |
| 313 | + <!-- | |
| 86 | 314 | <dependency> |
| 87 | 315 | <groupId>hsqldb</groupId> |
| 88 | 316 | <artifactId>hsqldb</artifactId> |
| 89 | 317 | <scope>test</scope> |
| 90 | 318 | </dependency> |
| 319 | + --> | |
| 320 | + | |
| 321 | + <!-- | |
| 322 | + <dependency> | |
| 323 | + <groupId>org.slf4j</groupId> | |
| 324 | + <artifactId>slf4j-log4j12</artifactId> | |
| 325 | + <scope>test</scope> | |
| 326 | + </dependency> | |
| 327 | + --> | |
| 328 | + | |
| 329 | + <!-- | |
| 330 | + <dependency> | |
| 331 | + <groupId>org.hibernate</groupId> | |
| 332 | + <artifactId>hibernate-entitymanager</artifactId> | |
| 333 | + <scope>test</scope> | |
| 334 | + </dependency> | |
| 335 | + <dependency> | |
| 336 | + <groupId>org.hibernate</groupId> | |
| 337 | + <artifactId>hibernate-validator</artifactId> | |
| 338 | + <scope>test</scope> | |
| 339 | + </dependency> | |
| 340 | + --> | |
| 91 | 341 | </dependencies> |
| 92 | 342 | |
| 93 | 343 | <repositories> |
| ... | ... | @@ -114,4 +364,46 @@ |
| 114 | 364 | </releases> |
| 115 | 365 | </repository> |
| 116 | 366 | </repositories> |
| 367 | + | |
| 368 | + <profiles> | |
| 369 | + <profile> | |
| 370 | + <id>arquillian-test</id> | |
| 371 | + | |
| 372 | + <dependencies> | |
| 373 | + <dependency> | |
| 374 | + <groupId>br.gov.frameworkdemoiselle</groupId> | |
| 375 | + <artifactId>demoiselle-core</artifactId> | |
| 376 | + <exclusions> | |
| 377 | + <exclusion> | |
| 378 | + <groupId>javax.enterprise</groupId> | |
| 379 | + <artifactId>cdi-api</artifactId> | |
| 380 | + </exclusion> | |
| 381 | + <exclusion> | |
| 382 | + <artifactId>validation-api</artifactId> | |
| 383 | + <groupId>javax.validation</groupId> | |
| 384 | + </exclusion> | |
| 385 | + <exclusion> | |
| 386 | + <groupId>org.slf4j</groupId> | |
| 387 | + <artifactId>slf4j-api</artifactId> | |
| 388 | + </exclusion> | |
| 389 | + <!-- | |
| 390 | + --> | |
| 391 | + <exclusion> | |
| 392 | + <groupId>org.javassist</groupId> | |
| 393 | + <artifactId>javassist</artifactId> | |
| 394 | + </exclusion> | |
| 395 | + </exclusions> | |
| 396 | + </dependency> | |
| 397 | + <dependency> | |
| 398 | + <groupId>org.eclipse.persistence</groupId> | |
| 399 | + <artifactId>javax.persistence</artifactId> | |
| 400 | + <scope>provided</scope> | |
| 401 | + </dependency> | |
| 402 | + </dependencies> | |
| 403 | + </profile> | |
| 404 | + </profiles> | |
| 405 | + | |
| 406 | + <properties> | |
| 407 | + <jbossas.version>7.1.1.Final</jbossas.version> | |
| 408 | + </properties> | |
| 117 | 409 | </project> | ... | ... |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerFactoryProducer.java
| ... | ... | @@ -26,6 +26,7 @@ import br.gov.frameworkdemoiselle.annotation.Name; |
| 26 | 26 | import br.gov.frameworkdemoiselle.util.ResourceBundle; |
| 27 | 27 | |
| 28 | 28 | @ApplicationScoped |
| 29 | +// @StaticScoped | |
| 29 | 30 | public class EntityManagerFactoryProducer implements Serializable { |
| 30 | 31 | |
| 31 | 32 | private static final long serialVersionUID = 1L; | ... | ... |
impl/extension/jpa/src/main/java/br/gov/frameworkdemoiselle/transaction/JPATransaction.java
| ... | ... | @@ -124,8 +124,11 @@ public class JPATransaction implements Transaction { |
| 124 | 124 | public boolean isActive() { |
| 125 | 125 | boolean active = false; |
| 126 | 126 | |
| 127 | + EntityTransaction transaction; | |
| 127 | 128 | for (EntityManager entityManager : getDelegate()) { |
| 128 | - if (entityManager.getTransaction().isActive()) { | |
| 129 | + transaction = entityManager.getTransaction(); | |
| 130 | + | |
| 131 | + if (transaction.isActive()) { | |
| 129 | 132 | active = true; |
| 130 | 133 | break; |
| 131 | 134 | } | ... | ... |
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/domain/Client.java
| ... | ... | @@ -1,65 +0,0 @@ |
| 1 | -package br.gov.frameworkdemoiselle.domain; | |
| 2 | - | |
| 3 | -import java.io.Serializable; | |
| 4 | -import java.util.Date; | |
| 5 | - | |
| 6 | -import javax.persistence.Entity; | |
| 7 | -import javax.persistence.GeneratedValue; | |
| 8 | -import javax.persistence.Id; | |
| 9 | -import javax.persistence.Temporal; | |
| 10 | -import javax.persistence.TemporalType; | |
| 11 | - | |
| 12 | -/** | |
| 13 | - * Simle entity for test classes | |
| 14 | - * @author serpro | |
| 15 | - * | |
| 16 | - */ | |
| 17 | -@Entity | |
| 18 | -public class Client implements Serializable { | |
| 19 | - | |
| 20 | - private static final long serialVersionUID = 1L; | |
| 21 | - | |
| 22 | - private Long id; | |
| 23 | - | |
| 24 | - private String name; | |
| 25 | - | |
| 26 | - private Date birthDate; | |
| 27 | - | |
| 28 | - @Id | |
| 29 | - @GeneratedValue | |
| 30 | - public Long getId() { | |
| 31 | - return id; | |
| 32 | - } | |
| 33 | - | |
| 34 | - | |
| 35 | - public void setId(Long id) { | |
| 36 | - this.id = id; | |
| 37 | - } | |
| 38 | - | |
| 39 | - | |
| 40 | - public String getName() { | |
| 41 | - return name; | |
| 42 | - } | |
| 43 | - | |
| 44 | - | |
| 45 | - public void setName(String name) { | |
| 46 | - this.name = name; | |
| 47 | - } | |
| 48 | - | |
| 49 | - | |
| 50 | - @Temporal(TemporalType.DATE) | |
| 51 | - public Date getBirthDate() { | |
| 52 | - return birthDate; | |
| 53 | - } | |
| 54 | - | |
| 55 | - | |
| 56 | - | |
| 57 | - public void setBirthDate(Date birthDate) { | |
| 58 | - this.birthDate = birthDate; | |
| 59 | - } | |
| 60 | - | |
| 61 | - | |
| 62 | - | |
| 63 | - | |
| 64 | - | |
| 65 | -} |
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/domain/Contact.java
| ... | ... | @@ -1,28 +0,0 @@ |
| 1 | -package br.gov.frameworkdemoiselle.domain; | |
| 2 | - | |
| 3 | -import java.io.Serializable; | |
| 4 | - | |
| 5 | -import javax.persistence.Column; | |
| 6 | -import javax.persistence.Entity; | |
| 7 | -import javax.persistence.GeneratedValue; | |
| 8 | -import javax.persistence.Id; | |
| 9 | - | |
| 10 | -@Entity | |
| 11 | -public class Contact implements Serializable { | |
| 12 | - | |
| 13 | - private static final long serialVersionUID = 1L; | |
| 14 | - | |
| 15 | - @Id | |
| 16 | - @GeneratedValue | |
| 17 | - @Column | |
| 18 | - private Long id; | |
| 19 | - | |
| 20 | - public void setId(Long id) { | |
| 21 | - this.id = id; | |
| 22 | - } | |
| 23 | - | |
| 24 | - public Long getId() { | |
| 25 | - return id; | |
| 26 | - } | |
| 27 | - | |
| 28 | -} |
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/configuration/EntityManagerConfigTest.java
| ... | ... | @@ -1,102 +0,0 @@ |
| 1 | -///* | |
| 2 | -// * Demoiselle Framework | |
| 3 | -// * Copyright (C) 2010 SERPRO | |
| 4 | -// * ---------------------------------------------------------------------------- | |
| 5 | -// * This file is part of Demoiselle Framework. | |
| 6 | -// * | |
| 7 | -// * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | -// * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | -// * as published by the Free Software Foundation. | |
| 10 | -// * | |
| 11 | -// * This program is distributed in the hope that it will be useful, | |
| 12 | -// * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | -// * GNU General Public License for more details. | |
| 15 | -// * | |
| 16 | -// * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | -// * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | -// * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | -// * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | -// * ---------------------------------------------------------------------------- | |
| 21 | -// * Este arquivo é parte do Framework Demoiselle. | |
| 22 | -// * | |
| 23 | -// * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | -// * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | -// * do Software Livre (FSF). | |
| 26 | -// * | |
| 27 | -// * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | -// * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | -// * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | -// * para maiores detalhes. | |
| 31 | -// * | |
| 32 | -// * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | -// * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | -// * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | -// * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | -// */ | |
| 37 | -//package br.gov.frameworkdemoiselle.internal.configuration; | |
| 38 | -//import static org.easymock.EasyMock.createMock; | |
| 39 | -//import static org.easymock.EasyMock.expect; | |
| 40 | -//import static org.junit.Assert.assertEquals; | |
| 41 | -// | |
| 42 | -//import java.util.Locale; | |
| 43 | -// | |
| 44 | -//import org.junit.After; | |
| 45 | -//import org.junit.Before; | |
| 46 | -//import org.junit.Test; | |
| 47 | -//import org.junit.runner.RunWith; | |
| 48 | -//import org.powermock.api.easymock.PowerMock; | |
| 49 | -//import org.powermock.core.classloader.annotations.PrepareForTest; | |
| 50 | -//import org.powermock.modules.junit4.PowerMockRunner; | |
| 51 | -//import org.powermock.reflect.Whitebox; | |
| 52 | -//import org.slf4j.Logger; | |
| 53 | -//import org.slf4j.LoggerFactory; | |
| 54 | -// | |
| 55 | -//import br.gov.frameworkdemoiselle.internal.bootstrap.CoreBootstrap; | |
| 56 | -//import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
| 57 | -// | |
| 58 | -///** | |
| 59 | -// * @author e-saito | |
| 60 | -// */ | |
| 61 | -///** | |
| 62 | -// * @author 80342167553 | |
| 63 | -// */ | |
| 64 | -//@RunWith(PowerMockRunner.class) | |
| 65 | -//@PrepareForTest(CoreBootstrap.class) | |
| 66 | -//public class EntityManagerConfigTest { | |
| 67 | -// | |
| 68 | -// private EntityManagerConfig config = new EntityManagerConfig(); | |
| 69 | -// | |
| 70 | -// @Before | |
| 71 | -// public void setUp() throws Exception { | |
| 72 | -// Logger logger = LoggerFactory.getLogger(this.getClass()); | |
| 73 | -// ResourceBundle bundle = new ResourceBundle("demoiselle-core-bundle", Locale.getDefault()); | |
| 74 | -// | |
| 75 | -// ConfigurationLoader configurationLoader = new ConfigurationLoader(); | |
| 76 | -// | |
| 77 | -// Whitebox.setInternalState(configurationLoader, "bundle", bundle); | |
| 78 | -// Whitebox.setInternalState(configurationLoader, "logger", logger); | |
| 79 | -// | |
| 80 | -// CoreBootstrap bootstrap = createMock(CoreBootstrap.class); | |
| 81 | -// expect(bootstrap.isAnnotatedType(config.getClass())).andReturn(true); | |
| 82 | -// PowerMock.replay(bootstrap); | |
| 83 | -// | |
| 84 | -// Whitebox.setInternalState(configurationLoader, "bootstrap", bootstrap); | |
| 85 | -// | |
| 86 | -// configurationLoader.load(config); | |
| 87 | -// } | |
| 88 | -// | |
| 89 | -// @After | |
| 90 | -// public void tearDown() throws Exception { | |
| 91 | -// config = null; | |
| 92 | -// } | |
| 93 | -// | |
| 94 | -// /** | |
| 95 | -// * Test method for | |
| 96 | -// * {@link br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig#getDefaultPersistenceUnitName()}. | |
| 97 | -// */ | |
| 98 | -// @Test | |
| 99 | -// public void testGetDefaultPersistenceUnitName() { | |
| 100 | -// assertEquals("PersistenceUnitName", config.getDefaultPersistenceUnitName()); | |
| 101 | -// } | |
| 102 | -//} |
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerFactoryProducerTest.java
| ... | ... | @@ -1,176 +0,0 @@ |
| 1 | -package br.gov.frameworkdemoiselle.internal.producer; | |
| 2 | - | |
| 3 | -import static org.easymock.EasyMock.createMock; | |
| 4 | -import static org.easymock.EasyMock.expect; | |
| 5 | -import static org.easymock.EasyMock.verify; | |
| 6 | -import static org.powermock.api.easymock.PowerMock.mockStatic; | |
| 7 | -import static org.powermock.api.easymock.PowerMock.replay; | |
| 8 | -import static org.powermock.reflect.Whitebox.setInternalState; | |
| 9 | - | |
| 10 | -import java.util.Collections; | |
| 11 | -import java.util.HashMap; | |
| 12 | -import java.util.Locale; | |
| 13 | -import java.util.Map; | |
| 14 | - | |
| 15 | -import javax.persistence.EntityManagerFactory; | |
| 16 | -import javax.persistence.Persistence; | |
| 17 | - | |
| 18 | -import junit.framework.Assert; | |
| 19 | - | |
| 20 | -import org.junit.Before; | |
| 21 | -import org.junit.Test; | |
| 22 | -import org.junit.runner.RunWith; | |
| 23 | -import org.powermock.core.classloader.annotations.PrepareForTest; | |
| 24 | -import org.powermock.modules.junit4.PowerMockRunner; | |
| 25 | -import org.slf4j.Logger; | |
| 26 | - | |
| 27 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
| 28 | - | |
| 29 | -@RunWith(PowerMockRunner.class) | |
| 30 | -@PrepareForTest(Persistence.class) | |
| 31 | -public class EntityManagerFactoryProducerTest { | |
| 32 | - | |
| 33 | - private EntityManagerFactory emFactory; | |
| 34 | - | |
| 35 | - private EntityManagerFactoryProducer producer; | |
| 36 | - | |
| 37 | - private Map<ClassLoader, Map<String, EntityManagerFactory>> cache; | |
| 38 | - | |
| 39 | - private Logger logger; | |
| 40 | - | |
| 41 | - private ResourceBundle bundle; | |
| 42 | - | |
| 43 | - @Before | |
| 44 | - public void setUp() { | |
| 45 | - logger = createMock(Logger.class); | |
| 46 | - bundle = ResourceBundleProducer.create("demoiselle-jpa-bundle", Locale.getDefault()); | |
| 47 | - producer = new EntityManagerFactoryProducer(); | |
| 48 | - cache = Collections.synchronizedMap(new HashMap<ClassLoader, Map<String, EntityManagerFactory>>()); | |
| 49 | - setInternalState(producer, "factoryCache", cache); | |
| 50 | - setInternalState(producer, Logger.class, logger); | |
| 51 | - setInternalState(producer, ResourceBundle.class, bundle); | |
| 52 | - emFactory = createMock(EntityManagerFactory.class); | |
| 53 | - } | |
| 54 | - | |
| 55 | - @Test | |
| 56 | - public void testCreateWithUnitPersistenceExisting() { | |
| 57 | - ClassLoader cl = this.getClass().getClassLoader(); | |
| 58 | - HashMap<String, EntityManagerFactory> emEntry = new HashMap<String, EntityManagerFactory>(); | |
| 59 | - emEntry.put("pu1", emFactory); | |
| 60 | - cache.put(cl, emEntry); | |
| 61 | - | |
| 62 | - Assert.assertEquals(emFactory, producer.create("pu1")); | |
| 63 | - } | |
| 64 | - | |
| 65 | - @Test | |
| 66 | - public void testCreateWithUnitPersistenceNotExisting() { | |
| 67 | - | |
| 68 | - mockStatic(Persistence.class); | |
| 69 | - expect(Persistence.createEntityManagerFactory("pu1")).andReturn(emFactory); | |
| 70 | - | |
| 71 | - replay(Persistence.class); | |
| 72 | - | |
| 73 | - Assert.assertEquals(emFactory, producer.create("pu1")); | |
| 74 | - } | |
| 75 | - | |
| 76 | - /** | |
| 77 | - * Test if after producing an entity manager, the EntityManagerFactory is correctly stored in the cache associated | |
| 78 | - * with the current class loader. | |
| 79 | - */ | |
| 80 | - @Test | |
| 81 | - public void testStorageCacheAfterCreate() { | |
| 82 | - mockStatic(Persistence.class); | |
| 83 | - expect(Persistence.createEntityManagerFactory("pu1")).andReturn(emFactory); | |
| 84 | - replay(Persistence.class); | |
| 85 | - | |
| 86 | - Map<String, EntityManagerFactory> producerCache = producer.getCache(); | |
| 87 | - Assert.assertNotNull(producerCache); | |
| 88 | - Assert.assertTrue(producerCache.containsKey("pu1")); | |
| 89 | - Assert.assertTrue(producerCache.containsValue(emFactory)); | |
| 90 | - } | |
| 91 | - | |
| 92 | - @Test | |
| 93 | - public void testInitWithoutError() { | |
| 94 | - mockStatic(Persistence.class); | |
| 95 | - expect(Persistence.createEntityManagerFactory("pu1")).andReturn(emFactory); | |
| 96 | - replay(Persistence.class); | |
| 97 | - | |
| 98 | - producer.loadPersistenceUnits(); | |
| 99 | - | |
| 100 | - ClassLoader cl = this.getClass().getClassLoader(); | |
| 101 | - Map<String, EntityManagerFactory> internalCache = cache.get(cl); | |
| 102 | - | |
| 103 | - Assert.assertNotNull(internalCache); | |
| 104 | - Assert.assertEquals(emFactory, internalCache.get("pu1")); | |
| 105 | - } | |
| 106 | - | |
| 107 | - /* | |
| 108 | - * @Test public void testInitWithError() { try { producer.loadPersistenceUnits(); Assert.fail(); | |
| 109 | - * }catch(DemoiselleException cause) { Assert.assertTrue(true); } } | |
| 110 | - */ | |
| 111 | - | |
| 112 | - @Test | |
| 113 | - public void testGetCache() { | |
| 114 | - ClassLoader cl = this.getClass().getClassLoader(); | |
| 115 | - HashMap<String, EntityManagerFactory> emEntry = new HashMap<String, EntityManagerFactory>(); | |
| 116 | - emEntry.put("pu1", emFactory); | |
| 117 | - cache.put(cl, emEntry); | |
| 118 | - | |
| 119 | - mockStatic(Persistence.class); | |
| 120 | - expect(Persistence.createEntityManagerFactory("pu1")).andReturn(emFactory); | |
| 121 | - replay(Persistence.class); | |
| 122 | - | |
| 123 | - Assert.assertEquals(cache.get(this.getClass().getClassLoader()), producer.getCache()); | |
| 124 | - } | |
| 125 | - | |
| 126 | - @Test | |
| 127 | - public void testClose() { | |
| 128 | - ClassLoader cl = this.getClass().getClassLoader(); | |
| 129 | - HashMap<String, EntityManagerFactory> emEntry = new HashMap<String, EntityManagerFactory>(); | |
| 130 | - emEntry.put("pu1", emFactory); | |
| 131 | - cache.put(cl, emEntry); | |
| 132 | - | |
| 133 | - emFactory.close(); | |
| 134 | - replay(emFactory); | |
| 135 | - producer.close(); | |
| 136 | - verify(emFactory); | |
| 137 | - } | |
| 138 | - | |
| 139 | - /** | |
| 140 | - * Test if detecting the persistence unit with an empty name throws correct error. | |
| 141 | - */ | |
| 142 | - // @Test | |
| 143 | - // public void testEmptyPersistenceUnitName(){ | |
| 144 | - // EntityManagerFactoryProducer.ENTITY_MANAGER_RESOURCE = "persistence-empty-name.xml"; | |
| 145 | - // | |
| 146 | - // try{ | |
| 147 | - // producer.getCache(); | |
| 148 | - // Assert.fail(); | |
| 149 | - // } | |
| 150 | - // catch(DemoiselleException de){ | |
| 151 | - // // | |
| 152 | - // } | |
| 153 | - // } | |
| 154 | - | |
| 155 | - /** | |
| 156 | - * Test if asking to create an entity manager still not in the cache will correctly create it and put it in the | |
| 157 | - * cache. | |
| 158 | - */ | |
| 159 | - @Test | |
| 160 | - public void testCreatePersistenceUnitNotInCache() { | |
| 161 | - mockStatic(Persistence.class); | |
| 162 | - expect(Persistence.createEntityManagerFactory("pu1")).andReturn(emFactory); | |
| 163 | - replay(Persistence.class); | |
| 164 | - | |
| 165 | - ClassLoader cl = this.getClass().getClassLoader(); | |
| 166 | - HashMap<String, EntityManagerFactory> emEntry = new HashMap<String, EntityManagerFactory>(); | |
| 167 | - cache.put(cl, emEntry); | |
| 168 | - | |
| 169 | - producer.create("pu1"); | |
| 170 | - | |
| 171 | - Map<String, EntityManagerFactory> producerCache = producer.getCache(); | |
| 172 | - Assert.assertNotNull(producerCache); | |
| 173 | - Assert.assertTrue(producerCache.containsKey("pu1")); | |
| 174 | - Assert.assertTrue(producerCache.containsValue(emFactory)); | |
| 175 | - } | |
| 176 | -} |
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/producer/EntityManagerProducerTest.java
| ... | ... | @@ -1,189 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * Copyright (C) 2010 SERPRO | |
| 4 | - * ---------------------------------------------------------------------------- | |
| 5 | - * This file is part of Demoiselle Framework. | |
| 6 | - * | |
| 7 | - * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | - * as published by the Free Software Foundation. | |
| 10 | - * | |
| 11 | - * This program is distributed in the hope that it will be useful, | |
| 12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | - * GNU General Public License for more details. | |
| 15 | - * | |
| 16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | - * ---------------------------------------------------------------------------- | |
| 21 | - * Este arquivo é parte do Framework Demoiselle. | |
| 22 | - * | |
| 23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | - * do Software Livre (FSF). | |
| 26 | - * | |
| 27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | - * para maiores detalhes. | |
| 31 | - * | |
| 32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | - */ | |
| 37 | -package br.gov.frameworkdemoiselle.internal.producer; | |
| 38 | - | |
| 39 | -import static org.easymock.EasyMock.createMock; | |
| 40 | -import static org.easymock.EasyMock.expect; | |
| 41 | -import static org.easymock.EasyMock.verify; | |
| 42 | -import static org.powermock.api.easymock.PowerMock.mockStatic; | |
| 43 | -import static org.powermock.api.easymock.PowerMock.replay; | |
| 44 | -import static org.powermock.reflect.Whitebox.setInternalState; | |
| 45 | - | |
| 46 | -import java.util.Collections; | |
| 47 | -import java.util.HashMap; | |
| 48 | -import java.util.Locale; | |
| 49 | -import java.util.Map; | |
| 50 | - | |
| 51 | -import javax.enterprise.inject.spi.Annotated; | |
| 52 | -import javax.enterprise.inject.spi.InjectionPoint; | |
| 53 | -import javax.persistence.EntityManager; | |
| 54 | -import javax.persistence.EntityManagerFactory; | |
| 55 | -import javax.persistence.Persistence; | |
| 56 | - | |
| 57 | -import junit.framework.Assert; | |
| 58 | - | |
| 59 | -import org.junit.After; | |
| 60 | -import org.junit.Before; | |
| 61 | -import org.junit.Test; | |
| 62 | -import org.junit.runner.RunWith; | |
| 63 | -import org.powermock.core.classloader.annotations.PrepareForTest; | |
| 64 | -import org.powermock.modules.junit4.PowerMockRunner; | |
| 65 | -import org.slf4j.Logger; | |
| 66 | - | |
| 67 | -import br.gov.frameworkdemoiselle.annotation.Name; | |
| 68 | -import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig; | |
| 69 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
| 70 | - | |
| 71 | -@RunWith(PowerMockRunner.class) | |
| 72 | -@PrepareForTest(Persistence.class) | |
| 73 | -public class EntityManagerProducerTest { | |
| 74 | - | |
| 75 | - private EntityManagerProducer producer; | |
| 76 | - | |
| 77 | - private Logger logger; | |
| 78 | - | |
| 79 | - private ResourceBundle bundle; | |
| 80 | - | |
| 81 | - private InjectionPoint ip; | |
| 82 | - | |
| 83 | - private EntityManagerConfig config; | |
| 84 | - | |
| 85 | - private Annotated annotated; | |
| 86 | - | |
| 87 | - private Name name; | |
| 88 | - | |
| 89 | - private EntityManagerFactory emf; | |
| 90 | - | |
| 91 | - private Map<String, EntityManager> cache; | |
| 92 | - | |
| 93 | - private EntityManager em; | |
| 94 | - | |
| 95 | - @Before | |
| 96 | - public void setUp() { | |
| 97 | - emf = createMock(EntityManagerFactory.class); | |
| 98 | - em = createMock(EntityManager.class); | |
| 99 | - | |
| 100 | - mockStatic(Persistence.class); | |
| 101 | - expect(Persistence.createEntityManagerFactory("pu1")).andReturn(emf); | |
| 102 | - expect(emf.createEntityManager()).andReturn(em); | |
| 103 | - | |
| 104 | - replay(emf, Persistence.class); | |
| 105 | - | |
| 106 | - producer = new EntityManagerProducer(); | |
| 107 | - bundle = ResourceBundleProducer.create("demoiselle-jpa-bundle", Locale.getDefault()); | |
| 108 | - logger = createMock(Logger.class); | |
| 109 | - | |
| 110 | - setInternalState(producer, ResourceBundle.class, bundle); | |
| 111 | - setInternalState(producer, Logger.class, logger); | |
| 112 | - | |
| 113 | - ip = createMock(InjectionPoint.class); | |
| 114 | - config = createMock(EntityManagerConfig.class); | |
| 115 | - annotated = createMock(Annotated.class); | |
| 116 | - } | |
| 117 | - | |
| 118 | - @Test | |
| 119 | - public void testClose() { | |
| 120 | - em.close(); | |
| 121 | - replay(em); | |
| 122 | - cache = Collections.synchronizedMap(new HashMap<String, EntityManager>()); | |
| 123 | - cache.put("pu1", em); | |
| 124 | - setInternalState(producer, Map.class, cache); | |
| 125 | - producer.close(); | |
| 126 | - verify(em); | |
| 127 | - } | |
| 128 | - | |
| 129 | - @Test | |
| 130 | - public void testGetCache() { | |
| 131 | - cache = Collections.synchronizedMap(new HashMap<String, EntityManager>()); | |
| 132 | - setInternalState(producer, Map.class, cache); | |
| 133 | - Assert.assertEquals(cache, producer.getCache()); | |
| 134 | - } | |
| 135 | - | |
| 136 | - @After | |
| 137 | - public void tearDown() { | |
| 138 | - producer = null; | |
| 139 | - } | |
| 140 | - | |
| 141 | - // @Test | |
| 142 | - // public void testCreateWithEntityManagerAnnotatedWithName() { | |
| 143 | - // name = createMock(Name.class); | |
| 144 | - // expect(name.value()).andReturn("pu1"); | |
| 145 | - // expect(annotated.isAnnotationPresent(Name.class)).andReturn(true); | |
| 146 | - // expect(annotated.getAnnotation(Name.class)).andReturn(name); | |
| 147 | - // expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); | |
| 148 | - // replay(name, annotated, ip); | |
| 149 | - // | |
| 150 | - // EntityManagerProxy entityManagerProxy = (EntityManagerProxy) producer.create(ip, config); | |
| 151 | - // assertNotNull(entityManagerProxy); | |
| 152 | - // } | |
| 153 | - | |
| 154 | - // @Test | |
| 155 | - // public void testCreateWithPersistenceUnitNameFromDemoiselleProperties() { | |
| 156 | - // expect(annotated.isAnnotationPresent(Name.class)).andReturn(false); | |
| 157 | - // expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); | |
| 158 | - // expect(config.getDefaultPersistenceUnitName()).andReturn("pu1"); | |
| 159 | - // | |
| 160 | - // replay(annotated, ip, config); | |
| 161 | - // | |
| 162 | - // EntityManagerProxy entityManagerProxy = (EntityManagerProxy) producer.create(ip, config); | |
| 163 | - // assertNotNull(entityManagerProxy); | |
| 164 | - // } | |
| 165 | - | |
| 166 | - // @Test | |
| 167 | - // public void testCreateWithPersistenceUnitNameFromPersistenceXML() { | |
| 168 | - // | |
| 169 | - // Map<String, EntityManagerFactory> cache = Collections | |
| 170 | - // .synchronizedMap(new HashMap<String, EntityManagerFactory>()); | |
| 171 | - // | |
| 172 | - // cache.put("pu1", emf); | |
| 173 | - // | |
| 174 | - // EntityManagerFactoryProducer entityManagerFactoryProducer = createMock(EntityManagerFactoryProducer.class); | |
| 175 | - // | |
| 176 | - // expect(entityManagerFactoryProducer.getCache()).andReturn(cache); | |
| 177 | - // | |
| 178 | - // expect(annotated.isAnnotationPresent(Name.class)).andReturn(false); | |
| 179 | - // expect(ip.getAnnotated()).andReturn(annotated).anyTimes(); | |
| 180 | - // expect(config.getDefaultPersistenceUnitName()).andReturn(null); | |
| 181 | - // | |
| 182 | - // replay(annotated, ip, config, entityManagerFactoryProducer); | |
| 183 | - // | |
| 184 | - // setInternalState(producer, EntityManagerFactoryProducer.class, entityManagerFactoryProducer); | |
| 185 | - // | |
| 186 | - // EntityManagerProxy entityManagerProxy = (EntityManagerProxy) producer.create(ip, config); | |
| 187 | - // assertNotNull(entityManagerProxy); | |
| 188 | - // } | |
| 189 | -} |
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/producer/FakeEntityManager.java
| ... | ... | @@ -1,277 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * Copyright (C) 2010 SERPRO | |
| 4 | - * ---------------------------------------------------------------------------- | |
| 5 | - * This file is part of Demoiselle Framework. | |
| 6 | - * | |
| 7 | - * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | - * as published by the Free Software Foundation. | |
| 10 | - * | |
| 11 | - * This program is distributed in the hope that it will be useful, | |
| 12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | - * GNU General Public License for more details. | |
| 15 | - * | |
| 16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | - * ---------------------------------------------------------------------------- | |
| 21 | - * Este arquivo é parte do Framework Demoiselle. | |
| 22 | - * | |
| 23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | - * do Software Livre (FSF). | |
| 26 | - * | |
| 27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | - * para maiores detalhes. | |
| 31 | - * | |
| 32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | - */ | |
| 37 | -package br.gov.frameworkdemoiselle.internal.producer; | |
| 38 | - | |
| 39 | -import java.util.Map; | |
| 40 | - | |
| 41 | -import javax.enterprise.inject.Alternative; | |
| 42 | -import javax.persistence.EntityManager; | |
| 43 | -import javax.persistence.EntityManagerFactory; | |
| 44 | -import javax.persistence.EntityTransaction; | |
| 45 | -import javax.persistence.FlushModeType; | |
| 46 | -import javax.persistence.LockModeType; | |
| 47 | -import javax.persistence.Query; | |
| 48 | -import javax.persistence.TypedQuery; | |
| 49 | -import javax.persistence.criteria.CriteriaBuilder; | |
| 50 | -import javax.persistence.criteria.CriteriaQuery; | |
| 51 | -import javax.persistence.metamodel.Metamodel; | |
| 52 | - | |
| 53 | -@Alternative | |
| 54 | -public class FakeEntityManager implements EntityManager { | |
| 55 | - | |
| 56 | - private boolean closed = false; | |
| 57 | - | |
| 58 | - private boolean equals = true; | |
| 59 | - | |
| 60 | - private int hashCode = 1; | |
| 61 | - | |
| 62 | - private String toString = ""; | |
| 63 | - | |
| 64 | - @Override | |
| 65 | - public void clear() { | |
| 66 | - } | |
| 67 | - | |
| 68 | - @Override | |
| 69 | - public void close() { | |
| 70 | - closed = true; | |
| 71 | - } | |
| 72 | - | |
| 73 | - @Override | |
| 74 | - public boolean contains(Object arg0) { | |
| 75 | - return false; | |
| 76 | - } | |
| 77 | - | |
| 78 | - @Override | |
| 79 | - public Query createNamedQuery(String arg0) { | |
| 80 | - return null; | |
| 81 | - } | |
| 82 | - | |
| 83 | - @Override | |
| 84 | - public <T> TypedQuery<T> createNamedQuery(String arg0, Class<T> arg1) { | |
| 85 | - return null; | |
| 86 | - } | |
| 87 | - | |
| 88 | - @Override | |
| 89 | - public Query createNativeQuery(String arg0) { | |
| 90 | - return null; | |
| 91 | - } | |
| 92 | - | |
| 93 | - @Override | |
| 94 | - public Query createNativeQuery(String arg0, @SuppressWarnings("rawtypes") Class arg1) { | |
| 95 | - return null; | |
| 96 | - } | |
| 97 | - | |
| 98 | - @Override | |
| 99 | - public Query createNativeQuery(String arg0, String arg1) { | |
| 100 | - return null; | |
| 101 | - } | |
| 102 | - | |
| 103 | - @Override | |
| 104 | - public Query createQuery(String arg0) { | |
| 105 | - return null; | |
| 106 | - } | |
| 107 | - | |
| 108 | - @Override | |
| 109 | - public <T> TypedQuery<T> createQuery(CriteriaQuery<T> arg0) { | |
| 110 | - return null; | |
| 111 | - } | |
| 112 | - | |
| 113 | - @Override | |
| 114 | - public <T> TypedQuery<T> createQuery(String arg0, Class<T> arg1) { | |
| 115 | - return null; | |
| 116 | - } | |
| 117 | - | |
| 118 | - @Override | |
| 119 | - public void detach(Object arg0) { | |
| 120 | - } | |
| 121 | - | |
| 122 | - @Override | |
| 123 | - public <T> T find(Class<T> arg0, Object arg1) { | |
| 124 | - return null; | |
| 125 | - } | |
| 126 | - | |
| 127 | - @Override | |
| 128 | - public <T> T find(Class<T> arg0, Object arg1, Map<String, Object> arg2) { | |
| 129 | - return null; | |
| 130 | - } | |
| 131 | - | |
| 132 | - @Override | |
| 133 | - public <T> T find(Class<T> arg0, Object arg1, LockModeType arg2) { | |
| 134 | - return null; | |
| 135 | - } | |
| 136 | - | |
| 137 | - @Override | |
| 138 | - public <T> T find(Class<T> arg0, Object arg1, LockModeType arg2, Map<String, Object> arg3) { | |
| 139 | - return null; | |
| 140 | - } | |
| 141 | - | |
| 142 | - @Override | |
| 143 | - public void flush() { | |
| 144 | - } | |
| 145 | - | |
| 146 | - @Override | |
| 147 | - public CriteriaBuilder getCriteriaBuilder() { | |
| 148 | - return null; | |
| 149 | - } | |
| 150 | - | |
| 151 | - @Override | |
| 152 | - public Object getDelegate() { | |
| 153 | - return null; | |
| 154 | - } | |
| 155 | - | |
| 156 | - @Override | |
| 157 | - public EntityManagerFactory getEntityManagerFactory() { | |
| 158 | - return null; | |
| 159 | - } | |
| 160 | - | |
| 161 | - @Override | |
| 162 | - public FlushModeType getFlushMode() { | |
| 163 | - return null; | |
| 164 | - } | |
| 165 | - | |
| 166 | - @Override | |
| 167 | - public LockModeType getLockMode(Object arg0) { | |
| 168 | - return null; | |
| 169 | - } | |
| 170 | - | |
| 171 | - @Override | |
| 172 | - public Metamodel getMetamodel() { | |
| 173 | - return null; | |
| 174 | - } | |
| 175 | - | |
| 176 | - @Override | |
| 177 | - public Map<String, Object> getProperties() { | |
| 178 | - return null; | |
| 179 | - } | |
| 180 | - | |
| 181 | - @Override | |
| 182 | - public <T> T getReference(Class<T> arg0, Object arg1) { | |
| 183 | - return null; | |
| 184 | - } | |
| 185 | - | |
| 186 | - @Override | |
| 187 | - public EntityTransaction getTransaction() { | |
| 188 | - return null; | |
| 189 | - } | |
| 190 | - | |
| 191 | - @Override | |
| 192 | - public boolean isOpen() { | |
| 193 | - return !closed; | |
| 194 | - } | |
| 195 | - | |
| 196 | - @Override | |
| 197 | - public void joinTransaction() { | |
| 198 | - } | |
| 199 | - | |
| 200 | - @Override | |
| 201 | - public void lock(Object arg0, LockModeType arg1) { | |
| 202 | - } | |
| 203 | - | |
| 204 | - @Override | |
| 205 | - public void lock(Object arg0, LockModeType arg1, Map<String, Object> arg2) { | |
| 206 | - } | |
| 207 | - | |
| 208 | - @Override | |
| 209 | - public <T> T merge(T arg0) { | |
| 210 | - return null; | |
| 211 | - } | |
| 212 | - | |
| 213 | - @Override | |
| 214 | - public void persist(Object arg0) { | |
| 215 | - } | |
| 216 | - | |
| 217 | - @Override | |
| 218 | - public void refresh(Object arg0) { | |
| 219 | - } | |
| 220 | - | |
| 221 | - @Override | |
| 222 | - public void refresh(Object arg0, Map<String, Object> arg1) { | |
| 223 | - } | |
| 224 | - | |
| 225 | - @Override | |
| 226 | - public void refresh(Object arg0, LockModeType arg1) { | |
| 227 | - } | |
| 228 | - | |
| 229 | - @Override | |
| 230 | - public void refresh(Object arg0, LockModeType arg1, Map<String, Object> arg2) { | |
| 231 | - } | |
| 232 | - | |
| 233 | - @Override | |
| 234 | - public void remove(Object arg0) { | |
| 235 | - } | |
| 236 | - | |
| 237 | - @Override | |
| 238 | - public void setFlushMode(FlushModeType arg0) { | |
| 239 | - } | |
| 240 | - | |
| 241 | - @Override | |
| 242 | - public void setProperty(String arg0, Object arg1) { | |
| 243 | - } | |
| 244 | - | |
| 245 | - @Override | |
| 246 | - public <T> T unwrap(Class<T> arg0) { | |
| 247 | - return null; | |
| 248 | - } | |
| 249 | - | |
| 250 | - @Override | |
| 251 | - public boolean equals(Object obj) { | |
| 252 | - return equals; | |
| 253 | - } | |
| 254 | - | |
| 255 | - public void setEquals(boolean equals) { | |
| 256 | - this.equals = equals; | |
| 257 | - } | |
| 258 | - | |
| 259 | - @Override | |
| 260 | - public int hashCode() { | |
| 261 | - return hashCode; | |
| 262 | - } | |
| 263 | - | |
| 264 | - public void setHashCode(int hash) { | |
| 265 | - this.hashCode = hash; | |
| 266 | - } | |
| 267 | - | |
| 268 | - @Override | |
| 269 | - public String toString() { | |
| 270 | - return toString; | |
| 271 | - } | |
| 272 | - | |
| 273 | - public void setToString(String toString) { | |
| 274 | - this.toString = toString; | |
| 275 | - } | |
| 276 | - | |
| 277 | -} |
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/proxy/EntityManagerProxyTest.java
| ... | ... | @@ -1,536 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * Copyright (C) 2010 SERPRO | |
| 4 | - * ---------------------------------------------------------------------------- | |
| 5 | - * This file is part of Demoiselle Framework. | |
| 6 | - * | |
| 7 | - * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | - * as published by the Free Software Foundation. | |
| 10 | - * | |
| 11 | - * This program is distributed in the hope that it will be useful, | |
| 12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | - * GNU General Public License for more details. | |
| 15 | - * | |
| 16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | - * ---------------------------------------------------------------------------- | |
| 21 | - * Este arquivo é parte do Framework Demoiselle. | |
| 22 | - * | |
| 23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | - * do Software Livre (FSF). | |
| 26 | - * | |
| 27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | - * para maiores detalhes. | |
| 31 | - * | |
| 32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | - */ | |
| 37 | -package br.gov.frameworkdemoiselle.internal.proxy; | |
| 38 | -import static org.easymock.EasyMock.expect; | |
| 39 | -import static org.easymock.EasyMock.replay; | |
| 40 | -import static org.easymock.EasyMock.verify; | |
| 41 | -import static org.junit.Assert.assertEquals; | |
| 42 | -import static org.junit.Assert.assertTrue; | |
| 43 | -import static org.powermock.api.easymock.PowerMock.mockStatic; | |
| 44 | -import static org.powermock.api.easymock.PowerMock.replayAll; | |
| 45 | - | |
| 46 | -import java.util.Map; | |
| 47 | - | |
| 48 | -import javax.persistence.EntityManager; | |
| 49 | -import javax.persistence.EntityManagerFactory; | |
| 50 | -import javax.persistence.EntityTransaction; | |
| 51 | -import javax.persistence.FlushModeType; | |
| 52 | -import javax.persistence.LockModeType; | |
| 53 | -import javax.persistence.Query; | |
| 54 | -import javax.persistence.TypedQuery; | |
| 55 | -import javax.persistence.criteria.CriteriaBuilder; | |
| 56 | -import javax.persistence.criteria.CriteriaQuery; | |
| 57 | -import javax.persistence.metamodel.Metamodel; | |
| 58 | - | |
| 59 | -import org.easymock.EasyMock; | |
| 60 | -import org.junit.Before; | |
| 61 | -import org.junit.Test; | |
| 62 | -import org.junit.runner.RunWith; | |
| 63 | -import org.powermock.core.classloader.annotations.PrepareForTest; | |
| 64 | -import org.powermock.modules.junit4.PowerMockRunner; | |
| 65 | - | |
| 66 | -import br.gov.frameworkdemoiselle.internal.producer.EntityManagerProducer; | |
| 67 | -import br.gov.frameworkdemoiselle.internal.producer.FakeEntityManager; | |
| 68 | -import br.gov.frameworkdemoiselle.util.Beans; | |
| 69 | - | |
| 70 | -@RunWith(PowerMockRunner.class) | |
| 71 | -@PrepareForTest({ Beans.class }) | |
| 72 | -public class EntityManagerProxyTest { | |
| 73 | - | |
| 74 | - private EntityManagerProxy entityManagerProxy; | |
| 75 | - | |
| 76 | - private EntityManager entityManager; | |
| 77 | - | |
| 78 | - private EntityManagerProducer entityManagerContext; | |
| 79 | - | |
| 80 | - @Before | |
| 81 | - public void setUp() throws Exception { | |
| 82 | - mockStatic(Beans.class); | |
| 83 | - this.entityManager = EasyMock.createMock(EntityManager.class); | |
| 84 | - this.entityManagerContext = EasyMock.createMock(EntityManagerProducer.class); | |
| 85 | - | |
| 86 | - expect(Beans.getReference(EntityManagerProducer.class)).andReturn(this.entityManagerContext).anyTimes(); | |
| 87 | - expect(this.entityManagerContext.getEntityManager("teste")).andReturn(this.entityManager).anyTimes(); | |
| 88 | - replay(this.entityManagerContext); | |
| 89 | - //expect(this.entityManager.getTransaction()).andReturn(transaction).anyTimes(); | |
| 90 | - //replay(this.entityManager); | |
| 91 | - replayAll(); | |
| 92 | - | |
| 93 | - this.entityManagerProxy = new EntityManagerProxy("teste"); | |
| 94 | - | |
| 95 | - } | |
| 96 | - | |
| 97 | - @Test | |
| 98 | - public void testJoinTransactionIfNecessaryException() { | |
| 99 | - this.entityManager.persist("teste"); | |
| 100 | - expect(this.entityManager.getTransaction()).andThrow(new IllegalStateException()).anyTimes(); | |
| 101 | - this.entityManager.joinTransaction(); | |
| 102 | - replay(this.entityManager); | |
| 103 | - | |
| 104 | - this.entityManagerProxy.persist("teste"); | |
| 105 | - verify(this.entityManager); | |
| 106 | - } | |
| 107 | - | |
| 108 | - @Test | |
| 109 | - public void testPersist() { | |
| 110 | - this.entityManager.persist("teste"); | |
| 111 | - expect(this.entityManager.getTransaction()).andReturn(null); | |
| 112 | - replay(this.entityManager); | |
| 113 | - this.entityManagerProxy.persist("teste"); | |
| 114 | - verify(this.entityManager); | |
| 115 | - } | |
| 116 | - | |
| 117 | - @Test | |
| 118 | - public void testRemove() { | |
| 119 | - this.entityManager.remove("teste"); | |
| 120 | - expect(this.entityManager.getTransaction()).andReturn(null); | |
| 121 | - replay(this.entityManager); | |
| 122 | - this.entityManagerProxy.remove("teste"); | |
| 123 | - verify(this.entityManager); | |
| 124 | - } | |
| 125 | - | |
| 126 | - @Test | |
| 127 | - public void testFlush() { | |
| 128 | - this.entityManager.flush(); | |
| 129 | - replay(this.entityManager); | |
| 130 | - this.entityManagerProxy.flush(); | |
| 131 | - verify(this.entityManager); | |
| 132 | - } | |
| 133 | - | |
| 134 | - @Test | |
| 135 | - public void testSetFlushMode() { | |
| 136 | - FlushModeType flushModeType = null; | |
| 137 | - this.entityManager.setFlushMode(flushModeType); | |
| 138 | - replay(this.entityManager); | |
| 139 | - this.entityManagerProxy.setFlushMode(flushModeType); | |
| 140 | - verify(this.entityManager); | |
| 141 | - } | |
| 142 | - | |
| 143 | - @Test | |
| 144 | - public void testLockWithParamsStringAndLockModeType() { | |
| 145 | - LockModeType lockMode = null; | |
| 146 | - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes(); | |
| 147 | - this.entityManager.lock("teste", lockMode); | |
| 148 | - replay(this.entityManager); | |
| 149 | - this.entityManagerProxy.lock("teste", lockMode); | |
| 150 | - verify(this.entityManager); | |
| 151 | - } | |
| 152 | - | |
| 153 | - @Test | |
| 154 | - public void testLockWithParamsStringLockModeTypeAndMap() { | |
| 155 | - LockModeType lockMode = null; | |
| 156 | - Map<String, Object> map = null; | |
| 157 | - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes(); | |
| 158 | - this.entityManager.lock("teste", lockMode, map); | |
| 159 | - replay(this.entityManager); | |
| 160 | - this.entityManagerProxy.lock("teste", lockMode, map); | |
| 161 | - verify(this.entityManager); | |
| 162 | - } | |
| 163 | - | |
| 164 | - @Test | |
| 165 | - public void testRefresh() { | |
| 166 | - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes(); | |
| 167 | - this.entityManager.refresh("teste"); | |
| 168 | - replay(this.entityManager); | |
| 169 | - this.entityManagerProxy.refresh("teste"); | |
| 170 | - verify(this.entityManager); | |
| 171 | - } | |
| 172 | - | |
| 173 | - @Test | |
| 174 | - public void testRefreshWithParamsStringAndMap() { | |
| 175 | - Map<String, Object> map = null; | |
| 176 | - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes(); | |
| 177 | - this.entityManager.refresh("teste", map); | |
| 178 | - replay(this.entityManager); | |
| 179 | - this.entityManagerProxy.refresh("teste", map); | |
| 180 | - verify(this.entityManager); | |
| 181 | - } | |
| 182 | - | |
| 183 | - @Test | |
| 184 | - public void testRefreshWithParamsStringAndLockModeType() { | |
| 185 | - LockModeType lockMode = null; | |
| 186 | - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes(); | |
| 187 | - this.entityManager.refresh("teste", lockMode); | |
| 188 | - replay(this.entityManager); | |
| 189 | - this.entityManagerProxy.refresh("teste", lockMode); | |
| 190 | - verify(this.entityManager); | |
| 191 | - } | |
| 192 | - | |
| 193 | - @Test | |
| 194 | - public void testRefreshWithParamsStringLockModeTypeAndMap() { | |
| 195 | - LockModeType lockMode = null; | |
| 196 | - Map<String, Object> map = null; | |
| 197 | - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes(); | |
| 198 | - this.entityManager.refresh("teste", lockMode, map); | |
| 199 | - replay(this.entityManager); | |
| 200 | - this.entityManagerProxy.refresh("teste", lockMode, map); | |
| 201 | - verify(this.entityManager); | |
| 202 | - } | |
| 203 | - | |
| 204 | - @Test | |
| 205 | - public void testClear() { | |
| 206 | - this.entityManager.clear(); | |
| 207 | - replay(this.entityManager); | |
| 208 | - this.entityManagerProxy.clear(); | |
| 209 | - verify(this.entityManager); | |
| 210 | - } | |
| 211 | - | |
| 212 | - @Test | |
| 213 | - public void testDetach() { | |
| 214 | - this.entityManager.detach("teste"); | |
| 215 | - replay(this.entityManager); | |
| 216 | - this.entityManagerProxy.detach("teste"); | |
| 217 | - verify(this.entityManager); | |
| 218 | - } | |
| 219 | - | |
| 220 | - @Test | |
| 221 | - public void testSetProperty() { | |
| 222 | - this.entityManager.setProperty("teste", "teste"); | |
| 223 | - replay(this.entityManager); | |
| 224 | - this.entityManagerProxy.setProperty("teste", "teste"); | |
| 225 | - verify(this.entityManager); | |
| 226 | - } | |
| 227 | - | |
| 228 | - @Test | |
| 229 | - public void testJoinTransaction() { | |
| 230 | - this.entityManager.joinTransaction(); | |
| 231 | - replay(this.entityManager); | |
| 232 | - this.entityManagerProxy.joinTransaction(); | |
| 233 | - verify(this.entityManager); | |
| 234 | - } | |
| 235 | - | |
| 236 | - @Test | |
| 237 | - public void testClose() { | |
| 238 | - this.entityManager.close(); | |
| 239 | - replay(this.entityManager); | |
| 240 | - this.entityManagerProxy.close(); | |
| 241 | - verify(this.entityManager); | |
| 242 | - } | |
| 243 | - | |
| 244 | - @Test | |
| 245 | - public void testMerge() { | |
| 246 | - expect(this.entityManager.merge("teste")).andReturn("xxx"); | |
| 247 | - expect(this.entityManager.getTransaction()).andReturn(null); | |
| 248 | - replay(this.entityManager); | |
| 249 | - assertEquals("xxx", this.entityManagerProxy.merge("teste")); | |
| 250 | - verify(this.entityManager); | |
| 251 | - } | |
| 252 | - | |
| 253 | - @Test | |
| 254 | - public void testFindWithParamsClassAndObject() { | |
| 255 | - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes(); | |
| 256 | - expect(this.entityManager.find(String.class, "teste")).andReturn("retorno"); | |
| 257 | - replay(this.entityManager); | |
| 258 | - assertEquals("retorno", this.entityManagerProxy.find(String.class, "teste")); | |
| 259 | - verify(this.entityManager); | |
| 260 | - } | |
| 261 | - | |
| 262 | - @Test | |
| 263 | - public void testFindWithParamsClassObjectAndMap() { | |
| 264 | - Map<String, Object> map = null; | |
| 265 | - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes(); | |
| 266 | - expect(this.entityManager.find(String.class, "teste", map)).andReturn("retorno"); | |
| 267 | - replay(this.entityManager); | |
| 268 | - assertEquals("retorno", this.entityManagerProxy.find(String.class, "teste", map)); | |
| 269 | - verify(this.entityManager); | |
| 270 | - } | |
| 271 | - | |
| 272 | - @Test | |
| 273 | - public void testFindWithParamsClassObjectAndLockModeType() { | |
| 274 | - LockModeType lock = null; | |
| 275 | - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes(); | |
| 276 | - expect(this.entityManager.find(String.class, "teste", lock)).andReturn("retorno"); | |
| 277 | - replay(this.entityManager); | |
| 278 | - assertEquals("retorno", this.entityManagerProxy.find(String.class, "teste", lock)); | |
| 279 | - verify(this.entityManager); | |
| 280 | - } | |
| 281 | - | |
| 282 | - @Test | |
| 283 | - public void testFindWithParamsClassObjectLockModeTypeAndMap() { | |
| 284 | - Map<String, Object> map = null; | |
| 285 | - LockModeType lock = null; | |
| 286 | - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes(); | |
| 287 | - expect(this.entityManager.find(String.class, "teste", lock, map)).andReturn("retorno"); | |
| 288 | - replay(this.entityManager); | |
| 289 | - assertEquals("retorno", this.entityManagerProxy.find(String.class, "teste", lock, map)); | |
| 290 | - verify(this.entityManager); | |
| 291 | - } | |
| 292 | - | |
| 293 | - @Test | |
| 294 | - public void testGetReference() { | |
| 295 | - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes(); | |
| 296 | - expect(this.entityManager.getReference(String.class, "teste")).andReturn("retorno"); | |
| 297 | - replay(this.entityManager); | |
| 298 | - assertEquals("retorno", this.entityManagerProxy.getReference(String.class, "teste")); | |
| 299 | - verify(this.entityManager); | |
| 300 | - } | |
| 301 | - | |
| 302 | - @Test | |
| 303 | - public void testGetFlushMode() { | |
| 304 | - FlushModeType flushModeType = null; | |
| 305 | - expect(this.entityManager.getFlushMode()).andReturn(flushModeType); | |
| 306 | - replay(this.entityManager); | |
| 307 | - assertEquals(flushModeType, this.entityManagerProxy.getFlushMode()); | |
| 308 | - verify(this.entityManager); | |
| 309 | - } | |
| 310 | - | |
| 311 | - @Test | |
| 312 | - public void testContains() { | |
| 313 | - expect(this.entityManager.contains("teste")).andReturn(true); | |
| 314 | - replay(this.entityManager); | |
| 315 | - assertTrue(this.entityManagerProxy.contains("teste")); | |
| 316 | - verify(this.entityManager); | |
| 317 | - } | |
| 318 | - | |
| 319 | - @Test | |
| 320 | - public void testGetLockMode() { | |
| 321 | - LockModeType lockModeType = null; | |
| 322 | - expect(this.entityManager.getTransaction()).andReturn(null).anyTimes(); | |
| 323 | - expect(this.entityManager.getLockMode("teste")).andReturn(lockModeType); | |
| 324 | - replay(this.entityManager); | |
| 325 | - assertEquals(lockModeType, this.entityManagerProxy.getLockMode("teste")); | |
| 326 | - verify(this.entityManager); | |
| 327 | - } | |
| 328 | - | |
| 329 | - @Test | |
| 330 | - public void testGetProperties() { | |
| 331 | - Map<String, Object> map = null; | |
| 332 | - expect(this.entityManager.getProperties()).andReturn(map); | |
| 333 | - replay(this.entityManager); | |
| 334 | - assertEquals(map, this.entityManagerProxy.getProperties()); | |
| 335 | - verify(this.entityManager); | |
| 336 | - } | |
| 337 | - | |
| 338 | - @Test | |
| 339 | - public void testCreateQuery() { | |
| 340 | - Query query = EasyMock.createMock(Query.class); | |
| 341 | - expect(this.entityManager.createQuery("teste")).andReturn(query); | |
| 342 | - replay(this.entityManager); | |
| 343 | - assertTrue(Query.class.isAssignableFrom(this.entityManagerProxy.createQuery("teste").getClass()) ); | |
| 344 | - verify(this.entityManager); | |
| 345 | - } | |
| 346 | - | |
| 347 | - @Test | |
| 348 | - public void testCreateQueryWithParamCriteria() { | |
| 349 | - @SuppressWarnings("unchecked") | |
| 350 | - TypedQuery<Object> typedQuery = EasyMock.createMock(TypedQuery.class); | |
| 351 | - | |
| 352 | - CriteriaQuery<Object> criteriaQuery = null; | |
| 353 | - expect(this.entityManager.createQuery(criteriaQuery)).andReturn(typedQuery); | |
| 354 | - replay(this.entityManager); | |
| 355 | - assertTrue(TypedQuery.class.isAssignableFrom(this.entityManagerProxy.createQuery(criteriaQuery).getClass())); | |
| 356 | - verify(this.entityManager); | |
| 357 | - } | |
| 358 | - | |
| 359 | - @Test | |
| 360 | - public void testCreateQueryWithParamStringAndClass() { | |
| 361 | - @SuppressWarnings("unchecked") | |
| 362 | - TypedQuery<String> typeQuery = EasyMock.createMock(TypedQuery.class); | |
| 363 | - | |
| 364 | - expect(this.entityManager.createQuery("teste", String.class)).andReturn(typeQuery); | |
| 365 | - replay(this.entityManager); | |
| 366 | - assertTrue(TypedQuery.class.isAssignableFrom(this.entityManagerProxy.createQuery("teste", String.class).getClass())); | |
| 367 | - verify(this.entityManager); | |
| 368 | - } | |
| 369 | - | |
| 370 | - @Test | |
| 371 | - public void testCreateNamedQuery() { | |
| 372 | - Query query = EasyMock.createMock(Query.class); | |
| 373 | - expect(this.entityManager.createNamedQuery("teste")).andReturn(query); | |
| 374 | - replay(this.entityManager); | |
| 375 | - assertTrue(Query.class.isAssignableFrom(this.entityManagerProxy.createNamedQuery("teste").getClass())); | |
| 376 | - verify(this.entityManager); | |
| 377 | - } | |
| 378 | - | |
| 379 | - @Test | |
| 380 | - public void testCreateNamedQueryWithParamsStringAndClass() { | |
| 381 | - @SuppressWarnings("unchecked") | |
| 382 | - TypedQuery<String> typedQuery = EasyMock.createMock(TypedQuery.class); | |
| 383 | - expect(this.entityManager.createNamedQuery("teste", String.class)).andReturn(typedQuery); | |
| 384 | - replay(this.entityManager); | |
| 385 | - assertEquals(typedQuery, this.entityManagerProxy.createNamedQuery("teste", String.class)); | |
| 386 | - verify(this.entityManager); | |
| 387 | - } | |
| 388 | - | |
| 389 | - @Test | |
| 390 | - public void testCreateNativeQuery() { | |
| 391 | - Query query = null; | |
| 392 | - expect(this.entityManager.createNativeQuery("teste")).andReturn(query); | |
| 393 | - replay(this.entityManager); | |
| 394 | - assertEquals(QueryProxy.class, this.entityManagerProxy.createNativeQuery("teste").getClass()); | |
| 395 | - verify(this.entityManager); | |
| 396 | - } | |
| 397 | - | |
| 398 | - @Test | |
| 399 | - public void testCreateNativeQueryWithParamsStringAndClass() { | |
| 400 | - Query query = null; | |
| 401 | - expect(this.entityManager.createNativeQuery("teste", String.class)).andReturn(query); | |
| 402 | - replay(this.entityManager); | |
| 403 | - assertEquals(QueryProxy.class, this.entityManagerProxy.createNativeQuery("teste", String.class).getClass()); | |
| 404 | - verify(this.entityManager); | |
| 405 | - } | |
| 406 | - | |
| 407 | - @Test | |
| 408 | - public void testCreateNativeQueryWithParamsStringAndString() { | |
| 409 | - Query query = null; | |
| 410 | - expect(this.entityManager.createNativeQuery("teste", "teste")).andReturn(query); | |
| 411 | - replay(this.entityManager); | |
| 412 | - assertEquals(QueryProxy.class, this.entityManagerProxy.createNativeQuery("teste", "teste").getClass()); | |
| 413 | - verify(this.entityManager); | |
| 414 | - } | |
| 415 | - | |
| 416 | - @Test | |
| 417 | - public void testUnwrap() { | |
| 418 | - String query = null; | |
| 419 | - expect(this.entityManager.unwrap(String.class)).andReturn(query); | |
| 420 | - replay(this.entityManager); | |
| 421 | - assertEquals(query, this.entityManagerProxy.unwrap(String.class)); | |
| 422 | - verify(this.entityManager); | |
| 423 | - } | |
| 424 | - | |
| 425 | - @Test | |
| 426 | - public void testGetDelegate() { | |
| 427 | - Object obj = null; | |
| 428 | - expect(this.entityManager.getDelegate()).andReturn(obj); | |
| 429 | - replay(this.entityManager); | |
| 430 | - assertEquals(obj, this.entityManagerProxy.getDelegate()); | |
| 431 | - verify(this.entityManager); | |
| 432 | - } | |
| 433 | - | |
| 434 | - @Test | |
| 435 | - public void testIsOpen() { | |
| 436 | - expect(this.entityManager.isOpen()).andReturn(true); | |
| 437 | - replay(this.entityManager); | |
| 438 | - assertTrue(this.entityManagerProxy.isOpen()); | |
| 439 | - verify(this.entityManager); | |
| 440 | - } | |
| 441 | - | |
| 442 | - @Test | |
| 443 | - public void testGetTransaction() { | |
| 444 | - EntityTransaction entityTransaction = null; | |
| 445 | - expect(this.entityManager.getTransaction()).andReturn(entityTransaction); | |
| 446 | - replay(this.entityManager); | |
| 447 | - assertEquals(entityTransaction, this.entityManagerProxy.getTransaction()); | |
| 448 | - verify(this.entityManager); | |
| 449 | - } | |
| 450 | - | |
| 451 | - @Test | |
| 452 | - public void testGetEntityManagerFactory() { | |
| 453 | - EntityManagerFactory entityManagerFactory = null; | |
| 454 | - expect(this.entityManager.getEntityManagerFactory()).andReturn(entityManagerFactory); | |
| 455 | - replay(this.entityManager); | |
| 456 | - assertEquals(entityManagerFactory, this.entityManagerProxy.getEntityManagerFactory()); | |
| 457 | - verify(this.entityManager); | |
| 458 | - } | |
| 459 | - | |
| 460 | - @Test | |
| 461 | - public void testGetCriteriaBuilder() { | |
| 462 | - CriteriaBuilder criteriaBuilder = null; | |
| 463 | - expect(this.entityManager.getCriteriaBuilder()).andReturn(criteriaBuilder); | |
| 464 | - replay(this.entityManager); | |
| 465 | - assertEquals(criteriaBuilder, this.entityManagerProxy.getCriteriaBuilder()); | |
| 466 | - verify(this.entityManager); | |
| 467 | - } | |
| 468 | - | |
| 469 | - @Test | |
| 470 | - public void testGetMetamodel() { | |
| 471 | - Metamodel metamodel = null; | |
| 472 | - expect(this.entityManager.getMetamodel()).andReturn(metamodel); | |
| 473 | - replay(this.entityManager); | |
| 474 | - assertEquals(metamodel, this.entityManagerProxy.getMetamodel()); | |
| 475 | - verify(this.entityManager); | |
| 476 | - } | |
| 477 | - | |
| 478 | - @Test | |
| 479 | - public void testEquals() { | |
| 480 | - Object obj = null; | |
| 481 | - | |
| 482 | - mockStatic(Beans.class); | |
| 483 | - // Method "equals" can't be mocked... | |
| 484 | - EntityManager em = new FakeEntityManager(); | |
| 485 | - ((FakeEntityManager) em).setEquals(true); | |
| 486 | - | |
| 487 | - this.entityManagerContext = EasyMock.createMock(EntityManagerProducer.class); | |
| 488 | - expect(this.entityManagerContext.getEntityManager("teste")).andReturn(em).anyTimes(); | |
| 489 | - | |
| 490 | - expect(Beans.getReference(EntityManagerProducer.class)).andReturn(this.entityManagerContext).anyTimes(); | |
| 491 | - replay(this.entityManagerContext); | |
| 492 | - replayAll(); | |
| 493 | - | |
| 494 | - EntityManagerProxy emp = new EntityManagerProxy("teste"); | |
| 495 | - | |
| 496 | - assertTrue(emp.equals(obj)); | |
| 497 | - } | |
| 498 | - | |
| 499 | - @Test | |
| 500 | - public void testHashCode() { | |
| 501 | - mockStatic(Beans.class); | |
| 502 | - // Method "hashCode" can't be mocked... | |
| 503 | - EntityManager em = new FakeEntityManager(); | |
| 504 | - ((FakeEntityManager) em).setHashCode(1); | |
| 505 | - | |
| 506 | - this.entityManagerContext = EasyMock.createMock(EntityManagerProducer.class); | |
| 507 | - expect(this.entityManagerContext.getEntityManager("teste")).andReturn(em).anyTimes(); | |
| 508 | - | |
| 509 | - expect(Beans.getReference(EntityManagerProducer.class)).andReturn(this.entityManagerContext).anyTimes(); | |
| 510 | - replay(this.entityManagerContext); | |
| 511 | - replayAll(); | |
| 512 | - | |
| 513 | - EntityManagerProxy emp = new EntityManagerProxy("teste"); | |
| 514 | - | |
| 515 | - assertEquals(1, emp.hashCode()); | |
| 516 | - } | |
| 517 | - | |
| 518 | - @Test | |
| 519 | - public void testToString() { | |
| 520 | - mockStatic(Beans.class); | |
| 521 | - // Method "toString" can't be mocked... | |
| 522 | - EntityManager em = new FakeEntityManager(); | |
| 523 | - ((FakeEntityManager) em).setToString("testing"); | |
| 524 | - | |
| 525 | - this.entityManagerContext = EasyMock.createMock(EntityManagerProducer.class); | |
| 526 | - expect(this.entityManagerContext.getEntityManager("teste")).andReturn(em).anyTimes(); | |
| 527 | - | |
| 528 | - expect(Beans.getReference(EntityManagerProducer.class)).andReturn(this.entityManagerContext).anyTimes(); | |
| 529 | - replay(this.entityManagerContext); | |
| 530 | - replayAll(); | |
| 531 | - | |
| 532 | - EntityManagerProxy emp = new EntityManagerProxy("teste"); | |
| 533 | - | |
| 534 | - assertEquals("testing", emp.toString()); | |
| 535 | - } | |
| 536 | -} |
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/proxy/QueryProxyTest.java
| ... | ... | @@ -1,294 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * Copyright (C) 2010 SERPRO | |
| 4 | - * ---------------------------------------------------------------------------- | |
| 5 | - * This file is part of Demoiselle Framework. | |
| 6 | - * | |
| 7 | - * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | - * as published by the Free Software Foundation. | |
| 10 | - * | |
| 11 | - * This program is distributed in the hope that it will be useful, | |
| 12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | - * GNU General Public License for more details. | |
| 15 | - * | |
| 16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | - * ---------------------------------------------------------------------------- | |
| 21 | - * Este arquivo é parte do Framework Demoiselle. | |
| 22 | - * | |
| 23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | - * do Software Livre (FSF). | |
| 26 | - * | |
| 27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | - * para maiores detalhes. | |
| 31 | - * | |
| 32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | - */ | |
| 37 | -package br.gov.frameworkdemoiselle.internal.proxy; | |
| 38 | - | |
| 39 | -import static junit.framework.Assert.assertTrue; | |
| 40 | -import static org.easymock.EasyMock.expect; | |
| 41 | -import static org.junit.Assert.assertEquals; | |
| 42 | -import static org.powermock.api.easymock.PowerMock.replay; | |
| 43 | -import static org.powermock.api.easymock.PowerMock.verifyAll; | |
| 44 | - | |
| 45 | -import java.util.ArrayList; | |
| 46 | -import java.util.Calendar; | |
| 47 | -import java.util.Collections; | |
| 48 | -import java.util.Date; | |
| 49 | -import java.util.HashMap; | |
| 50 | -import java.util.List; | |
| 51 | -import java.util.Map; | |
| 52 | - | |
| 53 | -import javax.persistence.EntityManager; | |
| 54 | -import javax.persistence.EntityManagerFactory; | |
| 55 | -import javax.persistence.FlushModeType; | |
| 56 | -import javax.persistence.LockModeType; | |
| 57 | -import javax.persistence.Parameter; | |
| 58 | -import javax.persistence.Persistence; | |
| 59 | -import javax.persistence.Query; | |
| 60 | -import javax.persistence.TemporalType; | |
| 61 | - | |
| 62 | -import org.easymock.EasyMock; | |
| 63 | -import org.junit.Before; | |
| 64 | -import org.junit.Test; | |
| 65 | -import org.junit.runner.RunWith; | |
| 66 | -import org.powermock.api.easymock.PowerMock; | |
| 67 | -import org.powermock.core.classloader.annotations.PrepareForTest; | |
| 68 | -import org.powermock.modules.junit4.PowerMockRunner; | |
| 69 | -import org.powermock.reflect.Whitebox; | |
| 70 | - | |
| 71 | -import br.gov.frameworkdemoiselle.domain.Client; | |
| 72 | -import br.gov.frameworkdemoiselle.internal.producer.EntityManagerProducer; | |
| 73 | -import br.gov.frameworkdemoiselle.util.Beans; | |
| 74 | - | |
| 75 | -/** | |
| 76 | - * Test the proxied {@link Query} class, {@link QueryProxy}. | |
| 77 | - * | |
| 78 | - * @author 81986912515 | |
| 79 | - */ | |
| 80 | -@RunWith(PowerMockRunner.class) | |
| 81 | -@PrepareForTest({ Beans.class }) | |
| 82 | -public class QueryProxyTest { | |
| 83 | - | |
| 84 | - private EntityManager manager; | |
| 85 | - | |
| 86 | - private EntityManagerProducer producer; | |
| 87 | - | |
| 88 | - private QueryProxy queryProxy; | |
| 89 | - | |
| 90 | - @Before | |
| 91 | - public void setUp() { | |
| 92 | - | |
| 93 | - Map<String, Object> configOverrides = new HashMap<String, Object>(); | |
| 94 | - configOverrides.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence"); | |
| 95 | - | |
| 96 | - configOverrides.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:."); | |
| 97 | - configOverrides.put("javax.persistence.jdbc.driver", "org.hsqldb.jdbcDriver"); | |
| 98 | - configOverrides.put("javax.persistence.jdbc.user", "sa"); | |
| 99 | - configOverrides.put("javax.persistence.jdbc.password", ""); | |
| 100 | - | |
| 101 | - configOverrides.put("hibernate.show_sql", "true"); | |
| 102 | - configOverrides.put("hibernate.hbm2ddl.auto", "create-drop"); | |
| 103 | - | |
| 104 | - EntityManagerFactory factory = Persistence.createEntityManagerFactory("pu1", configOverrides); | |
| 105 | - EntityManager delegate = factory.createEntityManager(); | |
| 106 | - | |
| 107 | - Map<String, EntityManager> cache = Collections.synchronizedMap(new HashMap<String, EntityManager>()); | |
| 108 | - cache.put("pu1", delegate); | |
| 109 | - | |
| 110 | - producer = new EntityManagerProducer(); | |
| 111 | - Whitebox.setInternalState(producer, "cache", cache); | |
| 112 | - | |
| 113 | - PowerMock.mockStatic(Beans.class); | |
| 114 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).anyTimes(); | |
| 115 | - PowerMock.replayAll(); | |
| 116 | - | |
| 117 | - manager = new EntityManagerProxy("pu1"); | |
| 118 | - } | |
| 119 | - | |
| 120 | - @Test | |
| 121 | - public void testGetResultList() { | |
| 122 | - Query queryDelegate = PowerMock.createMock(Query.class); | |
| 123 | - List<String> result = new ArrayList<String>(); | |
| 124 | - result.add("x"); | |
| 125 | - EasyMock.expect(queryDelegate.getResultList()).andReturn(result).anyTimes(); | |
| 126 | - | |
| 127 | - replay(queryDelegate); | |
| 128 | - | |
| 129 | - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 130 | - queryProxy.getResultList(); | |
| 131 | - assertEquals(queryProxy.getResultList().size(), queryDelegate.getResultList().size()); | |
| 132 | - | |
| 133 | - verifyAll(); | |
| 134 | - } | |
| 135 | - | |
| 136 | - @Test | |
| 137 | - public void testSingleResult() { | |
| 138 | - Query queryDelegate = PowerMock.createMock(Query.class); | |
| 139 | - String result = "Resultado"; | |
| 140 | - EasyMock.expect(queryDelegate.getSingleResult()).andReturn(result).anyTimes(); | |
| 141 | - | |
| 142 | - replay(queryDelegate); | |
| 143 | - | |
| 144 | - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 145 | - assertEquals(queryProxy.getSingleResult(), queryDelegate.getSingleResult()); | |
| 146 | - | |
| 147 | - verifyAll(); | |
| 148 | - } | |
| 149 | - | |
| 150 | - @Test | |
| 151 | - public void testExecuteUpdate() { | |
| 152 | - Query queryDelegate = PowerMock.createMock(Query.class); | |
| 153 | - EasyMock.expect(queryDelegate.executeUpdate()).andReturn(1).anyTimes(); | |
| 154 | - | |
| 155 | - replay(queryDelegate); | |
| 156 | - | |
| 157 | - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 158 | - assertEquals(queryProxy.executeUpdate(), 1); | |
| 159 | - | |
| 160 | - verifyAll(); | |
| 161 | - } | |
| 162 | - | |
| 163 | - @Test | |
| 164 | - public void testPagination() { | |
| 165 | - Query queryDelegate = PowerMock.createMock(Query.class); | |
| 166 | - expect(queryDelegate.getMaxResults()).andReturn(4).times(2); | |
| 167 | - expect(queryDelegate.getFirstResult()).andReturn(2).times(2); | |
| 168 | - expect(queryDelegate.setMaxResults(EasyMock.anyInt())).andReturn(queryDelegate); | |
| 169 | - expect(queryDelegate.setFirstResult(EasyMock.anyInt())).andReturn(queryDelegate); | |
| 170 | - replay(queryDelegate); | |
| 171 | - | |
| 172 | - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 173 | - queryProxy.setMaxResults(4); | |
| 174 | - queryProxy.setFirstResult(2); | |
| 175 | - assertEquals(queryProxy.getMaxResults(), queryDelegate.getMaxResults()); | |
| 176 | - assertEquals(queryProxy.getFirstResult(), queryDelegate.getFirstResult()); | |
| 177 | - | |
| 178 | - verifyAll(); | |
| 179 | - } | |
| 180 | - | |
| 181 | - @Test | |
| 182 | - public void testHint() { | |
| 183 | - Query queryDelegate = PowerMock.createMock(Query.class); | |
| 184 | - Map<String, Object> map = new HashMap<String, Object>(); | |
| 185 | - Client client = new Client(); | |
| 186 | - map.put("1", client); | |
| 187 | - expect(queryDelegate.getHints()).andReturn(map).times(2); | |
| 188 | - expect(queryDelegate.setHint(EasyMock.anyObject(String.class), EasyMock.anyObject())).andReturn(queryDelegate); | |
| 189 | - replay(queryDelegate); | |
| 190 | - | |
| 191 | - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 192 | - queryProxy.setHint("1", client); | |
| 193 | - assertEquals(queryProxy.getHints(), queryDelegate.getHints()); | |
| 194 | - | |
| 195 | - verifyAll(); | |
| 196 | - } | |
| 197 | - | |
| 198 | - @SuppressWarnings({ "unused", "rawtypes", "unchecked" }) | |
| 199 | - @Test | |
| 200 | - public void testParameters() { | |
| 201 | - Query queryDelegate = PowerMock.createMock(Query.class); | |
| 202 | - Date dateValue = new Date(); | |
| 203 | - Calendar calendar = PowerMock.createMock(Calendar.class); | |
| 204 | - Class<Date> type = Date.class; | |
| 205 | - Parameter parameter = PowerMock.createMock(Parameter.class); | |
| 206 | - | |
| 207 | - expect(queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))) | |
| 208 | - .andReturn(queryDelegate); | |
| 209 | - expect(queryDelegate.getParameterValue(EasyMock.anyObject(String.class))).andReturn("Named Parameter") | |
| 210 | - .anyTimes(); | |
| 211 | - expect(queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(String.class))) | |
| 212 | - .andReturn(queryDelegate); | |
| 213 | - expect(queryDelegate.getParameterValue(EasyMock.anyInt())).andReturn("Client").anyTimes(); | |
| 214 | - expect( | |
| 215 | - queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(Date.class), | |
| 216 | - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | |
| 217 | - expect( | |
| 218 | - queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(Date.class), | |
| 219 | - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | |
| 220 | - expect(queryDelegate.setParameter(EasyMock.anyObject(Parameter.class), EasyMock.anyObject())).andReturn( | |
| 221 | - queryDelegate); | |
| 222 | - expect(queryDelegate.getParameterValue(EasyMock.anyObject(Parameter.class))).andReturn(parameter).anyTimes(); | |
| 223 | - expect( | |
| 224 | - queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(Calendar.class), | |
| 225 | - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | |
| 226 | - expect( | |
| 227 | - queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(Calendar.class), | |
| 228 | - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | |
| 229 | - | |
| 230 | - replay(queryDelegate, parameter, calendar); | |
| 231 | - | |
| 232 | - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 233 | - queryProxy.setParameter("name", "Named Parameter"); | |
| 234 | - assertEquals(queryProxy.getParameterValue("name"), queryDelegate.getParameterValue("name")); | |
| 235 | - queryProxy.setParameter(1, "Client"); | |
| 236 | - assertEquals(queryProxy.getParameterValue("1"), queryDelegate.getParameterValue("1")); | |
| 237 | - queryProxy.setParameter("dateName", dateValue, TemporalType.DATE); | |
| 238 | - queryProxy.setParameter(2, dateValue, TemporalType.DATE); | |
| 239 | - queryProxy.setParameter(parameter, "X"); | |
| 240 | - queryProxy.getParameterValue(parameter); | |
| 241 | - assertEquals(queryProxy.getParameterValue(parameter), parameter); | |
| 242 | - queryProxy.setParameter("dateName", calendar, TemporalType.DATE); | |
| 243 | - queryProxy.setParameter(2, calendar, TemporalType.DATE); | |
| 244 | - | |
| 245 | - verifyAll(); | |
| 246 | - } | |
| 247 | - | |
| 248 | - @SuppressWarnings("rawtypes") | |
| 249 | - @Test | |
| 250 | - public void testIsBound() { | |
| 251 | - Query queryDelegate = PowerMock.createMock(Query.class); | |
| 252 | - Parameter parameter = PowerMock.createMock(Parameter.class); | |
| 253 | - expect(queryDelegate.isBound(EasyMock.anyObject(Parameter.class))).andReturn(true); | |
| 254 | - | |
| 255 | - replay(queryDelegate, parameter); | |
| 256 | - | |
| 257 | - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 258 | - assertTrue(queryProxy.isBound(parameter)); | |
| 259 | - | |
| 260 | - verifyAll(); | |
| 261 | - } | |
| 262 | - | |
| 263 | - @Test | |
| 264 | - public void testFlushMode() { | |
| 265 | - Query queryDelegate = PowerMock.createMock(Query.class); | |
| 266 | - FlushModeType flushModeType = FlushModeType.AUTO; | |
| 267 | - | |
| 268 | - expect(queryDelegate.setFlushMode(FlushModeType.AUTO)).andReturn(queryDelegate); | |
| 269 | - expect(queryDelegate.getFlushMode()).andReturn(flushModeType).anyTimes(); | |
| 270 | - | |
| 271 | - replay(queryDelegate); | |
| 272 | - | |
| 273 | - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 274 | - queryProxy.setFlushMode(FlushModeType.AUTO); | |
| 275 | - assertEquals(queryProxy.getFlushMode(), queryDelegate.getFlushMode()); | |
| 276 | - verifyAll(); | |
| 277 | - } | |
| 278 | - | |
| 279 | - @Test | |
| 280 | - public void testLockMode() { | |
| 281 | - Query queryDelegate = PowerMock.createMock(Query.class); | |
| 282 | - LockModeType lockModeType = LockModeType.OPTIMISTIC; | |
| 283 | - | |
| 284 | - expect(queryDelegate.setLockMode(lockModeType)).andReturn(queryDelegate); | |
| 285 | - expect(queryDelegate.getLockMode()).andReturn(lockModeType).anyTimes(); | |
| 286 | - | |
| 287 | - replay(queryDelegate); | |
| 288 | - | |
| 289 | - queryProxy = new QueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 290 | - queryProxy.setLockMode(lockModeType); | |
| 291 | - assertEquals(queryProxy.getLockMode(), queryDelegate.getLockMode()); | |
| 292 | - verifyAll(); | |
| 293 | - } | |
| 294 | -} |
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/internal/proxy/TypedQueryProxyTest.java
| ... | ... | @@ -1,258 +0,0 @@ |
| 1 | -package br.gov.frameworkdemoiselle.internal.proxy; | |
| 2 | - | |
| 3 | -import static junit.framework.Assert.assertTrue; | |
| 4 | -import static org.easymock.EasyMock.expect; | |
| 5 | -import static org.junit.Assert.assertEquals; | |
| 6 | -import static org.powermock.api.easymock.PowerMock.replay; | |
| 7 | -import static org.powermock.api.easymock.PowerMock.verifyAll; | |
| 8 | - | |
| 9 | -import java.util.ArrayList; | |
| 10 | -import java.util.Calendar; | |
| 11 | -import java.util.Collections; | |
| 12 | -import java.util.Date; | |
| 13 | -import java.util.HashMap; | |
| 14 | -import java.util.List; | |
| 15 | -import java.util.Map; | |
| 16 | - | |
| 17 | -import javax.persistence.EntityManager; | |
| 18 | -import javax.persistence.EntityManagerFactory; | |
| 19 | -import javax.persistence.FlushModeType; | |
| 20 | -import javax.persistence.LockModeType; | |
| 21 | -import javax.persistence.Parameter; | |
| 22 | -import javax.persistence.Persistence; | |
| 23 | -import javax.persistence.Query; | |
| 24 | -import javax.persistence.TemporalType; | |
| 25 | -import javax.persistence.TypedQuery; | |
| 26 | - | |
| 27 | -import org.easymock.EasyMock; | |
| 28 | -import org.junit.Before; | |
| 29 | -import org.junit.Test; | |
| 30 | -import org.junit.runner.RunWith; | |
| 31 | -import org.powermock.api.easymock.PowerMock; | |
| 32 | -import org.powermock.core.classloader.annotations.PrepareForTest; | |
| 33 | -import org.powermock.modules.junit4.PowerMockRunner; | |
| 34 | -import org.powermock.reflect.Whitebox; | |
| 35 | - | |
| 36 | -import br.gov.frameworkdemoiselle.domain.Client; | |
| 37 | -import br.gov.frameworkdemoiselle.internal.producer.EntityManagerProducer; | |
| 38 | -import br.gov.frameworkdemoiselle.util.Beans; | |
| 39 | - | |
| 40 | -/** | |
| 41 | - * Test the proxied {@link Query} class, {@link TypedQueryProxy}. | |
| 42 | - * | |
| 43 | - * @author 81986912515 | |
| 44 | - * @param <X> | |
| 45 | - */ | |
| 46 | - | |
| 47 | -@SuppressWarnings("rawtypes") | |
| 48 | -@RunWith(PowerMockRunner.class) | |
| 49 | -@PrepareForTest({ Beans.class }) | |
| 50 | -public class TypedQueryProxyTest { | |
| 51 | - | |
| 52 | - private EntityManager manager; | |
| 53 | - | |
| 54 | - private EntityManagerProducer producer; | |
| 55 | - | |
| 56 | - private TypedQueryProxy typedQueryProxy; | |
| 57 | - | |
| 58 | - @Before | |
| 59 | - public void setUp() { | |
| 60 | - | |
| 61 | - Map<String, Object> configOverrides = new HashMap<String, Object>(); | |
| 62 | - configOverrides.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence"); | |
| 63 | - | |
| 64 | - configOverrides.put("javax.persistence.jdbc.url", "jdbc:hsqldb:mem:."); | |
| 65 | - configOverrides.put("javax.persistence.jdbc.driver", "org.hsqldb.jdbcDriver"); | |
| 66 | - configOverrides.put("javax.persistence.jdbc.user", "sa"); | |
| 67 | - configOverrides.put("javax.persistence.jdbc.password", ""); | |
| 68 | - | |
| 69 | - configOverrides.put("hibernate.show_sql", "true"); | |
| 70 | - configOverrides.put("hibernate.hbm2ddl.auto", "create-drop"); | |
| 71 | - | |
| 72 | - EntityManagerFactory factory = Persistence.createEntityManagerFactory("pu1", configOverrides); | |
| 73 | - EntityManager delegate = factory.createEntityManager(); | |
| 74 | - | |
| 75 | - Map<String, EntityManager> cache = Collections.synchronizedMap(new HashMap<String, EntityManager>()); | |
| 76 | - cache.put("pu1", delegate); | |
| 77 | - | |
| 78 | - producer = new EntityManagerProducer(); | |
| 79 | - Whitebox.setInternalState(producer, "cache", cache); | |
| 80 | - | |
| 81 | - PowerMock.mockStatic(Beans.class); | |
| 82 | - EasyMock.expect(Beans.getReference(EntityManagerProducer.class)).andReturn(producer).anyTimes(); | |
| 83 | - PowerMock.replayAll(); | |
| 84 | - | |
| 85 | - manager = new EntityManagerProxy("pu1"); | |
| 86 | - | |
| 87 | - // PowerMock.resetAll(); | |
| 88 | - } | |
| 89 | - | |
| 90 | - @SuppressWarnings("unchecked") | |
| 91 | - @Test | |
| 92 | - public void testResultList() { | |
| 93 | - | |
| 94 | - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | |
| 95 | - List<String> result = new ArrayList<String>(); | |
| 96 | - result.add("x"); | |
| 97 | - EasyMock.expect(queryDelegate.getResultList()).andReturn(result).anyTimes(); | |
| 98 | - | |
| 99 | - replay(queryDelegate); | |
| 100 | - | |
| 101 | - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 102 | - assertEquals(typedQueryProxy.getResultList().size(), queryDelegate.getResultList().size()); | |
| 103 | - | |
| 104 | - verifyAll(); | |
| 105 | - } | |
| 106 | - | |
| 107 | - @SuppressWarnings("unchecked") | |
| 108 | - @Test | |
| 109 | - public void testSingleResult() { | |
| 110 | - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | |
| 111 | - String result = "Resultado"; | |
| 112 | - EasyMock.expect(queryDelegate.getSingleResult()).andReturn(result).anyTimes(); | |
| 113 | - | |
| 114 | - replay(queryDelegate); | |
| 115 | - | |
| 116 | - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 117 | - assertEquals(typedQueryProxy.getSingleResult(), queryDelegate.getSingleResult()); | |
| 118 | - | |
| 119 | - verifyAll(); | |
| 120 | - } | |
| 121 | - | |
| 122 | - @SuppressWarnings("unchecked") | |
| 123 | - @Test | |
| 124 | - public void testPagination() { | |
| 125 | - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | |
| 126 | - expect(queryDelegate.getMaxResults()).andReturn(4).times(2); | |
| 127 | - expect(queryDelegate.getFirstResult()).andReturn(2).times(2); | |
| 128 | - expect(queryDelegate.setMaxResults(EasyMock.anyInt())).andReturn(queryDelegate); | |
| 129 | - expect(queryDelegate.setFirstResult(EasyMock.anyInt())).andReturn(queryDelegate); | |
| 130 | - replay(queryDelegate); | |
| 131 | - | |
| 132 | - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 133 | - typedQueryProxy.setMaxResults(4); | |
| 134 | - typedQueryProxy.setFirstResult(2); | |
| 135 | - assertEquals(typedQueryProxy.getMaxResults(), queryDelegate.getMaxResults()); | |
| 136 | - assertEquals(typedQueryProxy.getFirstResult(), queryDelegate.getFirstResult()); | |
| 137 | - | |
| 138 | - verifyAll(); | |
| 139 | - } | |
| 140 | - | |
| 141 | - @SuppressWarnings("unchecked") | |
| 142 | - @Test | |
| 143 | - public void testHint() { | |
| 144 | - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | |
| 145 | - Map<String, Object> map = new HashMap<String, Object>(); | |
| 146 | - Client client = new Client(); | |
| 147 | - map.put("1", client); | |
| 148 | - expect(queryDelegate.getHints()).andReturn(map).times(2); | |
| 149 | - expect(queryDelegate.setHint(EasyMock.anyObject(String.class), EasyMock.anyObject())).andReturn(queryDelegate); | |
| 150 | - replay(queryDelegate); | |
| 151 | - | |
| 152 | - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 153 | - typedQueryProxy.setHint("1", client); | |
| 154 | - assertEquals(typedQueryProxy.getHints(), queryDelegate.getHints()); | |
| 155 | - | |
| 156 | - verifyAll(); | |
| 157 | - } | |
| 158 | - | |
| 159 | - @SuppressWarnings({ "unchecked", "unused" }) | |
| 160 | - @Test | |
| 161 | - public void testParameters() { | |
| 162 | - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | |
| 163 | - Date dateValue = new Date(); | |
| 164 | - Calendar calendar = PowerMock.createMock(Calendar.class); | |
| 165 | - Class<Date> type = Date.class; | |
| 166 | - Parameter parameter = PowerMock.createMock(Parameter.class); | |
| 167 | - | |
| 168 | - expect(queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(String.class))) | |
| 169 | - .andReturn(queryDelegate); | |
| 170 | - expect(queryDelegate.getParameterValue(EasyMock.anyObject(String.class))).andReturn("Named Parameter") | |
| 171 | - .anyTimes(); | |
| 172 | - expect(queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(String.class))) | |
| 173 | - .andReturn(queryDelegate); | |
| 174 | - expect(queryDelegate.getParameterValue(EasyMock.anyInt())).andReturn("Client").anyTimes(); | |
| 175 | - expect( | |
| 176 | - queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(Date.class), | |
| 177 | - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | |
| 178 | - expect( | |
| 179 | - queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(Date.class), | |
| 180 | - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | |
| 181 | - expect(queryDelegate.setParameter(EasyMock.anyObject(Parameter.class), EasyMock.anyObject())).andReturn( | |
| 182 | - queryDelegate); | |
| 183 | - expect(queryDelegate.getParameterValue(EasyMock.anyObject(Parameter.class))).andReturn(parameter).anyTimes(); | |
| 184 | - expect( | |
| 185 | - queryDelegate.setParameter(EasyMock.anyObject(String.class), EasyMock.anyObject(Calendar.class), | |
| 186 | - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | |
| 187 | - expect( | |
| 188 | - queryDelegate.setParameter(EasyMock.anyInt(), EasyMock.anyObject(Calendar.class), | |
| 189 | - EasyMock.anyObject(TemporalType.class))).andReturn(queryDelegate); | |
| 190 | - | |
| 191 | - replay(queryDelegate, parameter, calendar); | |
| 192 | - | |
| 193 | - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 194 | - typedQueryProxy.setParameter("name", "Named Parameter"); | |
| 195 | - assertEquals(typedQueryProxy.getParameterValue("name"), queryDelegate.getParameterValue("name")); | |
| 196 | - typedQueryProxy.setParameter(1, "Client"); | |
| 197 | - assertEquals(typedQueryProxy.getParameterValue("1"), queryDelegate.getParameterValue("1")); | |
| 198 | - typedQueryProxy.setParameter("dateName", dateValue, TemporalType.DATE); | |
| 199 | - typedQueryProxy.setParameter(2, dateValue, TemporalType.DATE); | |
| 200 | - typedQueryProxy.setParameter(parameter, "X"); | |
| 201 | - typedQueryProxy.getParameterValue(parameter); | |
| 202 | - assertEquals(typedQueryProxy.getParameterValue(parameter), parameter); | |
| 203 | - typedQueryProxy.setParameter("dateName", calendar, TemporalType.DATE); | |
| 204 | - typedQueryProxy.setParameter(2, calendar, TemporalType.DATE); | |
| 205 | - | |
| 206 | - verifyAll(); | |
| 207 | - } | |
| 208 | - | |
| 209 | - @SuppressWarnings("unchecked") | |
| 210 | - @Test | |
| 211 | - public void testIsBound() { | |
| 212 | - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | |
| 213 | - Parameter parameter = PowerMock.createMock(Parameter.class); | |
| 214 | - expect(queryDelegate.isBound(EasyMock.anyObject(Parameter.class))).andReturn(true); | |
| 215 | - | |
| 216 | - replay(queryDelegate, parameter); | |
| 217 | - | |
| 218 | - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 219 | - assertTrue(typedQueryProxy.isBound(parameter)); | |
| 220 | - | |
| 221 | - verifyAll(); | |
| 222 | - } | |
| 223 | - | |
| 224 | - @SuppressWarnings("unchecked") | |
| 225 | - @Test | |
| 226 | - public void testFlushMode() { | |
| 227 | - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | |
| 228 | - FlushModeType flushModeType = FlushModeType.AUTO; | |
| 229 | - | |
| 230 | - expect(queryDelegate.setFlushMode(FlushModeType.AUTO)).andReturn(queryDelegate); | |
| 231 | - expect(queryDelegate.getFlushMode()).andReturn(flushModeType).anyTimes(); | |
| 232 | - | |
| 233 | - replay(queryDelegate); | |
| 234 | - | |
| 235 | - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 236 | - typedQueryProxy.setFlushMode(FlushModeType.AUTO); | |
| 237 | - assertEquals(typedQueryProxy.getFlushMode(), queryDelegate.getFlushMode()); | |
| 238 | - verifyAll(); | |
| 239 | - } | |
| 240 | - | |
| 241 | - @SuppressWarnings("unchecked") | |
| 242 | - @Test | |
| 243 | - public void testLockMode() { | |
| 244 | - TypedQuery queryDelegate = PowerMock.createMock(TypedQuery.class); | |
| 245 | - LockModeType lockModeType = LockModeType.OPTIMISTIC; | |
| 246 | - | |
| 247 | - expect(queryDelegate.setLockMode(lockModeType)).andReturn(queryDelegate); | |
| 248 | - expect(queryDelegate.getLockMode()).andReturn(lockModeType).anyTimes(); | |
| 249 | - | |
| 250 | - replay(queryDelegate); | |
| 251 | - | |
| 252 | - typedQueryProxy = new TypedQueryProxy(queryDelegate, (EntityManagerProxy) manager); | |
| 253 | - typedQueryProxy.setLockMode(lockModeType); | |
| 254 | - assertEquals(typedQueryProxy.getLockMode(), queryDelegate.getLockMode()); | |
| 255 | - verifyAll(); | |
| 256 | - } | |
| 257 | - | |
| 258 | -} |
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/template/JPACrudTest.java
| ... | ... | @@ -1,434 +0,0 @@ |
| 1 | -/* | |
| 2 | - * Demoiselle Framework | |
| 3 | - * Copyright (C) 2010 SERPRO | |
| 4 | - * ---------------------------------------------------------------------------- | |
| 5 | - * This file is part of Demoiselle Framework. | |
| 6 | - * | |
| 7 | - * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | - * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | - * as published by the Free Software Foundation. | |
| 10 | - * | |
| 11 | - * This program is distributed in the hope that it will be useful, | |
| 12 | - * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | - * GNU General Public License for more details. | |
| 15 | - * | |
| 16 | - * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | - * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | - * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | - * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | - * ---------------------------------------------------------------------------- | |
| 21 | - * Este arquivo é parte do Framework Demoiselle. | |
| 22 | - * | |
| 23 | - * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | - * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | - * do Software Livre (FSF). | |
| 26 | - * | |
| 27 | - * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | - * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | - * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | - * para maiores detalhes. | |
| 31 | - * | |
| 32 | - * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | - * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | - * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | - * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | - */ | |
| 37 | -package br.gov.frameworkdemoiselle.template; | |
| 38 | -import static org.easymock.EasyMock.expect; | |
| 39 | -import static org.easymock.EasyMock.replay; | |
| 40 | -import static org.easymock.EasyMock.verify; | |
| 41 | -import static org.junit.Assert.assertEquals; | |
| 42 | -import static org.junit.Assert.assertTrue; | |
| 43 | -import static org.junit.Assert.fail; | |
| 44 | -import static org.powermock.api.easymock.PowerMock.replayAll; | |
| 45 | -import static org.powermock.api.easymock.PowerMock.verifyAll; | |
| 46 | -import static org.powermock.reflect.Whitebox.setInternalState; | |
| 47 | - | |
| 48 | -import java.util.ArrayList; | |
| 49 | -import java.util.HashMap; | |
| 50 | -import java.util.List; | |
| 51 | -import java.util.Map; | |
| 52 | - | |
| 53 | -import javax.enterprise.inject.Instance; | |
| 54 | -import javax.persistence.EntityManager; | |
| 55 | -import javax.persistence.EntityManagerFactory; | |
| 56 | -import javax.persistence.Persistence; | |
| 57 | -import javax.persistence.Query; | |
| 58 | -import javax.persistence.TransactionRequiredException; | |
| 59 | -import javax.persistence.TypedQuery; | |
| 60 | -import javax.persistence.criteria.CriteriaBuilder; | |
| 61 | -import javax.persistence.criteria.CriteriaQuery; | |
| 62 | -import javax.persistence.criteria.Predicate; | |
| 63 | -import javax.persistence.criteria.Root; | |
| 64 | - | |
| 65 | -import junit.framework.Assert; | |
| 66 | - | |
| 67 | -import org.easymock.EasyMock; | |
| 68 | -import org.junit.Before; | |
| 69 | -import org.junit.Test; | |
| 70 | -import org.junit.runner.RunWith; | |
| 71 | -import org.powermock.api.easymock.PowerMock; | |
| 72 | -import org.powermock.core.classloader.annotations.PrepareForTest; | |
| 73 | -import org.powermock.modules.junit4.PowerMockRunner; | |
| 74 | -import org.powermock.reflect.Whitebox; | |
| 75 | - | |
| 76 | -import br.gov.frameworkdemoiselle.DemoiselleException; | |
| 77 | -import br.gov.frameworkdemoiselle.configuration.Configuration; | |
| 78 | -import br.gov.frameworkdemoiselle.domain.Contact; | |
| 79 | -import br.gov.frameworkdemoiselle.internal.implementation.PaginationImpl; | |
| 80 | -import br.gov.frameworkdemoiselle.pagination.Pagination; | |
| 81 | -import br.gov.frameworkdemoiselle.pagination.PaginationContext; | |
| 82 | -import br.gov.frameworkdemoiselle.util.Beans; | |
| 83 | -import br.gov.frameworkdemoiselle.util.ResourceBundle; | |
| 84 | - | |
| 85 | -@RunWith(PowerMockRunner.class) | |
| 86 | -@PrepareForTest({ ResourceBundle.class, Instance.class, Beans.class }) | |
| 87 | -public class JPACrudTest { | |
| 88 | - | |
| 89 | - private EntityManager entityManager; | |
| 90 | - | |
| 91 | - private Contact contact; | |
| 92 | - | |
| 93 | - private ContactDAO contactDAO; | |
| 94 | - | |
| 95 | - class ContactDAO extends JPACrud<Contact, Long> { | |
| 96 | - | |
| 97 | - private static final long serialVersionUID = 1L; | |
| 98 | - | |
| 99 | - } | |
| 100 | - | |
| 101 | - @Before | |
| 102 | - public void setUp() throws Exception { | |
| 103 | - this.entityManager = EasyMock.createMock(EntityManager.class); | |
| 104 | - this.contact = new Contact(); | |
| 105 | - this.contactDAO = new ContactDAO(); | |
| 106 | - setInternalState(this.contactDAO, EntityManager.class, this.entityManager); | |
| 107 | - } | |
| 108 | - | |
| 109 | - @Test | |
| 110 | - public void testDelete() { | |
| 111 | - expect(this.entityManager.getReference(Contact.class, null)).andReturn(null); | |
| 112 | - this.entityManager.remove(null); | |
| 113 | - replay(this.entityManager); | |
| 114 | - this.contactDAO.delete(this.contact.getId()); | |
| 115 | - verify(this.entityManager); | |
| 116 | - } | |
| 117 | - | |
| 118 | - private TypedQuery<Contact> makeTypedQuery() { | |
| 119 | - @SuppressWarnings("unchecked") | |
| 120 | - TypedQuery<Contact> typeQuery = EasyMock.createMock(TypedQuery.class); | |
| 121 | - expect(typeQuery.setFirstResult(EasyMock.anyInt())).andReturn(null); | |
| 122 | - expect(typeQuery.setMaxResults(EasyMock.anyInt())).andReturn(null); | |
| 123 | - expect(typeQuery.getResultList()).andReturn(createContacts(1)); | |
| 124 | - return typeQuery; | |
| 125 | - } | |
| 126 | - | |
| 127 | - @Test | |
| 128 | - public void testCountAll() { | |
| 129 | - | |
| 130 | - Pagination pagination = new PaginationImpl(); | |
| 131 | - pagination.setPageSize(10); | |
| 132 | - setInternalState(this.contactDAO, "pagination", pagination); | |
| 133 | - | |
| 134 | - TypedQuery<Contact> typeQuery = makeTypedQuery(); | |
| 135 | - | |
| 136 | - Query query = EasyMock.createMock(Query.class); | |
| 137 | - expect(query.getSingleResult()).andReturn(10L); | |
| 138 | - | |
| 139 | - expect(this.entityManager.createQuery("select this from Contact this", Contact.class)).andReturn(typeQuery); | |
| 140 | - //expect(this.entityManager.createQuery("SELECT COUNT(THIS) FROM CONTACT THIS")).andReturn(query); | |
| 141 | - expect(this.entityManager.createQuery("select COUNT(this) from Contact this")).andReturn(query); | |
| 142 | - | |
| 143 | - replayAll(typeQuery, query, this.entityManager); | |
| 144 | - | |
| 145 | - List<Contact> find = this.contactDAO.findAll(); | |
| 146 | - | |
| 147 | - assertEquals(1, find.size()); | |
| 148 | - assertTrue(find.iterator().next().getId().equals(1L)); | |
| 149 | - | |
| 150 | - verifyAll(); | |
| 151 | - } | |
| 152 | - | |
| 153 | - @Test | |
| 154 | - public void testFailCountAll() { | |
| 155 | - | |
| 156 | - Pagination pagination = new PaginationImpl(); | |
| 157 | - setInternalState(this.contactDAO, "pagination", pagination); | |
| 158 | - | |
| 159 | - TypedQuery<Contact> typeQuery = makeTypedQuery(); | |
| 160 | - | |
| 161 | - Query query = EasyMock.createMock(Query.class); | |
| 162 | - | |
| 163 | - expect(query.getSingleResult()).andThrow(new DemoiselleException("")); | |
| 164 | - expect(this.entityManager.createQuery("select this from Contact this", Contact.class)).andReturn(typeQuery); | |
| 165 | - expect(this.entityManager.createQuery("select COUNT(this) from Contact this")).andReturn(query); | |
| 166 | - | |
| 167 | - replayAll(query, this.entityManager); | |
| 168 | - | |
| 169 | - try { | |
| 170 | - this.contactDAO.findAll(); | |
| 171 | - fail(); | |
| 172 | - } catch (DemoiselleException exception) { | |
| 173 | - } | |
| 174 | - | |
| 175 | - verifyAll(); | |
| 176 | - } | |
| 177 | - | |
| 178 | - @SuppressWarnings("unchecked") | |
| 179 | - @Test | |
| 180 | - public void testHandleException() throws Throwable { | |
| 181 | - try { | |
| 182 | - TransactionRequiredException throwed = new TransactionRequiredException(); | |
| 183 | - ResourceBundle bundle = PowerMock.createMock(ResourceBundle.class); | |
| 184 | - Instance<ResourceBundle> instance = PowerMock.createMock(Instance.class); | |
| 185 | - expect( | |
| 186 | - bundle.getString("no-transaction-active", "frameworkdemoiselle.transaction.class", | |
| 187 | - Configuration.DEFAULT_RESOURCE)).andReturn("message"); | |
| 188 | - expect(instance.get()).andReturn(bundle); | |
| 189 | - setInternalState(contactDAO, "bundle", instance); | |
| 190 | - replayAll(); | |
| 191 | - contactDAO.handleException(throwed); | |
| 192 | - fail(); | |
| 193 | - } catch (DemoiselleException exception) { | |
| 194 | - assertEquals(exception.getMessage(), "message"); | |
| 195 | - } | |
| 196 | - verifyAll(); | |
| 197 | - } | |
| 198 | - | |
| 199 | - @SuppressWarnings("unchecked") | |
| 200 | - @Test | |
| 201 | - public void testFailFindByExample() { | |
| 202 | - | |
| 203 | - CriteriaBuilder criteriaBuilder = PowerMock.createMock(CriteriaBuilder.class); | |
| 204 | - CriteriaQuery<Contact> criteriaQuery = PowerMock.createMock(CriteriaQuery.class); | |
| 205 | - Root<Contact> root = PowerMock.createMock(Root.class); | |
| 206 | - | |
| 207 | - expect(this.entityManager.getCriteriaBuilder()).andReturn(criteriaBuilder); | |
| 208 | - expect(criteriaBuilder.createQuery(Contact.class)).andReturn(criteriaQuery); | |
| 209 | - expect(criteriaQuery.from(Contact.class)).andReturn(root); | |
| 210 | - | |
| 211 | - expect(this.entityManager.createQuery(criteriaQuery)).andThrow(new DemoiselleException("")); | |
| 212 | - | |
| 213 | - Predicate predicate = PowerMock.createMock(Predicate.class); | |
| 214 | - | |
| 215 | - expect(root.get("id")).andReturn(null); | |
| 216 | - expect(criteriaBuilder.equal(EasyMock.anyObject(Predicate.class), EasyMock.anyObject())).andReturn(predicate); | |
| 217 | - expect(criteriaQuery.where(new Predicate[] { EasyMock.anyObject(Predicate.class) })).andReturn(criteriaQuery); | |
| 218 | - expect(criteriaQuery.select(EasyMock.anyObject(Root.class))).andReturn(criteriaQuery); | |
| 219 | - | |
| 220 | - replayAll(criteriaBuilder, criteriaQuery, root, this.entityManager); | |
| 221 | - | |
| 222 | - Contact example = new Contact(); | |
| 223 | - example.setId(1L); | |
| 224 | - try { | |
| 225 | - this.contactDAO.findByExample(example); | |
| 226 | - fail(); | |
| 227 | - } catch (DemoiselleException ce) { | |
| 228 | - } | |
| 229 | - | |
| 230 | - verifyAll(); | |
| 231 | - } | |
| 232 | - | |
| 233 | - @SuppressWarnings("unchecked") | |
| 234 | - @Test | |
| 235 | - public void testFindByExample() { | |
| 236 | - | |
| 237 | - TypedQuery<Contact> typedQuery = EasyMock.createMock(TypedQuery.class); | |
| 238 | - CriteriaBuilder criteriaBuilder = PowerMock.createMock(CriteriaBuilder.class); | |
| 239 | - CriteriaQuery<Contact> criteriaQuery = PowerMock.createMock(CriteriaQuery.class); | |
| 240 | - Root<Contact> root = PowerMock.createMock(Root.class); | |
| 241 | - | |
| 242 | - expect(this.entityManager.getCriteriaBuilder()).andReturn(criteriaBuilder); | |
| 243 | - expect(criteriaBuilder.createQuery(Contact.class)).andReturn(criteriaQuery); | |
| 244 | - expect(criteriaQuery.from(Contact.class)).andReturn(root); | |
| 245 | - | |
| 246 | - expect(this.entityManager.createQuery(criteriaQuery)).andReturn(typedQuery); | |
| 247 | - expect(typedQuery.getResultList()).andReturn(createContacts(1)); | |
| 248 | - | |
| 249 | - Predicate predicate = PowerMock.createMock(Predicate.class); | |
| 250 | - | |
| 251 | - expect(root.get("id")).andReturn(null); | |
| 252 | - expect(criteriaBuilder.equal(EasyMock.anyObject(Predicate.class), EasyMock.anyObject())).andReturn(predicate); | |
| 253 | - expect(criteriaQuery.where(new Predicate[] { EasyMock.anyObject(Predicate.class) })).andReturn(criteriaQuery); | |
| 254 | - expect(criteriaQuery.select(EasyMock.anyObject(Root.class))).andReturn(criteriaQuery); | |
| 255 | - | |
| 256 | - replayAll(typedQuery, criteriaBuilder, criteriaQuery, root, this.entityManager); | |
| 257 | - | |
| 258 | - Contact example = new Contact(); | |
| 259 | - example.setId(1L); | |
| 260 | - List<Contact> find = this.contactDAO.findByExample(example); | |
| 261 | - | |
| 262 | - assertEquals(1, find.size()); | |
| 263 | - assertTrue(find.iterator().next().getId().equals(1L)); | |
| 264 | - | |
| 265 | - verifyAll(); | |
| 266 | - } | |
| 267 | - | |
| 268 | - @Test | |
| 269 | - public void testFindAll() { | |
| 270 | - | |
| 271 | - Pagination pagination = new PaginationImpl(); | |
| 272 | - pagination.setPageSize(10); | |
| 273 | - setInternalState(this.contactDAO, "pagination", pagination); | |
| 274 | - | |
| 275 | - TypedQuery<Contact> typeQuery = makeTypedQuery(); | |
| 276 | - | |
| 277 | - Query query = EasyMock.createMock(Query.class); | |
| 278 | - expect(query.getSingleResult()).andReturn(10L); | |
| 279 | - | |
| 280 | - expect(this.entityManager.createQuery("select this from Contact this", Contact.class)).andReturn(typeQuery); | |
| 281 | - expect(this.entityManager.createQuery("select COUNT(this) from Contact this")).andReturn(query); | |
| 282 | - | |
| 283 | - replayAll(typeQuery, query, this.entityManager); | |
| 284 | - | |
| 285 | - List<Contact> find = this.contactDAO.findAll(); | |
| 286 | - | |
| 287 | - assertEquals(1, find.size()); | |
| 288 | - assertTrue(find.iterator().next().getId().equals(1L)); | |
| 289 | - | |
| 290 | - verifyAll(); | |
| 291 | - } | |
| 292 | - | |
| 293 | - @Test | |
| 294 | - public void testFailFindAll() { | |
| 295 | - | |
| 296 | - PaginationContext actualContext = PowerMock.createMock(PaginationContext.class); | |
| 297 | - expect(actualContext.getPagination(Contact.class)).andReturn(null); | |
| 298 | - /*@SuppressWarnings("unchecked") | |
| 299 | - Instance<PaginationContext> paginationContext = PowerMock.createMock(Instance.class); | |
| 300 | - expect(paginationContext.get()).andReturn(actualContext);*/ | |
| 301 | - | |
| 302 | - PowerMock.mockStatic(Beans.class); | |
| 303 | - expect(Beans.getReference(PaginationContext.class)).andReturn(actualContext); | |
| 304 | - | |
| 305 | - @SuppressWarnings("unchecked") | |
| 306 | - TypedQuery<Contact> typeQuery = EasyMock.createMock(TypedQuery.class); | |
| 307 | - expect(typeQuery.getResultList()).andThrow(new DemoiselleException("")); | |
| 308 | - | |
| 309 | - Query query = EasyMock.createMock(Query.class); | |
| 310 | - expect(this.entityManager.createQuery("select this from Contact this", Contact.class)).andReturn(typeQuery); | |
| 311 | - | |
| 312 | - replayAll(typeQuery, query, this.entityManager); | |
| 313 | - | |
| 314 | - try { | |
| 315 | - this.contactDAO.findAll(); | |
| 316 | - fail(); | |
| 317 | - } catch (DemoiselleException exception) { | |
| 318 | - } | |
| 319 | - | |
| 320 | - verifyAll(); | |
| 321 | - } | |
| 322 | - | |
| 323 | - private List<Contact> createContacts(int quantity) { | |
| 324 | - List<Contact> contacts = new ArrayList<Contact>(); | |
| 325 | - for (int i = 0; i < quantity; i++) { | |
| 326 | - Contact contact = new Contact(); | |
| 327 | - contact.setId((long) quantity); | |
| 328 | - contacts.add(contact); | |
| 329 | - } | |
| 330 | - return contacts; | |
| 331 | - } | |
| 332 | - | |
| 333 | - @Test | |
| 334 | - public void testFailInsert() { | |
| 335 | - this.entityManager.persist(null); | |
| 336 | - EasyMock.expectLastCall().andThrow(new DemoiselleException("")); | |
| 337 | - replay(this.entityManager); | |
| 338 | - try { | |
| 339 | - this.contactDAO.insert(null); | |
| 340 | - fail(); | |
| 341 | - } catch (DemoiselleException exc) { | |
| 342 | - } | |
| 343 | - verify(this.entityManager); | |
| 344 | - } | |
| 345 | - | |
| 346 | - @Test | |
| 347 | - public void testInsert() { | |
| 348 | - this.entityManager.persist(this.contact); | |
| 349 | - replay(this.entityManager); | |
| 350 | - setInternalState(this.contactDAO, EntityManager.class, this.entityManager); | |
| 351 | - this.contactDAO.insert(this.contact); | |
| 352 | - verify(this.entityManager); | |
| 353 | - } | |
| 354 | - | |
| 355 | - @Test | |
| 356 | - public void testLoad() { | |
| 357 | - Contact contact = new Contact(); | |
| 358 | - expect(this.entityManager.find(Contact.class, 1L)).andReturn(contact); | |
| 359 | - replay(this.entityManager); | |
| 360 | - Contact returnedContact = this.contactDAO.load(1L); | |
| 361 | - assertEquals(contact.hashCode(), returnedContact.hashCode()); | |
| 362 | - verify(this.entityManager); | |
| 363 | - } | |
| 364 | - | |
| 365 | - @Test | |
| 366 | - public void testFailLoad() { | |
| 367 | - expect(this.entityManager.find(Contact.class, 1L)).andThrow(new DemoiselleException("")); | |
| 368 | - replay(this.entityManager); | |
| 369 | - try { | |
| 370 | - this.contactDAO.load(1L); | |
| 371 | - fail(); | |
| 372 | - } catch (DemoiselleException exc) { | |
| 373 | - } | |
| 374 | - verify(this.entityManager); | |
| 375 | - } | |
| 376 | - | |
| 377 | - @Test | |
| 378 | - public void testUpdate() { | |
| 379 | - expect(this.entityManager.merge(this.contact)).andReturn(null); | |
| 380 | - replay(this.entityManager); | |
| 381 | - setInternalState(this.contactDAO, EntityManager.class, this.entityManager); | |
| 382 | - this.contactDAO.update(this.contact); | |
| 383 | - verify(this.entityManager); | |
| 384 | - } | |
| 385 | - | |
| 386 | - @Test | |
| 387 | - public void testFailUpdate() { | |
| 388 | - this.entityManager.merge(null); | |
| 389 | - EasyMock.expectLastCall().andThrow(new DemoiselleException("")); | |
| 390 | - replay(this.entityManager); | |
| 391 | - try { | |
| 392 | - this.contactDAO.update(null); | |
| 393 | - fail(); | |
| 394 | - } catch (DemoiselleException exc) { | |
| 395 | - } | |
| 396 | - verify(this.entityManager); | |
| 397 | - } | |
| 398 | - | |
| 399 | - /** | |
| 400 | - * Test if the JPACrud will correctly obtain a new entity manager the first | |
| 401 | - * time it is called and the entity manager is still null. | |
| 402 | - */ | |
| 403 | - @Test | |
| 404 | - public void testCreateEntityManagerIfNotExist(){ | |
| 405 | - PowerMock.mockStatic(Beans.class); | |
| 406 | - expect(Beans.getReference(EntityManager.class)).andReturn(entityManager); | |
| 407 | - PowerMock.replay(Beans.class); | |
| 408 | - | |
| 409 | - setInternalState(this.contactDAO, EntityManager.class, (EntityManager)null); | |
| 410 | - Assert.assertNotNull(this.contactDAO.getEntityManager()); | |
| 411 | - } | |
| 412 | - | |
| 413 | - @Test | |
| 414 | - public void testCriteriaQuery(){ | |
| 415 | - Map<String, Object> configOverrides = new HashMap<String, Object>(); | |
| 416 | - configOverrides.put("javax.persistence.provider", "org.hibernate.ejb.HibernatePersistence"); | |
| 417 | - configOverrides.put("javax.persistence.jdbc.url", "jdbc:hsqldb:hsql:."); | |
| 418 | - configOverrides.put("hibernate.show_sql", "true"); | |
| 419 | - configOverrides.put("hibernate.hbm2ddl.auto", "create-drop"); | |
| 420 | - | |
| 421 | - EntityManagerFactory factory = Persistence.createEntityManagerFactory("pu1", configOverrides); | |
| 422 | - this.entityManager = factory.createEntityManager(); | |
| 423 | - Whitebox.setInternalState(this.contactDAO, EntityManager.class, (EntityManager)null); | |
| 424 | - | |
| 425 | - PowerMock.mockStatic(Beans.class); | |
| 426 | - expect(Beans.getReference(EntityManager.class)).andReturn(entityManager); | |
| 427 | - PowerMock.replay(Beans.class); | |
| 428 | - | |
| 429 | - CriteriaQuery<Contact> query = this.contactDAO.createCriteriaQuery(); | |
| 430 | - query.select( query.from(Contact.class) ); | |
| 431 | - | |
| 432 | - } | |
| 433 | - | |
| 434 | -} |
impl/extension/jpa/src/test/java/br/gov/frameworkdemoiselle/transaction/JPATransactionTest.java
| ... | ... | @@ -1,222 +0,0 @@ |
| 1 | -///* | |
| 2 | -// * Demoiselle Framework | |
| 3 | -// * Copyright (C) 2010 SERPRO | |
| 4 | -// * ---------------------------------------------------------------------------- | |
| 5 | -// * This file is part of Demoiselle Framework. | |
| 6 | -// * | |
| 7 | -// * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | -// * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | -// * as published by the Free Software Foundation. | |
| 10 | -// * | |
| 11 | -// * This program is distributed in the hope that it will be useful, | |
| 12 | -// * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | -// * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | -// * GNU General Public License for more details. | |
| 15 | -// * | |
| 16 | -// * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | -// * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | -// * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | -// * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | -// * ---------------------------------------------------------------------------- | |
| 21 | -// * Este arquivo é parte do Framework Demoiselle. | |
| 22 | -// * | |
| 23 | -// * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | -// * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | -// * do Software Livre (FSF). | |
| 26 | -// * | |
| 27 | -// * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | -// * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | -// * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | -// * para maiores detalhes. | |
| 31 | -// * | |
| 32 | -// * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | -// * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | -// * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | -// * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | -// */ | |
| 37 | -package br.gov.frameworkdemoiselle.transaction; | |
| 38 | -import static org.easymock.EasyMock.createMock; | |
| 39 | -import static org.easymock.EasyMock.expect; | |
| 40 | -import static org.easymock.EasyMock.replay; | |
| 41 | -import static org.junit.Assert.assertEquals; | |
| 42 | -import static org.powermock.api.easymock.PowerMock.replayAll; | |
| 43 | -import static org.powermock.api.easymock.PowerMock.verifyAll; | |
| 44 | -import static org.powermock.reflect.Whitebox.setInternalState; | |
| 45 | - | |
| 46 | -import java.util.HashMap; | |
| 47 | -import java.util.Map; | |
| 48 | - | |
| 49 | -import javax.persistence.EntityManager; | |
| 50 | -import javax.persistence.EntityTransaction; | |
| 51 | - | |
| 52 | -import org.easymock.EasyMock; | |
| 53 | -import org.junit.After; | |
| 54 | -import org.junit.Before; | |
| 55 | -import org.junit.Test; | |
| 56 | -import org.omg.CORBA.SystemException; | |
| 57 | - | |
| 58 | -import br.gov.frameworkdemoiselle.internal.producer.EntityManagerProducer; | |
| 59 | - | |
| 60 | -/** | |
| 61 | - * @author SERPRO | |
| 62 | - * @see JPATransaction | |
| 63 | - */ | |
| 64 | -public class JPATransactionTest { | |
| 65 | - | |
| 66 | - private JPATransaction tx; | |
| 67 | - | |
| 68 | - private EntityManager em; | |
| 69 | - | |
| 70 | - private EntityTransaction et; | |
| 71 | - | |
| 72 | - private Map<String, EntityManager> cache; | |
| 73 | - | |
| 74 | - private EntityManagerProducer producer; | |
| 75 | - | |
| 76 | - @Before | |
| 77 | - public void setUp() { | |
| 78 | - et = createMock(EntityTransaction.class); | |
| 79 | - em = createMock(EntityManager.class); | |
| 80 | - cache = new HashMap<String, EntityManager>(); | |
| 81 | - producer = EasyMock.createMock(EntityManagerProducer.class); | |
| 82 | - | |
| 83 | - tx = new JPATransaction(); | |
| 84 | - setInternalState(tx, EntityManagerProducer.class, producer); | |
| 85 | - } | |
| 86 | - | |
| 87 | - @After | |
| 88 | - public void tearDown() { | |
| 89 | - tx = null; | |
| 90 | - em = null; | |
| 91 | - et = null; | |
| 92 | - cache = null; | |
| 93 | - producer = null; | |
| 94 | - } | |
| 95 | - | |
| 96 | - @Test | |
| 97 | - public void testBegin() throws SystemException { | |
| 98 | - et.begin(); | |
| 99 | - expect(et.isActive()).andReturn(false); | |
| 100 | - expect(em.getTransaction()).andReturn(et).anyTimes(); | |
| 101 | - cache.put("teste", em); | |
| 102 | - expect(producer.getCache()).andReturn(cache); | |
| 103 | - replay(producer); | |
| 104 | - replayAll(); | |
| 105 | - replay(em); | |
| 106 | - replay(et); | |
| 107 | - | |
| 108 | - tx.begin(); | |
| 109 | - verifyAll(); | |
| 110 | - } | |
| 111 | - | |
| 112 | - @Test | |
| 113 | - public void testCommit() throws Exception { | |
| 114 | - et.commit(); | |
| 115 | - expect(et.isActive()).andReturn(true); | |
| 116 | - expect(em.getTransaction()).andReturn(et).anyTimes(); | |
| 117 | - cache.put("teste", em); | |
| 118 | - expect(producer.getCache()).andReturn(cache); | |
| 119 | - replay(producer); | |
| 120 | - replayAll(); | |
| 121 | - replay(em); | |
| 122 | - replay(et); | |
| 123 | - | |
| 124 | - tx.commit(); | |
| 125 | - verifyAll(); | |
| 126 | - } | |
| 127 | - | |
| 128 | - @Test | |
| 129 | - public void testRollback() throws Exception { | |
| 130 | - et.rollback(); | |
| 131 | - expect(et.isActive()).andReturn(true); | |
| 132 | - expect(em.getTransaction()).andReturn(et).anyTimes(); | |
| 133 | - em.clear(); | |
| 134 | - cache.put("teste", em); | |
| 135 | - expect(producer.getCache()).andReturn(cache); | |
| 136 | - replay(producer); | |
| 137 | - replayAll(); | |
| 138 | - replay(em); | |
| 139 | - replay(et); | |
| 140 | - | |
| 141 | - tx.rollback(); | |
| 142 | - verifyAll(); | |
| 143 | - } | |
| 144 | - | |
| 145 | - @Test | |
| 146 | - public void testSetRollbackOnly() throws Exception { | |
| 147 | - et.setRollbackOnly(); | |
| 148 | - expect(et.isActive()).andReturn(true); | |
| 149 | - expect(em.getTransaction()).andReturn(et).anyTimes(); | |
| 150 | - cache.put("teste", em); | |
| 151 | - expect(producer.getCache()).andReturn(cache); | |
| 152 | - replay(producer); | |
| 153 | - replayAll(); | |
| 154 | - replay(em); | |
| 155 | - replay(et); | |
| 156 | - | |
| 157 | - tx.setRollbackOnly(); | |
| 158 | - verifyAll(); | |
| 159 | - } | |
| 160 | - | |
| 161 | - @Test | |
| 162 | - public void testIsActiveTrue() throws Exception { | |
| 163 | - expect(et.isActive()).andReturn(true).anyTimes(); | |
| 164 | - expect(em.getTransaction()).andReturn(et).anyTimes(); | |
| 165 | - cache.put("teste", em); | |
| 166 | - expect(producer.getCache()).andReturn(cache); | |
| 167 | - replay(producer); | |
| 168 | - replayAll(); | |
| 169 | - replay(em); | |
| 170 | - replay(et); | |
| 171 | - | |
| 172 | - assertEquals(true, tx.isActive()); | |
| 173 | - verifyAll(); | |
| 174 | - } | |
| 175 | - | |
| 176 | - @Test | |
| 177 | - public void testIsActiveFalse() throws Exception { | |
| 178 | - expect(et.isActive()).andReturn(false).anyTimes(); | |
| 179 | - expect(em.getTransaction()).andReturn(et).anyTimes(); | |
| 180 | - cache.put("teste", em); | |
| 181 | - expect(producer.getCache()).andReturn(cache); | |
| 182 | - replay(producer); | |
| 183 | - replayAll(); | |
| 184 | - replay(em); | |
| 185 | - replay(et); | |
| 186 | - | |
| 187 | - assertEquals(false, tx.isActive()); | |
| 188 | - verifyAll(); | |
| 189 | - } | |
| 190 | - | |
| 191 | - @Test | |
| 192 | - public void testIsMarkedRollbackTrue() throws Exception { | |
| 193 | - expect(et.isActive()).andReturn(true); | |
| 194 | - expect(et.getRollbackOnly()).andReturn(true).anyTimes(); | |
| 195 | - expect(em.getTransaction()).andReturn(et).anyTimes(); | |
| 196 | - cache.put("teste", em); | |
| 197 | - expect(producer.getCache()).andReturn(cache); | |
| 198 | - replay(producer); | |
| 199 | - replayAll(); | |
| 200 | - replay(em); | |
| 201 | - replay(et); | |
| 202 | - | |
| 203 | - assertEquals(true, tx.isMarkedRollback()); | |
| 204 | - verifyAll(); | |
| 205 | - } | |
| 206 | - | |
| 207 | - @Test | |
| 208 | - public void testIsMarkedRollbackFalse() throws Exception { | |
| 209 | - expect(et.isActive()).andReturn(true); | |
| 210 | - expect(et.getRollbackOnly()).andReturn(false).anyTimes(); | |
| 211 | - expect(em.getTransaction()).andReturn(et).anyTimes(); | |
| 212 | - cache.put("teste", em); | |
| 213 | - expect(producer.getCache()).andReturn(cache); | |
| 214 | - replay(producer); | |
| 215 | - replayAll(); | |
| 216 | - replay(em); | |
| 217 | - replay(et); | |
| 218 | - | |
| 219 | - assertEquals(false, tx.isMarkedRollback()); | |
| 220 | - verifyAll(); | |
| 221 | - } | |
| 222 | -} |
impl/extension/jpa/src/test/java/template/JPACrudTest.java
0 → 100644
| ... | ... | @@ -0,0 +1,84 @@ |
| 1 | +package template; | |
| 2 | + | |
| 3 | +import static junit.framework.Assert.assertEquals; | |
| 4 | +import static junit.framework.Assert.assertNotNull; | |
| 5 | +import static junit.framework.Assert.assertNull; | |
| 6 | + | |
| 7 | +import javax.inject.Inject; | |
| 8 | + | |
| 9 | +import org.jboss.arquillian.container.test.api.Deployment; | |
| 10 | +import org.jboss.arquillian.junit.Arquillian; | |
| 11 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | |
| 12 | +import org.junit.Test; | |
| 13 | +import org.junit.runner.RunWith; | |
| 14 | + | |
| 15 | +import test.Tests; | |
| 16 | + | |
| 17 | +@RunWith(Arquillian.class) | |
| 18 | +public class JPACrudTest { | |
| 19 | + | |
| 20 | + private static final String PATH = "src/test/resources/template"; | |
| 21 | + | |
| 22 | + @Inject | |
| 23 | + private MyCrud crud; | |
| 24 | + | |
| 25 | + @Deployment | |
| 26 | + public static WebArchive createDeployment() { | |
| 27 | + WebArchive deployment = Tests.createDeployment(JPACrudTest.class); | |
| 28 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/persistence.xml"), "META-INF/persistence.xml"); | |
| 29 | + | |
| 30 | + return deployment; | |
| 31 | + } | |
| 32 | + | |
| 33 | + @Test | |
| 34 | + public void x() { | |
| 35 | + | |
| 36 | + } | |
| 37 | + | |
| 38 | + @Test | |
| 39 | + public void successfullyInserted() { | |
| 40 | + populate(1, 0); | |
| 41 | + | |
| 42 | + MyEntity persisted = crud.load(createId("id-1")); | |
| 43 | + assertNotNull(persisted); | |
| 44 | + } | |
| 45 | + | |
| 46 | + @Test | |
| 47 | + public void successfullyDeleted() { | |
| 48 | + populate(1, 10); | |
| 49 | + | |
| 50 | + crud.delete(createId("id-11")); | |
| 51 | + MyEntity persisted = crud.load(createId("id-11")); | |
| 52 | + assertNull(persisted); | |
| 53 | + } | |
| 54 | + | |
| 55 | + @Test | |
| 56 | + public void successfullyUpdated() { | |
| 57 | + populate(1, 20); | |
| 58 | + | |
| 59 | + MyEntity persisted; | |
| 60 | + persisted = crud.load(createId("id-21")); | |
| 61 | + persisted.setDescription("update example"); | |
| 62 | + | |
| 63 | + crud.update(persisted); | |
| 64 | + persisted = crud.load(createId("id-21")); | |
| 65 | + | |
| 66 | + assertEquals("update example", persisted.getDescription()); | |
| 67 | + } | |
| 68 | + | |
| 69 | + private void populate(int size, int offset) { | |
| 70 | + MyEntity entity; | |
| 71 | + | |
| 72 | + for (int i = 0; i < size; i++) { | |
| 73 | + entity = new MyEntity(); | |
| 74 | + entity.setId(createId("id-" + (i + 1 + offset))); | |
| 75 | + entity.setDescription("desc-" + (i + 1 + offset)); | |
| 76 | + | |
| 77 | + crud.insert(entity); | |
| 78 | + } | |
| 79 | + } | |
| 80 | + | |
| 81 | + private String createId(String id) { | |
| 82 | + return this.getClass().getName() + "_" + id; | |
| 83 | + } | |
| 84 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +package template; | |
| 2 | + | |
| 3 | +import javax.persistence.Entity; | |
| 4 | +import javax.persistence.Id; | |
| 5 | + | |
| 6 | +@Entity | |
| 7 | +public class MyEntity { | |
| 8 | + | |
| 9 | + @Id | |
| 10 | + private String id; | |
| 11 | + | |
| 12 | + private String description; | |
| 13 | + | |
| 14 | + public String getId() { | |
| 15 | + return id; | |
| 16 | + } | |
| 17 | + | |
| 18 | + public void setId(String id) { | |
| 19 | + this.id = id; | |
| 20 | + } | |
| 21 | + | |
| 22 | + public String getDescription() { | |
| 23 | + return description; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public void setDescription(String description) { | |
| 27 | + this.description = description; | |
| 28 | + } | |
| 29 | +} | ... | ... |
| ... | ... | @@ -0,0 +1,102 @@ |
| 1 | +/* | |
| 2 | + * Demoiselle Framework | |
| 3 | + * Copyright (C) 2010 SERPRO | |
| 4 | + * ---------------------------------------------------------------------------- | |
| 5 | + * This file is part of Demoiselle Framework. | |
| 6 | + * | |
| 7 | + * Demoiselle Framework is free software; you can redistribute it and/or | |
| 8 | + * modify it under the terms of the GNU Lesser General Public License version 3 | |
| 9 | + * as published by the Free Software Foundation. | |
| 10 | + * | |
| 11 | + * This program is distributed in the hope that it will be useful, | |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 14 | + * GNU General Public License for more details. | |
| 15 | + * | |
| 16 | + * You should have received a copy of the GNU Lesser General Public License version 3 | |
| 17 | + * along with this program; if not, see <http://www.gnu.org/licenses/> | |
| 18 | + * or write to the Free Software Foundation, Inc., 51 Franklin Street, | |
| 19 | + * Fifth Floor, Boston, MA 02110-1301, USA. | |
| 20 | + * ---------------------------------------------------------------------------- | |
| 21 | + * Este arquivo é parte do Framework Demoiselle. | |
| 22 | + * | |
| 23 | + * O Framework Demoiselle é um software livre; você pode redistribuí-lo e/ou | |
| 24 | + * modificá-lo dentro dos termos da GNU LGPL versão 3 como publicada pela Fundação | |
| 25 | + * do Software Livre (FSF). | |
| 26 | + * | |
| 27 | + * Este programa é distribuído na esperança que possa ser útil, mas SEM NENHUMA | |
| 28 | + * GARANTIA; sem uma garantia implícita de ADEQUAÇÃO a qualquer MERCADO ou | |
| 29 | + * APLICAÇÃO EM PARTICULAR. Veja a Licença Pública Geral GNU/LGPL em português | |
| 30 | + * para maiores detalhes. | |
| 31 | + * | |
| 32 | + * Você deve ter recebido uma cópia da GNU LGPL versão 3, sob o título | |
| 33 | + * "LICENCA.txt", junto com esse programa. Se não, acesse <http://www.gnu.org/licenses/> | |
| 34 | + * ou escreva para a Fundação do Software Livre (FSF) Inc., | |
| 35 | + * 51 Franklin St, Fifth Floor, Boston, MA 02111-1301, USA. | |
| 36 | + */ | |
| 37 | +package test; | |
| 38 | + | |
| 39 | +import java.io.File; | |
| 40 | +import java.util.Locale; | |
| 41 | + | |
| 42 | +import javax.enterprise.inject.Default; | |
| 43 | +import javax.enterprise.inject.Produces; | |
| 44 | + | |
| 45 | +import org.jboss.shrinkwrap.api.ShrinkWrap; | |
| 46 | +import org.jboss.shrinkwrap.api.asset.FileAsset; | |
| 47 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | |
| 48 | +import org.jboss.shrinkwrap.resolver.api.maven.Maven; | |
| 49 | +import org.junit.Ignore; | |
| 50 | + | |
| 51 | +import br.gov.frameworkdemoiselle.internal.configuration.EntityManagerConfig; | |
| 52 | +import br.gov.frameworkdemoiselle.internal.producer.EntityManagerFactoryProducer; | |
| 53 | +import br.gov.frameworkdemoiselle.internal.producer.EntityManagerProducer; | |
| 54 | +import br.gov.frameworkdemoiselle.internal.proxy.EntityManagerProxy; | |
| 55 | +import br.gov.frameworkdemoiselle.internal.proxy.QueryProxy; | |
| 56 | +import br.gov.frameworkdemoiselle.internal.proxy.TypedQueryProxy; | |
| 57 | +import br.gov.frameworkdemoiselle.template.JPACrud; | |
| 58 | +import br.gov.frameworkdemoiselle.transaction.JPATransaction; | |
| 59 | + | |
| 60 | +@Ignore | |
| 61 | +public final class Tests { | |
| 62 | + | |
| 63 | + private Tests() { | |
| 64 | + } | |
| 65 | + | |
| 66 | + public static WebArchive createDeployment(final Class<?> baseClass) { | |
| 67 | + return createDeployment().addPackages(true, baseClass.getPackage()); | |
| 68 | + } | |
| 69 | + | |
| 70 | + public static WebArchive createDeployment() { | |
| 71 | + File[] libs = Maven.resolver().offline().loadPomFromFile("pom.xml", "arquillian-test") | |
| 72 | + .importCompileAndRuntimeDependencies().resolve().withTransitivity().asFile(); | |
| 73 | + | |
| 74 | + return ShrinkWrap | |
| 75 | + .create(WebArchive.class) | |
| 76 | + .addClass(Tests.class) | |
| 77 | + .addClass(EntityManagerConfig.class) | |
| 78 | + .addClass(EntityManagerFactoryProducer.class) | |
| 79 | + .addClass(EntityManagerProducer.class) | |
| 80 | + .addClass(EntityManagerProxy.class) | |
| 81 | + .addClass(QueryProxy.class) | |
| 82 | + .addClass(TypedQueryProxy.class) | |
| 83 | + .addClass(JPACrud.class) | |
| 84 | + .addClass(JPATransaction.class) | |
| 85 | + .addAsResource(createFileAsset("src/main/resources/demoiselle-jpa-bundle.properties"), | |
| 86 | + "demoiselle-jpa-bundle.properties") | |
| 87 | + .addAsResource(createFileAsset("src/test/resources/logging.properties"), "logging.properties") | |
| 88 | + .addAsLibraries(libs) | |
| 89 | + .addAsWebInfResource(createFileAsset("src/test/resources/test/beans.xml"), "beans.xml") | |
| 90 | + .addAsLibraries(libs); | |
| 91 | + } | |
| 92 | + | |
| 93 | + public static FileAsset createFileAsset(final String pathname) { | |
| 94 | + return new FileAsset(new File(pathname)); | |
| 95 | + } | |
| 96 | + | |
| 97 | + @Default | |
| 98 | + @Produces | |
| 99 | + public Locale create() { | |
| 100 | + return Locale.getDefault(); | |
| 101 | + } | |
| 102 | +} | ... | ... |
impl/extension/jpa/src/test/java/transaction/manual/JPATransactionTest.java
0 → 100644
| ... | ... | @@ -0,0 +1,127 @@ |
| 1 | +package transaction.manual; | |
| 2 | + | |
| 3 | +import static junit.framework.Assert.assertEquals; | |
| 4 | +import static junit.framework.Assert.assertFalse; | |
| 5 | +import static junit.framework.Assert.assertNull; | |
| 6 | +import static junit.framework.Assert.assertTrue; | |
| 7 | + | |
| 8 | +import javax.inject.Inject; | |
| 9 | +import javax.persistence.EntityManager; | |
| 10 | +import javax.persistence.TransactionRequiredException; | |
| 11 | + | |
| 12 | +import org.jboss.arquillian.container.test.api.Deployment; | |
| 13 | +import org.jboss.arquillian.junit.Arquillian; | |
| 14 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | |
| 15 | +import org.junit.Test; | |
| 16 | +import org.junit.runner.RunWith; | |
| 17 | + | |
| 18 | +import test.Tests; | |
| 19 | +import br.gov.frameworkdemoiselle.annotation.Name; | |
| 20 | +import br.gov.frameworkdemoiselle.transaction.JPATransaction; | |
| 21 | +import br.gov.frameworkdemoiselle.transaction.Transaction; | |
| 22 | +import br.gov.frameworkdemoiselle.transaction.TransactionContext; | |
| 23 | + | |
| 24 | +@RunWith(Arquillian.class) | |
| 25 | +public class JPATransactionTest { | |
| 26 | + | |
| 27 | + private static final String PATH = "src/test/resources/transaction/manual"; | |
| 28 | + | |
| 29 | + @Inject | |
| 30 | + private TransactionContext transactionContext; | |
| 31 | + | |
| 32 | + @Inject | |
| 33 | + @Name("pu1") | |
| 34 | + private EntityManager em1; | |
| 35 | + | |
| 36 | + @Inject | |
| 37 | + @Name("pu2") | |
| 38 | + private EntityManager em2; | |
| 39 | + | |
| 40 | + @Deployment(testable = true) | |
| 41 | + public static WebArchive createDeployment() { | |
| 42 | + WebArchive deployment = Tests.createDeployment(JPATransactionTest.class); | |
| 43 | + deployment.addAsResource(Tests.createFileAsset(PATH + "/persistence.xml"), "META-INF/persistence.xml"); | |
| 44 | + | |
| 45 | + return deployment; | |
| 46 | + } | |
| 47 | + | |
| 48 | + @Test | |
| 49 | + public void checkJPATransactionType() { | |
| 50 | + assertEquals(JPATransaction.class, transactionContext.getCurrentTransaction().getClass()); | |
| 51 | + } | |
| 52 | + | |
| 53 | + @Test | |
| 54 | + public void commitWithSuccess() { | |
| 55 | + Transaction transaction = transactionContext.getCurrentTransaction(); | |
| 56 | + | |
| 57 | + MyEntity1 entity1 = new MyEntity1(); | |
| 58 | + entity1.setId(createId("id-1")); | |
| 59 | + entity1.setDescription("desc-1"); | |
| 60 | + | |
| 61 | + MyEntity2 entity2 = new MyEntity2(); | |
| 62 | + entity2.setId(createId("id-2")); | |
| 63 | + entity2.setDescription("desc-2"); | |
| 64 | + | |
| 65 | + assertFalse(transaction.isActive()); | |
| 66 | + transaction.begin(); | |
| 67 | + assertTrue(transaction.isActive()); | |
| 68 | + | |
| 69 | + em1.persist(entity1); | |
| 70 | + em2.persist(entity2); | |
| 71 | + transaction.commit(); | |
| 72 | + em1.clear(); | |
| 73 | + em2.clear(); | |
| 74 | + | |
| 75 | + MyEntity1 persisted1 = em1.find(MyEntity1.class, createId("id-1")); | |
| 76 | + MyEntity2 persisted2 = em2.find(MyEntity2.class, createId("id-2")); | |
| 77 | + | |
| 78 | + assertEquals("desc-1", persisted1.getDescription()); | |
| 79 | + assertEquals("desc-2", persisted2.getDescription()); | |
| 80 | + } | |
| 81 | + | |
| 82 | + @Test(expected = TransactionRequiredException.class) | |
| 83 | + public void checkNoTransactionAutomaticallyLoaded() { | |
| 84 | + MyEntity1 entity = new MyEntity1(); | |
| 85 | + entity.setId(createId("id-2")); | |
| 86 | + | |
| 87 | + em1.persist(entity); | |
| 88 | + em1.flush(); | |
| 89 | + } | |
| 90 | + | |
| 91 | + @Test | |
| 92 | + public void rollbackWithSuccess() { | |
| 93 | + Transaction transaction = transactionContext.getCurrentTransaction(); | |
| 94 | + | |
| 95 | + MyEntity1 entity1 = new MyEntity1(); | |
| 96 | + entity1.setId(createId("id-3")); | |
| 97 | + | |
| 98 | + MyEntity2 entity2 = new MyEntity2(); | |
| 99 | + entity2.setId(createId("id-4")); | |
| 100 | + | |
| 101 | + assertFalse(transaction.isMarkedRollback()); | |
| 102 | + transaction.begin(); | |
| 103 | + assertTrue(transaction.isActive()); | |
| 104 | + | |
| 105 | + em1.persist(entity1); | |
| 106 | + em2.persist(entity2); | |
| 107 | + em1.flush(); | |
| 108 | + em2.flush(); | |
| 109 | + transaction.setRollbackOnly(); | |
| 110 | + | |
| 111 | + if (transaction.isMarkedRollback()) { | |
| 112 | + transaction.rollback(); | |
| 113 | + } | |
| 114 | + | |
| 115 | + em1.clear(); | |
| 116 | + em2.clear(); | |
| 117 | + | |
| 118 | + MyEntity1 persisted1 = em1.find(MyEntity1.class, createId("id-3")); | |
| 119 | + MyEntity2 persisted2 = em2.find(MyEntity2.class, createId("id-4")); | |
| 120 | + assertNull(persisted1); | |
| 121 | + assertNull(persisted2); | |
| 122 | + } | |
| 123 | + | |
| 124 | + private String createId(String id) { | |
| 125 | + return this.getClass().getName() + "_" + id; | |
| 126 | + } | |
| 127 | +} | ... | ... |
impl/extension/jpa/src/test/java/transaction/manual/MyEntity1.java
0 → 100644
| ... | ... | @@ -0,0 +1,29 @@ |
| 1 | +package transaction.manual; | |
| 2 | + | |
| 3 | +import javax.persistence.Entity; | |
| 4 | +import javax.persistence.Id; | |
| 5 | + | |
| 6 | +@Entity | |
| 7 | +public class MyEntity1 { | |
| 8 | + | |
| 9 | + @Id | |
| 10 | + private String id; | |
| 11 | + | |
| 12 | + private String description; | |
| 13 | + | |
| 14 | + public String getId() { | |
| 15 | + return id; | |
| 16 | + } | |
| 17 | + | |
| 18 | + public void setId(String id) { | |
| 19 | + this.id = id; | |
| 20 | + } | |
| 21 | + | |
| 22 | + public String getDescription() { | |
| 23 | + return description; | |
| 24 | + } | |
| 25 | + | |
| 26 | + public void setDescription(String description) { | |
| 27 | + this.description = description; | |
| 28 | + } | |
| 29 | +} | ... | ... |