Search in sources :

Example 21 with Username

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));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.Test)

Example 22 with Username

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);
}
Also used : UpdateConfigCommand(com.thoughtworks.go.config.UpdateConfigCommand) Username(com.thoughtworks.go.server.domain.Username) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Before(org.junit.Before)

Example 23 with Username

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));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) EntityConfigUpdateCommand(com.thoughtworks.go.config.commands.EntityConfigUpdateCommand) EntityConfigChangedListener(com.thoughtworks.go.listener.EntityConfigChangedListener) Test(org.junit.Test)

Example 24 with Username

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);
}
Also used : Modification(com.thoughtworks.go.domain.materials.Modification) PipelineConfig(com.thoughtworks.go.config.PipelineConfig) TimeProvider(com.thoughtworks.go.util.TimeProvider) Username(com.thoughtworks.go.server.domain.Username) MaterialRevisions(com.thoughtworks.go.domain.MaterialRevisions) Stage(com.thoughtworks.go.domain.Stage) MaterialRevision(com.thoughtworks.go.domain.MaterialRevision) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Pipeline(com.thoughtworks.go.domain.Pipeline) DefaultSchedulingContext(com.thoughtworks.go.domain.DefaultSchedulingContext)

Example 25 with Username

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);
}
Also used : TestSuite(com.thoughtworks.go.domain.testinfo.TestSuite) Username(com.thoughtworks.go.server.domain.Username) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Matchers.anyString(org.mockito.Matchers.anyString) StringContains.containsString(org.hamcrest.core.StringContains.containsString) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) JobIdentifier(com.thoughtworks.go.domain.JobIdentifier) Date(java.util.Date) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) Test(org.junit.Test)

Aggregations

Username (com.thoughtworks.go.server.domain.Username)331 Test (org.junit.Test)268 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)133 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)84 Before (org.junit.Before)39 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)35 Pipeline (com.thoughtworks.go.domain.Pipeline)34 MaterialRevision (com.thoughtworks.go.domain.MaterialRevision)28 PipelineMaterialRevision (com.thoughtworks.go.domain.PipelineMaterialRevision)21 StringContains.containsString (org.hamcrest.core.StringContains.containsString)20 GoConfigMother (com.thoughtworks.go.helper.GoConfigMother)18 PipelineInstanceModels (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModels)18 Modification (com.thoughtworks.go.domain.materials.Modification)17 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)15 PipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.PipelineInstanceModel)15 ArrayList (java.util.ArrayList)15 DependencyMaterial (com.thoughtworks.go.config.materials.dependency.DependencyMaterial)14 EmptyPipelineInstanceModel (com.thoughtworks.go.presentation.pipelinehistory.EmptyPipelineInstanceModel)13 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)12 Date (java.util.Date)12