Skip to content

Commit

Permalink
Merge pull request #66 from raul-arabaolaza/JENKINS-37801
Browse files Browse the repository at this point in the history
[JENKINS-37801] ViewCredentialsActionTest#smokes and CredentialsStoreActionTest are failing against stable-2.7
  • Loading branch information
stephenc committed Aug 30, 2016
2 parents ad9ba7f + 914b3a0 commit e0d05e2
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 7 deletions.
Expand Up @@ -15,14 +15,15 @@
import java.util.List;
import java.util.Random;
import javax.servlet.http.HttpServletResponse;
import jenkins.model.Jenkins;

import org.apache.commons.lang.StringUtils;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;
import org.xmlunit.matchers.CompareMatcher;

import static com.cloudbees.plugins.credentials.XmlMatchers.isSimilarToIgnoringPrivateAttrs;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
Expand Down Expand Up @@ -57,7 +58,7 @@ public void smokes() throws Exception {

JenkinsRule.WebClient wc = j.createWebClient();
WebResponse response = wc.goTo("credentials/store/system/api/xml?depth=5", "application/xml").getWebResponse();
assertThat(response.getContentAsString(), CompareMatcher.isIdenticalTo("<userFacingAction>"
assertThat(response.getContentAsString(), isSimilarToIgnoringPrivateAttrs("<userFacingAction>"
+ "<domains>"
+ "<_>"
+ "<description>"
Expand All @@ -83,7 +84,7 @@ public void smokes() throws Exception {
new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, credentialId,
credentialDescription, credentialUsername, "test-secret"));
response = wc.goTo("credentials/store/system/api/xml?depth=5", "application/xml").getWebResponse();
assertThat(response.getContentAsString(), CompareMatcher.isIdenticalTo("<userFacingAction>"
assertThat(response.getContentAsString(), isSimilarToIgnoringPrivateAttrs("<userFacingAction>"
+ "<domains>"
+ "<_>"
+ "<description>"
Expand Down
Expand Up @@ -9,12 +9,12 @@
import java.util.Collections;
import java.util.List;
import java.util.Random;
import jenkins.model.Jenkins;

import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import static org.hamcrest.Matchers.is;
import static com.cloudbees.plugins.credentials.XmlMatchers.isSimilarToIgnoringPrivateAttrs;
import static org.junit.Assert.assertThat;

public class ViewCredentialsActionTest {
Expand All @@ -41,7 +41,7 @@ public void smokes() throws Exception {

JenkinsRule.WebClient wc = j.createWebClient();
WebResponse response = wc.goTo("credentials/api/xml?depth=5", "application/xml").getWebResponse();
assertThat(response.getContentAsString(), is("<rootActionImpl>"
assertThat(response.getContentAsString(), isSimilarToIgnoringPrivateAttrs("<rootActionImpl>"
+ "<stores>"
+ "<system>"
+ "<domains>"
Expand Down Expand Up @@ -71,7 +71,7 @@ public void smokes() throws Exception {
new UsernamePasswordCredentialsImpl(CredentialsScope.GLOBAL, credentialId,
credentialDescription, credentialUsername, "test-secret"));
response = wc.goTo("credentials/api/xml?depth=5", "application/xml").getWebResponse();
assertThat(response.getContentAsString(), is("<rootActionImpl>"
assertThat(response.getContentAsString(), isSimilarToIgnoringPrivateAttrs("<rootActionImpl>"
+ "<stores>"
+ "<system>"
+ "<domains>"
Expand Down
22 changes: 22 additions & 0 deletions src/test/java/com/cloudbees/plugins/credentials/XmlMatchers.java
@@ -0,0 +1,22 @@
package com.cloudbees.plugins.credentials;

import org.w3c.dom.Attr;
import org.xmlunit.matchers.CompareMatcher;
import org.xmlunit.util.Predicate;

public class XmlMatchers {
public static CompareMatcher isSimilarToIgnoringPrivateAttrs(String control) {
return CompareMatcher.isSimilarTo(control)
.normalizeWhitespace()
.ignoreComments()
.withAttributeFilter(new Predicate<Attr>() {
@Override
public boolean test(Attr attr) {
if (attr.getName().startsWith("_")) {
return false;
}
return true;
}
});
}
}

0 comments on commit e0d05e2

Please sign in to comment.