Skip to content

Commit

Permalink
Merge pull request #20 from pixeltree/refactor_tests
Browse files Browse the repository at this point in the history
Refactor tests
  • Loading branch information
serene authored Nov 18, 2016
2 parents 967d7b8 + 5d5caf3 commit be3c8cd
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.opengis.cite.cdb10.metadataAndVersioning;

import org.testng.Assert;

import java.nio.file.Files;

/**
* Created by martin on 2016-11-18.
*/
public class GeomaticsAttributesXml extends MetadataXmlFile {
public GeomaticsAttributesXml(String path) {
super(path, "Geomatics_Attributes.xml", "Geomatics_Attributes.xsd");
}

public void verifyGeomaticsAttributesXsdFileExists() {
Assert.assertTrue(Files.exists(xsdFile.toPath()),
"If Geomatics_Attributes.xml exists there should be a Geomatics_Attributes.xsd in the Schema folder");
}
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,28 @@
package org.opengis.cite.cdb10.metadataAndVersioning;

import org.opengis.cite.cdb10.CommonFixture;
import org.opengis.cite.cdb10.util.SchemaValidatorErrorHandler;
import org.opengis.cite.cdb10.util.XMLUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
* Created by martin on 2016-09-10.
*/
public class GeomaticsAttributesXmlStructureTests extends CommonFixture {

@Test
public void verifyGeomaticsAttributesXsdFileExists() {
if (geomaticsAttributesXmlExists()) {
Assert.assertTrue(Files.exists(Paths.get(path, "Metadata", "Schema", "Geomatics_Attributes.xsd")),
"If Geomatics_Attributes.xml exists there should be a Geomatics_Attributes.xsd in the Schema folder");
}
public void verifyGeomaticsAttributesXmlFileExists() {
new GeomaticsAttributesXml(path);
}

@Test
public void verifyGeomaticsAttributesXmlAgainstSchema() throws IOException, SAXException {
if (geomaticsAttributesXmlExists() && geomaticsAttributesXsdExists()) {
File xmlFile = Paths.get(path, "Metadata", "Geomatics_Attributes.xml").toFile();
File xsdFile = Paths.get(path, "Metadata", "Schema", "Geomatics_Attributes.xsd").toFile();

SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile);

if (!errorHandler.noErrors()) {
Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages());
}
}
}

private boolean geomaticsAttributesXmlExists() {
return Paths.get(path, "Metadata", "Geomatics_Attributes.xml").toFile().exists();
public void verifyGeomaticsAttributesXsdFileExists() {
new GeomaticsAttributesXml(path).verifyGeomaticsAttributesXsdFileExists();
}

private boolean geomaticsAttributesXsdExists() {
return Paths.get(path, "Metadata", "Schema", "Geomatics_Attributes.xsd").toFile().exists();
@Test
public void verifyGeomaticsAttributesXmlAgainstSchema() throws IOException, SAXException {
new GeomaticsAttributesXml(path).verifyXmlAgainstSchema();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package org.opengis.cite.cdb10.metadataAndVersioning;

import org.testng.Assert;

import java.nio.file.Files;

/**
* Created by martin on 2016-11-10.
*/
public class VendorAttributesXml extends MetadataXmlFile {
public VendorAttributesXml(String path) {
super(path, "Vendor_Attributes.xml", "Vendor_Attributes.xsd");
}

public void verifyVendorAttributesXsdFileExists() {
Assert.assertTrue(Files.exists(xsdFile.toPath()),
"If Vendor_Attributes.xml exists there should be a Vendor_Attributes.xsd in the Schema folder");
}
}
Original file line number Diff line number Diff line change
@@ -1,49 +1,28 @@
package org.opengis.cite.cdb10.metadataAndVersioning;

import org.opengis.cite.cdb10.CommonFixture;
import org.opengis.cite.cdb10.util.SchemaValidatorErrorHandler;
import org.opengis.cite.cdb10.util.XMLUtils;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.xml.sax.SAXException;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
* Created by martin on 2016-09-09.
*/
public class VendorAttributesXmlStructureTests extends CommonFixture {

@Test
public void verifyVendorAttributesXsdFileExists() {
if (vendorAttributesXmlExists()) {
Assert.assertTrue(Files.exists(Paths.get(path, "Metadata", "Schema", "Vendor_Attributes.xsd")),
"If Vendor_Attributes.xml exists there should be a Vendor_Attributes.xsd in the Schema folder");
}
public void verifyVendorAttributesXmlFileExists() {
new VendorAttributesXml(path);
}

@Test
public void verifyVendorAttributesXmlAgainstSchema() throws IOException, SAXException {
if (vendorAttributesXmlExists() && vendorAttributesXsdExists()) {
File xmlFile = Paths.get(path, "Metadata", "Vendor_Attributes.xml").toFile();
File xsdFile = Paths.get(path, "Metadata", "Schema", "Vendor_Attributes.xsd").toFile();

SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile);

if (!errorHandler.noErrors()) {
Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages());
}
}
}

private boolean vendorAttributesXmlExists() {
return Paths.get(path, "Metadata", "Vendor_Attributes.xml").toFile().exists();
public void verifyVendorAttributesXsdFileExists() {
new VendorAttributesXml(path).verifyVendorAttributesXsdFileExists();
}

private boolean vendorAttributesXsdExists() {
return Paths.get(path, "Metadata", "Schema", "Vendor_Attributes.xsd").toFile().exists();
@Test
public void verifyVendorAttributesXmlAgainstSchema() throws IOException, SAXException {
new VendorAttributesXml(path).verifyXmlAgainstSchema();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void verifyVendorAttributesXsdFileExists_DoesNotExist() throws IOExceptio
// setup
Files.createFile(metadataFolder.resolve(Paths.get("Geomatics_Attributes.xml")));
expectedException.expect(AssertionError.class);
expectedException.expectMessage("If Geomatics_Attributes.xml exists there should be a Geomatics_Attributes.xsd in the Schema folder");
expectedException.expectMessage("Metadata directory should contain Geomatics_Attributes.xsd file.");

// execute
testSuite.verifyGeomaticsAttributesXsdFileExists();
Expand Down Expand Up @@ -78,15 +78,19 @@ public void verifyGeomaticsAttributesXmlAgainstSchema_XmlIsNotValid() throws IOE
public void verifyGeomaticsAttributesXmlAgainstSchema_GeomaticsAttributesXmlFileDoesNotExist() throws IOException, SAXException {
// setup
Files.createFile(metadataFolder.resolve(Paths.get("Geomatics_Attributes.xsd")));
expectedException.expect(AssertionError.class);
expectedException.expectMessage("Metadata directory should contain Geomatics_Attributes.xml file.");

// execute
testSuite.verifyGeomaticsAttributesXmlAgainstSchema(); // will not return an assertion error
testSuite.verifyGeomaticsAttributesXmlAgainstSchema();
}

@Test
public void verifyGeomaticsAttributesXmlAgainstSchema_GeomaticsAttributesXsdFileDoesNotExist() throws IOException, SAXException {
// setup
Files.createFile(metadataFolder.resolve(Paths.get("Geomatics_Attributes.xml")));
expectedException.expect(AssertionError.class);
expectedException.expectMessage("Metadata directory should contain Geomatics_Attributes.xsd file.");

// execute
testSuite.verifyGeomaticsAttributesXmlAgainstSchema(); // will not return an assertion error
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ public class VerifyVendorAttributesXmlStructureTests extends MetadataTestFixture
public void verifyVendorAttributesXsdFileExists_DoesNotExist() throws IOException {
// setup
Files.createFile(metadataFolder.resolve(Paths.get("Vendor_Attributes.xml")));

String expectedMessage = "Metadata directory should contain Vendor_Attributes.xsd file.";

expectedException.expect(AssertionError.class);
expectedException.expectMessage("If Vendor_Attributes.xml exists there should be a Vendor_Attributes.xsd in the Schema folder");
expectedException.expectMessage(expectedMessage);

// execute
testSuite.verifyVendorAttributesXsdFileExists();
Expand Down Expand Up @@ -77,15 +80,25 @@ public void verifyVendorAttributesXmlAgainstSchema_VendorAttributesXmlFileDoesNo
// setup
Files.createFile(metadataFolder.resolve(Paths.get("Vendor_Attributes.xsd")));

String expectedMessage = "Metadata directory should contain Vendor_Attributes.xml file.";

expectedException.expect(AssertionError.class);
expectedException.expectMessage(expectedMessage);

// execute
testSuite.verifyVendorAttributesXmlAgainstSchema(); // will not return an assertion error
testSuite.verifyVendorAttributesXmlAgainstSchema();
}

@Test
public void verifyVendorAttributesXmlAgainstSchema_VendorAttributesXsdFileDoesNotExist() throws IOException, SAXException {
// setup
Files.createFile(metadataFolder.resolve(Paths.get("Vendor_Attributes.xml")));

String expectedMessage = "Metadata directory should contain Vendor_Attributes.xsd file.";

expectedException.expect(AssertionError.class);
expectedException.expectMessage(expectedMessage);

// execute
testSuite.verifyVendorAttributesXmlAgainstSchema(); // will not return an assertion error
}
Expand Down

0 comments on commit be3c8cd

Please sign in to comment.