@Test public void testGetLicenseExpiryStatusMessageForNonExpiredEvaluation() { mockLicense.setEvaluation(true); mockLicense.setExpiryDate(tenSecondsFromNow); mockLicense.setExpired(false); assertExpiryMessageContains("admin.license.expiresin"); }
@Test public void testGetLicenseStatusMessageEvaluationNotAlmostExpired() { // not expired mockLicense.setEvaluation(true); mockLicense.setExpiryDate(tenDaysFromNow); assertNull(licenseDetails.getLicenseStatusMessage(fred, "")); }
@Test public void testGetLicenseExpiryStatusMessageForLicenseWithNonExpiredMaintenance() { mockLicense.setMaintenanceExpired(false); mockLicense.setMaintenanceExpiryDate(tenSecondsFromNow); assertExpiryMessageContains("admin.support.available.until"); }
@Test public void testGetLicenseExpiryStatusMessageForLicenseWithExpiredMaintenance() { // finally, if expired, message should be null mockLicense.setMaintenanceExpired(true); mockLicense.setMaintenanceExpiryDate(tenSecondsBeforeNow); assertNull(licenseDetails.getLicenseExpiryStatusMessage(fred)); }
@Test public void getDaysToExpiryOnPerpetualLicense() { mockLicense.setExpiryDate(null); mockLicense.setEvaluation(false); assertEquals(Integer.MAX_VALUE, licenseDetails.getDaysToLicenseExpiry()); }
@Test public void testGetBriefMaintenanceStatusMessageForMaintenanceExpiredPersonalLicense() { mockLicense.setLicenseType(LicenseType.PERSONAL); mockLicense.setMaintenanceExpired(true); mockLicense.setMaintenanceExpiryDate(tenSecondsBeforeNow); assertBriefMaintenanceMessageContains("unsupported"); }
@Test public void testGetLicenseExpiryStatusMessageForPersonalLicenseWithNonExpiredMaintenance() { mockLicense.setMaintenanceExpired(false); mockLicense.setMaintenanceExpiryDate(tenSecondsFromNow); // unsupported license mockLicense.setLicenseType(LicenseType.PERSONAL); assertExpiryMessageContains("admin.upgrades.available.until"); }
@Test public void testGetLicenseStatusMessageForAlmostMaintenanceExpiredPersonalLicense() throws Exception { mockLicense.setLicenseType(LicenseType.PERSONAL); mockLicense.setMaintenanceExpiryDate(tenSecondsFromNow); String message = licenseDetails.getLicenseStatusMessage(fred, ""); assertTrue(message.contains("admin.license.updates.only.will.end")); assertTrue(message.contains("admin.license.renew.for.updates.only.after")); }
@Test public void testGetLicenseExpiryStatusMessageForCommunityLicenseWithNonExpiredMaintenance() { mockLicense.setMaintenanceExpired(false); mockLicense.setMaintenanceExpiryDate(tenSecondsFromNow); // other self renewable but supported licenses mockLicense.setLicenseType(LicenseType.COMMUNITY); assertExpiryMessageContains("admin.support.available.until"); }
@Test public void testGetLicenseStatusMessageForMaintenanceExpiredLicense() throws Exception { mockLicense.setMaintenanceExpired(true); mockLicense.setMaintenanceExpiryDate(tenSecondsBeforeNow); String message = licenseDetails.getLicenseStatusMessage(fred, ""); assertTrue(message.contains("admin.license.support.and.updates.has.ended")); assertTrue(message.contains("admin.license.renew.for.support.and.updates")); }
@Test public void testGetLicenseStatusMessageEvaluationAlmostExpired() { // almost expired mockLicense.setEvaluation(true); mockLicense.setExpiryDate(tenSecondsFromNow); assertTrue( licenseDetails .getLicenseStatusMessage(fred, "") .contains("admin.license.evaluation.almost.expired")); }
@Test public void testGetLicenseExpiryStatusMessageForExpiredEvaluation() { mockLicense.setEvaluation(true); mockLicense.setExpiryDate(now); mockLicense.setExpired(true); applicationProperties.setOption(APKeys.JIRA_CONFIRMED_INSTALL_WITH_OLD_LICENSE, true); assertExpiryMessageContains("admin.license.expired"); }
@Test public void testGetLicenseStatusMessageNormalForMaintenanceExpiredNonProfitLicense() throws Exception { mockLicense.setLicenseType(LicenseType.NON_PROFIT); mockLicense.setMaintenanceExpired(true); mockLicense.setMaintenanceExpiryDate(tenSecondsBeforeNow); String message = licenseDetails.getLicenseStatusMessage(fred, ""); assertTrue(message.contains("admin.license.updates.only.has.ended")); assertTrue(message.contains("admin.license.renew.for.deprecated")); }
@Test public void testGetLicenseStatusMessageNewBuildOldLicenseForNonExpiredNonProfitLicense() { mockLicense.setLicenseType(LicenseType.NON_PROFIT); mockLicense.setMaintenanceExpiryDate(tenSecondsBeforeNow); setLicenseExtenstionTimestamp(tenDaysAgoInMillis); // user: doesnt exist, mockLicense: other/deprecated, expired: no String message = licenseDetails.getLicenseStatusMessage(fred, ""); assertTrue(message.contains("admin.license.nbol.current.version.user.unknown")); assertTrue(message.contains("admin.license.nbol.updates.only")); assertTrue(message.contains("admin.license.renew.for.deprecated")); assertTrue(message.contains("admin.license.nbol.evaluation.period.will.expire.in")); }
@Test public void testGetLicenseStatusMessageEvaluation() { mockLicense.setEvaluation(true); mockLicense.setExpiryDate(now); mockLicense.setExpired(true); // expired assertTrue( licenseDetails .getLicenseStatusMessage(fred, "") .contains("admin.license.evaluation.expired")); }
@Test public void testGetLicenseStatusMessageNewBuildOldLicenseForExpiredLicense() { // user: exists, license: commercial, expired: yes fred = new MockUser("fred", "Fred", "*****@*****.**"); mockLicense.setExpiryDate(tenSecondsBeforeNow); mockLicense.setMaintenanceExpiryDate(tenSecondsBeforeNow); setLicenseExtenstionTimestamp(fiftyDaysAgoInMillis); String message = licenseDetails.getLicenseStatusMessage(fred, ""); assertTrue(message.contains("admin.license.nbol.current.version")); assertTrue(message.contains("admin.license.nbol.support.and.updates")); assertTrue(message.contains("admin.license.renew.for.support.and.updates")); assertTrue(message.contains("admin.license.nbol.evaluation.period.has.expired")); }
@Test public void testGetBriefMaintenanceStatusMessageWithOldLicenseWithinGracePeriod() { mockLicense.setMaintenanceExpiryDate(tenSecondsBeforeNow); setLicenseExtenstionTimestamp(tenDaysAgoInMillis); // within grace period assertBriefMaintenanceMessageContains("supported.valid"); }
@Test public void testGetLicenseStatusMessageForAlmostMaintenanceExpiredLicense() throws Exception { mockLicense.setMaintenanceExpiryDate(tenSecondsFromNow); String message = licenseDetails.getLicenseStatusMessage(fred, ""); assertTrue(message.contains("admin.license.support.and.updates.will.end")); assertTrue(message.contains("admin.license.renew.for.support.and.updates.after")); }
@Test public void clusteringForScaleShouldBeOnWhenPropertySetToTrue() { // Set up mockLicense.setProperty(DATACENTER_PROPERTY_NAME, ENABLED); // Invoke and check assertTrue("Clustering for scale should be on", licenseDetails.isDataCenter()); }
@Test public void clusteringForScaleShouldBeOffWhenPropertySetToFalse() { // Set up mockLicense.setProperty(DATACENTER_PROPERTY_NAME, "false"); // Invoke and check assertFalse("Clustering for scale should be off", licenseDetails.isDataCenter()); }
@Test public void testGetMaintenanceEndStringOldNewBuild() { mockLicense.setMaintenanceExpiryDate(tenSecondsBeforeNow); setLicenseExtenstionTimestamp(tenSecondsBeforeNow.getTime()); Date expected = new Date(tenSecondsBeforeNow.getTime() + GRACE_PERIOD_IN_MILLIS); assertEquals(expected.toString(), licenseDetails.getMaintenanceEndString(OUTLOOK_DATE)); }
@Before public void setUp() throws Exception { final DateTimeFormatter dateTimeFormatter = new DateTimeFormatterFactoryStub().formatter(); buildUtilsInfo = Mockito.mock(BuildUtilsInfo.class); clusterManager = Mockito.mock(ClusterManager.class); applicationProperties = new MockApplicationProperties(); externalLinkUtil = new MockExternalLinkUtil(); mockI18nHelper = new NoopI18nHelper(Locale.ENGLISH); now = new Date(1401162923372L); tenSecondsFromNow = new Date(now.getTime() + TimeUnit.SECONDS.toMillis(10)); tenSecondsBeforeNow = new Date(now.getTime() - TimeUnit.SECONDS.toMillis(10)); tenDaysFromNow = new Date(now.getTime() + TimeUnit.DAYS.toMillis(10)); twentyFourDaysAgo = new Date(now.getTime() - TimeUnit.DAYS.toMillis(24)); fiftyDaysFromNow = new Date(now.getTime() + TimeUnit.DAYS.toMillis(50)); tenDaysAgoInMillis = now.getTime() - TimeUnit.DAYS.toMillis(10); thirtyDaysAgoInMillis = now.getTime() - TimeUnit.DAYS.toMillis(30); fiftyDaysAgoInMillis = now.getTime() - TimeUnit.DAYS.toMillis(50); mockLicense = new MockLicense(); mockLicense.setLicenseType(LicenseType.COMMERCIAL); mockLicense.setMaintenanceExpired(false); mockLicense.setMaintenanceExpiryDate(tenSecondsFromNow); when(buildUtilsInfo.getCurrentBuildDate()).thenReturn(now); licenseDetails = new DefaultLicenseDetails( mockLicense, LICENSE_STRING, applicationProperties, externalLinkUtil, buildUtilsInfo, new NoopI18nFactory(), dateTimeFormatter, new Version2LicenseDecoder(), clusterManager, new ConstantClock(now.getTime())) { @Override User getConfirmedUser() { return fred; } }; }
@Test public void testGetLicenseExpiryStatusMessageWhenTimestampedForOldLicenseWithinTheGracePeriod() { mockLicense.setMaintenanceExpiryDate( tenSecondsBeforeNow); // a tim well before the current build date setLicenseExtenstionTimestamp( tenDaysAgoInMillis); // set the recorded extension timestanmp to be within the grace period assertExpiryMessageContains("admin.license.expiresin"); }
@Test public void getDaysToMaintenanceExpiryOnEvaluationLicense() { mockLicense.setMaintenanceExpiryDate(tenDaysFromNow); // License expires in exactly 10 days. assertEquals(10, licenseDetails.getDaysToMaintenanceExpiry()); // License expires in exactly 10 days + 1 ms. mockLicense.setMaintenanceExpiryDate(new Date(tenDaysFromNow.getTime() + 1)); assertEquals(10, licenseDetails.getDaysToMaintenanceExpiry()); // License expires in exactly 10 days - 1 ms. mockLicense.setMaintenanceExpiryDate(new Date(tenDaysFromNow.getTime() - 1)); assertEquals(9, licenseDetails.getDaysToMaintenanceExpiry()); // License expires now. mockLicense.setMaintenanceExpiryDate(now); assertEquals(0, licenseDetails.getDaysToMaintenanceExpiry()); // License expires 1ms into the future. mockLicense.setMaintenanceExpiryDate(new Date(now.getTime() + 1)); assertEquals(0, licenseDetails.getDaysToMaintenanceExpiry()); // License expired 1ms ago. mockLicense.setMaintenanceExpiryDate(new Date(now.getTime() - 1)); assertEquals(-1, licenseDetails.getDaysToMaintenanceExpiry()); // License expired a long time ago. mockLicense.setMaintenanceExpiryDate(twentyFourDaysAgo); // License expired exactly 24 days ago. assertEquals(-24, licenseDetails.getDaysToMaintenanceExpiry()); // License expired exactly 24 days - 1ms ago (negative offset) mockLicense.setMaintenanceExpiryDate(new Date(twentyFourDaysAgo.getTime() + 1)); assertEquals(-24, licenseDetails.getDaysToMaintenanceExpiry()); // License expired exactly 24 days + 1ms ago (negative offset). mockLicense.setMaintenanceExpiryDate(new Date(twentyFourDaysAgo.getTime() - 1)); assertEquals(-25, licenseDetails.getDaysToMaintenanceExpiry()); }
@Test public void testGetLicenseVersion() throws Exception { mockLicense.setLicenseVersion(666); assertEquals(666, licenseDetails.getLicenseVersion()); }
@Test public void getDaysToMaintenanceExpiryOnPerpetualLicense() { mockLicense.setMaintenanceExpiryDate(null); assertEquals(Integer.MAX_VALUE, licenseDetails.getDaysToMaintenanceExpiry()); }
@Test public void getDaysToExpiryOnEvaluationLicense() { mockLicense.setExpiryDate(tenDaysFromNow); mockLicense.setEvaluation(true); // License expires in exactly 10 days. assertEquals(10, licenseDetails.getDaysToLicenseExpiry()); // License expires in exactly 10 days + 1 ms. mockLicense.setExpiryDate(new Date(tenDaysFromNow.getTime() + 1)); assertEquals(10, licenseDetails.getDaysToLicenseExpiry()); // License expires in exactly 10 days - 1 ms. mockLicense.setExpiryDate(new Date(tenDaysFromNow.getTime() - 1)); assertEquals(9, licenseDetails.getDaysToLicenseExpiry()); // License expires now. mockLicense.setExpiryDate(now); assertEquals(0, licenseDetails.getDaysToLicenseExpiry()); // License expires 1ms into the future. mockLicense.setExpiryDate(new Date(now.getTime() + 1)); assertEquals(0, licenseDetails.getDaysToLicenseExpiry()); // License expired 1ms ago. mockLicense.setExpiryDate(new Date(now.getTime() - 1)); assertEquals(-1, licenseDetails.getDaysToLicenseExpiry()); // License expired a long time ago. mockLicense.setExpiryDate(twentyFourDaysAgo); mockLicense.setEvaluation(true); // License expired exactly 24 days ago. assertEquals(-24, licenseDetails.getDaysToLicenseExpiry()); // License expired exactly 1ms later than 24 days ago. mockLicense.setExpiryDate(new Date(twentyFourDaysAgo.getTime() + 1)); assertEquals(-24, licenseDetails.getDaysToLicenseExpiry()); // License expired exactly 1ms earlier than 24 days ago. mockLicense.setExpiryDate(new Date(twentyFourDaysAgo.getTime() - 1)); assertEquals(-25, licenseDetails.getDaysToLicenseExpiry()); }
@Test public void testIsAlmostExpiredNewBuildOldLicense() throws Exception { mockLicense.setMaintenanceExpiryDate(tenSecondsBeforeNow); setLicenseExtenstionTimestamp(twentyFourDaysAgo.getTime()); assertTrue(licenseDetails.isLicenseAlmostExpired()); }
@Test public void testIsNotAlmostExpiredNewBuildOldLicense() throws Exception { mockLicense.setMaintenanceExpiryDate(tenSecondsBeforeNow); setLicenseExtenstionTimestamp(tenDaysAgoInMillis); assertFalse(licenseDetails.isLicenseAlmostExpired()); }
private void assertSupportEntitlement( final LicenseType licenceType, final boolean expectedEntitlement) { mockLicense.setLicenseType(licenceType); assertEquals(licenceType.name(), expectedEntitlement, licenseDetails.isEntitledToSupport()); }