@Test public void testValidateProduct() throws Exception { deleteCache(productNameCval); try { licenseChecker.validateProduct(productNameCval, "2.1", productTitleCval); Assert.fail(); } catch (InvalidCvalException expected) { assertEquals(productNameCval, expected.name); } Assert.assertFalse(cacheExists(productNameCval)); System.setProperty(licenseName, ""); try { licenseChecker.validateProduct(productNameCval, "2.1", productTitleCval); Assert.fail(); } catch (InvalidCvalException expected) { assertEquals(productNameCval, expected.name); } Assert.assertFalse(cacheExists(productNameCval)); System.setProperty(licenseName, "invalid"); try { licenseChecker.validateProduct(productNameCval, "2.1", productTitleCval); Assert.fail(); } catch (InvalidCvalException expected) { assertEquals(productNameCval, expected.name); } Assert.assertFalse(cacheExists(productNameCval)); System.setProperty(licenseName, VALID_KEY); try { licenseChecker.validateProduct(productNameCval, "3.0", productTitleCval); Assert.fail(); } catch (InvalidCvalException expected) { assertEquals(productNameCval, expected.name); assertTrue(expected.getMessage().contains("is not valid")); } Assert.assertFalse(cacheExists(productNameCval)); System.setProperty(licenseName, VALID_KEY); licenseChecker .validateProduct(productNameCval, "2.1", productTitleCval); Assert.assertTrue(cacheExists(productNameCval)); licenseChecker.setLicenseProvider(unreachableLicenseProvider); licenseChecker .validateProduct(productNameCval, "2.1", productTitleCval); Assert.assertTrue(cacheExists(productNameCval)); try { System.setProperty(licenseName, INVALID_KEY); licenseChecker.validateProduct(productNameCval, "2.1", productTitleCval); Assert.fail(); } catch (InvalidCvalException expected) { Assert.fail(); } catch (UnreachableCvalServerException expected) { assertEquals(productNameCval, expected.name); } Assert.assertFalse(cacheExists(productNameCval)); try { System.setProperty(licenseName, VALID_KEY); licenseChecker.validateProduct(productNameCval, "2.1", productTitleCval); Assert.fail(); } catch (InvalidCvalException expected) { Assert.fail(); } catch (UnreachableCvalServerException expected) { assertEquals(productNameCval, expected.name); } Assert.assertFalse(cacheExists(productNameCval)); deleteCache(productNameCval); licenseChecker.setLicenseProvider(expiredLicenseProviderWithMessage); try { licenseChecker.validateProduct(productNameCval, "2.1", productTitleCval); Assert.fail(); } catch (InvalidCvalException expected) { assertEquals(productNameCval, expected.name); Assert.assertTrue(expected.getMessage().contains("Custom")); } Assert.assertTrue(cacheExists(productNameCval)); deleteCache(productNameCval); licenseChecker.setLicenseProvider(unlimitedLicenseProvider); licenseChecker .validateProduct(productNameCval, "2.1", productTitleCval); Assert.assertTrue(cacheExists(productNameCval)); System.setProperty(licenseName, VALID_KEY); deleteCache(productNameCval); licenseChecker.setLicenseProvider(expiredEpochLicenseProvider); try { licenseChecker.validateProduct(productNameCval, "2.1", productTitleCval); Assert.fail(); } catch (InvalidCvalException expected) { assertEquals(productNameCval, expected.name); } Assert.assertTrue(cacheExists(productNameCval)); deleteCache(productNameCval); licenseChecker.setLicenseProvider(nullVersionLicenseProvider); licenseChecker .validateProduct(productNameCval, "2.1", productTitleCval); Assert.assertTrue(cacheExists(productNameCval)); }
public CvalInfo validateProduct(String productName, String productVersion, String productTitle) throws InvalidCvalException, UnreachableCvalServerException { String key = getDeveloperLicenseKey(productName, productVersion, productTitle); CvalInfo info = null; if (key != null && !key.isEmpty()) { info = getCachedLicenseInfo(productName); if (info != null && !info.isValidInfo(productName, key)) { deleteCache(productName); info = null; } info = askLicenseServer(productName, key, productVersion, info); if (info != null && info.isValidInfo(productName, key) && info.isValidVersion(computeMajorVersion(productVersion)) && !info.isLicenseExpired()) { return info; } } throw new InvalidCvalException(productName, productVersion, productTitle, key, info); }
CvalChecker { public CvalInfo validateProduct(String productName, String productVersion, String productTitle) throws InvalidCvalException, UnreachableCvalServerException { String key = getDeveloperLicenseKey(productName, productVersion, productTitle); CvalInfo info = null; if (key != null && !key.isEmpty()) { info = getCachedLicenseInfo(productName); if (info != null && !info.isValidInfo(productName, key)) { deleteCache(productName); info = null; } info = askLicenseServer(productName, key, productVersion, info); if (info != null && info.isValidInfo(productName, key) && info.isValidVersion(computeMajorVersion(productVersion)) && !info.isLicenseExpired()) { return info; } } throw new InvalidCvalException(productName, productVersion, productTitle, key, info); } }
CvalChecker { public CvalInfo validateProduct(String productName, String productVersion, String productTitle) throws InvalidCvalException, UnreachableCvalServerException { String key = getDeveloperLicenseKey(productName, productVersion, productTitle); CvalInfo info = null; if (key != null && !key.isEmpty()) { info = getCachedLicenseInfo(productName); if (info != null && !info.isValidInfo(productName, key)) { deleteCache(productName); info = null; } info = askLicenseServer(productName, key, productVersion, info); if (info != null && info.isValidInfo(productName, key) && info.isValidVersion(computeMajorVersion(productVersion)) && !info.isLicenseExpired()) { return info; } } throw new InvalidCvalException(productName, productVersion, productTitle, key, info); } CvalChecker(); }
CvalChecker { public CvalInfo validateProduct(String productName, String productVersion, String productTitle) throws InvalidCvalException, UnreachableCvalServerException { String key = getDeveloperLicenseKey(productName, productVersion, productTitle); CvalInfo info = null; if (key != null && !key.isEmpty()) { info = getCachedLicenseInfo(productName); if (info != null && !info.isValidInfo(productName, key)) { deleteCache(productName); info = null; } info = askLicenseServer(productName, key, productVersion, info); if (info != null && info.isValidInfo(productName, key) && info.isValidVersion(computeMajorVersion(productVersion)) && !info.isLicenseExpired()) { return info; } } throw new InvalidCvalException(productName, productVersion, productTitle, key, info); } CvalChecker(); CvalInfo validateProduct(String productName, String productVersion,
            String productTitle); }
CvalChecker { public CvalInfo validateProduct(String productName, String productVersion, String productTitle) throws InvalidCvalException, UnreachableCvalServerException { String key = getDeveloperLicenseKey(productName, productVersion, productTitle); CvalInfo info = null; if (key != null && !key.isEmpty()) { info = getCachedLicenseInfo(productName); if (info != null && !info.isValidInfo(productName, key)) { deleteCache(productName); info = null; } info = askLicenseServer(productName, key, productVersion, info); if (info != null && info.isValidInfo(productName, key) && info.isValidVersion(computeMajorVersion(productVersion)) && !info.isLicenseExpired()) { return info; } } throw new InvalidCvalException(productName, productVersion, productTitle, key, info); } CvalChecker(); CvalInfo validateProduct(String productName, String productVersion,
            String productTitle); static final String LINE; }