java barcode library | Appendix I: Interceptors: TV Channel Service Example in Java

Create Denso QR Bar Code in Java | Appendix I: Interceptors: TV Channel Service Example

708 | Appendix I: Interceptors: TV Channel Service Example
QR Code ISO/IEC18004 Generator In Java
Using Barcode maker for Java Control to generate, create QR-Code image in Java applications.
www.OnBarcode.com
Recognize Denso QR Bar Code In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
{
USS Code 39 Encoder In Java
Using Barcode printer for Java Control to generate, create Code-39 image in Java applications.
www.OnBarcode.com
Quick Response Code Encoder In Java
Using Barcode maker for Java Control to generate, create QR Code image in Java applications.
www.OnBarcode.com
// Set the access policy to block Channel2AccessPolicy.setChannel2Permitted(true);
Code 39 Full ASCII Generation In Java
Using Barcode maker for Java Control to generate, create Code-39 image in Java applications.
www.OnBarcode.com
Linear Creation In Java
Using Barcode encoder for Java Control to generate, create Linear Barcode image in Java applications.
www.OnBarcode.com
// Invoke final InvocationContext invocation = new MockInvocationContext(METHOD_GET_ CHANNEL, new Object[] {2}); try { interceptor.checkAccessibility(invocation); } catch (final Channel2ClosedException e) { TestCase.fail("Should not have been blocked with: " + e); } } /** * Ensures requests for channel 1 are not blocked channel 2's access is closed */ @Test public void requestsToChannel1NeverBlocked() throws Exception { // Set the access policy to block Channel2AccessPolicy.setChannel2Permitted(false); // Invoke final InvocationContext invocation = new MockInvocationContext(METHOD_GET_ CHANNEL, new Object[] {1}); interceptor.checkAccessibility(invocation); } }
EAN128 Generation In Java
Using Barcode generator for Java Control to generate, create UCC-128 image in Java applications.
www.OnBarcode.com
Encoding USD-4 In Java
Using Barcode creator for Java Control to generate, create Monarch image in Java applications.
www.OnBarcode.com
InterceptorIntegrationTest.java
Print QR Code 2d Barcode In VS .NET
Using Barcode generation for Visual Studio .NET Control to generate, create Denso QR Bar Code image in .NET applications.
www.OnBarcode.com
Quick Response Code Drawer In .NET
Using Barcode printer for ASP.NET Control to generate, create Quick Response Code image in ASP.NET applications.
www.OnBarcode.com
package org.jboss.ejb3.examples.ch18.tuner; import import import import java.io.IOException; java.io.InputStream; java.lang.reflect.UndeclaredThrowableException; java.util.logging.Logger;
EAN / UCC - 13 Generator In None
Using Barcode creation for Word Control to generate, create EAN / UCC - 14 image in Office Word applications.
www.OnBarcode.com
UPC-A Supplement 2 Recognizer In Visual Basic .NET
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in VS .NET applications.
www.OnBarcode.com
import javax.ejb.EJB; import javax.interceptor.Interceptors; import javax.naming.NamingException; import junit.framework.TestCase; import import import import org.jboss.arquillian.api.Deployment; org.jboss.arquillian.junit.Arquillian; org.jboss.ejb3.examples.ch18.tuner.CachingAuditor; org.jboss.ejb3.examples.ch18.tuner.Channel2AccessPolicy;
Printing EAN-13 In None
Using Barcode printer for Online Control to generate, create EAN-13 Supplement 5 image in Online applications.
www.OnBarcode.com
Barcode Creator In VS .NET
Using Barcode maker for Reporting Service Control to generate, create Barcode image in Reporting Service applications.
www.OnBarcode.com
import import import import import import import import import
Encode UPC Code In None
Using Barcode generator for Software Control to generate, create UPC Code image in Software applications.
www.OnBarcode.com
Generate QR In None
Using Barcode generator for Software Control to generate, create Quick Response Code image in Software applications.
www.OnBarcode.com
org.jboss.ejb3.examples.ch18.tuner.Channel2ClosedException; org.jboss.ejb3.examples.ch18.tuner.Channel2Restrictor; org.jboss.ejb3.examples.ch18.tuner.TunerBean; org.jboss.ejb3.examples.ch18.tuner.TunerLocalBusiness; org.jboss.shrinkwrap.api.ShrinkWrap; org.jboss.shrinkwrap.api.spec.JavaArchive; org.junit.After; org.junit.Test; org.junit.runner.RunWith;
Scanning Barcode In Java
Using Barcode recognizer for Java Control to read, scan read, scan image in Java applications.
www.OnBarcode.com
Printing QR-Code In None
Using Barcode drawer for Word Control to generate, create QR Code ISO/IEC18004 image in Word applications.
www.OnBarcode.com
/** * Integration test ensuring that an EJB with {@link Interceptors} * declared are intercepted when invoked * * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a> * @version $Revision: $ */ @RunWith(Arquillian.class) public class InterceptionIntegrationTest { //--------------------------------------------------------------------------|| // Class Members -----------------------------------------------------------|| //--------------------------------------------------------------------------|| /** * Logger */ private static final Logger log = Logger.getLogger(InterceptionIntegrationTest .class.getName()); //--------------------------------------------------------------------------|| // Instance Members --------------------------------------------------------|| //--------------------------------------------------------------------------|| /** * Archive representing the deployment */ @Deployment public static JavaArchive createDeployment() { final JavaArchive deployment = ShrinkWrap.create("echo.jar", JavaArchive. class).addClasses( TunerLocalBusiness.class, TunerBean.class, CachingAuditor.class, Channel2Restrictor.class); log.info(deployment.toString(true)); return deployment; } /** * The bean to invoke upon */ @EJB private TunerLocalBusiness bean;
Barcode Recognizer In .NET
Using Barcode Control SDK for ASP.NET Control to generate, create, read, scan barcode image in ASP.NET applications.
www.OnBarcode.com
Painting UPC - 13 In Objective-C
Using Barcode creation for iPad Control to generate, create EAN-13 Supplement 5 image in iPad applications.
www.OnBarcode.com
710 | Appendix I: Interceptors: TV Channel Service Example
//--------------------------------------------------------------------------|| // Lifecycle ---------------------------------------------------------------|| //--------------------------------------------------------------------------|| /** * Cleanup */ @After public void clearInvocationsAfterTest() { // Clean up CachingAuditor.clearInTesting(); } //--------------------------------------------------------------------------|| // Tests -------------------------------------------------------------------|| //--------------------------------------------------------------------------|| /** * Ensures that invocation upon an EJB with {@link CachingAuditor} declared * results in the interception of targeted methods */ @Test public void testCachingInterception() throws NamingException, IOException { // Ensure no invocations intercepted yet TestCase.assertEquals("No invocations should have yet been intercepted", 0, CachingAuditor.getInvocations() .size()); // Invoke final int channel = 1; final InputStream content = bean.getChannel(channel); // Test the response is as expected TestCase.assertEquals("Did not obtain expected response", channel, content. read()); // Test the invocation was intercepted TestCase.assertEquals("The invocation should have been intercepted", 1, CachingAuditor.getInvocations().size()); } /** * Ensures that requests to obtain Channel 2 while restricted are blocked with {@link Channel2ClosedException} */ @Test(expected = Channel2ClosedException.class) public void testChannel2Restricted() throws Throwable { // Set the policy to block channel 2 Channel2AccessPolicy.setChannel2Permitted(false); // Invoke try
{
bean.getChannel(2); } // Expected catch (final UndeclaredThrowableException ute) { throw ute.getCause(); } // Fail if we reach here TestCase.fail("Request should have been blocked");
}
/** * Ensures that requests to obtain Channel 2 while open succeed */ @Test public void testChannel2Allowed() throws NamingException, IOException { // Set the policy to block channel 2 Channel2AccessPolicy.setChannel2Permitted(true); // Invoke final int channel = 2; final InputStream stream = bean.getChannel(channel); // Test TestCase.assertEquals("Unexpected content obtained from channel " + channel , channel, stream.read()); } }
MockInvocationContext.java
package org.jboss.ejb3.examples.ch18.tuner; import java.lang.reflect.Method; import java.util.Map; import javax.interceptor.InvocationContext; /** * {@link InvocationContext} implementation which throws {@link Unsupported OperationException} * for all required methods except {@link InvocationContext#proceed()}, which will always return null, * {@link InvocationContext#getMethod()}, and {@link InvocationContext#get Parameters()}. * * @author <a href="mailto:andrew.rubinger@jboss.org">ALR</a> * @version $Revision: $ */ class MockInvocationContext implements InvocationContext {
712 | Appendix I: Interceptors: TV Channel Service Example
//--------------------------------------------------------------------------|| // Class Members -----------------------------------------------------------|| //--------------------------------------------------------------------------|| /** * Message used to denote that the operation is not supported */ private static final String MSG_UNSUPPORTED = "Not supported in mock implement ation"; //--------------------------------------------------------------------------|| // Instance Members --------------------------------------------------------|| //--------------------------------------------------------------------------|| /** * Method invoked */ private final Method method; /** * Parameters in the request */ private final Object[] params; //--------------------------------------------------------------------------|| // Constructor -------------------------------------------------------------|| //--------------------------------------------------------------------------|| /** * Constructs a new instance with the specified required arguments * @param method * @param params */ MockInvocationContext(final Method method, final Object[] params) { assert method assert params this.method = this.params = != null : "method must be specified"; != null : "params must be specified"; method; params;
}
//--------------------------------------------------------------------------|| // Required Implementations ------------------------------------------------|| //--------------------------------------------------------------------------|| @Override public Map<String, Object> getContextData() { throw new UnsupportedOperationException(MSG_UNSUPPORTED); }
@Override public Method getMethod() { return method; } @Override public Object[] getParameters() { return params; } @Override public Object getTarget() { throw new UnsupportedOperationException(MSG_UNSUPPORTED); } @Override public Object proceed() throws Exception { return null; } @Override public void setParameters(final Object[] arg0) { throw new UnsupportedOperationException(MSG_UNSUPPORTED); }
}
Copyright © OnBarcode.com . All rights reserved.