Kirk Rader  1.0-SNAPSHOT
Classes
Package us.rader.logging.demo

Manual integration tests for the us.rader.logging package. More...

Classes

class  Demo
 Integration test / demo. More...
 
class  MockClass1
 Mock class used in tests. More...
 
class  MockClass2
 Mock class used in tests. More...
 
class  MockClass3
 Mock class used in tests. More...
 

Detailed Description

Manual integration tests for the us.rader.logging package.

Here is the POM file for the logging-demo module:

<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>us.rader.logging</groupId>
<artifactId>logging</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<artifactId>logging-demo</artifactId>
<name>logging-demo</name>
<description>Integration test / demo of logging API</description>
<distributionManagement>
<site>
<id>site</id>
<name>Site</name>
<!-- TODO: What should the site URL be? -->
<url>scp://rader.us/docs/${project.parent.artifactId}/${project.parent.version}/${project.artifactId}/</url>
</site>
</distributionManagement>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>status-codes</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>trace</artifactId>
<version>${project.version}</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.sonarsource.java</groupId>
<artifactId>sonar-jacoco-listeners</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>us.rader.logging.demo.Demo</mainClass>
<!-- custom classpath layout required due to bugs in Maven -->
<classpathLayoutType>custom</classpathLayoutType>
<customClasspathLayout>lib/$${artifact.artifactId}-$${artifact.version}$${dashClassifier?}.$${artifact.extension}</customClasspathLayout>
<addClasspath>true</addClasspath>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
</plugin>
<plugin>
<groupId>us.rader.logging</groupId>
<artifactId>status-codes-maven-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration>
<classes>${project.basedir}/target/classes</classes>
<resource>${project.basedir}/target/classes/logmessages.properties</resource>
<aspects>
<param>us.rader.logging.tracing.TraceAll</param>
</aspects>
<weaverExclusions>
<param>us.rader.logging.tracing.*</param>
</weaverExclusions>
</configuration>
<executions>
<execution>
<phase>process-classes</phase>
<goals>
<goal>extract</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Note in particular the invocation of us.rader.examples:status-codes-maven-plugin for the process-classes phase of the build life cycle.

The logic in us.rader.logging.demo.Demo::main relies on the fact that a Java properties file with the appropriate definitions will have been created and embedded in the JAR build artifact.

Specifically, the extract mojo in us.rader.logging.statuscodes.maven.StatusCodesMojo uses us.rader.logging.statuscodes.maven.DynamicClassLoader to scan the compiled class files and include the output of us.rader.logging.statuscodes.MonitoredStatusCodeInfoList::toProperties as a resource in the output of the build. The us.rader.logging.demo.Demo::main command-line entry point then uses us.rader.logging.statuscodes.MonitoredStatusCodeInfoList::loadLogMessages and us.rader.logging.statuscodes.MonitoredStatusCodeInfoList::log to write messages whose format and content was determined at build time by extracting information contained in custom us.rader.logging.statuscodes.MonitoredComponent and us.rader.logging.statuscodes.MonitoredStatusCode annotations.