use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class PackageRepositoryServiceIntegrationTest method shouldReturnTheExactLocalizeMessageIfItFailsToDeletePackageRepository.
@Test
public void shouldReturnTheExactLocalizeMessageIfItFailsToDeletePackageRepository() throws Exception {
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
String repoId = "npm";
PackageRepository npmRepo = new PackageRepository();
npmRepo.setId(repoId);
goConfigService.getConfigForEditing().setPackageRepositories(new PackageRepositories(npmRepo));
HttpLocalizedOperationResult expectedResult = new HttpLocalizedOperationResult();
expectedResult.unauthorized(LocalizedMessage.string("UNAUTHORIZED_TO_EDIT"), HealthStateType.unauthorised());
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId), is(npmRepo));
service.deleteRepository(new Username("UnauthorizedUser"), npmRepo, result);
assertThat(result, is(expectedResult));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().size(), is(1));
assertThat(goConfigService.getConfigForEditing().getPackageRepositories().find(repoId), is(npmRepo));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class PackageRepositoryServiceIntegrationTest method setUp.
@Before
public void setUp() throws Exception {
initMocks(this);
service.setPluginManager(pluginManager);
username = new Username("CurrentUser");
UpdateConfigCommand command = goConfigService.modifyAdminPrivilegesCommand(asList(username.getUsername().toString()), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.add));
goConfigService.updateConfig(command);
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class CachedGoConfigTest method shouldNotifyConcernedListenersWhenEntityChanges.
@Test
public void shouldNotifyConcernedListenersWhenEntityChanges() {
final boolean[] pipelineConfigChangeListenerCalled = { false };
final boolean[] agentConfigChangeListenerCalled = { false };
final boolean[] cruiseConfigChangeListenerCalled = { false };
EntityConfigChangedListener<PipelineConfig> pipelineConfigChangeListener = new EntityConfigChangedListener<PipelineConfig>() {
@Override
public void onEntityConfigChange(PipelineConfig entity) {
pipelineConfigChangeListenerCalled[0] = true;
}
};
EntityConfigChangedListener<AgentConfig> agentConfigChangeListener = new EntityConfigChangedListener<AgentConfig>() {
@Override
public void onEntityConfigChange(AgentConfig entity) {
agentConfigChangeListenerCalled[0] = true;
}
};
EntityConfigChangedListener<CruiseConfig> cruiseConfigChangeListener = new EntityConfigChangedListener<CruiseConfig>() {
@Override
public void onEntityConfigChange(CruiseConfig entity) {
cruiseConfigChangeListenerCalled[0] = true;
}
};
cachedGoConfig.registerListener(pipelineConfigChangeListener);
cachedGoConfig.registerListener(agentConfigChangeListener);
cachedGoConfig.registerListener(cruiseConfigChangeListener);
EntityConfigUpdateCommand configCommand = mock(EntityConfigUpdateCommand.class);
when(configCommand.isValid(any(CruiseConfig.class))).thenReturn(true);
when(configCommand.getPreprocessedEntityConfig()).thenReturn(mock(PipelineConfig.class));
EntityConfigSaveResult entityConfigSaveResult = mock(EntityConfigSaveResult.class);
when(entityConfigSaveResult.getConfigHolder()).thenReturn(configHolder);
when(entityConfigSaveResult.getEntityConfig()).thenReturn(new PipelineConfig());
Username user = new Username(new CaseInsensitiveString("user"));
when(dataSource.writeEntityWithLock(configCommand, configHolder, user)).thenReturn(entityConfigSaveResult);
cachedGoConfig.loadConfigIfNull();
cachedGoConfig.writeEntityWithLock(configCommand, user);
assertThat(pipelineConfigChangeListenerCalled[0], is(true));
assertThat(agentConfigChangeListenerCalled[0], is(false));
assertThat(cruiseConfigChangeListenerCalled[0], is(false));
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class StageNotificationServiceTest method stubPipelineAndStage.
private void stubPipelineAndStage(Date date) {
final PipelineConfig pipelineConfig = PipelineConfigMother.createPipelineConfig("go", "dev", "compile", "test", "twist");
final Modification svnModification = new Modification("lgao", "Fixing the not checked in files", "jez@cruise.com", date, "123");
svnModification.createModifiedFile("build.xml", "some_dir", ModifiedAction.added);
svnModification.createModifiedFile("some.xml", "other_dir", ModifiedAction.deleted);
Pipeline pipeline = instanceFactory.createPipelineInstance(pipelineConfig, new ManualBuild(new Username(new CaseInsensitiveString("loser"))).onModifications(new MaterialRevisions(new MaterialRevision(new MaterialConfigConverter().toMaterials(pipelineConfig.materialConfigs()).get(0), svnModification)), false, null), new DefaultSchedulingContext("loser"), "md5-test", new TimeProvider());
Stage stage = pipeline.getStages().get(0);
when(stageService.findStageWithIdentifier(stageIdentifier)).thenReturn(stage);
stage.setPipelineId(100L);
when(pipelineService.fullPipelineById(100)).thenReturn(pipeline);
}
use of com.thoughtworks.go.server.domain.Username in project gocd by gocd.
the class StageNotificationServiceTest method shouldSendEmailWithFailureDetails.
@Test
public void shouldSendEmailWithFailureDetails() throws Exception {
final String expectedBaseUrl = String.format("http://test.host:8153");
String jezMail = prepareOneMatchedUser();
final Date date = new Date();
stubPipelineAndStage(date);
final TestSuite suite1 = new TestSuite("com.thoughtworks.go.FailOne");
suite1.addTest("shouldCompile", TestStatus.Error, new JobIdentifier(stageIdentifier, "compile"));
suite1.addTest("shouldPass", TestStatus.Failure, new JobIdentifier(stageIdentifier, "test"));
suite1.addTest("shouldPass", TestStatus.Failure, new JobIdentifier(stageIdentifier, "twist"));
suite1.addTest("shouldCompile2", TestStatus.Failure, new JobIdentifier(stageIdentifier, "compile"));
final TestSuite suite2 = new TestSuite("com.thoughtworks.go.FailTwo");
suite2.addTest("shouldCompile", TestStatus.Error, new JobIdentifier(stageIdentifier, "test"));
suite2.addTest("shouldTest", TestStatus.Failure, new JobIdentifier(stageIdentifier, "test"));
when(serverConfigService.siteUrlFor(anyString(), eq(false))).thenAnswer(new Answer<String>() {
public String answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
return morphURl((String) args[0], expectedBaseUrl);
}
});
when(systemEnvironment.isShineEnabled()).thenReturn(true);
when(shineDao.failedTestsFor(stageIdentifier)).thenReturn(Arrays.asList(suite1, suite2));
stageNotificationService.sendNotifications(stageIdentifier, StageEvent.Fails, new Username(new CaseInsensitiveString("loser")));
String body = inMemoryEmailNotificationTopic.getBody(jezMail);
assertThat(body, containsString(StageNotificationService.FAILED_TEST_SECTION));
String restOfThebody = textAfter(body, StageNotificationService.FAILED_TEST_SECTION);
String failuresText = restOfThebody.substring(0, restOfThebody.indexOf(StageNotificationService.MATERIAL_SECTION_HEADER));
assertEquals("\n\nThe following tests failed in pipeline 'go' (instance 'go-1'):\n\n" + "* com.thoughtworks.go.FailOne\n" + " shouldCompile\n" + " Errored on 'compile' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/compile)\n" + " shouldCompile2\n" + " Failed on 'compile' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/compile)\n" + " shouldPass\n" + " Failed on 'test' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/test)\n" + " Failed on 'twist' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/twist)\n" + "\n\n* com.thoughtworks.go.FailTwo\n" + " shouldCompile\n" + " Errored on 'test' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/test)\n" + " shouldTest\n" + " Failed on 'test' (" + expectedBaseUrl + "/go/tab/build/detail/go/1/dev/2/test)\n\n\n", failuresText);
}
Aggregations