Skip to content

Commit

Permalink
in relation to LOGBACK-1696
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <ceki@qos.ch>
  • Loading branch information
ceki committed Oct 7, 2022
1 parent 9b3b800 commit 41e1ddc
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -131,11 +131,7 @@ public long getTimeStamp() {
}

public void setTimeStamp(long timeStamp) {
if (this.timeStamp != 0) {
throw new IllegalStateException("timeStamp has been already set for this event.");
} else {
this.timeStamp = timeStamp;
}
this.timeStamp = timeStamp;
}

public long getSequenceNumber() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,30 @@
import ch.qos.logback.access.spi.AccessContext;
import ch.qos.logback.access.spi.AccessEvent;
import ch.qos.logback.access.spi.IAccessEvent;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.model.TimestampModel;
import jakarta.servlet.http.Cookie;
import org.assertj.core.util.Lists;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.time.Instant;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class ConverterTest {

IAccessEvent event;
AccessEvent event;
DummyRequest request = new DummyRequest();
DummyResponse response = new DummyResponse();
AccessContext accessContext = new AccessContext();

Locale defaultLocale = Locale.getDefault();

@BeforeEach
public void setUp() throws Exception {
event = createEvent();
Expand All @@ -47,6 +54,7 @@ public void tearDown() throws Exception {
event = null;
request = null;
response = null;
Locale.setDefault(defaultLocale);
}

@Test
Expand All @@ -65,6 +73,29 @@ public void testDateConverter() {
assertEquals(converter.cachingDateFormatter.format(event.getTimeStamp()), result);
}

@Test
public void testDateConverter_AU_locale() {
Locale auLocale = Locale.forLanguageTag("en-AU");
Locale.setDefault(auLocale);

DateConverter converter = new DateConverter();
List<String> optionsList = Lists.list(CoreConstants.CLF_DATE_PATTERN, "Australia/Sydney");

converter.setOptionList(optionsList);
converter.start();
Instant instant = Instant.parse("2022-10-21T10:30:20.800Z");

System.out.println(instant.toEpochMilli());

event.setTimeStamp(instant.toEpochMilli());
String result = converter.convert(event);
assertEquals("21/Oct/2022:21:30:20 +1100", result);
System.out.println(result);

assertEquals(converter.cachingDateFormatter.format(event.getTimeStamp()), result);
}


public void testLineLocalPortConverter() {
LocalPortConverter converter = new LocalPortConverter();
converter.start();
Expand Down Expand Up @@ -190,7 +221,7 @@ public void testStatusCodeConverter() {
assertEquals(Integer.toString(event.getServerAdapter().getStatusCode()), result);
}

private IAccessEvent createEvent() {
private AccessEvent createEvent() {
DummyServerAdapter dummyAdapter = new DummyServerAdapter(request, response);
return new AccessEvent(accessContext, request, response, dummyAdapter);
}
Expand Down

0 comments on commit 41e1ddc

Please sign in to comment.