Search in sources :

Example 11 with Mockery

use of org.jmock.Mockery in project gocd by gocd.

the class JobStatusCacheTest method shouldLoadMostRecentInstanceFromDBOnlyOnce.

@Test
public void shouldLoadMostRecentInstanceFromDBOnlyOnce() throws SQLException {
    Mockery mockery = new Mockery();
    final StageDao mock = mockery.mock(StageDao.class);
    final JobInstance instance = JobInstanceMother.passed("linux-firefox");
    final List<JobInstance> found = new ArrayList<>();
    found.add(instance);
    mockery.checking(new Expectations() {

        {
            one(mock).mostRecentJobsForStage("pipeline", "stage");
            will(returnValue(found));
        }
    });
    JobConfigIdentifier identifier = new JobConfigIdentifier(instance.getPipelineName(), instance.getStageName(), instance.getName());
    JobStatusCache cache = new JobStatusCache(mock);
    assertThat(cache.currentJob(identifier).getState(), is(instance.getState()));
    // call currentJob for the second time, should not call jobInstanceDao now
    assertThat(cache.currentJob(identifier).getState(), is(instance.getState()));
}
Also used : StageDao(com.thoughtworks.go.server.dao.StageDao) Expectations(org.jmock.Expectations) ArrayList(java.util.ArrayList) Mockery(org.jmock.Mockery) Test(org.junit.Test)

Example 12 with Mockery

use of org.jmock.Mockery in project gocd by gocd.

the class StageStatusCacheTest method shouldLoadMostRecentInstanceFromDBOnlyOnce.

@Test
public void shouldLoadMostRecentInstanceFromDBOnlyOnce() throws SQLException {
    Mockery mockery = new Mockery();
    final StageDao mock = mockery.mock(StageDao.class);
    final StageConfigIdentifier identifier = new StageConfigIdentifier("cruise", "dev");
    final Stage instance = StageMother.failingStage("dev");
    mockery.checking(new Expectations() {

        {
            one(mock).mostRecentStage(identifier);
            will(returnValue(instance));
        }
    });
    StageStatusCache cache = new StageStatusCache(mock);
    assertThat(cache.currentStage(identifier).getName(), is(instance.getName()));
    // call currentStage for the second time, should not call stageDao now
    assertThat(cache.currentStage(identifier).getName(), is(instance.getName()));
}
Also used : StageDao(com.thoughtworks.go.server.dao.StageDao) Expectations(org.jmock.Expectations) Mockery(org.jmock.Mockery) Test(org.junit.Test)

Example 13 with Mockery

use of org.jmock.Mockery in project gocd by gocd.

the class StageResultTypeHandlerCallbackTest method assertMaps.

private void assertMaps(final String str, StageResult value) throws SQLException {
    final ResultGetter resultGetter;
    Mockery context = new Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };
    resultGetter = context.mock(ResultGetter.class);
    context.checking(new Expectations() {

        {
            one(resultGetter).getString();
            will(returnValue(str));
        }
    });
    StageResult result = (StageResult) callback.getResult(resultGetter);
    assertThat(result, is(equal(value)));
    final ParameterSetter parameterSetter = context.mock(ParameterSetter.class);
    context.checking(new Expectations() {

        {
            one(parameterSetter).setString(str);
        }
    });
    callback.setParameter(parameterSetter, value);
}
Also used : Expectations(org.jmock.Expectations) StageResult(com.thoughtworks.go.domain.StageResult) ParameterSetter(com.ibatis.sqlmap.client.extensions.ParameterSetter) ResultGetter(com.ibatis.sqlmap.client.extensions.ResultGetter) Mockery(org.jmock.Mockery)

Example 14 with Mockery

use of org.jmock.Mockery in project gocd by gocd.

the class StageStateTypeHandlerCallbackTest method assertMaps.

private void assertMaps(final String str, StageState value) throws SQLException {
    final ResultGetter resultGetter;
    Mockery context = new Mockery() {

        {
            setImposteriser(ClassImposteriser.INSTANCE);
        }
    };
    resultGetter = context.mock(ResultGetter.class);
    context.checking(new Expectations() {

        {
            one(resultGetter).getString();
            will(returnValue(str));
        }
    });
    StageState result = (StageState) callback.getResult(resultGetter);
    assertThat(result, is(equal(value)));
    final ParameterSetter parameterSetter = context.mock(ParameterSetter.class);
    context.checking(new Expectations() {

        {
            one(parameterSetter).setString(str);
        }
    });
    callback.setParameter(parameterSetter, value);
}
Also used : Expectations(org.jmock.Expectations) StageState(com.thoughtworks.go.domain.StageState) ParameterSetter(com.ibatis.sqlmap.client.extensions.ParameterSetter) ResultGetter(com.ibatis.sqlmap.client.extensions.ResultGetter) Mockery(org.jmock.Mockery)

Example 15 with Mockery

use of org.jmock.Mockery in project gocd by gocd.

the class JobInstanceLogTest method setUp.

@Before
public void setUp() {
    context = new Mockery();
    context.setImposteriser(ClassImposteriser.INSTANCE);
    jobInstanceLog = new JobInstanceLog(null, new HashMap());
    defaultLogFile = new LogFile(new File("log20051209122103.xml"));
    rootFolder = new File("root");
    rootFolder.mkdirs();
    env = new SystemEnvironment();
}
Also used : SystemEnvironment(com.thoughtworks.go.util.SystemEnvironment) HashMap(java.util.HashMap) Mockery(org.jmock.Mockery) File(java.io.File) JobInstanceLog(com.thoughtworks.go.domain.JobInstanceLog) Before(org.junit.Before)

Aggregations

Mockery (org.jmock.Mockery)32 Before (org.junit.Before)21 Expectations (org.jmock.Expectations)14 Synchroniser (org.jmock.lib.concurrent.Synchroniser)12 HttpServletResponse (javax.servlet.http.HttpServletResponse)4 JUnit4Mockery (org.jmock.integration.junit4.JUnit4Mockery)4 Test (org.junit.Test)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 ParameterSetter (com.ibatis.sqlmap.client.extensions.ParameterSetter)2 ResultGetter (com.ibatis.sqlmap.client.extensions.ResultGetter)2 StageDao (com.thoughtworks.go.server.dao.StageDao)2 SystemEnvironment (com.thoughtworks.go.util.SystemEnvironment)2 File (java.io.File)2 ArrayList (java.util.ArrayList)2 Dictionary (java.util.Dictionary)2 HashMap (java.util.HashMap)2 Servlet (javax.servlet.Servlet)2 BundleContext (org.osgi.framework.BundleContext)2 ComponentContext (org.osgi.service.component.ComponentContext)2 JobInstanceLog (com.thoughtworks.go.domain.JobInstanceLog)1