Search in sources :

Example 1 with MessageData

use of com.microsoft.applicationinsights.smoketest.schemav2.MessageData in project ApplicationInsights-Java by microsoft.

the class CoreAndFilterTests method testTrackTrace.

@Test
@TargetUri("/trackTrace")
public void testTrackTrace() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    List<Envelope> mdList = mockedIngestion.waitForMessageItemsInRequest(3);
    Envelope rdEnvelope = rdList.get(0);
    Envelope mdEnvelope1 = mdList.get(0);
    Envelope mdEnvelope2 = mdList.get(1);
    Envelope mdEnvelope3 = mdList.get(2);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    List<MessageData> messages = mockedIngestion.getMessageDataInRequest();
    assertThat(messages, hasItem(TraceDataMatchers.hasMessage("This is first trace message.")));
    assertThat(messages, hasItem(allOf(TraceDataMatchers.hasMessage("This is second trace message."), TraceDataMatchers.hasSeverityLevel(SeverityLevel.Error))));
    assertThat(messages, hasItem(allOf(TraceDataMatchers.hasMessage("This is third trace message."), TraceDataMatchers.hasSeverityLevel(SeverityLevel.Information), TraceDataMatchers.hasProperty("key", "value"))));
    assertParentChild(rd, rdEnvelope, mdEnvelope1, "GET /CoreAndFilter/trackTrace");
    assertParentChild(rd, rdEnvelope, mdEnvelope2, "GET /CoreAndFilter/trackTrace");
    assertParentChild(rd, rdEnvelope, mdEnvelope3, "GET /CoreAndFilter/trackTrace");
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) MessageData(com.microsoft.applicationinsights.smoketest.schemav2.MessageData) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test)

Example 2 with MessageData

use of com.microsoft.applicationinsights.smoketest.schemav2.MessageData in project ApplicationInsights-Java by microsoft.

the class MockedAppInsightsIngestionServer method getMessageDataInRequest.

public <T extends Domain> List<T> getMessageDataInRequest() {
    List<Envelope> items = getItemsEnvelopeDataType("MessageData");
    List<T> dataItems = new ArrayList<>();
    for (Envelope e : items) {
        String message = ((MessageData) ((Data<?>) e.getData()).getBaseData()).getMessage();
        if (e.getTags().containsKey("ai.operation.id") && !ignoreMessageData(message)) {
            Data<T> dt = (Data<T>) e.getData();
            dataItems.add(dt.getBaseData());
        }
    }
    return dataItems;
}
Also used : MessageData(com.microsoft.applicationinsights.smoketest.schemav2.MessageData) ArrayList(java.util.ArrayList) MessageData(com.microsoft.applicationinsights.smoketest.schemav2.MessageData) Data(com.microsoft.applicationinsights.smoketest.schemav2.Data) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope)

Example 3 with MessageData

use of com.microsoft.applicationinsights.smoketest.schemav2.MessageData in project ApplicationInsights-Java by microsoft.

the class SpringBootAutoTest method test.

@Test
@TargetUri("/test")
public void test() throws Exception {
    List<Envelope> rdList = mockedIngestion.waitForItems("RequestData", 1);
    List<Envelope> mdList = mockedIngestion.waitForMessageItemsInRequest(1);
    Envelope rdEnvelope = rdList.get(0);
    Envelope mdEnvelope = mdList.get(0);
    RequestData rd = (RequestData) ((Data<?>) rdEnvelope.getData()).getBaseData();
    MessageData md = (MessageData) ((Data<?>) mdEnvelope.getData()).getBaseData();
    assertEquals("GET /test", rd.getName());
    assertEquals("200", rd.getResponseCode());
    assertEquals("z", rd.getProperties().get("tenant"));
    assertEquals(1, rd.getProperties().size());
    assertTrue(rd.getSuccess());
    assertEquals("hello", md.getMessage());
    assertEquals(SeverityLevel.Information, md.getSeverityLevel());
    assertEquals("Logger", md.getProperties().get("SourceType"));
    assertEquals("INFO", md.getProperties().get("LoggingLevel"));
    assertEquals("smoketestapp", md.getProperties().get("LoggerName"));
    assertNotNull(md.getProperties().get("ThreadName"));
    assertEquals("z", rd.getProperties().get("tenant"));
    assertEquals(5, md.getProperties().size());
}
Also used : RequestData(com.microsoft.applicationinsights.smoketest.schemav2.RequestData) MessageData(com.microsoft.applicationinsights.smoketest.schemav2.MessageData) Envelope(com.microsoft.applicationinsights.smoketest.schemav2.Envelope) Test(org.junit.Test)

Example 4 with MessageData

use of com.microsoft.applicationinsights.smoketest.schemav2.MessageData in project ApplicationInsights-Java by microsoft.

the class SpringBootAutoTest method doDelayedSystemExitTest.

@Test
@TargetUri("/delayedSystemExit")
public void doDelayedSystemExitTest() throws Exception {
    mockedIngestion.waitForItems("RequestData", 1);
    mockedIngestion.waitForItem(input -> {
        if (!"MessageData".equals(input.getData().getBaseType())) {
            return false;
        }
        MessageData data = (MessageData) ((Data<?>) input.getData()).getBaseData();
        return data.getMessage().equals("this is an error right before shutdown");
    }, 10, TimeUnit.SECONDS);
}
Also used : MessageData(com.microsoft.applicationinsights.smoketest.schemav2.MessageData) Test(org.junit.Test)

Example 5 with MessageData

use of com.microsoft.applicationinsights.smoketest.schemav2.MessageData in project ApplicationInsights-Java by microsoft.

the class SpringBootAutoTest method doMostBasicTest.

@Test
@TargetUri("/test")
public void doMostBasicTest() throws Exception {
    Telemetry telemetry = getTelemetry(0);
    assertEquals("testValue1", telemetry.rd.getProperties().get("attribute1"));
    assertEquals("testValue2", telemetry.rd.getProperties().get("attribute2"));
    assertEquals("sensitiveData1", telemetry.rd.getProperties().get("sensitiveAttribute1"));
    assertEquals("*/TelemetryProcessors/test*", telemetry.rd.getProperties().get("httpPath"));
    assertEquals(4, telemetry.rd.getProperties().size());
    assertTrue(telemetry.rd.getSuccess());
    // Log processor test
    List<MessageData> logs = mockedIngestion.getMessageDataInRequest();
    MessageData md1 = logs.get(0);
    assertEquals("smoketestappcontroller::INFO", md1.getMessage());
}
Also used : MessageData(com.microsoft.applicationinsights.smoketest.schemav2.MessageData) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)10 Envelope (com.microsoft.applicationinsights.smoketest.schemav2.Envelope)9 MessageData (com.microsoft.applicationinsights.smoketest.schemav2.MessageData)9 RequestData (com.microsoft.applicationinsights.smoketest.schemav2.RequestData)8 RemoteDependencyData (com.microsoft.applicationinsights.smoketest.schemav2.RemoteDependencyData)2 Data (com.microsoft.applicationinsights.smoketest.schemav2.Data)1 ArrayList (java.util.ArrayList)1