From e4b1c3ce86a6d00b0a76d803b6797774996b03c4 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Mon, 12 Sep 2016 09:35:49 -0600 Subject: [PATCH 01/14] Check if a custom lights xml file exists if it exists check it has Lights_Tuning.xsd and validate against it --- .../LightsXxxXmlStructureTests.java | 70 +++++++++++++++++ .../fixtures/invalid/Lights_ClientInvalid.xml | 23 ++++++ .../cdb10/fixtures/schema/Lights_Tuning.xsd | 70 +++++++++++++++++ .../cdb10/fixtures/valid/Lights_Client.xml | 23 ++++++ .../VerifyLightsXxxXmlStructureTests.java | 76 +++++++++++++++++++ 5 files changed, 262 insertions(+) create mode 100644 src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java create mode 100755 src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalid.xml create mode 100755 src/test/java/org/opengis/cite/cdb10/fixtures/schema/Lights_Tuning.xsd create mode 100755 src/test/java/org/opengis/cite/cdb10/fixtures/valid/Lights_Client.xml create mode 100644 src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java diff --git a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java new file mode 100644 index 0000000..9df2771 --- /dev/null +++ b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java @@ -0,0 +1,70 @@ +package org.opengis.cite.cdb10.CDBStructure; + +import org.opengis.cite.cdb10.CommonFixture; +import org.opengis.cite.cdb10.util.SchemaValidatorErrorHandler; +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.*; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by martin on 2016-09-12. + */ +public class LightsXxxXmlStructureTests extends CommonFixture { + + @Test + public void verifyLightsTuningXsdFFileExists() { + File xmlFile = getCustomLightsXmlFile(); + + if (xmlFile != null) { + System.out.println("here"); + 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."); + } + } + + @Test + public void verifyLightsXxxXmlAgainstSchema() throws IOException, SAXException { + File xmlFile = getCustomLightsXmlFile(); + if (xmlFile != null) { + File xsdFile = Paths.get(path, "Metadata", "Schema", "Lights_Tuning.xsd").toFile(); + + SchemaValidatorErrorHandler errorHandler = XmlUtilities.validateXmlFileIsValid(xmlFile, xsdFile); + + if (!errorHandler.noErrors()) { + Assert.fail(xmlFile.getName() + " does not contain valid XML. Errors: " + errorHandler.getMessages()); + } + } + } + + private File getCustomLightsXmlFile() { + String glob = "glob:Lights_*.xml"; + + final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher(glob); + + List files = new ArrayList<>(); + + try { + DirectoryStream stream = Files.newDirectoryStream(Paths.get(path, "Metadata")); + for (Path entry : stream) { + if (pathMatcher.matches(entry.getFileName())) { + files.add(String.valueOf(entry.getFileName())); + } + } + stream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + if (files.size() > 0) { + return Paths.get(path, "Metadata", files.get(0)).toFile(); + } else { + return null; + } + } +} diff --git a/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalid.xml b/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalid.xml new file mode 100755 index 0000000..6d4db94 --- /dev/null +++ b/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalid.xml @@ -0,0 +1,23 @@ + + + + Tuned for MH-47 CMS + 0.75 + 1.0 0.0 0.0 + Omnidirectional + 0.5 + 0.2 + + + ... + 1.07 + 1.0 0.9 0.9 + Invalid + 0.05 + + 1.1 + 1.5 + + + diff --git a/src/test/java/org/opengis/cite/cdb10/fixtures/schema/Lights_Tuning.xsd b/src/test/java/org/opengis/cite/cdb10/fixtures/schema/Lights_Tuning.xsd new file mode 100755 index 0000000..496dd1f --- /dev/null +++ b/src/test/java/org/opengis/cite/cdb10/fixtures/schema/Lights_Tuning.xsd @@ -0,0 +1,70 @@ + + + + + CDB Light Tuning Schema + + XML schema to define and validate CDB Light Tuning. + In accordance with chapter 2 of the CDB specification. + Distribution B, Second Draft, March 16, 2005 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/test/java/org/opengis/cite/cdb10/fixtures/valid/Lights_Client.xml b/src/test/java/org/opengis/cite/cdb10/fixtures/valid/Lights_Client.xml new file mode 100755 index 0000000..f26faea --- /dev/null +++ b/src/test/java/org/opengis/cite/cdb10/fixtures/valid/Lights_Client.xml @@ -0,0 +1,23 @@ + + + + Tuned for MH-47 CMS + 0.75 + 1.0 0.0 0.0 + Omnidirectional + 0.5 + 0.2 + + + ... + 1.07 + 1.0 0.9 0.9 + Directional + 0.05 + + 1.1 + 1.5 + + + diff --git a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java new file mode 100644 index 0000000..7ecec2d --- /dev/null +++ b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java @@ -0,0 +1,76 @@ +package org.opengis.cite.cdb10.level1; + +import org.junit.Test; +import org.opengis.cite.cdb10.CDBStructure.LightsXxxXmlStructureTests; +import org.xml.sax.SAXException; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; + +import static java.nio.file.StandardCopyOption.REPLACE_EXISTING; + +/** + * Created by martin on 2016-09-12. + */ +public class VerifyLightsXxxXmlStructureTests extends MetadataTestFixture { + + private final static Path XSD_FILE = SOURCE_DIRECTORY.resolve(Paths.get("schema", "Lights_Tuning.xsd")); + + private final static Path VALID_FILE = SOURCE_DIRECTORY.resolve(Paths.get("valid", "Lights_Client.xml")); + + private final static Path INVALID_FILE = SOURCE_DIRECTORY.resolve(Paths.get("invalid", "Lights_ClientInvalid.xml")); + + public VerifyLightsXxxXmlStructureTests() { + testSuite = new LightsXxxXmlStructureTests(); + } + + @Test + public void verifyLightsTuningXsdFileExists_DoesNotExist() throws IOException { + //setup + Files.createFile(metadataFolder.resolve(Paths.get("Lights_Client.xml"))); + + expectedException.expect(AssertionError.class); + expectedException.expectMessage("If a custom Lights_xxx.xml exists there should be Lights_Tuning.xsd in the Schema folder."); + + // execute + testSuite.verifyLightsTuningXsdFFileExists(); + } + + @Test + public void verifyLightsTuningXsdFileExists_DoesExist() throws IOException { + // setup + Files.createFile(metadataFolder.resolve(Paths.get("Lights_Client.xml"))); + Files.createFile(schemaFolder.resolve(Paths.get("Lights_Tuning.xsd"))); + + // execute + testSuite.verifyLightsTuningXsdFFileExists(); + } + + @Test + public void verifyLightsXxxXmlAgainstSchema_XmlIsValid() throws IOException, SAXException { + // setup + Files.copy(VALID_FILE, metadataFolder.resolve("Lights_Client.xml"), REPLACE_EXISTING); + Files.copy(XSD_FILE, schemaFolder.resolve("Lights_Tuning.xsd"), REPLACE_EXISTING); + + // execute + testSuite.verifyLightsXxxXmlAgainstSchema(); + } + + @Test + public void verifyLightsXxxXmlAgainstSchema_XmlIsNotValid() throws IOException, SAXException { + // setup + Files.copy(INVALID_FILE, metadataFolder.resolve("Lights_Client.xml"), REPLACE_EXISTING); + Files.copy(XSD_FILE, schemaFolder.resolve("Lights_Tuning.xsd"), REPLACE_EXISTING); + + expectedException.expect(AssertionError.class); + expectedException.expectMessage("Lights_Client.xml does not contain valid XML. " + + "Errors: cvc-pattern-valid: Value 'Invalid' is not facet-valid with respect to pattern " + + "'Omnidirectional|Directional|Bidirectional' for type '#AnonType_DirectionalityLight'., " + + "cvc-type.3.1.3: The value 'Invalid' of element 'Directionality' is not valid."); + + // execute + testSuite.verifyLightsXxxXmlAgainstSchema(); + } +} From 0d5a797c38ab89ee63bbc28e732b3259d8cc8911 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Mon, 12 Sep 2016 09:56:04 -0600 Subject: [PATCH 02/14] validate the name of the file --- .../LightsXxxXmlStructureTests.java | 11 +++++++++ .../VerifyLightsXxxXmlStructureTests.java | 24 +++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java index 9df2771..1732b8d 100644 --- a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java @@ -17,6 +17,17 @@ */ public class LightsXxxXmlStructureTests extends CommonFixture { + @Test + public void verifyLightsXmlFileNameIsValid() { + File xmlFile = getCustomLightsXmlFile(); + + if(!xmlFile.getName().matches("^Lights_[a-zA-Z0-9_-]{0,25}.xml$")) { + Assert.fail(String.format("'%s' is not a valid file name it must start with 'Lights_', " + + "can only be a maximum of 32 characters and contain letters, numbers, " + + "underscores and dashes.", xmlFile.getName())); + } + } + @Test public void verifyLightsTuningXsdFFileExists() { File xmlFile = getCustomLightsXmlFile(); diff --git a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java index 7ecec2d..35555e2 100644 --- a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java @@ -26,6 +26,30 @@ public VerifyLightsXxxXmlStructureTests() { testSuite = new LightsXxxXmlStructureTests(); } + @Test + public void verifyLightsXmlFileNameIsValid_IsNotValid() throws Exception { + //setup + Files.createFile(metadataFolder.resolve(Paths.get("Lights_123451234512345123451234512345.xml"))); + + String expectedMessage = "'Lights_123451234512345123451234512345.xml' is not a valid file name it must start " + + "with 'Lights_', can only be a maximum of 32 characters and contain letters, numbers, underscores and dashes."; + + expectedException.expect(AssertionError.class); + expectedException.expectMessage(expectedMessage); + + // execute + testSuite.verifyLightsXmlFileNameIsValid(); + } + + @Test + public void verifyLightsXmlFileNameIsValid_IsValid() throws Exception { + //setup + Files.createFile(metadataFolder.resolve(Paths.get("Lights_Client.xml"))); + + // execute + testSuite.verifyLightsXmlFileNameIsValid(); + } + @Test public void verifyLightsTuningXsdFileExists_DoesNotExist() throws IOException { //setup From cc0652fa31b1abf4f4d15f396eb431104778cfd3 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Mon, 12 Sep 2016 11:11:02 -0600 Subject: [PATCH 03/14] verify Intensity values are within range --- .../LightsXxxXmlStructureTests.java | 26 +++++++++++++- ...ights_ClientInvalidIntensityOutOfRange.xml | 23 ++++++++++++ .../cdb10/fixtures/valid/Lights_Client.xml | 2 +- .../VerifyLightsXxxXmlStructureTests.java | 36 ++++++++++++++++--- 4 files changed, 81 insertions(+), 6 deletions(-) create mode 100755 src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidIntensityOutOfRange.xml diff --git a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java index 1732b8d..0b0267e 100644 --- a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java @@ -4,6 +4,8 @@ import org.opengis.cite.cdb10.util.SchemaValidatorErrorHandler; 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; @@ -21,7 +23,7 @@ public class LightsXxxXmlStructureTests extends CommonFixture { public void verifyLightsXmlFileNameIsValid() { File xmlFile = getCustomLightsXmlFile(); - if(!xmlFile.getName().matches("^Lights_[a-zA-Z0-9_-]{0,25}.xml$")) { + if (!xmlFile.getName().matches("^Lights_[a-zA-Z0-9_-]{0,25}.xml$")) { Assert.fail(String.format("'%s' is not a valid file name it must start with 'Lights_', " + "can only be a maximum of 32 characters and contain letters, numbers, " + "underscores and dashes.", xmlFile.getName())); @@ -53,6 +55,28 @@ public void verifyLightsXxxXmlAgainstSchema() throws IOException, SAXException { } } + public void verifyElementIntensityIsInRange() { + File xmlFile = getCustomLightsXmlFile(); + if (xmlFile != null) { + NodeList intensityNodes = XmlUtilities.getNodeList("//Intensity", Paths.get(path, "Metadata", xmlFile.getName())); + + ArrayList invalidIntensityValues = new ArrayList<>(); + + for (int i = 0; i < intensityNodes.getLength(); i++) { + Node currentItem = intensityNodes.item(i); + Float value = Float.parseFloat(currentItem.getTextContent()); + + if (value >= 0.0 && value <= 1.0) { + invalidIntensityValues.add(currentItem.getTextContent()); + } + } + + Assert.assertEquals(intensityNodes.getLength(), 0, + String.format("'%s' Intensity elements value can range from 0.0 to 1.0. %s", + xmlFile.getName().toString(), invalidIntensityValues.toString())); + } + } + private File getCustomLightsXmlFile() { String glob = "glob:Lights_*.xml"; diff --git a/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidIntensityOutOfRange.xml b/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidIntensityOutOfRange.xml new file mode 100755 index 0000000..626079b --- /dev/null +++ b/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidIntensityOutOfRange.xml @@ -0,0 +1,23 @@ + + + + Tuned for MH-47 CMS + -0.1 + 1.0 0.0 0.0 + Omnidirectional + 0.5 + 0.2 + + + ... + 1.01 + 1.0 0.9 0.9 + Directional + 0.05 + + 1.1 + 1.5 + + + diff --git a/src/test/java/org/opengis/cite/cdb10/fixtures/valid/Lights_Client.xml b/src/test/java/org/opengis/cite/cdb10/fixtures/valid/Lights_Client.xml index f26faea..9326dc3 100755 --- a/src/test/java/org/opengis/cite/cdb10/fixtures/valid/Lights_Client.xml +++ b/src/test/java/org/opengis/cite/cdb10/fixtures/valid/Lights_Client.xml @@ -11,7 +11,7 @@ ... - 1.07 + 1.0 1.0 0.9 0.9 Directional 0.05 diff --git a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java index 35555e2..e62f7f2 100644 --- a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java @@ -21,6 +21,7 @@ public class VerifyLightsXxxXmlStructureTests extends MetadataTestFixture Date: Mon, 12 Sep 2016 11:37:23 -0600 Subject: [PATCH 04/14] verify Directionality has a valid value --- .../LightsXxxXmlStructureTests.java | 25 +++++++++++++- ...ights_ClientInvalidDirectionalityValue.xml | 12 +++++++ .../VerifyLightsXxxXmlStructureTests.java | 33 ++++++++++++++++--- .../VerifyVersionXmlStructureTests.java | 1 - 4 files changed, 65 insertions(+), 6 deletions(-) create mode 100755 src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidDirectionalityValue.xml diff --git a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java index 0b0267e..182e554 100644 --- a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java @@ -12,6 +12,7 @@ import java.io.IOException; import java.nio.file.*; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; /** @@ -55,7 +56,7 @@ public void verifyLightsXxxXmlAgainstSchema() throws IOException, SAXException { } } - public void verifyElementIntensityIsInRange() { + public void verifyLightsXxxXmlElementIntensityIsInRange() { File xmlFile = getCustomLightsXmlFile(); if (xmlFile != null) { NodeList intensityNodes = XmlUtilities.getNodeList("//Intensity", Paths.get(path, "Metadata", xmlFile.getName())); @@ -77,6 +78,28 @@ public void verifyElementIntensityIsInRange() { } } + @Test + public void verifyLightsXxxXmlDirectionalityValueIsValid() { + File xmlFile = getCustomLightsXmlFile(); + if (xmlFile != null) { + NodeList nodeList = XmlUtilities.getNodeList("//Directionality", Paths.get(path, "Metadata", xmlFile.getName())); + + ArrayList values = new ArrayList<>(); + List VALID_VALUES = Arrays.asList("Omnidirectional", "Directional", "Bidirectional"); + + 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("'%s' element Directionality should have a value of 'Omnidirectional', " + + "'Directional' or 'Bidirectional'. Value '%s' is not valid.", xmlFile.getName(), value)); + } + } + } + private File getCustomLightsXmlFile() { String glob = "glob:Lights_*.xml"; diff --git a/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidDirectionalityValue.xml b/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidDirectionalityValue.xml new file mode 100755 index 0000000..9ac00f0 --- /dev/null +++ b/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidDirectionalityValue.xml @@ -0,0 +1,12 @@ + + + + Tuned for MH-47 CMS + 0.75 + 1.0 0.0 0.0 + INVALID_VALUE + 0.5 + 0.2 + + diff --git a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java index e62f7f2..b405ec6 100644 --- a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java @@ -22,6 +22,7 @@ public class VerifyLightsXxxXmlStructureTests extends MetadataTestFixture Date: Mon, 12 Sep 2016 12:15:01 -0600 Subject: [PATCH 05/14] verify Residual_Intensity has a valid value --- .../LightsXxxXmlStructureTests.java | 30 +++++++++++++--- ...entInvalidResidual_IntensityOutOfRange.xml | 24 +++++++++++++ .../VerifyLightsXxxXmlStructureTests.java | 34 ++++++++++++++++--- 3 files changed, 79 insertions(+), 9 deletions(-) create mode 100755 src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidResidual_IntensityOutOfRange.xml diff --git a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java index 182e554..b03ef4b 100644 --- a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java @@ -36,7 +36,6 @@ public void verifyLightsTuningXsdFFileExists() { File xmlFile = getCustomLightsXmlFile(); if (xmlFile != null) { - System.out.println("here"); 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."); } @@ -67,13 +66,13 @@ public void verifyLightsXxxXmlElementIntensityIsInRange() { Node currentItem = intensityNodes.item(i); Float value = Float.parseFloat(currentItem.getTextContent()); - if (value >= 0.0 && value <= 1.0) { + if (value < 0.0 || value > 1.0) { invalidIntensityValues.add(currentItem.getTextContent()); } } - Assert.assertEquals(intensityNodes.getLength(), 0, - String.format("'%s' Intensity elements value can range from 0.0 to 1.0. %s", + Assert.assertEquals(invalidIntensityValues.size(), 0, + String.format("'%s' Intensity elements value can range from 0.0 to 1.0. Values %s are not valid.", xmlFile.getName().toString(), invalidIntensityValues.toString())); } } @@ -100,6 +99,29 @@ public void verifyLightsXxxXmlDirectionalityValueIsValid() { } } + @Test + public void verifyLightsXxxXmlElementResidualIntensityIsInRange() { + File xmlFile = getCustomLightsXmlFile(); + if (xmlFile != null) { + NodeList intensityNodes = XmlUtilities.getNodeList("//Residual_Intensity", Paths.get(path, "Metadata", xmlFile.getName())); + + ArrayList invalidResidualIntensityValues = new ArrayList<>(); + + for (int i = 0; i < intensityNodes.getLength(); i++) { + Node currentItem = intensityNodes.item(i); + Float value = Float.parseFloat(currentItem.getTextContent()); + + if (value < 0.0 || value > 1.0) { + invalidResidualIntensityValues.add(currentItem.getTextContent()); + } + } + + Assert.assertEquals(invalidResidualIntensityValues.size(), 0, + String.format("'%s' Residual_Intensity elements value can range from 0.0 to 1.0. Values %s are not valid.", + xmlFile.getName().toString(), invalidResidualIntensityValues.toString())); + } + } + private File getCustomLightsXmlFile() { String glob = "glob:Lights_*.xml"; diff --git a/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidResidual_IntensityOutOfRange.xml b/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidResidual_IntensityOutOfRange.xml new file mode 100755 index 0000000..27ca4ed --- /dev/null +++ b/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidResidual_IntensityOutOfRange.xml @@ -0,0 +1,24 @@ + + + + Tuned for MH-47 CMS + 0.75 + 1.0 0.0 0.0 + Omnidirectional + -0.1 + 0.5 + 0.2 + + + ... + 1.0 + 1.0 0.9 0.9 + Directional + 1.01 + + 1.1 + 1.5 + + + diff --git a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java index b405ec6..79064c4 100644 --- a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java @@ -22,7 +22,8 @@ public class VerifyLightsXxxXmlStructureTests extends MetadataTestFixture Date: Mon, 12 Sep 2016 12:28:39 -0600 Subject: [PATCH 06/14] verify Duty_Cycle has valid values and refactored common code to find invalid values to a method --- .../LightsXxxXmlStructureTests.java | 73 ++++++++++--------- ...ghts_ClientInvalidDuty_CycleOutOfRange.xml | 24 ++++++ .../VerifyLightsXxxXmlStructureTests.java | 27 ++++++- 3 files changed, 90 insertions(+), 34 deletions(-) create mode 100755 src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidDuty_CycleOutOfRange.xml diff --git a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java index b03ef4b..073820e 100644 --- a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java @@ -55,28 +55,6 @@ public void verifyLightsXxxXmlAgainstSchema() throws IOException, SAXException { } } - public void verifyLightsXxxXmlElementIntensityIsInRange() { - File xmlFile = getCustomLightsXmlFile(); - if (xmlFile != null) { - NodeList intensityNodes = XmlUtilities.getNodeList("//Intensity", Paths.get(path, "Metadata", xmlFile.getName())); - - ArrayList invalidIntensityValues = new ArrayList<>(); - - for (int i = 0; i < intensityNodes.getLength(); i++) { - Node currentItem = intensityNodes.item(i); - Float value = Float.parseFloat(currentItem.getTextContent()); - - if (value < 0.0 || value > 1.0) { - invalidIntensityValues.add(currentItem.getTextContent()); - } - } - - Assert.assertEquals(invalidIntensityValues.size(), 0, - String.format("'%s' Intensity elements value can range from 0.0 to 1.0. Values %s are not valid.", - xmlFile.getName().toString(), invalidIntensityValues.toString())); - } - } - @Test public void verifyLightsXxxXmlDirectionalityValueIsValid() { File xmlFile = getCustomLightsXmlFile(); @@ -100,21 +78,22 @@ public void verifyLightsXxxXmlDirectionalityValueIsValid() { } @Test - public void verifyLightsXxxXmlElementResidualIntensityIsInRange() { + public void verifyLightsXxxXmlElementIntensityIsInRange() { File xmlFile = getCustomLightsXmlFile(); if (xmlFile != null) { - NodeList intensityNodes = XmlUtilities.getNodeList("//Residual_Intensity", Paths.get(path, "Metadata", xmlFile.getName())); - - ArrayList invalidResidualIntensityValues = new ArrayList<>(); + ArrayList invalidIntensityValues = getInvalidValues(xmlFile, "//Intensity"); - for (int i = 0; i < intensityNodes.getLength(); i++) { - Node currentItem = intensityNodes.item(i); - Float value = Float.parseFloat(currentItem.getTextContent()); + Assert.assertEquals(invalidIntensityValues.size(), 0, + String.format("'%s' Intensity elements value can range from 0.0 to 1.0. Values %s are not valid.", + xmlFile.getName().toString(), invalidIntensityValues.toString())); + } + } - if (value < 0.0 || value > 1.0) { - invalidResidualIntensityValues.add(currentItem.getTextContent()); - } - } + @Test + public void verifyLightsXxxXmlElementResidualIntensityIsInRange() { + File xmlFile = getCustomLightsXmlFile(); + if (xmlFile != null) { + ArrayList invalidResidualIntensityValues = getInvalidValues(xmlFile, "//Residual_Intensity"); Assert.assertEquals(invalidResidualIntensityValues.size(), 0, String.format("'%s' Residual_Intensity elements value can range from 0.0 to 1.0. Values %s are not valid.", @@ -122,6 +101,34 @@ public void verifyLightsXxxXmlElementResidualIntensityIsInRange() { } } + @Test + public void verifyLightsXxxXmlElementDuty_CycleIsInRange() { + File xmlFile = getCustomLightsXmlFile(); + if (xmlFile != null) { + ArrayList invalidResidualIntensityValues = getInvalidValues(xmlFile, "//Duty_Cycle"); + + Assert.assertEquals(invalidResidualIntensityValues.size(), 0, + String.format("'%s' Duty_Cycle elements value can range from 0.0 to 1.0. Values %s are not valid.", + xmlFile.getName().toString(), invalidResidualIntensityValues.toString())); + } + } + + private ArrayList getInvalidValues(File xmlFile, String nodeToSearchFor) { + NodeList intensityNodes = XmlUtilities.getNodeList(nodeToSearchFor, Paths.get(path, "Metadata", xmlFile.getName())); + + ArrayList invalidResidualIntensityValues = new ArrayList<>(); + + for (int i = 0; i < intensityNodes.getLength(); i++) { + Node currentItem = intensityNodes.item(i); + Float value = Float.parseFloat(currentItem.getTextContent()); + + if (value < 0.0 || value > 1.0) { + invalidResidualIntensityValues.add(currentItem.getTextContent()); + } + } + return invalidResidualIntensityValues; + } + private File getCustomLightsXmlFile() { String glob = "glob:Lights_*.xml"; diff --git a/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidDuty_CycleOutOfRange.xml b/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidDuty_CycleOutOfRange.xml new file mode 100755 index 0000000..0d59c47 --- /dev/null +++ b/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidDuty_CycleOutOfRange.xml @@ -0,0 +1,24 @@ + + + + Tuned for MH-47 CMS + 0.75 + 1.0 0.0 0.0 + Omnidirectional + 0.5 + -0.1 + + + ... + 1.0 + 1.0 0.9 0.9 + Directional + 0.05 + 1.01 + + 1.1 + 1.5 + + + diff --git a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java index 79064c4..69a3722 100644 --- a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java @@ -21,9 +21,10 @@ public class VerifyLightsXxxXmlStructureTests extends MetadataTestFixture Date: Mon, 12 Sep 2016 12:50:03 -0600 Subject: [PATCH 07/14] verify Frequency has a valid value --- .../LightsXxxXmlStructureTests.java | 35 +++++++++++++++---- .../Lights_ClientInvalidFrequencyValue.xml | 12 +++++++ .../VerifyLightsXxxXmlStructureTests.java | 26 ++++++++++++++ 3 files changed, 67 insertions(+), 6 deletions(-) create mode 100755 src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidFrequencyValue.xml diff --git a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java index 073820e..4229034 100644 --- a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java @@ -113,20 +113,43 @@ public void verifyLightsXxxXmlElementDuty_CycleIsInRange() { } } + @Test + public void verifyLightsXxxXmlFrequencyValueIsValid() { + File xmlFile = getCustomLightsXmlFile(); + if (xmlFile != null) { + NodeList frequencyNodes = XmlUtilities.getNodeList("//Frequency", Paths.get(path, "Metadata", xmlFile.getName())); + + ArrayList invalidFrequencyValues = new ArrayList<>(); + + for (int i = 0; i < frequencyNodes.getLength(); i++) { + Node currentItem = frequencyNodes.item(i); + Float value = Float.parseFloat(currentItem.getTextContent()); + + if (value < 0.0) { + invalidFrequencyValues.add(currentItem.getTextContent()); + } + } + + Assert.assertEquals(invalidFrequencyValues.size(), 0, + String.format("'%s' Duty_Cycle elements value can range from 0.0 to 1.0. Values %s are not valid.", + xmlFile.getName().toString(), invalidFrequencyValues.toString())); + } + } + private ArrayList getInvalidValues(File xmlFile, String nodeToSearchFor) { - NodeList intensityNodes = XmlUtilities.getNodeList(nodeToSearchFor, Paths.get(path, "Metadata", xmlFile.getName())); + NodeList nodes = XmlUtilities.getNodeList(nodeToSearchFor, Paths.get(path, "Metadata", xmlFile.getName())); - ArrayList invalidResidualIntensityValues = new ArrayList<>(); + ArrayList invalidValues = new ArrayList<>(); - for (int i = 0; i < intensityNodes.getLength(); i++) { - Node currentItem = intensityNodes.item(i); + for (int i = 0; i < nodes.getLength(); i++) { + Node currentItem = nodes.item(i); Float value = Float.parseFloat(currentItem.getTextContent()); if (value < 0.0 || value > 1.0) { - invalidResidualIntensityValues.add(currentItem.getTextContent()); + invalidValues.add(currentItem.getTextContent()); } } - return invalidResidualIntensityValues; + return invalidValues; } private File getCustomLightsXmlFile() { diff --git a/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidFrequencyValue.xml b/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidFrequencyValue.xml new file mode 100755 index 0000000..ec31970 --- /dev/null +++ b/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidFrequencyValue.xml @@ -0,0 +1,12 @@ + + + + Tuned for MH-47 CMS + 0.75 + 1.0 0.0 0.0 + Omnidirectional + -0.1 + 0.2 + + diff --git a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java index 69a3722..fb23588 100644 --- a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java @@ -22,6 +22,7 @@ public class VerifyLightsXxxXmlStructureTests extends MetadataTestFixture Date: Mon, 12 Sep 2016 13:12:54 -0600 Subject: [PATCH 08/14] check if Color element has valid values --- .../LightsXxxXmlStructureTests.java | 32 ++++++++++++++++++- ...ts_ClientInvalidColorValueIsOutOfRange.xml | 12 +++++++ .../VerifyLightsXxxXmlStructureTests.java | 24 ++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) create mode 100755 src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidColorValueIsOutOfRange.xml diff --git a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java index 4229034..9fc94db 100644 --- a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java @@ -136,6 +136,32 @@ public void verifyLightsXxxXmlFrequencyValueIsValid() { } } + @Test + public void verifyLightsXxxXmlColorIsInRange() { + File xmlFile = getCustomLightsXmlFile(); + if (xmlFile != null) { + NodeList frequencyNodes = XmlUtilities.getNodeList("//Color", Paths.get(path, "Metadata", xmlFile.getName())); + + ArrayList invalidColorValues = new ArrayList<>(); + + for (int i = 0; i < frequencyNodes.getLength(); i++) { + Node currentItem = frequencyNodes.item(i); + String[] values = currentItem.getTextContent().split("\\s+"); + + for (String value : values) { + Float floatValue = Float.parseFloat(value); + if (valueIsOutOfRange(floatValue)) { + invalidColorValues.add(floatValue.toString()); + } + } + } + + Assert.assertEquals(invalidColorValues.size(), 0, + String.format("'%s' Duty_Cycle elements value can range from 0.0 to 1.0. Values %s are not valid.", + xmlFile.getName().toString(), invalidColorValues.toString())); + } + } + private ArrayList getInvalidValues(File xmlFile, String nodeToSearchFor) { NodeList nodes = XmlUtilities.getNodeList(nodeToSearchFor, Paths.get(path, "Metadata", xmlFile.getName())); @@ -145,13 +171,17 @@ private ArrayList getInvalidValues(File xmlFile, String nodeToSearchFor) Node currentItem = nodes.item(i); Float value = Float.parseFloat(currentItem.getTextContent()); - if (value < 0.0 || value > 1.0) { + if (valueIsOutOfRange(value)) { invalidValues.add(currentItem.getTextContent()); } } return invalidValues; } + private boolean valueIsOutOfRange(Float value) { + return value < 0.0 || value > 1.0; + } + private File getCustomLightsXmlFile() { String glob = "glob:Lights_*.xml"; diff --git a/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidColorValueIsOutOfRange.xml b/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidColorValueIsOutOfRange.xml new file mode 100755 index 0000000..397b8c9 --- /dev/null +++ b/src/test/java/org/opengis/cite/cdb10/fixtures/invalid/Lights_ClientInvalidColorValueIsOutOfRange.xml @@ -0,0 +1,12 @@ + + + + Tuned for MH-47 CMS + 0.75 + 1.1 0.0 -0.1 + Omnidirectional + 0.5 + 0.2 + + diff --git a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java index fb23588..d0874ec 100644 --- a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java @@ -26,6 +26,7 @@ public class VerifyLightsXxxXmlStructureTests extends MetadataTestFixture Date: Mon, 12 Sep 2016 13:31:42 -0600 Subject: [PATCH 09/14] check if the file exists if not that is ok --- .../cdb10/CDBStructure/LightsXxxXmlStructureTests.java | 9 +++++++++ .../cdb10/level1/VerifyLightsXxxXmlStructureTests.java | 6 ++++++ 2 files changed, 15 insertions(+) diff --git a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java index 9fc94db..b9549ba 100644 --- a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java @@ -20,6 +20,15 @@ */ public class LightsXxxXmlStructureTests extends CommonFixture { + @Test + public void verifyLights_XxxXmlFileExists() { + File xmlFile = getCustomLightsXmlFile(); + + if (xmlFile != null) { + Assert.assertTrue(Files.exists(Paths.get(path, "Metadata", "Schema", xmlFile.getName())), "Optional file."); + } + } + @Test public void verifyLightsXmlFileNameIsValid() { File xmlFile = getCustomLightsXmlFile(); diff --git a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java index d0874ec..9a0c5d7 100644 --- a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java @@ -78,6 +78,12 @@ public void verifyLightsTuningXsdFileExists_DoesExist() throws IOException { testSuite.verifyLightsTuningXsdFFileExists(); } + @Test + public void verifyLights_XxxXmlFileExists_DoesNotExist() throws IOException { + // execute + testSuite.verifyLights_XxxXmlFileExists(); + } + @Test public void verifyLightsXxxXmlAgainstSchema_XmlIsValid() throws IOException, SAXException { // setup From da976d9b7d4feab24f25fb75f22b2431eed82435 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Mon, 12 Sep 2016 14:16:06 -0600 Subject: [PATCH 10/14] Refactor into smaller methods --- .../LightsXxxXmlStructureTests.java | 148 ++++++++++-------- 1 file changed, 82 insertions(+), 66 deletions(-) diff --git a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java index b9549ba..55105c9 100644 --- a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java @@ -20,6 +20,8 @@ */ public class LightsXxxXmlStructureTests extends CommonFixture { + private static final List DIRECTIONALITY_VALUES = Arrays.asList("Omnidirectional", "Directional", "Bidirectional"); + @Test public void verifyLights_XxxXmlFileExists() { File xmlFile = getCustomLightsXmlFile(); @@ -68,18 +70,10 @@ public void verifyLightsXxxXmlAgainstSchema() throws IOException, SAXException { public void verifyLightsXxxXmlDirectionalityValueIsValid() { File xmlFile = getCustomLightsXmlFile(); if (xmlFile != null) { - NodeList nodeList = XmlUtilities.getNodeList("//Directionality", Paths.get(path, "Metadata", xmlFile.getName())); - - ArrayList values = new ArrayList<>(); - List VALID_VALUES = Arrays.asList("Omnidirectional", "Directional", "Bidirectional"); + ArrayList directionalityValues = getDirectionalityValues(xmlFile); - 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), + for (String value : directionalityValues) { + Assert.assertTrue(DIRECTIONALITY_VALUES.contains(value), String.format("'%s' element Directionality should have a value of 'Omnidirectional', " + "'Directional' or 'Bidirectional'. Value '%s' is not valid.", xmlFile.getName(), value)); } @@ -90,11 +84,11 @@ public void verifyLightsXxxXmlDirectionalityValueIsValid() { public void verifyLightsXxxXmlElementIntensityIsInRange() { File xmlFile = getCustomLightsXmlFile(); if (xmlFile != null) { - ArrayList invalidIntensityValues = getInvalidValues(xmlFile, "//Intensity"); + ArrayList invalidIntensityValues = getInvalidPercentageValues(xmlFile, "//Intensity"); Assert.assertEquals(invalidIntensityValues.size(), 0, String.format("'%s' Intensity elements value can range from 0.0 to 1.0. Values %s are not valid.", - xmlFile.getName().toString(), invalidIntensityValues.toString())); + xmlFile.getName(), invalidIntensityValues.toString())); } } @@ -102,11 +96,11 @@ public void verifyLightsXxxXmlElementIntensityIsInRange() { public void verifyLightsXxxXmlElementResidualIntensityIsInRange() { File xmlFile = getCustomLightsXmlFile(); if (xmlFile != null) { - ArrayList invalidResidualIntensityValues = getInvalidValues(xmlFile, "//Residual_Intensity"); + ArrayList invalidResidualIntensityValues = getInvalidPercentageValues(xmlFile, "//Residual_Intensity"); Assert.assertEquals(invalidResidualIntensityValues.size(), 0, String.format("'%s' Residual_Intensity elements value can range from 0.0 to 1.0. Values %s are not valid.", - xmlFile.getName().toString(), invalidResidualIntensityValues.toString())); + xmlFile.getName(), invalidResidualIntensityValues.toString())); } } @@ -114,11 +108,11 @@ public void verifyLightsXxxXmlElementResidualIntensityIsInRange() { public void verifyLightsXxxXmlElementDuty_CycleIsInRange() { File xmlFile = getCustomLightsXmlFile(); if (xmlFile != null) { - ArrayList invalidResidualIntensityValues = getInvalidValues(xmlFile, "//Duty_Cycle"); + ArrayList invalidResidualIntensityValues = getInvalidPercentageValues(xmlFile, "//Duty_Cycle"); Assert.assertEquals(invalidResidualIntensityValues.size(), 0, String.format("'%s' Duty_Cycle elements value can range from 0.0 to 1.0. Values %s are not valid.", - xmlFile.getName().toString(), invalidResidualIntensityValues.toString())); + xmlFile.getName(), invalidResidualIntensityValues.toString())); } } @@ -126,22 +120,11 @@ public void verifyLightsXxxXmlElementDuty_CycleIsInRange() { public void verifyLightsXxxXmlFrequencyValueIsValid() { File xmlFile = getCustomLightsXmlFile(); if (xmlFile != null) { - NodeList frequencyNodes = XmlUtilities.getNodeList("//Frequency", Paths.get(path, "Metadata", xmlFile.getName())); - - ArrayList invalidFrequencyValues = new ArrayList<>(); - - for (int i = 0; i < frequencyNodes.getLength(); i++) { - Node currentItem = frequencyNodes.item(i); - Float value = Float.parseFloat(currentItem.getTextContent()); - - if (value < 0.0) { - invalidFrequencyValues.add(currentItem.getTextContent()); - } - } + ArrayList invalidFrequencyValues = getInvalidFrequencyValues(xmlFile); Assert.assertEquals(invalidFrequencyValues.size(), 0, String.format("'%s' Duty_Cycle elements value can range from 0.0 to 1.0. Values %s are not valid.", - xmlFile.getName().toString(), invalidFrequencyValues.toString())); + xmlFile.getName(), invalidFrequencyValues.toString())); } } @@ -149,46 +132,12 @@ public void verifyLightsXxxXmlFrequencyValueIsValid() { public void verifyLightsXxxXmlColorIsInRange() { File xmlFile = getCustomLightsXmlFile(); if (xmlFile != null) { - NodeList frequencyNodes = XmlUtilities.getNodeList("//Color", Paths.get(path, "Metadata", xmlFile.getName())); - - ArrayList invalidColorValues = new ArrayList<>(); - - for (int i = 0; i < frequencyNodes.getLength(); i++) { - Node currentItem = frequencyNodes.item(i); - String[] values = currentItem.getTextContent().split("\\s+"); - - for (String value : values) { - Float floatValue = Float.parseFloat(value); - if (valueIsOutOfRange(floatValue)) { - invalidColorValues.add(floatValue.toString()); - } - } - } + ArrayList invalidColorValues = getInvalidColorValues(xmlFile); Assert.assertEquals(invalidColorValues.size(), 0, String.format("'%s' Duty_Cycle elements value can range from 0.0 to 1.0. Values %s are not valid.", - xmlFile.getName().toString(), invalidColorValues.toString())); - } - } - - private ArrayList getInvalidValues(File xmlFile, String nodeToSearchFor) { - NodeList nodes = XmlUtilities.getNodeList(nodeToSearchFor, Paths.get(path, "Metadata", xmlFile.getName())); - - ArrayList invalidValues = new ArrayList<>(); - - for (int i = 0; i < nodes.getLength(); i++) { - Node currentItem = nodes.item(i); - Float value = Float.parseFloat(currentItem.getTextContent()); - - if (valueIsOutOfRange(value)) { - invalidValues.add(currentItem.getTextContent()); - } + xmlFile.getName(), invalidColorValues.toString())); } - return invalidValues; - } - - private boolean valueIsOutOfRange(Float value) { - return value < 0.0 || value > 1.0; } private File getCustomLightsXmlFile() { @@ -216,4 +165,71 @@ private File getCustomLightsXmlFile() { return null; } } + + private boolean valueIsOutOfRange(Float value) { + return value < 0.0 || value > 1.0; + } + + private ArrayList getDirectionalityValues(File xmlFile) { + NodeList nodeList = XmlUtilities.getNodeList("//Directionality", Paths.get(path, "Metadata", xmlFile.getName())); + + ArrayList directionalityValues = new ArrayList<>(); + + for (int i = 0; i < nodeList.getLength(); i++) { + Node currentItem = nodeList.item(i); + directionalityValues.add(currentItem.getTextContent()); + } + return directionalityValues; + } + + private ArrayList getInvalidColorValues(File xmlFile) { + NodeList frequencyNodes = XmlUtilities.getNodeList("//Color", Paths.get(path, "Metadata", xmlFile.getName())); + + ArrayList invalidColorValues = new ArrayList<>(); + + for (int i = 0; i < frequencyNodes.getLength(); i++) { + Node currentItem = frequencyNodes.item(i); + String[] values = currentItem.getTextContent().split("\\s+"); + + for (String value : values) { + Float floatValue = Float.parseFloat(value); + if (valueIsOutOfRange(floatValue)) { + invalidColorValues.add(floatValue.toString()); + } + } + } + return invalidColorValues; + } + + private ArrayList getInvalidPercentageValues(File xmlFile, String nodeToSearchFor) { + NodeList nodes = XmlUtilities.getNodeList(nodeToSearchFor, Paths.get(path, "Metadata", xmlFile.getName())); + + ArrayList invalidValues = new ArrayList<>(); + + for (int i = 0; i < nodes.getLength(); i++) { + Node currentItem = nodes.item(i); + Float value = Float.parseFloat(currentItem.getTextContent()); + + if (valueIsOutOfRange(value)) { + invalidValues.add(currentItem.getTextContent()); + } + } + return invalidValues; + } + + private ArrayList getInvalidFrequencyValues(File xmlFile) { + NodeList frequencyNodes = XmlUtilities.getNodeList("//Frequency", Paths.get(path, "Metadata", xmlFile.getName())); + + ArrayList invalidFrequencyValues = new ArrayList<>(); + + for (int i = 0; i < frequencyNodes.getLength(); i++) { + Node currentItem = frequencyNodes.item(i); + Float value = Float.parseFloat(currentItem.getTextContent()); + + if (value < 0.0) { + invalidFrequencyValues.add(currentItem.getTextContent()); + } + } + return invalidFrequencyValues; + } } From d3767aa0ab040ccac6b10b289da6f152f4055e90 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Mon, 12 Sep 2016 14:23:55 -0600 Subject: [PATCH 11/14] redesign to check for multiple custom light files --- .../LightsXxxXmlStructureTests.java | 53 +++++++------------ 1 file changed, 19 insertions(+), 34 deletions(-) diff --git a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java index 55105c9..249cd12 100644 --- a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java @@ -24,29 +24,25 @@ public class LightsXxxXmlStructureTests extends CommonFixture { @Test public void verifyLights_XxxXmlFileExists() { - File xmlFile = getCustomLightsXmlFile(); - - if (xmlFile != null) { + for (File xmlFile : getCustomLightsXmlFiles()) { Assert.assertTrue(Files.exists(Paths.get(path, "Metadata", "Schema", xmlFile.getName())), "Optional file."); } } @Test public void verifyLightsXmlFileNameIsValid() { - File xmlFile = getCustomLightsXmlFile(); - - if (!xmlFile.getName().matches("^Lights_[a-zA-Z0-9_-]{0,25}.xml$")) { - Assert.fail(String.format("'%s' is not a valid file name it must start with 'Lights_', " + - "can only be a maximum of 32 characters and contain letters, numbers, " + - "underscores and dashes.", xmlFile.getName())); + for (File xmlFile : getCustomLightsXmlFiles()) { + if (!xmlFile.getName().matches("^Lights_[a-zA-Z0-9_-]{0,25}.xml$")) { + Assert.fail(String.format("'%s' is not a valid file name it must start with 'Lights_', " + + "can only be a maximum of 32 characters and contain letters, numbers, " + + "underscores and dashes.", xmlFile.getName())); + } } } @Test public void verifyLightsTuningXsdFFileExists() { - File xmlFile = getCustomLightsXmlFile(); - - if (xmlFile != null) { + 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."); } @@ -54,8 +50,7 @@ public void verifyLightsTuningXsdFFileExists() { @Test public void verifyLightsXxxXmlAgainstSchema() throws IOException, SAXException { - File xmlFile = getCustomLightsXmlFile(); - if (xmlFile != null) { + for (File xmlFile : getCustomLightsXmlFiles()) { File xsdFile = Paths.get(path, "Metadata", "Schema", "Lights_Tuning.xsd").toFile(); SchemaValidatorErrorHandler errorHandler = XmlUtilities.validateXmlFileIsValid(xmlFile, xsdFile); @@ -68,8 +63,7 @@ public void verifyLightsXxxXmlAgainstSchema() throws IOException, SAXException { @Test public void verifyLightsXxxXmlDirectionalityValueIsValid() { - File xmlFile = getCustomLightsXmlFile(); - if (xmlFile != null) { + for (File xmlFile : getCustomLightsXmlFiles()) { ArrayList directionalityValues = getDirectionalityValues(xmlFile); for (String value : directionalityValues) { @@ -82,8 +76,7 @@ public void verifyLightsXxxXmlDirectionalityValueIsValid() { @Test public void verifyLightsXxxXmlElementIntensityIsInRange() { - File xmlFile = getCustomLightsXmlFile(); - if (xmlFile != null) { + for (File xmlFile : getCustomLightsXmlFiles()) { ArrayList invalidIntensityValues = getInvalidPercentageValues(xmlFile, "//Intensity"); Assert.assertEquals(invalidIntensityValues.size(), 0, @@ -94,8 +87,7 @@ public void verifyLightsXxxXmlElementIntensityIsInRange() { @Test public void verifyLightsXxxXmlElementResidualIntensityIsInRange() { - File xmlFile = getCustomLightsXmlFile(); - if (xmlFile != null) { + for (File xmlFile : getCustomLightsXmlFiles()) { ArrayList invalidResidualIntensityValues = getInvalidPercentageValues(xmlFile, "//Residual_Intensity"); Assert.assertEquals(invalidResidualIntensityValues.size(), 0, @@ -106,8 +98,7 @@ public void verifyLightsXxxXmlElementResidualIntensityIsInRange() { @Test public void verifyLightsXxxXmlElementDuty_CycleIsInRange() { - File xmlFile = getCustomLightsXmlFile(); - if (xmlFile != null) { + for (File xmlFile : getCustomLightsXmlFiles()) { ArrayList invalidResidualIntensityValues = getInvalidPercentageValues(xmlFile, "//Duty_Cycle"); Assert.assertEquals(invalidResidualIntensityValues.size(), 0, @@ -118,8 +109,7 @@ public void verifyLightsXxxXmlElementDuty_CycleIsInRange() { @Test public void verifyLightsXxxXmlFrequencyValueIsValid() { - File xmlFile = getCustomLightsXmlFile(); - if (xmlFile != null) { + for (File xmlFile : getCustomLightsXmlFiles()) { ArrayList invalidFrequencyValues = getInvalidFrequencyValues(xmlFile); Assert.assertEquals(invalidFrequencyValues.size(), 0, @@ -130,8 +120,7 @@ public void verifyLightsXxxXmlFrequencyValueIsValid() { @Test public void verifyLightsXxxXmlColorIsInRange() { - File xmlFile = getCustomLightsXmlFile(); - if (xmlFile != null) { + for (File xmlFile : getCustomLightsXmlFiles()) { ArrayList invalidColorValues = getInvalidColorValues(xmlFile); Assert.assertEquals(invalidColorValues.size(), 0, @@ -140,18 +129,18 @@ public void verifyLightsXxxXmlColorIsInRange() { } } - private File getCustomLightsXmlFile() { + private List getCustomLightsXmlFiles() { String glob = "glob:Lights_*.xml"; final PathMatcher pathMatcher = FileSystems.getDefault().getPathMatcher(glob); - List files = new ArrayList<>(); + List lightsXmlFiles = new ArrayList<>(); try { DirectoryStream stream = Files.newDirectoryStream(Paths.get(path, "Metadata")); for (Path entry : stream) { if (pathMatcher.matches(entry.getFileName())) { - files.add(String.valueOf(entry.getFileName())); + lightsXmlFiles.add(entry.toFile()); } } stream.close(); @@ -159,11 +148,7 @@ private File getCustomLightsXmlFile() { e.printStackTrace(); } - if (files.size() > 0) { - return Paths.get(path, "Metadata", files.get(0)).toFile(); - } else { - return null; - } + return lightsXmlFiles; } private boolean valueIsOutOfRange(Float value) { From cc01be9e1f277fa3c87e8ec771240fa4b5fe82a7 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Mon, 12 Sep 2016 14:58:54 -0600 Subject: [PATCH 12/14] check file name with multiple files --- .../LightsXxxXmlStructureTests.java | 12 +++++-- .../VerifyLightsXxxXmlStructureTests.java | 31 ++++++++++++++++++- 2 files changed, 39 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java index 249cd12..5433cc5 100644 --- a/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java +++ b/src/main/java/org/opengis/cite/cdb10/CDBStructure/LightsXxxXmlStructureTests.java @@ -31,13 +31,19 @@ public void verifyLights_XxxXmlFileExists() { @Test public void verifyLightsXmlFileNameIsValid() { + ArrayList invalidFileNames = new ArrayList<>(); + for (File xmlFile : getCustomLightsXmlFiles()) { if (!xmlFile.getName().matches("^Lights_[a-zA-Z0-9_-]{0,25}.xml$")) { - Assert.fail(String.format("'%s' is not a valid file name it must start with 'Lights_', " + - "can only be a maximum of 32 characters and contain letters, numbers, " + - "underscores and dashes.", xmlFile.getName())); + invalidFileNames.add(xmlFile.getName()); } } + + if (invalidFileNames.size() > 0) { + Assert.fail(String.format("%s are not a valid file name(s) the file name must start with 'Lights_', " + + "can only be a maximum of 32 characters and contain letters, numbers, " + + "underscores and dashes.", invalidFileNames.toString())); + } } @Test diff --git a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java index 9a0c5d7..b858142 100644 --- a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java @@ -37,7 +37,7 @@ public void verifyLightsXmlFileNameIsValid_IsNotValid() throws Exception { //setup Files.createFile(metadataFolder.resolve(Paths.get("Lights_123451234512345123451234512345.xml"))); - String expectedMessage = "'Lights_123451234512345123451234512345.xml' is not a valid file name it must start " + + String expectedMessage = "[Lights_123451234512345123451234512345.xml] are not a valid file name(s) the file name must start " + "with 'Lights_', can only be a maximum of 32 characters and contain letters, numbers, underscores and dashes."; expectedException.expect(AssertionError.class); @@ -56,6 +56,35 @@ public void verifyLightsXmlFileNameIsValid_IsValid() throws IOException { testSuite.verifyLightsXmlFileNameIsValid(); } + + @Test + public void verifyLightsXmlFileNameIsValidWithMultipleFiles_IsNotValid() throws Exception { + //setup + Files.createFile(metadataFolder.resolve(Paths.get("Lights_123451234512345123451234512345_example1.xml"))); + Files.createFile(metadataFolder.resolve(Paths.get("Lights_123451234512345123451234512345_example2.xml"))); + + String expectedMessage = "[Lights_123451234512345123451234512345_example1.xml, " + + "Lights_123451234512345123451234512345_example2.xml] are not a valid file name(s) the file name must start with " + + "'Lights_', can only be a maximum of 32 characters and contain letters, numbers, underscores and dashes."; + + expectedException.expect(AssertionError.class); + expectedException.expectMessage(expectedMessage); + + // execute + testSuite.verifyLightsXmlFileNameIsValid(); + } + + @Test + public void verifyLightsXmlFileNameIsValidWithMultipleFiles_IsValid() throws IOException { + //setup + Files.createFile(metadataFolder.resolve(Paths.get("Lights_Client_example1.xml"))); + Files.createFile(metadataFolder.resolve(Paths.get("Lights_Client_example2.xml"))); + + // execute + testSuite.verifyLightsXmlFileNameIsValid(); + } + + @Test public void verifyLightsTuningXsdFileExists_DoesNotExist() throws IOException { //setup From 4171499c075b387bf65e2cebe9d10af4c2e06446 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Mon, 12 Sep 2016 15:03:09 -0600 Subject: [PATCH 13/14] remove spaces --- .../cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java index b858142..9f3a831 100644 --- a/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java +++ b/src/test/java/org/opengis/cite/cdb10/level1/VerifyLightsXxxXmlStructureTests.java @@ -56,7 +56,6 @@ public void verifyLightsXmlFileNameIsValid_IsValid() throws IOException { testSuite.verifyLightsXmlFileNameIsValid(); } - @Test public void verifyLightsXmlFileNameIsValidWithMultipleFiles_IsNotValid() throws Exception { //setup @@ -84,7 +83,6 @@ public void verifyLightsXmlFileNameIsValidWithMultipleFiles_IsValid() throws IOE testSuite.verifyLightsXmlFileNameIsValid(); } - @Test public void verifyLightsTuningXsdFileExists_DoesNotExist() throws IOException { //setup From d82c23f1b376c723162d7617375a91e20d27c0b9 Mon Sep 17 00:00:00 2001 From: martinechtner Date: Tue, 13 Sep 2016 16:36:39 -0600 Subject: [PATCH 14/14] Change text on web form --- src/main/scripts/ctl/cdb10-suite.ctl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scripts/ctl/cdb10-suite.ctl b/src/main/scripts/ctl/cdb10-suite.ctl index 07bfa16..0a6c6f6 100644 --- a/src/main/scripts/ctl/cdb10-suite.ctl +++ b/src/main/scripts/ctl/cdb10-suite.ctl @@ -60,7 +60,7 @@ - +