Search in sources :

Example 1 with TrapException

use of org.apache.tomcat.jdbc.pool.TrapException in project tomcat by apache.

the class TestJdbcInterceptorConfigParsing method testWhitespace.

@Test
public void testWhitespace() throws Exception {
    String interceptorConfig = "FirstInterceptor ; \n" + "SecondInterceptor (parm1  = value1 , parm2= value2 ) ; \n\n" + "\t org.cyb.ThirdInterceptor(parm1=value1);  \n" + "EmptyParmValInterceptor(parm1=  )";
    PoolProperties props = new PoolProperties();
    props.setJdbcInterceptors(interceptorConfig);
    InterceptorDefinition[] interceptorDefs = props.getJdbcInterceptorsAsArray();
    assertNotNull(interceptorDefs);
    // 5 items because parser automatically inserts TrapException interceptor to front of list
    assertEquals(interceptorDefs.length, 5);
    assertEquals(interceptorDefs[0].getClassName(), TrapException.class.getName());
    assertNotNull(interceptorDefs[1]);
    assertEquals(interceptorDefs[1].getClassName(), "FirstInterceptor");
    assertNotNull(interceptorDefs[2]);
    assertEquals(interceptorDefs[2].getClassName(), "SecondInterceptor");
    assertNotNull(interceptorDefs[3]);
    assertEquals(interceptorDefs[3].getClassName(), "org.cyb.ThirdInterceptor");
    Map<String, InterceptorProperty> secondProps = interceptorDefs[2].getProperties();
    assertNotNull(secondProps);
    assertEquals(secondProps.size(), 2);
    assertNotNull(secondProps.get("parm1"));
    assertEquals(secondProps.get("parm1").getValue(), "value1");
    assertNotNull(secondProps.get("parm2"));
    // Bug 54395
    assertEquals(secondProps.get("parm2").getValue(), "value2");
    Map<String, InterceptorProperty> thirdProps = interceptorDefs[3].getProperties();
    assertNotNull(thirdProps);
    assertEquals(thirdProps.size(), 1);
    assertNotNull(thirdProps.get("parm1"));
    assertEquals(thirdProps.get("parm1").getValue(), "value1");
    Map<String, InterceptorProperty> emptyParmValProps = interceptorDefs[4].getProperties();
    assertNotNull(emptyParmValProps);
    assertEquals(emptyParmValProps.size(), 1);
    assertNotNull(emptyParmValProps.get("parm1"));
    assertEquals(emptyParmValProps.get("parm1").getValue(), "");
}
Also used : InterceptorDefinition(org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorDefinition) InterceptorProperty(org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorProperty) TrapException(org.apache.tomcat.jdbc.pool.TrapException) PoolProperties(org.apache.tomcat.jdbc.pool.PoolProperties) Test(org.junit.Test)

Example 2 with TrapException

use of org.apache.tomcat.jdbc.pool.TrapException in project tomcat by apache.

the class TestJdbcInterceptorConfigParsing method testBasic.

@Test
public void testBasic() throws Exception {
    String interceptorConfig = "FirstInterceptor;SecondInterceptor(parm1=value1,parm2=value2)";
    PoolProperties props = new PoolProperties();
    props.setJdbcInterceptors(interceptorConfig);
    InterceptorDefinition[] interceptorDefs = props.getJdbcInterceptorsAsArray();
    assertNotNull(interceptorDefs);
    // 3 items because parser automatically inserts TrapException interceptor to front of list
    assertEquals(interceptorDefs.length, 3);
    assertEquals(interceptorDefs[0].getClassName(), TrapException.class.getName());
    assertNotNull(interceptorDefs[1]);
    assertEquals(interceptorDefs[1].getClassName(), "FirstInterceptor");
    assertNotNull(interceptorDefs[2]);
    assertEquals(interceptorDefs[2].getClassName(), "SecondInterceptor");
    Map<String, InterceptorProperty> secondProps = interceptorDefs[2].getProperties();
    assertNotNull(secondProps);
    assertEquals(secondProps.size(), 2);
    assertNotNull(secondProps.get("parm1"));
    assertEquals(secondProps.get("parm1").getValue(), "value1");
    assertNotNull(secondProps.get("parm2"));
    assertEquals(secondProps.get("parm2").getValue(), "value2");
}
Also used : InterceptorDefinition(org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorDefinition) InterceptorProperty(org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorProperty) TrapException(org.apache.tomcat.jdbc.pool.TrapException) PoolProperties(org.apache.tomcat.jdbc.pool.PoolProperties) Test(org.junit.Test)

Aggregations

PoolProperties (org.apache.tomcat.jdbc.pool.PoolProperties)2 InterceptorDefinition (org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorDefinition)2 InterceptorProperty (org.apache.tomcat.jdbc.pool.PoolProperties.InterceptorProperty)2 TrapException (org.apache.tomcat.jdbc.pool.TrapException)2 Test (org.junit.Test)2