Search in sources :

Example 11 with MockHttpRequest

use of com.newrelic.agent.tracers.servlet.MockHttpRequest in project newrelic-java-agent by newrelic.

the class OtherTransactionErrorsTest method testException.

@Test
public void testException() throws Exception {
    MockHttpRequest mockHttpRequest = new MockHttpRequest();
    mockHttpRequest.setMethod("GET");
    mockHttpRequest.setRequestURI("requesturi");
    mockHttpRequest.setHeader(AttributeNames.REQUEST_ACCEPT_PARAMETER_NAME, "accept");
    mockHttpRequest.setHeader(AttributeNames.REQUEST_HOST_PARAMETER_NAME, "host");
    mockHttpRequest.setHeader(AttributeNames.REQUEST_USER_AGENT_PARAMETER_NAME, "useragent");
    mockHttpRequest.setHeader(AttributeNames.REQUEST_CONTENT_LENGTH_PARAMETER_NAME, "content-length");
    NewRelic.setRequestAndResponse(mockHttpRequest, new Response() {

        @Override
        public int getStatus() throws Exception {
            return 200;
        }

        @Override
        public String getStatusMessage() throws Exception {
            return "Status Message";
        }

        @Override
        public String getContentType() {
            return "text/content-type";
        }

        @Override
        public HeaderType getHeaderType() {
            return HeaderType.HTTP;
        }

        @Override
        public void setHeader(String name, String value) {
        // 
        }
    });
    try {
        new Runnable() {

            @Trace(dispatcher = true)
            @Override
            public void run() {
                throw new RuntimeException();
            }
        }.run();
    } catch (RuntimeException ex) {
    }
    Assert.assertEquals(1, transactions.size());
    Assert.assertNotNull(transactions.get(0).getThrowable());
}
Also used : Response(com.newrelic.api.agent.Response) Trace(com.newrelic.api.agent.Trace) MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) HeaderType(com.newrelic.api.agent.HeaderType) Test(org.junit.Test)

Example 12 with MockHttpRequest

use of com.newrelic.agent.tracers.servlet.MockHttpRequest in project newrelic-java-agent by newrelic.

the class TransactionDispatcherTest method testSetWebResponseFirstWins.

@Test
public void testSetWebResponseFirstWins() {
    Transaction tx = Transaction.getTransaction(true);
    MockHttpRequest request = new MockHttpRequest();
    tx.setWebRequest(request);
    MockHttpResponse responseOne = new MockHttpResponse();
    tx.setWebResponse(responseOne);
    assertEquals(responseOne, tx.getDispatcher().getResponse());
    MockHttpResponse responseTwo = new MockHttpResponse();
    tx.setWebResponse(responseTwo);
    assertEquals(responseOne, tx.getDispatcher().getResponse());
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) Transaction(com.newrelic.agent.Transaction) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Test(org.junit.Test)

Example 13 with MockHttpRequest

use of com.newrelic.agent.tracers.servlet.MockHttpRequest in project newrelic-java-agent by newrelic.

the class TransactionDispatcherTest method testSetDispatcherFirstWins.

@Test
public void testSetDispatcherFirstWins() {
    Transaction tx = Transaction.getTransaction(true);
    Dispatcher dispatcherOne = new WebRequestDispatcher(new MockHttpRequest(), new MockHttpResponse(), tx);
    tx.setDispatcher(dispatcherOne);
    assertEquals(dispatcherOne, tx.getDispatcher());
    Dispatcher dispatcherTwo = new WebRequestDispatcher(new MockHttpRequest(), new MockHttpResponse(), tx);
    tx.setDispatcher(dispatcherTwo);
    assertEquals(dispatcherOne, tx.getDispatcher());
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) Transaction(com.newrelic.agent.Transaction) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) Dispatcher(com.newrelic.agent.dispatchers.Dispatcher) WebRequestDispatcher(com.newrelic.agent.dispatchers.WebRequestDispatcher) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Test(org.junit.Test)

Example 14 with MockHttpRequest

use of com.newrelic.agent.tracers.servlet.MockHttpRequest in project newrelic-java-agent by newrelic.

the class TransactionDispatcherTest method testSetWebRequestFirstWins.

@Test
public void testSetWebRequestFirstWins() {
    Transaction.clearTransaction();
    Transaction tx = Transaction.getTransaction(true);
    MockHttpRequest requestOne = new MockHttpRequest();
    tx.setWebRequest(requestOne);
    assertEquals(requestOne, tx.getDispatcher().getRequest());
    MockHttpRequest requestTwo = new MockHttpRequest();
    tx.setWebRequest(requestTwo);
    assertEquals(requestOne, tx.getDispatcher().getRequest());
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) Transaction(com.newrelic.agent.Transaction) Test(org.junit.Test)

Example 15 with MockHttpRequest

use of com.newrelic.agent.tracers.servlet.MockHttpRequest in project newrelic-java-agent by newrelic.

the class AgentAttributeSenderTest method createDispatcherTracer.

private BasicRequestRootTracer createDispatcherTracer() {
    Transaction tx = Transaction.getTransaction();
    MockHttpRequest httpRequest = new MockHttpRequest();
    MockHttpResponse httpResponse = new MockHttpResponse();
    ClassMethodSignature sig = new ClassMethodSignature(getClass().getName(), "dude", "()V");
    return new BasicRequestRootTracer(tx, sig, this, httpRequest, httpResponse);
}
Also used : MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse)

Aggregations

MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)22 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)19 Transaction (com.newrelic.agent.Transaction)16 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)15 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)15 Test (org.junit.Test)5 Tracer (com.newrelic.agent.tracers.Tracer)4 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)3 Dispatcher (com.newrelic.agent.dispatchers.Dispatcher)2 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)1 SpanEvent (com.newrelic.agent.model.SpanEvent)1 TransactionEvent (com.newrelic.agent.service.analytics.TransactionEvent)1 DefaultTracer (com.newrelic.agent.tracers.DefaultTracer)1 OtherRootSqlTracer (com.newrelic.agent.tracers.OtherRootSqlTracer)1 SqlTracer (com.newrelic.agent.tracers.SqlTracer)1 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)1 HeaderType (com.newrelic.api.agent.HeaderType)1 Response (com.newrelic.api.agent.Response)1 Trace (com.newrelic.api.agent.Trace)1 JSONArray (org.json.simple.JSONArray)1