@BeforeClass public static void beforeClass() throws Exception { strategy.registerExpressionEvaluator("hostname", "tomcat1"); strategy.registerExpressionEvaluator("canonical_hostname", "tomcat1.www.private.mycompany.com"); strategy.registerExpressionEvaluator( "escaped_canonical_hostname", "tomcat1_www_private_mycompany_com"); strategy.registerExpressionEvaluator("hostaddress", "10.0.0.81"); strategy.registerExpressionEvaluator("escaped_hostaddress", "10_0_0_81"); }
@Test public void testEscapeObjectName2() throws Exception { String objectName = "Catalina:type=Resource,resourcetype=Context,path=/,host=localhost,class=javax.sql.DataSource,name=\"jdbc/my-datasource\""; String actual = strategy.escapeObjectName(new ObjectName(objectName)); assertThat( actual, is( "Catalina.class__javax_sql_DataSource.host__localhost.name__jdbc_my-datasource.path___.resourcetype__Context.type__Resource")); }
/** * Test an expression with '#' based keywords (#hostname#) and with '%' based variables mapped to * objectname properties. * * @throws Exception */ @Test public void testResolveExpression() throws Exception { // prepare String expression = "#hostname#.tomcat.datasource.%host%.%path%.%name%"; String objectName = "Catalina:type=Resource,resourcetype=Context,path=/,host=localhost,class=javax.sql.DataSource,name=\"jdbc/my-datasource\""; // test String actual = strategy.resolveExpression(expression, new ObjectName(objectName)); // verify assertThat(actual, is("tomcat1.tomcat.datasource.localhost._.jdbc_my-datasource")); }
@Test public void testEscapeObjectName1() throws Exception { String objectName = "java.lang:type=GarbageCollector,name=PS Scavenge"; String actual = strategy.escapeObjectName(new ObjectName(objectName)); assertThat(actual, is("java_lang.name__PS_Scavenge.type__GarbageCollector")); }