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 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 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 MaterialRepositoryTest method setUp.
@Before
public void setUp() {
databaseStrategy = mock(DatabaseStrategy.class);
sessionFactory = mock(SessionFactory.class);
goCache = mock(GoCache.class);
ourCustomCache = new HashMap<>();
transactionSynchronizationManager = mock(TransactionSynchronizationManager.class);
mockHibernateTemplate = mock(HibernateTemplate.class);
materialConfigConverter = mock(MaterialConfigConverter.class);
materialExpansionService = mock(MaterialExpansionService.class);
materialRepository = new MaterialRepository(sessionFactory, goCache, 4242, transactionSynchronizationManager, materialConfigConverter, materialExpansionService, databaseStrategy);
materialRepository.setHibernateTemplate(mockHibernateTemplate);
when(goCache.get(anyString())).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
return ourCustomCache.get(arguments[0]);
}
});
doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
return ourCustomCache.put((String) arguments[0], arguments[1]);
}
}).when(goCache).put(anyString(), anyObject());
when(goCache.remove(anyString())).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
return ourCustomCache.remove(arguments[0]);
}
});
}
use of com.thoughtworks.go.server.transaction.TransactionSynchronizationManager in project gocd by gocd.
the class TransactionSynchronizationManagerTest method shouldRegisterSynchronization_andNotCallItOnTransactionFailure.
@Test
public void shouldRegisterSynchronization_andNotCallItOnTransactionFailure() {
final TransactionSynchronizationManager synchronizationManager = new TransactionSynchronizationManager();
final TransactionSynchronization synchronization = mock(TransactionSynchronization.class);
try {
transactionTemplate.execute(new org.springframework.transaction.support.TransactionCallbackWithoutResult() {
@Override
protected void doInTransactionWithoutResult(TransactionStatus status) {
synchronizationManager.registerSynchronization(synchronization);
throw new RuntimeException();
}
});
} catch (Exception e) {
// ignore
}
verify(synchronization, never()).afterCommit();
}
Aggregations