Skip to content

Commit

Permalink
NCL5715 Refactor integration test code to be simpler
Browse files Browse the repository at this point in the history
  • Loading branch information
rnc committed Dec 17, 2020
1 parent aabdff9 commit 3172469
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,38 +198,24 @@ static void runLikeInvoker( String workingDir, String url )
static Integer runCli( List<String> args, Map<String, String> params, String workingDir )
{
ArrayList<String> arguments = new ArrayList<>( args );
if (!params.isEmpty() )
{
Collections.addAll( arguments, toJavaParams( params ).split( "\\s+" ) );
}
boolean argsContainsFile = false;
for ( String s : args)
{
if ( s.startsWith( "--file" ) )
{
argsContainsFile = true;
break;
}
}
if ( ! argsContainsFile )
Collections.addAll( arguments, toJavaParams( params ).split( "\\s+" ) );
arguments.add( "--log=" + workingDir + File.separator + "build.log" );

if ( args.stream().noneMatch( s -> s.startsWith( "--file" ) ) )
{
arguments.add( "--log=" + workingDir + File.separator + "build.log" );
arguments.add( "--file=" + workingDir + File.separator + "pom.xml" );
}
logger.info( "Invoking CLI with {} ", arguments );
Cli cli = new Cli();
int result = cli.run( arguments.toArray( new String[0] ) );

// Close unirest client down to prevent any hanging.
// Unirest.shutdown();
int result = new Cli().run( arguments.toArray( new String[0] ) );

// This is a bit of a hack. The CLI, if log-to-file is enabled resets the logging. As we don't fork and run
// in the same process this means we need to reset it back again. The benefit of not forking is a simpler test
// harness and it saves time when running the tests.
final ch.qos.logback.classic.Logger root = (ch.qos.logback.classic.Logger) LoggerFactory.getLogger( org.slf4j.Logger.ROOT_LOGGER_NAME );

root.detachAndStopAllAppenders();

LoggerContext loggerContext = (LoggerContext) LoggerFactory.getILoggerFactory();
loggerContext.reset();

PatternLayoutEncoder ple = new PatternLayoutEncoder();
ple.setPattern( "[%t] %level %logger{32} - %msg%n" );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
import org.commonjava.maven.ext.io.rest.rule.MockServer;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;

import java.io.File;
Expand All @@ -31,10 +31,10 @@

public class CircularIntegrationTest
{
private static AddSuffixJettyHandler handler = new AddSuffixJettyHandler( "/", null );
private final AddSuffixJettyHandler handler = new AddSuffixJettyHandler( "/", null );

@ClassRule
public static MockServer mockServer = new MockServer( handler );
@Rule
public MockServer mockServer = new MockServer( handler );

@BeforeClass
public static void setUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
import static org.commonjava.maven.ext.integrationtest.ITestUtils.runLikeInvoker;
import static org.commonjava.maven.ext.integrationtest.ITestUtils.runMaven;

@SuppressWarnings( "ConstantConditions" )
@RunWith( Parameterized.class )
public class DefaultCliIntegrationTest
{
private static final Logger LOGGER = LoggerFactory.getLogger( DefaultCliIntegrationTest.class );
private static final Logger logger = LoggerFactory.getLogger( DefaultCliIntegrationTest.class );

@Parameters( name = "{0}" )
public static Collection<Object[]> getFiles()
Expand Down Expand Up @@ -98,7 +98,7 @@ public void testIntegration()
{
testRelativeLocation = ITestUtils.LOCATION_REWRITE.get( this.testRelativeLocation );
}
LOGGER.info ("Testing {}", testRelativeLocation);
logger.info ("Testing {}", testRelativeLocation);
String test = getDefaultTestLocation( testRelativeLocation );
runLikeInvoker( test, null );
}
Expand All @@ -119,7 +119,7 @@ static boolean setupExists( File test )
{
if ( t2.exists() && dir.exists() && dir.listFiles() != null && dir.listFiles().length > 0)
{
LOGGER.info( "Setup has already been run for {}", test);
logger.info( "Setup has already been run for {}", test);
return true;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.commonjava.maven.ext.io.rest.handler.StaticResourceHandler;
import org.commonjava.maven.ext.io.rest.rule.MockServer;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -35,10 +35,10 @@ public class GroovyIntegrationTest
{
private static final Logger LOGGER = LoggerFactory.getLogger( DefaultCliIntegrationTest.class );

private static StaticResourceHandler handler = new StaticResourceHandler( "src/it/setup/depMgmt2/POMModifier.groovy" );
private final StaticResourceHandler handler = new StaticResourceHandler( "src/it/setup/depMgmt2/POMModifier.groovy" );

@ClassRule
public static MockServer mockServer = new MockServer( handler );
@Rule
public MockServer mockServer = new MockServer( handler );

@BeforeClass
public static void setUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.commonjava.maven.ext.io.rest.rule.MockServer;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -37,10 +37,10 @@ public class RESTIntegrationTest
{
private static final Logger LOGGER = LoggerFactory.getLogger( DefaultCliIntegrationTest.class );

private static AddSuffixJettyHandler handler = new AddSuffixJettyHandler( "/", null );
private final AddSuffixJettyHandler handler = new AddSuffixJettyHandler( "/", null );

@ClassRule
public static MockServer mockServer = new MockServer( handler );
@Rule
public MockServer mockServer = new MockServer( handler );

@BeforeClass
public static void setUp()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import org.commonjava.maven.ext.core.state.VersioningState;
import org.commonjava.maven.ext.io.rest.handler.AddSuffixJettyHandler;
import org.commonjava.maven.ext.io.rest.rule.MockServer;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -49,12 +48,12 @@
*/
public class ResultJsonFileTest
{
@ClassRule
public static MockServer mockServer = new MockServer( new AddSuffixJettyHandler("/", AddSuffixJettyHandler.DEFAULT_SUFFIX) );
private final File workingDirectory = new File ( System.getProperty( "user.dir" ) );

private static final ObjectMapper MAPPER = new ObjectMapper();
private final ObjectMapper MAPPER = new ObjectMapper();

private static final File workingDirectory = new File ( System.getProperty( "user.dir" ) );
@Rule
public MockServer mockServer = new MockServer( new AddSuffixJettyHandler("/", AddSuffixJettyHandler.DEFAULT_SUFFIX) );

@Rule
public TemporaryFolder tmpFolderRule = new TemporaryFolder();
Expand Down

0 comments on commit 3172469

Please sign in to comment.