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