Search in sources :

Example 16 with ConfigElementImplementationRegistry

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"));
    }
}
Also used : ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ExecTask(com.thoughtworks.go.config.ExecTask) IOException(java.io.IOException) JDOMException(org.jdom2.JDOMException) Test(org.junit.Test)

Example 17 with ConfigElementImplementationRegistry

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);
}
Also used : ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ExecTask(com.thoughtworks.go.config.ExecTask) Test(org.junit.Test)

Example 18 with ConfigElementImplementationRegistry

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);
}
Also used : ConfigRepository(com.thoughtworks.go.service.ConfigRepository) UserDao(com.thoughtworks.go.server.dao.UserDao) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) PipelineRepository(com.thoughtworks.go.server.persistence.PipelineRepository) GoCache(com.thoughtworks.go.server.cache.GoCache) Before(org.junit.Before)

Example 19 with ConfigElementImplementationRegistry

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);
}
Also used : TimeProvider(com.thoughtworks.go.util.TimeProvider) Date(java.util.Date) DateTime(org.joda.time.DateTime) ClassPathResource(org.springframework.core.io.ClassPathResource) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) ConfigElementImplementationRegistrar(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistrar) NoPluginsInstalled(com.thoughtworks.go.config.registry.NoPluginsInstalled) SimpleDateFormat(java.text.SimpleDateFormat) File(java.io.File) Before(org.junit.Before)

Example 20 with ConfigElementImplementationRegistry

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);
}
Also used : ServerVersion(com.thoughtworks.go.server.util.ServerVersion) TimeProvider(com.thoughtworks.go.util.TimeProvider) ConfigRepository(com.thoughtworks.go.service.ConfigRepository) Document(org.jdom2.Document) FullConfigUpdateCommand(com.thoughtworks.go.config.update.FullConfigUpdateCommand) ConfigElementImplementationRegistry(com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry) Before(org.junit.Before)

Aggregations

ConfigElementImplementationRegistry (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistry)24 Test (org.junit.Test)13 ExecTask (com.thoughtworks.go.config.ExecTask)8 ConfigRepository (com.thoughtworks.go.service.ConfigRepository)7 Before (org.junit.Before)7 NoPluginsInstalled (com.thoughtworks.go.config.registry.NoPluginsInstalled)4 ServerVersion (com.thoughtworks.go.server.util.ServerVersion)4 TimeProvider (com.thoughtworks.go.util.TimeProvider)4 IOException (java.io.IOException)4 AntTask (com.thoughtworks.go.config.AntTask)3 PluggableTask (com.thoughtworks.go.config.pluggabletask.PluggableTask)3 PluginManager (com.thoughtworks.go.plugin.infra.PluginManager)3 ConfigCache (com.thoughtworks.go.config.ConfigCache)2 FetchTask (com.thoughtworks.go.config.FetchTask)2 MagicalGoConfigXmlLoader (com.thoughtworks.go.config.MagicalGoConfigXmlLoader)2 ConfigElementImplementationRegistrar (com.thoughtworks.go.config.registry.ConfigElementImplementationRegistrar)2 FullConfigUpdateCommand (com.thoughtworks.go.config.update.FullConfigUpdateCommand)2 UserDao (com.thoughtworks.go.server.dao.UserDao)2 PipelineRepository (com.thoughtworks.go.server.persistence.PipelineRepository)2 ServerHealthService (com.thoughtworks.go.serverhealth.ServerHealthService)2