Created
August 12, 2010 16:22
-
-
Save pmuir/521231 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class CatFilter implements Filter | |
{ | |
@Inject | |
Sewer sewer; | |
public void init(FilterConfig filterConfig) throws ServletException | |
{ | |
isSewerNameOk(); | |
} | |
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException | |
{ | |
((HttpServletResponse) response).setStatus(isSewerNameOk() ? HttpServletResponse.SC_OK : HttpServletResponse.SC_INTERNAL_SERVER_ERROR); | |
} | |
public void destroy() | |
{ | |
isSewerNameOk(); | |
} | |
private boolean isSewerNameOk() throws NullPointerException | |
{ | |
return Sewer.NAME.equals(sewer.getName()); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RunWith(Arquillian.class) | |
@Run(AS_CLIENT) | |
public class FilterInjectionTest | |
{ | |
public static final Asset WEB_XML = new ByteArrayAsset(("<web-app><listener><listener-class>org.jboss.weld.environment.servlet.Listener</listener-class></listener> <filter><filter-name>Cat Filter</filter-name><filter-class>" + CatFilter.class.getName() + "</filter-class></filter><filter-mapping><filter-name>Cat Filter</filter-name><url-pattern>/cat</url-pattern></filter-mapping></web-app>").getBytes()); | |
@Deployment | |
public static WebArchive deployment() | |
{ | |
return DeploymentDescriptor.deployment(WEB_XML).addClasses(CatFilter.class, Sewer.class); | |
} | |
@Test | |
public void testFilterInjection() throws Exception | |
{ | |
HttpClient client = new HttpClient(); | |
HttpMethod method = new GetMethod(CONTEXT_PATH + "/cat"); | |
int sc = client.executeMethod(method); | |
assert sc == HttpServletResponse.SC_OK; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment