Michael Blow has uploaded a new change for review.

  https://asterix-gerrit.ics.uci.edu/2479

Change subject: [NO ISSUE][TEST] Refactor licensing test support
......................................................................

[NO ISSUE][TEST] Refactor licensing test support

Change-Id: I11385a73302b22f9aaaf91c426df8320f52ebb72
---
M asterixdb/asterix-server/pom.xml
M 
asterixdb/asterix-server/src/test/java/org/apache/asterix/test/server/LicensingIT.java
M hyracks-fullstack/hyracks/hyracks-test-support/pom.xml
A 
hyracks-fullstack/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/test/support/LicensingTestBase.java
4 files changed, 103 insertions(+), 40 deletions(-)


  git pull ssh://asterix-gerrit.ics.uci.edu:29418/asterixdb 
refs/changes/79/2479/1

diff --git a/asterixdb/asterix-server/pom.xml b/asterixdb/asterix-server/pom.xml
index 8a28a49..4c93a42 100644
--- a/asterixdb/asterix-server/pom.xml
+++ b/asterixdb/asterix-server/pom.xml
@@ -614,5 +614,10 @@
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j-api</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.apache.hyracks</groupId>
+      <artifactId>hyracks-test-support</artifactId>
+      <scope>test</scope>
+    </dependency>
   </dependencies>
 </project>
diff --git 
a/asterixdb/asterix-server/src/test/java/org/apache/asterix/test/server/LicensingIT.java
 
b/asterixdb/asterix-server/src/test/java/org/apache/asterix/test/server/LicensingIT.java
index 4ac3abb..60406b8 100644
--- 
a/asterixdb/asterix-server/src/test/java/org/apache/asterix/test/server/LicensingIT.java
+++ 
b/asterixdb/asterix-server/src/test/java/org/apache/asterix/test/server/LicensingIT.java
@@ -18,77 +18,56 @@
  */
 package org.apache.asterix.test.server;
 
-import java.io.File;
 import java.io.IOException;
-import java.nio.charset.StandardCharsets;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
 
-import org.apache.commons.io.FileUtils;
+import org.apache.hyracks.test.support.LicensingTestBase;
 import org.apache.hyracks.util.file.FileUtil;
-import org.junit.Assert;
 import org.junit.Before;
 import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runners.MethodSorters;
 
 @FixMethodOrder(MethodSorters.JVM)
-public class LicensingIT {
-
-    protected String installerDir;
+public class LicensingIT extends LicensingTestBase {
 
     @Before
     public void setup() {
-        final String pattern = getInstallerDirPattern();
-        final String targetDir = getTargetDir();
-        final String[] list = new File(targetDir).list((dir, name) -> 
name.matches(pattern));
-        Assert.assertNotNull("installerDir", list);
-        Assert.assertFalse("Ambiguous install dir (" + pattern + "): " + 
Arrays.toString(list), list.length > 1);
-        Assert.assertEquals("Can't find install dir (" + pattern + ")", 1, 
list.length);
-        installerDir = FileUtil.joinPath(targetDir, list[0]);
+        initInstallerDir();
     }
 
+    @Override
     protected String getTargetDir() {
         return FileUtil.joinPath("target");
     }
 
+    @Override
     protected String getInstallerDirPattern() {
         return "asterix-server.*-binary-assembly";
     }
 
+    @Override
     protected String pathToLicensingFiles() {
         return "";
     }
 
-    @Test
-    public void testLicenseNoticeFilesPresent() throws IOException {
-        for (String name : getRequiredArtifactNames()) {
-            final String fileName = FileUtil.joinPath(installerDir, 
pathToLicensingFiles(), name);
-            Assert.assertTrue(fileName + " missing", new 
File(fileName).exists());
-        }
-    }
-
+    @Override
     protected String[] getRequiredArtifactNames() {
         return 
org.apache.commons.lang3.ArrayUtils.add(getLicenseArtifactNames(), "NOTICE");
     }
 
-    @Test
-    public void ensureNoMissingLicenses() throws IOException {
-        for (String licenseArtifactName : getLicenseArtifactNames()) {
-            final File licenseFile =
-                    new File(FileUtil.joinPath(installerDir, 
pathToLicensingFiles(), licenseArtifactName));
-            List<String> badLines = new ArrayList<>();
-            for (String line : FileUtils.readLines(licenseFile, 
StandardCharsets.UTF_8)) {
-                if (line.matches("^\\s*MISSING:.*")) {
-                    badLines.add(line.trim());
-                }
-            }
-            Assert.assertEquals("Missing licenses in " + licenseFile + ": " + 
badLines, 0, badLines.size());
-        }
-    }
-
+    @Override
     protected String[] getLicenseArtifactNames() {
         return new String[] { "LICENSE" };
     }
+
+    @Test
+    public void testLicenseNoticeFilesPresent() {
+        verifyAllRequiredArtifactsPresent();
+    }
+
+    @Test
+    public void ensureNoMissingLicenses() throws IOException {
+        verifyMissingLicenses();
+    }
+
 }
diff --git a/hyracks-fullstack/hyracks/hyracks-test-support/pom.xml 
b/hyracks-fullstack/hyracks/hyracks-test-support/pom.xml
index 67ebc9b..7fa9a12 100644
--- a/hyracks-fullstack/hyracks/hyracks-test-support/pom.xml
+++ b/hyracks-fullstack/hyracks/hyracks-test-support/pom.xml
@@ -112,5 +112,9 @@
       <groupId>org.apache.logging.log4j</groupId>
       <artifactId>log4j-core</artifactId>
     </dependency>
+    <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+    </dependency>
   </dependencies>
 </project>
diff --git 
a/hyracks-fullstack/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/test/support/LicensingTestBase.java
 
b/hyracks-fullstack/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/test/support/LicensingTestBase.java
new file mode 100644
index 0000000..f6dbdec
--- /dev/null
+++ 
b/hyracks-fullstack/hyracks/hyracks-test-support/src/main/java/org/apache/hyracks/test/support/LicensingTestBase.java
@@ -0,0 +1,75 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.hyracks.test.support;
+
+import java.io.File;
+import java.io.IOException;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.commons.io.FileUtils;
+import org.apache.hyracks.util.file.FileUtil;
+import org.junit.Assert;
+
+public abstract class LicensingTestBase {
+    protected String installerDir;
+
+    protected void initInstallerDir() {
+        final String pattern = getInstallerDirPattern();
+        final String targetDir = getTargetDir();
+        final String[] list = new File(targetDir).list((dir, name) -> 
name.matches(pattern));
+        Assert.assertNotNull("installerDir", list);
+        Assert.assertFalse("Ambiguous install dir (" + pattern + "): " + 
Arrays.toString(list), list.length > 1);
+        Assert.assertEquals("Can't find install dir (" + pattern + ")", 1, 
list.length);
+        installerDir = FileUtil.joinPath(targetDir, list[0]);
+    }
+
+    protected abstract String getTargetDir();
+
+    protected abstract String getInstallerDirPattern();
+
+    protected abstract String pathToLicensingFiles();
+
+    protected abstract String[] getRequiredArtifactNames();
+
+    protected void verifyMissingLicenses() throws IOException {
+        for (String licenseArtifactName : getLicenseArtifactNames()) {
+            final File licenseFile =
+                    new File(FileUtil.joinPath(installerDir, 
pathToLicensingFiles(), licenseArtifactName));
+            List<String> badLines = new ArrayList<>();
+            for (String line : FileUtils.readLines(licenseFile, 
StandardCharsets.UTF_8)) {
+                if (line.matches("^\\s*MISSING:.*")) {
+                    badLines.add(line.trim());
+                }
+            }
+            Assert.assertEquals("Missing licenses in " + licenseFile + ": " + 
badLines, 0, badLines.size());
+        }
+    }
+
+    protected void verifyAllRequiredArtifactsPresent() {
+        for (String name : getRequiredArtifactNames()) {
+            final String fileName = FileUtil.joinPath(installerDir, 
pathToLicensingFiles(), name);
+            Assert.assertTrue(fileName + " missing", new 
File(fileName).exists());
+        }
+    }
+
+    protected abstract String[] getLicenseArtifactNames();
+}

-- 
To view, visit https://asterix-gerrit.ics.uci.edu/2479
To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I11385a73302b22f9aaaf91c426df8320f52ebb72
Gerrit-PatchSet: 1
Gerrit-Project: asterixdb
Gerrit-Branch: master
Gerrit-Owner: Michael Blow <mb...@apache.org>

Reply via email to