Skip to content

Commit

Permalink
[JENKINS-39950] Reproduced broken links.
Browse files Browse the repository at this point in the history
  • Loading branch information
uhafner committed May 12, 2017
1 parent 9ed5a4a commit 63fa5ae
Show file tree
Hide file tree
Showing 7 changed files with 254 additions and 67 deletions.
@@ -1,19 +1,14 @@
package org.jenkinsci.test.acceptance.plugins.dashboard_view;

import com.google.inject.Injector;
import org.hamcrest.Description;
import org.jenkinsci.test.acceptance.Matcher;
import org.jenkinsci.test.acceptance.plugins.analysis_collector.AnalysisPlugin;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import org.jenkinsci.test.acceptance.po.Control;
import org.jenkinsci.test.acceptance.po.Describable;
import org.jenkinsci.test.acceptance.po.Job;
import org.jenkinsci.test.acceptance.po.View;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebElement;

import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import com.google.inject.Injector;

/**
* @author Kohsuke Kawaguchi
Expand Down Expand Up @@ -57,25 +52,4 @@ public <T extends AbstractDashboardViewPortlet> T getBottomPortlet(Class<T> port
}
throw new java.util.NoSuchElementException();
}

public static Matcher<DashboardView> hasWarningsFor(final Job job, final AnalysisPlugin plugin, final int warningsCount) {
return new Matcher<DashboardView>(" shows %s warnings for plugin %s and job %s", warningsCount, plugin.getId(), job.name) {
@Override
public boolean matchesSafely(final DashboardView view) {
view.open();
try {
WebElement warningsLink = view.find(by.css("a[href='job/" + job.name + "/" + plugin.getId() + "']"));
String linkText = warningsLink.getText();
return Integer.parseInt(linkText) == warningsCount;
} catch (NoSuchElementException | NumberFormatException e) {
return false;
}
}

@Override
public void describeMismatchSafely(final DashboardView view, final Description desc) {
desc.appendText("Portlet does not show expected warnings for plugin " + plugin.getId());
}
};
}
}
@@ -1,18 +1,35 @@
package org.jenkinsci.test.acceptance.plugins.git;

import com.jcraft.jsch.*;
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Properties;

import org.apache.commons.io.FileUtils;
import org.jenkinsci.test.acceptance.docker.fixtures.GitContainer;
import org.zeroturnaround.zip.ZipUtil;

import java.io.*;
import java.nio.file.Files;
import java.util.*;
import com.jcraft.jsch.ChannelExec;
import com.jcraft.jsch.ChannelSftp;
import com.jcraft.jsch.JSch;
import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.SftpException;

import static java.lang.ProcessBuilder.Redirect.INHERIT;
import static java.nio.file.attribute.PosixFilePermission.OWNER_EXECUTE;
import static java.nio.file.attribute.PosixFilePermission.OWNER_READ;
import static java.util.Collections.singleton;
import static java.lang.ProcessBuilder.Redirect.*;
import static java.nio.file.attribute.PosixFilePermission.*;
import static java.util.Collections.*;
import static org.jenkinsci.test.acceptance.docker.fixtures.GitContainer.*;

/**
Expand Down Expand Up @@ -107,13 +124,13 @@ public void commit(String msg) throws IOException, InterruptedException {
}

public void touch(String name) throws IOException {
FileUtils.writeStringToFile(path(name), "");
FileUtils.writeStringToFile(file(name), "");
}

/**
* Refers to a path relative to the workspace directory.
* Refers to a file relative to the workspace directory.
*/
public File path(String name) {
public File file(String name) {
return new File(dir, name);
}

Expand Down Expand Up @@ -163,10 +180,10 @@ public File createTempDir(String name) throws IOException {
* @param port SSH port of Docker container
*/
public void transferToDockerContainer(String host, int port) throws IOException, InterruptedException, JSchException, SftpException {

String zippedFilename = "repo.zip";
File zipppedRepo = new File(dir.getPath() + "/" + zippedFilename);
ZipUtil.pack(new File(dir.getPath()), zipppedRepo);
Path zipPath = Files.createTempFile("git", "zip");
File zippedRepo = zipPath.toFile();
String zippedFilename = zipPath.getFileName().toString();
ZipUtil.pack(new File(dir.getPath()), zippedRepo);

Properties props = new Properties();
props.put("StrictHostKeyChecking", "no");
Expand All @@ -181,7 +198,7 @@ public void transferToDockerContainer(String host, int port) throws IOException,
ChannelSftp channel = (ChannelSftp) session.openChannel("sftp");
channel.connect();
channel.cd("/home/git");
channel.put(new FileInputStream(zipppedRepo), zippedFilename);
channel.put(new FileInputStream(zippedRepo), zippedFilename);

ChannelExec channelExec = (ChannelExec) session.openChannel("exec");
InputStream in = channelExec.getInputStream();
Expand All @@ -198,5 +215,10 @@ public void transferToDockerContainer(String host, int port) throws IOException,
channelExec.disconnect();
channel.disconnect();
session.disconnect();
Files.delete(zipPath);
}

public Path path(Path path) {
return dir.toPath().resolve(path);
}
}
@@ -1,11 +1,12 @@
package org.jenkinsci.test.acceptance.plugins.nested_view;

import com.google.inject.Injector;
import java.net.URL;

import org.jenkinsci.test.acceptance.po.Describable;
import org.jenkinsci.test.acceptance.po.View;
import org.jenkinsci.test.acceptance.po.ViewsMixIn;
import java.net.URL;

import com.google.inject.Injector;

/**
* @author Kohsuke Kawaguchi
Expand All @@ -31,4 +32,8 @@ public void assertActiveView(String name) {
public void assertInactiveView(String name) {
find(by.xpath("//*[contains(@class, 'inactive') or not(contains(@class, 'active'))]/a[text()='%s']", name));
}

public ViewsMixIn getViews() {
return views;
}
}
@@ -0,0 +1,35 @@
package org.jenkinsci.test.acceptance.plugins.workflow_multibranch;

import org.jenkinsci.test.acceptance.po.Control;
import org.jenkinsci.test.acceptance.po.Describable;
import org.jenkinsci.test.acceptance.po.WorkflowMultiBranchJob;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.Select;

/**
* Git Branch Source for the pipeline multi-branch plugin.
*
* @author Ullrich Hafner
*/
@Describable("Git")
// TODO: Remove duplicates with GitScm
public class GitBranchSource extends BranchSource {
private final Control remote = control("remote");

public GitBranchSource(WorkflowMultiBranchJob job, String path) {
super(job, path);
}

public GitBranchSource setRemote(final String remoteUrl) {
this.remote.set(remoteUrl);

return this;
}

public GitBranchSource setCredentials(final String name) {
Select select = new Select(control(By.className("credentials-select")).resolve());
select.selectByVisibleText(name);

return this;
}
}
18 changes: 12 additions & 6 deletions src/main/java/org/jenkinsci/test/acceptance/po/View.java
@@ -1,16 +1,16 @@
package org.jenkinsci.test.acceptance.po;

import com.fasterxml.jackson.databind.JsonNode;
import com.google.inject.Injector;

import java.net.URL;

import org.hamcrest.Description;
import org.jenkinsci.test.acceptance.Matcher;

import static org.hamcrest.CoreMatchers.not;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.jenkinsci.test.acceptance.Matchers.hasContent;
import com.fasterxml.jackson.databind.JsonNode;
import com.google.inject.Injector;

import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.jenkinsci.test.acceptance.Matchers.*;

/**
* Page object for view, which is a collection of jobs rendered in the UI.
Expand All @@ -20,6 +20,8 @@
* @author Kohsuke Kawaguchi
*/
public abstract class View extends ContainerPageObject {
private final Control recurseIntoFolder = control("/recurse");

public final JobsMixIn jobs;

public View(Injector injector, URL url) {
Expand Down Expand Up @@ -85,4 +87,8 @@ public void describeMismatchSafely(View view, Description mismatchDescription) {
}
};
}

public void checkRecurseIntoFolders() {
recurseIntoFolder.check();
}
}

0 comments on commit 63fa5ae

Please sign in to comment.