Search in sources :

Example 1 with SystemTimeClock

use of com.thoughtworks.go.util.SystemTimeClock in project gocd by gocd.

the class ServerVersionInfoManagerTest method shouldGetVersionInfoIflatestVersionIsBeingUpdatedForMoreThanHalfAnHour.

@Test
public void shouldGetVersionInfoIflatestVersionIsBeingUpdatedForMoreThanHalfAnHour() {
    SystemTimeClock systemTimeClock = mock(SystemTimeClock.class);
    Date yesterday = new Date(System.currentTimeMillis() - 24 * 60 * 60 * 1000);
    DateTime halfAnHourFromNow = new DateTime(System.currentTimeMillis() - 35 * 60 * 1000);
    VersionInfo versionInfo = new VersionInfo("go_server", new GoVersion("1.2.3-1"), new GoVersion("2.3.4-2"), yesterday);
    when(builder.getServerVersionInfo()).thenReturn(versionInfo);
    when(systemTimeClock.currentDateTime()).thenReturn(halfAnHourFromNow);
    manager = new ServerVersionInfoManager(builder, versionInfoDao, systemTimeClock, goCache, systemEnvironment);
    manager.initialize();
    VersionInfo serverVersionInfo1 = manager.versionInfoForUpdate();
    VersionInfo serverVersionInfo2 = manager.versionInfoForUpdate();
    assertNotNull(serverVersionInfo1);
    assertNotNull(serverVersionInfo2);
}
Also used : VersionInfo(com.thoughtworks.go.domain.VersionInfo) SystemTimeClock(com.thoughtworks.go.util.SystemTimeClock) GoVersion(com.thoughtworks.go.domain.GoVersion) Date(java.util.Date) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 2 with SystemTimeClock

use of com.thoughtworks.go.util.SystemTimeClock in project gocd by gocd.

the class ServerVersionInfoManagerTest method shouldBeFalseIfVersionCheckIsDisabled.

@Test
public void shouldBeFalseIfVersionCheckIsDisabled() {
    SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
    when(builder.getServerVersionInfo()).thenReturn(new VersionInfo());
    when(systemEnvironment.isProductionMode()).thenReturn(true);
    when(systemEnvironment.isGOUpdateCheckEnabled()).thenReturn(false);
    manager = new ServerVersionInfoManager(builder, versionInfoDao, new SystemTimeClock(), goCache, systemEnvironment);
    manager.initialize();
    assertFalse(manager.isUpdateCheckEnabled());
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) VersionInfo(com.thoughtworks.go.domain.VersionInfo) SystemTimeClock(com.thoughtworks.go.util.SystemTimeClock) Test(org.junit.Test)

Example 3 with SystemTimeClock

use of com.thoughtworks.go.util.SystemTimeClock in project gocd by gocd.

the class ServerVersionInfoManagerTest method updateCheckShouldBeDisabledForADevelopmentServer.

@Test
public void updateCheckShouldBeDisabledForADevelopmentServer() {
    SystemEnvironment systemEnvironment = mock(SystemEnvironment.class);
    when(builder.getServerVersionInfo()).thenReturn(new VersionInfo());
    when(systemEnvironment.isProductionMode()).thenReturn(false);
    when(systemEnvironment.isGOUpdateCheckEnabled()).thenReturn(true);
    manager = new ServerVersionInfoManager(builder, versionInfoDao, new SystemTimeClock(), goCache, systemEnvironment);
    manager.initialize();
    assertFalse(manager.isUpdateCheckEnabled());
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) VersionInfo(com.thoughtworks.go.domain.VersionInfo) SystemTimeClock(com.thoughtworks.go.util.SystemTimeClock) Test(org.junit.Test)

Example 4 with SystemTimeClock

use of com.thoughtworks.go.util.SystemTimeClock in project gocd by gocd.

the class IsSecurityEnabledVoterTest method shouldNotVoteAccessGrantedIfSecurityIsEnabledButAnonymousIsNot.

@Test
public void shouldNotVoteAccessGrantedIfSecurityIsEnabledButAnonymousIsNot() {
    configHelper.addSecurityWithBogusLdapConfig(false);
    GoConfigService configService = new GoConfigService(goConfigDao, null, new SystemTimeClock(), mock(GoConfigMigration.class), null, null, ConfigElementImplementationRegistryMother.withNoPlugins(), new InstanceFactory(), mock(CachedGoPartials.class), null);
    IsSecurityEnabledVoter voter = new IsSecurityEnabledVoter(configService);
    int accessStatus = voter.vote(null, null, null);
    assertThat(accessStatus, Is.is(AccessDecisionVoter.ACCESS_ABSTAIN));
}
Also used : CachedGoPartials(com.thoughtworks.go.config.CachedGoPartials) InstanceFactory(com.thoughtworks.go.server.service.InstanceFactory) SystemTimeClock(com.thoughtworks.go.util.SystemTimeClock) GoConfigMigration(com.thoughtworks.go.config.GoConfigMigration) GoConfigService(com.thoughtworks.go.server.service.GoConfigService) Test(org.junit.Test)

Example 5 with SystemTimeClock

use of com.thoughtworks.go.util.SystemTimeClock in project gocd by gocd.

the class ServerVersionInfoManagerTest method shouldGetGoUpdateFromCache.

@Test
public void shouldGetGoUpdateFromCache() {
    String newRelease = "15.0.1-123";
    GoCache goCache = mock(GoCache.class);
    when(goCache.get("GOUpdate")).thenReturn(newRelease);
    manager = new ServerVersionInfoManager(builder, versionInfoDao, new SystemTimeClock(), goCache, null);
    assertThat(manager.getGoUpdate(), is(newRelease));
}
Also used : SystemTimeClock(com.thoughtworks.go.util.SystemTimeClock) GoCache(com.thoughtworks.go.server.cache.GoCache) Test(org.junit.Test)

Aggregations

SystemTimeClock (com.thoughtworks.go.util.SystemTimeClock)8 Test (org.junit.Test)8 VersionInfo (com.thoughtworks.go.domain.VersionInfo)6 GoVersion (com.thoughtworks.go.domain.GoVersion)3 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)3 Date (java.util.Date)3 CachedGoPartials (com.thoughtworks.go.config.CachedGoPartials)1 GoConfigMigration (com.thoughtworks.go.config.GoConfigMigration)1 GoCache (com.thoughtworks.go.server.cache.GoCache)1 GoConfigService (com.thoughtworks.go.server.service.GoConfigService)1 InstanceFactory (com.thoughtworks.go.server.service.InstanceFactory)1 DateTime (org.joda.time.DateTime)1