summaryrefslogtreecommitdiffstats
path: root/client-compiler/tests
diff options
context:
space:
mode:
authorJonatan Kronqvist <jonatan@vaadin.com>2014-08-12 13:52:09 +0300
committerVaadin Code Review <review@vaadin.com>2014-08-13 13:37:42 +0000
commitfba69ae5d8cd617424e324c62b14225decf0315e (patch)
treeaea203ee02a551a8abd841b8a22cfcf1d2d9a8f4 /client-compiler/tests
parent223670ca8b6f8a89af59b0088bad97fddf2d956a (diff)
downloadvaadin-framework-fba69ae5d8cd617424e324c62b14225decf0315e.tar.gz
vaadin-framework-fba69ae5d8cd617424e324c62b14225decf0315e.zip
Allow for multiple license keys in a single license file #14408
License files can now contain multiple keys to support different versions of a product. The keys are identified by the major version number followed by an equals sign and the key for that version, e.g. 1 = foo-bar-baz 2 = baz-foo-bar The license file can also contain a "default" license key, which is used for all versions except for the explicitly defined ones, e.g. foo-bar-baz 3 = baz-bar-foo 4 = bar-baz-baz Change-Id: Id07d22e9fdc44189c4298b634006cf0df128bfd9
Diffstat (limited to 'client-compiler/tests')
-rw-r--r--client-compiler/tests/src/com/vaadin/tools/CvalCheckerTest.java147
1 files changed, 139 insertions, 8 deletions
diff --git a/client-compiler/tests/src/com/vaadin/tools/CvalCheckerTest.java b/client-compiler/tests/src/com/vaadin/tools/CvalCheckerTest.java
index 51b12f4c7e..2985f61631 100644
--- a/client-compiler/tests/src/com/vaadin/tools/CvalCheckerTest.java
+++ b/client-compiler/tests/src/com/vaadin/tools/CvalCheckerTest.java
@@ -24,13 +24,17 @@ import static com.vaadin.tools.CvalChecker.GRACE_DAYS_MSECS;
import static com.vaadin.tools.CvalChecker.cacheLicenseInfo;
import static com.vaadin.tools.CvalChecker.deleteCache;
import static com.vaadin.tools.CvalChecker.parseJson;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileDescriptor;
+import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.PrintStream;
+import java.io.PrintWriter;
import java.lang.reflect.Method;
import java.net.URL;
import java.net.URLClassLoader;
@@ -147,7 +151,7 @@ public class CvalCheckerTest {
productTitleCval);
Assert.fail();
} catch (InvalidCvalException expected) {
- Assert.assertEquals(productNameCval, expected.name);
+ assertEquals(productNameCval, expected.name);
}
Assert.assertFalse(cacheExists(productNameCval));
@@ -158,7 +162,7 @@ public class CvalCheckerTest {
productTitleCval);
Assert.fail();
} catch (InvalidCvalException expected) {
- Assert.assertEquals(productNameCval, expected.name);
+ assertEquals(productNameCval, expected.name);
}
Assert.assertFalse(cacheExists(productNameCval));
@@ -169,7 +173,7 @@ public class CvalCheckerTest {
productTitleCval);
Assert.fail();
} catch (InvalidCvalException expected) {
- Assert.assertEquals(productNameCval, expected.name);
+ assertEquals(productNameCval, expected.name);
}
Assert.assertFalse(cacheExists(productNameCval));
@@ -180,7 +184,7 @@ public class CvalCheckerTest {
productTitleCval);
Assert.fail();
} catch (InvalidCvalException expected) {
- Assert.assertEquals(productNameCval, expected.name);
+ assertEquals(productNameCval, expected.name);
}
Assert.assertFalse(cacheExists(productNameCval));
@@ -207,7 +211,7 @@ public class CvalCheckerTest {
} catch (InvalidCvalException expected) {
Assert.fail();
} catch (UnreachableCvalServerException expected) {
- Assert.assertEquals(productNameCval, expected.name);
+ assertEquals(productNameCval, expected.name);
}
Assert.assertFalse(cacheExists(productNameCval));
@@ -221,7 +225,7 @@ public class CvalCheckerTest {
} catch (InvalidCvalException expected) {
Assert.fail();
} catch (UnreachableCvalServerException expected) {
- Assert.assertEquals(productNameCval, expected.name);
+ assertEquals(productNameCval, expected.name);
}
Assert.assertFalse(cacheExists(productNameCval));
@@ -234,7 +238,7 @@ public class CvalCheckerTest {
productTitleCval);
Assert.fail();
} catch (InvalidCvalException expected) {
- Assert.assertEquals(productNameCval, expected.name);
+ assertEquals(productNameCval, expected.name);
// Check that we use server customized message if it comes
Assert.assertTrue(expected.getMessage().contains("Custom"));
}
@@ -255,7 +259,7 @@ public class CvalCheckerTest {
productTitleCval);
Assert.fail();
} catch (InvalidCvalException expected) {
- Assert.assertEquals(productNameCval, expected.name);
+ assertEquals(productNameCval, expected.name);
}
Assert.assertTrue(cacheExists(productNameCval));
}
@@ -339,4 +343,131 @@ public class CvalCheckerTest {
static void restoreSystemOut() {
System.setOut(new PrintStream(new FileOutputStream(FileDescriptor.out)));
}
+
+ @Test(expected = FileNotFoundException.class)
+ public void testReadKeyFromFile_NonexistingLicenseFile() throws Exception {
+ licenseChecker.readKeyFromFile(new URL("file:///foobar.baz"), 4);
+ }
+
+ @Test
+ public void testReadKeyFromFile_LicenseFileEmpty() throws Exception {
+ File tmpLicenseFile = File.createTempFile("license", "lic");
+
+ assertNull(licenseChecker.readKeyFromFile(tmpLicenseFile.toURI()
+ .toURL(), 4));
+
+ tmpLicenseFile.delete();
+ }
+
+ @Test
+ public void testReadKeyFromFile_LicenseFileHasSingleUnidentifiedKey()
+ throws Exception {
+ File tmpLicenseFile = File.createTempFile("license", "lic");
+ PrintWriter out = new PrintWriter(tmpLicenseFile);
+ out.println("this-is-a-license");
+ out.close();
+
+ assertEquals("this-is-a-license", licenseChecker.readKeyFromFile(
+ tmpLicenseFile.toURI().toURL(), 4));
+
+ tmpLicenseFile.delete();
+ }
+
+ @Test
+ public void testReadKeyFromFile_LicenseFileHasSingleIdentifiedKey()
+ throws Exception {
+ File tmpLicenseFile = File.createTempFile("license", "lic");
+ PrintWriter out = new PrintWriter(tmpLicenseFile);
+ out.println("4=this-is-a-license");
+ out.close();
+
+ assertEquals("this-is-a-license", licenseChecker.readKeyFromFile(
+ tmpLicenseFile.toURI().toURL(), 4));
+
+ tmpLicenseFile.delete();
+ }
+
+ @Test
+ public void testReadKeyFromFile_LicenseFileHasMultipleKeys()
+ throws Exception {
+ File tmpLicenseFile = File.createTempFile("license", "lic");
+ PrintWriter out = new PrintWriter(tmpLicenseFile);
+ out.println("4=this-is-a-license");
+ out.println("5=this-is-another-license");
+ out.close();
+
+ assertEquals("this-is-a-license", licenseChecker.readKeyFromFile(
+ tmpLicenseFile.toURI().toURL(), 4));
+ assertEquals("this-is-another-license", licenseChecker.readKeyFromFile(
+ tmpLicenseFile.toURI().toURL(), 5));
+
+ tmpLicenseFile.delete();
+ }
+
+ @Test
+ public void testReadKeyFromFile_LicenseFileHasMultipleKeysWithWhitespace()
+ throws Exception {
+ File tmpLicenseFile = File.createTempFile("license", "lic");
+ PrintWriter out = new PrintWriter(tmpLicenseFile);
+ out.println("4 = this-is-a-license");
+ out.println("5 = this-is-another-license");
+ out.close();
+
+ assertEquals("this-is-a-license", licenseChecker.readKeyFromFile(
+ tmpLicenseFile.toURI().toURL(), 4));
+ assertEquals("this-is-another-license", licenseChecker.readKeyFromFile(
+ tmpLicenseFile.toURI().toURL(), 5));
+
+ tmpLicenseFile.delete();
+ }
+
+ @Test
+ public void testReadKeyFromFile_RequestedVersionMissing() throws Exception {
+ File tmpLicenseFile = File.createTempFile("license", "lic");
+ PrintWriter out = new PrintWriter(tmpLicenseFile);
+ out.println("4 = this-is-a-license");
+ out.println("5 = this-is-another-license");
+ out.close();
+
+ assertNull(licenseChecker.readKeyFromFile(tmpLicenseFile.toURI()
+ .toURL(), 3));
+
+ tmpLicenseFile.delete();
+ }
+
+ @Test
+ public void testReadKeyFromFile_FallbackToDefaultKey() throws Exception {
+ File tmpLicenseFile = File.createTempFile("license", "lic");
+ PrintWriter out = new PrintWriter(tmpLicenseFile);
+ out.println("this-is-a-license");
+ out.println("5 = this-is-another-license");
+ out.close();
+
+ assertEquals("this-is-a-license", licenseChecker.readKeyFromFile(tmpLicenseFile.toURI()
+ .toURL(), 3));
+ assertEquals("this-is-a-license", licenseChecker.readKeyFromFile(tmpLicenseFile.toURI()
+ .toURL(), 4));
+ assertEquals("this-is-another-license", licenseChecker.readKeyFromFile(
+ tmpLicenseFile.toURI().toURL(), 5));
+
+ tmpLicenseFile.delete();
+ }
+
+ @Test
+ public void testReadKeyFromFile_FallbackToDefaultKeyReversed() throws Exception {
+ File tmpLicenseFile = File.createTempFile("license", "lic");
+ PrintWriter out = new PrintWriter(tmpLicenseFile);
+ out.println("5 = this-is-another-license");
+ out.println("this-is-a-license");
+ out.close();
+
+ assertEquals("this-is-a-license", licenseChecker.readKeyFromFile(tmpLicenseFile.toURI()
+ .toURL(), 3));
+ assertEquals("this-is-a-license", licenseChecker.readKeyFromFile(tmpLicenseFile.toURI()
+ .toURL(), 4));
+ assertEquals("this-is-another-license", licenseChecker.readKeyFromFile(
+ tmpLicenseFile.toURI().toURL(), 5));
+
+ tmpLicenseFile.delete();
+ }
}