Search in sources :

Example 1 with TransactionNamePriority

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

the class BrowserConfigTest method testFooterWithNonce.

@Test
public void testFooterWithNonce() throws Exception {
    setupManager(true, false);
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    TransactionNamePriority expectedPriority = TransactionNamePriority.FILTER_NAME;
    PriorityTransactionName ptn = PriorityTransactionName.create("name", null, expectedPriority);
    tx.setPriorityTransactionName(ptn);
    tx.getUserAttributes().put("theInt", 11);
    tx.getUserAttributes().put("theDouble", 11.22);
    tx.getUserAttributes().put("theLong", 22L);
    tx.getUserAttributes().put("theString", "abc123");
    tx.getUserAttributes().put("theShort", Short.parseShort("1"));
    Map<String, Object> beaconSettings = createBeaconSettings(true);
    BrowserConfig beaconConfig = BrowserConfig.createBrowserConfig("appName", beaconSettings);
    BrowserTransactionState bts = BrowserTransactionStateImpl.create(tx);
    String value = beaconConfig.getBrowserTimingFooter(bts, "ABC123");
    List<String> matched = new ArrayList<>(2);
    String expectedStartScript = "\n<script type=\"text/javascript\" nonce=\"ABC123\">" + BrowserFooter.FOOTER_JS_START;
    Assert.assertTrue(value.startsWith(expectedStartScript));
    matched.add(expectedStartScript);
    Assert.assertTrue(value.endsWith(BrowserFooter.FOOTER_END));
    matched.add(BrowserFooter.FOOTER_END);
    final List<String> expectedFooterProperties = Arrays.asList(EXPECTED_FOOTER_PROPERTIES);
    // The whole point to the tricky code in checkStrings(), above, is that these key:value
    // pairs do not have to come back in the same order that they were added in, above.
    final String[] USER_ATTRIBUTES = { "\"theInt\":11", "\"theDouble\":11.22", "\"theLong\":22", "\"theString\":\"abc123\"", "\"theShort\":1" };
    final List<String> expectedUserAttributes = Arrays.asList(USER_ATTRIBUTES);
    checkStringsAndUserParams(value, expectedFooterProperties, expectedUserAttributes, null, matched);
}
Also used : Transaction(com.newrelic.agent.Transaction) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) ArrayList(java.util.ArrayList) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) TransactionNamePriority(com.newrelic.agent.bridge.TransactionNamePriority) Test(org.junit.Test)

Example 2 with TransactionNamePriority

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

the class BrowserConfigTest method testRumDisableNoAgentFile.

@Test
public void testRumDisableNoAgentFile() throws Exception {
    setupManager(false, false);
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    TransactionNamePriority expectedPriority = TransactionNamePriority.FILTER_NAME;
    PriorityTransactionName ptn = PriorityTransactionName.create("name", null, expectedPriority);
    tx.setPriorityTransactionName(ptn);
    // off
    try {
        Map<String, Object> beaconSettings = createBeaconSettingsEmtpyAgentFile(false);
        BrowserConfig beaconConfig = BrowserConfig.createBrowserConfig("appName", beaconSettings);
        beaconConfig.getBrowserTimingHeader();
        Assert.fail("An exception should have been thrown when rum is disabled");
    } catch (Exception e) {
    // we should go into here
    }
    // back on
    Map<String, Object> beaconSettings = createBeaconSettingsEmtpyAgentFile(true);
    BrowserConfig beaconConfig = BrowserConfig.createBrowserConfig("appName", beaconSettings);
    BrowserTransactionState bts = BrowserTransactionStateImpl.create(tx);
    Assert.assertEquals(HEADER, beaconConfig.getBrowserTimingHeader());
    Assert.assertTrue(beaconConfig.getBrowserTimingFooter(bts).startsWith("\n<script type=\"text/javascript\">window.NREUM||"));
}
Also used : Transaction(com.newrelic.agent.Transaction) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) TransactionNamePriority(com.newrelic.agent.bridge.TransactionNamePriority) Test(org.junit.Test)

Example 3 with TransactionNamePriority

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

the class BrowserConfigTest method testFooterCaptureAttsOneAndSsl.

@Test
public void testFooterCaptureAttsOneAndSsl() throws Exception {
    setupManager(true, true);
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    TransactionNamePriority expectedPriority = TransactionNamePriority.FILTER_NAME;
    PriorityTransactionName ptn = PriorityTransactionName.create("name", null, expectedPriority);
    tx.setPriorityTransactionName(ptn);
    tx.getUserAttributes().put("product", "daProduct");
    Map<String, Object> beaconSettings = createBeaconSettings(true);
    BrowserConfig beaconConfig = BrowserConfig.createBrowserConfig("appName", beaconSettings);
    BrowserTransactionState bts = BrowserTransactionStateImpl.create(tx);
    Assert.assertEquals(HEADER, beaconConfig.getBrowserTimingHeader());
    String value = beaconConfig.getBrowserTimingFooter(bts);
    List<String> matched = new ArrayList<>(15);
    checkFooter(value, matched);
    final ArrayList<String> expectedFooterProperties = new ArrayList<>();
    expectedFooterProperties.addAll(Arrays.asList(EXPECTED_FOOTER_PROPERTIES));
    expectedFooterProperties.add("\"sslForHttp\":true");
    final String[] USER_ATTRIBUTES = { "\"product\":\"daProduct\"" };
    final List<String> expectedUserAttributes = Arrays.asList(USER_ATTRIBUTES);
    checkStringsAndUserParams(value, expectedFooterProperties, expectedUserAttributes, null, matched);
}
Also used : PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) ArrayList(java.util.ArrayList) Transaction(com.newrelic.agent.Transaction) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) TransactionNamePriority(com.newrelic.agent.bridge.TransactionNamePriority) Test(org.junit.Test)

Example 4 with TransactionNamePriority

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

the class BrowserConfigTest method testFooterCaptureAtts.

@Test
public void testFooterCaptureAtts() throws Exception {
    setupManager(true, false);
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    TransactionNamePriority expectedPriority = TransactionNamePriority.FILTER_NAME;
    PriorityTransactionName ptn = PriorityTransactionName.create("name", null, expectedPriority);
    tx.setPriorityTransactionName(ptn);
    tx.getUserAttributes().put("theInt", 11);
    tx.getUserAttributes().put("theDouble", 11.22);
    tx.getUserAttributes().put("theLong", 22L);
    tx.getUserAttributes().put("theString", "abc123");
    tx.getUserAttributes().put("theShort", Short.parseShort("1"));
    Map<String, Object> beaconSettings = createBeaconSettings(true);
    BrowserConfig beaconConfig = BrowserConfig.createBrowserConfig("appName", beaconSettings);
    BrowserTransactionState bts = BrowserTransactionStateImpl.create(tx);
    Assert.assertEquals(HEADER, beaconConfig.getBrowserTimingHeader());
    String value = beaconConfig.getBrowserTimingFooter(bts);
    List<String> matched = new ArrayList<>(15);
    checkFooter(value, matched);
    final List<String> expectedFooterProperties = Arrays.asList(EXPECTED_FOOTER_PROPERTIES);
    // The whole point to the tricky code in checkStrings(), above, is that these key:value
    // pairs do not have to come back in the same order that they were added in, above.
    final String[] USER_ATTRIBUTES = { "\"theInt\":11", "\"theDouble\":11.22", "\"theLong\":22", "\"theString\":\"abc123\"", "\"theShort\":1" };
    final List<String> expectedUserAttributes = Arrays.asList(USER_ATTRIBUTES);
    checkStringsAndUserParams(value, expectedFooterProperties, expectedUserAttributes, null, matched);
}
Also used : Transaction(com.newrelic.agent.Transaction) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) ArrayList(java.util.ArrayList) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) TransactionNamePriority(com.newrelic.agent.bridge.TransactionNamePriority) Test(org.junit.Test)

Example 5 with TransactionNamePriority

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

the class BrowserConfigTest method testFooterNoCaptureParams.

@Test
public void testFooterNoCaptureParams() throws Exception {
    setupManager(false, false);
    Transaction tx = Transaction.getTransaction();
    BasicRequestRootTracer tracer = createDispatcherTracer();
    tx.getTransactionActivity().tracerStarted(tracer);
    TransactionNamePriority expectedPriority = TransactionNamePriority.FILTER_NAME;
    PriorityTransactionName ptn = PriorityTransactionName.create("name", null, expectedPriority);
    tx.setPriorityTransactionName(ptn);
    tx.getUserAttributes().put("theInt", 11);
    tx.getUserAttributes().put("theDouble", 11.22);
    tx.getUserAttributes().put("theLong", 22L);
    tx.getUserAttributes().put("theString", "abc123");
    tx.getUserAttributes().put("theShort", Short.parseShort("1"));
    Map<String, Object> beaconSettings = createBeaconSettings(true);
    BrowserConfig beaconConfig = BrowserConfig.createBrowserConfig("appName", beaconSettings);
    BrowserTransactionState bts = BrowserTransactionStateImpl.create(tx);
    Assert.assertEquals(HEADER, beaconConfig.getBrowserTimingHeader());
    // The value looks something like this but with no line breaks:
    // <script type="text/javascript">window.NREUM||(NREUM={});NREUM.info={
    // "applicationID":"45047","applicationTime":4045,"beacon":"staging-beacon-2.newrelic.com","queueTime":0,
    // "licenseKey":"3969ca217b","transactionName":"DxIJAw==","agent":"js-agent.newrelic.com\nr-248.min.js",
    // "errorBeacon":"staging-jserror.newrelic.com"}</script>
    String value = beaconConfig.getBrowserTimingFooter(bts);
    List<String> matched = new ArrayList<>(15);
    checkFooter(value, matched);
    List<String> expectedFooterProperties = Arrays.asList(EXPECTED_FOOTER_PROPERTIES);
    checkStrings(value, expectedFooterProperties, matched);
}
Also used : Transaction(com.newrelic.agent.Transaction) PriorityTransactionName(com.newrelic.agent.transaction.PriorityTransactionName) ArrayList(java.util.ArrayList) BasicRequestRootTracer(com.newrelic.agent.tracers.servlet.BasicRequestRootTracer) TransactionNamePriority(com.newrelic.agent.bridge.TransactionNamePriority) Test(org.junit.Test)

Aggregations

TransactionNamePriority (com.newrelic.agent.bridge.TransactionNamePriority)16 Test (org.junit.Test)16 Transaction (com.newrelic.agent.Transaction)14 BasicRequestRootTracer (com.newrelic.agent.tracers.servlet.BasicRequestRootTracer)14 PriorityTransactionName (com.newrelic.agent.transaction.PriorityTransactionName)14 ArrayList (java.util.ArrayList)7 BrowserConfigTest (com.newrelic.agent.browser.BrowserConfigTest)5