Search in sources :

Example 1 with LocalController

use of org.jenkinsci.test.acceptance.controller.LocalController in project acceptance-test-harness by jenkinsci.

the class Job method copyFile.

/**
 * "Copy" any file from the System into the Workspace using a zipFIle.
 *
 * Differentiates when the file is being run on Windows or Unix based machines.
 *
 * @param file
 */
public void copyFile(File file) {
    File tmp = null;
    try {
        tmp = File.createTempFile("jenkins-acceptance-tests", "dir");
        ZipUtil.pack(file, tmp);
        byte[] archive = IOUtils.toByteArray(new FileInputStream(tmp));
        if (SystemUtils.IS_OS_WINDOWS) {
            if (!(controller instanceof LocalController)) {
                // TODO: Make it work for RemoteJenkinsController like in Unix (below)
                throw new AssumptionViolatedException("Copying files in Windows is only supported if a LocalController is in use. Test will be skipped.");
            }
            addBatchStep(xCopy(file.getAbsolutePath(), "%cd%"));
        } else {
            addShellStep(String.format("base64 --decode << ENDOFFILE > archive.zip && unzip -o archive.zip \n%s\nENDOFFILE", new String(Base64.encodeBase64Chunked(archive))));
        }
    } catch (IOException e) {
        throw new AssertionError(e);
    } finally {
        if (tmp != null) {
            tmp.delete();
        }
    }
}
Also used : LocalController(org.jenkinsci.test.acceptance.controller.LocalController) AssumptionViolatedException(org.junit.internal.AssumptionViolatedException) IOException(java.io.IOException) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 2 with LocalController

use of org.jenkinsci.test.acceptance.controller.LocalController in project acceptance-test-harness by jenkinsci.

the class WizardLogin method getPassword.

/**
 * Gets the generated password from the file on disk
 *
 * @return the read password
 * @throws IOException if there is an IO error
 */
public String getPassword(JenkinsController controller) throws IOException {
    Assume.assumeThat("Testing the setup wizard is only supported if a LocalController is in use. Test will be skipped.", controller, instanceOf(LocalController.class));
    File passwordFile = new File(((LocalController) controller).getJenkinsHome(), "secrets/initialAdminPassword");
    String pass = FileUtils.readFileToString(passwordFile).trim();
    return pass;
}
Also used : LocalController(org.jenkinsci.test.acceptance.controller.LocalController) File(java.io.File)

Example 3 with LocalController

use of org.jenkinsci.test.acceptance.controller.LocalController in project acceptance-test-harness by jenkinsci.

the class WorkflowPluginTest method grapeLibrary.

@WithPlugins({ "workflow-cps-global-lib@2.3", "workflow-basic-steps@2.1", "workflow-job@2.5" })
@Issue("JENKINS-26192")
@Test
public void grapeLibrary() throws Exception {
    assumeThat("TODO otherwise we would need to set up SSH access to push via Git, which seems an awful hassle", controller, instanceOf(LocalController.class));
    File workflowLibs = /* WorkflowLibRepository.workspace() */
    new File(((LocalController) controller).getJenkinsHome(), "workflow-libs");
    // Cf. GrapeTest.useBinary using JenkinsRule:
    FileUtils.write(new File(workflowLibs, "src/pkg/Lists.groovy"), "package pkg\n" + "@Grab('commons-primitives:commons-primitives:1.0')\n" + "import org.apache.commons.collections.primitives.ArrayIntList\n" + "static def arrayInt() {new ArrayIntList()}");
    WorkflowJob job = jenkins.jobs.create(WorkflowJob.class);
    job.script.set("echo(/got ${pkg.Lists.arrayInt()}/)");
    job.sandbox.check();
    job.save();
    assertThat(job.startBuild().shouldSucceed().getConsole(), containsString("got []"));
}
Also used : LocalController(org.jenkinsci.test.acceptance.controller.LocalController) WorkflowJob(org.jenkinsci.test.acceptance.po.WorkflowJob) File(java.io.File) Issue(org.jvnet.hudson.test.Issue) AbstractJUnitTest(org.jenkinsci.test.acceptance.junit.AbstractJUnitTest) Test(org.junit.Test) DockerTest(org.jenkinsci.test.acceptance.junit.DockerTest) WithPlugins(org.jenkinsci.test.acceptance.junit.WithPlugins)

Aggregations

File (java.io.File)3 LocalController (org.jenkinsci.test.acceptance.controller.LocalController)3 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 AbstractJUnitTest (org.jenkinsci.test.acceptance.junit.AbstractJUnitTest)1 DockerTest (org.jenkinsci.test.acceptance.junit.DockerTest)1 WithPlugins (org.jenkinsci.test.acceptance.junit.WithPlugins)1 WorkflowJob (org.jenkinsci.test.acceptance.po.WorkflowJob)1 Test (org.junit.Test)1 AssumptionViolatedException (org.junit.internal.AssumptionViolatedException)1 Issue (org.jvnet.hudson.test.Issue)1