Skip to content

Commit

Permalink
Merge pull request #7 from pixeltree/master
Browse files Browse the repository at this point in the history
Validate Lights XML files. Fixed radio button selection.
  • Loading branch information
serene authored Nov 18, 2016
2 parents f691a05 + 748c67d commit 3234782
Show file tree
Hide file tree
Showing 33 changed files with 614 additions and 445 deletions.
8 changes: 0 additions & 8 deletions src/main/java/org/opengis/cite/cdb10/CommonFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
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));
}
}
}
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();
}
}
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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);
}
}
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");
}
}
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();
}
}
Loading

0 comments on commit 3234782

Please sign in to comment.