use of com.newrelic.api.agent.Request in project newrelic-java-agent by newrelic.
the class ApiTest method testSetUserName.
@Test
public void testSetUserName() {
Transaction tx = Transaction.getTransaction();
tx.getTransactionActivity().tracerStarted(new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("dude")));
Request request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
Response response = new ApiTestHelper.ResponseWrapper(new MockHttpServletResponse());
NewRelic.setRequestAndResponse(request, response);
NewRelic.setUserName("myname");
Assert.assertEquals("myname", tx.getUserAttributes().get("user"));
}
use of com.newrelic.api.agent.Request in project newrelic-java-agent by newrelic.
the class ApiTest method testSetRequestAndResponse.
@Test
public void testSetRequestAndResponse() {
TransactionDataList txList = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txList);
Transaction tx = Transaction.getTransaction();
OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("blah"));
Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
Request request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
Response response = new ApiTestHelper.ResponseWrapper(new MockHttpServletResponse());
NewRelic.setRequestAndResponse(request, response);
tracer.finish(0, null);
Assert.assertEquals(1, txList.size());
Assert.assertEquals("/mytest", txList.get(0).getRequestUri(AgentConfigImpl.ATTRIBUTES));
TransactionStats stats = apiTestHelper.tranStats;
ResponseTimeStats dispatcherStats = stats.getUnscopedStats().getOrCreateResponseTimeStats("HttpDispatcher");
Assert.assertEquals(1, dispatcherStats.getCallCount());
Assert.assertEquals(1, stats.getUnscopedStats().getOrCreateResponseTimeStats("WebTransaction/Uri/mytest").getCallCount());
Assert.assertEquals(1, stats.getUnscopedStats().getApdexStats("Apdex/Uri/mytest").getApdexSatisfying());
Assert.assertEquals(1, stats.getUnscopedStats().getApdexStats("Apdex").getApdexSatisfying());
Assert.assertEquals(1, stats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.WEB_TRANSACTION).getCallCount());
Assert.assertEquals(0, stats.getUnscopedStats().getOrCreateResponseTimeStats(MetricNames.OTHER_TRANSACTION_ALL).getCallCount());
}
use of com.newrelic.api.agent.Request in project newrelic-java-agent by newrelic.
the class ApiTest method testSetRequestAndResponseThenSetTxName.
@Test
public void testSetRequestAndResponseThenSetTxName() {
TransactionDataList txList = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txList);
Transaction tx = Transaction.getTransaction();
OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("blah"));
Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
Request request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
Response response = new ApiTestHelper.ResponseWrapper(new MockHttpServletResponse());
NewRelic.setRequestAndResponse(request, response);
NewRelic.setTransactionName("Test", "Foo");
tracer.finish(0, null);
Assert.assertEquals("WebTransaction/Test/Foo", tx.getPriorityTransactionName().getName());
}
use of com.newrelic.api.agent.Request in project newrelic-java-agent by newrelic.
the class ApiTest method nameTransactionThenSetRequestAndResponse.
@Test
public void nameTransactionThenSetRequestAndResponse() {
TransactionDataList txList = new TransactionDataList();
ServiceFactory.getTransactionService().addTransactionListener(txList);
Transaction tx = Transaction.getTransaction();
OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("blah"));
Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
tracer.nameTransaction(TransactionNamePriority.CUSTOM_HIGH);
Request request = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "mytest", "", "&test=dude"));
Response response = new ApiTestHelper.ResponseWrapper(new MockHttpServletResponse());
NewRelic.setRequestAndResponse(request, response);
tracer.finish(0, null);
Assert.assertEquals("WebTransaction/Custom/test.newrelic.test.agent.api.ApiTest/", tx.getPriorityTransactionName().getName());
}
use of com.newrelic.api.agent.Request in project newrelic-java-agent by newrelic.
the class AgentHelper method getWebRequestDispatcher.
public static Dispatcher getWebRequestDispatcher(final MockHttpServletRequest request, MockHttpServletResponse response, Transaction transaction) {
Request req = new Request() {
@Override
public String getRequestURI() {
return request.getRequestURI();
}
@Override
public String getRemoteUser() {
return request.getRemoteUser();
}
@Override
public String[] getParameterValues(String name) {
return request.getParameterValues(name);
}
@Override
public Enumeration getParameterNames() {
return request.getParameterNames();
}
@Override
public String getHeader(String name) {
return request.getHeader(name);
}
@Override
public String getCookieValue(String name) {
return null;
}
@Override
public Object getAttribute(String name) {
return request.getAttribute(name);
}
@Override
public HeaderType getHeaderType() {
return HeaderType.HTTP;
}
};
Response res = new Response() {
@Override
public int getStatus() throws Exception {
return 0;
}
@Override
public String getStatusMessage() throws Exception {
return null;
}
@Override
public void setHeader(String name, String value) {
}
@Override
public String getContentType() {
return null;
}
@Override
public HeaderType getHeaderType() {
return HeaderType.HTTP;
}
};
return new com.newrelic.agent.dispatchers.WebRequestDispatcher(req, res, transaction);
}
Aggregations