Browse Source

move test constants into a class defined in the test tree

master
Stefan Bodewig 6 years ago
parent
commit
d7bafaa19a
12 changed files with 88 additions and 60 deletions
  1. +1
    -0
      src/etc/poms/ant-testutil/pom.xml
  2. +0
    -35
      src/main/org/apache/tools/ant/MagicNames.java
  3. +4
    -4
      src/tests/junit/org/apache/tools/ant/BuildFileRule.java
  4. +4
    -4
      src/tests/junit/org/apache/tools/ant/BuildFileTest.java
  5. +61
    -0
      src/tests/junit/org/apache/tools/ant/MagicTestNames.java
  6. +3
    -2
      src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java
  7. +3
    -3
      src/tests/junit/org/apache/tools/ant/types/PathTest.java
  8. +3
    -3
      src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java
  9. +3
    -3
      src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java
  10. +2
    -2
      src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java
  11. +2
    -2
      src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java
  12. +2
    -2
      src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java

+ 1
- 0
src/etc/poms/ant-testutil/pom.xml View File

@@ -60,6 +60,7 @@
<include>org/apache/tools/ant/AntAssert*</include>
<include>org/apache/tools/ant/BuildFile*</include>
<include>org/apache/tools/ant/FileUtilities*</include>
<include>org/apache/tools/ant/MagicTestNames*</include>
<include>org/apache/tools/ant/util/regexp/RegexpMatcherTest*</include>
<include>org/apache/tools/ant/util/regexp/RegexpTest*</include>
<include>org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest*</include>


+ 0
- 35
src/main/org/apache/tools/ant/MagicNames.java View File

@@ -322,40 +322,5 @@ public final class MagicNames {
*/
public static final String TSTAMP_NOW_ISO = "ant.tstamp.now.iso";

/**
* Magic property that makes unit tests based on BuildFileTest
* or BuildFileRule ignore externally set basedir
* (typically by Surefire/Failsafe)
*
* Value: {@value}
* @since Ant 1.10.6
*/
public static final String TEST_BASEDIR_IGNORE = "ant.test.basedir.ignore";

/**
* Magic property that makes unit tests based on BuildFileTest
* or BuildFileRule use build files in alternative locations
* (relative to "root" directory)
*
* Value: {@value}
* @since Ant 1.10.6
*/
public static final String TEST_ROOT_DIRECTORY = "root";

/**
* Property for ant process ID set in unit tests by BuildFileTest
* or BuildFileRule.
*
* Value: {@value}
*/
public static final String TEST_PROCESS_ID = "ant.processid";

/**
* Property for ant thread name set in unit tests by BuildFileTest
* or BuildFileRule.
*
* Value: {@value}
*/
public static final String TEST_THREAD_NAME = "ant.threadname";
}


+ 4
- 4
src/tests/junit/org/apache/tools/ant/BuildFileRule.java View File

@@ -153,13 +153,13 @@ public class BuildFileRule extends ExternalResource {
logBuffer = new StringBuffer();
fullLogBuffer = new StringBuffer();
project = new Project();
if (Boolean.getBoolean(MagicNames.TEST_BASEDIR_IGNORE)) {
if (Boolean.getBoolean(MagicTestNames.TEST_BASEDIR_IGNORE)) {
System.clearProperty(MagicNames.PROJECT_BASEDIR);
}
project.init();
File antFile = new File(System.getProperty(MagicNames.TEST_ROOT_DIRECTORY), filename);
project.setProperty(MagicNames.TEST_PROCESS_ID, ProcessUtil.getProcessId("<Process>"));
project.setProperty(MagicNames.TEST_THREAD_NAME, Thread.currentThread().getName());
File antFile = new File(System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY), filename);
project.setProperty(MagicTestNames.TEST_PROCESS_ID, ProcessUtil.getProcessId("<Process>"));
project.setProperty(MagicTestNames.TEST_THREAD_NAME, Thread.currentThread().getName());
project.setUserProperty(MagicNames.ANT_FILE, antFile.getAbsolutePath());
project.addBuildListener(new AntTestListener(logLevel));
ProjectHelper.configureProject(project, antFile);


+ 4
- 4
src/tests/junit/org/apache/tools/ant/BuildFileTest.java View File

@@ -327,15 +327,15 @@ public abstract class BuildFileTest extends TestCase {
logBuffer = new StringBuffer();
fullLogBuffer = new StringBuffer();
project = new Project();
if (Boolean.getBoolean(MagicNames.TEST_BASEDIR_IGNORE)) {
if (Boolean.getBoolean(MagicTestNames.TEST_BASEDIR_IGNORE)) {
System.clearProperty(MagicNames.PROJECT_BASEDIR);
}
project.init();
File antFile = new File(System.getProperty(MagicNames.TEST_ROOT_DIRECTORY), filename);
File antFile = new File(System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY), filename);
project.setUserProperty(MagicNames.ANT_FILE, antFile.getAbsolutePath());
// set two new properties to allow to build unique names when running multithreaded tests
project.setProperty(MagicNames.TEST_PROCESS_ID, ProcessUtil.getProcessId("<Process>"));
project.setProperty(MagicNames.TEST_THREAD_NAME, Thread.currentThread().getName());
project.setProperty(MagicTestNames.TEST_PROCESS_ID, ProcessUtil.getProcessId("<Process>"));
project.setProperty(MagicTestNames.TEST_THREAD_NAME, Thread.currentThread().getName());
project.addBuildListener(new AntTestListener(logLevel));
ProjectHelper.configureProject(project, antFile);
}


+ 61
- 0
src/tests/junit/org/apache/tools/ant/MagicTestNames.java View File

@@ -0,0 +1,61 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
package org.apache.tools.ant;

/**
* Magic names used within Ant's tests.
*
* @since Ant 1.10.6
*/
public final class MagicTestNames {
/**
* Magic property that makes unit tests based on BuildFileTest
* or BuildFileRule ignore externally set basedir
* (typically by Surefire/Failsafe)
*
* Value: {@value}
* @since Ant 1.10.6
*/
public static final String TEST_BASEDIR_IGNORE = "ant.test.basedir.ignore";

/**
* Magic property that makes unit tests based on BuildFileTest
* or BuildFileRule use build files in alternative locations
* (relative to "root" directory)
*
* Value: {@value}
* @since Ant 1.10.6
*/
public static final String TEST_ROOT_DIRECTORY = "root";

/**
* Property for ant process ID set in unit tests by BuildFileTest
* or BuildFileRule.
*
* Value: {@value}
*/
public static final String TEST_PROCESS_ID = "ant.processid";

/**
* Property for ant thread name set in unit tests by BuildFileTest
* or BuildFileRule.
*
* Value: {@value}
*/
public static final String TEST_THREAD_NAME = "ant.threadname";
}

+ 3
- 2
src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java View File

@@ -19,6 +19,7 @@
package org.apache.tools.ant.types;

import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.MagicTestNames;
import org.apache.tools.ant.Project;
import org.junit.After;
import org.junit.Before;
@@ -49,8 +50,8 @@ public class CommandlineJavaTest {
@Before
public void setUp() {
project = new Project();
if (System.getProperty(MagicNames.TEST_ROOT_DIRECTORY) != null) {
project.setBasedir(System.getProperty(MagicNames.TEST_ROOT_DIRECTORY));
if (System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY) != null) {
project.setBasedir(System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY));
}
project.setProperty("build.sysclasspath", "ignore");
cloneVm = System.getProperty("ant.build.clonevm");


+ 3
- 3
src/tests/junit/org/apache/tools/ant/types/PathTest.java View File

@@ -23,7 +23,7 @@ import java.nio.file.Paths;
import java.util.Locale;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.MagicTestNames;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.condition.Os;
import org.junit.Before;
@@ -55,8 +55,8 @@ public class PathTest {
@Before
public void setUp() {
project = new Project();
if (System.getProperty(MagicNames.TEST_ROOT_DIRECTORY) != null) {
project.setBasedir(System.getProperty(MagicNames.TEST_ROOT_DIRECTORY));
if (System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY) != null) {
project.setBasedir(System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY));
}
p = new Path(project);
}


+ 3
- 3
src/tests/junit/org/apache/tools/ant/types/XMLCatalogTest.java View File

@@ -28,7 +28,7 @@ import javax.xml.transform.TransformerException;
import javax.xml.transform.sax.SAXSource;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.MagicTestNames;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.util.JAXPUtils;
import org.junit.Before;
@@ -69,8 +69,8 @@ public class XMLCatalogTest {
@Before
public void setUp() {
project = new Project();
if (System.getProperty(MagicNames.TEST_ROOT_DIRECTORY) != null) {
project.setBasedir(System.getProperty(MagicNames.TEST_ROOT_DIRECTORY));
if (System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY) != null) {
project.setBasedir(System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY));
}
// This causes XMLCatalog to print out detailed logging
// messages for debugging


+ 3
- 3
src/tests/junit/org/apache/tools/ant/types/resources/FileResourceTest.java View File

@@ -20,7 +20,7 @@ package org.apache.tools.ant.types.resources;
import java.io.File;
import java.io.IOException;

import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.MagicTestNames;
import org.apache.tools.ant.Project;
import org.junit.Before;
import org.junit.Test;
@@ -37,9 +37,9 @@ public class FileResourceTest {

@Before
public void setUp() throws IOException {
root = (System.getProperty(MagicNames.TEST_ROOT_DIRECTORY) == null)
root = (System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY) == null)
? new File(".").getCanonicalFile()
: new File(System.getProperty(MagicNames.TEST_ROOT_DIRECTORY));
: new File(System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY));
}

@Test


+ 2
- 2
src/tests/junit/org/apache/tools/ant/util/FileUtilsTest.java View File

@@ -23,7 +23,7 @@ import java.io.FileOutputStream;
import java.io.IOException;

import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.MagicTestNames;
import org.apache.tools.ant.taskdefs.condition.Os;
import org.junit.After;
import org.junit.Before;
@@ -51,7 +51,7 @@ public class FileUtilsTest {
public ExpectedException thrown = ExpectedException.none();

private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
private static final String ROOT = System.getProperty(MagicNames.TEST_ROOT_DIRECTORY);
private static final String ROOT = System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY);
private File removeThis;
private String root;



+ 2
- 2
src/tests/junit/org/apache/tools/ant/util/LayoutPreservingPropertiesTest.java View File

@@ -24,7 +24,7 @@ import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.MagicTestNames;
import org.junit.Before;
import org.junit.Test;

@@ -36,7 +36,7 @@ import static org.junit.Assert.assertThat;

public class LayoutPreservingPropertiesTest {

private static final String ROOT = System.getProperty(MagicNames.TEST_ROOT_DIRECTORY);
private static final String ROOT = System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY);

private LayoutPreservingProperties lpf;



+ 2
- 2
src/tests/junit/org/apache/tools/ant/util/ReaderInputStreamTest.java View File

@@ -17,7 +17,7 @@
*/
package org.apache.tools.ant.util;

import org.apache.tools.ant.MagicNames;
import org.apache.tools.ant.MagicTestNames;
import org.junit.Test;

import java.io.ByteArrayOutputStream;
@@ -34,7 +34,7 @@ import static org.junit.Assert.assertEquals;
*/
public class ReaderInputStreamTest {

private static final String ROOT = System.getProperty(MagicNames.TEST_ROOT_DIRECTORY);
private static final String ROOT = System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY);

@Test
public void testSimple() throws Exception {


Loading…
Cancel
Save