Skip to content

Commit

Permalink
Refactoring of min-level set tests for better naming
Browse files Browse the repository at this point in the history
  • Loading branch information
galderz committed Dec 4, 2020
1 parent 3b9aacf commit cae32ee
Show file tree
Hide file tree
Showing 20 changed files with 134 additions and 97 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.logging.minlevel.set.warn;
package io.quarkus.it.logging.minlevel.set.above;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
Expand All @@ -9,9 +9,10 @@

import io.quarkus.it.logging.minlevel.set.LoggingWitness;

@Path("/log/warn")
public class LoggingWarnResource {
static final Logger LOG = Logger.getLogger(LoggingWarnResource.class);
@Path("/log/above")
public class LoggingMinLevelAbove {

static final Logger LOG = Logger.getLogger(LoggingMinLevelAbove.class);

@GET
@Path("/not-info")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.logging.minlevel.set.trace;
package io.quarkus.it.logging.minlevel.set.below;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
Expand All @@ -9,10 +9,10 @@

import io.quarkus.it.logging.minlevel.set.LoggingWitness;

@Path("/log/trace")
public class LoggingTraceResource {
@Path("/log/below")
public class LoggingMinLevelBelow {

static final Logger LOG = Logger.getLogger(LoggingTraceResource.class);
static final Logger LOG = Logger.getLogger(LoggingMinLevelBelow.class);

@GET
@Path("/trace")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.logging.minlevel.set.any;
package io.quarkus.it.logging.minlevel.set.bydefault;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
Expand All @@ -9,10 +9,10 @@

import io.quarkus.it.logging.minlevel.set.LoggingWitness;

@Path("/log/any")
public class LoggingAnyResource {
@Path("/log/bydefault")
public class LoggingMinLevelByDefault {

static final Logger LOG = Logger.getLogger(LoggingAnyResource.class);
static final Logger LOG = Logger.getLogger(LoggingMinLevelByDefault.class);

@GET
@Path("/debug")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.it.logging.minlevel.set.min_level_error.sub;
package io.quarkus.it.logging.minlevel.set.promote;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
Expand All @@ -9,10 +9,10 @@

import io.quarkus.it.logging.minlevel.set.LoggingWitness;

@Path("/log/min-level-error")
public class LoggingMinLevelError {
@Path("/log/promote")
public class LoggingMinLevelPromote {

static final Logger LOG = Logger.getLogger(LoggingMinLevelError.class);
static final Logger LOG = Logger.getLogger(LoggingMinLevelPromote.class);

@GET
@Path("/not-info")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.quarkus.it.logging.minlevel.set.promote.sub;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.jboss.logging.Logger;

import io.quarkus.it.logging.minlevel.set.LoggingWitness;

@Path("/log/promote/sub")
public class LoggingMinLevelPromoteSub {

static final Logger LOG = Logger.getLogger(LoggingMinLevelPromoteSub.class);

@GET
@Path("/not-info")
@Produces(MediaType.TEXT_PLAIN)
public boolean isNotInfo() {
return !LOG.isInfoEnabled() && !LoggingWitness.loggedInfo("should not print", LOG);
}

@GET
@Path("/error")
@Produces(MediaType.TEXT_PLAIN)
public boolean isError() {
return LoggingWitness.loggedError("error message", LOG);
}

}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
quarkus.log.min-level=DEBUG
quarkus.log.category."io.quarkus.it.logging.minlevel.set.trace".min-level=TRACE
quarkus.log.category."io.quarkus.it.logging.minlevel.set.warn".min-level=INFO
quarkus.log.category."io.quarkus.it.logging.minlevel.set.min_level_error".min-level=ERROR
quarkus.log.category."io.quarkus.it.logging.minlevel.set.above".min-level=INFO
quarkus.log.category."io.quarkus.it.logging.minlevel.set.below".min-level=TRACE
quarkus.log.category."io.quarkus.it.logging.minlevel.set.promote".min-level=ERROR
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,18 @@
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;

/**
* Test that verifies that min-level can go higher than default min-level,
* and this can be further tweaked at runtime to go to above to an even higher level.
*/
@QuarkusTest
@QuarkusTestResource(SetRuntimeLogLevels.class)
public class LoggingWarnResourceTest {
public class LoggingMinLevelAboveTest {

@Test
public void testNotInfo() {
given()
.when().get("/log/warn/not-info")
.when().get("/log/above/not-info")
.then()
.statusCode(200)
.body(is("true"));
Expand All @@ -24,7 +28,7 @@ public void testNotInfo() {
@Test
public void testWarn() {
given()
.when().get("/log/warn/warn")
.when().get("/log/above/warn")
.then()
.statusCode(200)
.body(is("true"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;

/**
* Test verifies that a min-level override that goes below the default min-level is applied correctly.
*/
@QuarkusTest
@QuarkusTestResource(SetRuntimeLogLevels.class)
public class LoggingSubTraceResourceTest {
public class LoggingMinLevelBelowTest {

@Test
public void testTrace() {
given()
.when().get("/log/trace/sub/trace")
.when().get("/log/below/trace")
.then()
.statusCode(200)
.body(is("true"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.quarkus.it.logging.minlevel.set;

import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.is;

import org.junit.jupiter.api.Test;

import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;

/**
* Tests that verify that changes to the default min-level are applied correctly.
*
* If unset, the default is INFO,
* so this test verifies that when the default min-level is changed,
* say to DEBUG, the code works as expected.
*/
@QuarkusTest
@QuarkusTestResource(SetRuntimeLogLevels.class)
public class LoggingMinLevelByDefaultTest {

@Test
public void testDebug() {
given()
.when().get("/log/bydefault/debug")
.then()
.statusCode(200)
.body(is("true"));
}

@Test
public void testNotTrace() {
given()
.when().get("/log/bydefault/not-trace")
.then()
.statusCode(200)
.body(is("true"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,26 @@
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;

/**
* This test verifies that log levels are promoted to min-level when set below, even for subpackages.
*/
@QuarkusTest
@QuarkusTestResource(SetRuntimeLogLevels.class)
public class LoggingAnyResourceTest {
public class LoggingMinLevelPromoteSubTest {

@Test
public void testDebug() {
public void testNotInfo() {
given()
.when().get("/log/any/debug")
.when().get("/log/promote/sub/not-info")
.then()
.statusCode(200)
.body(is("true"));
}

@Test
public void testNotTrace() {
public void testError() {
given()
.when().get("/log/any/not-trace")
.when().get("/log/promote/sub/error")
.then()
.statusCode(200)
.body(is("true"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,17 @@
import io.quarkus.test.common.QuarkusTestResource;
import io.quarkus.test.junit.QuarkusTest;

/**
* This test verifies that log levels are promoted to min-level when set below.
*/
@QuarkusTest
@QuarkusTestResource(SetRuntimeLogLevels.class)
public class LoggingMinLevelErrorTest {
public class LoggingMinLevelPromoteTest {

@Test
public void testNotInfo() {
given()
.when().get("/log/min-level-error/not-info")
.when().get("/log/promote/not-info")
.then()
.statusCode(200)
.body(is("true"));
Expand All @@ -24,7 +27,7 @@ public void testNotInfo() {
@Test
public void testError() {
given()
.when().get("/log/min-level-error/error")
.when().get("/log/promote/error")
.then()
.statusCode(200)
.body(is("true"));
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativeLoggingAnyResourceIT extends LoggingAnyResourceTest {
public class NativeLoggingMinLevelAboveIT extends LoggingMinLevelAboveTest {

// Execute the same tests but in native mode.
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativeLoggingTraceResourceIT extends LoggingTraceResourceTest {
public class NativeLoggingMinLevelBelowIT extends LoggingMinLevelBelowTest {

// Execute the same tests but in native mode.
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativeLoggingSubTraceResourceIT extends LoggingSubTraceResourceTest {
public class NativeLoggingMinLevelByDefaultIT extends LoggingMinLevelByDefaultTest {

// Execute the same tests but in native mode.
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativeLoggingWarnResourceIT extends LoggingWarnResourceTest {
public class NativeLoggingMinLevelPromoteIT extends LoggingMinLevelPromoteTest {

// Execute the same tests but in native mode.
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package io.quarkus.it.logging.minlevel.set;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
public class NativeLoggingMinLevelPromoteSubIT extends LoggingMinLevelPromoteSubTest {

// Execute the same tests but in native mode.
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ public final class SetRuntimeLogLevels implements QuarkusTestResourceLifecycleMa
@Override
public Map<String, String> start() {
final Map<String, String> systemProperties = new HashMap<>();
systemProperties.put("quarkus.log.category.\"io.quarkus.it.logging.minlevel.set.any\".level", "DEBUG");
systemProperties.put("quarkus.log.category.\"io.quarkus.it.logging.minlevel.set.trace\".level", "TRACE");
systemProperties.put("quarkus.log.category.\"io.quarkus.it.logging.minlevel.set.warn\".level", "WARN");
systemProperties.put("quarkus.log.category.\"io.quarkus.it.logging.minlevel.set.min_level_error.sub\".level", "INFO");
systemProperties.put("quarkus.log.category.\"io.quarkus.it.logging.minlevel.set.bydefault\".level", "DEBUG");
systemProperties.put("quarkus.log.category.\"io.quarkus.it.logging.minlevel.set.above\".level", "WARN");
systemProperties.put("quarkus.log.category.\"io.quarkus.it.logging.minlevel.set.below\".level", "TRACE");
systemProperties.put("quarkus.log.category.\"io.quarkus.it.logging.minlevel.set.promote\".level", "INFO");
return systemProperties;
}

Expand Down

0 comments on commit cae32ee

Please sign in to comment.