Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions cdi/interceptors/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,5 @@
<relativePath>../pom.xml</relativePath>
</parent>

<groupId>org.javaee7.cdi</groupId>
<artifactId>interceptors</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@

/**
* @author Arun Gupta
* @author Radim Hanus
*/
public interface Greeting {
public String greet(String name);
public String getGreet();
public void setGreet(String name);
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,23 @@
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
import java.lang.reflect.Field;

/**
* @author Arun Gupta
* @author Radim Hanus
*/
@Interceptor
@MyInterceptorBinding
public class MyInterceptor {

@AroundInvoke
public Object log(InvocationContext context) throws Exception {
String name = context.getMethod().getName();
String params = "";
for (Object param : context.getParameters()) {
params += param + " ";
}
System.out.println("MyInterceptor: " + name + " " + params);
return context.proceed();
}
@AroundInvoke
public Object log(InvocationContext context) throws Exception {
Object[] parameters = context.getParameters();
if (parameters.length > 0 && parameters[0] instanceof String) {
String param = (String) parameters[0];
parameters[0] = "Hi " + param + " !";
context.setParameters(parameters);
}
return context.proceed();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,17 @@

/**
* @author Arun Gupta
* @author Radim Hanus
*/
@MyInterceptorBinding
public class SimpleGreeting implements Greeting {
private String greet;

@Override
public String greet(String name) {
return "Hello " + name;
}

public String getGreet() {
return greet;
}

public void setGreet(String greet) {
this.greet = greet;
}
}

This file was deleted.

52 changes: 0 additions & 52 deletions cdi/interceptors/src/main/webapp/WEB-INF/beans.xml

This file was deleted.

55 changes: 0 additions & 55 deletions cdi/interceptors/src/main/webapp/index.jsp

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package org.javaee7.cdi.interceptors;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;

import javax.inject.Inject;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;

/**
* @author Radim Hanus
*/
@RunWith(Arquillian.class)
public class GreetingTest {
@Deployment
public static Archive<?> deploy() {
return ShrinkWrap.create(JavaArchive.class)
.addClasses(Greeting.class, SimpleGreeting.class, MyInterceptorBinding.class, MyInterceptor.class)
.addAsManifestResource("beans.xml");
}

@Inject
Greeting bean;

@Test
public void test() throws Exception {
assertThat(bean, is(notNullValue()));
assertThat(bean, instanceOf(SimpleGreeting.class));

bean.setGreet("Arun");
assertEquals(bean.getGreet(), "Hi Arun !");
}
}
16 changes: 16 additions & 0 deletions cdi/interceptors/src/test/resources/arquillian.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>

<arquillian xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://jboss.org/schema/arquillian"
xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd">

<defaultProtocol type="Servlet 3.0"/>

<container qualifier="test" default="true">
<configuration>
<property name="jbossHome">${serverRoot:target/wildfly-8.0.0.CR1}</property>
<property name="serverConfig">${serverProfile:standalone-full.xml}</property>
</configuration>
</container>

</arquillian>
12 changes: 12 additions & 0 deletions cdi/interceptors/src/test/resources/beans.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd"
bean-discovery-mode="all">

<interceptors>
<class>org.javaee7.cdi.interceptors.MyInterceptor</class>
</interceptors>

</beans>