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 8e20652021
commit f26a726db7
5 changed files with 19 additions and 9 deletions

View File

@ -271,7 +271,7 @@ public class ChefSolo implements Statement {
private RunList runlist; private RunList runlist;
private final InstallChefGems installChefGems; 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<ImmutableList<String>> cookbookPath, Optional<String> cookbooksArchiveLocation,
Optional<String> jsonAttributes, Optional<String> group, Optional<Integer> interval, Optional<String> jsonAttributes, Optional<String> group, Optional<Integer> interval,
Optional<String> logLevel, Optional<String> logFile, Optional<String> nodeName, Optional<Integer> splay, 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; private Optional<String> version;
public InstallChefGems(Optional<String> version) { protected InstallChefGems(Optional<String> version) {
this.version = version; this.version = version;
} }

View File

@ -30,7 +30,17 @@ import org.jclouds.scriptbuilder.domain.StatementList;
*/ */
public class InstallRuby extends 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")); super(call("setupPublicCurl"), call("installRuby"));
} }

View File

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

View File

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