aboutsummaryrefslogtreecommitdiffstats
path: root/container-core/src/test/java/com/yahoo/container/logging/JsonConnectionLogWriterTest.java
blob: 1575cb56ab7ad9644e437c1336f9aed997e98592 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.logging;

import com.yahoo.test.json.JsonTestHelper;
import org.junit.jupiter.api.Test;

import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.List;
import java.util.UUID;

/**
 * @author bjorncs
 */
class JsonConnectionLogWriterTest {

    @Test
     void test_serialization() throws IOException {
        var id = UUID.randomUUID();
        var instant = Instant.parse("2021-01-13T12:12:12Z");
        ConnectionLogEntry entry = ConnectionLogEntry.builder(id, instant)
                .withPeerPort(1234)
                .withSslHandshakeFailure(new ConnectionLogEntry.SslHandshakeFailure("UNKNOWN",
                        List.of(
                                new ConnectionLogEntry.SslHandshakeFailure.ExceptionEntry("javax.net.ssl.SSLHandshakeException", "message"),
                                new ConnectionLogEntry.SslHandshakeFailure.ExceptionEntry("java.io.IOException", "cause message"))))
                .withSslSubjectAlternativeNames(List.of("sandns", "sanemail"))
                .build();
        String expectedJson = "{" +
                "\"id\":\""+id.toString()+"\"," +
                "\"timestamp\":\"2021-01-13T12:12:12Z\"," +
                "\"peerPort\":1234," +
                "\"ssl\":{\"handshake-failure\":{\"exception\":[" +
                "{\"cause\":\"javax.net.ssl.SSLHandshakeException\",\"message\":\"message\"}," +
                "{\"cause\":\"java.io.IOException\",\"message\":\"cause message\"}" +
                "],\"type\":\"UNKNOWN\"},\"san\":[\"sandns\",\"sanemail\"]}}";

        JsonConnectionLogWriter writer = new JsonConnectionLogWriter();
        ByteArrayOutputStream out = new ByteArrayOutputStream();
        writer.write(entry, out);
        String actualJson = out.toString(StandardCharsets.UTF_8);
        JsonTestHelper.assertJsonEquals(actualJson, expectedJson);
    }
}