Search in sources :

Example 1 with DatabaseStrategy

use of com.thoughtworks.go.server.database.DatabaseStrategy 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]);
        }
    });
}
Also used : SessionFactory(org.hibernate.SessionFactory) TransactionSynchronizationManager(com.thoughtworks.go.server.transaction.TransactionSynchronizationManager) HibernateTemplate(org.springframework.orm.hibernate3.HibernateTemplate) MaterialConfigConverter(com.thoughtworks.go.server.service.MaterialConfigConverter) Answer(org.mockito.stubbing.Answer) MaterialExpansionService(com.thoughtworks.go.server.service.MaterialExpansionService) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GoCache(com.thoughtworks.go.server.cache.GoCache) DatabaseStrategy(com.thoughtworks.go.server.database.DatabaseStrategy) Before(org.junit.Before)

Aggregations

GoCache (com.thoughtworks.go.server.cache.GoCache)1 DatabaseStrategy (com.thoughtworks.go.server.database.DatabaseStrategy)1 MaterialConfigConverter (com.thoughtworks.go.server.service.MaterialConfigConverter)1 MaterialExpansionService (com.thoughtworks.go.server.service.MaterialExpansionService)1 TransactionSynchronizationManager (com.thoughtworks.go.server.transaction.TransactionSynchronizationManager)1 SessionFactory (org.hibernate.SessionFactory)1 Before (org.junit.Before)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 Answer (org.mockito.stubbing.Answer)1 HibernateTemplate (org.springframework.orm.hibernate3.HibernateTemplate)1