use of com.thoughtworks.go.domain.EnvironmentVariable in project gocd by gocd.
the class EnvironmentVariableSqlMapDao method load.
public EnvironmentVariables load(final Long entityId, final EnvironmentVariableType type) {
List<EnvironmentVariable> result = (List<EnvironmentVariable>) transactionTemplate.execute(new TransactionCallback() {
@Override
public Object doInTransaction(TransactionStatus transactionStatus) {
Criteria criteria = sessionFactory.getCurrentSession().createCriteria(EnvironmentVariable.class).add(Restrictions.eq("entityId", entityId)).add(Restrictions.eq("entityType", type.toString())).addOrder(Order.asc("id"));
criteria.setCacheable(true);
return criteria.list();
}
});
return new EnvironmentVariables(result);
}
use of com.thoughtworks.go.domain.EnvironmentVariable in project gocd by gocd.
the class EnvironmentVariableSqlMapDaoIntegrationTest method shouldSavePlainTextEnvironmentVariable.
@Test
public void shouldSavePlainTextEnvironmentVariable() {
EnvironmentVariables variables = new EnvironmentVariables();
String plainText = "plainText";
String key = "key";
variables.add(new EnvironmentVariable(key, plainText, false));
dao.save(1L, Job, variables);
EnvironmentVariables actual = dao.load(1L, Job);
assertThat(actual.get(0).getName(), is(key));
assertThat(actual.get(0).getValue(), is(plainText));
assertThat(actual.get(0).isSecure(), is(false));
}
use of com.thoughtworks.go.domain.EnvironmentVariable in project gocd by gocd.
the class EnvironmentVariableSqlMapDaoIntegrationTest method shouldSaveSecureEnvironmentVariable.
@Test
public void shouldSaveSecureEnvironmentVariable() {
EnvironmentVariables variables = new EnvironmentVariables();
String plainText = "plainText";
String key = "key";
variables.add(new EnvironmentVariable(key, plainText, true));
dao.save(1L, Job, variables);
EnvironmentVariables actual = dao.load(1L, Job);
assertThat(actual.get(0).getName(), is(key));
assertThat(actual.get(0).getValue(), is(plainText));
assertThat(actual.get(0).isSecure(), is(true));
}
use of com.thoughtworks.go.domain.EnvironmentVariable in project gocd by gocd.
the class EnvironmentVariableSqlMapDaoIntegrationTest method shouldDeleteEnvironmentVariable.
@Test
public void shouldDeleteEnvironmentVariable() throws Exception {
EnvironmentVariables variables = new EnvironmentVariables();
String plainText = "plainText";
String key = "key";
variables.add(new EnvironmentVariable(key, plainText, false));
dao.save(1L, Job, variables);
EnvironmentVariables variableFromDb = dao.load(1L, Job);
assertThat(variableFromDb.size(), is(1));
dao.deleteAll(variableFromDb);
variableFromDb = dao.load(1L, Job);
assertThat(variableFromDb.size(), is(0));
}
use of com.thoughtworks.go.domain.EnvironmentVariable in project gocd by gocd.
the class PipelineTriggerServiceIntegrationTest method shouldScheduleAPipelineWithTheProvidedEnvironmentVariables.
@Test
public void shouldScheduleAPipelineWithTheProvidedEnvironmentVariables() throws IOException {
pipelineConfig.addEnvironmentVariable("ENV_VAR1", "VAL1");
pipelineConfig.addEnvironmentVariable("ENV_VAR2", "VAL2");
pipelineConfig.addEnvironmentVariable(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "SECURE_VAL", true));
pipelineConfig.addEnvironmentVariable(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR2", "SECURE_VAL2", true));
pipelineConfigService.updatePipelineConfig(admin, pipelineConfig, entityHashingService.md5ForEntity(pipelineConfig), new HttpLocalizedOperationResult());
Integer pipelineCounterBefore = pipelineSqlMapDao.getCounterForPipeline(pipelineName);
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(false));
PipelineScheduleOptions pipelineScheduleOptions = new PipelineScheduleOptions();
pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "ENV_VAR1", "overridden_value", false));
pipelineScheduleOptions.getAllEnvironmentVariables().add(new EnvironmentVariableConfig(new GoCipher(), "SECURE_VAR1", "overridden_secure_value", true));
pipelineTriggerService.schedule(pipelineName, pipelineScheduleOptions, admin, result);
assertThat(result.isSuccess(), is(true));
assertThat(result.fullMessage(), is(String.format("Request to schedule pipeline %s accepted", pipelineName)));
assertThat(result.httpCode(), is(202));
assertThat(triggerMonitor.isAlreadyTriggered(pipelineName), is(true));
materialUpdateStatusNotifier.onMessage(new MaterialUpdateSuccessfulMessage(svnMaterial, 1));
BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(pipelineName);
assertNotNull(buildCause);
assertThat(buildCause.getApprover(), is(CaseInsensitiveString.str(admin.getUsername())));
assertThat(buildCause.getMaterialRevisions().findRevisionFor(pipelineConfig.materialConfigs().first()).getLatestRevisionString(), is("s3"));
assertThat(buildCause.getBuildCauseMessage(), is("Forced by admin1"));
assertThat(buildCause.getVariables().size(), is(2));
EnvironmentVariable plainTextVariable = (EnvironmentVariable) CollectionUtils.find(buildCause.getVariables(), new Predicate() {
@Override
public boolean evaluate(Object o) {
EnvironmentVariable variable = (EnvironmentVariable) o;
return variable.getName().equals("ENV_VAR1");
}
});
EnvironmentVariable secureVariable = (EnvironmentVariable) CollectionUtils.find(buildCause.getVariables(), new Predicate() {
@Override
public boolean evaluate(Object o) {
EnvironmentVariable variable = (EnvironmentVariable) o;
return variable.getName().equals("SECURE_VAR1");
}
});
assertThat(plainTextVariable.getValue(), is("overridden_value"));
assertThat(secureVariable.getValue(), is("overridden_secure_value"));
assertThat(secureVariable.isSecure(), is(true));
scheduleService.autoSchedulePipelinesFromRequestBuffer();
Integer pipelineCounterAfter = pipelineSqlMapDao.getCounterForPipeline(pipelineName);
assertThat(pipelineCounterAfter, is(pipelineCounterBefore + 1));
BuildCause buildCauseOfLatestRun = pipelineSqlMapDao.findBuildCauseOfPipelineByNameAndCounter(pipelineName, pipelineCounterAfter);
assertThat(buildCauseOfLatestRun, is(buildCause));
}
Aggregations