Search in sources :

Example 1 with EnvironmentVariables

use of com.thoughtworks.go.domain.EnvironmentVariables in project gocd by gocd.

the class EnvironmentVariableSqlMapDao method load.

@Override
public EnvironmentVariables load(final Long entityId, final EnvironmentVariableType type) {
    List<EnvironmentVariable> result = (List<EnvironmentVariable>) transactionTemplate.execute((TransactionCallback) 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);
}
Also used : TransactionCallback(org.springframework.transaction.support.TransactionCallback) EnvironmentVariables(com.thoughtworks.go.domain.EnvironmentVariables) EnvironmentVariable(com.thoughtworks.go.domain.EnvironmentVariable) List(java.util.List) Criteria(org.hibernate.Criteria)

Example 2 with EnvironmentVariables

use of com.thoughtworks.go.domain.EnvironmentVariables 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));
}
Also used : EnvironmentVariables(com.thoughtworks.go.domain.EnvironmentVariables) EnvironmentVariable(com.thoughtworks.go.domain.EnvironmentVariable) Test(org.junit.jupiter.api.Test)

Example 3 with EnvironmentVariables

use of com.thoughtworks.go.domain.EnvironmentVariables 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));
}
Also used : EnvironmentVariables(com.thoughtworks.go.domain.EnvironmentVariables) EnvironmentVariable(com.thoughtworks.go.domain.EnvironmentVariable) Test(org.junit.jupiter.api.Test)

Example 4 with EnvironmentVariables

use of com.thoughtworks.go.domain.EnvironmentVariables 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));
}
Also used : EnvironmentVariables(com.thoughtworks.go.domain.EnvironmentVariables) EnvironmentVariable(com.thoughtworks.go.domain.EnvironmentVariable) Test(org.junit.jupiter.api.Test)

Example 5 with EnvironmentVariables

use of com.thoughtworks.go.domain.EnvironmentVariables in project gocd by gocd.

the class PipelineSchedulerIntegrationTest method shouldPassOverriddenEnvironmentVariablesForScheduling.

@Test
public void shouldPassOverriddenEnvironmentVariablesForScheduling() {
    final ScheduleOptions scheduleOptions = new ScheduleOptions(new HashMap<>(), Collections.singletonMap("KEY", "value"), new HashMap<>());
    HttpOperationResult operationResult = new HttpOperationResult();
    goConfigService.pipelineConfigNamed(new CaseInsensitiveString(PIPELINE_MINGLE)).setVariables(env("KEY", "somejunk"));
    serverHealthService.update(ServerHealthState.failToScheduling(HealthStateType.general(HealthStateScope.forPipeline(PIPELINE_MINGLE)), PIPELINE_MINGLE, "should wait till cleared"));
    pipelineScheduler.manualProduceBuildCauseAndSave(PIPELINE_MINGLE, Username.ANONYMOUS, scheduleOptions, operationResult);
    assertThat(operationResult.message(), operationResult.canContinue(), is(true));
    Assertions.waitUntil(Timeout.ONE_MINUTE, new BooleanSupplier() {

        @Override
        public boolean getAsBoolean() {
            return serverHealthService.filterByScope(HealthStateScope.forPipeline(PIPELINE_MINGLE)).size() == 0;
        }
    });
    BuildCause buildCause = pipelineScheduleQueue.toBeScheduled().get(new CaseInsensitiveString(PIPELINE_MINGLE));
    EnvironmentVariables overriddenVariables = buildCause.getVariables();
    assertThat(overriddenVariables, is(new EnvironmentVariables(Arrays.asList(new EnvironmentVariable("KEY", "value")))));
}
Also used : HttpOperationResult(com.thoughtworks.go.server.service.result.HttpOperationResult) ScheduleOptions(com.thoughtworks.go.server.scheduling.ScheduleOptions) EnvironmentVariables(com.thoughtworks.go.domain.EnvironmentVariables) EnvironmentVariable(com.thoughtworks.go.domain.EnvironmentVariable) BooleanSupplier(java.util.function.BooleanSupplier) CaseInsensitiveString(com.thoughtworks.go.config.CaseInsensitiveString) BuildCause(com.thoughtworks.go.domain.buildcause.BuildCause) Test(org.junit.jupiter.api.Test)

Aggregations

EnvironmentVariable (com.thoughtworks.go.domain.EnvironmentVariable)5 EnvironmentVariables (com.thoughtworks.go.domain.EnvironmentVariables)5 Test (org.junit.jupiter.api.Test)4 CaseInsensitiveString (com.thoughtworks.go.config.CaseInsensitiveString)1 BuildCause (com.thoughtworks.go.domain.buildcause.BuildCause)1 ScheduleOptions (com.thoughtworks.go.server.scheduling.ScheduleOptions)1 HttpOperationResult (com.thoughtworks.go.server.service.result.HttpOperationResult)1 List (java.util.List)1 BooleanSupplier (java.util.function.BooleanSupplier)1 Criteria (org.hibernate.Criteria)1 TransactionCallback (org.springframework.transaction.support.TransactionCallback)1