hudson.util.OneShotEvent Java Examples

The following examples show how to use hudson.util.OneShotEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 6 votes vote down vote up
private boolean ciSkipTestHelper(String MRDescription, String lastCommitMsg) throws IOException, InterruptedException {
    final OneShotEvent buildTriggered = new OneShotEvent();
    FreeStyleProject project = jenkins.createFreeStyleProject();
    project.getBuildersList().add(new TestBuilder() {
        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            buildTriggered.signal();
            return true;
        }
    });
    project.setQuietPeriod(0);
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = new MergeRequestHookTriggerHandlerImpl(Arrays.asList(State.opened, State.reopened), Arrays.asList(Action.approved), false, false, false);
    mergeRequestHookTriggerHandler.handle(project, mergeRequestHook()
            .withObjectAttributes(defaultMergeRequestObjectAttributes().withDescription(MRDescription).withLastCommit(commit().withMessage(lastCommitMsg).withAuthor(user().withName("test").build()).withId("testid").build()).build())
            .build(), true, BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
        newMergeRequestLabelFilter(null));

    buildTriggered.block(10000);
    return buildTriggered.isSignaled();
}
 
Example #2
Source File: PipelineHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void pipeline_build() throws IOException, InterruptedException, GitAPIException, ExecutionException {

    final OneShotEvent buildTriggered = new OneShotEvent();
    FreeStyleProject project = jenkins.createFreeStyleProject();
    project.getBuildersList().add(new TestBuilder() {
        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            buildTriggered.signal();
            return true;
        }
    });
    project.setQuietPeriod(0);

    pipelineHookTriggerHandler.handle(project, pipelineHook, false, newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
                                  newMergeRequestLabelFilter(null));

    buildTriggered.block(10000);
    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example #3
Source File: PipelineHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 6 votes vote down vote up
@Test
/**
 * always triggers since pipeline events do not contain ci skip message
 */
public void pipeline_ciSkip() throws IOException, InterruptedException {
    final OneShotEvent buildTriggered = new OneShotEvent();
    FreeStyleProject project = jenkins.createFreeStyleProject();
    project.getBuildersList().add(new TestBuilder() {
        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            buildTriggered.signal();
            return true;
        }
    });
    project.setQuietPeriod(0);
    pipelineHookTriggerHandler.handle(project, pipelineHook , true, newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
        newMergeRequestLabelFilter(null));

    buildTriggered.block(10000);
    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example #4
Source File: PushHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 6 votes vote down vote up
@Test
public void push_ciSkip() throws IOException, InterruptedException {
    final OneShotEvent buildTriggered = new OneShotEvent();
    FreeStyleProject project = jenkins.createFreeStyleProject();
    project.getBuildersList().add(new TestBuilder() {
        @Override
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
            buildTriggered.signal();
            return true;
        }
    });
    project.setQuietPeriod(0);
    pushHookTriggerHandler.handle(project, pushHook()
            .withCommits(Arrays.asList(commit().withMessage("some message").build(),
                                       commit().withMessage("[ci-skip]").build()))
            .build(), true, newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
                                  newMergeRequestLabelFilter(null));

    buildTriggered.block(10000);
    assertThat(buildTriggered.isSignaled(), is(false));
}
 
Example #5
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_build_for_update_state_when_updated_state_and_approved_action_enabled() throws IOException, InterruptedException, GitAPIException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnApprovedMergeRequest(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.updated, Action.approved);

    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example #6
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_build_when_closed() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnClosedMergeRequest(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.closed, Action.closed);

    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example #7
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_build_when_closed_with_actions_enabled() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnClosedMergeRequest(true)
        .setTriggerOnApprovedMergeRequest(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.closed, Action.closed);

    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example #8
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_do_not_build_when_accepted_some_enabled() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOpenMergeRequest(TriggerOpenMergeRequest.source)
        .setTriggerOnApprovedMergeRequest(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.merged);

    assertThat(buildTriggered.isSignaled(), is(false));
}
 
Example #9
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_build_for_accepted_state_when_approved_action_triggered() throws IOException, InterruptedException, GitAPIException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnApprovedMergeRequest(true)
        .setTriggerOnAcceptedMergeRequest(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.merged, Action.approved);

    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example #10
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_do_not_build_when_closed() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOpenMergeRequest(TriggerOpenMergeRequest.source)
        .setTriggerOnApprovedMergeRequest(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.closed);

    assertThat(buildTriggered.isSignaled(), is(false));
}
 
Example #11
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_build_when_accepted_with_approved_action_enabled() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnAcceptedMergeRequest(true)
        .setTriggerOnApprovedMergeRequest(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.merged, Action.merge);

    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example #12
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
private OneShotEvent doHandle(MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler,
		MergeRequestObjectAttributesBuilder objectAttributes) throws GitAPIException, IOException,
           InterruptedException {
	Git.init().setDirectory(tmp.getRoot()).call();
       tmp.newFile("test");
       Git git = Git.open(tmp.getRoot());
       git.add().addFilepattern("test");
       RevCommit commit = git.commit().setMessage("test").call();
       ObjectId head = git.getRepository().resolve(Constants.HEAD);
       String repositoryUrl = tmp.getRoot().toURI().toString();

       final OneShotEvent buildTriggered = new OneShotEvent();
       FreeStyleProject project = jenkins.createFreeStyleProject();
       project.setScm(new GitSCM(repositoryUrl));
       project.getBuildersList().add(new TestBuilder() {
           @Override
           public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
               buildTriggered.signal();
               return true;
           }
       });
       project.setQuietPeriod(0);
	mergeRequestHookTriggerHandler.handle(project, mergeRequestHook()
               .withObjectAttributes(objectAttributes
           		    .withTargetBranch("refs/heads/" + git.nameRev().add(head).call().get(head))
           		    .withLastCommit(commit().withAuthor(user().withName("test").build()).withId(commit.getName()).build())
                   .build())
               .withProject(project()
                   .withWebUrl("https://gitlab.org/test.git")
                   .build()
               )
               .build(), true, BranchFilterFactory.newBranchFilter(branchFilterConfig().build(BranchFilterType.All)),
           newMergeRequestLabelFilter(null));

       buildTriggered.block(10000);
       return buildTriggered;
}
 
Example #13
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_do_not_build_for_updated_state_and_approved_action_when_both_not_enabled() throws IOException, InterruptedException, GitAPIException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOpenMergeRequest(TriggerOpenMergeRequest.source)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.updated, Action.approved);

    assertThat(buildTriggered.isSignaled(), is(false));
}
 
Example #14
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_do_not_build_for_updated_state_and_approved_action_when_updated_enabled_but_approved_not() throws IOException, InterruptedException, GitAPIException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler =
        withConfig()
            .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.updated, Action.approved);

    assertThat(buildTriggered.isSignaled(), is(false));
}
 
Example #15
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
private void do_not_build_for_state_when_nothing_enabled(State state) throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnMergeRequest(false)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, state);

    assertThat(buildTriggered.isSignaled(), is(false));
}
 
Example #16
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_build_for_update_state_and_action_when_updated_state_and_approved_action_enabled() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnApprovedMergeRequest(true)
        .setTriggerOpenMergeRequest(TriggerOpenMergeRequest.source)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.updated, Action.update);

    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example #17
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
private void mergeRequest_build_only_when_approved(Action action)
		throws GitAPIException, IOException, InterruptedException {
	MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
           .setTriggerOnMergeRequest(false)
           .setTriggerOnApprovedMergeRequest(true)
           .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, action);

    assertThat(buildTriggered.isSignaled(), is(false));
}
 
Example #18
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_do_not_build_for_update_state_and_action_when_opened_state_and_approved_action_enabled() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnApprovedMergeRequest(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.updated, Action.update);

    assertThat(buildTriggered.isSignaled(), is(false));
}
 
Example #19
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_build_for_update_state_when_updated_state_and_merge_action() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnAcceptedMergeRequest(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.updated, Action.merge);

    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example #20
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_build_for_approved_action_when_opened_state_and_approved_action_enabled() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnApprovedMergeRequest(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.updated, Action.approved);
    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example #21
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_build_for_approved_action_when_only_approved_enabled() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnMergeRequest(false)
        .setTriggerOnApprovedMergeRequest(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.updated, Action.approved);

    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example #22
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_build_when_new_commits_were_pushed_state_opened_action_open() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnMergeRequest(true)
        .setTriggerOnlyIfNewCommitsPushed(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.opened, Action.open);

    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example #23
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_build_when_new_commits_were_pushed_state_reopened_action_reopen() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnMergeRequest(true)
        .setTriggerOnlyIfNewCommitsPushed(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.reopened, Action.reopen);

    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example #24
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_build_when_new_commits_were_pushed_do_not_build_without_commits() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnMergeRequest(true)
        .setTriggerOnlyIfNewCommitsPushed(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.updated, Action.update);

    assertThat(buildTriggered.isSignaled(), is(false));
}
 
Example #25
Source File: MergeRequestHookTriggerHandlerImplTest.java    From gitlab-plugin with GNU General Public License v2.0 5 votes vote down vote up
@Test
public void mergeRequest_build_when_accepted() throws IOException, InterruptedException, GitAPIException, ExecutionException {
    MergeRequestHookTriggerHandler mergeRequestHookTriggerHandler = withConfig()
        .setTriggerOnAcceptedMergeRequest(true)
        .build();
    OneShotEvent buildTriggered = doHandle(mergeRequestHookTriggerHandler, State.merged, Action.merge);

    assertThat(buildTriggered.isSignaled(), is(true));
}
 
Example #26
Source File: AbstractJenkinsTestProject.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
protected void submitAndAssertFixture(ProjectFixture fixture) throws Exception {
    this.subscribeProject(fixture);
    OneShotEvent event = fixture.getEvent();
    event.block(fixture.getTimeout());
    Assertions.assertThat(event.isSignaled())
        .describedAs("Fixture %s should be pass", fixture.getName())
        .isEqualTo(fixture.getShouldStarted());
}
 
Example #27
Source File: AbstractFreestyleTestProject.java    From aws-codecommit-trigger-plugin with Apache License 2.0 5 votes vote down vote up
protected void subscribeProject(final ProjectFixture fixture) throws Exception {
        String name = UUID.randomUUID().toString();

        final FreeStyleProject job = jenkinsRule.getInstance().createProject(FreeStyleProject.class, name);
        job.setScm(new NullSCM());
        if (fixture.getScm() != null) {
            job.setScm(fixture.getScm());
        }

        final String uuid = this.sqsQueue.getUuid();

        SQSTrigger trigger = null;

        if (fixture.isHasTrigger()) {
            trigger = new SQSTrigger(uuid, fixture.isSubscribeInternalScm(), fixture.getScmConfigs());
        }

//        final OneShotEvent event = new OneShotEvent();
        fixture.setEvent(new OneShotEvent());
        job.getBuildersList().add(new TestBuilder() {

            @Override
            public boolean perform(AbstractBuild<?, ?> build, Launcher launcher, BuildListener listener) throws InterruptedException, IOException {
                fixture.setLastBuild(job.getLastBuild());
                fixture.getEvent().signal();
                return true;
            }
        });
        job.setQuietPeriod(0);

        if (trigger != null) {
            trigger.start(job, false);
            job.addTrigger(trigger);
        }

//        fixture.setEvent(event);
    }
 
Example #28
Source File: SseEventTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void jobCreationEvents() throws IOException, ExecutionException, InterruptedException {
    final OneShotEvent success = new OneShotEvent();

    final AssertionHelper assertionHelper = new AssertionHelper();
    SSEConnection con = new SSEConnection(j.getURL(), "me", new ChannelSubscriber() {
        @Override
        public void onMessage(@Nonnull Message message) {
            System.out.println(message);
            assertionHelper.isEquals("job_crud_created", message.get(jenkins_event));
            assertionHelper.isEquals("/blue/rest/organizations/jenkins/pipelines/test1/", message.get(blueocean_job_rest_url));
            assertionHelper.isEquals("test1", message.get(blueocean_job_pipeline_name));
            assertionHelper.isEquals("test1", message.get(job_name));
            assertionHelper.isEquals("job", message.get(jenkins_channel));
            assertionHelper.isNull(message.get(job_ismultibranch));
            assertionHelper.isNull(message.get(job_multibranch_indexing_result));
            assertionHelper.isNull(message.get(job_multibranch_indexing_status));
            assertionHelper.isNull(message.get(Job.job_run_queueId));
            assertionHelper.isNull(message.get(Job.job_run_status));

            if ("job_crud_created".equals(message.get(jenkins_event)))
                success.signal();
        }
    });

    con.subscribe("job");

    j.createFreeStyleProject("test1");

    // make sure we got the event we were looking for
    success.block(5000);
    con.close();
    if(assertionHelper.totalErrors() > 0){
        fail("There were errors: "+ assertionHelper.totalErrors());
    }
}
 
Example #29
Source File: SseEventTest.java    From blueocean-plugin with MIT License 5 votes vote down vote up
@Test
public void jobRunEvents() throws IOException, ExecutionException, InterruptedException {
    final OneShotEvent success = new OneShotEvent();

    final FreeStyleProject p = j.createFreeStyleProject("test1");
    final AssertionHelper assertionHelper = new AssertionHelper();
    SSEConnection con = new SSEConnection(j.getURL(), "me", new ChannelSubscriber() {
        @Override
        public void onMessage(@Nonnull Message message) {
            System.out.println(message);
            assertionHelper.isEquals("/blue/rest/organizations/jenkins/pipelines/test1/", message.get(blueocean_job_rest_url));
            assertionHelper.isEquals(p.getName(), message.get(blueocean_job_pipeline_name));
            if(message.get(jenkins_event).equals(Events.JobChannel.job_run_queue_left.name())) {
                assertionHelper.isEquals("1", message.get(blueocean_queue_item_expected_build_number));
            }
            assertionHelper.isEquals(p.getName(), message.get(job_name));
            assertionHelper.isEquals("job", message.get(jenkins_channel));
            assertionHelper.isEquals("jenkins", message.get(jenkins_org));
            assertionHelper.isNull(message.get(job_ismultibranch));
            assertionHelper.isNull(message.get(job_multibranch_indexing_result));
            assertionHelper.isNull(message.get(job_multibranch_indexing_status));
            assertionHelper.isNotNull(message.get(Job.job_run_queueId));
            assertionHelper.isNotNull(message.get(Job.job_run_status));

            if ("SUCCESS".equals(message.get(Job.job_run_status))
                    && "job_run_ended".equals(message.get(jenkins_event)))
                success.signal();
        }
    });
    con.subscribe("job");
    p.scheduleBuild2(0).get();

    // make sure we got the event we were looking for
    success.block(5000);
    con.close();

    if(assertionHelper.totalErrors() > 0){
        fail("There were errors: "+ assertionHelper.totalErrors());
    }
}
 
Example #30
Source File: WorkSpaceZipperTest.java    From aws-lambda-jenkins-plugin with MIT License 5 votes vote down vote up
@Test
public void testGetZipWithZip() throws Exception {
    final OneShotEvent buildEnded = new OneShotEvent();

    FreeStyleProject p = j.createFreeStyleProject();
    p.getBuildersList().add(new TestBuilder() {
        public boolean perform(AbstractBuild<?, ?> build, Launcher launcher,
                               BuildListener listener) throws InterruptedException, IOException {
            build.getWorkspace().child("echo.zip").copyFrom(new FileInputStream(testUtil.getResource("echo.zip")));
            buildEnded.signal();
            return true;
        }
    });

    p.scheduleBuild2(0);
    buildEnded.block();

    JenkinsLogger logger = new JenkinsLogger(System.out);
    WorkSpaceZipper workSpaceZipper = new WorkSpaceZipper(p.getSomeWorkspace(), logger);
    File zip = workSpaceZipper.getZip("echo.zip");

    assertTrue(zip.exists());
    assertTrue(zip.getAbsolutePath().contains("awslambda-"));

    ZipFile zipFile = new ZipFile(zip);
    assertNotNull(zipFile);
    assertNotNull(zipFile.getEntry("index.js"));
}