Testcase is sensitive to System Property from other tests.

+ Making the testcase for PathFinderTest not discover jetty.base, as
  this value can be obtained from System Property (set from another
  test case) giving false success/failure based on run order.
This commit is contained in:
Joakim Erdfelt 2014-08-19 10:33:04 -07:00
parent c15480644f
commit 7700d1ce53
3 changed files with 55 additions and 3 deletions

View File

@ -130,7 +130,6 @@ public class BaseHome
public BaseHome(CommandLineConfigSource cmdLineSource) throws IOException
{
sources = new ConfigSources();
sources.add(cmdLineSource);
this.homeDir = cmdLineSource.getHomePath();

View File

@ -116,6 +116,50 @@ public class ModulesTest
ConfigurationAssert.assertContainsUnordered("All Modules",expected,moduleNames);
}
/**
* Test loading of only shallow modules, not deep references.
* In other words. ${search-dir}/modules/*.mod should be the only
* valid references, but ${search-dir}/alt/foo/modules/*.mod should
* not be considered valid.
*/
@Test
public void testLoadShallowModulesOnly() throws IOException
{
// Test Env
File homeDir = MavenTestingUtils.getTestResourceDir("jetty home with spaces");
// intentionally setup top level resources dir (as this would have many deep references)
File baseDir = MavenTestingUtils.getTestResourcesDir();
String cmdLine[] = new String[] {"jetty.version=TEST"};
// Configuration
CommandLineConfigSource cmdLineSource = new CommandLineConfigSource(cmdLine);
ConfigSources config = new ConfigSources();
config.add(cmdLineSource);
config.add(new JettyHomeConfigSource(homeDir.toPath()));
config.add(new JettyBaseConfigSource(baseDir.toPath()));
// Initialize
BaseHome basehome = new BaseHome(config);
StartArgs args = new StartArgs();
args.parse(config);
// Test Modules
Modules modules = new Modules(basehome,args);
modules.registerAll();
List<String> moduleNames = new ArrayList<>();
for (Module mod : modules)
{
moduleNames.add(mod.getName());
}
List<String> expected = new ArrayList<>();
expected.add("base");
ConfigurationAssert.assertContainsUnordered("All Modules",expected,moduleNames);
}
@Test
public void testEnableRegexSimple() throws IOException

View File

@ -28,15 +28,22 @@ import java.util.EnumSet;
import java.util.List;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.toolchain.test.TestingDir;
import org.junit.Rule;
import org.junit.Test;
public class PathFinderTest
{
@Rule
public TestingDir testdir = new TestingDir();
@Test
public void testFindInis() throws IOException
{
File homeDir = MavenTestingUtils.getTestResourceDir("hb.1/home");
Path homePath = homeDir.toPath().toAbsolutePath();
File baseDir = testdir.getEmptyDir();
Path basePath = baseDir.toPath().toAbsolutePath();
PathFinder finder = new PathFinder();
finder.setFileMatcher("glob:**/*.ini");
@ -53,7 +60,7 @@ public class PathFinderTest
expected.add("${jetty.home}/start.ini");
FSTest.toOsSeparators(expected);
BaseHome hb = new BaseHome(new String[] { "jetty.home=" + homePath.toString() });
BaseHome hb = new BaseHome(new String[] { "jetty.home=" + homePath.toString(), "jetty.base=" + basePath.toString() });
BaseHomeTest.assertPathList(hb,"Files found",expected,finder);
}
@ -62,6 +69,8 @@ public class PathFinderTest
{
File homeDir = MavenTestingUtils.getTestResourceDir("usecases/home");
Path homePath = homeDir.toPath().toAbsolutePath();
File baseDir = testdir.getEmptyDir();
Path basePath = baseDir.toPath().toAbsolutePath();
List<String> expected = new ArrayList<>();
File modulesDir = new File(homeDir,"modules");
@ -82,7 +91,7 @@ public class PathFinderTest
Files.walkFileTree(modulesPath,EnumSet.of(FileVisitOption.FOLLOW_LINKS),1,finder);
BaseHome hb = new BaseHome(new String[] { "jetty.home=" + homePath.toString() });
BaseHome hb = new BaseHome(new String[] { "jetty.home=" + homePath.toString(), "jetty.base=" + basePath.toString() });
BaseHomeTest.assertPathList(hb,"Files found",expected,finder);
}
}