use of com.thoughtworks.go.server.transaction.TransactionSynchronizationManager in project gocd by gocd.
the class TransactionSynchronizationManagerTest method shouldUnderstandIfTransactionBodyExecuting.
@Test
public void shouldUnderstandIfTransactionBodyExecuting() {
final boolean[] inBody = new boolean[] { false };
final TransactionSynchronizationManager synchronizationManager = new TransactionSynchronizationManager();
transactionTemplate.execute(new TransactionCallback() {
public Object doInTransaction(TransactionStatus status) {
inBody[0] = synchronizationManager.isTransactionBodyExecuting();
return null;
}
});
assertThat(inBody[0], is(true));
assertThat(synchronizationManager.isTransactionBodyExecuting(), is(false));
}
use of com.thoughtworks.go.server.transaction.TransactionSynchronizationManager in project gocd by gocd.
the class TransactionSynchronizationManagerTest method shouldUnderstandIfTransactionIsActive.
@Test
public void shouldUnderstandIfTransactionIsActive() {
final TransactionSynchronizationManager synchronizationManager = new TransactionSynchronizationManager();
final ArrayList<Boolean> transactionActivity = new ArrayList<>();
transactionTemplate.execute(new org.springframework.transaction.support.TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
transactionActivity.add(synchronizationManager.isActualTransactionActive());
}
});
assertThat(transactionActivity, is(Arrays.asList(true)));
assertThat(synchronizationManager.isActualTransactionActive(), is(false));
}
use of com.thoughtworks.go.server.transaction.TransactionSynchronizationManager in project gocd by gocd.
the class StageServiceTest method findStageSummaryByIdentifierShouldRespondWith401WhenUserDoesNotHavePermissionToViewThePipeline.
@Test
public void findStageSummaryByIdentifierShouldRespondWith401WhenUserDoesNotHavePermissionToViewThePipeline() throws Exception {
SecurityService securityService = mock(SecurityService.class);
when(securityService.hasViewPermissionForPipeline(ALWAYS_ALLOW_USER, "pipeline_name")).thenReturn(false);
TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
StageService service = new StageService(stageDao, null, null, null, securityService, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
HttpLocalizedOperationResult result = new HttpLocalizedOperationResult();
StageSummaryModel model = service.findStageSummaryByIdentifier(new StageIdentifier("pipeline_name/10/stage_name/1"), ALWAYS_ALLOW_USER, result);
assertThat(result.httpCode(), is(401));
assertThat(model, is(nullValue()));
}
use of com.thoughtworks.go.server.transaction.TransactionSynchronizationManager in project gocd by gocd.
the class StageServiceTest method shouldNotReturnAnythingWhenCurrentStageHasNotFailed.
@Test
public void shouldNotReturnAnythingWhenCurrentStageHasNotFailed() {
TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
StageRunFinder runFinder = new StageService(stageDao, jobInstanceService, mock(StageStatusTopic.class), mock(StageStatusCache.class), securityService, pipelineDao, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
Pipeline pipeline = pipeline(10.0);
Pipeline pipelineThatLastPassed = pipeline(5.0);
when(pipelineDao.findPipelineByNameAndCounter(PIPELINE_NAME, 3)).thenReturn(pipeline);
when(pipelineDao.findEarlierPipelineThatPassedForStage(PIPELINE_NAME, STAGE_NAME, 10.0)).thenReturn(pipelineThatLastPassed);
when(stageDao.findFailedStagesBetween(PIPELINE_NAME, STAGE_NAME, 5.0, 10.0)).thenReturn(asList(identifier(2, "2"), identifier(1, "1")));
assertThat(runFinder.findRunForStage(new StageIdentifier(PIPELINE_NAME, 3, STAGE_NAME, "1")).isEmpty(), is(true));
}
use of com.thoughtworks.go.server.transaction.TransactionSynchronizationManager in project gocd by gocd.
the class StageServiceTest method shouldFindStageSummaryModelForGivenStageIdentifier.
@Test
public void shouldFindStageSummaryModelForGivenStageIdentifier() throws Exception {
SecurityService securityService = alwaysAllow();
TransactionSynchronizationManager transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
StageService service = new StageService(stageDao, null, null, null, securityService, null, changesetService, goConfigService, transactionTemplate, transactionSynchronizationManager, goCache);
Stage stageRun1 = StageMother.completedStageInstanceWithTwoPlans("stage_name");
stageRun1.setIdentifier(new StageIdentifier("pipeline_name/10/stage_name/1"));
stageRun1.setCounter(1);
Stage stageRun2 = StageMother.completedStageInstanceWithTwoPlans("stage_name");
stageRun2.setIdentifier(new StageIdentifier("pipeline_name/10/stage_name/2"));
stageRun2.setCounter(2);
Stages stages = new Stages(stageRun1, stageRun2);
StageIdentifier stageId = new StageIdentifier("pipeline_name/10/stage_name/2");
when(stageDao.getAllRunsOfStageForPipelineInstance(stageId.getPipelineName(), stageId.getPipelineCounter(), stageId.getStageName())).thenReturn(stages);
StageSummaryModel stageForView = service.findStageSummaryByIdentifier(stageId, ALWAYS_ALLOW_USER, new HttpLocalizedOperationResult());
assertThat(stageForView.getName(), is(stageRun2.getName()));
assertThat(stageForView.getState(), is(stageRun2.stageState()));
assertThat(stageForView.getStageCounter(), is(String.valueOf(stageRun2.getCounter())));
assertThat(stageForView.getTotalRuns(), is(2));
}
Aggregations