Search in sources :

Example 56 with PackageRepository

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

the class UpdatePackageConfigCommandTest method shouldValidateDuplicatePackageName.

@Test
public void shouldValidateDuplicatePackageName() throws Exception {
    PackageRepository repository = cruiseConfig.getPackageRepositories().find("repoId");
    PackageDefinition pkg = new PackageDefinition("Id", newPackageName, new Configuration());
    pkg.setRepository(repository);
    repository.addPackage(pkg);
    cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
    UpdatePackageConfigCommand command = new UpdatePackageConfigCommand(goConfigService, packageUuid, newPackageDefinition, currentUser, "md5", this.entityHashingService, result, packageDefinitionService);
    command.update(cruiseConfig);
    assertFalse(command.isValid(cruiseConfig));
    assertThat(newPackageDefinition.errors().size(), is(1));
    assertThat(newPackageDefinition.errors().firstError(), is("You have defined multiple packages called 'prettyjson'. Package names are case-insensitive and must be unique within a repository."));
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.Test)

Example 57 with PackageRepository

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

the class UpdatePackageConfigCommandTest method shouldValidateIfPackageNameIsNull.

@Test
public void shouldValidateIfPackageNameIsNull() throws Exception {
    PackageRepository repository = cruiseConfig.getPackageRepositories().find("repoId");
    PackageDefinition pkg = new PackageDefinition("Id", null, new Configuration());
    pkg.setRepository(repository);
    repository.addPackage(pkg);
    cruiseConfig.setPackageRepositories(new PackageRepositories(repository));
    UpdatePackageConfigCommand command = new UpdatePackageConfigCommand(goConfigService, packageUuid, pkg, currentUser, "md5", this.entityHashingService, result, packageDefinitionService);
    command.update(cruiseConfig);
    assertFalse(command.isValid(cruiseConfig));
    assertThat(pkg.errors().size(), is(1));
    assertThat(pkg.errors().firstError(), is("Package name is mandatory"));
}
Also used : PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepositories(com.thoughtworks.go.domain.packagerepository.PackageRepositories) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) Test(org.junit.Test)

Example 58 with PackageRepository

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

the class PackageRepositoryServiceTest method shouldValidateUpdateCommandForPackageRepository.

@Test
public void shouldValidateUpdateCommandForPackageRepository() throws Exception {
    Username username = new Username(new CaseInsensitiveString("user"));
    Validatable packageRepository = new PackageRepository();
    ((PackageRepository) packageRepository).setId("id");
    Validatable cruiseConfig = GoConfigMother.configWithPipelines("sample");
    ((CruiseConfig) cruiseConfig).getPackageRepositories().add((PackageRepository) packageRepository);
    UpdateConfigFromUI updateCommand = service.getPackageRepositoryUpdateCommand((PackageRepository) packageRepository, username);
    assertThat(updateCommand.node((CruiseConfig) cruiseConfig), is(cruiseConfig));
    assertThat(updateCommand.updatedNode((CruiseConfig) cruiseConfig), is(cruiseConfig));
    assertThat(updateCommand.subject(cruiseConfig), is(packageRepository));
    assertThat(updateCommand.updatedSubject(cruiseConfig), is(packageRepository));
}
Also used : Username(com.thoughtworks.go.server.domain.Username) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) UpdateConfigFromUI(com.thoughtworks.go.config.update.UpdateConfigFromUI) Test(org.junit.Test)

Example 59 with PackageRepository

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

the class PackageRepositoryServiceTest method shouldSavePackageRepositoryAndReturnSuccess.

@Test
public void shouldSavePackageRepositoryAndReturnSuccess() throws Exception {
    service = spy(service);
    PackageRepository packageRepository = new PackageRepository();
    packageRepository.setId("repoid");
    Username username = new Username(new CaseInsensitiveString("user"));
    UpdateConfigFromUI updateConfigFromUI = mock(UpdateConfigFromUI.class);
    doNothing().when(service).performPluginValidationsFor(packageRepository);
    doReturn(updateConfigFromUI).when(service).getPackageRepositoryUpdateCommand(packageRepository, username);
    when(goConfigService.updateConfigFromUI(eq(updateConfigFromUI), eq("md5"), eq(username), any(LocalizedOperationResult.class))).then(new Answer<ConfigUpdateResponse>() {

        @Override
        public ConfigUpdateResponse answer(InvocationOnMock invocationOnMock) throws Throwable {
            return new ConfigUpdateResponse(null, null, null, mock(ConfigAwareUpdate.class), ConfigSaveState.UPDATED);
        }
    });
    when(localizer.localize("SAVED_CONFIGURATION_SUCCESSFULLY")).thenReturn("SAVED_CONFIGURATION_SUCCESSFULLY");
    ConfigUpdateAjaxResponse response = service.savePackageRepositoryToConfig(packageRepository, "md5", username);
    assertThat(response.isSuccessful(), is(true));
    assertThat(response.getMessage(), is("SAVED_CONFIGURATION_SUCCESSFULLY"));
    assertThat(response.getSubjectIdentifier(), is("repoid"));
    assertThat(response.getStatusCode(), is(HttpStatus.SC_OK));
    verify(service).performPluginValidationsFor(packageRepository);
    verify(service).getPackageRepositoryUpdateCommand(packageRepository, username);
}
Also used : 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) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository) 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 60 with PackageRepository

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

the class PackageDefinitionRepresenter method fromJSON.

public static PackageDefinition fromJSON(JsonReader jsonReader) {
    PackageDefinition packageDefinition = new PackageDefinition();
    jsonReader.readStringIfPresent("id", packageDefinition::setId);
    jsonReader.readStringIfPresent("name", packageDefinition::setName);
    List<ConfigurationProperty> configuration = ConfigurationPropertyRepresenter.fromJSONArray(jsonReader, "configuration");
    packageDefinition.addConfigurations(configuration);
    packageDefinition.setAutoUpdate(jsonReader.getBoolean("auto_update"));
    PackageRepository packageRepo = PackageRepositoryRepresenter.fromJSON(jsonReader.readJsonObject("package_repo"));
    packageDefinition.setRepository(packageRepo);
    return packageDefinition;
}
Also used : ConfigurationProperty(com.thoughtworks.go.domain.config.ConfigurationProperty) PackageDefinition(com.thoughtworks.go.domain.packagerepository.PackageDefinition) PackageRepository(com.thoughtworks.go.domain.packagerepository.PackageRepository)

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