use of com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry in project gocd by gocd.
the class UniqueOnCancelValidatorTest method shouldFailWithExceptionWhenThereIsMoreThanOneOnCancelTasksForABuiltInTask.
@Test
public void shouldFailWithExceptionWhenThereIsMoreThanOneOnCancelTasksForABuiltInTask() throws Exception {
ConfigElementImplementationRegistry registry = mock(ConfigElementImplementationRegistry.class);
when(registry.implementersOf(Task.class)).thenReturn(tasks(ExecTask.class));
String content = "<cruise>" + " <pipeline>" + " <stage>" + " <jobs>" + " <job>" + " <tasks>" + " <exec command=\"install_addons.sh\">" + " <runif status=\"passed\" />" + " <oncancel>\n" + " <ant buildfile=\"build1.xml\" />\n" + " </oncancel>" + " <oncancel>\n" + " <ant buildfile=\"build2.xml\" />\n" + " </oncancel>" + " </exec>" + " </tasks>" + " </job>" + " </jobs>" + " </stage>" + " </pipeline>" + "</cruise>";
try {
UniqueOnCancelValidator validator = new UniqueOnCancelValidator();
validator.validate(elementFor(content), registry);
} catch (Exception e) {
assertThat(e.getMessage(), is("Task [exec] should not contain more than 1 oncancel task"));
}
}
use of com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry in project gocd by gocd.
the class UniqueOnCancelValidatorTest method shouldNotFailWithExceptionWhenThereAreNoOnCancelTasksForAPluginInTask.
@Test
public void shouldNotFailWithExceptionWhenThereAreNoOnCancelTasksForAPluginInTask() throws Exception {
ConfigElementImplementationRegistry registry = mock(ConfigElementImplementationRegistry.class);
when(registry.implementersOf(Task.class)).thenReturn(tasks(ExecTask.class));
String content = "<cruise>" + " <pipeline>" + " <stage>" + " <jobs>" + " <job>" + " <tasks>" + " <task name=\"\">\n" + " <pluginConfiguration id=\"curl.task.plugin\" version=\"1\" />\n" + " <configuration>\n" + " <property>\n" + " <key>Url</key>\n" + " <value>URL</value>\n" + " </property>\n" + " </configuration>\n" + " <runif status=\"passed\" />\n" + " </task>" + " </tasks>" + " </job>" + " </jobs>" + " </stage>" + " </pipeline>" + "</cruise>";
UniqueOnCancelValidator validator = new UniqueOnCancelValidator();
validator.validate(elementFor(content), registry);
}
use of com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry in project gocd by gocd.
the class GoConfigServiceTest method setup.
@Before
public void setup() throws Exception {
new SystemEnvironment().setProperty(SystemEnvironment.ENFORCE_SERVER_IMMUTABILITY, "N");
configRepo = mock(ConfigRepository.class);
goConfigDao = mock(GoConfigDao.class);
pipelineRepository = mock(PipelineRepository.class);
systemEnvironment = mock(SystemEnvironment.class);
cruiseConfig = unchangedConfig();
expectLoad(cruiseConfig);
this.clock = mock(Clock.class);
goCache = mock(GoCache.class);
instanceFactory = mock(InstanceFactory.class);
userDao = mock(UserDao.class);
stub(systemEnvironment.optimizeFullConfigSave()).toReturn(false);
ConfigElementImplementationRegistry registry = ConfigElementImplementationRegistryMother.withNoPlugins();
goConfigService = new GoConfigService(goConfigDao, pipelineRepository, this.clock, new GoConfigMigration(configRepo, new TimeProvider(), new ConfigCache(), registry), goCache, configRepo, registry, instanceFactory, mock(CachedGoPartials.class), systemEnvironment);
}
use of com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry in project gocd by gocd.
the class ConfigCipherUpdaterTest method setUp.
@Before
public void setUp() throws Exception {
systemEnvironment.setProperty(SystemEnvironment.CONFIG_DIR_PROPERTY, temporaryFolder.newFolder().getAbsolutePath());
final Date currentTime = new DateTime().toDate();
timestamp = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss").format(currentTime);
updater = new ConfigCipherUpdater(systemEnvironment, new TimeProvider() {
@Override
public Date currentTime() {
return currentTime;
}
});
configCache = new ConfigCache();
registry = new ConfigElementImplementationRegistry(new NoPluginsInstalled());
ConfigElementImplementationRegistrar registrar = new ConfigElementImplementationRegistrar(registry);
registrar.initialize();
magicalGoConfigXmlLoader = new MagicalGoConfigXmlLoader(configCache, registry);
File configFileEncryptedWithFlawedCipher = new ClassPathResource("cruise-config-with-encrypted-with-flawed-cipher.xml").getFile();
FileUtils.writeStringToFile(systemEnvironment.getCipherFile(), ConfigCipherUpdater.FLAWED_VALUE, UTF_8);
ReflectionUtil.setStaticField(CipherProvider.class, "cachedKey", null);
String xml = ConfigMigrator.migrate(FileUtils.readFileToString(configFileEncryptedWithFlawedCipher, UTF_8));
originalConfigFile = new File(systemEnvironment.getCruiseConfigFile());
FileUtils.writeStringToFile(originalConfigFile, xml, UTF_8);
}
use of com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry in project gocd by gocd.
the class FullConfigSaveMergeFlowTest method setup.
@Before
public void setup() throws Exception {
configForEdit = mock(CruiseConfig.class);
updateConfigCommand = new FullConfigUpdateCommand(configForEdit, "md5");
loader = mock(MagicalGoConfigXmlLoader.class);
writer = mock(MagicalGoConfigXmlWriter.class);
document = mock(Document.class);
fileWriter = mock(GoConfigFileWriter.class);
serverVersion = mock(ServerVersion.class);
timeProvider = mock(TimeProvider.class);
configRepository = mock(ConfigRepository.class);
cachedGoPartials = mock(CachedGoPartials.class);
configElementImplementationRegistry = mock(ConfigElementImplementationRegistry.class);
partials = new ArrayList<>();
flow = new FullConfigSaveMergeFlow(loader, writer, configElementImplementationRegistry, serverVersion, timeProvider, configRepository, cachedGoPartials, fileWriter);
}
Aggregations