Enforce the use of builders in Ruby and Chef statements

This commit is contained in:
Ignasi Barrera 2013-04-03 10:27:46 +02:00
parent 1760b401b1
commit 89e04c2342
5 changed files with 19 additions and 9 deletions

View File

@ -271,7 +271,7 @@ public class ChefSolo implements Statement {
private RunList runlist;
private final InstallChefGems installChefGems;
public ChefSolo(Optional<String> fileCachePath, Optional<String> rolePath, Optional<String> databagPath,
protected ChefSolo(Optional<String> fileCachePath, Optional<String> rolePath, Optional<String> databagPath,
Optional<ImmutableList<String>> cookbookPath, Optional<String> cookbooksArchiveLocation,
Optional<String> jsonAttributes, Optional<String> group, Optional<Integer> interval,
Optional<String> logLevel, Optional<String> logFile, Optional<String> nodeName, Optional<Integer> splay,

View File

@ -58,7 +58,7 @@ public class InstallChefGems implements Statement {
private Optional<String> version;
public InstallChefGems(Optional<String> version) {
protected InstallChefGems(Optional<String> version) {
this.version = version;
}

View File

@ -30,7 +30,17 @@ import org.jclouds.scriptbuilder.domain.StatementList;
*/
public class InstallRuby extends StatementList {
public InstallRuby() {
public static Builder builder() {
return new Builder();
}
public static class Builder {
public InstallRuby build() {
return new InstallRuby();
}
}
protected InstallRuby() {
super(call("setupPublicCurl"), call("installRuby"));
}

View File

@ -99,7 +99,7 @@ public class InstallRubyGems implements Statement {
private Optional<String> updateSystemVersion;
private boolean updateExistingGems;
public InstallRubyGems(Optional<String> version, boolean updateSystem, Optional<String> updateSystemVersion,
protected InstallRubyGems(Optional<String> version, boolean updateSystem, Optional<String> updateSystemVersion,
boolean updateExistingGems) {
this.version = checkNotNull(version, "version must be set");
this.updateSystem = updateSystem;

View File

@ -38,19 +38,19 @@ import com.google.common.io.Resources;
@Test(groups = "unit", testName = "InstallRubyTest")
public class InstallRubyTest {
@Test(expectedExceptions = UnsupportedOperationException.class,
expectedExceptionsMessageRegExp = "windows not yet implemented")
@Test(expectedExceptions = UnsupportedOperationException.class, expectedExceptionsMessageRegExp = "windows not yet implemented")
public void installRubyInWindows() {
new InstallRuby().render(OsFamily.WINDOWS);
InstallRuby.builder().build().render(OsFamily.WINDOWS);
}
public void installRubyUnix() throws IOException {
assertEquals(new InstallRuby().render(OsFamily.UNIX), Resources.toString(
assertEquals(InstallRuby.builder().build().render(OsFamily.UNIX), Resources.toString(
Resources.getResource("test_install_ruby." + ShellToken.SH.to(OsFamily.UNIX)), Charsets.UTF_8));
}
public void installRubyUnixInScriptBuilderSourcesSetupPublicCurl() throws IOException {
assertEquals(InitScript.builder().name("install_ruby").run(new InstallRuby()).build().render(OsFamily.UNIX),
assertEquals(
InitScript.builder().name("install_ruby").run(InstallRuby.builder().build()).build().render(OsFamily.UNIX),
Resources.toString(
Resources.getResource("test_install_ruby_scriptbuilder." + ShellToken.SH.to(OsFamily.UNIX)),
Charsets.UTF_8));