Skip to content

Commit

Permalink
Reproduce JENKINS-23893
Browse files Browse the repository at this point in the history
  • Loading branch information
olivergondza committed Jul 21, 2014
1 parent 68635eb commit ed06b80
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 1 deletion.
8 changes: 7 additions & 1 deletion src/main/java/org/jenkinsci/test/acceptance/po/Job.java
Expand Up @@ -27,7 +27,7 @@
* @author Kohsuke Kawaguchi
*/
public class Job extends ContainerPageObject {
public final String name;
public String name;

public List<Parameter> getParameters() {
return parameters;
Expand All @@ -44,6 +44,12 @@ public Job(Injector injector, URL url, String name) {
this.name = name;
}

public void setName(String name) {
ensureConfigPage();
this.name = name;
control("/name").set(name);
}

/**
* "Casts" this object into a subtype by creating the specified type.
*/
Expand Down
26 changes: 26 additions & 0 deletions src/main/java/org/jenkinsci/test/acceptance/po/View.java
@@ -1,9 +1,13 @@
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;
Expand Down Expand Up @@ -54,4 +58,26 @@ public void save() {
clickButton("OK");
assertThat(driver, not(hasContent("This page expects a form submission")));
}

public static Matcher<View> containsJob(final Job needle) {
return new Matcher<View>("Contains job " + needle.name) {
@Override
public boolean matchesSafely(View view) {
for (JsonNode job: view.getJson().get("jobs")) {
String name = job.get("name").asText();
if (needle.name.equals(name)) return true;
}
return false;
}

@Override
public void describeMismatchSafely(View view, Description mismatchDescription) {
mismatchDescription.appendText("view containing:");
for (JsonNode job: view.getJson().get("jobs")) {
String name = job.get("name").asText();
mismatchDescription.appendText(" ").appendText(name);
}
}
};
}
}
53 changes: 53 additions & 0 deletions src/test/java/core/ViewTest.java
@@ -0,0 +1,53 @@
/*
* The MIT License
*
* Copyright (c) 2014 Red Hat, Inc.
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* THE SOFTWARE.
*/
package core;

import static org.jenkinsci.test.acceptance.po.View.containsJob;
import static org.hamcrest.MatcherAssert.assertThat;

import org.jenkinsci.test.acceptance.junit.AbstractJUnitTest;
import org.jenkinsci.test.acceptance.po.FreeStyleJob;
import org.jenkinsci.test.acceptance.po.ListView;
import org.junit.Test;

public class ViewTest extends AbstractJUnitTest {

@Test
public void renameJob() {
FreeStyleJob job = jenkins.jobs.create(FreeStyleJob.class, "original_name");
ListView view = jenkins.views.create(ListView.class, "a_view");
view.configure();
view.check(job.name);
view.save();

assertThat(view, containsJob(job));

job.configure();
job.setName("new_name");
job.save();
clickButton("Yes"); // confirm rename

assertThat(view, containsJob(job));
}
}

0 comments on commit ed06b80

Please sign in to comment.