Search in sources :

Example 6 with PackageRepository

use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.

the class PackageRepositoryServiceTest method shouldFailAndReturnReturnFailureResponse.

@Test
public void shouldFailAndReturnReturnFailureResponse() throws Exception {
    service = spy(service);
    Username username = new Username(new CaseInsensitiveString("user"));
    final PackageRepository packageRepository = new PackageRepository();
    packageRepository.errors().add("name", "Name is invalid");
    final CruiseConfig cruiseConfig = GoConfigMother.configWithPipelines("sample");
    cruiseConfig.errors().add("global", "error");
    final UpdateConfigFromUI updateConfigFromUI = mock(UpdateConfigFromUI.class);
    final ConfigAwareUpdate configAwareUpdate = mock(ConfigAwareUpdate.class);
    doNothing().when(service).performPluginValidationsFor(packageRepository);
    doReturn(updateConfigFromUI).when(service).getPackageRepositoryUpdateCommand(packageRepository, username);
    when(configAwareUpdate.configAfter()).thenReturn(cruiseConfig);
    when(goConfigService.updateConfigFromUI(eq(updateConfigFromUI), eq("md5"), eq(username), any(LocalizedOperationResult.class))).then(new Answer<ConfigUpdateResponse>() {

        @Override
        public ConfigUpdateResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            LocalizedOperationResult result = (LocalizedOperationResult) invocationOnMock.getArguments()[3];
            result.badRequest(LocalizedMessage.string("BAD_REQUEST"));
            return new ConfigUpdateResponse(cruiseConfig, cruiseConfig, packageRepository, configAwareUpdate, ConfigSaveState.UPDATED);
        }
    });
    when(localizer.localize("BAD_REQUEST", new Object[] {})).thenReturn("Save Failed");
    ConfigUpdateAjaxResponse response = service.savePackageRepositoryToConfig(packageRepository, "md5", username);
    assertThat(response.isSuccessful(), is(false));
    assertThat(response.getMessage(), is("Save Failed"));
    assertThat(response.getFieldErrors().size(), is(1));
    assertThat(response.getFieldErrors().get("package_repository[name]"), is(asList("Name is invalid")));
    assertThat(response.getGlobalErrors().size(), is(1));
    assertThat(response.getGlobalErrors().contains("error"), is(true));
    assertThat(response.getStatusCode(), is(HttpStatus.SC_BAD_REQUEST));
    verify(service).performPluginValidationsFor(packageRepository);
    verify(service).getPackageRepositoryUpdateCommand(packageRepository, username);
}
Also used : PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Username(com.thoughtworks.go.server.domain.Username) LocalizedOperationResult(com.thoughtworks.go.server.service.result.LocalizedOperationResult) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ConfigUpdateAjaxResponse(com.thoughtworks.go.config.update.ConfigUpdateAjaxResponse) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) ConfigUpdateResponse(com.thoughtworks.go.config.update.ConfigUpdateResponse) Test(org.junit.Test)

Example 7 with PackageRepository

use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.

the class GoConfigGraphWalkerTest method shouldNotWalkPackageDefinitionWhileTraversingPackageMaterial.

@Test
public void shouldNotWalkPackageDefinitionWhileTraversingPackageMaterial() {
    PackageDefinition packageDefinition = mock(PackageDefinition.class);
    PackageMaterialConfig packageMaterialConfig = new PackageMaterialConfig("package-id");
    setField(packageMaterialConfig, "packageDefinition", packageDefinition);
    BasicCruiseConfig config = new BasicCruiseConfig();
    PackageRepository packageRepository = mock(PackageRepository.class);
    when(packageRepository.getPackages()).thenReturn(new Packages(packageDefinition));
    when(packageDefinition.getRepository()).thenReturn(packageRepository);
    when(packageRepository.doesPluginExist()).thenReturn(true);
    when(packageDefinition.getId()).thenReturn("package-id");
    config.getPackageRepositories().add(packageRepository);
    final ConfigSaveValidationContext context = new ConfigSaveValidationContext(config);
    new GoConfigGraphWalker(packageMaterialConfig).walk(new GoConfigGraphWalker.Handler() {

        @Override
        public void handle(Validatable validatable, ValidationContext ctx) {
            validatable.validate(context);
        }
    });
    verify(packageDefinition, never()).validate(any(ValidationContext.class));
}
Also used : PackageMaterialConfig(com.thoughtworks.go.config.materials.PackageMaterialConfig) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) Packages(com.thoughtworks.go.domain.packagerepository.Packages) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.jupiter.api.Test)

Example 8 with PackageRepository

use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.

the class UpdatePackageRepositoryCommand method isRequestFresh.

private boolean isRequestFresh() {
    PackageRepository oldRepo = goConfigService.getPackageRepository(newRepo.getRepoId());
    boolean freshRequest = entityHashingService.hashForEntity(oldRepo).equals(digest);
    if (!freshRequest) {
        result.stale(EntityType.PackageRepository.staleConfig(newRepo.getRepoId()));
    }
    return freshRequest;
}
Also used : PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository)

Example 9 with PackageRepository

use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.

the class UpdatePackageRepositoryCommand method update.

@Override
public void update(CruiseConfig modifiedConfig) {
    PackageRepository oldRepo = modifiedConfig.getPackageRepositories().find(newRepo.getRepoId());
    this.newRepo.setPackages(oldRepo.getPackages());
    PackageRepositories repositories = modifiedConfig.getPackageRepositories();
    repositories.replace(oldRepo, newRepo);
    modifiedConfig.setPackageRepositories(repositories);
    updatePackageRepositoryConfigurationOnAssociatedPipelines(modifiedConfig);
}
Also used : PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository)

Example 10 with PackageRepository

use of com.thoughtworks.go.domain.packagerepository.PackageRepository in project gocd by gocd.

the class PackageRepositoryServiceTest method shouldPopulateErrorsForCheckConnectionOnPlugin.

@Test
void shouldPopulateErrorsForCheckConnectionOnPlugin() {
    String pluginId = "yum";
    PackageRepository packageRepository = packageRepository(pluginId);
    HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
    PackageRepositoryService service = new PackageRepositoryService(pluginManager, packageRepositoryExtension, goConfigService, securityService, entityHashingService, secretParamResolver);
    ArgumentCaptor<RepositoryConfiguration> argumentCaptor = ArgumentCaptor.forClass(RepositoryConfiguration.class);
    when(packageRepositoryExtension.checkConnectionToRepository(eq(pluginId), argumentCaptor.capture())).thenReturn(new Result().withErrorMessages("Repo invalid!!", "Could not connect"));
    service.checkConnection(packageRepository, result);
    RepositoryConfiguration packageConfigurations = argumentCaptor.getValue();
    PackageMaterialTestHelper.assertPackageConfiguration(packageConfigurations.list(), packageRepository.getConfiguration());
    assertThat(result.isSuccessful()).isFalse();
    assertThat(result.message()).isEqualTo("Could not connect to package repository. Reason(s): Repo invalid!!\nCould not connect");
    verify(packageRepositoryExtension).checkConnectionToRepository(eq(pluginId), any(RepositoryConfiguration.class));
}
Also used : HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) RepositoryConfiguration(com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration) Result(com.thoughtworks.go.plugin.api.response.Result) ValidationResult(com.thoughtworks.go.plugin.api.response.validation.ValidationResult) HttpLocalizedOperationResult(com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult) Test(org.junit.jupiter.api.Test)

Aggregations

PackageRepository (com.thoughtworks.go.domain.packagerepository.PackageRepository)89 Test (org.junit.jupiter.api.Test)46 PackageDefinition (com.thoughtworks.go.domain.packagerepository.PackageDefinition)40 PackageRepositories (com.thoughtworks.go.domain.packagerepository.PackageRepositories)39 HttpLocalizedOperationResult (com.thoughtworks.go.server.service.result.HttpLocalizedOperationResult)23 Packages (com.thoughtworks.go.domain.packagerepository.Packages)13 Username (com.thoughtworks.go.server.domain.Username)13 Test (org.junit.Test)13 RepositoryConfiguration (com.thoughtworks.go.plugin.api.material.packagerepository.RepositoryConfiguration)9 PluginConfiguration (com.thoughtworks.go.domain.config.PluginConfiguration)7 ValidationResult (com.thoughtworks.go.plugin.api.response.validation.ValidationResult)7 BeforeEach (org.junit.jupiter.api.BeforeEach)6 PackageMaterialConfig (com.thoughtworks.go.config.materials.PackageMaterialConfig)5 UpdateConfigFromUI (com.thoughtworks.go.config.update.UpdateConfigFromUI)5 ConfigurationProperty (com.thoughtworks.go.domain.config.ConfigurationProperty)5 PackageConfigurations (com.thoughtworks.go.plugin.access.packagematerial.PackageConfigurations)5 XsdValidationException (com.thoughtworks.go.util.XsdValidationException)5 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)4 GoConfigInvalidException (com.thoughtworks.go.config.exceptions.GoConfigInvalidException)4 ConfigurationValue (com.thoughtworks.go.domain.config.ConfigurationValue)4