Search in sources :

Example 16 with Pointcut

use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut in project newrelic-java-agent by newrelic.

the class ExtensionDomParserTest method testMethodAnnotation.

@Test
public void testMethodAnnotation() throws Exception {
    Extension ext = ExtensionDomParser.readFile(getFile(METHOD_ANNOTATION_FILE_PATH));
    Instrumentation inst = ext.getInstrumentation();
    List<Pointcut> thePcs = inst.getPointcut();
    Assert.assertEquals(1, thePcs.size());
    Pointcut pc = thePcs.get(0);
    Assert.assertNull(pc.getClassName());
    Assert.assertNull(pc.getInterfaceName());
    Assert.assertNotNull(pc.getMethodAnnotation());
    Assert.assertEquals("javax.ws.rs.DELETE", pc.getMethodAnnotation());
    ExtensionConversionUtility.convertToPointCutsForValidation(ext);
}
Also used : Extension(com.newrelic.agent.extension.beans.Extension) Pointcut(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut) Instrumentation(com.newrelic.agent.extension.beans.Extension.Instrumentation) Test(org.junit.Test)

Example 17 with Pointcut

use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut in project newrelic-java-agent by newrelic.

the class ExtensionDomParserTest method testDomOnePointCutNoPrefix.

@Test
public void testDomOnePointCutNoPrefix() throws Exception {
    Extension ext = ExtensionDomParser.readFile(getFile(FILE_PATH_1_NO_PREFIX));
    // ext attributes
    Assert.assertEquals("test1", ext.getName());
    Assert.assertEquals(1.0, ext.getVersion(), .001);
    Assert.assertTrue(ext.isEnabled());
    Instrumentation inst = ext.getInstrumentation();
    Assert.assertEquals("PREFIX", inst.getMetricPrefix());
    List<Pointcut> thePcs = inst.getPointcut();
    Assert.assertEquals(1, thePcs.size());
    Pointcut pc = thePcs.get(0);
    Assert.assertTrue(pc.isTransactionStartPoint());
    Assert.assertFalse(pc.isIgnoreTransaction());
    Assert.assertFalse(pc.isExcludeFromTransactionTrace());
    Assert.assertFalse(pc.isLeaf());
    Assert.assertNull(pc.getMetricNameFormat());
    Assert.assertEquals("test.CustomExampleTest", pc.getClassName().getValue());
    List<Method> methods = pc.getMethod();
    Assert.assertEquals(2, methods.size());
    Assert.assertEquals("run", methods.get(0).getName());
    Assert.assertEquals("finish", methods.get(1).getName());
    Assert.assertEquals("(Ljava/lang/String;Ljava/lang/String;)", MethodParameters.getDescriptor(methods.get(0).getParameters()));
    Assert.assertEquals("(F)", MethodParameters.getDescriptor(methods.get(1).getParameters()));
    List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToPointCutsForValidation(ext);
    Assert.assertNotNull(pcs);
    Assert.assertEquals(1, pcs.size());
    ExtensionClassAndMethodMatcher actual = pcs.get(0);
    // test method matching
    Assert.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "run", "(Ljava/lang/String;Ljava/lang/String;)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(Ljava/lang/String;Ljava/lang/String;)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(F)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "run", "(F)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(actual.getMethodMatcher().matches(MethodMatcher.UNSPECIFIED_ACCESS, "finish", "(B)V", com.google.common.collect.ImmutableSet.<String>of()));
    // test class matching
    Assert.assertEquals(1, actual.getClassMatcher().getClassNames().size());
    Assert.assertEquals("test/CustomExampleTest", actual.getClassMatcher().getClassNames().toArray()[0]);
}
Also used : Extension(com.newrelic.agent.extension.beans.Extension) Pointcut(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) Instrumentation(com.newrelic.agent.extension.beans.Extension.Instrumentation) Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) Test(org.junit.Test)

Example 18 with Pointcut

use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut in project newrelic-java-agent by newrelic.

the class ExtensionDomParserTest method testSuperclassPointCut.

@Test
public void testSuperclassPointCut() throws Exception {
    Extension ext = ExtensionDomParser.readFile(getFile(SUPERCLASS_FILE_PATH));
    Instrumentation inst = ext.getInstrumentation();
    List<Pointcut> thePcs = inst.getPointcut();
    Assert.assertEquals(2, thePcs.size());
    Pointcut pc = thePcs.get(0);
    Assert.assertNotNull(pc.getClassName());
    Assert.assertEquals("test.SuperTest", pc.getClassName().getValue());
    List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToPointCutsForValidation(ext);
    Assert.assertNotNull(pcs);
    Assert.assertEquals(2, pcs.size());
    ExtensionClassAndMethodMatcher actual = pcs.get(0);
    Assert.assertTrue(actual.getClassMatcher() instanceof ChildClassMatcher);
    ExtensionClassAndMethodMatcher returnMatcher = pcs.get(1);
    Assert.assertTrue(returnMatcher.getClassMatcher() instanceof ChildClassMatcher);
    Assert.assertTrue(returnMatcher.getMethodMatcher() instanceof ExactReturnTypeMethodMatcher);
    Assert.assertTrue(returnMatcher.getMethodMatcher().matches(Opcodes.ACC_PUBLIC, "bogus", "()Lcom/framework/Result;", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(returnMatcher.getMethodMatcher().matches(Opcodes.ACC_PUBLIC, "test", "()[Lcom/framework/Result;", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(returnMatcher.getMethodMatcher().matches(Opcodes.ACC_PUBLIC, "dude", "(Lcom/framework/Result;)V", com.google.common.collect.ImmutableSet.<String>of()));
}
Also used : Extension(com.newrelic.agent.extension.beans.Extension) Pointcut(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut) ExactReturnTypeMethodMatcher(com.newrelic.agent.instrumentation.methodmatchers.ExactReturnTypeMethodMatcher) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) Instrumentation(com.newrelic.agent.extension.beans.Extension.Instrumentation) ChildClassMatcher(com.newrelic.agent.instrumentation.classmatchers.ChildClassMatcher) Test(org.junit.Test)

Example 19 with Pointcut

use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut in project newrelic-java-agent by newrelic.

the class ExtensionDomParserTest method testClassInterface.

@Test
public void testClassInterface() throws Exception {
    Extension ext = ExtensionDomParser.readFile(getFile(FILE_PATH_7_INTERFACE_CLASS));
    // ext attributes
    Assert.assertEquals("test1", ext.getName());
    Assert.assertEquals(1.0, ext.getVersion(), .001);
    Assert.assertTrue(ext.isEnabled());
    Instrumentation inst = ext.getInstrumentation();
    List<Pointcut> thePcs = inst.getPointcut();
    Assert.assertEquals(2, thePcs.size());
    Pointcut pc = thePcs.get(0);
    Assert.assertTrue(pc.isTransactionStartPoint());
    Assert.assertEquals("com.newrelic.agent.extension.beans.Extension", pc.getClassName().getValue());
    Assert.assertNull(pc.getInterfaceName());
    List<Method> methods = pc.getMethod();
    Assert.assertEquals(1, methods.size());
    pc = thePcs.get(1);
    Assert.assertTrue(pc.isTransactionStartPoint());
    Assert.assertEquals("com.newrelic.agent.Agent", pc.getInterfaceName());
    Assert.assertNull(pc.getClassName());
    methods = pc.getMethod();
    Assert.assertEquals(2, methods.size());
    List<ExtensionClassAndMethodMatcher> pcs = ExtensionConversionUtility.convertToPointCutsForValidation(ext);
    Assert.assertNotNull(pcs);
    Assert.assertEquals(2, pcs.size());
    ExtensionClassAndMethodMatcher actual = pcs.get(0);
    Assert.assertEquals(ExactClassMatcher.class, actual.getClassMatcher().getClass());
    actual = pcs.get(1);
    Assert.assertEquals(InterfaceMatcher.class, actual.getClassMatcher().getClass());
}
Also used : Extension(com.newrelic.agent.extension.beans.Extension) Pointcut(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut) ExtensionClassAndMethodMatcher(com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher) Instrumentation(com.newrelic.agent.extension.beans.Extension.Instrumentation) Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) Test(org.junit.Test)

Example 20 with Pointcut

use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut in project newrelic-java-agent by newrelic.

the class ExtensionDomParserTest method testDomAllAtts.

@Test
public void testDomAllAtts() throws Exception {
    Extension ext = ExtensionDomParser.readFile(getFile(FILE_PATH_2));
    // ext attributes
    Assert.assertEquals("test2", ext.getName());
    Assert.assertEquals(2.2, ext.getVersion(), .001);
    Assert.assertFalse(ext.isEnabled());
    Instrumentation inst = ext.getInstrumentation();
    Assert.assertEquals("special", inst.getMetricPrefix());
    List<Pointcut> thePcs = inst.getPointcut();
    Assert.assertEquals(2, thePcs.size());
    Pointcut pc = thePcs.get(0);
    Assert.assertTrue(pc.isTransactionStartPoint());
    Assert.assertFalse(pc.isIgnoreTransaction());
    Assert.assertTrue(pc.isExcludeFromTransactionTrace());
    Assert.assertTrue(pc.isLeaf());
    Assert.assertEquals("/Hello", pc.getMetricNameFormat());
    Assert.assertEquals("test.CustomExampleTest$1", ExtensionConversionUtility.getClassName(pc));
    List<Method> methods = pc.getMethod();
    Assert.assertEquals(2, methods.size());
    Assert.assertEquals("run", methods.get(0).getName());
    Assert.assertEquals("finish", methods.get(1).getName());
    Assert.assertEquals("(Ljava/lang/String;[Ljava/lang/String;)", MethodParameters.getDescriptor(methods.get(0).getParameters()));
    Assert.assertEquals("()", MethodParameters.getDescriptor(methods.get(1).getParameters()));
    Pointcut pc1 = thePcs.get(1);
    Assert.assertFalse(pc1.isTransactionStartPoint());
    Assert.assertTrue(pc1.isIgnoreTransaction());
    Assert.assertFalse(pc1.isExcludeFromTransactionTrace());
    Assert.assertEquals("/Yikes/End", pc1.getMetricNameFormat());
    Assert.assertEquals("com.sample.Validator", pc1.getClassName().getValue());
    methods = pc1.getMethod();
    Assert.assertEquals(2, methods.size());
    Assert.assertEquals("runner", methods.get(0).getName());
    Assert.assertEquals("startup", methods.get(1).getName());
    Assert.assertEquals("(ILjava/util/List;)", MethodParameters.getDescriptor(methods.get(0).getParameters()));
    Assert.assertEquals("()", MethodParameters.getDescriptor(methods.get(1).getParameters()));
}
Also used : Extension(com.newrelic.agent.extension.beans.Extension) Pointcut(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut) Instrumentation(com.newrelic.agent.extension.beans.Extension.Instrumentation) Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) Test(org.junit.Test)

Aggregations

Pointcut (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut)22 Test (org.junit.Test)19 Instrumentation (com.newrelic.agent.extension.beans.Extension.Instrumentation)17 Extension (com.newrelic.agent.extension.beans.Extension)16 Method (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method)12 ExtensionClassAndMethodMatcher (com.newrelic.agent.instrumentation.custom.ExtensionClassAndMethodMatcher)9 HashMap (java.util.HashMap)7 HashSet (java.util.HashSet)6 MethodParameters (com.newrelic.agent.extension.beans.MethodParameters)4 ArrayList (java.util.ArrayList)4 ClassName (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.ClassName)2 AgentHelper.getFile (com.newrelic.agent.AgentHelper.getFile)1 XmlException (com.newrelic.agent.extension.util.XmlException)1 ChildClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ChildClassMatcher)1 ClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ClassMatcher)1 ExactClassMatcher (com.newrelic.agent.instrumentation.classmatchers.ExactClassMatcher)1 InterfaceMatcher (com.newrelic.agent.instrumentation.classmatchers.InterfaceMatcher)1 ExactReturnTypeMethodMatcher (com.newrelic.agent.instrumentation.methodmatchers.ExactReturnTypeMethodMatcher)1 File (java.io.File)1