Skip to content

Commit

Permalink
started black box testing
Browse files Browse the repository at this point in the history
Signed-off-by: Ceki Gulcu <[email protected]>
  • Loading branch information
ceki committed Oct 2, 2022
1 parent f22db3f commit c336307
Show file tree
Hide file tree
Showing 87 changed files with 836 additions and 185 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import ch.qos.logback.core.read.ListAppender;
import ch.qos.logback.core.testUtil.CoreTestConstants;
import ch.qos.logback.core.testUtil.RandomUtil;
import ch.qos.logback.core.testUtil.StatusChecker;
import ch.qos.logback.core.status.testUtil.StatusChecker;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import ch.qos.logback.access.AccessTestConstants;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.testUtil.StatusChecker;
import ch.qos.logback.core.status.testUtil.StatusChecker;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.core.ContainerBase;
import org.junit.jupiter.api.AfterEach;
Expand Down
100 changes: 100 additions & 0 deletions logback-classic-blackbox/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-parent</artifactId>
<version>1.4.2-SNAPSHOT</version>
</parent>

<artifactId>logback-classic-blackbox</artifactId>
<packaging>jar</packaging>
<name>Logback Classic Blackbox Testing</name>
<description>Logback Classic Blackbox Testing Module</description>

<dependencies>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>

<dependency>
<groupId>jakarta.servlet</groupId>
<artifactId>jakarta.servlet-api</artifactId>
</dependency>

<dependency>
<groupId>jakarta.mail</groupId>
<artifactId>jakarta.mail-api</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.codehaus.janino</groupId>
<artifactId>janino</artifactId>
<scope>compile</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<executions>
<execution>
<id>default-test</id>
<configuration>

<argLine>
</argLine>
<parallel>classes</parallel>
<threadCount>8</threadCount>
<!--<useUnlimitedThreads>false</useUnlimitedThreads>-->
<forkCount>1C</forkCount>
<reuseForks>true</reuseForks>
<reportFormat>plain</reportFormat>
<trimStackTrace>false</trimStackTrace>
<!-- See https://issues.apache.org/jira/browse/SUREFIRE-1265 -->
<!--<childDelegation>true</childDelegation>-->
<useModulePath>true</useModulePath>

<excludes>
<!--- temporary -->
<exclude>**/JaninoEventEvaluatorTest.java</exclude>
<exclude>**/ConditionalTest.java</exclude>
</excludes>
</configuration>
</execution>

<execution>
<id>singleJVM</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<forkCount>4</forkCount>
<reuseForks>false</reuseForks>
<includes>
</includes>
</configuration>
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>

</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE configuration>

<configuration>

<evaluator name="helloEval">
<Expression>m.matches(message)</Expression>
<matcher>
<name>m</name>
<regex>^hello.*</regex>
<CaseSensitive>false</CaseSensitive>
</matcher>
</evaluator>

<appender name="STR_LIST"
class="ch.qos.logback.core.testUtil.StringListAppender">
<layout>
<Pattern>%caller{4, helloEval}%d %level - %m%n</Pattern>
</layout>
</appender>

<root>
<level value="DEBUG" />
<appender-ref ref="STR_LIST" />
</root>



</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2022, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/

package ch.qos.logback.classic.blackbox;

public class BlackboxClassicTestConstants {

public static final String TEST_SRC_PREFIX = "src/test/";
public static final String TEST_INPUT_PREFIX = TEST_SRC_PREFIX + "blackboxInput/";
public static final String JORAN_INPUT_PREFIX = TEST_INPUT_PREFIX + "joran/";
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* Logback: the reliable, generic, fast and flexible logging framework.
* Copyright (C) 1999-2022, QOS.ch. All rights reserved.
*
* This program and the accompanying materials are dual-licensed under
* either the terms of the Eclipse Public License v1.0 as published by
* the Eclipse Foundation
*
* or (per the licensee's choosing)
*
* under the terms of the GNU Lesser General Public License version 2.1
* as published by the Free Software Foundation.
*/

package ch.qos.logback.classic.blackbox.joran;

import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.blackbox.BlackboxClassicTestConstants;
import ch.qos.logback.classic.joran.JoranConfigurator;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.testUtil.RandomUtil;
import ch.qos.logback.core.testUtil.StringListAppender;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

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

public class BlackboxJoranConfiguratorTest {
LoggerContext loggerContext = new LoggerContext();
Logger logger = loggerContext.getLogger(this.getClass().getName());
Logger root = loggerContext.getLogger(Logger.ROOT_LOGGER_NAME);
//StatusChecker checker = new StatusChecker(loggerContext);
int diff = RandomUtil.getPositiveInt();

void configure(String file) throws JoranException {
JoranConfigurator jc = new JoranConfigurator();
jc.setContext(loggerContext);
loggerContext.putProperty("diff", "" + diff);
jc.doConfigure(file);

}

@Test
public void eval() throws JoranException {
configure(BlackboxClassicTestConstants.JORAN_INPUT_PREFIX + "callerData.xml");
String msg = "hello world";
logger.debug("toto");
logger.debug(msg);

StringListAppender<ILoggingEvent> slAppender = (StringListAppender<ILoggingEvent>) loggerContext
.getLogger("root").getAppender("STR_LIST");
assertNotNull(slAppender);
assertEquals(2, slAppender.strList.size());
assertTrue(slAppender.strList.get(0).contains(" DEBUG - toto"));

String str1 = slAppender.strList.get(1);
assertTrue(str1.contains("Caller+0"));
assertTrue(str1.contains(" DEBUG - hello world"));
}
}
11 changes: 11 additions & 0 deletions logback-classic-blackbox/src/test/java/module-info.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module logback.classic.blackbox {
requires ch.qos.logback.core;
requires ch.qos.logback.classic;
requires jakarta.mail;
requires janino;

requires org.junit.jupiter.api;
requires org.junit.jupiter.engine;

exports ch.qos.logback.classic.blackbox.joran;
}
38 changes: 0 additions & 38 deletions logback-classic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -375,42 +375,4 @@
</pluginManagement>
</build>

<profiles>

<profile>
<!-- Integration tests require the host-orion profile -->
<id>host-orion</id>
<dependencies>
<!-- locally installed artifact -->
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc4</artifactId>
<version>2.0</version>
<scope>test</scope>
</dependency>
<!-- locally installed artifact -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>

<profile>
<!-- Integration tests require the host-hora profile -->
<id>host-hora</id>
<dependencies>
<!-- locally installed artifact -->
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import ch.qos.logback.classic.turbo.ReconfigureOnChangeFilter
import ch.qos.logback.classic.Level
import ch.qos.logback.core.testUtil.CoreTestConstants
import ch.qos.logback.core.testUtil.RandomUtil
import ch.qos.logback.core.testUtil.StatusChecker
import ch.qos.logback.core.status.testUtil.StatusChecker
import ch.qos.logback.classic.Logger
import ch.qos.logback.core.Appender
import ch.qos.logback.core.helpers.NOPAppender
Expand Down
4 changes: 2 additions & 2 deletions logback-classic/src/test/input/fqcn.txt
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ ch.qos.logback.core.joran.action.ext.TouchAction
ch.qos.logback.core.joran.action.IncludeActionTest
ch.qos.logback.core.joran.action.PropertyActionTest
ch.qos.logback.core.joran.action.TopElementAction
ch.qos.logback.core.joran.conditional.PropertyEvalScriptBuilderTest
ch.qos.logback.core.blackbox.joran.conditional.PropertyEvalScriptBuilderTest
ch.qos.logback.core.joran.event.SaxEventRecorderTest
ch.qos.logback.core.joran.event.stax.StaxEventRecorderTest
ch.qos.logback.core.joran.implicitAction.Cake
Expand Down Expand Up @@ -1008,7 +1008,7 @@ ch.qos.logback.core.testUtil.FileTestUtil
ch.qos.logback.core.testUtil.FileToBufferUtil
ch.qos.logback.core.testUtil.NPEAppender
ch.qos.logback.core.testUtil.RandomUtil
ch.qos.logback.core.testUtil.StatusChecker
ch.qos.logback.core.status.testUtil.StatusChecker
ch.qos.logback.core.testUtil.StringListAppender
ch.qos.logback.core.testUtil.TeeOutputStream
ch.qos.logback.core.testUtil.TrivialStatusListener
Expand Down
2 changes: 1 addition & 1 deletion logback-classic/src/test/input/joran/callerData.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
</evaluator>

<appender name="STR_LIST"
class="ch.qos.logback.core.testUtil.StringListAppender">
class="ch.qos.logback.core.testUtil.StringListAppender">
<layout>
<Pattern>%caller{4, helloEval}%d %level - %m%n</Pattern>
</layout>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package ch.qos.logback.classic;

import java.util.concurrent.CyclicBarrier;
import java.util.concurrent.TimeUnit;

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;

import ch.qos.logback.core.contention.AbstractMultiThreadedHarness;
import ch.qos.logback.core.contention.RunnableWithCounterAndDone;
import ch.qos.logback.core.testUtil.StatusChecker;
import ch.qos.logback.core.status.testUtil.StatusChecker;
import org.junit.jupiter.api.Timeout;

@Disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import ch.qos.logback.core.spi.ScanException;
import ch.qos.logback.core.testUtil.StringListAppender;
import ch.qos.logback.core.util.OptionHelper;
import ch.qos.logback.core.util.StatusPrinter;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.slf4j.MDC;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import ch.qos.logback.classic.PatternLayout;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.AppenderBase;
import ch.qos.logback.core.testUtil.RandomUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.CoreConstants;
import ch.qos.logback.core.boolex.EvaluationException;
import ch.qos.logback.core.testUtil.StatusChecker;
import ch.qos.logback.core.status.testUtil.StatusChecker;
import ch.qos.logback.core.util.ContextUtil;
import ch.qos.logback.core.util.StatusPrinter;
import org.junit.Before;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import ch.qos.logback.core.encoder.LayoutWrappingEncoder;
import ch.qos.logback.core.joran.spi.JoranException;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.testUtil.StatusChecker;
import ch.qos.logback.core.status.testUtil.StatusChecker;
import ch.qos.logback.core.util.StatusPrinter;

public class LayoutInsteadOfEncoderTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
import ch.qos.logback.core.spi.ScanException;
import ch.qos.logback.core.status.Status;
import ch.qos.logback.core.testUtil.RandomUtil;
import ch.qos.logback.core.testUtil.StatusChecker;
import ch.qos.logback.core.status.testUtil.StatusChecker;
import ch.qos.logback.core.testUtil.StringListAppender;
import ch.qos.logback.core.util.CachingDateFormatter;
import ch.qos.logback.core.util.StatusPrinter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
import ch.qos.logback.core.testUtil.CoreTestConstants;
import ch.qos.logback.core.testUtil.FileTestUtil;
import ch.qos.logback.core.testUtil.RandomUtil;
import ch.qos.logback.core.testUtil.StatusChecker;
import ch.qos.logback.core.status.testUtil.StatusChecker;
import ch.qos.logback.core.util.StatusPrinter;
import org.junit.jupiter.api.Timeout;

Expand Down
Loading

0 comments on commit c336307

Please sign in to comment.