Merge pull request #89 from eugenp/master

update
This commit is contained in:
Maiklins 2021-03-30 21:22:06 +02:00 committed by GitHub
commit 1ac73a5450
56 changed files with 275 additions and 293 deletions

View File

@ -115,7 +115,6 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<useFile>false</useFile>
<includes>
@ -186,7 +185,6 @@
<logback.version>1.2.3</logback.version>
<groovy.version>2.5.7</groovy.version>
<assembly.plugin.version>3.1.0</assembly.plugin.version>
<surefire.plugin.version>2.20.1</surefire.plugin.version>
<compiler.plugin.version>3.8.0</compiler.plugin.version>
<groovy.compiler.version>3.3.0-01</groovy.compiler.version>
</properties>

View File

@ -101,7 +101,6 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<useFile>false</useFile>
<includes>
@ -128,7 +127,6 @@
<hsqldb.version>2.4.0</hsqldb.version>
<spock-core.version>1.1-groovy-2.4</spock-core.version>
<gmavenplus-plugin.version>1.6</gmavenplus-plugin.version>
<surefire.plugin.version>2.20.1</surefire.plugin.version>
</properties>
</project>

View File

@ -49,8 +49,6 @@
<properties>
<!-- testing -->
<assertj.version>3.6.1</assertj.version>
<!-- plugins -->
<maven-surefire-plugin.version>2.22.1</maven-surefire-plugin.version>
</properties>
</project>

View File

@ -148,18 +148,6 @@
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<properties>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>

View File

@ -29,7 +29,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.16</version>
<configuration>
<enableAssertions>true</enableAssertions>
</configuration>

View File

@ -66,7 +66,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<forkCount>0</forkCount>
</configuration>
@ -79,7 +78,6 @@
<target.version>9</target.version>
<compiler.plugin.version>3.8.1</compiler.plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<appmodules.version>1.0</appmodules.version>

View File

@ -99,15 +99,6 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
<properties>
<joda-money.version>1.0.1</joda-money.version>

View File

@ -97,7 +97,6 @@
<!-- Skip normal test execution, we use gwt:test instead -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
<configuration>
<skip>true</skip>
</configuration>
@ -115,7 +114,6 @@
<gwt.version>2.8.2</gwt.version>
<gwt.plugin.version>1.0-rc-8</gwt.plugin.version>
<surefire.plugin.version>2.17</surefire.plugin.version>
</properties>
</project>

View File

@ -66,14 +66,6 @@
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<properties>

View File

@ -38,14 +38,6 @@
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<properties>

View File

@ -37,14 +37,6 @@
<build>
<finalName>guava-collections-set</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<properties>

View File

@ -71,14 +71,6 @@
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<properties>

View File

@ -40,14 +40,6 @@
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
</project>

View File

@ -52,14 +52,6 @@
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<properties>

View File

@ -46,17 +46,8 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<properties>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<guava.version>29.0-jre</guava.version>
</properties>

View File

@ -50,16 +50,6 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<properties>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
</properties>

View File

@ -51,14 +51,6 @@
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<properties>

View File

@ -523,7 +523,6 @@
<jersey.version>2.25</jersey.version>
<arquillian-glassfish.version>1.0.0.Final</arquillian-glassfish.version>
<org.springframework.security.version>4.2.3.RELEASE</org.springframework.security.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
<taglibs.standard.version>1.1.2</taglibs.standard.version>
<com.sun.faces.jsf.version>2.2.14</com.sun.faces.jsf.version>
<httpclient.version>4.5</httpclient.version>

View File

@ -55,12 +55,12 @@
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${bytebuddy.version}</version>
<version>${byte-buddy.version}</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-agent</artifactId>
<version>${bytebuddy.version}</version>
<version>${byte-buddy.version}</version>
</dependency>
<!--Java Docker API Client -->
@ -127,7 +127,6 @@
<scala.version>2.11</scala.version>
<typesafe-akka.version>2.5.11</typesafe-akka.version>
<streamex.version>0.6.5</streamex.version>
<bytebuddy.version>1.7.1</bytebuddy.version>
<docker.version>3.0.14</docker.version>
<caffeine.version>2.5.5</caffeine.version>
<findbugs.version>3.0.2</findbugs.version>

View File

@ -95,14 +95,6 @@
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<properties>

View File

@ -21,16 +21,6 @@
<module>flogger</module>
</modules>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<properties>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
</properties>

View File

@ -147,10 +147,6 @@
<artifactId>maven-source-plugin</artifactId>
<version>${source.plugin.version}</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire.plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
@ -181,7 +177,6 @@
<resources.plugin.version>3.1.0</resources.plugin.version>
<site.plugin.version>3.9.1</site.plugin.version>
<source.plugin.version>3.2.1</source.plugin.version>
<surefire.plugin.version>2.17</surefire.plugin.version>
</properties>
</project>

View File

@ -175,7 +175,6 @@
<log4jdbc.version>2.0.0</log4jdbc.version>
<logback.version>1.2.3</logback.version>
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
<maven.surefire.version>2.22.2</maven.surefire.version>
<maven.compiler.version>3.8.1</maven.compiler.version>
<maven.version>3.8.1</maven.version>
<mysql.version>8.0.19</mysql.version>

View File

@ -66,11 +66,6 @@
<artifactId>guava</artifactId>
<version>${guava.version}</version>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>${byte-buddy.version}</version>
</dependency>
<!-- test scoped -->
<dependency>
@ -97,7 +92,6 @@
<!-- utilities -->
<guava.version>21.0</guava.version>
<byte-buddy.version>1.10.16</byte-buddy.version>
</properties>
</project>

View File

@ -531,7 +531,7 @@
<module>protobuffer</module>
<module>quarkus</module>
<!-- <module>quarkus-extension</module> --> <!-- Module broken, fixing in http://team.baeldung.com/browse/JAVA-4770 -->
<module>quarkus-extension</module>
<module>rabbitmq</module>
<!-- <module>raml</module> --> <!-- Not a maven project -->
@ -992,7 +992,7 @@
<module>protobuffer</module>
<module>quarkus</module>
<!-- <module>quarkus-extension</module> --> <!-- Module broken, fixing in http://team.baeldung.com/browse/JAVA-4770 -->
<module>quarkus-extension</module>
<module>rabbitmq</module>
<!-- <module>raml</module> --> <!-- Not a maven project -->
@ -1357,7 +1357,7 @@
<hamcrest.version>2.2</hamcrest.version>
<hamcrest-all.version>1.3</hamcrest-all.version>
<mockito.version>3.3.0</mockito.version>
<byte-buddy.version>1.10.5</byte-buddy.version>
<byte-buddy.version>1.10.22</byte-buddy.version>
<!-- logging -->
<org.slf4j.version>1.7.30</org.slf4j.version>

View File

@ -27,9 +27,10 @@
<dependencies>
<dependency>
<groupId>com.baeldung.quarkus.liquibase</groupId>
<artifactId>quarkus-liquibase-runtime</artifactId>
<artifactId>runtime</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>

View File

@ -3,6 +3,7 @@
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>
<groupId>com.baeldung.quarkus.liquibase</groupId>
<artifactId>deployment</artifactId>
<name>deployment</name>
@ -30,7 +31,7 @@
</dependency>
<dependency>
<groupId>com.baeldung.quarkus.liquibase</groupId>
<artifactId>quarkus-liquibase-runtime</artifactId>
<artifactId>runtime</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

View File

@ -2,6 +2,7 @@
<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>
<groupId>com.baeldung.quarkus.liquibase</groupId>
<artifactId>runtime</artifactId>
<name>runtime</name>
@ -41,7 +42,7 @@
<goal>extension-descriptor</goal>
</goals>
<configuration>
<deployment>${project.groupId}:quarkus-liquibase-deployment:${project.version}
<deployment>${project.groupId}:deployment:${project.version}
</deployment>
</configuration>
</execution>

View File

@ -97,7 +97,6 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<configuration>
<forkCount>1</forkCount>
<reuseForks>true</reuseForks>
@ -136,7 +135,6 @@
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${surefire-plugin.version}</version>
<executions>
<execution>
<goals>
@ -157,7 +155,6 @@
</profiles>
<properties>
<surefire-plugin.version>2.22.0</surefire-plugin.version>
<quarkus.version>1.7.0.Final</quarkus.version>
<junit-jupiter.version>5.6.0</junit-jupiter.version>
</properties>

View File

@ -150,21 +150,6 @@
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>

View File

@ -142,7 +142,6 @@
<asciidoctor-plugin.version>1.5.6</asciidoctor-plugin.version>
<commons-collections4.version>4.1</commons-collections4.version>
<snippetsDirectory>${project.build.directory}/generated-snippets</snippetsDirectory>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
</properties>
</project>

View File

@ -106,17 +106,8 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
</plugins>
</build>
<properties>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
</properties>
</project>

View File

@ -71,11 +71,6 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<version>1.10.11</version>
</dependency>
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-commons</artifactId>

View File

@ -35,11 +35,6 @@
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-dep</artifactId>
<version>${bytebuddy.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
@ -63,8 +58,6 @@
<spring-boot.version>2.2.6.RELEASE</spring-boot.version>
<spring-cloud-dependencies.version>Hoxton.SR4</spring-cloud-dependencies.version>
<postgresql.version>42.2.10</postgresql.version>
<bytebuddy.version>1.10.10</bytebuddy.version>
</properties>
</project>

View File

@ -45,13 +45,6 @@
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-task-batch</artifactId>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy-dep</artifactId>
<version>${bytebuddy.version}</version>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
@ -70,7 +63,6 @@
<properties>
<start-class>com.baeldung.TaskDemo</start-class>
<bytebuddy.version>1.10.10</bytebuddy.version>
</properties>
</project>

View File

@ -69,18 +69,7 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
</plugin>
</plugins>
</build>
<properties>
<maven.surefire.version>2.22.1</maven.surefire.version>
<annotation-api.version>1.3.2</annotation-api.version>
<spring.boot.version>2.2.2.RELEASE</spring.boot.version>
</properties>

View File

@ -87,18 +87,7 @@
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
</plugin>
</plugins>
</build>
<properties>
<maven.surefire.version>2.22.1</maven.surefire.version>
<annotation-api.version>1.3.2</annotation-api.version>
<spring.boot.version>2.2.2.RELEASE</spring.boot.version>
<guava.version>28.2-jre</guava.version>

View File

@ -25,22 +25,16 @@
<version>${spring-boot-starter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.version}</version>
</plugin>
</plugins>
</build>
<properties>
<spring.version>5.3.3</spring.version>
<spring-boot-starter.version>2.4.2</spring-boot-starter.version>
<maven.surefire.version>2.22.1</maven.surefire.version>
</properties>
</project>

View File

@ -0,0 +1,12 @@
package com.baeldung.component.autoproxying;
import lombok.Getter;
import org.springframework.stereotype.Component;
@Getter
@Component
public class DataCache {
@RandomInt(min = 2, max = 10)
private int group;
private String name;
}

View File

@ -0,0 +1,33 @@
package com.baeldung.component.autoproxying;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Lazy;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Field;
public class EligibleForAutoProxyRandomIntProcessor implements BeanPostProcessor {
private final RandomIntGenerator randomIntGenerator;
@Lazy
public EligibleForAutoProxyRandomIntProcessor(RandomIntGenerator randomIntGenerator) {
this.randomIntGenerator = randomIntGenerator;
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
Field[] fields = bean.getClass().getDeclaredFields();
for (Field field : fields) {
RandomInt injectRandomInt = field.getAnnotation(RandomInt.class);
if (injectRandomInt != null) {
int min = injectRandomInt.min();
int max = injectRandomInt.max();
int randomValue = randomIntGenerator.generate(min, max);
field.setAccessible(true);
ReflectionUtils.setField(field, bean, randomValue);
}
}
return bean;
}
}

View File

@ -0,0 +1,31 @@
package com.baeldung.component.autoproxying;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.util.ReflectionUtils;
import java.lang.reflect.Field;
public class NotEligibleForAutoProxyRandomIntProcessor implements BeanPostProcessor {
private final RandomIntGenerator randomIntGenerator;
public NotEligibleForAutoProxyRandomIntProcessor(RandomIntGenerator randomIntGenerator) {
this.randomIntGenerator = randomIntGenerator;
}
@Override
public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
Field[] fields = bean.getClass().getDeclaredFields();
for (Field field : fields) {
RandomInt injectRandomInt = field.getAnnotation(RandomInt.class);
if (injectRandomInt != null) {
int min = injectRandomInt.min();
int max = injectRandomInt.max();
int randomValue = randomIntGenerator.generate(min, max);
field.setAccessible(true);
ReflectionUtils.setField(field, bean, randomValue);
}
}
return bean;
}
}

View File

@ -0,0 +1,11 @@
package com.baeldung.component.autoproxying;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
@Retention(RetentionPolicy.RUNTIME)
public @interface RandomInt {
int min();
int max();
}

View File

@ -0,0 +1,21 @@
package com.baeldung.component.autoproxying;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import java.util.Random;
@Slf4j
@Component
public class RandomIntGenerator {
private final Random random = new Random();
private final DataCache dataCache;
public RandomIntGenerator(DataCache dataCache) {
this.dataCache = dataCache;
}
public int generate(int min, int max) {
return random.nextInt(max - min) + min;
}
}

View File

@ -0,0 +1,49 @@
package com.baeldung.component.autoproxying;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.ILoggingEvent;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {EligibleForAutoProxyRandomIntProcessor.class, DataCache.class, RandomIntGenerator.class})
public class EligibleForAutoProxyingIntegrationTest {
private static MemoryLogAppender memoryAppender;
private EligibleForAutoProxyRandomIntProcessor randomIntProcessor;
@Autowired
private DataCache dataCache;
@BeforeClass
public static void setup() {
memoryAppender = new MemoryLogAppender();
memoryAppender.setContext((LoggerContext) LoggerFactory.getILoggerFactory());
Logger logger = (Logger) LoggerFactory.getLogger("org.springframework.context");
logger.setLevel(Level.INFO);
logger.addAppender(memoryAppender);
memoryAppender.start();
}
@Test
public void givenAutowireInBeanPostProcessor_whenSpringContextInitialize_thenNotEligibleLogShouldShowAndGroupFieldPopulated() {
List<ILoggingEvent> notEligibleEvents = memoryAppender.search("Bean 'randomIntGenerator' of type [com.baeldung.autoproxying.RandomIntGenerator] " +
"is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)");
assertEquals(0, notEligibleEvents.size());
assertNotEquals(0, dataCache.getGroup());
}
}

View File

@ -0,0 +1,48 @@
package com.baeldung.component.autoproxying;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
public class MemoryLogAppender extends ListAppender<ILoggingEvent> {
public void reset() {
this.list.clear();
}
public boolean contains(String string, Level level) {
return this.list.stream()
.anyMatch(event -> event.getMessage().toString().contains(string)
&& event.getLevel().equals(level));
}
public int countEventsForLogger(String loggerName) {
return (int) this.list.stream()
.filter(event -> event.getLoggerName().contains(loggerName))
.count();
}
public List<ILoggingEvent> search(String string) {
return this.list.stream()
.filter(event -> event.getMessage().toString().contains(string))
.collect(Collectors.toList());
}
public List<ILoggingEvent> search(String string, Level level) {
return this.list.stream()
.filter(event -> event.getMessage().toString().contains(string)
&& event.getLevel().equals(level))
.collect(Collectors.toList());
}
public int getSize() {
return this.list.size();
}
public List<ILoggingEvent> getLoggedEvents() {
return Collections.unmodifiableList(this.list);
}
}

View File

@ -0,0 +1,48 @@
package com.baeldung.component.autoproxying;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
import ch.qos.logback.classic.spi.ILoggingEvent;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.util.List;
import static org.junit.Assert.assertEquals;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {NotEligibleForAutoProxyRandomIntProcessor.class, DataCache.class, RandomIntGenerator.class})
public class NotEligibleForAutoProxyingIntegrationTest {
private static MemoryLogAppender memoryAppender;
private NotEligibleForAutoProxyRandomIntProcessor proxyRandomIntProcessor;
@Autowired
private DataCache dataCache;
@BeforeClass
public static void setup() {
memoryAppender = new MemoryLogAppender();
memoryAppender.setContext((LoggerContext) LoggerFactory.getILoggerFactory());
Logger logger = (Logger) LoggerFactory.getLogger("org.springframework.context");
logger.setLevel(Level.INFO);
logger.addAppender(memoryAppender);
memoryAppender.start();
}
@Test
public void givenAutowireInBeanPostProcessor_whenSpringContextInitialize_thenNotEligibleLogShouldShowAndGroupFieldNotPopulated() {
List<ILoggingEvent> notEligibleEvents = memoryAppender.search("Bean 'randomIntGenerator' of type [com.baeldung.autoproxying.RandomIntGenerator] " +
"is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)");
assertEquals(1, notEligibleEvents.size());
assertEquals(0, dataCache.getGroup());
}
}

View File

@ -184,7 +184,6 @@
<activemq.broker.version>5.10.2</activemq.broker.version>
<activemq.junit.version>5.13.1</activemq.junit.version>
<mockito.version>2.21.0</mockito.version>
<byte-buddy.version>1.8.5</byte-buddy.version>
<maven-dependency-plugin.version>2.8</maven-dependency-plugin.version>
<wildfly-ejb.version>8.2.1.Final</wildfly-ejb.version>
</properties>

View File

@ -131,14 +131,6 @@
<artifactId>json</artifactId>
<version>${json.version}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.surefire</groupId>
<artifactId>surefire-logger-api</artifactId>
<version>${maven-surefire-plugin.version}</version>
<!-- to get around bug https://github.com/junit-team/junit5/issues/1367 -->
<scope>test</scope>
<optional>true</optional>
</dependency>
</dependencies>
<build>
@ -163,7 +155,6 @@
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
<javax.servlet.jsp-api.version>2.3.2-b02</javax.servlet.jsp-api.version>
<javax.servlet-api.version>4.0.0</javax.servlet-api.version>
<hibernate-validator.version>6.0.10.Final</hibernate-validator.version>

View File

@ -35,18 +35,8 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
</plugins>
</build>
<properties>
<junit-jupiter.version>5.4.2</junit-jupiter.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
<junit.vintage.version>5.4.2</junit.vintage.version>
</properties>

View File

@ -152,7 +152,6 @@
<junit-platform.version>1.2.0</junit-platform.version>
<junit-jupiter.version>5.4.2</junit-jupiter.version>
<spring.version>5.0.6.RELEASE</spring.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
</properties>
</project>

View File

@ -105,10 +105,6 @@
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>

View File

@ -18,12 +18,12 @@
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-engine</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<version>${junit-platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
@ -48,17 +48,6 @@
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
@ -79,7 +68,7 @@
<properties>
<junit.jupiter.version>5.2.0</junit.jupiter.version>
<junit.platform.version>1.2.0</junit.platform.version>
<junit-platform.version>1.2.0</junit-platform.version>
<junit.vintage.version>5.2.0</junit.vintage.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
<exec-maven-plugin.version>1.6.0</exec-maven-plugin.version>

View File

@ -73,6 +73,5 @@
<properties>
<testcontainers.version>1.12.2</testcontainers.version>
<maven-surefire-plugin.version>2.21.0</maven-surefire-plugin.version>
</properties>
</project>

View File

@ -80,17 +80,6 @@
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit-platform-surefire-provider.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
@ -117,7 +106,7 @@
<postgresql.version>42.2.6</postgresql.version>
<selenium-remote-driver.version>3.141.59</selenium-remote-driver.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
<junit-platform-surefire-provider.version>1.3.2</junit-platform-surefire-provider.version>
<junit-platform.version>1.3.2</junit-platform.version>
</properties>
</project>

View File

@ -50,16 +50,6 @@
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
</plugins>
</build>
<properties>
<assertj-core.version>3.16.1</assertj-core.version>
<commons-collections4.version>4.4</commons-collections4.version>

View File

@ -382,7 +382,6 @@
<!-- maven plugins -->
<maven-jibx-plugin.version>1.3.1</maven-jibx-plugin.version>
<maven-compiler-plugin.version>3.8.0</maven-compiler-plugin.version>
<maven-surefire-plugin.version>2.22.2</maven-surefire-plugin.version>
</properties>
</project>