-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from pixeltree/master
Validate Lights XML files. Fixed radio button selection.
- Loading branch information
Showing
33 changed files
with
614 additions
and
445 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
105 changes: 105 additions & 0 deletions
105
src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXml.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
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.Collections; | ||
import java.util.List; | ||
|
||
/** | ||
* Created by martin on 2016-09-20. | ||
*/ | ||
public class CDBAttributesXml extends MetadataXmlFile { | ||
|
||
public CDBAttributesXml(String path) { | ||
super(path, "CDB_Attributes.xml", "Vector_Attributes.xsd"); | ||
} | ||
|
||
public void verifyCodeIsAnInteger() { | ||
NodeList nodeList = XMLUtils.getNodeList("//Attribute", xmlFile.toPath()); | ||
|
||
ArrayList<String> 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<String> 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<String> types = new ArrayList<>(); | ||
List<String> 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<String> 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<String> 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)); | ||
} | ||
} | ||
} |
109 changes: 14 additions & 95 deletions
109
...ain/java/org/opengis/cite/cdb10/metadataAndVersioning/CDBAttributesXmlStructureTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,129 +1,48 @@ | ||
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. | ||
*/ | ||
public class CDBAttributesXmlStructureTests extends CommonFixture { | ||
public class CDBAttributesXmlStructureTests extends Capability2Tests { | ||
|
||
@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<String> 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<String> 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<String> types = new ArrayList<>(); | ||
List<String> 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<String> 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<String> 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(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXml.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package org.opengis.cite.cdb10.metadataAndVersioning; | ||
|
||
/** | ||
* Created by martin on 2016-09-20. | ||
*/ | ||
public class ConfigurationXml extends MetadataXmlFile { | ||
|
||
public ConfigurationXml(String path) { | ||
super(path, "Configuration.xml", "Configuration.xsd"); | ||
} | ||
} |
20 changes: 3 additions & 17 deletions
20
...ain/java/org/opengis/cite/cdb10/metadataAndVersioning/ConfigurationXmlStructureTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,37 +1,23 @@ | ||
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. | ||
*/ | ||
public class ConfigurationXmlStructureTests extends CommonFixture { | ||
public class ConfigurationXmlStructureTests extends Capability2Tests { | ||
|
||
@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).verifyXmlAgainstSchema(); | ||
} | ||
} |
Oops, something went wrong.