Search in sources :

Example 16 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class PipelineConfigServiceIntegrationTest method setup.

@Before
public void setup() throws Exception {
    cachedGoPartials.clear();
    configHelper = new GoConfigFileHelper();
    dbHelper.onSetUp();
    configHelper.usingCruiseConfigDao(goConfigDao).initializeConfigFile();
    configHelper.onSetUp();
    goConfigService.forceNotifyListeners();
    user = new Username(new CaseInsensitiveString("current"));
    pipelineConfig = GoConfigMother.createPipelineConfigWithMaterialConfig(UUID.randomUUID().toString(), new GitMaterialConfig("FOO"));
    goConfigService.addPipeline(pipelineConfig, groupName);
    repoConfig1 = new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url"), XmlPartialConfigProvider.providerName);
    repoConfig2 = new ConfigRepoConfig(MaterialConfigsMother.gitMaterialConfig("url2"), XmlPartialConfigProvider.providerName);
    goConfigService.updateConfig(new UpdateConfigCommand() {

        @Override
        public CruiseConfig update(CruiseConfig cruiseConfig) throws Exception {
            cruiseConfig.getConfigRepos().add(repoConfig1);
            cruiseConfig.getConfigRepos().add(repoConfig2);
            return cruiseConfig;
        }
    });
    GoCipher goCipher = new GoCipher();
    goConfigService.updateServerConfig(new MailHost(goCipher), new LdapConfig(goCipher), new PasswordFileConfig("path"), false, goConfigService.configFileMd5(), "artifacts", null, null, "0", null, null, "foo");
    UpdateConfigCommand command = goConfigService.modifyAdminPrivilegesCommand(asList(user.getUsername().toString()), new TriStateSelection(Admin.GO_SYSTEM_ADMIN, TriStateSelection.Action.add));
    goConfigService.updateConfig(command);
    remoteDownstreamPipelineName = "remote-downstream";
    partialConfig = PartialConfigMother.pipelineWithDependencyMaterial(remoteDownstreamPipelineName, pipelineConfig, new RepoConfigOrigin(repoConfig1, "repo1_r1"));
    goPartialConfig.onSuccessPartialConfig(repoConfig1, partialConfig);
    PartialConfig partialConfigFromRepo2 = PartialConfigMother.withPipeline("independent-pipeline", new RepoConfigOrigin(repoConfig2, "repo2_r1"));
    goPartialConfig.onSuccessPartialConfig(repoConfig2, partialConfigFromRepo2);
    result = new HttpLocalizedOperationResult();
    headCommitBeforeUpdate = configRepository.getCurrentRevCommit().name();
}
Also used : GoCipher(com.thoughtworks.go.security.GoCipher) ConfigRepoConfig(com.thoughtworks.go.config.remote.ConfigRepoConfig) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) PartialConfig(com.thoughtworks.go.config.remote.PartialConfig) ExpectedException(org.junit.rules.ExpectedException) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Username(com.thoughtworks.go.server.domain.Username) GitMaterialConfig(com.thoughtworks.go.config.materials.git.GitMaterialConfig) RepoConfigOrigin(com.thoughtworks.go.config.remote.RepoConfigOrigin) GoConfigFileHelper(com.thoughtworks.go.util.GoConfigFileHelper)

Example 17 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldNotFailTryingToAddAnAgentThatsAlreadyPresentInEnvironment.

@Test
public void shouldNotFailTryingToAddAnAgentThatsAlreadyPresentInEnvironment() throws Exception {
    createEnvironment("uat");
    createEnabledAgent(UUID);
    createEnabledAgent(UUID2);
    CONFIG_HELPER.addAgentToEnvironment("uat", UUID);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.modifyEnvironments(USERNAME, operationResult, Arrays.asList(UUID, UUID2), Arrays.asList(new TriStateSelection("uat", TriStateSelection.Action.add)));
    assertThat(operationResult.httpCode(), is(200));
    assertThat(environmentConfigService.environmentsFor(UUID), containsSet("uat"));
    assertThat(environmentConfigService.environmentsFor(UUID2), containsSet("uat"));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 18 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class AgentServiceIntegrationTest method updateAgentAttributesShouldUpdateAnAgentEnvironments.

@Test
public void updateAgentAttributesShouldUpdateAnAgentEnvironments() throws Exception {
    createEnvironment("a", "b", "c", "d", "e");
    AgentConfig agent = createEnabledAgent(UUID);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.modifyEnvironments(USERNAME, operationResult, Arrays.asList(UUID), Arrays.asList(new TriStateSelection("a", TriStateSelection.Action.add), new TriStateSelection("b", TriStateSelection.Action.add), new TriStateSelection("c", TriStateSelection.Action.add)));
    assertThat(operationResult.httpCode(), is(200));
    goConfigDao.load();
    assertThat(agentService.agents().size(), is(1));
    assertThat(getFirstAgent().getResources(), is(empty()));
    operationResult = new HttpOperationResult();
    agentService.updateAgentAttributes(USERNAME, operationResult, UUID, null, null, "c,d,e", TriState.UNSET);
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Updated agent with uuid uuid."));
    assertThat(agentService.agents().size(), is(1));
    assertThat(getEnvironments(getFirstAgent().getUuid()).equals(new HashSet<>(Arrays.asList("c", "d", "e"))), is(true));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 19 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldAddResourcesToMultipleAgents.

@Test
public void shouldAddResourcesToMultipleAgents() {
    createEnabledAgent(UUID);
    createEnabledAgent(UUID2);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.modifyResources(USERNAME, operationResult, Arrays.asList(UUID, UUID2), Arrays.asList(new TriStateSelection("old-resource", TriStateSelection.Action.add), new TriStateSelection("new-resource", TriStateSelection.Action.add)));
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Resource(s) modified on 2 agent(s)"));
    assertThat(agentService.findAgentAndRefreshStatus(UUID).agentConfig().getResources(), hasItem(new Resource("old-resource")));
    assertThat(agentService.findAgentAndRefreshStatus(UUID).agentConfig().getResources(), hasItem(new Resource("new-resource")));
    assertThat(agentService.findAgentAndRefreshStatus(UUID2).agentConfig().getResources(), hasItem(new Resource("old-resource")));
    assertThat(agentService.findAgentAndRefreshStatus(UUID2).agentConfig().getResources(), hasItem(new Resource("new-resource")));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Example 20 with TriStateSelection

use of com.thoughtworks.go.presentation.TriStateSelection in project gocd by gocd.

the class AgentServiceIntegrationTest method shouldNotChangeResourcesForNoChange.

@Test
public void shouldNotChangeResourcesForNoChange() {
    createEnabledAgent(UUID);
    createEnabledAgent(UUID2);
    HttpOperationResult operationResult = new HttpOperationResult();
    agentService.modifyResources(USERNAME, operationResult, Arrays.asList(UUID), Arrays.asList(new TriStateSelection("resource-1", TriStateSelection.Action.add)));
    agentService.modifyResources(USERNAME, operationResult, Arrays.asList(UUID, UUID2), Arrays.asList(new TriStateSelection("resource-1", TriStateSelection.Action.nochange)));
    assertThat(operationResult.httpCode(), is(200));
    assertThat(operationResult.message(), is("Resource(s) modified on 2 agent(s)"));
    assertThat(agentService.findAgentAndRefreshStatus(UUID).agentConfig().getResources(), hasItem(new Resource("resource-1")));
    assertThat(agentService.findAgentAndRefreshStatus(UUID2).agentConfig().getResources(), not(hasItem(new Resource("resource-1"))));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) TriStateSelection(com.thoughtworks.go.presentation.TriStateSelection) Test(org.junit.Test)

Aggregations

TriStateSelection (com.thoughtworks.go.presentation.TriStateSelection)30 Test (org.junit.Test)24 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)13 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)12 Username (com.thoughtworks.go.server.domain.Username)5 GoConfigFileHelper (com.thoughtworks.go.util.GoConfigFileHelper)2 Before (org.junit.Before)2 UpdateConfigCommand (com.thoughtworks.go.config.UpdateConfigCommand)1 GitMaterialConfig (com.thoughtworks.go.config.materials.git.GitMaterialConfig)1 ConfigRepoConfig (com.thoughtworks.go.config.remote.ConfigRepoConfig)1 PartialConfig (com.thoughtworks.go.config.remote.PartialConfig)1 RepoConfigOrigin (com.thoughtworks.go.config.remote.RepoConfigOrigin)1 AgentInstance (com.thoughtworks.go.domain.AgentInstance)1 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)1 PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)1 GoCipher (com.thoughtworks.go.security.GoCipher)1 AgentConfigsUpdateValidator (com.thoughtworks.go.validation.AgentConfigsUpdateValidator)1 ArrayList (java.util.ArrayList)1 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)1 ExpectedException (org.junit.rules.ExpectedException)1