use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method 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()));
}
use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method 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()));
}
use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method 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()));
}
use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method in project newrelic-java-agent by newrelic.
the class OrExactParamMethodMatcherTest method testNoParamTag.
@Test
public void testNoParamTag() throws Exception {
Method m1 = new Method();
m1.setName("hello");
List<Method> methods = new ArrayList<>();
methods.add(m1);
Map<String, MethodMapper> mapper = new HashMap<>();
MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("hello", methods, mapper, "EXT");
Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "()V", com.google.common.collect.ImmutableSet.<String>of()));
}
use of com.newrelic.agent.extension.beans.Extension.Instrumentation.Pointcut.Method in project newrelic-java-agent by newrelic.
the class OrExactParamMethodMatcherTest method testMatchingBasicEmptyParameterTypeMultiples.
@Test
public void testMatchingBasicEmptyParameterTypeMultiples() throws Exception {
Method m1 = new Method();
m1.setName("hello");
List<String> pts = new ArrayList<>();
m1.setParameters(new MethodParameters(pts));
Method m2 = new Method();
m2.setName("configure");
m2.setParameters(new MethodParameters(null));
List<Method> methods = new ArrayList<>();
methods.add(m1);
methods.add(m2);
Map<String, MethodMapper> mapper = new HashMap<>();
MethodMatcher matcher1 = MethodMatcherUtility.createMethodMatcher("classy", methods, mapper, "EXT");
Assert.assertTrue(matcher1.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "()V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(matcher1.matches(MethodMatcher.UNSPECIFIED_ACCESS, "configure", "()V", com.google.common.collect.ImmutableSet.<String>of()));
// different class and so this should be okay
MethodMatcher matcher2 = MethodMatcherUtility.createMethodMatcher("classing", methods, mapper, "EXT");
Assert.assertTrue(matcher2.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "()V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(matcher2.matches(MethodMatcher.UNSPECIFIED_ACCESS, "configure", "()V", com.google.common.collect.ImmutableSet.<String>of()));
try {
// we should fail here
MethodMatcherUtility.createMethodMatcher("classing", methods, mapper, "EXT");
Assert.fail("Should fail due to methods already being added.");
} catch (Exception e) {
// should get to here
}
}
Aggregations