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."));
}
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"));
}
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));
}
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);
}
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;
}
Aggregations