use of com.newrelic.agent.extension.beans.MethodParameters in project newrelic-java-agent by newrelic.
the class OrExactParamMethodMatcherTest method testMatchingBasicDuplicatesInSecondCall.
@Test(expected = XmlException.class)
public void testMatchingBasicDuplicatesInSecondCall() throws Exception {
Method m1 = new Method();
m1.setName("hello");
List<String> pts = new ArrayList<>();
pts.add("int");
pts.add("char");
MethodParameters mps1 = new MethodParameters(pts);
m1.setParameters(mps1);
Method m2 = new Method();
m2.setName("configure");
List<String> ptsForM2 = new ArrayList<>();
ptsForM2.add("int");
ptsForM2.add("char");
MethodParameters mps2 = new MethodParameters(ptsForM2);
m2.setParameters(mps2);
List<Method> methods = new ArrayList<>();
methods.add(m1);
methods.add(m2);
Map<String, MethodMapper> mapper = new HashMap<>();
MethodMatcher matcher1 = MethodMatcherUtility.createMethodMatcher("classz", methods, mapper, "EXT");
Assert.assertTrue(matcher1.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "(IC)V", com.google.common.collect.ImmutableSet.<String>of()));
Assert.assertTrue(matcher1.matches(MethodMatcher.UNSPECIFIED_ACCESS, "configure", "(IC)V", com.google.common.collect.ImmutableSet.<String>of()));
MethodMatcherUtility.createMethodMatcher("classz", methods, mapper, "EXT");
}
use of com.newrelic.agent.extension.beans.MethodParameters in project newrelic-java-agent by newrelic.
the class OrExactParamMethodMatcherTest method testMatchingBasicDuplicates.
@Test
public void testMatchingBasicDuplicates() throws Exception {
List<String> pts = new ArrayList<>();
Method m1 = new Method();
m1.setName("hello");
pts.add("int");
pts.add("char");
MethodParameters mps1 = new MethodParameters(pts);
m1.setParameters(mps1);
Method m2 = new Method();
m2.setName("hello");
List<String> ptsForM2 = new ArrayList<>();
ptsForM2.add("int");
ptsForM2.add("char");
MethodParameters mps2 = new MethodParameters(pts);
m2.setParameters(mps2);
List<Method> methods = new ArrayList<>();
methods.add(m1);
methods.add(m2);
Map<String, MethodMapper> mapper = new HashMap<>();
MethodMatcher matcher = MethodMatcherUtility.createMethodMatcher("classz", methods, mapper, "EXT");
Assert.assertTrue(matcher.matches(MethodMatcher.UNSPECIFIED_ACCESS, "hello", "(IC)V", com.google.common.collect.ImmutableSet.<String>of()));
}
use of com.newrelic.agent.extension.beans.MethodParameters in project newrelic-java-agent by newrelic.
the class ReinstrumentUtilsTest method checkInputNotMatchingClasses.
@Test
public void checkInputNotMatchingClasses() {
SampleObject obj = new SampleObject();
ReinstrumentResult result = new ReinstrumentResult();
obj.getClass().getClassLoader();
Set<ClassLoader> loaders = new HashSet<>();
loaders.add(this.getClass().getClassLoader());
Extension ext = new Extension();
Instrumentation inst = new Instrumentation();
ext.setInstrumentation(inst);
Pointcut pc = new Pointcut();
inst.getPointcut().add(pc);
setClassName(pc, SampleObject.class);
// this should match
Method m1 = new Method();
m1.setName("falala");
MethodParameters params1 = new MethodParameters(new ArrayList<String>());
m1.setParameters(params1);
// this should not match
Method m2 = new Method();
m2.setName("notAMatch");
MethodParameters params2 = new MethodParameters(Arrays.asList("boolean"));
m2.setParameters(params2);
// this should not match
Method m3 = new Method();
m3.setName("getHello");
MethodParameters params3 = new MethodParameters(Arrays.asList("java.lang.String", "int"));
m3.setParameters(params3);
pc.getMethod().addAll(Arrays.asList(m1, m2, m3));
Map<String, Class<?>> daClasses = new HashMap<>();
daClasses.put(SampleObject.class.getName(), SampleObject.class);
ReinstrumentUtils.checkInputClasses(result, loaders, ext, daClasses);
Object actual = result.getStatusMap().get(ReinstrumentResult.ERROR_KEY);
Assert.assertNotNull("There should not have been an error. Errors: " + actual, actual);
Assert.assertFalse("The method " + m1.getName() + " should NOT be in the error message", ((String) actual).contains(m1.getName()));
Assert.assertTrue("The method " + m2.getName() + " should be in the error message", ((String) actual).contains(m2.getName()));
Assert.assertTrue("The method " + m3.getName() + " should be in the error message", ((String) actual).contains(m3.getName()));
}
use of com.newrelic.agent.extension.beans.MethodParameters in project newrelic-java-agent by newrelic.
the class ReinstrumentUtilsTest method checkInputClassesNullPointers3.
@Test
public void checkInputClassesNullPointers3() {
SampleObject obj = new SampleObject();
ReinstrumentResult result = new ReinstrumentResult();
obj.getClass().getClassLoader();
Set<ClassLoader> loaders = new HashSet<>();
loaders.add(this.getClass().getClassLoader());
Extension ext = new Extension();
Instrumentation inst = new Instrumentation();
ext.setInstrumentation(inst);
Pointcut pc = new Pointcut();
inst.getPointcut().add(pc);
// no class name set
Method m1 = new Method();
m1.setName("falala");
MethodParameters params1 = new MethodParameters(new ArrayList<String>());
m1.setParameters(params1);
Map<String, Class<?>> daClasses = new HashMap<>();
daClasses.put(SampleObject.class.getName(), SampleObject.class);
ReinstrumentUtils.checkInputClasses(result, loaders, ext, daClasses);
Object actual = result.getStatusMap().get(ReinstrumentResult.ERROR_KEY);
Assert.assertNull("There should not have been an error. Errors: " + actual, actual);
}
use of com.newrelic.agent.extension.beans.MethodParameters in project newrelic-java-agent by newrelic.
the class ReinstrumentUtilsTest method checkInputClassesNullPointers4.
@Test
public void checkInputClassesNullPointers4() {
SampleObject obj = new SampleObject();
ReinstrumentResult result = new ReinstrumentResult();
obj.getClass().getClassLoader();
Set<ClassLoader> loaders = new HashSet<>();
loaders.add(this.getClass().getClassLoader());
Extension ext = new Extension();
Instrumentation inst = new Instrumentation();
ext.setInstrumentation(inst);
Pointcut pc = new Pointcut();
inst.getPointcut().add(pc);
setClassName(pc, SampleObject.class);
Method m1 = new Method();
// no method name
MethodParameters params1 = new MethodParameters(new ArrayList<String>());
m1.setParameters(params1);
Map<String, Class<?>> daClasses = new HashMap<>();
daClasses.put(SampleObject.class.getName(), SampleObject.class);
ReinstrumentUtils.checkInputClasses(result, loaders, ext, daClasses);
Object actual = result.getStatusMap().get(ReinstrumentResult.ERROR_KEY);
Assert.assertNull("There should not have been an error. Errors: " + actual, actual);
}
Aggregations