@Test public void shouldNotCreatePackageRepositoryIfTheSpecifiedPluginTypeIsInvalid() throws Exception { when(packageRepositoryService.validatePluginId(packageRepository)).thenReturn(false); when(packageRepositoryService.validateRepositoryConfiguration(packageRepository)) .thenReturn(true); CreatePackageRepositoryCommand command = new CreatePackageRepositoryCommand( goConfigService, packageRepositoryService, packageRepository, currentUser, result); assertFalse(command.isValid(cruiseConfig)); }
@Test public void shouldNotCreatePackageRepositoryWhenRepositoryWithSpecifiedNameAlreadyExists() throws Exception { CreatePackageRepositoryCommand command = new CreatePackageRepositoryCommand( goConfigService, packageRepositoryService, packageRepository, currentUser, result); command.update(cruiseConfig); assertFalse(command.isValid(cruiseConfig)); assertThat( packageRepository.errors().firstError(), is( "You have defined multiple repositories called 'npmOrg'. Repository names are case-insensitive and must be unique.")); }
@Test public void shouldNotCreatePackageRepositoryWhenRepositoryHasInvalidName() throws Exception { packageRepository.setName("~!@#$%^&*("); CreatePackageRepositoryCommand command = new CreatePackageRepositoryCommand( goConfigService, packageRepositoryService, packageRepository, currentUser, result); assertFalse(command.isValid(cruiseConfig)); assertThat( packageRepository.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 shouldNotCreatePackageRepositoryWhenRepositoryHasDuplicateConfigurationProperties() throws Exception { ConfigurationProperty property = new ConfigurationProperty(new ConfigurationKey("foo"), new ConfigurationValue("bar")); Configuration configuration = new Configuration(property, property); packageRepository.setConfiguration(configuration); CreatePackageRepositoryCommand command = new CreatePackageRepositoryCommand( goConfigService, packageRepositoryService, packageRepository, currentUser, result); assertFalse(command.isValid(cruiseConfig)); assertThat( property.errors().firstError(), is("Duplicate key 'foo' found for Repository 'npmOrg'")); }