From c2ad533cfaf8271ee934349bf483dbe0f1761627 Mon Sep 17 00:00:00 2001 From: Shane StClair Date: Sat, 23 Aug 2014 10:48:29 -0700 Subject: [PATCH 1/3] Name parameterized tests and upgrade jUnit to 4.11 --- pom.xml | 1 + .../com/asascience/ncsos/DSNetworkTest.java | 26 +++++++----- .../com/asascience/ncsos/DSPlatformTest.java | 10 +++-- .../java/com/asascience/ncsos/GCBaseTest.java | 12 ++++-- .../com/asascience/ncsos/GOBaseGridTest.java | 29 +++++++++---- .../asascience/ncsos/GOBasePlatformTest.java | 42 +++++++++++++------ .../java/com/asascience/ncsos/NcSOSTest.java | 12 ++++++ 7 files changed, 92 insertions(+), 40 deletions(-) diff --git a/pom.xml b/pom.xml index 38a2d5c..9fd32c5 100644 --- a/pom.xml +++ b/pom.xml @@ -62,6 +62,7 @@ junit junit + 4.11 test diff --git a/src/test/java/com/asascience/ncsos/DSNetworkTest.java b/src/test/java/com/asascience/ncsos/DSNetworkTest.java index 5334ed7..9e26fa1 100644 --- a/src/test/java/com/asascience/ncsos/DSNetworkTest.java +++ b/src/test/java/com/asascience/ncsos/DSNetworkTest.java @@ -1,19 +1,18 @@ package com.asascience.ncsos; -import com.asascience.ncsos.util.XMLDomUtils; -import junit.framework.Assert; -import org.jdom.Element; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; -import org.junit.runners.Parameterized.Parameters; - import java.io.File; import java.net.URLEncoder; import java.util.Arrays; import java.util.Collection; import java.util.HashMap; +import org.jdom.Element; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; + @RunWith(Parameterized.class) public class DSNetworkTest extends NcSOSTest { @@ -23,9 +22,11 @@ public class DSNetworkTest extends NcSOSTest { private Element currentFile; private String authority; - public DSNetworkTest(Element file, String authority){ + + public DSNetworkTest(Element file, String authority, String testLabel){ this.currentFile = file; this.authority = authority; + //discard testLabel } public static void setUpClass() throws Exception { @@ -46,16 +47,19 @@ public static void setUpClass() throws Exception { } // Create the parameters for the test constructor - @Parameters +// @Parameters(name = "{index}: {2}") + @Parameters(name = "{index}: {2}") public static Collection testCases() throws Exception { setUpClass(); - Object[][] data = new Object[fileElements.size()][2]; + Object[][] data = new Object[fileElements.size()][3]; int curIndex = 0; String authority; for (Element e : fileElements) { data[curIndex][0] = e; authority = e.getAttributeValue("authority","ncsos"); // "ncsos" is the default authority in NcSOS data[curIndex][1] = authority; + //label for parameterized test + data[curIndex][2] = getTestLabel(e); curIndex++; } return Arrays.asList(data); diff --git a/src/test/java/com/asascience/ncsos/DSPlatformTest.java b/src/test/java/com/asascience/ncsos/DSPlatformTest.java index 0112add..02a2f52 100644 --- a/src/test/java/com/asascience/ncsos/DSPlatformTest.java +++ b/src/test/java/com/asascience/ncsos/DSPlatformTest.java @@ -1,6 +1,6 @@ package com.asascience.ncsos; -import junit.framework.Assert; +import org.junit.Assert; import org.jdom.Element; import org.junit.Test; import org.junit.runner.RunWith; @@ -20,9 +20,10 @@ public class DSPlatformTest extends NcSOSTest { private Element currentFile; private String procedure; - public DSPlatformTest(Element file, String procedure) { + public DSPlatformTest(Element file, String procedure, String testLabel) { this.currentFile = file; this.procedure = procedure; + //discard testLabel } public static void setUpClass() throws Exception { @@ -43,7 +44,7 @@ public static void setUpClass() throws Exception { } // Create the parameters for the test constructor - @Parameters + @Parameters(name = "{index}: {2}") public static Collection testCases() throws Exception { setUpClass(); @@ -58,12 +59,13 @@ public static Collection testCases() throws Exception { } } - Object[][] data = new Object[nonGrids][2]; + Object[][] data = new Object[nonGrids][3]; int curIndex = 0; for (Element e : fileElements) { for (Element p : (List) e.getChildren("platform")) { data[curIndex][0] = e; data[curIndex][1] = p.getAttributeValue("id"); + data[curIndex][2] = getTestLabel(e); curIndex++; } } diff --git a/src/test/java/com/asascience/ncsos/GCBaseTest.java b/src/test/java/com/asascience/ncsos/GCBaseTest.java index 9612dc2..b76510b 100644 --- a/src/test/java/com/asascience/ncsos/GCBaseTest.java +++ b/src/test/java/com/asascience/ncsos/GCBaseTest.java @@ -1,10 +1,11 @@ package com.asascience.ncsos; -import junit.framework.Assert; +import org.junit.Assert; import org.jdom.Element; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; import java.io.File; import java.util.Arrays; @@ -19,8 +20,9 @@ public class GCBaseTest extends NcSOSTest { private static String exampleDir; private Element currentFile; - public GCBaseTest(Element file){ + public GCBaseTest(Element file, String testLabel){ this.currentFile = file; + //discard testLabel } public static void setUpClass() throws Exception { @@ -39,13 +41,15 @@ public static void setUpClass() throws Exception { } // Create the parameters for the test constructor - @Parameterized.Parameters + @Parameters(name = "{index}: {1}") public static Collection testCases() throws Exception { setUpClass(); - Object[][] data = new Object[fileElements.size()][1]; + Object[][] data = new Object[fileElements.size()][2]; int curIndex = 0; for (Element e : fileElements) { data[curIndex][0] = e; + //include test label + data[curIndex][1] = getTestLabel(e); curIndex++; } return Arrays.asList(data); diff --git a/src/test/java/com/asascience/ncsos/GOBaseGridTest.java b/src/test/java/com/asascience/ncsos/GOBaseGridTest.java index d2f1dcb..f71a63c 100644 --- a/src/test/java/com/asascience/ncsos/GOBaseGridTest.java +++ b/src/test/java/com/asascience/ncsos/GOBaseGridTest.java @@ -1,6 +1,6 @@ package com.asascience.ncsos; -import junit.framework.Assert; +import org.junit.Assert; import org.jdom.Element; import org.junit.Test; import org.junit.runner.RunWith; @@ -25,7 +25,8 @@ public class GOBaseGridTest extends NcSOSTest { private String latitude; private String longitude; private String observedProperty; - public GOBaseGridTest(Element file, String offering, String procedure, String observedProperty, String latitude, String longitude, String testType) { + public GOBaseGridTest(Element file, String offering, String procedure, String observedProperty, + String latitude, String longitude, String testType, String testLabel) { this.currentFile = file; this.offering = offering; this.procedure = procedure; @@ -57,7 +58,7 @@ public static void setUpClass() throws Exception { } // Create the parameters for the test constructor - @Parameters + @Parameters(name = "{index}: {7}") public static Collection testCases() throws Exception { setUpClass(); @@ -73,13 +74,13 @@ public static Collection testCases() throws Exception { } } - Object[][] data = new Object[grids*3][7]; + Object[][] data = new Object[grids*3][8]; int curIndex = 0; for (Element e : fileElements) { String authority = e.getAttributeValue("authority","ncsos"); String networkOffering = "urn:ioos:network:" + authority + ":all"; - + String testType; for (Element s : (List) e.getChildren("sensor")) { String standard = s.getAttributeValue("standard"); @@ -99,7 +100,11 @@ public static Collection testCases() throws Exception { data[curIndex][3] = standard; data[curIndex][4] = lat; data[curIndex][5] = lon; - data[curIndex][6] = "grid0_offering_grid0_procedure" + lat + lon; + testType = "grid0_offering_grid0_procedure" + lat + lon; + data[curIndex][6] = testType; + //include test label + data[curIndex][7] = getTestLabel(e, testType); + curIndex++; // A request with the offering as network:all data[curIndex][0] = e; @@ -108,8 +113,12 @@ public static Collection testCases() throws Exception { data[curIndex][3] = standard; data[curIndex][4] = lat; data[curIndex][5] = lon; - data[curIndex][6] = "network_offering_grid0_procedure" + lat + lon; + testType = "network_offering_grid0_procedure" + lat + lon; + data[curIndex][6] = testType; + //include test label + data[curIndex][7] = getTestLabel(e, testType); curIndex++; + // A request with only the offering data[curIndex][0] = e; data[curIndex][1] = "urn:ioos:station:" + authority + ":Grid0"; @@ -117,7 +126,11 @@ public static Collection testCases() throws Exception { data[curIndex][3] = standard; data[curIndex][4] = lat; data[curIndex][5] = lon; - data[curIndex][6] = "grid0_offering_no_procedure" + lat + lon; + testType = "grid0_offering_no_procedure" + lat + lon; + data[curIndex][6] = testType; + //include test label + data[curIndex][7] = getTestLabel(e, testType); + curIndex++; } } diff --git a/src/test/java/com/asascience/ncsos/GOBasePlatformTest.java b/src/test/java/com/asascience/ncsos/GOBasePlatformTest.java index 576c49a..c30c2e0 100644 --- a/src/test/java/com/asascience/ncsos/GOBasePlatformTest.java +++ b/src/test/java/com/asascience/ncsos/GOBasePlatformTest.java @@ -1,6 +1,6 @@ package com.asascience.ncsos; -import junit.framework.Assert; +import org.junit.Assert; import org.apache.commons.lang.StringUtils; import org.jdom.Element; @@ -27,13 +27,14 @@ public class GOBasePlatformTest extends NcSOSTest { private String offering; private String testType; private String observedProperty; - public GOBasePlatformTest(Element file, String offering, String procedure, String observedProperty, String testType) { + public GOBasePlatformTest(Element file, String offering, String procedure, String observedProperty, + String testType, String testLabel) { this.currentFile = file; this.procedure = procedure; this.offering = offering; this.observedProperty = observedProperty; this.testType = testType; - + //discard testLabel } public static void setUpClass() throws Exception { @@ -54,7 +55,7 @@ public static void setUpClass() throws Exception { } // Create the parameters for the test constructor - @Parameters + @Parameters(name = "{index}: {5}") public static Collection testCases() throws Exception { setUpClass(); @@ -72,9 +73,10 @@ public static Collection testCases() throws Exception { } } - Object[][] data = new Object[nonGrids][5]; + Object[][] data = new Object[nonGrids][6]; int curIndex = 0; List observedPropertyList; + for (Element e : fileElements) { String networkOffering = "urn:ioos:network:" + e.getAttributeValue("authority","ncsos") + ":all"; @@ -84,7 +86,7 @@ public static Collection testCases() throws Exception { String procedure = p.getAttributeValue("id"); String offering = procedure; observedPropertyList = new ArrayList(); - + String testType; for (Element s : (List) p.getChildren("sensor")) { // Keep track of the observedProperties so we can make a request // with all of them outside of this forloop. @@ -99,21 +101,27 @@ public static Collection testCases() throws Exception { data[curIndex][1] = offering; data[curIndex][2] = procedure; data[curIndex][3] = observedProperty; - data[curIndex][4] = "platform_offering_platform_procedure"; + testType = "platform_offering_platform_procedure"; + data[curIndex][4] = testType; + data[curIndex][5] = getTestLabel(e, testType); curIndex++; // A request with the offering as network:all data[curIndex][0] = e; data[curIndex][1] = networkOffering; data[curIndex][2] = procedure; data[curIndex][3] = observedProperty; - data[curIndex][4] = "network_offering_platform_procedure"; + testType = "network_offering_platform_procedure"; + data[curIndex][4] = testType; + data[curIndex][5] = getTestLabel(e, testType); curIndex++; // A request with only the offering data[curIndex][0] = e; data[curIndex][1] = offering; data[curIndex][2] = null; data[curIndex][3] = observedProperty; - data[curIndex][4] = "platform_offering_no_procedure"; + testType = "platform_offering_no_procedure"; + data[curIndex][4] = testType; + data[curIndex][5] = getTestLabel(e, testType); curIndex++; @@ -123,7 +131,9 @@ public static Collection testCases() throws Exception { data[curIndex][1] = offering; data[curIndex][2] = procedure; data[curIndex][3] = VocabDefinitions.GetDefinitionForParameter(observedProperty); - data[curIndex][4] = "platform_offering_platform_procedure_ioos_vocab"; + testType = "platform_offering_platform_procedure_ioos_vocab"; + data[curIndex][4] = testType; + data[curIndex][5] = getTestLabel(e, testType); curIndex++; @@ -137,21 +147,27 @@ public static Collection testCases() throws Exception { data[curIndex][1] = offering; data[curIndex][2] = procedure; data[curIndex][3] = StringUtils.join(observedPropertyList, ','); - data[curIndex][4] = "platform_offering_platform_procedure"; + testType = "platform_offering_platform_procedure"; + data[curIndex][4] = testType; + data[curIndex][5] = getTestLabel(e, testType); curIndex++; // A request with the offering as network:all data[curIndex][0] = e; data[curIndex][1] = networkOffering; data[curIndex][2] = procedure; data[curIndex][3] = StringUtils.join(observedPropertyList, ','); - data[curIndex][4] = "network_offering_platform_procedure"; + testType = "network_offering_platform_procedure"; + data[curIndex][4] = testType; + data[curIndex][5] = getTestLabel(e, testType); curIndex++; // A request with only the offering data[curIndex][0] = e; data[curIndex][1] = offering; data[curIndex][2] = null; data[curIndex][3] = StringUtils.join(observedPropertyList, ','); - data[curIndex][4] = "platform_offering_no_procedure"; + testType = "platform_offering_no_procedure"; + data[curIndex][4] = testType; + data[curIndex][5] = getTestLabel(e, testType); curIndex++; } diff --git a/src/test/java/com/asascience/ncsos/NcSOSTest.java b/src/test/java/com/asascience/ncsos/NcSOSTest.java index d30733f..e7ecb28 100644 --- a/src/test/java/com/asascience/ncsos/NcSOSTest.java +++ b/src/test/java/com/asascience/ncsos/NcSOSTest.java @@ -129,4 +129,16 @@ protected static void fileWriter(String filePath, Writer writer, boolean append) output.write(writer.toString()); output.close(); } + + protected static String getTestLabel(Element e, String... extraLabels) { + StringBuilder sb = new StringBuilder(); + sb.append(e.getAttributeValue("path", "[no path]")); + sb.append(" - "); + sb.append(e.getAttributeValue("feature", "[no feature]")); + for (String extraLabel : extraLabels) { + sb.append(" - "); + sb.append(extraLabel); + } + return sb.toString(); + } } From 86d69d911419a00351f3b82b31e206fdffa728aa Mon Sep 17 00:00:00 2001 From: Shane StClair Date: Sat, 23 Aug 2014 12:29:52 -0700 Subject: [PATCH 2/3] Remove extra comment --- src/test/java/com/asascience/ncsos/DSNetworkTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/test/java/com/asascience/ncsos/DSNetworkTest.java b/src/test/java/com/asascience/ncsos/DSNetworkTest.java index 9e26fa1..aecd855 100644 --- a/src/test/java/com/asascience/ncsos/DSNetworkTest.java +++ b/src/test/java/com/asascience/ncsos/DSNetworkTest.java @@ -46,8 +46,7 @@ public static void setUpClass() throws Exception { kvp.put("service", "SOS"); } - // Create the parameters for the test constructor -// @Parameters(name = "{index}: {2}") + // Create the parameters for the test constructor @Parameters(name = "{index}: {2}") public static Collection testCases() throws Exception { setUpClass(); From 22c56d824aaa7b4aad4c1edeb57e238d0381426d Mon Sep 17 00:00:00 2001 From: Shane StClair Date: Sat, 23 Aug 2014 13:02:39 -0700 Subject: [PATCH 3/3] Add comment (trigger Travis rebuild) --- src/test/java/com/asascience/ncsos/GOBaseGridTest.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/com/asascience/ncsos/GOBaseGridTest.java b/src/test/java/com/asascience/ncsos/GOBaseGridTest.java index f71a63c..55f049f 100644 --- a/src/test/java/com/asascience/ncsos/GOBaseGridTest.java +++ b/src/test/java/com/asascience/ncsos/GOBaseGridTest.java @@ -34,6 +34,7 @@ public GOBaseGridTest(Element file, String offering, String procedure, String ob this.latitude = latitude; this.longitude = longitude; this.testType = testType; + //discard testLabel } public static void setUpClass() throws Exception {