Aggiunto l'esempio del capitolo sul CDI
This commit is contained in:
90
.gitignore
vendored
Normal file
90
.gitignore
vendored
Normal file
@@ -0,0 +1,90 @@
|
|||||||
|
# Compiled class file
|
||||||
|
*.class
|
||||||
|
|
||||||
|
# Log file
|
||||||
|
*.log
|
||||||
|
|
||||||
|
# BlueJ files
|
||||||
|
*.ctxt
|
||||||
|
|
||||||
|
# Mobile Tools for Java (J2ME)
|
||||||
|
.mtj.tmp/
|
||||||
|
|
||||||
|
# Package Files #
|
||||||
|
*.jar
|
||||||
|
*.war
|
||||||
|
*.nar
|
||||||
|
*.ear
|
||||||
|
*.zip
|
||||||
|
*.tar.gz
|
||||||
|
*.rar
|
||||||
|
|
||||||
|
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
|
||||||
|
hs_err_pid*
|
||||||
|
|
||||||
|
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
|
||||||
|
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
||||||
|
|
||||||
|
# User-specific stuff
|
||||||
|
.idea/**/workspace.xml
|
||||||
|
.idea/**/tasks.xml
|
||||||
|
.idea/**/usage.statistics.xml
|
||||||
|
.idea/**/dictionaries
|
||||||
|
.idea/**/shelf
|
||||||
|
|
||||||
|
# Generated files
|
||||||
|
.idea/**/contentModel.xml
|
||||||
|
|
||||||
|
# Sensitive or high-churn files
|
||||||
|
.idea/**/dataSources/
|
||||||
|
.idea/**/dataSources.ids
|
||||||
|
.idea/**/dataSources.local.xml
|
||||||
|
.idea/**/sqlDataSources.xml
|
||||||
|
.idea/**/dynamic.xml
|
||||||
|
.idea/**/uiDesigner.xml
|
||||||
|
.idea/**/dbnavigator.xml
|
||||||
|
|
||||||
|
# Gradle
|
||||||
|
.idea/**/gradle.xml
|
||||||
|
.idea/**/libraries
|
||||||
|
|
||||||
|
# Gradle and Maven with auto-import
|
||||||
|
# When using Gradle or Maven with auto-import, you should exclude module files,
|
||||||
|
# since they will be recreated, and may cause churn. Uncomment if using
|
||||||
|
# auto-import.
|
||||||
|
# .idea/modules.xml
|
||||||
|
# .idea/*.iml
|
||||||
|
# .idea/modules
|
||||||
|
|
||||||
|
# CMake
|
||||||
|
cmake-build-*/
|
||||||
|
|
||||||
|
# Mongo Explorer plugin
|
||||||
|
.idea/**/mongoSettings.xml
|
||||||
|
|
||||||
|
# File-based project format
|
||||||
|
*.iws
|
||||||
|
|
||||||
|
# IntelliJ
|
||||||
|
out/
|
||||||
|
|
||||||
|
# mpeltonen/sbt-idea plugin
|
||||||
|
.idea_modules/
|
||||||
|
|
||||||
|
# JIRA plugin
|
||||||
|
atlassian-ide-plugin.xml
|
||||||
|
|
||||||
|
# Cursive Clojure plugin
|
||||||
|
.idea/replstate.xml
|
||||||
|
|
||||||
|
# Crashlytics plugin (for Android Studio and IntelliJ)
|
||||||
|
com_crashlytics_export_strings.xml
|
||||||
|
crashlytics.properties
|
||||||
|
crashlytics-build.properties
|
||||||
|
fabric.properties
|
||||||
|
|
||||||
|
# Editor-based Rest Client
|
||||||
|
.idea/httpRequests
|
||||||
|
|
||||||
|
# Android studio 3.1+ serialized cache file
|
||||||
|
.idea/caches/build_file_checksums.ser
|
||||||
33
cdidemo/cdidemo.iml
Normal file
33
cdidemo/cdidemo.iml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
|
||||||
|
<output url="file://$MODULE_DIR$/target/classes" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="jdk" jdkName="1.8" jdkType="JavaSDK" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
<orderEntry type="library" name="Maven: org.jboss.weld.se:weld-se-core:2.0.0.Final" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.jboss.weld:weld-spi:2.0.Final" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: javax.inject:javax.inject:1" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.jboss.weld:weld-api:2.0.Final" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.jboss.weld:weld-core:2.0.0.Final" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.jboss.classfilewriter:jboss-classfilewriter:1.0.4.Final" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: com.google.guava:guava:13.0.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.jboss.spec.javax.interceptor:jboss-interceptors-api_1.2_spec:1.0.0.Alpha3" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.slf4j:slf4j-ext:1.7.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: ch.qos.cal10n:cal10n-api:0.7.7" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.slf4j:slf4j-api:1.7.2" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: javax.enterprise:cdi-api:1.1" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: javax.annotation:jsr250-api:1.0" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: javax.el:javax.el-api:3.0-b08" level="project" />
|
||||||
|
<orderEntry type="library" name="Maven: org.jboss.spec.javax.annotation:jboss-annotations-api_1.2_spec:1.0.0.Alpha1" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
|
||||||
|
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
75
cdidemo/pom.xml
Normal file
75
cdidemo/pom.xml
Normal file
@@ -0,0 +1,75 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<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">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>cdidemo</artifactId>
|
||||||
|
<name>cdidemo</name>
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<artifactId>jeedemo</artifactId>
|
||||||
|
<groupId>it.plague.jeedemo</groupId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<exec.mainClass>it.plague.jeedemo.CdiMain</exec.mainClass>
|
||||||
|
<maven.compiler.source>1.7</maven.compiler.source>
|
||||||
|
<maven.compiler.target>1.7</maven.compiler.target>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jboss.weld.se</groupId>
|
||||||
|
<artifactId>weld-se-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>2.5.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.7</source>
|
||||||
|
<target>1.7</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-failsafe-plugin</artifactId>
|
||||||
|
<version>2.12.4</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>integration-test</id>
|
||||||
|
<goals>
|
||||||
|
<goal>integration-test</goal>
|
||||||
|
<goal>verify</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.codehaus.mojo</groupId>
|
||||||
|
<artifactId>exec-maven-plugin</artifactId>
|
||||||
|
<version>1.2.1</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>java</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<mainClass>it.plague.jeedemo.CdiMain</mainClass>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
18
cdidemo/src/main/java/it/plague/jeedemo/CdiMain.java
Normal file
18
cdidemo/src/main/java/it/plague/jeedemo/CdiMain.java
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
package it.plague.jeedemo;
|
||||||
|
|
||||||
|
import it.plague.jeedemo.beans.Book;
|
||||||
|
import it.plague.jeedemo.services.BookService;
|
||||||
|
import org.jboss.weld.environment.se.Weld;
|
||||||
|
import org.jboss.weld.environment.se.WeldContainer;
|
||||||
|
|
||||||
|
public class CdiMain {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
Weld weld = new Weld();
|
||||||
|
WeldContainer container = weld.initialize();
|
||||||
|
BookService bookService = container.instance().select(BookService.class).get();
|
||||||
|
Book book = bookService.createBook("H2G2", 12.5f, "Geeky scifi Book");
|
||||||
|
System.out.println(book);
|
||||||
|
weld.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package it.plague.jeedemo.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
import javax.inject.Qualifier;
|
||||||
|
|
||||||
|
@Qualifier
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.FIELD, ElementType.TYPE, ElementType.METHOD})
|
||||||
|
public @interface EightDigits {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package it.plague.jeedemo.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
import javax.interceptor.InterceptorBinding;
|
||||||
|
|
||||||
|
@InterceptorBinding
|
||||||
|
@Target({ElementType.METHOD, ElementType.TYPE})
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
public @interface Loggable {
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package it.plague.jeedemo.annotations;
|
||||||
|
|
||||||
|
import java.lang.annotation.ElementType;
|
||||||
|
import java.lang.annotation.Retention;
|
||||||
|
import java.lang.annotation.RetentionPolicy;
|
||||||
|
import java.lang.annotation.Target;
|
||||||
|
import javax.inject.Qualifier;
|
||||||
|
|
||||||
|
@Qualifier
|
||||||
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
|
@Target({ElementType.FIELD, ElementType.TYPE, ElementType.METHOD})
|
||||||
|
public @interface ThirteenDigits {
|
||||||
|
|
||||||
|
}
|
||||||
58
cdidemo/src/main/java/it/plague/jeedemo/beans/Book.java
Normal file
58
cdidemo/src/main/java/it/plague/jeedemo/beans/Book.java
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
package it.plague.jeedemo.beans;
|
||||||
|
|
||||||
|
public class Book {
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
private Float price;
|
||||||
|
private String description;
|
||||||
|
private String number;
|
||||||
|
|
||||||
|
public Book(String title, Float price, String description) {
|
||||||
|
this.title = title;
|
||||||
|
this.price = price;
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Float getPrice() {
|
||||||
|
return price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPrice(Float price) {
|
||||||
|
this.price = price;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNumber() {
|
||||||
|
return number;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNumber(String number) {
|
||||||
|
this.number = number;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "Book{" +
|
||||||
|
"title='" + title + '\'' +
|
||||||
|
", price=" + price +
|
||||||
|
", description='" + description + '\'' +
|
||||||
|
", number='" + number + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package it.plague.jeedemo.beans;
|
||||||
|
|
||||||
|
import it.plague.jeedemo.annotations.Loggable;
|
||||||
|
import it.plague.jeedemo.annotations.ThirteenDigits;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
@ThirteenDigits
|
||||||
|
public class IsbnGenerator implements NumberGenerator {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Logger logger;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Loggable
|
||||||
|
public String generateNumber() {
|
||||||
|
String isbn = " 13-84356- " + Math.abs(new Random().nextInt());
|
||||||
|
logger.info("Generated ISBN: " + isbn);
|
||||||
|
return isbn;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,22 @@
|
|||||||
|
package it.plague.jeedemo.beans;
|
||||||
|
|
||||||
|
import it.plague.jeedemo.annotations.EightDigits;
|
||||||
|
import it.plague.jeedemo.annotations.Loggable;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
@EightDigits
|
||||||
|
public class IssnGenerator implements NumberGenerator {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Logger logger;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Loggable
|
||||||
|
public String generateNumber() {
|
||||||
|
String issn = " 8- " + Math.abs(new Random().nextInt());
|
||||||
|
logger.info("Generated ISSN: " + issn);
|
||||||
|
return issn;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package it.plague.jeedemo.beans;
|
||||||
|
|
||||||
|
public interface NumberGenerator {
|
||||||
|
|
||||||
|
String generateNumber();
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package it.plague.jeedemo.interceptors;
|
||||||
|
|
||||||
|
import it.plague.jeedemo.annotations.Loggable;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.interceptor.AroundInvoke;
|
||||||
|
import javax.interceptor.Interceptor;
|
||||||
|
import javax.interceptor.InvocationContext;
|
||||||
|
|
||||||
|
@Interceptor
|
||||||
|
@Loggable
|
||||||
|
public class LoggingInterceptor {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Logger logger;
|
||||||
|
|
||||||
|
@AroundInvoke
|
||||||
|
public Object logMethod(InvocationContext ic) throws Exception {
|
||||||
|
logger.entering(ic.getTarget().getClass().getName(), ic.getMethod().getName());
|
||||||
|
try {
|
||||||
|
return ic.proceed();
|
||||||
|
} finally {
|
||||||
|
logger.exiting(ic.getTarget().getClass().getName(), ic.getMethod().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package it.plague.jeedemo.producers;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import javax.enterprise.inject.Produces;
|
||||||
|
import javax.enterprise.inject.spi.InjectionPoint;
|
||||||
|
|
||||||
|
public class LoggerProducer {
|
||||||
|
|
||||||
|
@Produces
|
||||||
|
public Logger produceLogger(InjectionPoint injectionPoint) {
|
||||||
|
return Logger.getLogger(injectionPoint.getMember().getDeclaringClass().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,21 @@
|
|||||||
|
package it.plague.jeedemo.services;
|
||||||
|
|
||||||
|
import it.plague.jeedemo.annotations.Loggable;
|
||||||
|
import it.plague.jeedemo.annotations.ThirteenDigits;
|
||||||
|
import it.plague.jeedemo.beans.Book;
|
||||||
|
import it.plague.jeedemo.beans.NumberGenerator;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
@Loggable
|
||||||
|
public class BookService {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
@ThirteenDigits
|
||||||
|
private NumberGenerator numberGenerator;
|
||||||
|
|
||||||
|
public Book createBook(String title, Float price, String description) {
|
||||||
|
Book book = new Book(title, price, description);
|
||||||
|
book.setNumber(numberGenerator.generateNumber());
|
||||||
|
return book;
|
||||||
|
}
|
||||||
|
}
|
||||||
6
cdidemo/src/main/resources/META-INF/beans.xml
Normal file
6
cdidemo/src/main/resources/META-INF/beans.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/
|
||||||
|
XMLSchema-instance" xsi:schemeLocation="http://java.sun.com/xml/ns/javaee http://
|
||||||
|
java.sun.com/xml/ns/javaee/beans_1_0.xsd" version="1.1" bean-discovery-mode="all">
|
||||||
|
<!-- This is empty on purpose. -->
|
||||||
|
</beans>
|
||||||
22
cdidemo/src/test/java/it/plague/jeedemo/BookServiceIT.java
Normal file
22
cdidemo/src/test/java/it/plague/jeedemo/BookServiceIT.java
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
package it.plague.jeedemo;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
import it.plague.jeedemo.beans.Book;
|
||||||
|
import it.plague.jeedemo.services.BookService;
|
||||||
|
import org.jboss.weld.environment.se.Weld;
|
||||||
|
import org.jboss.weld.environment.se.WeldContainer;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class BookServiceIT {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldCheckNumberIsMOCK() {
|
||||||
|
Weld weld = new Weld();
|
||||||
|
WeldContainer container = weld.initialize();
|
||||||
|
BookService bookService = container.instance().select(BookService.class).get();
|
||||||
|
Book book = bookService.createBook("H2G2", 12.5f, "Geeky scifi Book");
|
||||||
|
assertTrue(book.getNumber().startsWith("MOCK"));
|
||||||
|
weld.shutdown();
|
||||||
|
}
|
||||||
|
}
|
||||||
25
cdidemo/src/test/java/it/plague/jeedemo/MockGenerator.java
Normal file
25
cdidemo/src/test/java/it/plague/jeedemo/MockGenerator.java
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
package it.plague.jeedemo;
|
||||||
|
|
||||||
|
import it.plague.jeedemo.annotations.Loggable;
|
||||||
|
import it.plague.jeedemo.annotations.ThirteenDigits;
|
||||||
|
import it.plague.jeedemo.beans.NumberGenerator;
|
||||||
|
import java.util.Random;
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import javax.enterprise.inject.Alternative;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
|
||||||
|
@Alternative
|
||||||
|
@ThirteenDigits
|
||||||
|
public class MockGenerator implements NumberGenerator {
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
private Logger logger;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Loggable
|
||||||
|
public String generateNumber() {
|
||||||
|
String mock = "MOCK- " + Math.abs(new Random().nextInt());
|
||||||
|
logger.info("Generated Mock: " + mock);
|
||||||
|
return mock;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
cdidemo/src/test/resources/META-INF/beans.xml
Normal file
11
cdidemo/src/test/resources/META-INF/beans.xml
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<beans xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/
|
||||||
|
XMLSchema-instance" xsi:schemeLocation="http://java.sun.com/xml/ns/javaee http://
|
||||||
|
java.sun.com/xml/ns/javaee/beans_1_0.xsd" version="1.1" bean-discovery-mode="all">
|
||||||
|
<alternatives>
|
||||||
|
<class>it.plague.jeedemo.MockGenerator</class>
|
||||||
|
</alternatives>
|
||||||
|
<interceptors>
|
||||||
|
<class>it.plague.jeedemo.interceptors.LoggingInterceptor</class>
|
||||||
|
</interceptors>
|
||||||
|
</beans>
|
||||||
12
jeedemo.iml
Normal file
12
jeedemo.iml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
|
||||||
|
<output url="file://$MODULE_DIR$/target/classes" />
|
||||||
|
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
62
pom.xml
Normal file
62
pom.xml
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
<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">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>it.plague.jeedemo</groupId>
|
||||||
|
<artifactId>jeedemo</artifactId>
|
||||||
|
<version>1.0-SNAPSHOT</version>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>jeedemo</name>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>cdidemo</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.persistence</groupId>
|
||||||
|
<artifactId>org.eclipse.persistence.jpa</artifactId>
|
||||||
|
<version>2.5.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.hibernate</groupId>
|
||||||
|
<artifactId>hibernate-validator</artifactId>
|
||||||
|
<version>6.0.16.Final</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.glassfish</groupId>
|
||||||
|
<artifactId>javax.el</artifactId>
|
||||||
|
<version>3.0.1-b09</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.projectlombok</groupId>
|
||||||
|
<artifactId>lombok</artifactId>
|
||||||
|
<version>1.18.6</version>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.jboss.weld.se</groupId>
|
||||||
|
<artifactId>weld-se-core</artifactId>
|
||||||
|
<version>2.0.0.Final</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.derby</groupId>
|
||||||
|
<artifactId>derbyclient</artifactId>
|
||||||
|
<version>10.9.1.0</version>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.derby</groupId>
|
||||||
|
<artifactId>derby</artifactId>
|
||||||
|
<version>10.9.1.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>junit</groupId>
|
||||||
|
<artifactId>junit</artifactId>
|
||||||
|
<version>4.12</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
</dependencyManagement>
|
||||||
|
</project>
|
||||||
Reference in New Issue
Block a user