@Test public void shouldNotUpdatePackageRepositoryIfTheSpecifiedPluginTypeIsInvalid() throws Exception { when(packageRepositoryService.validatePluginId(newPackageRepo)).thenReturn(false); when(packageRepositoryService.validateRepositoryConfiguration(newPackageRepo)).thenReturn(true); UpdatePackageRepositoryCommand command = new UpdatePackageRepositoryCommand( goConfigService, packageRepositoryService, newPackageRepo, currentUser, "md5", entityHashingService, result, repoId); command.update(cruiseConfig); assertFalse(command.isValid(cruiseConfig)); }
@Test public void shouldNotUpdatePackageRepositoryWhenRepositoryHasInvalidName() throws Exception { newPackageRepo.setName("~!@#$%^&*("); UpdatePackageRepositoryCommand command = new UpdatePackageRepositoryCommand( goConfigService, packageRepositoryService, newPackageRepo, currentUser, "md5", entityHashingService, result, repoId); command.update(cruiseConfig); assertFalse(command.isValid(cruiseConfig)); assertThat( newPackageRepo.errors().firstError(), is( "Invalid PackageRepository name '~!@#$%^&*('. This must be alphanumeric and can contain underscores and periods (however, it cannot start with a period). The maximum allowed length is 255 characters.")); }
@Test public void shouldNotUpdatePackageRepositoryWhenRepositoryWithSpecifiedNameAlreadyExists() throws Exception { cruiseConfig.getPackageRepositories().add(newPackageRepo); UpdatePackageRepositoryCommand command = new UpdatePackageRepositoryCommand( goConfigService, packageRepositoryService, newPackageRepo, currentUser, "md5", entityHashingService, result, repoId); assertFalse(command.isValid(cruiseConfig)); assertThat( newPackageRepo.errors().firstError(), is( "You have defined multiple repositories called 'npmOrg'. Repository names are case-insensitive and must be unique.")); }
@Test public void shouldNotUpdatePackageRepositoryWhenRepositoryHasDuplicateConfigurationProperties() throws Exception { ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("foo"), new ConfigurationValue("bar")); Configuration configuration = new Configuration(property, property); newPackageRepo.setConfiguration(configuration); UpdatePackageRepositoryCommand command = new UpdatePackageRepositoryCommand( goConfigService, packageRepositoryService, newPackageRepo, currentUser, "md5", entityHashingService, result, repoId); command.update(cruiseConfig); assertFalse(command.isValid(cruiseConfig)); assertThat( property.errors().firstError(), is("Duplicate key 'foo' found for Repository 'npmOrg'")); }