From 14f37f16768f3998a05c2ec7c8ab723a6c683c7d Mon Sep 17 00:00:00 2001 From: martinechtner Date: Tue, 20 Sep 2016 11:08:01 -0600 Subject: [PATCH 01/20] added DOCTYPE to testng file --- src/main/resources/org/opengis/cite/cdb10/testng.xml | 1 + 1 file changed, 1 insertion(+) diff --git a/src/main/resources/org/opengis/cite/cdb10/testng.xml b/src/main/resources/org/opengis/cite/cdb10/testng.xml index dee71af..c41b712 100644 --- a/src/main/resources/org/opengis/cite/cdb10/testng.xml +++ b/src/main/resources/org/opengis/cite/cdb10/testng.xml @@ -1,4 +1,5 @@ + From 8697cddb7346422fad452efa0776bacbcb33b5eb Mon Sep 17 00:00:00 2001 From: martinechtner Date: Tue, 20 Sep 2016 14:37:28 -0600 Subject: [PATCH 02/20] refactor tests into an object so we can verify the xml file exists --- .../CDBAttributesXml.java | 128 ++++++++++++++++++ .../CDBAttributesXmlStructureTests.java | 107 ++------------- .../VerifyCDBAttributesXmlStructureTests.java | 29 ++-- 3 files changed, 160 insertions(+), 104 deletions(-) create mode 100644 src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXml.java diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXml.java new file mode 100644 index 0000000..1bdb9b9 --- /dev/null +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXml.java @@ -0,0 +1,128 @@ +package org.opengis.cite.cdb10.metadataAndVersioning; + +import org.opengis.cite.cdb10.util.SchemaValidatorErrorHandler; +import org.opengis.cite.cdb10.util.XMLUtils; +import org.testng.Assert; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.SAXException; + +import java.io.File; +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; + +/** + * Created by martin on 2016-09-20. + */ +public class CDBAttributesXml { + private File xmlFile; + private File xsdFile; + + public CDBAttributesXml(String path) { + xmlFile = Paths.get(path, "Metadata", "CDB_Attributes.xml").toFile(); + xsdFile = Paths.get(path, "Metadata", "Schema", "Vector_Attributes.xsd").toFile(); + + verifyXmlFileExists(); + } + + private void verifyXmlFileExists(){ + Assert.assertTrue(Files.exists(xmlFile.toPath()), "Metadata directory should contain CDB_Attributes.xml file."); + } + + public void verifyXmlAgainstSchema() throws SAXException, IOException { + SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile); + + if (!errorHandler.noErrors()) { + Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages()); + } + } + + public void verifyCodeIsAnInteger() { + NodeList nodeList = XMLUtils.getNodeList("//Attribute", xmlFile.toPath()); + + ArrayList values = new ArrayList<>(); + + for (int i = 0; i < nodeList.getLength(); i++) { + Node currentItem = nodeList.item(i); + values.add(currentItem.getAttributes().getNamedItem("code").getNodeValue()); + } + + for (String value : values) { + Assert.assertTrue(value.matches("^\\d+$"), + String.format("CDB_Attributes.xml attribute code " + + "should be an integer. Code '%s' is not valid.", value)); + } + } + + public void verifySymbolIsUnique() { + NodeList nodeList = XMLUtils.getNodeList("//Attribute", xmlFile.toPath()); + + ArrayList symbols = new ArrayList<>(); + + for (int i = 0; i < nodeList.getLength(); i++) { + Node currentItem = nodeList.item(i); + symbols.add(currentItem.getAttributes().getNamedItem("symbol").getNodeValue()); + } + + for (String symbol : symbols) { + Assert.assertEquals(Collections.frequency(symbols, symbol), 1, + String.format("CDB_Attributes.xml element Attribute should " + + "have unique symbols. Symbol '%s' is not unique.", symbol)); + } + } + + public void verifyValueHasAValidType() { + NodeList nodeList = XMLUtils.getNodeList("//Value/Type", xmlFile.toPath()); + + ArrayList types = new ArrayList<>(); + List VALID_TYPES = Arrays.asList("Text", "Numeric", "Boolean"); + + for (int i = 0; i < nodeList.getLength(); i++) { + Node currentItem = nodeList.item(i); + types.add(currentItem.getTextContent()); + } + + for (String type : types) { + Assert.assertTrue(VALID_TYPES.contains(type), + String.format("CDB_Attributes.xml element Type should have a value of " + + "'Text', 'Numeric' or 'Boolean'. Type '%s' is not valid.", type)); + } + } + + public void verifyScalerCodeIsValid() { + NodeList nodeList = XMLUtils.getNodeList("//Scalers/Scaler", xmlFile.toPath()); + + ArrayList values = new ArrayList<>(); + + for (int i = 0; i < nodeList.getLength(); i++) { + Node currentItem = nodeList.item(i); + values.add(currentItem.getAttributes().getNamedItem("code").getNodeValue()); + } + + for (String value : values) { + Assert.assertTrue(value.matches("^[1-9]\\d*$"), + String.format("CDB_Attributes.xml Scaler code should be a positive integer. Code '%s' is not valid.", value)); + } + } + + public void verifyUnitCodeIsValid() { + NodeList nodeList = XMLUtils.getNodeList("//Units/Unit", xmlFile.toPath()); + + ArrayList values = new ArrayList<>(); + + for (int i = 0; i < nodeList.getLength(); i++) { + Node currentItem = nodeList.item(i); + values.add(currentItem.getAttributes().getNamedItem("code").getNodeValue()); + } + + for (String value : values) { + Assert.assertTrue(value.matches("^[1-9]\\d*$"), + String.format("CDB_Attributes.xml Unit code should be a positive integer. Code '%s' is not valid.", value)); + } + } +} diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXmlStructureTests.java index 9904a9a..74de804 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXmlStructureTests.java @@ -1,22 +1,10 @@ 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.w3c.dom.Node; -import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import java.io.File; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; /** * Created by martin on 2016-09-08. @@ -25,105 +13,36 @@ public class CDBAttributesXmlStructureTests extends CommonFixture { @Test public void verifyCDBAttributesXmlFileExists() { - Assert.assertTrue(Files.exists(Paths.get(path, "Metadata", "CDB_Attributes.xml")), - "Metadata directory should contain CDB_Attributes.xml file."); + new CDBAttributesXml(path); } @Test public void verifyCDBAttributesXmlAgainstSchema() throws IOException, SAXException { - File xmlFile = Paths.get(path, "Metadata", "CDB_Attributes.xml").toFile(); - File xsdFile = Paths.get(path, "Metadata", "Schema", "Vector_Attributes.xsd").toFile(); - - SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile); - - if (!errorHandler.noErrors()) { - Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages()); - } + new CDBAttributesXml(path).verifyXmlAgainstSchema(); } @Test - public void verifyCodeIsAnInteger() { - NodeList nodeList = XMLUtils.getNodeList("//Attribute", Paths.get(path, "Metadata", "CDB_Attributes.xml")); - - ArrayList values = new ArrayList<>(); - - for (int i = 0; i < nodeList.getLength(); i++) { - Node currentItem = nodeList.item(i); - values.add(currentItem.getAttributes().getNamedItem("code").getNodeValue()); - } - - for (String value : values) { - Assert.assertTrue(value.matches("^\\d+$"), - String.format("CDB_Attributes.xml attribute code should be an integer. Code '%s' is not valid.", value)); - } + public void verifyCDBAttributesXmlCodeIsAnInteger() { + new CDBAttributesXml(path).verifyCodeIsAnInteger(); } @Test - public void verifySymbolIsUnique() { - NodeList nodeList = XMLUtils.getNodeList("//Attribute", Paths.get(path, "Metadata", "CDB_Attributes.xml")); - - ArrayList symbols = new ArrayList<>(); - - for (int i = 0; i < nodeList.getLength(); i++) { - Node currentItem = nodeList.item(i); - symbols.add(currentItem.getAttributes().getNamedItem("symbol").getNodeValue()); - } - - for (String symbol : symbols) { - Assert.assertEquals(Collections.frequency(symbols, symbol), 1, - String.format("CDB_Attributes.xml element Attribute should have unique symbols. Symbol '%s' is not unique.", symbol)); - } + public void verifyCDBAttributesXmlSymbolIsUnique() { + new CDBAttributesXml(path).verifySymbolIsUnique(); } @Test - public void verifyValueHasAValidType() { - NodeList nodeList = XMLUtils.getNodeList("//Value/Type", Paths.get(path, "Metadata", "CDB_Attributes.xml")); - - ArrayList types = new ArrayList<>(); - List VALID_TYPES = Arrays.asList("Text", "Numeric", "Boolean"); - - for (int i = 0; i < nodeList.getLength(); i++) { - Node currentItem = nodeList.item(i); - types.add(currentItem.getTextContent()); - } - - for (String type : types) { - Assert.assertTrue(VALID_TYPES.contains(type), - String.format("CDB_Attributes.xml element Type should have a value of " + - "'Text', 'Numeric' or 'Boolean'. Type '%s' is not valid.", type)); - } + public void verifyCDBAttributesXmlValueHasAValidType() { + new CDBAttributesXml(path).verifyValueHasAValidType(); } @Test - public void verifyScalerCodeIsValid() { - NodeList nodeList = XMLUtils.getNodeList("//Scalers/Scaler", Paths.get(path, "Metadata", "CDB_Attributes.xml")); - - ArrayList values = new ArrayList<>(); - - for (int i = 0; i < nodeList.getLength(); i++) { - Node currentItem = nodeList.item(i); - values.add(currentItem.getAttributes().getNamedItem("code").getNodeValue()); - } - - for (String value : values) { - Assert.assertTrue(value.matches("^[1-9]\\d*$"), - String.format("CDB_Attributes.xml Scaler code should be a positive integer. Code '%s' is not valid.", value)); - } + public void verifyCDBAttributesXmlScalerCodeIsValid() { + new CDBAttributesXml(path).verifyScalerCodeIsValid(); } - public void verifyUnitCodeIsValid() { - NodeList nodeList = XMLUtils.getNodeList("//Units/Unit", Paths.get(path, "Metadata", "CDB_Attributes.xml")); - - ArrayList values = new ArrayList<>(); - - for (int i = 0; i < nodeList.getLength(); i++) { - Node currentItem = nodeList.item(i); - values.add(currentItem.getAttributes().getNamedItem("code").getNodeValue()); - } - - for (String value : values) { - Assert.assertTrue(value.matches("^[1-9]\\d*$"), - String.format("CDB_Attributes.xml Unit code should be a positive integer. Code '%s' is not valid.", value)); - } + @Test + public void verifyCDBAttributesXmlUnitCodeIsValid() { + new CDBAttributesXml(path).verifyUnitCodeIsValid(); } } diff --git a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyCDBAttributesXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyCDBAttributesXmlStructureTests.java index 80f077a..b2db45c 100644 --- a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyCDBAttributesXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyCDBAttributesXmlStructureTests.java @@ -58,6 +58,15 @@ public void verifyCDBAttributesXmlAgainstSchema_XmlIsValid() throws IOException, testSuite.verifyCDBAttributesXmlAgainstSchema(); } + @Test + public void verifyCDBAttributesXmlAgainstSchema_FileDoesNotExist() throws IOException, SAXException { + expectedException.expect(AssertionError.class); + expectedException.expectMessage("Metadata directory should contain CDB_Attributes.xml file."); + + // execute + testSuite.verifyCDBAttributesXmlAgainstSchema(); + } + @Test public void verifyCDBAttributesXmlAgainstSchema_XmlIsNotValid() throws IOException, SAXException { // setup @@ -84,7 +93,7 @@ public void verifyCodeIsAnInteger_CodeIsAnInteger() throws IOException { Files.copy(XSD_FILE, schemaFolder.resolve("Vector_Attributes.xsd"), REPLACE_EXISTING); // execute - testSuite.verifyCodeIsAnInteger(); + testSuite.verifyCDBAttributesXmlCodeIsAnInteger(); } @Test @@ -99,7 +108,7 @@ public void verifyCodeIsAnInteger_CodeIsNotAnInteger() throws IOException { expectedException.expectMessage(expectedMessage); // execute - testSuite.verifyCodeIsAnInteger(); + testSuite.verifyCDBAttributesXmlCodeIsAnInteger(); } @Test @@ -109,7 +118,7 @@ public void verifySymbolIsUnique_SymbolIsUnique() throws IOException { Files.copy(XSD_FILE, schemaFolder.resolve("Vector_Attributes.xsd"), REPLACE_EXISTING); // execute - testSuite.verifySymbolIsUnique(); + testSuite.verifyCDBAttributesXmlSymbolIsUnique(); } @Test @@ -125,7 +134,7 @@ public void verifySymbolIsUnique_SymbolIsNotUnique() throws IOException { expectedException.expectMessage(expectedMessage); // execute - testSuite.verifySymbolIsUnique(); + testSuite.verifyCDBAttributesXmlSymbolIsUnique(); } @Test @@ -135,7 +144,7 @@ public void verifyValueHasAValidType_IsValid() throws IOException { Files.copy(XSD_FILE, schemaFolder.resolve("Vector_Attributes.xsd"), REPLACE_EXISTING); // execute - testSuite.verifyValueHasAValidType(); + testSuite.verifyCDBAttributesXmlValueHasAValidType(); } @Test @@ -151,7 +160,7 @@ public void verifyValueHasAValidType_IsNotValid() throws IOException { expectedException.expectMessage(expectedMessage); // execute - testSuite.verifyValueHasAValidType(); + testSuite.verifyCDBAttributesXmlValueHasAValidType(); } @Test @@ -161,7 +170,7 @@ public void verifyScalerCodeIsValid_IsValid() throws IOException { Files.copy(XSD_FILE, schemaFolder.resolve("Vector_Attributes.xsd"), REPLACE_EXISTING); // execute - testSuite.verifyScalerCodeIsValid(); + testSuite.verifyCDBAttributesXmlScalerCodeIsValid(); } @Test @@ -177,7 +186,7 @@ public void verifyScalerCodeIsValid_IsNotValid() throws IOException { expectedException.expectMessage(expectedMessage); // execute - testSuite.verifyScalerCodeIsValid(); + testSuite.verifyCDBAttributesXmlScalerCodeIsValid(); } @Test @@ -187,7 +196,7 @@ public void verifyUnitCodeIsValid_IsValid() throws IOException { Files.copy(XSD_FILE, schemaFolder.resolve("Vector_Attributes.xsd"), REPLACE_EXISTING); // execute - testSuite.verifyUnitCodeIsValid(); + testSuite.verifyCDBAttributesXmlUnitCodeIsValid(); } @Test @@ -203,6 +212,6 @@ public void verifyUnitCodeIsValid_IsNotValid() throws IOException { expectedException.expectMessage(expectedMessage); // execute - testSuite.verifyUnitCodeIsValid(); + testSuite.verifyCDBAttributesXmlUnitCodeIsValid(); } } From 396956a497c1c5c1b8c417d0a379ceab3e95ef45 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Tue, 20 Sep 2016 14:49:53 -0600 Subject: [PATCH 03/20] refactor test into an object so we can verify the xml file exists --- .../ConfigurationXml.java | 38 +++++++++++++++++++ .../ConfigurationXmlStructureTests.java | 12 +----- 2 files changed, 40 insertions(+), 10 deletions(-) create mode 100644 src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXml.java diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXml.java new file mode 100644 index 0000000..31813f8 --- /dev/null +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXml.java @@ -0,0 +1,38 @@ +package org.opengis.cite.cdb10.metadataAndVersioning; + +import org.opengis.cite.cdb10.util.SchemaValidatorErrorHandler; +import org.opengis.cite.cdb10.util.XMLUtils; +import org.testng.Assert; +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-20. + */ +public class ConfigurationXml { + private File xmlFile; + private File xsdFile; + + public ConfigurationXml(String path) { + xmlFile = Paths.get(path, "Metadata", "Configuration.xml").toFile(); + xsdFile = Paths.get(path, "Metadata", "Schema", "Configuration.xsd").toFile(); + + verifyXmlFileExists(); + } + + private void verifyXmlFileExists() { + Assert.assertTrue(Files.exists(xmlFile.toPath()), "Metadata directory should contain Configuration.xml file."); + } + + public void verifyAgainstSchema() throws IOException, SAXException { + SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile); + + if (!errorHandler.noErrors()) { + Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages()); + } + } +} diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java index 56e446b..4c880ba 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java @@ -19,19 +19,11 @@ public class ConfigurationXmlStructureTests extends CommonFixture { @Test public void verifyConfigurationXmlFileExists() { - Assert.assertTrue(Files.exists(Paths.get(path, "Metadata", "Configuration.xml")), - "Metadata directory should contain Configuration.xml file."); + new ConfigurationXml(path); } @Test public void verifyConfigurationXmlAgainstSchema() throws IOException, SAXException { - File xmlFile = Paths.get(path, "Metadata", "Configuration.xml").toFile(); - File xsdFile = Paths.get(path, "Metadata", "Schema", "Configuration.xsd").toFile(); - - SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile); - - if (!errorHandler.noErrors()) { - Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages()); - } + new ConfigurationXml(path).verifyAgainstSchema(); } } From 111794cc4b5a9e4d1900c5b86003829f4c8ffeac Mon Sep 17 00:00:00 2001 From: martinechtner Date: Tue, 20 Sep 2016 15:31:35 -0600 Subject: [PATCH 04/20] create a super class to DRY code --- .../CDBAttributesXml.java | 27 +------------ .../ConfigurationXml.java | 31 +-------------- .../ConfigurationXmlStructureTests.java | 2 +- .../cdb10/metadataAndVersioning/XmlFile.java | 38 +++++++++++++++++++ 4 files changed, 43 insertions(+), 55 deletions(-) create mode 100644 src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/XmlFile.java diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXml.java index 1bdb9b9..570691c 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXml.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXml.java @@ -1,16 +1,10 @@ package org.opengis.cite.cdb10.metadataAndVersioning; -import org.opengis.cite.cdb10.util.SchemaValidatorErrorHandler; import org.opengis.cite.cdb10.util.XMLUtils; import org.testng.Assert; import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import org.xml.sax.SAXException; -import java.io.File; -import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; @@ -19,27 +13,10 @@ /** * Created by martin on 2016-09-20. */ -public class CDBAttributesXml { - private File xmlFile; - private File xsdFile; +public class CDBAttributesXml extends XmlFile { public CDBAttributesXml(String path) { - xmlFile = Paths.get(path, "Metadata", "CDB_Attributes.xml").toFile(); - xsdFile = Paths.get(path, "Metadata", "Schema", "Vector_Attributes.xsd").toFile(); - - verifyXmlFileExists(); - } - - private void verifyXmlFileExists(){ - Assert.assertTrue(Files.exists(xmlFile.toPath()), "Metadata directory should contain CDB_Attributes.xml file."); - } - - public void verifyXmlAgainstSchema() throws SAXException, IOException { - SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile); - - if (!errorHandler.noErrors()) { - Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages()); - } + super(path, "CDB_Attributes.xml", "Vector_Attributes.xsd"); } public void verifyCodeIsAnInteger() { diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXml.java index 31813f8..79bc837 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXml.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXml.java @@ -1,38 +1,11 @@ package org.opengis.cite.cdb10.metadataAndVersioning; -import org.opengis.cite.cdb10.util.SchemaValidatorErrorHandler; -import org.opengis.cite.cdb10.util.XMLUtils; -import org.testng.Assert; -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-20. */ -public class ConfigurationXml { - private File xmlFile; - private File xsdFile; +public class ConfigurationXml extends XmlFile { public ConfigurationXml(String path) { - xmlFile = Paths.get(path, "Metadata", "Configuration.xml").toFile(); - xsdFile = Paths.get(path, "Metadata", "Schema", "Configuration.xsd").toFile(); - - verifyXmlFileExists(); - } - - private void verifyXmlFileExists() { - Assert.assertTrue(Files.exists(xmlFile.toPath()), "Metadata directory should contain Configuration.xml file."); - } - - public void verifyAgainstSchema() throws IOException, SAXException { - SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile); - - if (!errorHandler.noErrors()) { - Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages()); - } + super(path, "Configuration.xml", "Configuration.xsd"); } } diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java index 4c880ba..023eff3 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java @@ -24,6 +24,6 @@ public void verifyConfigurationXmlFileExists() { @Test public void verifyConfigurationXmlAgainstSchema() throws IOException, SAXException { - new ConfigurationXml(path).verifyAgainstSchema(); + new ConfigurationXml(path).verifyXmlAgainstSchema(); } } diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/XmlFile.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/XmlFile.java new file mode 100644 index 0000000..7ffee93 --- /dev/null +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/XmlFile.java @@ -0,0 +1,38 @@ +package org.opengis.cite.cdb10.metadataAndVersioning; + +import org.opengis.cite.cdb10.util.SchemaValidatorErrorHandler; +import org.opengis.cite.cdb10.util.XMLUtils; +import org.testng.Assert; +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-20. + */ +public class XmlFile { + protected File xmlFile; + protected File xsdFile; + + public XmlFile(String path, String xmlFileName, String xsdFileName) { + xmlFile = Paths.get(path, "Metadata", xmlFileName).toFile(); + xsdFile = Paths.get(path, "Metadata", "Schema", xsdFileName).toFile(); + + verifyXmlFileExists(); + } + + protected void verifyXmlFileExists() { + Assert.assertTrue(Files.exists(xmlFile.toPath()), String.format("Metadata directory should contain %s file.", xmlFile.getName())); + } + + public void verifyXmlAgainstSchema() throws IOException, SAXException { + SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile); + + if (!errorHandler.noErrors()) { + Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages()); + } + } +} From b6b25a80d50aeff69a271c6577b580f995f90014 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Tue, 20 Sep 2016 15:42:33 -0600 Subject: [PATCH 05/20] refactor to use an object --- .../metadataAndVersioning/DefaultsXml.java | 91 +++++++++++++++++++ .../DefaultsXmlStructureTests.java | 79 +--------------- 2 files changed, 96 insertions(+), 74 deletions(-) create mode 100644 src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXml.java diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXml.java new file mode 100644 index 0000000..914d92a --- /dev/null +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXml.java @@ -0,0 +1,91 @@ +package org.opengis.cite.cdb10.metadataAndVersioning; + +import org.opengis.cite.cdb10.util.XMLUtils; +import org.testng.Assert; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import java.util.*; + +/** + * Created by martin on 2016-09-20. + */ +public class DefaultsXml extends XmlFile { + public DefaultsXml(String path) { + super(path, "Defaults.xml", "Defaults.xsd"); + } + + public void verifyElementR_W_TypeHasValidValues() { + NodeList nodeList = XMLUtils.getNodeList("//R_W_Type", xmlFile.toPath()); + + ArrayList values = new ArrayList<>(); + List VALID_VALUES = Arrays.asList("W", "R"); + + for (int i = 0; i < nodeList.getLength(); i++) { + Node currentItem = nodeList.item(i); + values.add(currentItem.getTextContent()); + } + + for (String value : values) { + Assert.assertTrue(VALID_VALUES.contains(value), + String.format("Defaults.xml element R_W_Type should " + + "have a value of R or W. Value '%s' is not valid.", value)); + } + } + + public void verifyNameIsUniqueForEachDataset() { + for (String datasetValue : getDatasetValues()) { + assertNamesAreUnique(datasetValue); + } + } + + public void verifyElementTypeHasValidValue() { + NodeList nodeList = XMLUtils.getNodeList("//Type", xmlFile.toPath()); + + ArrayList values = new ArrayList<>(); + List VALID_VALUES = Arrays.asList("string", "integer", "float"); + + for (int i = 0; i < nodeList.getLength(); i++) { + Node currentItem = nodeList.item(i); + values.add(currentItem.getTextContent()); + } + + for (String value : values) { + Assert.assertTrue(VALID_VALUES.contains(value), + String.format("Defaults.xml element Type should have a value of " + + "'float', 'integer' or 'string'. Value '%s' is not valid.", value)); + } + } + + private HashSet getDatasetValues() { + NodeList datasetNodes = XMLUtils.getNodeList("//Dataset", xmlFile.toPath()); + + HashSet datasetValues = new HashSet<>(); + + for (int i = 0; i < datasetNodes.getLength(); i++) { + Node currentItem = datasetNodes.item(i); + datasetValues.add(currentItem.getTextContent()); + } + return datasetValues; + } + + private ArrayList collectNameNodesWithDatasetValue(String datasetValue) { + NodeList nameNodes = XMLUtils.getNodeList("//Default_Value[Dataset/text() = \"" + datasetValue + "\"]/Name", xmlFile.toPath()); + + ArrayList names = new ArrayList<>(); + for (int i = 0; i < nameNodes.getLength(); i++) { + names.add(nameNodes.item(i).getTextContent()); + } + return names; + } + + private void assertNamesAreUnique(String datasetValue) { + ArrayList names = collectNameNodesWithDatasetValue(datasetValue); + + for (String name : names) { + Assert.assertEquals(Collections.frequency(names, name), 1, + String.format("Defaults.xml element Name should be " + + "unique under each Dataset. '%s' is not unique.", name)); + } + } +} diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXmlStructureTests.java index e3fb0db..b4f1489 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXmlStructureTests.java @@ -20,95 +20,26 @@ public class DefaultsXmlStructureTests extends CommonFixture { @Test public void verifyDefaultsXmlFileExists() { - Assert.assertTrue(Files.exists(Paths.get(path, "Metadata", "Defaults.xml")), - "Metadata directory should contain Defaults.xml file."); + new DefaultsXml(path); } @Test public void verifyDefaultsXmlAgainstSchema() throws IOException, SAXException { - File xmlFile = Paths.get(path, "Metadata", "Defaults.xml").toFile(); - File xsdFile = Paths.get(path, "Metadata", "Schema", "Defaults.xsd").toFile(); - - SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile); - - if (!errorHandler.noErrors()) { - Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages()); - } + new DefaultsXml(path).verifyXmlAgainstSchema(); } @Test public void verifyDefaultsXmlElementR_W_TypeHasValidValues() { - NodeList nodeList = XMLUtils.getNodeList("//R_W_Type", Paths.get(path, "Metadata", "Defaults.xml")); - - ArrayList values = new ArrayList<>(); - List VALID_VALUES = Arrays.asList("W", "R"); - - for (int i = 0; i < nodeList.getLength(); i++) { - Node currentItem = nodeList.item(i); - values.add(currentItem.getTextContent()); - } - - for (String value : values) { - Assert.assertTrue(VALID_VALUES.contains(value), - String.format("Defaults.xml element R_W_Type should have a value of R or W. Value '%s' is not valid.", value)); - } + new DefaultsXml(path).verifyElementR_W_TypeHasValidValues(); } @Test public void verifyDefaultsXmlNameIsUniqueForEachDataset() { - for (String datasetValue : getDatasetValues()) { - assertNamesAreUnique(datasetValue); - } + new DefaultsXml(path).verifyNameIsUniqueForEachDataset(); } @Test public void verifyDefaultsXmlElementTypeHasValidValue() { - NodeList nodeList = XMLUtils.getNodeList("//Type", Paths.get(path, "Metadata", "Defaults.xml")); - - ArrayList values = new ArrayList<>(); - List VALID_VALUES = Arrays.asList("string", "integer", "float"); - - for (int i = 0; i < nodeList.getLength(); i++) { - Node currentItem = nodeList.item(i); - values.add(currentItem.getTextContent()); - } - - for (String value : values) { - Assert.assertTrue(VALID_VALUES.contains(value), - String.format("Defaults.xml element Type should have a value of " + - "'float', 'integer' or 'string'. Value '%s' is not valid.", value)); - } + new DefaultsXml(path).verifyElementTypeHasValidValue(); } - - private HashSet getDatasetValues() { - NodeList datasetNodes = XMLUtils.getNodeList("//Dataset", Paths.get(path, "Metadata", "Defaults.xml")); - - HashSet datasetValues = new HashSet<>(); - - for (int i = 0; i < datasetNodes.getLength(); i++) { - Node currentItem = datasetNodes.item(i); - datasetValues.add(currentItem.getTextContent()); - } - return datasetValues; - } - - private ArrayList collectNameNodesWithDatasetValue(String datasetValue) { - NodeList nameNodes = XMLUtils.getNodeList("//Default_Value[Dataset/text() = \"" + datasetValue + "\"]/Name", Paths.get(path, "Metadata", "Defaults.xml")); - - ArrayList names = new ArrayList<>(); - for (int i = 0; i < nameNodes.getLength(); i++) { - names.add(nameNodes.item(i).getTextContent()); - } - return names; - } - - private void assertNamesAreUnique(String datasetValue) { - ArrayList names = collectNameNodesWithDatasetValue(datasetValue); - - for (String name : names) { - Assert.assertEquals(Collections.frequency(names, name), 1, - String.format("Defaults.xml element Name should be unique under each Dataset. '%s' is not unique.", name)); - } - } - } From 4d34b2a32f56727939a9a8a4d322ca261fdbb102 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Tue, 20 Sep 2016 16:03:41 -0600 Subject: [PATCH 06/20] refactor to use an object --- .../metadataAndVersioning/LightsXml.java | 46 +++++++++++++++++++ .../LightsXmlStructureTests.java | 35 ++------------ 2 files changed, 50 insertions(+), 31 deletions(-) create mode 100644 src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXml.java diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXml.java new file mode 100644 index 0000000..564ff9e --- /dev/null +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXml.java @@ -0,0 +1,46 @@ +package org.opengis.cite.cdb10.metadataAndVersioning; + +import org.opengis.cite.cdb10.util.XMLUtils; +import org.testng.Assert; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; + +/** + * Created by martin on 2016-09-20. + */ +public class LightsXml extends XmlFile { + public LightsXml(String path) { + super(path, "Lights.xml", "Lights.xsd"); + } + + public void verifyHasUniqueCodes() { + NodeList nodeList = XMLUtils.getNodeList("//Light", xmlFile.toPath()); + + ArrayList codes = new ArrayList<>(); + + for (int i = 0; i < nodeList.getLength(); i++) { + Node currentItem = nodeList.item(i); + codes.add(currentItem.getAttributes().getNamedItem("code").getNodeValue()); + } + + for (String code : codes) { + Assert.assertEquals(Collections.frequency(codes, code), 1, + String.format("Lights.xml element Light should have unique codes. Code '%s' is not unique.", code)); + } + } + + public void verifyCodesAreWithinRange() { + NodeList nodeList = XMLUtils.getNodeList("//Light", xmlFile.toPath()); + + for (int i = 0; i < nodeList.getLength(); i++) { + Node currentItem = nodeList.item(i); + int key = Integer.parseInt(currentItem.getAttributes().getNamedItem("code").getNodeValue()); + + Assert.assertTrue((key >= 0) && (key <= 9999), "Lights.xml element Light should have a code from 0 - 9999 inclusive."); + } + } +} diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXmlStructureTests.java index 4ab1694..edaddd0 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXmlStructureTests.java @@ -23,48 +23,21 @@ public class LightsXmlStructureTests extends CommonFixture { @Test public void verifyLightsXmlFileExists() { - Assert.assertTrue(Files.exists(Paths.get(path, "Metadata", "Lights.xml")), "Metadata directory should contain Lights.xml file."); + new LightsXml(path); } @Test public void verifyLightsXmlFileAgainstSchema() throws IOException, SAXException { - File xmlFile = Paths.get(path, "Metadata", "Lights.xml").toFile(); - File xsdFile = Paths.get(path, "Metadata", "Schema", "Lights.xsd").toFile(); - - SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile); - - if (!errorHandler.noErrors()) { - Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages()); - } + new LightsXml(path).verifyXmlAgainstSchema(); } @Test public void verifyLightsXmlHasUniqueCodes() { - NodeList nodeList = XMLUtils.getNodeList("//Light", Paths.get(path, "Metadata", "Lights.xml")); - - ArrayList codes = new ArrayList<>(); - - for (int i = 0; i < nodeList.getLength(); i++) { - Node currentItem = nodeList.item(i); - codes.add(currentItem.getAttributes().getNamedItem("code").getNodeValue()); - } - - for (String code : codes) { - Assert.assertEquals(Collections.frequency(codes, code), 1, - String.format("Lights.xml element Light should have unique codes. Code '%s' is not unique.", code)); - } + new LightsXml(path).verifyHasUniqueCodes(); } @Test public void verifyLightsXmlCodesAreWithinRange() { - NodeList nodeList = XMLUtils.getNodeList("//Light", Paths.get(path, "Metadata", "Lights.xml")); - - for (int i = 0; i < nodeList.getLength(); i++) { - Node currentItem = nodeList.item(i); - int key = Integer.parseInt(currentItem.getAttributes().getNamedItem("code").getNodeValue()); - - Assert.assertTrue((key >= 0) && (key <= 9999), "Lights.xml element Light should have a code from 0 - 9999 inclusive."); - } + new LightsXml(path).verifyCodesAreWithinRange(); } - } From 84ac64cdf377ac2dc9e287acf58081c0373303b1 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Tue, 20 Sep 2016 16:08:38 -0600 Subject: [PATCH 07/20] rename superclass --- .../cite/cdb10/metadataAndVersioning/CDBAttributesXml.java | 2 +- .../cite/cdb10/metadataAndVersioning/ConfigurationXml.java | 2 +- .../opengis/cite/cdb10/metadataAndVersioning/DefaultsXml.java | 2 +- .../opengis/cite/cdb10/metadataAndVersioning/LightsXml.java | 3 +-- .../{XmlFile.java => MetadataXmlFile.java} | 4 ++-- 5 files changed, 6 insertions(+), 7 deletions(-) rename src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/{XmlFile.java => MetadataXmlFile.java} (91%) diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXml.java index 570691c..b6f518f 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXml.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXml.java @@ -13,7 +13,7 @@ /** * Created by martin on 2016-09-20. */ -public class CDBAttributesXml extends XmlFile { +public class CDBAttributesXml extends MetadataXmlFile { public CDBAttributesXml(String path) { super(path, "CDB_Attributes.xml", "Vector_Attributes.xsd"); diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXml.java index 79bc837..252b3c9 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXml.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXml.java @@ -3,7 +3,7 @@ /** * Created by martin on 2016-09-20. */ -public class ConfigurationXml extends XmlFile { +public class ConfigurationXml extends MetadataXmlFile { public ConfigurationXml(String path) { super(path, "Configuration.xml", "Configuration.xsd"); diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXml.java index 914d92a..2f76d86 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXml.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXml.java @@ -10,7 +10,7 @@ /** * Created by martin on 2016-09-20. */ -public class DefaultsXml extends XmlFile { +public class DefaultsXml extends MetadataXmlFile { public DefaultsXml(String path) { super(path, "Defaults.xml", "Defaults.xsd"); } diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXml.java index 564ff9e..42cae40 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXml.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXml.java @@ -5,14 +5,13 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; /** * Created by martin on 2016-09-20. */ -public class LightsXml extends XmlFile { +public class LightsXml extends MetadataXmlFile { public LightsXml(String path) { super(path, "Lights.xml", "Lights.xsd"); } diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/XmlFile.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java similarity index 91% rename from src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/XmlFile.java rename to src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java index 7ffee93..f935a12 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/XmlFile.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java @@ -13,11 +13,11 @@ /** * Created by martin on 2016-09-20. */ -public class XmlFile { +public class MetadataXmlFile { protected File xmlFile; protected File xsdFile; - public XmlFile(String path, String xmlFileName, String xsdFileName) { + public MetadataXmlFile(String path, String xmlFileName, String xsdFileName) { xmlFile = Paths.get(path, "Metadata", xmlFileName).toFile(); xsdFile = Paths.get(path, "Metadata", "Schema", xsdFileName).toFile(); From 7877380c386a3311fe507acdac47404094ce4c72 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Tue, 20 Sep 2016 16:18:50 -0600 Subject: [PATCH 08/20] refactor to a object --- .../metadataAndVersioning/MaterialsXml.java | 61 +++++++++++++++++++ .../MaterialsXmlStructureTests.java | 48 ++------------- .../MetadataXmlFile.java | 2 +- 3 files changed, 67 insertions(+), 44 deletions(-) create mode 100644 src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXml.java diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXml.java new file mode 100644 index 0000000..cb2428a --- /dev/null +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXml.java @@ -0,0 +1,61 @@ +package org.opengis.cite.cdb10.metadataAndVersioning; + +import org.opengis.cite.cdb10.util.XMLUtils; +import org.testng.Assert; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Collections; + +/** + * Created by martin on 2016-09-20. + */ +public class MaterialsXml extends MetadataXmlFile { + public MaterialsXml(String path) { + super(path, "Materials.xml", "Base_Material_Table.xsd"); + } + + public void verifyElementNameIsUnique() { + ArrayList names = getNameValues(); + for (String name : names) { + Assert.assertEquals(Collections.frequency(names, name), 1, + String.format("Materials.xml element Name should be unique. '%s' is not unique.", name)); + } + } + + public void verifyAllBaseMaterialElementsHaveAChildNodeName() { + NodeList baseMaterialNodes = XMLUtils.getNodeList("//Base_Material[not(Name)]", xmlFile.toPath()); + Assert.assertEquals(baseMaterialNodes.getLength(), 0, "Materials.xml element Base_Material requires a child element Name."); + } + + public void verifyBaseMaterialNameIsValid() { + ArrayList names = getNameValues(); + + ArrayList invalidNames = new ArrayList<>(); + + for (String name : names) { + if(!name.matches("^BM_[a-zA-Z0-9_-]{0,29}")) { + invalidNames.add(name); + } + } + + Assert.assertEquals(invalidNames.size(), 0, + String.format("Materials.xml element Name is always in format \"BM__*\", " + + "has a maximum of 32 characters, and can only contain letters, digits, " + + "underscores, and hyphens. %s do not conform", invalidNames.toString())); + } + + private ArrayList getNameValues() { + NodeList nameNodes = XMLUtils.getNodeList("//Base_Material/Name", xmlFile.toPath()); + + ArrayList nameValues = new ArrayList<>(); + + for (int i = 0; i < nameNodes.getLength(); i++) { + Node currentItem = nameNodes.item(i); + nameValues.add(currentItem.getTextContent()); + } + return nameValues; + } +} diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXmlStructureTests.java index beeb488..9384df1 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXmlStructureTests.java @@ -23,64 +23,26 @@ public class MaterialsXmlStructureTests extends CommonFixture { @Test public void verifyMaterialsXmlFileExists() { - Assert.assertTrue(Files.exists(Paths.get(path, "Metadata", "Materials.xml")), - "Metadata directory should contain Materials.xml file."); + new MaterialsXml(path); } @Test public void verifyMaterialsXmlAgainstSchema() throws IOException, SAXException { - File xmlFile = Paths.get(path, "Metadata", "Materials.xml").toFile(); - File xsdFile = Paths.get(path, "Metadata", "Schema", "Base_Material_Table.xsd").toFile(); - - SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile); - - if (!errorHandler.noErrors()) { - Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages()); - } + new MaterialsXml(path).verifyXmlAgainstSchema(); } @Test public void verifyMaterialsXmlElementNameIsUnique() { - ArrayList names = getNameValues(); - for (String name : names) { - Assert.assertEquals(Collections.frequency(names, name), 1, - String.format("Materials.xml element Name should be unique. '%s' is not unique.", name)); - } + new MaterialsXml(path).verifyElementNameIsUnique(); } @Test public void verifyMaterialsXmlAllBaseMaterialElementsHaveAChildNodeName() { - NodeList baseMaterialNodes = XMLUtils.getNodeList("//Base_Material[not(Name)]", Paths.get(path, "Metadata", "Materials.xml")); - Assert.assertEquals(baseMaterialNodes.getLength(), 0, "Materials.xml element Base_Material requires a child element Name."); + new MaterialsXml(path).verifyAllBaseMaterialElementsHaveAChildNodeName(); } @Test public void verifyMaterialsXmlBaseMaterialNameIsValid() { - ArrayList names = getNameValues(); - - ArrayList invalidNames = new ArrayList<>(); - - for (String name : names) { - if(!name.matches("^BM_[a-zA-Z0-9_-]{0,29}")) { - invalidNames.add(name); - } - } - - Assert.assertEquals(invalidNames.size(), 0, - String.format("Materials.xml element Name is always in format \"BM__*\", " + - "has a maximum of 32 characters, and can only contain letters, digits, " + - "underscores, and hyphens. %s do not conform", invalidNames.toString())); - } - - private ArrayList getNameValues() { - NodeList nameNodes = XMLUtils.getNodeList("//Base_Material/Name", Paths.get(path, "Metadata", "Materials.xml")); - - ArrayList nameValues = new ArrayList<>(); - - for (int i = 0; i < nameNodes.getLength(); i++) { - Node currentItem = nameNodes.item(i); - nameValues.add(currentItem.getTextContent()); - } - return nameValues; + new MaterialsXml(path).verifyBaseMaterialNameIsValid(); } } diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java index f935a12..873555f 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java @@ -13,7 +13,7 @@ /** * Created by martin on 2016-09-20. */ -public class MetadataXmlFile { +public abstract class MetadataXmlFile { protected File xmlFile; protected File xsdFile; From 4a1ba41f2a04e5dd77c3240c9e108cf1cbc27662 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Tue, 20 Sep 2016 16:20:13 -0600 Subject: [PATCH 09/20] optimize imports --- .../ConfigurationXmlStructureTests.java | 6 ------ .../DefaultsXmlStructureTests.java | 8 -------- .../metadataAndVersioning/LightsXmlStructureTests.java | 10 ---------- .../cite/cdb10/metadataAndVersioning/MaterialsXml.java | 1 - 4 files changed, 25 deletions(-) diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java index 023eff3..10ae73f 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java @@ -1,16 +1,10 @@ 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-07. diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXmlStructureTests.java index b4f1489..5f13de2 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXmlStructureTests.java @@ -1,18 +1,10 @@ package org.opengis.cite.cdb10.metadataAndVersioning; import org.opengis.cite.cdb10.CommonFixture; -import org.opengis.cite.cdb10.util.*; -import org.testng.Assert; import org.testng.annotations.Test; -import org.w3c.dom.Node; -import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import java.io.File; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.*; /** * Created by martin on 2016-09-03. diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXmlStructureTests.java index edaddd0..347d326 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXmlStructureTests.java @@ -1,20 +1,10 @@ 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.w3c.dom.Node; -import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import java.io.File; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Collections; /** * Created by martin on 2016-09-01. diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXml.java index cb2428a..c1122ea 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXml.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXml.java @@ -5,7 +5,6 @@ import org.w3c.dom.Node; import org.w3c.dom.NodeList; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.Collections; From 287a10e6568b0cec07cddf7c0889a270a016e4a3 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Tue, 20 Sep 2016 16:23:40 -0600 Subject: [PATCH 10/20] refactor to an object --- .../ModelComponentsXml.java | 10 ++++++++++ .../ModelComponentsXmlStructureTests.java | 18 ++---------------- 2 files changed, 12 insertions(+), 16 deletions(-) create mode 100644 src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ModelComponentsXml.java diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ModelComponentsXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ModelComponentsXml.java new file mode 100644 index 0000000..505612f --- /dev/null +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ModelComponentsXml.java @@ -0,0 +1,10 @@ +package org.opengis.cite.cdb10.metadataAndVersioning; + +/** + * Created by martin on 2016-09-20. + */ +public class ModelComponentsXml extends MetadataXmlFile { + public ModelComponentsXml(String path) { + super(path, "Model_Components.xml", "Model_Components.xsd"); + } +} diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ModelComponentsXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ModelComponentsXmlStructureTests.java index 68018c7..0623adc 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ModelComponentsXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ModelComponentsXmlStructureTests.java @@ -1,16 +1,10 @@ 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-02. @@ -19,19 +13,11 @@ public class ModelComponentsXmlStructureTests extends CommonFixture { @Test public void verifyModelComponentsXmlFileExists() { - Assert.assertTrue(Files.exists(Paths.get(path, "Metadata", "Model_Components.xml")), - "Metadata directory should contain Model_Components.xml file."); + new ModelComponentsXml(path); } @Test public void verifyModelComponentsXmlAgainstSchema() throws IOException, SAXException { - File xmlFile = Paths.get(path, "Metadata", "Model_Components.xml").toFile(); - File xsdFile = Paths.get(path, "Metadata", "Schema", "Model_Components.xsd").toFile(); - - SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile); - - if (!errorHandler.noErrors()) { - Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages()); - } + new ModelComponentsXml(path).verifyXmlAgainstSchema(); } } From 2d5654439f21e5233122229a54146586984bfa6b Mon Sep 17 00:00:00 2001 From: martinechtner Date: Tue, 20 Sep 2016 16:30:44 -0600 Subject: [PATCH 11/20] Refactor Version XML specifications to object --- .../metadataAndVersioning/VersionXml.java | 45 +++++++++++++++++++ .../VersionXmlStructureTests.java | 45 ++----------------- 2 files changed, 49 insertions(+), 41 deletions(-) create mode 100644 src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VersionXml.java diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VersionXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VersionXml.java new file mode 100644 index 0000000..944de53 --- /dev/null +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VersionXml.java @@ -0,0 +1,45 @@ +package org.opengis.cite.cdb10.metadataAndVersioning; + +import org.opengis.cite.cdb10.util.XMLUtils; +import org.testng.Assert; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +/** + * Created by martin on 2016-09-20. + */ +public class VersionXml extends MetadataXmlFile { + public VersionXml(String path) { + super(path, "Version.xml", "Version.xsd"); + } + + public void verifyHasSpecificationElement() { + NodeList nodeList = XMLUtils.getNodeList("//Specification", xmlFile.toPath()); + + if (nodeList.getLength() == 0) { + Assert.fail("Version.xml Specification element is mandatory the element was not found."); + } + } + + public void verifySpecificationVersionIsValid() { + NodeList nodeList = XMLUtils.getNodeList("//Specification", xmlFile.toPath()); + + ArrayList values = new ArrayList<>(); + List VALID_VALUES = Arrays.asList("3.0", "3.1", "3.2"); + + for (int i = 0; i < nodeList.getLength(); i++) { + Node currentItem = nodeList.item(i); + values.add(currentItem.getAttributes().getNamedItem("version").getNodeValue()); + } + + for (String value : values) { + Assert.assertTrue(VALID_VALUES.contains(value), + String.format("Version.xml Specification elements attribute version can have values " + + "of '3.0', '3.1', '3.1'. Value '%s' is not valid.", value)); + } + } +} diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VersionXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VersionXmlStructureTests.java index ad13ab0..bf589a3 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VersionXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VersionXmlStructureTests.java @@ -1,21 +1,10 @@ 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.w3c.dom.Node; -import org.w3c.dom.NodeList; import org.xml.sax.SAXException; -import java.io.File; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; /** * Created by martin on 2016-09-06. @@ -24,47 +13,21 @@ public class VersionXmlStructureTests extends CommonFixture { @Test public void verifyVersionXmlFileExists() { - Assert.assertTrue(Files.exists(Paths.get(path, "Metadata", "Version.xml")), - "Metadata directory should contain Version.xml file."); + new VersionXml(path); } @Test public void verifyVersionXmlAgainstSchema() throws IOException, SAXException { - File xmlFile = Paths.get(path, "Metadata", "Version.xml").toFile(); - File xsdFile = Paths.get(path, "Metadata", "Schema", "Version.xsd").toFile(); - - SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile); - - if (!errorHandler.noErrors()) { - Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages()); - } + new VersionXml(path).verifyXmlAgainstSchema(); } @Test public void verifyVersionXmlHasSpecificationElement() { - NodeList nodeList = XMLUtils.getNodeList("//Specification", Paths.get(path, "Metadata", "Version.xml")); - - if (nodeList.getLength() == 0) { - Assert.fail("Version.xml Specification element is mandatory the element was not found."); - } + new VersionXml(path).verifyHasSpecificationElement(); } @Test public void verifyVersionXmlSpecificationVersionIsValid() { - NodeList nodeList = XMLUtils.getNodeList("//Specification", Paths.get(path, "Metadata", "Version.xml")); - - ArrayList values = new ArrayList<>(); - List VALID_VALUES = Arrays.asList("3.0", "3.1", "3.2"); - - for (int i = 0; i < nodeList.getLength(); i++) { - Node currentItem = nodeList.item(i); - values.add(currentItem.getAttributes().getNamedItem("version").getNodeValue()); - } - - for (String value : values) { - Assert.assertTrue(VALID_VALUES.contains(value), - String.format("Version.xml Specification elements attribute version can have values " + - "of '3.0', '3.1', '3.1'. Value '%s' is not valid.", value)); - } + new VersionXml(path).verifySpecificationVersionIsValid(); } } From fd14bc642da71166c2dd3d220efed5b48815156b Mon Sep 17 00:00:00 2001 From: martinechtner Date: Tue, 20 Sep 2016 16:52:32 -0600 Subject: [PATCH 12/20] Validate that a corresponding xsd file exists --- .../metadataAndVersioning/MetadataXmlFile.java | 3 ++- .../VerifyCDBAttributesXmlStructureTests.java | 13 +++++++++++++ .../VerifyConfigurationXmlStructureTests.java | 1 + .../VerifyDefaultsXmlStructureTests.java | 1 + .../VerifyLightsXmlStructureTests.java | 6 ++++++ .../VerifyMaterialsXmlStructureTests.java | 7 +++++++ .../VerifyModelComponentsXmlStructureTests.java | 1 + .../VerifyVersionXmlStructureTests.java | 1 + 8 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java index 873555f..ea79661 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java @@ -24,8 +24,9 @@ public MetadataXmlFile(String path, String xmlFileName, String xsdFileName) { verifyXmlFileExists(); } - protected void verifyXmlFileExists() { + private void verifyXmlFileExists() { Assert.assertTrue(Files.exists(xmlFile.toPath()), String.format("Metadata directory should contain %s file.", xmlFile.getName())); + Assert.assertTrue(Files.exists(xsdFile.toPath()), String.format("Metadata directory should contain %s file.", xsdFile.getName())); } public void verifyXmlAgainstSchema() throws IOException, SAXException { diff --git a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyCDBAttributesXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyCDBAttributesXmlStructureTests.java index b2db45c..a9070c1 100644 --- a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyCDBAttributesXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyCDBAttributesXmlStructureTests.java @@ -43,6 +43,7 @@ public void verifyCDBAttributesXmlExists_DoesNotExist() throws IOException { public void verifyCDBAttributesXmlExists_DoesExist() throws IOException { // setup Files.createFile(metadataFolder.resolve(Paths.get("CDB_Attributes.xml"))); + Files.createFile(schemaFolder.resolve(Paths.get("Vector_Attributes.xsd"))); // execute testSuite.verifyCDBAttributesXmlFileExists(); @@ -96,6 +97,18 @@ public void verifyCodeIsAnInteger_CodeIsAnInteger() throws IOException { testSuite.verifyCDBAttributesXmlCodeIsAnInteger(); } + @Test + public void verifyCodeIsAnInteger_XsdFileDoesNotExist() throws IOException { + // setup + Files.copy(VALID_FILE, metadataFolder.resolve("CDB_Attributes.xml"), REPLACE_EXISTING); + + expectedException.expect(AssertionError.class); + expectedException.expectMessage("Metadata directory should contain Vector_Attributes.xsd file."); + + // execute + testSuite.verifyCDBAttributesXmlCodeIsAnInteger(); + } + @Test public void verifyCodeIsAnInteger_CodeIsNotAnInteger() throws IOException { // setup diff --git a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyConfigurationXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyConfigurationXmlStructureTests.java index dfdd29b..8de9e32 100644 --- a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyConfigurationXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyConfigurationXmlStructureTests.java @@ -38,6 +38,7 @@ public void verifyConfigurationXmlExists_DoesNotExist() throws IOException { public void verifyConfigurationXmlExists_DoesExist() throws IOException { // setup Files.createFile(metadataFolder.resolve(Paths.get("Configuration.xml"))); + Files.createFile(schemaFolder.resolve(Paths.get("Configuration.xsd"))); // execute testSuite.verifyConfigurationXmlFileExists(); diff --git a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyDefaultsXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyDefaultsXmlStructureTests.java index d01187d..c46c56a 100644 --- a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyDefaultsXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyDefaultsXmlStructureTests.java @@ -42,6 +42,7 @@ public void verifyDefaultsXmlExists_DoesNotExist() throws IOException { public void verifyDefaultsXmlExists_DoesExist() throws IOException { // setup Files.createFile(metadataFolder.resolve(Paths.get("Defaults.xml"))); + Files.createFile(schemaFolder.resolve(Paths.get("Defaults.xsd"))); // execute testSuite.verifyDefaultsXmlFileExists(); diff --git a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyLightsXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyLightsXmlStructureTests.java index 49d3aab..bd3760c 100644 --- a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyLightsXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyLightsXmlStructureTests.java @@ -41,6 +41,7 @@ public void verifyLightsXmlExists_DoesNotExist() throws IOException { public void verifyLightsXmlExists_DoesExist() throws IOException { // setup Files.createFile(metadataFolder.resolve(Paths.get("Lights.xml"))); + Files.createFile(schemaFolder.resolve(Paths.get("Lights.xsd"))); // execute testSuite.verifyLightsXmlFileExists(); @@ -80,6 +81,7 @@ public void verifyLightsXmlAgainstSchema_XmlIsNotValid() throws IOException, SAX public void verifyLightsXmlHasUniqueCodes_LightsXmlHasUniqueCodes() throws IOException { // setup Files.copy(VALID_FILE, metadataFolder.resolve("Lights.xml"), REPLACE_EXISTING); + Files.createFile(schemaFolder.resolve(Paths.get("Lights.xsd"))); // execute testSuite.verifyLightsXmlHasUniqueCodes(); @@ -89,6 +91,7 @@ public void verifyLightsXmlHasUniqueCodes_LightsXmlHasUniqueCodes() throws IOExc public void verifyLightsXmlHasUniqueCodes_LightsXmlDoesNotHaveUniqueCodes() throws IOException { // setup Files.copy(DUPLICATED_CODE_FILE, metadataFolder.resolve("Lights.xml"), REPLACE_EXISTING); + Files.createFile(schemaFolder.resolve(Paths.get("Lights.xsd"))); expectedException.expect(AssertionError.class); expectedException.expectMessage("Lights.xml element Light should have unique codes. Code '1' is not unique. expected [1] but found [2]"); @@ -101,6 +104,7 @@ public void verifyLightsXmlHasUniqueCodes_LightsXmlDoesNotHaveUniqueCodes() thro public void verifyLightsXmlHasCodesWithinRange_LightsXmlHasCodesInRange() throws IOException { // setup Files.copy(VALID_FILE, metadataFolder.resolve("Lights.xml"), REPLACE_EXISTING); + Files.createFile(schemaFolder.resolve(Paths.get("Lights.xsd"))); // execute testSuite.verifyLightsXmlCodesAreWithinRange(); @@ -110,6 +114,7 @@ public void verifyLightsXmlHasCodesWithinRange_LightsXmlHasCodesInRange() throws public void verifyLightsXmlHasCodesWithinRange_LightsXmlCodeIsOver9999() throws IOException { // setup Files.copy(INVALID_CODE_TEN_THOUSAND_FILE, metadataFolder.resolve("Lights.xml"), REPLACE_EXISTING); + Files.createFile(schemaFolder.resolve(Paths.get("Lights.xsd"))); expectedException.expect(AssertionError.class); expectedException.expectMessage("Lights.xml element Light should have a code from 0 - 9999 inclusive."); @@ -122,6 +127,7 @@ public void verifyLightsXmlHasCodesWithinRange_LightsXmlCodeIsOver9999() throws public void verifyLightsXmlHasCodesWithinRange_LightsXmlCodeLessThanZero() throws IOException { // setup Files.copy(INVALID_CODE_NEGATIVE_ONE_FILE, metadataFolder.resolve("Lights.xml"), REPLACE_EXISTING); + Files.createFile(schemaFolder.resolve(Paths.get("Lights.xsd"))); expectedException.expect(AssertionError.class); expectedException.expectMessage("Lights.xml element Light should have a code from 0 - 9999 inclusive."); diff --git a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyMaterialsXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyMaterialsXmlStructureTests.java index 2de2ef0..0c6ca4a 100644 --- a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyMaterialsXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyMaterialsXmlStructureTests.java @@ -41,6 +41,7 @@ public void verifyMaterialsXmlFileExists_DoesNotExist() throws IOException { public void verifyMaterialsXmlFileExists_DoesExist() throws IOException { // setup Files.createFile(metadataFolder.resolve(Paths.get("Materials.xml"))); + Files.createFile(schemaFolder.resolve(Paths.get("Base_Material_Table.xsd"))); // execute testSuite.verifyMaterialsXmlFileExists(); @@ -78,6 +79,7 @@ public void verifyMaterialsXmlAgainstSchema_XmlIsNotValid() throws IOException, public void verifyMaterialsXmlElementNameIsUnique_IsUnique() throws IOException { // setup Files.copy(VALID_FILE, metadataFolder.resolve("Materials.xml"), REPLACE_EXISTING); + Files.createFile(schemaFolder.resolve(Paths.get("Base_Material_Table.xsd"))); // execute testSuite.verifyMaterialsXmlElementNameIsUnique(); @@ -87,6 +89,7 @@ public void verifyMaterialsXmlElementNameIsUnique_IsUnique() throws IOException public void verifyMaterialsXmlElementNameIsUnique_IsNotUnique() throws IOException { // setup Files.copy(NAME_NOT_UNIQUE_FILE, metadataFolder.resolve("Materials.xml"), REPLACE_EXISTING); + Files.createFile(schemaFolder.resolve(Paths.get("Base_Material_Table.xsd"))); String expectedMessage = "Materials.xml element Name should be unique. " + "'BM_ASH-VOLCANIC' is not unique. expected [1] but found [2]"; @@ -102,6 +105,7 @@ public void verifyMaterialsXmlElementNameIsUnique_IsNotUnique() throws IOExcepti public void verifyMaterialsXmlAllBaseMaterialElementsHaveAChildNodeName_TheyDo() throws IOException { // setup Files.copy(VALID_FILE, metadataFolder.resolve("Materials.xml"), REPLACE_EXISTING); + Files.createFile(schemaFolder.resolve(Paths.get("Base_Material_Table.xsd"))); // execute testSuite.verifyMaterialsXmlAllBaseMaterialElementsHaveAChildNodeName(); @@ -111,6 +115,7 @@ public void verifyMaterialsXmlAllBaseMaterialElementsHaveAChildNodeName_TheyDo() public void verifyMaterialsXmlAllBaseMaterialElementsHaveAChildNodeName_TheyDoNot() throws IOException { // setup Files.copy(MISSING_NAME_ELEMENT_FILE, metadataFolder.resolve("Materials.xml"), REPLACE_EXISTING); + Files.createFile(schemaFolder.resolve(Paths.get("Base_Material_Table.xsd"))); String expectedMessage = "Materials.xml element Base_Material requires a " + "child element Name. expected [0] but found [1]"; @@ -126,6 +131,7 @@ public void verifyMaterialsXmlAllBaseMaterialElementsHaveAChildNodeName_TheyDoNo public void verifyMaterialsXmlBaseMaterialNameIsValid_IsValid() throws Exception { // setup Files.copy(VALID_FILE, metadataFolder.resolve("Materials.xml"), REPLACE_EXISTING); + Files.createFile(schemaFolder.resolve(Paths.get("Base_Material_Table.xsd"))); // execute testSuite.verifyMaterialsXmlBaseMaterialNameIsValid(); @@ -135,6 +141,7 @@ public void verifyMaterialsXmlBaseMaterialNameIsValid_IsValid() throws Exception public void verifyMaterialsXmlBaseMaterialNameIsValid_IsNotValid() throws Exception { // setup Files.copy(INVALID_NAME_VALUE_FILE, metadataFolder.resolve("Materials.xml"), REPLACE_EXISTING); + Files.createFile(schemaFolder.resolve(Paths.get("Base_Material_Table.xsd"))); String expectedMessage = "Materials.xml element Name is always in format \"BM__*\", " + "has a maximum of 32 characters, and can only contain letters, digits, " + diff --git a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyModelComponentsXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyModelComponentsXmlStructureTests.java index ffbd7ba..7f93365 100644 --- a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyModelComponentsXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyModelComponentsXmlStructureTests.java @@ -38,6 +38,7 @@ public void verifyModelComponentsXmlExists_DoesNotExist() throws IOException { public void verifyModelComponentsXmlExists_XmlDoesExist() throws IOException { // setup Files.createFile(metadataFolder.resolve(Paths.get("Model_Components.xml"))); + Files.createFile(schemaFolder.resolve(Paths.get("Model_Components.xsd"))); // execute testSuite.verifyModelComponentsXmlFileExists(); diff --git a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyVersionXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyVersionXmlStructureTests.java index 7aa6601..d5142b0 100644 --- a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyVersionXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyVersionXmlStructureTests.java @@ -40,6 +40,7 @@ public void verifyVersionXmlFileExists_DoesNotExist() throws IOException { public void verifyVersionXmlFileExists_DoesExist() throws IOException { // setup Files.createFile(metadataFolder.resolve(Paths.get("Version.xml"))); + Files.createFile(schemaFolder.resolve(Paths.get("Version.xsd"))); // execute testSuite.verifyVersionXmlFileExists(); From bc626a281181550f75fc6cbb0f2d56dc770af1fa Mon Sep 17 00:00:00 2001 From: Serene Yew Date: Tue, 20 Sep 2016 17:15:32 -0600 Subject: [PATCH 13/20] Verify that metadata directory exists before running metadata tests --- .../metadataAndVersioning/MetadataXmlFile.java | 2 ++ .../VerifyCDBAttributesXmlStructureTests.java | 13 +++++++++++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java index ea79661..8d82793 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java @@ -18,6 +18,8 @@ public abstract class MetadataXmlFile { protected File xsdFile; public MetadataXmlFile(String path, String xmlFileName, String xsdFileName) { + Assert.assertTrue(Files.exists(Paths.get(path, "Metadata")), String.format("Metadata directory is missing.")); + xmlFile = Paths.get(path, "Metadata", xmlFileName).toFile(); xsdFile = Paths.get(path, "Metadata", "Schema", xsdFileName).toFile(); diff --git a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyCDBAttributesXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyCDBAttributesXmlStructureTests.java index a9070c1..cbc1e33 100644 --- a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyCDBAttributesXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyCDBAttributesXmlStructureTests.java @@ -30,6 +30,19 @@ public VerifyCDBAttributesXmlStructureTests() { testSuite = new CDBAttributesXmlStructureTests(); } + @Test + public void verifyCDBAttributesXmlExists_MetadataFolderDoesNotExist() throws IOException { + // setup + Files.delete(cdb_root.resolve(Paths.get("Metadata", "Schema"))); + Files.delete(cdb_root.resolve(Paths.get("Metadata"))); + + expectedException.expect(AssertionError.class); + expectedException.expectMessage("Metadata directory is missing."); + + // execute + testSuite.verifyCDBAttributesXmlFileExists(); + } + @Test public void verifyCDBAttributesXmlExists_DoesNotExist() throws IOException { expectedException.expect(AssertionError.class); From fafee08437467711b619584a66bf405a70ef28e2 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Tue, 20 Sep 2016 17:30:56 -0600 Subject: [PATCH 14/20] move private method to the bottom of the class --- .../cdb10/metadataAndVersioning/MetadataXmlFile.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java index 8d82793..09985c1 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MetadataXmlFile.java @@ -26,11 +26,6 @@ public MetadataXmlFile(String path, String xmlFileName, String xsdFileName) { verifyXmlFileExists(); } - private void verifyXmlFileExists() { - Assert.assertTrue(Files.exists(xmlFile.toPath()), String.format("Metadata directory should contain %s file.", xmlFile.getName())); - Assert.assertTrue(Files.exists(xsdFile.toPath()), String.format("Metadata directory should contain %s file.", xsdFile.getName())); - } - public void verifyXmlAgainstSchema() throws IOException, SAXException { SchemaValidatorErrorHandler errorHandler = XMLUtils.validateXmlFileIsValid(xmlFile, xsdFile); @@ -38,4 +33,10 @@ public void verifyXmlAgainstSchema() throws IOException, SAXException { Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages()); } } + + private void verifyXmlFileExists() { + Assert.assertTrue(Files.exists(xmlFile.toPath()), String.format("Metadata directory should contain %s file.", xmlFile.getName())); + Assert.assertTrue(Files.exists(xsdFile.toPath()), String.format("Metadata directory should contain %s file.", xsdFile.getName())); + } + } From 6df5a32d7f53772d23a1629f165a417ffe6b2f2f Mon Sep 17 00:00:00 2001 From: martinechtner Date: Wed, 21 Sep 2016 09:55:32 -0600 Subject: [PATCH 15/20] add before class to check if and custom lights files exist if not it will skip the tests --- .../metadataAndVersioning/LightsXxxXmlStructureTests.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java index 01b65de..5cd9099 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java @@ -4,6 +4,7 @@ import org.opengis.cite.cdb10.util.SchemaValidatorErrorHandler; import org.opengis.cite.cdb10.util.XMLUtils; import org.testng.Assert; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -23,6 +24,11 @@ public class LightsXxxXmlStructureTests extends CommonFixture { private static final List DIRECTIONALITY_VALUES = Arrays.asList("Omnidirectional", "Directional", "Bidirectional"); + @BeforeClass + public void checkFilesExist() { + Assert.assertTrue(!getCustomLightsXmlFiles().isEmpty(), "No custom Lights xml files."); + } + @Test public void verifyLights_XxxXmlFileExists() { for (File xmlFile : getCustomLightsXmlFiles()) { @@ -48,7 +54,7 @@ public void verifyLightsXmlFileNameIsValid() { } @Test - public void verifyLightsTuningXsdFFileExists() { + public void verifyLightsTuningXsdFileExists() { for (File xmlFile : getCustomLightsXmlFiles()) { Assert.assertTrue(Files.exists(Paths.get(path, "Metadata", "Schema", "Lights_Tuning.xsd")), "If a custom Lights_xxx.xml exists there should be Lights_Tuning.xsd in the Schema folder."); From 509301b48e0e5e723e29f35d8fad6a2a320d7a18 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Wed, 21 Sep 2016 10:02:29 -0600 Subject: [PATCH 16/20] Revert "add before class to check if and custom lights files exist if not it will skip the tests" This reverts commit 6df5a32d7f53772d23a1629f165a417ffe6b2f2f. --- .../metadataAndVersioning/LightsXxxXmlStructureTests.java | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java index 5cd9099..01b65de 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java @@ -4,7 +4,6 @@ import org.opengis.cite.cdb10.util.SchemaValidatorErrorHandler; import org.opengis.cite.cdb10.util.XMLUtils; import org.testng.Assert; -import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -24,11 +23,6 @@ public class LightsXxxXmlStructureTests extends CommonFixture { private static final List DIRECTIONALITY_VALUES = Arrays.asList("Omnidirectional", "Directional", "Bidirectional"); - @BeforeClass - public void checkFilesExist() { - Assert.assertTrue(!getCustomLightsXmlFiles().isEmpty(), "No custom Lights xml files."); - } - @Test public void verifyLights_XxxXmlFileExists() { for (File xmlFile : getCustomLightsXmlFiles()) { @@ -54,7 +48,7 @@ public void verifyLightsXmlFileNameIsValid() { } @Test - public void verifyLightsTuningXsdFileExists() { + public void verifyLightsTuningXsdFFileExists() { for (File xmlFile : getCustomLightsXmlFiles()) { Assert.assertTrue(Files.exists(Paths.get(path, "Metadata", "Schema", "Lights_Tuning.xsd")), "If a custom Lights_xxx.xml exists there should be Lights_Tuning.xsd in the Schema folder."); From ed5db1fdd929660530012cadf04ffc86b566a62f Mon Sep 17 00:00:00 2001 From: martinechtner Date: Wed, 21 Sep 2016 10:06:18 -0600 Subject: [PATCH 17/20] Add BeforeClass to check if there are any custom lights xml files --- .../metadataAndVersioning/LightsXxxXmlStructureTests.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java index 01b65de..04d3d11 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java @@ -4,6 +4,7 @@ import org.opengis.cite.cdb10.util.SchemaValidatorErrorHandler; import org.opengis.cite.cdb10.util.XMLUtils; import org.testng.Assert; +import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -23,6 +24,11 @@ public class LightsXxxXmlStructureTests extends CommonFixture { private static final List DIRECTIONALITY_VALUES = Arrays.asList("Omnidirectional", "Directional", "Bidirectional"); + @BeforeClass + public void checkFilesExist() { + Assert.assertFalse(getCustomLightsXmlFiles().isEmpty(), "No custom Lights xml files."); + } + @Test public void verifyLights_XxxXmlFileExists() { for (File xmlFile : getCustomLightsXmlFiles()) { From b1f1e00b641ef1a95f432b840546c4538f8a356a Mon Sep 17 00:00:00 2001 From: martinechtner Date: Thu, 10 Nov 2016 14:04:37 -0700 Subject: [PATCH 18/20] refactored vendor attributes xml to fail if no Metadata directory --- .../VendorAttributesXml.java | 19 +++++++++++ .../VendorAttributesXmlStructureTests.java | 32 ++++--------------- ...rifyVendorAttributesXmlStructureTests.java | 17 ++++++++-- 3 files changed, 41 insertions(+), 27 deletions(-) create mode 100644 src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXml.java diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXml.java new file mode 100644 index 0000000..7d453c8 --- /dev/null +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXml.java @@ -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"); + } +} diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXmlStructureTests.java index dbfc0f0..0bf40c2 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXmlStructureTests.java @@ -1,13 +1,10 @@ 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; @@ -18,32 +15,17 @@ 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(); } } diff --git a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyVendorAttributesXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyVendorAttributesXmlStructureTests.java index 5594770..d4ac1c3 100644 --- a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyVendorAttributesXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyVendorAttributesXmlStructureTests.java @@ -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(); @@ -77,8 +80,13 @@ 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 @@ -86,6 +94,11 @@ public void verifyVendorAttributesXmlAgainstSchema_VendorAttributesXsdFileDoesNo // 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 } From 5d5caf35d883858f6b7654477f135c32a75da605 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Fri, 18 Nov 2016 10:59:14 -0700 Subject: [PATCH 19/20] refactor to fail when no metadata folder --- .../GeomaticsAttributesXml.java | 19 ++++++++++ .../GeomaticsAttributesXmlStructureTests.java | 35 ++++--------------- .../VendorAttributesXmlStructureTests.java | 3 -- ...yGeomaticsAttributesXmlStructureTests.java | 8 +++-- 4 files changed, 32 insertions(+), 33 deletions(-) create mode 100644 src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/GeomaticsAttributesXml.java diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/GeomaticsAttributesXml.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/GeomaticsAttributesXml.java new file mode 100644 index 0000000..41ffb03 --- /dev/null +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/GeomaticsAttributesXml.java @@ -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"); + } +} diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/GeomaticsAttributesXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/GeomaticsAttributesXmlStructureTests.java index 040b502..9298b21 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/GeomaticsAttributesXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/GeomaticsAttributesXmlStructureTests.java @@ -1,16 +1,10 @@ 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. @@ -18,32 +12,17 @@ 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(); } } diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXmlStructureTests.java index 0bf40c2..caacbee 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXmlStructureTests.java @@ -1,13 +1,10 @@ package org.opengis.cite.cdb10.metadataAndVersioning; import org.opengis.cite.cdb10.CommonFixture; -import org.testng.Assert; import org.testng.annotations.Test; import org.xml.sax.SAXException; import java.io.IOException; -import java.nio.file.Files; -import java.nio.file.Paths; /** * Created by martin on 2016-09-09. diff --git a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyGeomaticsAttributesXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyGeomaticsAttributesXmlStructureTests.java index 5862fcf..1c245ea 100644 --- a/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyGeomaticsAttributesXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/metadataAndVersioning/VerifyGeomaticsAttributesXmlStructureTests.java @@ -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(); @@ -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 From b583028bf5a6011a7868a6d32bc20dc1abd38ac3 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Fri, 18 Nov 2016 15:00:57 -0700 Subject: [PATCH 20/20] fixed issue with selecting the conformance level only runs conformance level selected and below --- .../org/opengis/cite/cdb10/CommonFixture.java | 8 ---- .../CDBAttributesXmlStructureTests.java | 2 +- .../Capability2Tests.java | 40 ++++++++----------- .../ConfigurationXmlStructureTests.java | 2 +- .../DefaultsXmlStructureTests.java | 2 +- .../GeomaticsAttributesXmlStructureTests.java | 2 +- .../LightsXmlStructureTests.java | 2 +- .../LightsXxxXmlStructureTests.java | 2 +- .../MaterialsXmlStructureTests.java | 2 +- .../ModelComponentsXmlStructureTests.java | 2 +- .../VendorAttributesXmlStructureTests.java | 2 +- .../VersionXmlStructureTests.java | 2 +- src/main/scripts/ctl/cdb10-suite.ctl | 2 +- 13 files changed, 28 insertions(+), 42 deletions(-) diff --git a/src/main/java/org/opengis/cite/cdb10/CommonFixture.java b/src/main/java/org/opengis/cite/cdb10/CommonFixture.java index 1ab1d18..eb37a12 100644 --- a/src/main/java/org/opengis/cite/cdb10/CommonFixture.java +++ b/src/main/java/org/opengis/cite/cdb10/CommonFixture.java @@ -70,14 +70,6 @@ public void initCommonFixture(ITestContext testContext) { */ @BeforeClass public void obtainTestSubject(ITestContext testContext) { - Object obj = testContext.getSuite().getAttribute( - SuiteAttribute.LEVEL.getName()); - if ((null != obj)) { - Integer level = Integer.class.cast(obj); -// Assert.assertTrue(level.intValue() > 0, -// "Conformance level 1 will not be checked since ics = " + level); - } - path = testContext.getSuite().getAttribute( SuiteAttribute.TEST_SUBJECT.getName()).toString().trim(); diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXmlStructureTests.java index 74de804..ce5be6a 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXmlStructureTests.java @@ -9,7 +9,7 @@ /** * Created by martin on 2016-09-08. */ -public class CDBAttributesXmlStructureTests extends CommonFixture { +public class CDBAttributesXmlStructureTests extends Capability2Tests { @Test public void verifyCDBAttributesXmlFileExists() { diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/Capability2Tests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/Capability2Tests.java index 0743d38..f3d3952 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/Capability2Tests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/Capability2Tests.java @@ -1,7 +1,10 @@ package org.opengis.cite.cdb10.metadataAndVersioning; import org.opengis.cite.cdb10.CommonFixture; +import org.opengis.cite.cdb10.SuiteAttribute; import org.testng.Assert; +import org.testng.ITestContext; +import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeTest; import org.testng.annotations.Test; @@ -10,30 +13,21 @@ */ public class Capability2Tests extends CommonFixture { - /** - * Run conformance level 2 tests only if the preconditions are satisfied. - */ - @BeforeTest - public void checkPreconditions() { - Assert.assertTrue(2 > 1, - "Preconditions for Conformance Level 2 were not satisfied."); - } - - /** - * Checks the result of the length function. - */ - @Test(description = "Implements ATC 2-1") - public void checkLength() { - String str = "perihelion"; - Assert.assertEquals(str.length(), 10); - } - /** - * Checks the Unicode code point value of the first character. + * Obtains the test subject from the ISuite context. The suite attribute + * {@link org.opengis.cite.cdb10.SuiteAttribute#TEST_SUBJECT} should + * evaluate to a DOM Document node. + * + * @param testContext The test (group) context. */ - @Test(description = "Implements ATC 2-2") - public void codePoint() { - String str = "perihelion"; - Assert.assertEquals(str.codePointAt(0), 100); + @BeforeClass + public void obtainTestSubject(ITestContext testContext) { + Object obj = testContext.getSuite().getAttribute(SuiteAttribute.LEVEL.getName()); + if ((null != obj)) { + Integer level = Integer.class.cast(obj); + Assert.assertTrue(level > 1, + "Conformance level " + "2 will not be checked since ics = " + level); + } + super.obtainTestSubject(testContext); } } diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java index 10ae73f..8bbbc37 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java @@ -9,7 +9,7 @@ /** * Created by martin on 2016-09-07. */ -public class ConfigurationXmlStructureTests extends CommonFixture { +public class ConfigurationXmlStructureTests extends Capability2Tests { @Test public void verifyConfigurationXmlFileExists() { diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXmlStructureTests.java index 5f13de2..a2c0d63 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/DefaultsXmlStructureTests.java @@ -9,7 +9,7 @@ /** * Created by martin on 2016-09-03. */ -public class DefaultsXmlStructureTests extends CommonFixture { +public class DefaultsXmlStructureTests extends Capability2Tests { @Test public void verifyDefaultsXmlFileExists() { new DefaultsXml(path); diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/GeomaticsAttributesXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/GeomaticsAttributesXmlStructureTests.java index 9298b21..84502ea 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/GeomaticsAttributesXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/GeomaticsAttributesXmlStructureTests.java @@ -9,7 +9,7 @@ /** * Created by martin on 2016-09-10. */ -public class GeomaticsAttributesXmlStructureTests extends CommonFixture { +public class GeomaticsAttributesXmlStructureTests extends Capability2Tests { @Test public void verifyGeomaticsAttributesXmlFileExists() { diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXmlStructureTests.java index 347d326..a2fdd9d 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXmlStructureTests.java @@ -9,7 +9,7 @@ /** * Created by martin on 2016-09-01. */ -public class LightsXmlStructureTests extends CommonFixture { +public class LightsXmlStructureTests extends Capability2Tests { @Test public void verifyLightsXmlFileExists() { diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java index 04d3d11..b367915 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/LightsXxxXmlStructureTests.java @@ -20,7 +20,7 @@ /** * Created by martin on 2016-09-12. */ -public class LightsXxxXmlStructureTests extends CommonFixture { +public class LightsXxxXmlStructureTests extends Capability2Tests { private static final List DIRECTIONALITY_VALUES = Arrays.asList("Omnidirectional", "Directional", "Bidirectional"); diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXmlStructureTests.java index 9384df1..f15fc45 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/MaterialsXmlStructureTests.java @@ -19,7 +19,7 @@ /** * Created by martin on 2016-09-09. */ -public class MaterialsXmlStructureTests extends CommonFixture { +public class MaterialsXmlStructureTests extends Capability2Tests { @Test public void verifyMaterialsXmlFileExists() { diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ModelComponentsXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ModelComponentsXmlStructureTests.java index 0623adc..28bdd41 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ModelComponentsXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ModelComponentsXmlStructureTests.java @@ -9,7 +9,7 @@ /** * Created by martin on 2016-09-02. */ -public class ModelComponentsXmlStructureTests extends CommonFixture { +public class ModelComponentsXmlStructureTests extends Capability2Tests { @Test public void verifyModelComponentsXmlFileExists() { diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXmlStructureTests.java index caacbee..6b99f27 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VendorAttributesXmlStructureTests.java @@ -9,7 +9,7 @@ /** * Created by martin on 2016-09-09. */ -public class VendorAttributesXmlStructureTests extends CommonFixture { +public class VendorAttributesXmlStructureTests extends Capability2Tests { @Test public void verifyVendorAttributesXmlFileExists() { diff --git a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VersionXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VersionXmlStructureTests.java index bf589a3..93d57c9 100644 --- a/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VersionXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/VersionXmlStructureTests.java @@ -9,7 +9,7 @@ /** * Created by martin on 2016-09-06. */ -public class VersionXmlStructureTests extends CommonFixture { +public class VersionXmlStructureTests extends Capability2Tests { @Test public void verifyVersionXmlFileExists() { diff --git a/src/main/scripts/ctl/cdb10-suite.ctl b/src/main/scripts/ctl/cdb10-suite.ctl index 0a6c6f6..8307cb8 100644 --- a/src/main/scripts/ctl/cdb10-suite.ctl +++ b/src/main/scripts/ctl/cdb10-suite.ctl @@ -54,7 +54,7 @@

-