Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions google-cloud-logging/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -108,11 +108,35 @@
</dependency>

<!-- Test dependencies -->
<!-- JUnit 4.x is still needed as the gapic-generator still generates tests with it -->
<!-- Remove once the gapic-generator is able to generate JUnit 5.x tests -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<!-- The generated tests from gapic-generator are still generated with JUnit4. -->
<!-- Remove once they are migrated to JUnit 5.x+ -->
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.easymock</groupId>
<artifactId>easymock</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2025 Google LLC
* Copyright 2026 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@
import static org.easymock.EasyMock.expect;
import static org.easymock.EasyMock.newCapture;
import static org.easymock.EasyMock.replay;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;

import com.google.api.core.ApiFutures;
import com.google.cloud.MonitoredResource;
Expand All @@ -34,14 +36,11 @@
import com.google.logging.v2.WriteLogEntriesRequest;
import com.google.logging.v2.WriteLogEntriesResponse;
import org.easymock.Capture;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

@RunWith(JUnit4.class)
public class AutoPopulateMetadataTests {
class AutoPopulateMetadataTests {

private static final String LOG_NAME = "test-log";
private static final String RESOURCE_PROJECT_ID = "env-project-id";
Expand Down Expand Up @@ -81,8 +80,8 @@ public class AutoPopulateMetadataTests {
private final Capture<WriteLogEntriesRequest> rpcWriteArgument = newCapture();
private ResourceTypeEnvironmentGetter mockedEnvGetter;

@Before
public void setup() {
@BeforeEach
void setup() {
mockedEnvGetter = createMock(ResourceTypeEnvironmentGetter.class);
mockedRpcFactory = createMock(LoggingRpcFactory.class);
mockedRpc = createMock(LoggingRpc.class);
Expand All @@ -106,8 +105,8 @@ public void setup() {
logging = options.getService();
}

@After
public void teardown() {
@AfterEach
void teardown() {
new ContextHandler().removeCurrentContext();
}

Expand All @@ -124,7 +123,7 @@ private void mockCurrentContext(
}

@Test
public void testAutoPopulationEnabledInLoggingOptions() {
void testAutoPopulationEnabledInLoggingOptions() {
mockCurrentContext(HTTP_REQUEST, TRACE_ID, SPAN_ID, TRACE_SAMPLED);

logging.write(ImmutableList.of(SIMPLE_LOG_ENTRY));
Expand All @@ -138,7 +137,7 @@ public void testAutoPopulationEnabledInLoggingOptions() {
}

@Test
public void testAutoPopulationEnabledInWriteOptionsAndDisabledInLoggingOptions() {
void testAutoPopulationEnabledInWriteOptionsAndDisabledInLoggingOptions() {
// redefine logging option to opt out auto-populating
LoggingOptions options =
logging.getOptions().toBuilder().setAutoPopulateMetadata(false).build();
Expand All @@ -156,7 +155,7 @@ public void testAutoPopulationEnabledInWriteOptionsAndDisabledInLoggingOptions()
}

@Test
public void testAutoPopulationDisabledInWriteOptions() {
void testAutoPopulationDisabledInWriteOptions() {
mockCurrentContext(HTTP_REQUEST, TRACE_ID, SPAN_ID, TRACE_SAMPLED);

logging.write(ImmutableList.of(SIMPLE_LOG_ENTRY), WriteOption.autoPopulateMetadata(false));
Expand All @@ -170,7 +169,7 @@ public void testAutoPopulationDisabledInWriteOptions() {
}

@Test
public void testSourceLocationPopulation() {
void testSourceLocationPopulation() {
SourceLocation expected = SourceLocation.fromCurrentContext();
logging.write(ImmutableList.of(SIMPLE_LOG_ENTRY_WITH_DEBUG));

Expand All @@ -182,7 +181,7 @@ public void testSourceLocationPopulation() {
}

@Test
public void testNotFormattedTraceId() {
void testNotFormattedTraceId() {
mockCurrentContext(HTTP_REQUEST, TRACE_ID, SPAN_ID, TRACE_SAMPLED);

final MonitoredResource expectedResource = MonitoredResource.newBuilder("custom").build();
Expand All @@ -194,7 +193,7 @@ public void testNotFormattedTraceId() {
}

@Test
public void testMonitoredResourcePopulationInWriteOptions() {
void testMonitoredResourcePopulationInWriteOptions() {
mockCurrentContext(HTTP_REQUEST, TRACE_ID, SPAN_ID, TRACE_SAMPLED);

final MonitoredResource expectedResource = MonitoredResource.newBuilder("custom").build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,31 +26,30 @@
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Iterator;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.rules.Timeout;
import java.util.concurrent.TimeUnit;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Timeout;

/**
* A base class for system tests. This class can be extended to run system tests in different
* environments (e.g. local emulator or remote Logging service).
*/
@Timeout(value = 600, unit = TimeUnit.SECONDS)
public class BaseSystemTest {

@Rule public Timeout globalTimeout = Timeout.seconds(600);

private static final DateTimeFormatter RFC_3339 =
DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");

protected static Logging logging;

@BeforeClass
@BeforeAll
public static void beforeClass() {
RemoteLoggingHelper helper = RemoteLoggingHelper.create();
logging = helper.getOptions().getService();
}

@AfterClass
@AfterAll
public static void afterClass() throws Exception {
logging.close();
}
Expand Down
Loading