gerrithudsontrigger/src/test/java/com/sonyericsson/hudson/plugins/gerrit/trigger/spec/SpecGerritTriggerHudsonTest.java
/**
     * Tests to trigger builds with two different patch sets. Expecting two build to be scheduled with one cause each.
     *
     * @throws Exception if so.
     */
Tests to trigger builds with two different patch sets. Expecting two build to be scheduled with one cause each.
@throws Exception if so.
Tests to trigger builds with two different patch sets . Expecting two build to be scheduled with one cause each . @throws Exception if so .
@LocalData
    public void testDoubleTriggeredBuildsOfDifferentChange() throws Exception {
        FreeStyleProject project = DuplicatesUtil.createGerritTriggeredJob(this, "projectX");
        server.waitForCommand(GERRIT_STREAM_EVENTS, 2000);
        PluginImpl.getInstance().triggerEvent(Setup.createPatchsetCreated());
        PatchsetCreated patchsetCreated = Setup.createPatchsetCreated();
        patchsetCreated.getChange().setNumber("2000");
        PluginImpl.getInstance().triggerEvent(patchsetCreated);
        RunList<FreeStyleBuild> builds = DuplicatesUtil.waitForBuilds(project, 2, 5000);
        assertEquals(2, builds.size());
        assertSame(Result.SUCCESS, builds.get(0).getResult());
        assertSame(Result.SUCCESS, builds.get(1).getResult());
        int count = 0;
        for (Cause cause : builds.get(0).getCauses()) {
            if (cause instanceof GerritCause) {
                count++;
            }
        }
        assertEquals(1, count);
        count = 0;
        for (Cause cause : builds.get(1).getCauses()) {
            if (cause instanceof GerritCause) {
                count++;
                assertNotNull(((GerritCause)cause).getContext());
                assertNotNull(((GerritCause)cause).getEvent());
            }
        }
        assertEquals(1, count);
    }
@ LocalData public void testDoubleTriggeredBuildsOfDifferentChange ( ) throws Exception { FreeStyleProject project = DuplicatesUtil . createGerritTriggeredJob ( this , "projectX" ) ; server . waitForCommand ( GERRIT_STREAM_EVENTS , 2000 ) ; PluginImpl . getInstance ( ) . triggerEvent ( Setup . createPatchsetCreated ( ) ) ; PatchsetCreated patchsetCreated = Setup . createPatchsetCreated ( ) ; patchsetCreated . getChange ( ) . setNumber ( "2000" ) ; PluginImpl . getInstance ( ) . triggerEvent ( patchsetCreated ) ; RunList < FreeStyleBuild > builds = DuplicatesUtil . waitForBuilds ( project , 2 , 5000 ) ; assertEquals ( 2 , builds . size ( ) ) ; assertSame ( Result . SUCCESS , builds . get ( 0 ) . getResult ( ) ) ; assertSame ( Result . SUCCESS , builds . get ( 1 ) . getResult ( ) ) ; int count = 0 ; for ( Cause cause : builds . get ( 0 ) . getCauses ( ) ) { if ( cause instanceof GerritCause ) { count ++ ; } } assertEquals ( 1 , count ) ; count = 0 ; for ( Cause cause : builds . get ( 1 ) . getCauses ( ) ) { if ( cause instanceof GerritCause ) { count ++ ; assertNotNull ( ( ( GerritCause ) cause ) . getContext ( ) ) ; assertNotNull ( ( ( GerritCause ) cause ) . getEvent ( ) ) ; } } assertEquals ( 1 , count ) ; }
Tests to trigger builds with two different patch sets.
Tests to trigger builds with two different patch sets .