Java 类hudson.model.FreeStyleProject 实例源码

项目:embeddable-badges-plugin    文件:PublicBadgeActionTest.java   
/**
 *
 * @throws Exception
 */
@PresetData(NO_ANONYMOUS_READACCESS)
@Test
public void authenticatedAccess() throws Exception {
    final FreeStyleProject project = j.createFreeStyleProject("free");
    JenkinsRule.WebClient wc = j.createWebClient();
    wc.login("alice", "alice");
    try {
        // try with wrong job name
        wc.goTo("buildStatus/buildIcon?job=dummy");
        fail("should fail, because there is no job with this name");
    } catch (FailingHttpStatusCodeException x) {
        assertEquals(HTTP_NOT_FOUND, x.getStatusCode());
    }
    wc.goTo("buildStatus/buildIcon?job=free", "image/svg+xml");
    j.buildAndAssertSuccess(project);
}
项目:vsts-jenkins-build-integration-sample    文件:TfsBuildWrapperTest.java   
@Test
public void loggerShouldBeDecorated() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject();
    project.getPublishersList().add(new TfsBuildNotifier("http://testurl.com", "tester", Secret.fromString("testpass"), "testProj", "1"));
    jenkinsBuild = project.scheduleBuild2(0).get();

    OutputStream os = new ByteArrayOutputStream(2048);
    OutputStream appender = underTest.decorateLogger(jenkinsBuild, os);

    verify(buildFacadeMock, times(1)).startBuild();
    verify(buildFacadeMock, times(1)).startAllTaskRecords();

    assertNotNull("Did not create a log appender for TFS", appender);

    // verify we properly set environments, this tests makeBuildVariables
    Map<String,String> env = new HashMap<String, String>();
    underTest.makeBuildVariables(jenkinsBuild, env);

    assertTrue("Env is empty", env.size() > 0);
    assertEquals("build is should be 1", 1, Integer.parseInt(env.get("TfsBuildId" + jenkinsBuild.getId())));
}
项目:vsts-jenkins-build-integration-sample    文件:TfsBuildWrapperTest.java   
@Test
public void skipDecorateLoggerIfNoNotifier() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject();
    jenkinsBuild = project.scheduleBuild2(0).get();

    ByteArrayOutputStream os = new ByteArrayOutputStream(2048);
    OutputStream appender = underTest.decorateLogger(jenkinsBuild, os);

    verify(buildFacadeMock, never()).startBuild();
    verify(buildFacadeMock, never()).startAllTaskRecords();

    // reference check, not equality check since we should just return without decorating
    assertTrue("Created a log appender for TFS without TFS configuration!", os == appender);

    ByteArrayInputStream is = new ByteArrayInputStream(os.toByteArray());
    BufferedReader reader = new BufferedReader(new InputStreamReader(is));

    String log = reader.readLine();
    assertTrue("Log not displayed on screen", log.indexOf("not configured") > 0);
}
项目:embeddable-badges-plugin    文件:PublicBadgeActionTest.java   
/**
 *
 * @throws Exception
 */
@Test
public void validAnonymousViewStatusAccess() throws Exception {

    final SecurityRealm realm = j.createDummySecurityRealm();
    j.jenkins.setSecurityRealm(realm);
    GlobalMatrixAuthorizationStrategy auth = new GlobalMatrixAuthorizationStrategy();
    auth.add(VIEW_STATUS, "anonymous");
    j.getInstance().setSecurityRealm(realm);
    j.getInstance().setAuthorizationStrategy(auth);

    final FreeStyleProject project = j.createFreeStyleProject("free");

    JenkinsRule.WebClient wc = j.createWebClient();
    try {
        // try with wrong job name
        wc.goTo("buildStatus/buildIcon?job=dummy");
        fail("should fail, because there is no job with this name");
    } catch (FailingHttpStatusCodeException x) {
        assertEquals(HTTP_NOT_FOUND, x.getStatusCode());
    }

    wc.goTo("buildStatus/buildIcon?job=free", "image/svg+xml");
    j.buildAndAssertSuccess(project);

}
项目:embeddable-badges-plugin    文件:PublicBadgeActionTest.java   
/**
 *
 * @throws Exception
 */
@PresetData(ANONYMOUS_READONLY)
@Test
public void validAnonymousAccess() throws Exception {
    final FreeStyleProject project = j.createFreeStyleProject("free");
    JenkinsRule.WebClient wc = j.createWebClient();
    try {
        // try with wrong job name
        wc.goTo("buildStatus/buildIcon?job=dummy");
        fail("should fail, because there is no job with this name");
    } catch (FailingHttpStatusCodeException x) {
        assertEquals(HTTP_NOT_FOUND, x.getStatusCode());
    }

    // try with correct job name
    wc.goTo("buildStatus/buildIcon?job=free", "image/svg+xml");
    j.buildAndAssertSuccess(project);
}
项目:run-selector-plugin    文件:ParameterizedRunSelectorTest.java   
/**
 * Also applicable for workflow jobs.
 */
@Issue("JENKINS-30357")
@Test
public void testWorkflow() throws Exception {
    FreeStyleProject jobToSelect = j.createFreeStyleProject();
    Run runToSelect = j.assertBuildStatusSuccess(jobToSelect.scheduleBuild2(0));

    WorkflowJob selecter = createWorkflowJob();

    ParameterDefinition paramDef = new StringParameterDefinition(
            "SELECTOR", "<StatusRunSelector><buildStatus>STABLE</buildStatus></StatusRunSelector>"
    );
    selecter.addProperty(new ParametersDefinitionProperty(paramDef));

    selecter.setDefinition(new CpsFlowDefinition(String.format("" +
            "def runWrapper = selectRun job: '%s', " +
            " selector: [$class: 'ParameterizedRunSelector', parameterName: '${SELECTOR}'] \n" +
            "assert(runWrapper.id == '%s')", jobToSelect.getFullName(), runToSelect.getId())));

    j.assertBuildStatusSuccess(selecter.scheduleBuild2(0));
}
项目:run-selector-plugin    文件:ParameterizedRunSelectorTest.java   
/**
 * Should not cause a fatal error even for a broken selectors.
 */
@Test
public void testBrokenParameter() throws Exception {
    FreeStyleProject jobToSelect = j.createFreeStyleProject();
    FreeStyleProject selecter = j.createFreeStyleProject();

    RunSelector selector = new ParameterizedRunSelector("${SELECTOR}");
    Run run = (Run) selecter.scheduleBuild2(
            0,
            new ParametersAction(
                    new StringParameterValue("SELECTOR", "<SomeBrokenSelector")
            )
    ).get();
    j.assertBuildStatusSuccess(run);

    Run selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL));
    assertThat(selectedRun, nullValue());
}
项目:run-selector-plugin    文件:ParameterizedRunSelectorTest.java   
/**
 * Should not cause a fatal error even for an unavailable selectors.
 */
@Test
public void testUnavailableSelector() throws Exception {
    FreeStyleProject jobToSelect = j.createFreeStyleProject();
    FreeStyleProject selecter = j.createFreeStyleProject();

    RunSelector selector = new ParameterizedRunSelector("${SELECTOR}");
    Run run = (Run) selecter.scheduleBuild2(
            0,
            new ParametersAction(
                    new StringParameterValue("SELECTOR", "<NoSuchSelector />")
            )
    ).get();
    j.assertBuildStatusSuccess(run);

    Run selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL));
    assertThat(selectedRun, nullValue());
}
项目:run-selector-plugin    文件:ParameterizedRunSelectorTest.java   
/**
 * Should not cause a fatal error even for an empty selectors.
 */
@Test
public void testEmptySelector() throws Exception {
    FreeStyleProject jobToSelect = j.createFreeStyleProject();
    FreeStyleProject selecter = j.createFreeStyleProject();

    RunSelector selector = new ParameterizedRunSelector("${SELECTOR}");
    Run run = (Run) selecter.scheduleBuild2(
            0,
            new ParametersAction(
                    new StringParameterValue("SELECTOR", "")
            )
    ).get();
    j.assertBuildStatusSuccess(run);

    Run selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL));
    assertThat(selectedRun, nullValue());
}
项目:run-selector-plugin    文件:ParameterizedRunSelectorTest.java   
/**
 * Also accepts immediate value.
 */
@Test
public void testImmediateValue() throws Exception {
    // Prepare an artifact to be copied.
    FreeStyleProject jobToSelect = j.createFreeStyleProject();
    Run runToSelect = j.assertBuildStatusSuccess(jobToSelect.scheduleBuild2(0));

    WorkflowJob selecter = createWorkflowJob();
    selecter.setDefinition(new CpsFlowDefinition(String.format("" +
            "def runWrapper = selectRun job: '%s', " +
            " selector: [$class: 'ParameterizedRunSelector', parameterName: '${SELECTOR}'] \n" +
            "assert(runWrapper.id == '%s')", jobToSelect.getFullName(), runToSelect.getId())));

    j.assertBuildStatusSuccess(selecter.scheduleBuild2(
            0,
            null,
            new ParametersAction(new StringParameterValue(
                    "SELECTOR", "<StatusRunSelector><buildStatus>STABLE</buildStatus></StatusRunSelector>"
            ))
    ));
}
项目:run-selector-plugin    文件:ParameterizedRunSelectorTest.java   
/**
 * Also accepts variable expression.
 */
@Test
public void testVariableExpression() throws Exception {
    FreeStyleProject jobToSelect = j.createFreeStyleProject();
    Run runToSelect = j.assertBuildStatusSuccess(jobToSelect.scheduleBuild2(0));

    FreeStyleProject selecter = j.createFreeStyleProject();
    RunSelector selector = new ParameterizedRunSelector("${SELECTOR}");

    Run run = j.assertBuildStatusSuccess(selecter.scheduleBuild2(
            0,
            (Cause) null,
            new ParametersAction(new StringParameterValue(
                    "SELECTOR",
                    "<StatusRunSelector><buildStatus>STABLE</buildStatus></StatusRunSelector>"
            ))
    ));
    Run selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL));
    assertThat(selectedRun, is(runToSelect));
}
项目:cucumber-living-documentation-plugin    文件:CucumberLivingDocumentationIT.java   
@Test
public void shouldGenerateLivingDocumentatation() throws Exception{
    //given
    FreeStyleProject project = jenkins.createFreeStyleProject("test");
    SingleFileSCM scm = new SingleFileSCM("asciidoctor.json",
            CucumberLivingDocumentationIT.class.getResource("/json-output/asciidoctor/asciidoctor.json").toURI().toURL());

    project.setScm(scm);
    CukedoctorPublisher publisher = new CukedoctorPublisher(null, FormatType.HTML, TocType.RIGHT, true, true, "Living Documentation",false,false,false,false,false);
    project.getPublishersList().add(publisher);
    project.save();

    //when
    FreeStyleBuild build = jenkins.buildAndAssertSuccess(project);

    //then
    jenkins.assertLogContains("Format: html" + NEW_LINE + "Toc: right"+NEW_LINE +
            "Title: Living Documentation"+NEW_LINE+"Numbered: true"+NEW_LINE +
            "Section anchors: true", build);
    jenkins.assertLogContains("Found 4 feature(s)...",build);
    jenkins.assertLogContains("Documentation generated successfully!",build);

}
项目:cucumber-living-documentation-plugin    文件:CucumberLivingDocumentationIT.java   
@Test
public void shouldGenerateLivingDocumentatationOnSlaveNode() throws Exception{
    DumbSlave slave = jenkins.createOnlineSlave();
    FreeStyleProject project = jenkins.createFreeStyleProject("test");
    project.setAssignedNode(slave);

    SingleFileSCM scm = new SingleFileSCM("asciidoctor.json",
            CucumberLivingDocumentationIT.class.getResource("/json-output/asciidoctor/asciidoctor.json").toURI().toURL());

    project.setScm(scm);
    CukedoctorPublisher publisher = new CukedoctorPublisher(null, FormatType.HTML, TocType.RIGHT, true, true, "Living Documentation",false,false,false,false,false);
    project.getPublishersList().add(publisher);
    project.save();

    FreeStyleBuild build = jenkins.buildAndAssertSuccess(project);
    jenkins.assertLogContains("Format: html" + NEW_LINE + "Toc: right"+NEW_LINE +
            "Title: Living Documentation"+NEW_LINE+"Numbered: true"+NEW_LINE +
            "Section anchors: true", build);
    jenkins.assertLogContains("Found 4 feature(s)...",build);
    jenkins.assertLogContains("Documentation generated successfully!",build);
    Assert.assertTrue("It should run on slave",build.getBuiltOn().equals(slave));

}
项目:consul-kv-builder-plugin    文件:ConsulKVBuilderTest.java   
@Test
public void consulWrite() throws BuilderException {

    try {
        FreeStyleProject project = jenkinsRule.createFreeStyleProject();
        project.getBuildersList().add(new ConsulKVBuilder(ConsulKVBuilderTest.ACL_ID,
                ConsulKVBuilderTest.HOST, ConsulKVBuilderTest.KEY,
                ConsulKVBuilderTest.VALUE, null, null, RequestMode.WRITE, 30000, 30000, DebugMode.ENABLED, false));
        FreeStyleBuild build = project.scheduleBuild2(0).get();

        String log = FileUtils.readFileToString(build.getLogFile());
        assertThat(log, containsString(ConsulKVBuilderTest.WRITE_TEST_VALUE));
    } catch (IOException ioe) {
        throw new BuilderException(ConsulKVBuilderTest.IO_EXCEPTION_TEXT, ioe);
    } catch (InterruptedException ie) {
        throw new BuilderException(ConsulKVBuilderTest.INTERRUPTED_EXCEPTION_TEXT, ie);
    } catch (ExecutionException ee) {
        throw new BuilderException(ConsulKVBuilderTest.EXECUTION_EXCEPTION_TEXT, ee);
    }
}
项目:consul-kv-builder-plugin    文件:ConsulKVBuilderTest.java   
@Test
public void consulRead() throws BuilderException {
    try {
        FreeStyleProject project = jenkinsRule.createFreeStyleProject();
        project.getBuildersList().add(new ConsulKVBuilder(null, ConsulKVBuilderTest.HOST, ConsulKVBuilderTest
                .KEY, null,
                null, ConsulKVBuilderTest.ENV_KEY, RequestMode.READ, 30000,
                30000, DebugMode.ENABLED, false));
        FreeStyleBuild build = project.scheduleBuild2(0).get();

        String log = FileUtils.readFileToString(build.getLogFile());
        assertThat(log, containsString(ConsulKVBuilderTest.READ_TEST_VALUE_1));
        assertThat(log, containsString(ConsulKVBuilderTest.READ_TEST_VALUE_2));
    } catch (IOException ioe) {
        throw new BuilderException(ConsulKVBuilderTest.IO_EXCEPTION_TEXT, ioe);
    } catch (InterruptedException ie) {
        throw new BuilderException(ConsulKVBuilderTest.INTERRUPTED_EXCEPTION_TEXT, ie);
    } catch (ExecutionException ee) {
        throw new BuilderException(ConsulKVBuilderTest.EXECUTION_EXCEPTION_TEXT, ee);
    }
}
项目:consul-kv-builder-plugin    文件:ConsulKVBuilderTest.java   
@Test
public void consulDelete() throws BuilderException {
    try {
        FreeStyleProject project = jenkinsRule.createFreeStyleProject();
        project.getBuildersList().add(new ConsulKVBuilder(ConsulKVBuilderTest.ACL_ID,
                ConsulKVBuilderTest.HOST, ConsulKVBuilderTest.KEY, null, null, null, RequestMode.DELETE, 30000,
                30000,
                DebugMode.ENABLED, false));
        FreeStyleBuild build = project.scheduleBuild2(0).get();

        String log = FileUtils.readFileToString(build.getLogFile());
        assertThat(log, containsString(ConsulKVBuilderTest.WRITE_TEST_VALUE));
    } catch (IOException ioe) {
        throw new BuilderException(ConsulKVBuilderTest.IO_EXCEPTION_TEXT, ioe);
    } catch (InterruptedException ie) {
        throw new BuilderException(ConsulKVBuilderTest.INTERRUPTED_EXCEPTION_TEXT, ie);
    } catch (ExecutionException ee) {
        throw new BuilderException(ConsulKVBuilderTest.EXECUTION_EXCEPTION_TEXT, ee);
    }
}
项目:display-url-api-plugin    文件:DisplayURLProviderTest.java   
@Test
public void urls() throws Exception {
    MockFolder folder = rule.createFolder("my folder");
    FreeStyleProject project = (FreeStyleProject) folder.createProject(rule.jenkins.getDescriptorByType(FreeStyleProject.DescriptorImpl.class), "my job", false);
    Run<?, ?> run = project.scheduleBuild2(0).get();

    String root = DisplayURLProvider.get().getRoot();
    assertEquals("http://localhost:" + rule.getLocalPort() + "/jenkins/", root);
    assertEquals(root + "job/my%20folder/job/my%20job/1/display/redirect", DisplayURLProvider.get().getRunURL(run));
    assertEquals(root + "job/my%20folder/job/my%20job/display/redirect", DisplayURLProvider.get().getJobURL(project));
    assertEquals(root + "job/my%20folder/job/my%20job/1/display/redirect?page=changes", DisplayURLProvider.get().getChangesURL(run));

    EnvVars environment = run.getEnvironment();
    assertEquals(DisplayURLProvider.get().getRunURL(run), environment.get("RUN_DISPLAY_URL"));
    assertEquals(DisplayURLProvider.get().getChangesURL(run), environment.get("RUN_CHANGES_DISPLAY_URL"));
    assertEquals(DisplayURLProvider.get().getJobURL(project), environment.get("JOB_DISPLAY_URL"));
}
项目:parameter-pool-plugin    文件:ParameterPoolTest.java   
@Test
public void pickFirstErrorBuildIfPreferringErrors() throws Exception {
    FreeStyleProject project = createProject(0, true);

    Shell exitShell = new Shell("exit 1");
    project.getBuildersList().add(exitShell);
    project.scheduleBuild2(0).waitForStart().run();
    project.scheduleBuild2(0).waitForStart().run();

    project.getBuildersList().remove(exitShell);

    FreeStyleBuild successfulBuildAfterFailures = project.scheduleBuild2(0).get();
    String logText = FileUtils.readFileToString(successfulBuildAfterFailures.getLogFile());
    assertEquals(logText, Result.SUCCESS, successfulBuildAfterFailures.getResult());

    FreeStyleBuild completedBuild = project.scheduleBuild2(0).get();
    logText = FileUtils.readFileToString(completedBuild.getLogFile());
    assertThatVmIsInText(completedBuild.getNumber(), 2, logText);
}
项目:ansible-plugin    文件:DslJobRule.java   
private void before(Description description) throws Exception {
    FreeStyleProject job = jRule.createFreeStyleProject();
    String script = description.getAnnotation(WithJobDsl.class).value();
    String scriptText = Resources.toString(Resources.getResource(script), Charsets.UTF_8);

    job.getBuildersList().add(
            new ExecuteDslScripts(
                    new ExecuteDslScripts.ScriptLocation(
                            null, null,
                            scriptText
                    ),
                    false,
                    RemovedJobAction.DELETE,
                    RemovedViewAction.DELETE,
                    LookupStrategy.JENKINS_ROOT
            )
    );

    jRule.buildAndAssertSuccess(job);

    assertThat(jRule.getInstance().getJobNames(), hasItem(is(JOB_NAME_IN_DSL_SCRIPT)));

    generated = jRule.getInstance().getItemByFullName(JOB_NAME_IN_DSL_SCRIPT, FreeStyleProject.class);
}
项目:aws-lambda-jenkins-plugin    文件:LambdaInvokeBuildStepTest.java   
@Ignore
@Test
public void testHtml() throws Exception {
    List<JsonParameterVariables> jsonParameterVariables = new ArrayList<JsonParameterVariables>();
    jsonParameterVariables.add(new JsonParameterVariables("KEY", "value"));
    LambdaInvokeBuildStepVariables variables = new LambdaInvokeBuildStepVariables(false, "accessKeyId", Secret.fromString("secretKey"), "eu-west-1", "function", "payload", true, jsonParameterVariables);

    FreeStyleProject p = j.createFreeStyleProject();
    LambdaInvokeBuildStep before = new LambdaInvokeBuildStep(variables);
    p.getBuildersList().add(before);

    j.submit(j.createWebClient().getPage(p, "configure").getFormByName("config"));

    LambdaInvokeBuildStep after = p.getBuildersList().get(LambdaInvokeBuildStep.class);

    assertEquals(before, after);
}
项目:github-integration-plugin    文件:GHBranchSubscriberTest.java   
@Test
public void dontFailOnBadJob() throws IOException, ANTLRException {
    String goodRepo = "https://github.com/KostyaSha-auto/test-repo";

    final FreeStyleProject job1 = jRule.createProject(FreeStyleProject.class, "bad job");
    job1.addProperty(new GithubProjectProperty("http://bad.url/deep/bad/path/"));
    job1.addTrigger(new GitHubBranchTrigger("", GitHubPRTriggerMode.HEAVY_HOOKS_CRON, emptyList()));

    Set<Job> jobs = getBranchTriggerJobs(goodRepo);
    assertThat(jobs, hasSize(0));

    final FreeStyleProject job2 = jRule.createProject(FreeStyleProject.class, "good job");
    job2.addProperty(new GithubProjectProperty(goodRepo));
    job2.addTrigger(new GitHubBranchTrigger("", GitHubPRTriggerMode.HEAVY_HOOKS_CRON, emptyList()));

    jobs = getBranchTriggerJobs("KostyaSha-auto/test-repo");
    assertThat(jobs, hasSize(1));
    assertThat(jobs, hasItems(job2));
}
项目:github-integration-plugin    文件:GHPullRequestSubscriberTest.java   
@Test
public void dontFailOnBadJob() throws IOException, ANTLRException {
    String goodRepo = "https://github.com/KostyaSha-auto/test-repo";

    final FreeStyleProject job1 = jenkins.createProject(FreeStyleProject.class, "bad job");
    job1.addProperty(new GithubProjectProperty("http://bad.url/deep/bad/path/"));
    job1.addTrigger(new GitHubPRTrigger("", GitHubPRTriggerMode.HEAVY_HOOKS_CRON, emptyList()));

    Set<Job> jobs = getPRTriggerJobs(goodRepo);
    MatcherAssert.assertThat(jobs, hasSize(0));

    final FreeStyleProject job2 = jenkins.createProject(FreeStyleProject.class, "good job");
    job2.addProperty(new GithubProjectProperty(goodRepo));
    job2.addTrigger(new GitHubPRTrigger("", GitHubPRTriggerMode.HEAVY_HOOKS_CRON, emptyList()));

    jobs = getPRTriggerJobs("KostyaSha-auto/test-repo");
    MatcherAssert.assertThat(jobs, hasSize(1));
    MatcherAssert.assertThat(jobs, hasItems(job2));
}
项目:jenkinslint-plugin    文件:HardcodedScriptCheckerTestCase.java   
@Test public void testJobWithHardcodedScript() throws Exception {
    FreeStyleProject project = j.createFreeStyleProject("Bash_Single_Line");
    project.getBuildersList().add(new hudson.tasks.Shell("#!/bin/bash #single line"));
    assertFalse(checker.executeCheck(project));
    project.delete();
    project = j.createFreeStyleProject("Bash_Multiple_Line");
    project.getBuildersList().add(new hudson.tasks.Shell("#!/bin/bash\nline1\nline2\nline3\nline4\nline5\nline6"));
    assertTrue(checker.executeCheck(project));
    project.delete();
    project = j.createFreeStyleProject("Batch_Single_Line");
    project.getBuildersList().add(new hudson.tasks.BatchFile("echo first"));
    assertFalse(checker.executeCheck(project));
    project.delete();
    project = j.createFreeStyleProject("Batch_Multiple_Line");
    project.getBuildersList().add(new hudson.tasks.BatchFile("echo first\nline1\nline2\nline3\nline4\nline5\nline6"));
    assertTrue(checker.executeCheck(project));
}
项目:aws-lambda-jenkins-plugin    文件:WorkSpaceZipperTest.java   
@Test
public void testGetZipFolderNotExists() throws Exception {

    FreeStyleProject p = j.createFreeStyleProject();

    p.scheduleBuild2(0).get();

    JenkinsLogger logger = new JenkinsLogger(System.out);
    WorkSpaceZipper workSpaceZipper = new WorkSpaceZipper(p.getSomeWorkspace(), logger);
    try {
        workSpaceZipper.getZip("echo");
        fail("Expected LambdaDeployException.");
    } catch (LambdaDeployException lde){
        assertEquals("Could not find zipfile or folder.", lde.getMessage());
    }
}
项目:sumologic-jenkins-plugin    文件:SumoBuildNotifierTest.java   
@Test
public void testSendBuildData() throws Exception {
  ArgumentCaptor<HttpRequest> captor = ArgumentCaptor.forClass(HttpRequest.class);
  FreeStyleProject project = j.createFreeStyleProject();

  project.getBuildersList().add(new Shell("Echo Hello"));
  project.getBuildersList().add(new Shell("Echo Hello2"));
  project.getBuildersList().add(new Shell("Echo Hello3"));
  project.getBuildersList().add(new Shell("Echo Hello4"));
  project.getPublishersList().add(new SumoBuildNotifier());

  FreeStyleBuild build = project.scheduleBuild2(0).get();

  Mockito.verify(handler, atLeast(1)).handle(
      captor.capture(),
      Mockito.isA(HttpResponse.class),
      Mockito.isA(HttpContext.class));

  HttpEntityEnclosingRequest request = (HttpEntityEnclosingRequest) captor.getValue();


  Assert.assertTrue("Message too short.", ModelFactory.createBuildModel(build).toJson().length() <= request.getEntity().getContentLength());
}
项目:yet-another-docker-plugin    文件:DockerSimpleBuildWrapperTest.java   
@Ignore("For local experiments")
@Test
public void testWrapper() throws Exception {
    final FreeStyleProject project = jRule.createProject(FreeStyleProject.class, "freestyle");

    final DockerConnector connector = new DockerConnector("tcp://" + ADDRESS + ":2376/");
    connector.setConnectorType(JERSEY);

    final DockerSlaveConfig config = new DockerSlaveConfig();
    config.getDockerContainerLifecycle().setImage("java:8-jdk-alpine");
    config.setLauncher(new NoOpDelegatingComputerLauncher(new DockerComputerSingleJNLPLauncher()));
    config.setRetentionStrategy(new DockerOnceRetentionStrategy(10));

    final DockerSimpleBuildWrapper dockerSimpleBuildWrapper = new DockerSimpleBuildWrapper(connector, config);
    project.getBuildWrappersList().add(dockerSimpleBuildWrapper);
    project.getBuildersList().add(new Shell("sleep 30"));

    final QueueTaskFuture<FreeStyleBuild> taskFuture = project.scheduleBuild2(0);

    jRule.waitUntilNoActivity();
    jRule.pause();
}
项目:Jenkins-Plugin-Examples    文件:HelloWorldBuilderTest.java   
@Test
public void testConfigRoundtrip() throws Exception {
    FreeStyleProject project = jenkins.createFreeStyleProject();
    project.getBuildersList().add(new HelloWorldBuilder(name));
    project = jenkins.configRoundtrip(project);
    jenkins.assertEqualDataBoundBeans(new HelloWorldBuilder(name), project.getBuildersList().get(0));
}
项目:Jenkins-Plugin-Examples    文件:HelloWorldBuilderTest.java   
@Test
public void testConfigRoundtripFrench() throws Exception {
    FreeStyleProject project = jenkins.createFreeStyleProject();
    HelloWorldBuilder builder = new HelloWorldBuilder(name);
    builder.setUseFrench(true);
    project.getBuildersList().add(builder);
    project = jenkins.configRoundtrip(project);

    HelloWorldBuilder lhs = new HelloWorldBuilder(name);
    lhs.setUseFrench(true);
    jenkins.assertEqualDataBoundBeans(lhs, project.getBuildersList().get(0));
}
项目:Jenkins-Plugin-Examples    文件:HelloWorldBuilderTest.java   
@Test
public void testBuild() throws Exception {
    FreeStyleProject project = jenkins.createFreeStyleProject();
    HelloWorldBuilder builder = new HelloWorldBuilder(name);
    project.getBuildersList().add(builder);

    FreeStyleBuild build = jenkins.buildAndAssertSuccess(project);
    jenkins.assertLogContains("Hello, " + name, build);
}
项目:Jenkins-Plugin-Examples    文件:HelloWorldBuilderTest.java   
@Test
public void testBuildFrench() throws Exception {

    FreeStyleProject project = jenkins.createFreeStyleProject();
    HelloWorldBuilder builder = new HelloWorldBuilder(name);
    builder.setUseFrench(true);
    project.getBuildersList().add(builder);

    FreeStyleBuild build = jenkins.buildAndAssertSuccess(project);
    jenkins.assertLogContains("Bonjour, " + name, build);
}
项目:aws-codecommit-trigger-plugin    文件:AbstractFreestyleIT.java   
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();
    job.getBuildersList().add(new TestBuilder() {

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

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

    fixture.setEvent(event);
}
项目:jenkins-aws-bucket-credentials    文件:AwsBucketCredentialsBindingTest.java   
/**
 * this is an integration test as the bind is a bit tricky to mock out
 * @throws Exception
 */
@Test
public void bindAddsNoNewVariablesAndValuesYet() throws Exception{
    AwsBucketCredentialsImpl credentials = mock(AwsBucketCredentialsImpl.class);
    when(credentials.getId()).thenReturn("id");
    when(credentials.getPassword()).thenReturn(Secret.fromString("password"));
    when(credentials.getUsername()).thenReturn("username");
    CredentialsProvider.lookupStores(jenkinsRule.jenkins).iterator().next().addCredentials(Domain.global(), credentials);

    FreeStyleProject p = jenkinsRule.createFreeStyleProject();
    p.getBuildWrappersList().add(new SecretBuildWrapper(Collections.<MultiBinding<?>>singletonList(new AwsBucketCredentialsBinding("userid", "pass", "id"))));
    if (Functions.isWindows()) {
        p.getBuildersList().add(new BatchFile("@echo off\necho %userid%/%pass% > auth.txt"));
    } else {
        p.getBuildersList().add(new Shell("set +x\necho $userid/$pass > auth.txt"));
    }
    jenkinsRule.configRoundtrip((Item)p);
    SecretBuildWrapper wrapper = p.getBuildWrappersList().get(SecretBuildWrapper.class);
    assertThat(wrapper).isNotNull();
    List<? extends MultiBinding<?>> bindings = wrapper.getBindings();
    assertThat(bindings).hasSize(1);
    MultiBinding<?> binding = bindings.get(0);

    assertThat(((AwsBucketCredentialsBinding) binding).getUsernameVariable()).isEqualTo("userid");
    assertThat(((AwsBucketCredentialsBinding) binding).getPasswordVariable()).isEqualTo("pass");
    FreeStyleBuild b = jenkinsRule.buildAndAssertSuccess(p);
    assertThat(b.getWorkspace().child("auth.txt").readToString().trim()).contains("username/password");

}
项目:CPWR-CodeCoverage    文件:CodeCoverageBuilderTest.java   
/**
 * Perform a round trip test on the Code Coverage configuration builder.
 * <p>
 * A project is created, configured, submitted / saved, and reloaded where the original configuration is compared against
 * the reloaded configuration for equality.
 */
@Test
public void roundTripTest()
{
    try
    {
        FreeStyleProject project = m_jenkinsRule.createFreeStyleProject("TestProject");
        CodeCoverageBuilder before = new CodeCoverageBuilder(EXPECTED_CONNECTION_ID, EXPECTED_CREDENTIALS_ID, EXPECTED_ANALYSIS_PROPERTIES_FILEPATH,
                EXPECTED_ANALYSIS_PROPERTIES_STRING);
        project.getBuildersList().add(before);

        // workaround for eclipse compiler Ambiguous method call
        project.save();
        m_jenkinsRule.jenkins.reload();

        FreeStyleProject reloaded = m_jenkinsRule.jenkins.getItemByFullName(project.getFullName(), FreeStyleProject.class);
        assertNotNull(reloaded);

        CodeCoverageBuilder after = reloaded.getBuildersList().get(CodeCoverageBuilder.class);
        assertNotNull(after);

        m_jenkinsRule.assertEqualBeans(before, after, "connectionId,credentialsId,analysisPropertiesPath,analysisProperties");
    }
    catch (Exception e)
    {
        // Add the print of the stack trace because the exception message is not enough to troubleshoot the root issue. For
        // example, if the exception is constructed without a message, you get no information from executing fail().
        e.printStackTrace();
        fail(e.getMessage());
    }
}
项目:run-selector-plugin    文件:RunSelectorParameterTest.java   
@Test
public void testConfiguration() throws Exception {
    RunSelectorParameter expected = new RunSelectorParameter("SELECTOR", new StatusRunSelector(StatusRunSelector.BuildStatus.STABLE), "foo");
    FreeStyleProject job = rule.createFreeStyleProject();
    job.addProperty(new ParametersDefinitionProperty(expected));
    job.save();

    job = rule.configRoundtrip(job);
    RunSelectorParameter actual = (RunSelectorParameter) job.getProperty(ParametersDefinitionProperty.class).getParameterDefinition("SELECTOR");
    rule.assertEqualDataBoundBeans(expected, actual);
}
项目:run-selector-plugin    文件:PermalinkRunSelectorTest.java   
private static void verifySelectedRun(RunSelector selector, Run expectedRun) throws Exception {
    FreeStyleProject selecter = j.createFreeStyleProject();

    Run run = j.assertBuildStatusSuccess(selecter.scheduleBuild2(0));
    Run selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL));
    assertThat(selectedRun, is(expectedRun));
}
项目:run-selector-plugin    文件:StatusRunSelectorTest.java   
private static void verifySelectedRun(RunSelector selector, Run expectedRun) throws Exception {
    FreeStyleProject selecter = j.createFreeStyleProject();

    Run run = j.assertBuildStatusSuccess(selecter.scheduleBuild2(0));
    Run selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL));
    assertThat(selectedRun, is(expectedRun));
}
项目:run-selector-plugin    文件:DisplayNameRunFilterTest.java   
@Test
public void testDisplayName() throws Exception {
    jobToSelect.getBuildByNumber(2).setDisplayName("RC1");

    FreeStyleProject selecter = j.createFreeStyleProject();
    RunSelector selector = new StatusRunSelector();
    RunFilter filter = new DisplayNameRunFilter("$NUM");

    Run run = j.assertBuildStatusSuccess(selecter.scheduleBuild2(
            0,
            new Cause.UserIdCause(),
            new ParametersAction(
                    new StringParameterValue("NUM", "RC1")
            )
    ));
    Run selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL, filter));
    assertThat(selectedRun.getNumber(), is(2));

    run = j.assertBuildStatusSuccess(selecter.scheduleBuild2(
            0,
            new Cause.UserIdCause(),
            new ParametersAction(
                    new StringParameterValue("NUM", "RC2")
            )
    ));
    selectedRun = selector.select(jobToSelect, new RunSelectorContext(j.jenkins, run, TaskListener.NULL, filter));
    assertThat(selectedRun, nullValue());
}
项目:compuware-scm-downloader-plugin    文件:ScmTestUtils.java   
/**
 * Perform a round trip test on the SCM configuration.
 * <p>
 * A project is created, configured, submitted / saved, and reloaded where the original configuration is compared against
 * the reloaded configuration for equality.
 * 
 * @param jenkinsRule
 *            the Jenkins rule
 * @param scmConfig
 *            the configuration to perform the round trip on
 * @properties ','-separated list of property names that are compared.
 */
public static void roundTripTest(JenkinsRule jenkinsRule, SCM scmConfig, String properties)
{
    try
    {
        FreeStyleProject project = jenkinsRule.createFreeStyleProject("TestProject");
        project.setScm(scmConfig);

        // workaround for eclipse compiler Ambiguous method call
        project.save();
        jenkinsRule.jenkins.reload();

        FreeStyleProject reloaded = jenkinsRule.jenkins.getItemByFullName(project.getFullName(), FreeStyleProject.class);
        assertNotNull(reloaded);

        SCM after = (SCM) reloaded.getScm();
        assertNotNull(after);

        jenkinsRule.assertEqualBeans(scmConfig, after, properties);
    }
    catch (Exception e)
    {
        // Add the print of the stack trace because the exception message is not enough to troubleshoot the root issue. For
        // example, if the exception is constructed without a message, you get no information from executing fail().
        e.printStackTrace();
        fail(e.getMessage());
    }
}
项目:bandit-plugin-    文件:BanditDescriptor.java   
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override
public boolean isApplicable(final Class<? extends AbstractProject> jobType) {

    return FreeStyleProject.class.isAssignableFrom(jobType);
}
项目:display-url-api-plugin    文件:AbstractActionRedirectTest.java   
@Before
public void createJobAndRun() throws Exception {
    MockFolder folder = rule.createFolder("my folder");
    FreeStyleProject job = (FreeStyleProject) folder.createProject(rule.jenkins.getDescriptorByType(FreeStyleProject.DescriptorImpl.class), "my job", false);
    this.job = job;
    this.run = job.scheduleBuild2(0).get();
    provider = DisplayURLProvider.get();
}