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());
}
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());
}
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());
}
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());
}
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);
}
Aggregations