Navigation Menu

Skip to content

Commit

Permalink
[JENKINS-28440] Uses CLICommandInvoker in tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ikedam committed Aug 30, 2015
1 parent d6f9c5c commit 0d54d89
Showing 1 changed file with 25 additions and 37 deletions.
62 changes: 25 additions & 37 deletions test/src/test/java/hudson/util/RobustReflectionConverterTest.java
Expand Up @@ -24,7 +24,7 @@

package hudson.util;

import hudson.cli.CLI;
import hudson.cli.CLICommandInvoker;
import hudson.diagnosis.OldDataMonitor;
import hudson.model.AbstractDescribableImpl;
import hudson.model.Items;
Expand All @@ -37,8 +37,6 @@
import hudson.security.ACL;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.util.Arrays;
import java.util.Collections;
import java.util.Map;

Expand Down Expand Up @@ -272,23 +270,19 @@ public void testCliFailure() throws Exception {

// Configure a bad keyword via CLI.
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
CLI cli = new CLI(r.getURL());
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
int ret = cli.execute(
Arrays.asList(
"update-job",
p.getFullName(),
"--username",
"test",
"--password",
"test"
),
new ByteArrayInputStream(String.format(CONFIGURATION_TEMPLATE, "badvalue", AcceptOnlySpecificKeyword.ACCEPT_KEYWORD).getBytes()),
stdout,
stderr
);
assertEquals(0, ret);

CLICommandInvoker.Result ret = new CLICommandInvoker(r, "update-job")
.withStdin(new ByteArrayInputStream(String.format(CONFIGURATION_TEMPLATE, "badvalue", AcceptOnlySpecificKeyword.ACCEPT_KEYWORD).getBytes()))
.withArgs(
p.getFullName(),
"--username",
"test",
"--password",
"test"
)
.invoke();

assertEquals(0, ret.returnCode());

// AcceptOnlySpecificKeyword with bad value is not instantiated for rejected with readResolve,
assertNull(p.getProperty(KeywordProperty.class).getNonCriticalField());
Expand All @@ -312,23 +306,17 @@ public void testCliFailure() throws Exception {

// Configure a bad keyword via CLI.
r.jenkins.setSecurityRealm(r.createDummySecurityRealm());
CLI cli = new CLI(r.getURL());
ByteArrayOutputStream stdout = new ByteArrayOutputStream();
ByteArrayOutputStream stderr = new ByteArrayOutputStream();
int ret = cli.execute(
Arrays.asList(
"update-job",
p.getFullName(),
"--username",
"test",
"--password",
"test"
),
new ByteArrayInputStream(String.format(CONFIGURATION_TEMPLATE, AcceptOnlySpecificKeyword.ACCEPT_KEYWORD, "badvalue").getBytes()),
stdout,
stderr
);
assertNotEquals(0, ret);
CLICommandInvoker.Result ret = new CLICommandInvoker(r, "update-job")
.withStdin(new ByteArrayInputStream(String.format(CONFIGURATION_TEMPLATE, AcceptOnlySpecificKeyword.ACCEPT_KEYWORD, "badvalue").getBytes()))
.withArgs(
p.getFullName(),
"--username",
"test",
"--password",
"test"
)
.invoke();
assertNotEquals(0, ret.returnCode());

// Configuration should not be updated for a failure of the critical field,
assertNotEquals("badvalue", p.getProperty(KeywordProperty.class).getCriticalField().getKeyword());
Expand Down

0 comments on commit 0d54d89

Please sign in to comment.