Search in sources :

Example 1 with TestLogger

use of com.newrelic.agent.bridge.TestLogger in project newrelic-java-agent by newrelic.

the class ClassNoticingFactoryTest method doesNotAddDuplicates.

@Test
public void doesNotAddDuplicates() throws MalformedURLException {
    ExecutorService executorService = mock(ExecutorService.class);
    JarAnalystFactory factory = mock(JarAnalystFactory.class);
    when(factory.createURLAnalyzer(any(URL.class))).thenReturn(mock(Runnable.class));
    ClassNoticingFactory target = new ClassNoticingFactory(factory, executorService, new TestLogger());
    target.addURL(new URL("file:/Users/roger/webapps/java_test_webapp/WEB-INF/lib/commons-httpclient-3.0.1.jar!/org/apache/commons/httpclient/HttpVersion.class"));
    target.addURL(new URL("file:/Users/roger/webapps/java_test_webapp/WEB-INF/lib/commons-httpclient-3.0.1.jar!/org/apache/commons/httpclient/Dude.class"));
    verify(factory, times(1)).createURLAnalyzer(new URL("file:/Users/roger/webapps/java_test_webapp/WEB-INF/lib/commons-httpclient-3.0.1.jar"));
    verify(executorService, times(1)).submit(any(Runnable.class));
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) TestLogger(com.newrelic.agent.bridge.TestLogger) URL(java.net.URL) Test(org.junit.Test)

Example 2 with TestLogger

use of com.newrelic.agent.bridge.TestLogger in project newrelic-java-agent by newrelic.

the class ClassNoticingFactoryTest method noticingJunit.

@Test
public void noticingJunit() throws IOException {
    ExecutorService executorService = mock(ExecutorService.class);
    JarAnalystFactory factory = mock(JarAnalystFactory.class);
    when(factory.createURLAnalyzer(any(URL.class))).thenReturn(mock(Runnable.class));
    ClassNoticingFactory target = new ClassNoticingFactory(factory, executorService, new TestLogger());
    target.newClassMatchVisitor(Test.class.getClassLoader(), Test.class, new ClassReader("org.junit.Test"), new ClassWriter(0), new InstrumentationContext(null, Test.class, Test.class.getProtectionDomain()));
    ArgumentCaptor<URL> captor = ArgumentCaptor.forClass(URL.class);
    verify(factory, times(1)).createURLAnalyzer(captor.capture());
    // Yes, this test will fail if you upgrade junit. Should be an easy fix, but sorry!
    assertTrue(captor.getValue().toString(), captor.getValue().toString().endsWith("junit-4.12.jar"));
}
Also used : InstrumentationContext(com.newrelic.agent.instrumentation.context.InstrumentationContext) Test(org.junit.Test) ExecutorService(java.util.concurrent.ExecutorService) ClassReader(org.objectweb.asm.ClassReader) TestLogger(com.newrelic.agent.bridge.TestLogger) URL(java.net.URL) ClassWriter(org.objectweb.asm.ClassWriter) Test(org.junit.Test)

Example 3 with TestLogger

use of com.newrelic.agent.bridge.TestLogger in project newrelic-java-agent by newrelic.

the class ClassNoticingFactoryTest method noticingTestClass.

@Test
public void noticingTestClass() throws IOException {
    ExecutorService executorService = mock(ExecutorService.class);
    JarAnalystFactory factory = mock(JarAnalystFactory.class);
    when(factory.createURLAnalyzer(any(URL.class))).thenReturn(mock(Runnable.class));
    ClassNoticingFactory target = new ClassNoticingFactory(factory, executorService, new TestLogger());
    target.newClassMatchVisitor(this.getClass().getClassLoader(), this.getClass(), new ClassReader(this.getClass().getName()), new ClassWriter(0), new InstrumentationContext(null, this.getClass(), this.getClass().getProtectionDomain()));
    String codeSourceLocation = this.getClass().getProtectionDomain().getCodeSource().getLocation().toString();
    if (codeSourceLocation.endsWith("/")) {
        // we expect the test classes to be staged in a gradle directory, not in a jar.
        verifyZeroInteractions(factory, executorService);
    } else {
        fail("Unexpected jar for test class?? " + codeSourceLocation);
    }
}
Also used : InstrumentationContext(com.newrelic.agent.instrumentation.context.InstrumentationContext) ExecutorService(java.util.concurrent.ExecutorService) ClassReader(org.objectweb.asm.ClassReader) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) TestLogger(com.newrelic.agent.bridge.TestLogger) URL(java.net.URL) ClassWriter(org.objectweb.asm.ClassWriter) Test(org.junit.Test)

Example 4 with TestLogger

use of com.newrelic.agent.bridge.TestLogger in project newrelic-java-agent by newrelic.

the class ClassNoticingFactoryTest method jarProtocol.

@Test
public void jarProtocol() throws MalformedURLException {
    ExecutorService executorService = mock(ExecutorService.class);
    JarAnalystFactory factory = mock(JarAnalystFactory.class);
    when(factory.createURLAnalyzer(any(URL.class))).thenReturn(mock(Runnable.class));
    ClassNoticingFactory target = new ClassNoticingFactory(factory, executorService, new TestLogger());
    // jboss sends us complex urls like this
    target.addURL(new URL("jar:file:/Users/sdaubin/servers/jboss-as-7.1.1.Final/modules/org/apache/xerces/main/xercesImpl-2.9.1-jbossas-1.jar!/"));
    verify(factory, times(1)).createURLAnalyzer(new URL("file:/Users/sdaubin/servers/jboss-as-7.1.1.Final/modules/org/apache/xerces/main/xercesImpl-2.9.1-jbossas-1.jar"));
    verify(executorService, times(1)).submit(any(Runnable.class));
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) TestLogger(com.newrelic.agent.bridge.TestLogger) URL(java.net.URL) Test(org.junit.Test)

Aggregations

TestLogger (com.newrelic.agent.bridge.TestLogger)4 URL (java.net.URL)4 ExecutorService (java.util.concurrent.ExecutorService)4 Test (org.junit.Test)4 InstrumentationContext (com.newrelic.agent.instrumentation.context.InstrumentationContext)2 ClassReader (org.objectweb.asm.ClassReader)2 ClassWriter (org.objectweb.asm.ClassWriter)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)1