Skip to content

Commit

Permalink
fix setup and teardown methods
Browse files Browse the repository at this point in the history
- Only set static variables from LdpTest setup. Setup is only called
  once even when several classes inherit from LdpTest.
- Change setup and tear down method names so we don't accidentally
  override them in subclasses.

See testng-team/testng#313

Fixes w3c#192
  • Loading branch information
Samuel Padgett committed Oct 7, 2014
1 parent 03f6d3c commit 6162c41
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ public void testContainerSupportsHttpLinkHeader() {

@Test(
groups = {MUST},
enabled = false,
description = "Each LDP Indirect Container MUST also be a conforming "
+ "LDP Direct Container in section 5.4 Direct along "
+ "the following restrictions.")
Expand All @@ -90,7 +89,6 @@ public void testCreateIndirectContainer() {

@Test(
groups = {MUST},
enabled = false,
description = "LDP Indirect Containers MUST contain exactly one "
+ "triple whose subject is the LDPC URI, whose predicate "
+ "is ldp:insertedContentRelation, and whose object ICR "
Expand All @@ -106,7 +104,6 @@ public void testContainsLdpcUri() {

@Test(
groups = {MUST},
enabled = false,
description = "LDPCs whose ldp:insertedContentRelation triple has an "
+ "object other than ldp:MemberSubject and that create new "
+ "resources MUST add a triple to the container whose subject is "
Expand Down
37 changes: 18 additions & 19 deletions src/main/java/org/w3/ldp/testsuite/test/LdpTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,24 +42,29 @@ public abstract class LdpTest {
public final static String SKIPPED_LOG_FILENAME = "skipped.log";

public final static String HTTP_LOG_FILENAME = "http.log";
public static final DateFormat df = DateFormat.getDateTimeInstance();
public final static DateFormat df = DateFormat.getDateTimeInstance();

public final static String DEFAULT_MODEL_TYPE = "http://example.com/ns#Bug";

/*
* The following properties are marked static because commonSetup() is only called
* one time, even if several test classes inherit from LdpTest.
*/

/**
* Alternate content to use on POST requests
*/
private Model postModel;
private static Model postModel;

/**
* For HTTP details on validation failures
*/
protected PrintWriter httpLog;
protected static PrintWriter httpLog;

/**
* For skipped test logging
*/
protected PrintWriter skipLog;
protected static PrintWriter skipLog;

/**
* Builds a model from a turtle representation in a file
Expand Down Expand Up @@ -105,11 +110,16 @@ protected Model readModel(String path) {
*/
@BeforeSuite(alwaysRun = true)
@Parameters({"output", "postTtl", "httpLogging", "skipLogging"})
public void setup(String outputDir, @Optional String postTtl, @Optional String httpLogging, @Optional String skipLogging) throws IOException {
public void commonSetup(String outputDir, @Optional String postTtl, @Optional String httpLogging, @Optional String skipLogging) throws IOException {

/*
* Note: This method is only called one time, even if many classes inherit
* from LdpTest. Don't set non-static members here.
*/

postModel = readModel(postTtl);

File dir = new File(outputDir);
//FileUtils.deleteDirectory(dir);
dir.mkdirs();

if ("true".equals(httpLogging)) {
Expand Down Expand Up @@ -139,7 +149,7 @@ public void setup(String outputDir, @Optional String postTtl, @Optional String h
}

@AfterSuite(alwaysRun = true)
public void tearDown() {
public void commonTearDown() {
if (httpLog != null) {
httpLog.println();
httpLog.flush();
Expand Down Expand Up @@ -184,17 +194,6 @@ public void tearDown() {
*/
public static final String MANUAL = "MANUAL";

private boolean warnings = false;

public boolean getWarnings() {
return warnings;
}

/**
* If true, log HTTP request and response details on errors.
*/
protected boolean httpLogging = false;

/**
* Build a base RestAssured {@link com.jayway.restassured.specification.RequestSpecification}.
*
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/org/w3/ldp/testsuite/test/MemberResourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@ public MemberResourceTest(@Optional String auth) throws IOException {
super(auth);
}

/*
* Creates a resource to test if there's no memberResource test parameter.
*/
@Parameters({"memberResource", "directContainer", "indirectContainer", "basicContainer", "memberTtl"})
@BeforeSuite(alwaysRun = true)
public void setup(@Optional String memberResource, @Optional String directContainer,
public void createTestResource(@Optional String memberResource, @Optional String directContainer,
@Optional String indirectContainer, @Optional String basicContainer,
@Optional String memberTtl) {
// If resource is defined, use that. Otherwise, fall back to creating one from one of the containers.
Expand Down Expand Up @@ -89,8 +92,12 @@ protected String getResourceUri() {
return memberResource;
}

/*
* Deletes the test resource to clean up if it's wasn't provided using the
* memberResource test parameter.
*/
@AfterSuite(alwaysRun = true)
public void tearDown() {
public void deleteTestResource() {
// If container isn't null, we created the resource ourselves. To clean up, delete the resource.
if (container != null) {
buildBaseRequestSpecification().delete(memberResource);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/w3/ldp/testsuite/test/NonRDFSourceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public NonRDFSourceTest(@Optional String auth) throws IOException {

@Parameters({ "basicContainer", "directContainer", "indirectContainer" })
@BeforeSuite(alwaysRun = true)
public void setup(@Optional String basicContainer, @Optional String directContainer, @Optional String indirectContainer) {
public void createTestResource(@Optional String basicContainer, @Optional String directContainer, @Optional String indirectContainer) {
if (StringUtils.isNotBlank(basicContainer)) {
container = basicContainer;
} else if (StringUtils.isNotBlank(directContainer)) {
Expand Down Expand Up @@ -88,7 +88,7 @@ public void setup(@Optional String basicContainer, @Optional String directContai
}

@AfterSuite(alwaysRun = true)
public void tearDown() {
public void deleteTestResource() {
if (nonRdfSource != null) {
buildBaseRequestSpecification().delete(nonRdfSource);
}
Expand Down

0 comments on commit 6162c41

Please sign in to comment.