mirror of https://github.com/apache/jclouds.git
Updated ForwardingRuleCreationOptions to AutoValue + Builder
This commit is contained in:
parent
a26a721575
commit
ec52bdbfb9
|
@ -45,8 +45,8 @@ public class ForwardingRuleCreationBinder extends BindToJsonPayload {
|
|||
|
||||
/**
|
||||
* Values used to bind ForwardingRuleOptions to json request.
|
||||
* Note: Two break convention of starting with lower case letters due to
|
||||
* attributes on GCE starting with upper case letters.
|
||||
* Note: Two break convention of starting with lower case letters due to
|
||||
* attributes on GCE starting with upper case letters.
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
|
@ -63,11 +63,11 @@ public class ForwardingRuleCreationBinder extends BindToJsonPayload {
|
|||
|
||||
private ForwardingRuleCreationBinderHelper(String name, ForwardingRuleCreationOptions forwardingRuleCreationOptions){
|
||||
this.name = name;
|
||||
this.description = forwardingRuleCreationOptions.getDescription();
|
||||
this.IPAddress = forwardingRuleCreationOptions.getIPAddress();
|
||||
this.IPProtocol = forwardingRuleCreationOptions.getIPProtocol();
|
||||
this.portRange = forwardingRuleCreationOptions.getPortRange();
|
||||
this.target = forwardingRuleCreationOptions.getTarget();
|
||||
this.description = forwardingRuleCreationOptions.description();
|
||||
this.IPAddress = forwardingRuleCreationOptions.ipAddress();
|
||||
this.IPProtocol = forwardingRuleCreationOptions.ipProtocol();
|
||||
this.portRange = forwardingRuleCreationOptions.portRange();
|
||||
this.target = forwardingRuleCreationOptions.target();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,98 +19,91 @@ package org.jclouds.googlecomputeengine.options;
|
|||
import java.net.URI;
|
||||
|
||||
import org.jclouds.googlecomputeengine.domain.ForwardingRule;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.json.SerializedNames;
|
||||
|
||||
import com.google.auto.value.AutoValue;
|
||||
|
||||
/**
|
||||
* Options for creating a Forwarding Rule
|
||||
*/
|
||||
public class ForwardingRuleCreationOptions{
|
||||
@AutoValue
|
||||
public abstract class ForwardingRuleCreationOptions{
|
||||
|
||||
private String description;
|
||||
private String ipAddress;
|
||||
private ForwardingRule.IPProtocol ipProtocol;
|
||||
private String portRange;
|
||||
private URI target;
|
||||
|
||||
/**
|
||||
* An optional textual description of the TargetPool.
|
||||
* @return description, provided by the client.
|
||||
*/
|
||||
public String getDescription(){
|
||||
return description;
|
||||
@Nullable public abstract String description();
|
||||
@Nullable public abstract String ipAddress();
|
||||
@Nullable public abstract ForwardingRule.IPProtocol ipProtocol();
|
||||
@Nullable public abstract String portRange();
|
||||
@Nullable public abstract URI target();
|
||||
|
||||
|
||||
@SerializedNames({"description", "ipAddress", "ipProtocol", "portRange", "target"})
|
||||
static ForwardingRuleCreationOptions create(
|
||||
String description, String ipAddress, ForwardingRule.IPProtocol ipProtocol,
|
||||
String portRange, URI target){
|
||||
return new AutoValue_ForwardingRuleCreationOptions(description, ipAddress, ipProtocol, portRange, target);
|
||||
}
|
||||
|
||||
/**
|
||||
* The external IP address that this forwarding rule is serving on behalf of
|
||||
* @return ipAddress
|
||||
*/
|
||||
public String getIPAddress(){
|
||||
return ipAddress;
|
||||
ForwardingRuleCreationOptions(){
|
||||
}
|
||||
|
||||
/**
|
||||
* The IP protocol to which this rule applies
|
||||
* @return ipProtocol
|
||||
*/
|
||||
public ForwardingRule.IPProtocol getIPProtocol(){
|
||||
return ipProtocol;
|
||||
}
|
||||
public static class Builder {
|
||||
|
||||
/**
|
||||
* If IPProtocol is TCP or UDP, packets addressed to ports in the specified range
|
||||
* will be forwarded to backend. By default, this is empty and all ports are allowed.
|
||||
* @return portRange
|
||||
*/
|
||||
public String getPortRange(){
|
||||
return portRange;
|
||||
}
|
||||
private String description;
|
||||
private String ipAddress;
|
||||
private ForwardingRule.IPProtocol ipProtocol;
|
||||
private String portRange;
|
||||
private URI target;
|
||||
|
||||
/**
|
||||
* The URL of the target resource to receive the matched traffic.
|
||||
* The target resource must live in the same region as this forwarding rule.
|
||||
* @return target
|
||||
*/
|
||||
public URI getTarget(){
|
||||
return target;
|
||||
}
|
||||
/**
|
||||
* An optional textual description of the TargetPool.
|
||||
* @return description, provided by the client.
|
||||
*/
|
||||
public Builder description(String description){
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ForwardingRuleCreationOptions#getDescription()
|
||||
*/
|
||||
public ForwardingRuleCreationOptions description(String description){
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* The external IP address that this forwarding rule is serving on behalf of
|
||||
* @return ipAddress
|
||||
*/
|
||||
public Builder ipAddress(String ipAddress){
|
||||
this.ipAddress = ipAddress;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ForwardingRuleCreationOptions#getIPAddress()
|
||||
*/
|
||||
public ForwardingRuleCreationOptions ipAddress(String ipAddress){
|
||||
this.ipAddress = ipAddress;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* The IP protocol to which this rule applies
|
||||
* @return ipProtocol
|
||||
*/
|
||||
public Builder ipProtocol(ForwardingRule.IPProtocol ipProtocol){
|
||||
this.ipProtocol = ipProtocol;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ForwardingRuleCreationOptions#getIPProtocol()
|
||||
*/
|
||||
public ForwardingRuleCreationOptions ipProtocol(ForwardingRule.IPProtocol ipProtocol){
|
||||
this.ipProtocol = ipProtocol;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* If IPProtocol is TCP or UDP, packets addressed to ports in the specified range
|
||||
* will be forwarded to backend. By default, this is empty and all ports are allowed.
|
||||
* @return portRange
|
||||
*/
|
||||
public Builder portRange(String portRange){
|
||||
this.portRange = portRange;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ForwardingRuleCreationOptions#getPortRange()
|
||||
*/
|
||||
public ForwardingRuleCreationOptions portRange(String portRange){
|
||||
this.portRange = portRange;
|
||||
return this;
|
||||
}
|
||||
/**
|
||||
* The URL of the target resource to receive the matched traffic.
|
||||
* The target resource must live in the same region as this forwarding rule.
|
||||
* @return target
|
||||
*/
|
||||
public Builder target(URI target){
|
||||
this.target = target;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see ForwardingRuleCreationOptions#getTarget()
|
||||
*/
|
||||
public ForwardingRuleCreationOptions target(URI target){
|
||||
this.target = target;
|
||||
return this;
|
||||
public ForwardingRuleCreationOptions build() {
|
||||
return create(description, ipAddress, ipProtocol, portRange, target);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -45,12 +45,13 @@ public class ForwardingRuleCreationBinderTest extends BaseGoogleComputeEngineExp
|
|||
@Test
|
||||
public void testMap() throws SecurityException, NoSuchMethodException {
|
||||
ForwardingRuleCreationBinder binder = new ForwardingRuleCreationBinder(json);
|
||||
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
|
||||
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions.Builder()
|
||||
.description(DESCRIPTION)
|
||||
.ipAddress(IP_ADDRESS)
|
||||
.ipProtocol(ForwardingRule.IPProtocol.SCTP)
|
||||
.portRange(PORT_RANGE)
|
||||
.target(TARGET);
|
||||
.target(TARGET)
|
||||
.build();
|
||||
|
||||
HttpRequest request = HttpRequest.builder().method("GET").endpoint("http://momma").build();
|
||||
Map<String, Object> postParams = ImmutableMap.of("name", "testForwardingRuleName", "options", forwardingRuleCreationOptions);
|
||||
|
|
|
@ -82,11 +82,12 @@ public class ForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiLiveTes
|
|||
|
||||
@Test(groups = "live")
|
||||
public void testInsertForwardingRule() {
|
||||
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
|
||||
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions.Builder()
|
||||
.description(DESCRIPTION)
|
||||
.ipAddress(address.address())
|
||||
.ipProtocol(ForwardingRule.IPProtocol.TCP)
|
||||
.target(targetPool.selfLink());
|
||||
.target(targetPool.selfLink())
|
||||
.build();
|
||||
assertOperationDoneSuccessfully(api().create(FORWARDING_RULE_NAME, forwardingRuleCreationOptions));
|
||||
}
|
||||
|
||||
|
|
|
@ -50,8 +50,8 @@ public class ForwardingRuleApiMockTest extends BaseGoogleComputeEngineApiMockTes
|
|||
public void insert() throws Exception {
|
||||
server.enqueue(jsonResponse("/region_operation.json"));
|
||||
|
||||
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
|
||||
.target(URI.create(url("/projects/party/regions/europe-west1/targetPools/test-target-pool")));
|
||||
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions.Builder()
|
||||
.target(URI.create(url("/projects/party/regions/europe-west1/targetPools/test-target-pool"))).build();
|
||||
assertEquals(forwardingRuleApi().create("test-forwarding-rule", forwardingRuleCreationOptions),
|
||||
new ParseRegionOperationTest().expected(url("/projects")));
|
||||
|
||||
|
|
|
@ -75,18 +75,19 @@ public class GlobalForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiL
|
|||
getUrlMapUrl(GLOBAL_FORWARDING_RULE_URL_MAP_NAME)));
|
||||
assertOperationDoneSuccessfully(
|
||||
api().create(GLOBAL_FORWARDING_RULE_NAME,
|
||||
new ForwardingRuleCreationOptions().target(getTargetHttpProxyUrl(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME))
|
||||
.portRange(PORT_RANGE)));
|
||||
new ForwardingRuleCreationOptions.Builder().target(getTargetHttpProxyUrl(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME))
|
||||
.portRange(PORT_RANGE).build()));
|
||||
}
|
||||
|
||||
@Test(groups = "live", dependsOnMethods = "testInsertGlobalForwardingRule")
|
||||
public void testGetGlobalForwardingRule() {
|
||||
ForwardingRule forwardingRule = api().get(GLOBAL_FORWARDING_RULE_NAME);
|
||||
assertNotNull(forwardingRule);
|
||||
ForwardingRuleCreationOptions expected = new ForwardingRuleCreationOptions()
|
||||
ForwardingRuleCreationOptions expected = new ForwardingRuleCreationOptions.Builder()
|
||||
.target(getTargetHttpProxyUrl(GLOBAL_FORWARDING_RULE_TARGET_HTTP_PROXY_NAME))
|
||||
.portRange("80-80")
|
||||
.ipProtocol(IPProtocol.TCP);
|
||||
.ipProtocol(IPProtocol.TCP)
|
||||
.build();
|
||||
assertGlobalForwardingRuleEquals(forwardingRule, expected);
|
||||
}
|
||||
|
||||
|
@ -127,10 +128,10 @@ public class GlobalForwardingRuleApiLiveTest extends BaseGoogleComputeEngineApiL
|
|||
}
|
||||
|
||||
private void assertGlobalForwardingRuleEquals(ForwardingRule result, ForwardingRuleCreationOptions expected) {
|
||||
assertEquals(result.target(), expected.getTarget());
|
||||
assertEquals(result.ipProtocol(), expected.getIPProtocol());
|
||||
assertEquals(result.description(), expected.getDescription());
|
||||
assertEquals(result.portRange(), expected.getPortRange());
|
||||
assertEquals(result.target(), expected.target());
|
||||
assertEquals(result.ipProtocol(), expected.ipProtocol());
|
||||
assertEquals(result.description(), expected.description());
|
||||
assertEquals(result.portRange(), expected.portRange());
|
||||
assertTrue(result.ipAddress() != null);
|
||||
}
|
||||
|
||||
|
|
|
@ -50,8 +50,8 @@ public class GlobalForwardingRuleApiMockTest extends BaseGoogleComputeEngineApiM
|
|||
public void insert() throws Exception {
|
||||
server.enqueue(jsonResponse("/region_operation.json"));
|
||||
|
||||
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions()
|
||||
.target(URI.create(url("/projects/party/regions/europe-west1/targetPools/test-target-pool")));
|
||||
ForwardingRuleCreationOptions forwardingRuleCreationOptions = new ForwardingRuleCreationOptions.Builder()
|
||||
.target(URI.create(url("/projects/party/regions/europe-west1/targetPools/test-target-pool"))).build();
|
||||
|
||||
assertEquals(globalForwardingRuleApi().create("test-forwarding-rule", forwardingRuleCreationOptions),
|
||||
new ParseRegionOperationTest().expected(url("/projects")));
|
||||
|
|
|
@ -115,10 +115,11 @@ public class TargetPoolApiLiveTest extends BaseGoogleComputeEngineApiLiveTest {
|
|||
TargetPool targetPool = api().get(TARGETPOOL_NAME);
|
||||
URI target = targetPool.selfLink();
|
||||
|
||||
ForwardingRuleCreationOptions forwardingRuleOptions = new ForwardingRuleCreationOptions()
|
||||
ForwardingRuleCreationOptions forwardingRuleOptions = new ForwardingRuleCreationOptions.Builder()
|
||||
.ipProtocol(IPProtocol.TCP)
|
||||
.portRange("80-80")
|
||||
.target(target);
|
||||
.target(target)
|
||||
.build();
|
||||
|
||||
assertOperationDoneSuccessfully(api.forwardingRulesInRegion(DEFAULT_REGION_NAME)
|
||||
.create(FORWARDING_RULE_NAME, forwardingRuleOptions));
|
||||
|
|
Loading…
Reference in New Issue