Search in sources :

Example 6 with Request

use of com.newrelic.api.agent.Request in project newrelic-java-agent by newrelic.

the class ApiTest method testSetProductName.

@Test
public void testSetProductName() {
    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.setProductName("prodName");
    Assert.assertEquals("prodName", tx.getUserAttributes().get("product"));
}
Also used : MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Response(com.newrelic.api.agent.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) Request(com.newrelic.api.agent.Request) MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 7 with Request

use of com.newrelic.api.agent.Request in project newrelic-java-agent by newrelic.

the class ApiTest method testSetTxNameThenSetRequestAndResponse.

@Test
public void testSetTxNameThenSetRequestAndResponse() {
    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));
    NewRelic.setTransactionName("Test", "Foo");
    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/Test/Foo", tx.getPriorityTransactionName().getName());
}
Also used : MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Response(com.newrelic.api.agent.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) TransactionDataList(com.newrelic.agent.TransactionDataList) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) Request(com.newrelic.api.agent.Request) MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 8 with Request

use of com.newrelic.api.agent.Request in project newrelic-java-agent by newrelic.

the class ApiTest method testSetAccountName.

@Test
public void testSetAccountName() {
    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.setAccountName("accountName");
    Assert.assertEquals("accountName", tx.getUserAttributes().get("account"));
}
Also used : MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Response(com.newrelic.api.agent.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) Request(com.newrelic.api.agent.Request) MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Example 9 with Request

use of com.newrelic.api.agent.Request in project newrelic-java-agent by newrelic.

the class ApiImplementationUpdateTest method testTransform.

@Test
public void testTransform() throws Exception {
    // remove required methods from Request implementation class
    Class<?> clazz = RequestImpl.class;
    Set<Method> methodsToRemove = new HashSet<>();
    methodsToRemove.add(new Method("getHeaderType", "()Lcom/newrelic/api/agent/HeaderType;"));
    byte[] classBytes = removeMethods(clazz, methodsToRemove);
    // verify missing methods
    RequireMethodsAdapter adapter = getRequireMethodsAdapter(clazz, Request.class, REQUEST_METHODS);
    expectMissingMethods(adapter, classBytes);
    // should add default implementations for missing methods
    ApiImplementationUpdate transformer = new ApiImplementationUpdate();
    classBytes = transformer.transform(clazz.getClassLoader(), null, null, null, classBytes, null, null);
    // verify no missing methods
    adapter = getRequireMethodsAdapter(clazz, Request.class, REQUEST_METHODS);
    expectNoMissingMethods(adapter, classBytes);
}
Also used : RequireMethodsAdapter(com.newrelic.agent.instrumentation.RequireMethodsAdapter) Request(com.newrelic.api.agent.Request) Method(org.objectweb.asm.commons.Method) HashSet(java.util.HashSet) Test(org.junit.Test) ClassMatcherTest(com.newrelic.agent.instrumentation.classmatchers.ClassMatcherTest)

Example 10 with Request

use of com.newrelic.api.agent.Request in project newrelic-java-agent by newrelic.

the class ApiTest method setRequestAndResponseFirstWins.

@Test
public void setRequestAndResponseFirstWins() throws Exception {
    TransactionDataList txList = new TransactionDataList();
    ServiceFactory.getTransactionService().addTransactionListener(txList);
    Transaction tx = Transaction.getTransaction();
    OtherRootTracer tracer = new OtherRootTracer(tx, new ClassMethodSignature("", "", ""), this, new SimpleMetricNameFormat("otherRootTracer"));
    Assert.assertEquals(tracer, tx.getTransactionActivity().tracerStarted(tracer));
    Request firstRequest = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "firstWins", "", ""));
    Response firstResponse = new FirstResponse(new MockHttpServletResponse());
    NewRelic.setRequestAndResponse(firstRequest, firstResponse);
    Request secondRequest = new ApiTestHelper.RequestWrapper(new MockHttpServletRequest("/", "thisIsABug", "", ""));
    Response secondResponse = new SecondResponse(new MockHttpServletResponse());
    NewRelic.setRequestAndResponse(secondRequest, secondResponse);
    tracer.finish(0, null);
    Assert.assertEquals(firstRequest.getRequestURI(), tx.getDispatcher().getUri());
    Assert.assertEquals(firstResponse.getStatus(), ((WebRequestDispatcher) tx.getDispatcher()).getStatus());
    String name = tx.getPriorityTransactionName().getName();
    Assert.assertNotEquals("WebTransaction/Uri/thisIsABug", name);
    Assert.assertEquals("WebTransaction/Uri/firstWins", name);
}
Also used : MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) ExtendedRequest(com.newrelic.api.agent.ExtendedRequest) Request(com.newrelic.api.agent.Request) MockHttpRequest(com.newrelic.agent.tracers.servlet.MockHttpRequest) MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) OtherRootTracer(com.newrelic.agent.tracers.OtherRootTracer) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) MockHttpResponse(com.newrelic.agent.tracers.servlet.MockHttpResponse) Response(com.newrelic.api.agent.Response) CloseableHttpResponse(org.apache.http.client.methods.CloseableHttpResponse) HttpServletResponse(javax.servlet.http.HttpServletResponse) TransactionDataList(com.newrelic.agent.TransactionDataList) Transaction(com.newrelic.agent.Transaction) ClassMethodSignature(com.newrelic.agent.tracers.ClassMethodSignature) SimpleMetricNameFormat(com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse) BrowserConfigTest(com.newrelic.agent.browser.BrowserConfigTest) Test(org.junit.Test)

Aggregations

Request (com.newrelic.api.agent.Request)15 Response (com.newrelic.api.agent.Response)12 Test (org.junit.Test)11 MockHttpServletRequest (org.apache.struts.mock.MockHttpServletRequest)10 MockHttpServletResponse (org.apache.struts.mock.MockHttpServletResponse)10 HttpServletResponse (javax.servlet.http.HttpServletResponse)9 Transaction (com.newrelic.agent.Transaction)8 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)8 ClassMethodSignature (com.newrelic.agent.tracers.ClassMethodSignature)8 OtherRootTracer (com.newrelic.agent.tracers.OtherRootTracer)8 SimpleMetricNameFormat (com.newrelic.agent.tracers.metricname.SimpleMetricNameFormat)8 MockHttpRequest (com.newrelic.agent.tracers.servlet.MockHttpRequest)8 MockHttpResponse (com.newrelic.agent.tracers.servlet.MockHttpResponse)8 ExtendedRequest (com.newrelic.api.agent.ExtendedRequest)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 HttpUriRequest (org.apache.http.client.methods.HttpUriRequest)8 TransactionDataList (com.newrelic.agent.TransactionDataList)5 WebRequestDispatcher (com.newrelic.agent.dispatchers.WebRequestDispatcher)2 TransactionStats (com.newrelic.agent.stats.TransactionStats)2 WebResponse (com.newrelic.agent.bridge.WebResponse)1