Search in sources :

Example 1 with MethodMapper

use of com.newrelic.agent.extension.util.MethodMapper in project newrelic-java-agent by newrelic.

the class MethodMatcherTests method createOrMethodMatcherNameOnly.

@Test
public void createOrMethodMatcherNameOnly() throws XmlException {
    Method m1 = new Method();
    m1.setName("m1");
    Method m2 = new Method();
    m2.setName("m2");
    MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("myclass", Arrays.asList(m1, m2), new HashMap<String, MethodMapper>(), "EXT");
    Assert.assertNotNull(matcher);
    Assert.assertTrue(matcher + " not of type OrMethodMatcher", matcher instanceof OrMethodMatcher);
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m3", "()V", com.google.common.collect.ImmutableSet.<String>of()));
}
Also used : Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) MethodMapper(com.newrelic.agent.extension.util.MethodMapper) Test(org.junit.Test)

Example 2 with MethodMapper

use of com.newrelic.agent.extension.util.MethodMapper in project newrelic-java-agent by newrelic.

the class MethodMatcherTests method createOrMethodMatcherMix.

@Test
public void createOrMethodMatcherMix() throws XmlException {
    Method m1 = new Method();
    m1.setName("m1");
    m1.setParameters(new MethodParameters(Arrays.asList("int")));
    Method m2 = new Method();
    m2.setName("m2");
    MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("myclass", Arrays.asList(m1, m2), new HashMap<String, MethodMapper>(), "EXT");
    Assert.assertNotNull(matcher);
    Assert.assertTrue(matcher + " not of type OrMethodMatcher", matcher instanceof OrMethodMatcher);
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m3", "()V", com.google.common.collect.ImmutableSet.<String>of()));
}
Also used : Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) MethodParameters(com.newrelic.agent.extension.beans.MethodParameters) MethodMapper(com.newrelic.agent.extension.util.MethodMapper) Test(org.junit.Test)

Example 3 with MethodMapper

use of com.newrelic.agent.extension.util.MethodMapper in project newrelic-java-agent by newrelic.

the class MethodMatcherTests method createOrMethodMatcherExactOnly.

@Test
public void createOrMethodMatcherExactOnly() throws XmlException {
    Method m1 = new Method();
    m1.setName("m1");
    m1.setParameters(new MethodParameters(Arrays.asList("int")));
    Method m2 = new Method();
    m2.setName("m2");
    m2.setParameters(new MethodParameters(Arrays.asList("int[]")));
    Method m3 = new Method();
    m3.setName("m3");
    m3.setParameters(new MethodParameters(null));
    Method m4 = new Method();
    m4.setName("m4");
    m4.setParameters(new MethodParameters(Collections.EMPTY_LIST));
    MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("myclass", Arrays.asList(m1, m2, m3, m4), new HashMap<String, MethodMapper>(), "EXT");
    Assert.assertNotNull(matcher);
    Assert.assertTrue(matcher + " not of type OrMethodMatcher", matcher instanceof OrMethodMatcher);
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m3", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m3", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m4", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m4", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
}
Also used : Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) MethodParameters(com.newrelic.agent.extension.beans.MethodParameters) MethodMapper(com.newrelic.agent.extension.util.MethodMapper) Test(org.junit.Test)

Example 4 with MethodMapper

use of com.newrelic.agent.extension.util.MethodMapper in project newrelic-java-agent by newrelic.

the class MethodMatcherTests method createMethodMatcherNameOnly.

@Test
public void createMethodMatcherNameOnly() throws XmlException {
    Method m1 = new Method();
    m1.setName("m1");
    MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("myclass", Arrays.asList(m1), new HashMap<String, MethodMapper>(), "EXT");
    Assert.assertNotNull(matcher);
    Assert.assertTrue(matcher + " not of type NameMethodMatcher", matcher instanceof NameMethodMatcher);
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "()V", com.google.common.collect.ImmutableSet.<String>of()));
}
Also used : Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) MethodMapper(com.newrelic.agent.extension.util.MethodMapper) Test(org.junit.Test)

Example 5 with MethodMapper

use of com.newrelic.agent.extension.util.MethodMapper in project newrelic-java-agent by newrelic.

the class MethodMatcherTests method createMethodMatcherExactOnly.

@Test
public void createMethodMatcherExactOnly() throws XmlException {
    Method m1 = new Method();
    m1.setName("m1");
    m1.setParameters(new MethodParameters(Arrays.asList("int")));
    MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("myclass", Arrays.asList(m1), new HashMap<String, MethodMapper>(), "EXT");
    Assert.assertNotNull(matcher);
    Assert.assertTrue(matcher + " not of type ExactParamsMethodMatcher", matcher instanceof ExactParamsMethodMatcher);
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "()V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "(I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m1", "([I)V", com.google.common.collect.ImmutableSet.<String>of()));
    Assert.assertFalse(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "m2", "()V", com.google.common.collect.ImmutableSet.<String>of()));
}
Also used : Method(com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method) MethodParameters(com.newrelic.agent.extension.beans.MethodParameters) MethodMapper(com.newrelic.agent.extension.util.MethodMapper) Test(org.junit.Test)

Aggregations

Method (com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method)13 MethodMapper (com.newrelic.agent.extension.util.MethodMapper)13 Test (org.junit.Test)13 MethodParameters (com.newrelic.agent.extension.beans.MethodParameters)10 ArrayList (java.util.ArrayList)8 HashMap (java.util.HashMap)8 XmlException (com.newrelic.agent.extension.util.XmlException)1