You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by ad...@apache.org on 2014/11/04 00:21:23 UTC
[02/14] JCLOUDS-750 Convert GoogleComputeEngine to AutoValue +
general cleanup.
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java
index 58ed81c..f01bdab 100644
--- a/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java
+++ b/google-compute-engine/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java
@@ -19,7 +19,6 @@ package org.jclouds.googlecomputeengine.predicates;
import static org.jclouds.googlecomputeengine.compute.functions.FirewallToIpPermissionTest.fwForTest;
import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.equalsIpPermission;
import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.hasPortRange;
-import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.hasProtocol;
import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.hasSourceRange;
import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.hasSourceTag;
import static org.jclouds.googlecomputeengine.predicates.NetworkFirewallPredicates.providesIpPermission;
@@ -27,136 +26,134 @@ import static org.testng.Assert.assertFalse;
import static org.testng.Assert.assertTrue;
import java.net.URI;
-import java.util.Date;
import org.jclouds.googlecomputeengine.domain.Firewall;
import org.jclouds.net.domain.IpPermission;
import org.jclouds.net.domain.IpProtocol;
import org.testng.annotations.Test;
-import com.google.common.collect.Range;
+import com.google.common.collect.ImmutableList;
-@Test(groups = "unit")
+@Test(groups = "unit", testName = "NetworkFirewallPredicatesTest")
public class NetworkFirewallPredicatesTest {
+ protected static final String BASE_URL = "https://www.googleapis.com/compute/v1/projects";
public static Firewall getFwForTestSourceTags() {
- Firewall.Builder builder = Firewall.builder();
-
- builder.network(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test"));
- builder.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/jclouds-test"));
- builder.addSourceTag("tag-1");
- builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.TCP)
- .addPortRange(1, 10).build());
- builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.TCP)
- .addPort(33).build());
- builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.ICMP).build());
- builder.id("abcd");
- builder.creationTimestamp(new Date());
- builder.name("jclouds-test");
-
- return builder.build();
+ return Firewall.create( //
+ "abcd", // id
+ URI.create(BASE_URL + "/myproject/global/firewalls/jclouds-test"), // selfLink
+ "jclouds-test", // name
+ null, // description
+ URI.create(BASE_URL + "/myproject/global/networks/jclouds-test"), // network
+ null, // sourceRanges
+ ImmutableList.of("tag-1"), // sourceTags
+ null, // targetTags
+ ImmutableList.of( // allowed
+ Firewall.Rule.create("tcp", ImmutableList.of("1-10")), //
+ Firewall.Rule.create("tcp", ImmutableList.of("33")) //
+ ));
}
public static Firewall getFwForTestSourceTagsExact() {
- Firewall.Builder builder = Firewall.builder();
-
- builder.network(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/jclouds-test"));
- builder.selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/firewalls/jclouds-test"));
- builder.addSourceTag("tag-1");
- builder.addAllowed(Firewall.Rule.builder().IpProtocol(IpProtocol.TCP)
- .addPortRange(1, 10).build());
- builder.id("abcd");
- builder.creationTimestamp(new Date());
- builder.name("jclouds-test");
-
- return builder.build();
+ return Firewall.create( //
+ "abcd", // id
+ URI.create(BASE_URL + "/myproject/global/firewalls/jclouds-test"), // selfLink
+ "jclouds-test", // name
+ null, // description
+ URI.create(BASE_URL + "/myproject/global/networks/jclouds-test"), // network
+ null, // sourceRanges
+ ImmutableList.of("tag-1"), // sourceTags
+ null, // targetTags
+ ImmutableList.of(Firewall.Rule.create("tcp", ImmutableList.of("1-10"))) // allowed
+ );
}
@Test
- public void testHasProtocol() {
- assertTrue(hasProtocol(IpProtocol.TCP).apply(fwForTest()),
- "Firewall " + fwForTest() + " should contain a TCP rule.");
+ public void testHasPortRange() {
+ assertTrue(hasPortRange("tcp", 2, 9).apply(fwForTest()),
+ "Firewall " + fwForTest() + " should contain the port range 2-9.");
}
@Test
- public void testHasProtocolFails() {
- assertFalse(hasProtocol(IpProtocol.UDP).apply(fwForTest()),
- "Firewall " + fwForTest() + " should NOT contain a UDP rule.");
+ public void testHasPortRangeSame() {
+ assertTrue(hasPortRange("tcp", 2, 2).apply(fwForTest()),
+ "Firewall " + fwForTest() + " should contain the port range 2-2.");
}
@Test
- public void testHasPortRange() {
- assertTrue(hasPortRange(Range.closed(2, 9)).apply(fwForTest()),
- "Firewall " + fwForTest() + " should contain the port range 2-9.");
+ public void testHasPortRangeFails() {
+ assertFalse(hasPortRange("tcp", 11, 15).apply(fwForTest()),
+ "Firewall " + fwForTest() + " should NOT contain the port range 11-15.");
}
@Test
- public void testHasPortRangeFails() {
- assertFalse(hasPortRange(Range.closed(11, 15)).apply(fwForTest()),
- "Firewall " + fwForTest() + " should NOT contain the port range 11-15.");
+ public void testHasPortRangeFailsSame() {
+ assertFalse(hasPortRange("tcp", 15, 15).apply(fwForTest()),
+ "Firewall " + fwForTest() + " should NOT contain the port range 15-15.");
}
@Test
public void testHasSourceTag() {
assertTrue(hasSourceTag("tag-1").apply(getFwForTestSourceTags()),
- "Firewall " + getFwForTestSourceTags() + " should contain the source tag 'tag-1'.");
+ "Firewall " + getFwForTestSourceTags() + " should contain the source tag 'tag-1'.");
}
@Test
public void testHasSourceTagFails() {
assertFalse(hasSourceTag("tag-1").apply(fwForTest()),
- "Firewall " + fwForTest() + " should NOT contain the source tag 'tag-1'.");
+ "Firewall " + fwForTest() + " should NOT contain the source tag 'tag-1'.");
}
@Test
public void testHasSourceRange() {
assertTrue(hasSourceRange("0.0.0.0/0").apply(fwForTest()),
- "Firewall " + fwForTest() + " should contain the source range '0.0.0.0/0'.");
+ "Firewall " + fwForTest() + " should contain the source range '0.0.0.0/0'.");
}
@Test
public void testHasSourceRangeFails() {
assertFalse(hasSourceRange("0.0.0.0/0").apply(getFwForTestSourceTags()),
- "Firewall " + getFwForTestSourceTags() + " should NOT contain the source range '0.0.0.0/0'.");
+ "Firewall " + getFwForTestSourceTags() + " should NOT contain the source range '0.0.0.0/0'.");
}
@Test
public void testEqualsIpPermission() {
- IpPermission perm = IpPermission.builder().groupId("tag-1")
- .fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP).build();
+ IpPermission perm = IpPermission.builder().groupId("tag-1").fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP)
+ .build();
assertTrue(equalsIpPermission(perm).apply(getFwForTestSourceTagsExact()),
- "Firewall " + getFwForTestSourceTagsExact() + " should match IpPermission " + perm + " but does not.");
+ "Firewall " + getFwForTestSourceTagsExact() + " should match IpPermission " + perm + " but does not.");
}
@Test
public void testEqualsIpPermissionFails() {
- IpPermission perm = IpPermission.builder().groupId("tag-1")
- .fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP).build();
+ IpPermission perm = IpPermission.builder().groupId("tag-1").fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP)
+ .build();
assertFalse(equalsIpPermission(perm).apply(getFwForTestSourceTags()),
- "Firewall " + getFwForTestSourceTags() + " should not match IpPermission " + perm + " but does.");
+ "Firewall " + getFwForTestSourceTags() + " should not match IpPermission " + perm + " but does.");
}
@Test
public void testProvidesIpPermission() {
- IpPermission perm = IpPermission.builder().groupId("tag-1")
- .fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP).build();
+ IpPermission perm = IpPermission.builder().groupId("tag-1").fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP)
+ .build();
assertTrue(providesIpPermission(perm).apply(getFwForTestSourceTagsExact()),
- "Firewall " + getFwForTestSourceTagsExact() + " should provide IpPermission " + perm + " but does not.");
+ "Firewall " + getFwForTestSourceTagsExact() + " should provide IpPermission " + perm + " but does not.");
assertTrue(providesIpPermission(perm).apply(getFwForTestSourceTags()),
- "Firewall " + getFwForTestSourceTags() + " should inexactly provide IpPermission " + perm + " but does not.");
+ "Firewall " + getFwForTestSourceTags() + " should inexactly provide IpPermission " + perm
+ + " but does not.");
}
@Test
public void testProvidesIpPermissionFails() {
- IpPermission perm = IpPermission.builder().groupId("tag-1")
- .fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP).build();
+ IpPermission perm = IpPermission.builder().groupId("tag-1").fromPort(1).toPort(10).ipProtocol(IpProtocol.TCP)
+ .build();
assertFalse(providesIpPermission(perm).apply(fwForTest()),
- "Firewall " + fwForTest() + " should not provide IpPermission " + perm + " but does.");
+ "Firewall " + fwForTest() + " should not provide IpPermission " + perm + " but does.");
}
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/resources/disk_list.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/disk_list.json b/google-compute-engine/src/test/resources/disk_list.json
index bdca33d..4d864c3 100644
--- a/google-compute-engine/src/test/resources/disk_list.json
+++ b/google-compute-engine/src/test/resources/disk_list.json
@@ -11,7 +11,8 @@
"name": "testimage1",
"sizeGb": "1",
"zone": "https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a",
- "status": "READY"
+ "status": "READY",
+ "type": "https://www.googleapis.com/compute/v1/projects/studied-point-720/zones/us-central1-a/diskTypes/pd-standard"
}
]
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/resources/image_get.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/image_get.json b/google-compute-engine/src/test/resources/image_get.json
index 23cb0d2..d31e4e7 100644
--- a/google-compute-engine/src/test/resources/image_get.json
+++ b/google-compute-engine/src/test/resources/image_get.json
@@ -6,6 +6,10 @@
"name": "centos-6-2-v20120326",
"description": "DEPRECATED. CentOS 6.2 image; Created Mon, 26 Mar 2012 21:19:09 +0000",
"sourceType": "RAW",
+ "deprecated": {
+ "state": "DEPRECATED",
+ "replacement": "https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images/centos-6-v20130104"
+ },
"rawDisk": {
"source": "",
"containerType": "TAR"
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/resources/instance_get.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/instance_get.json b/google-compute-engine/src/test/resources/instance_get.json
index ca591c9..3d6ce02 100644
--- a/google-compute-engine/src/test/resources/instance_get.json
+++ b/google-compute-engine/src/test/resources/instance_get.json
@@ -55,7 +55,8 @@
},
"tags": {
"items": [
- "aTag"
+ "aTag",
+ "Group-port-42"
],
"fingerprint": "abcd"
}
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/resources/instance_insert.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/instance_insert.json b/google-compute-engine/src/test/resources/instance_insert.json
index 0ce3c53..4c59302 100644
--- a/google-compute-engine/src/test/resources/instance_insert.json
+++ b/google-compute-engine/src/test/resources/instance_insert.json
@@ -1 +1 @@
-{"name":"test-0","description":"desc","machineType":"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1","serviceAccounts":[{"email":"default","scopes":["myscope"]}],"networkInterfaces":[{"network":"https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default","accessConfigs":[{"type":"ONE_TO_ONE_NAT"}]}],"disks":[{"mode":"READ_WRITE","source":"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/test","deleteOnTerminate":true,"boot":false,"type":"PERSISTENT"}],"metadata":{"kind":"compute#metadata","items":[{"key":"aKey","value":"aValue"}]}}
\ No newline at end of file
+{"name":"test-0","description":"desc","machineType":"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1","serviceAccounts":[{"email":"default","scopes":["myscope"]}],"disks":[{"type":"PERSISTENT","mode":"READ_WRITE","source":"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/test","autoDelete":true,"boot":false}],"networkInterfaces":[{"network":"https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default","accessConfigs":[{"type":"ONE_TO_ONE_NAT"}]}],"metadata":{"kind":"compute#metadata","items":[{"key":"aKey","value":"aValue"}]}}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/resources/instance_insert_simple.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/instance_insert_simple.json b/google-compute-engine/src/test/resources/instance_insert_simple.json
index 038e7f8..990b009 100644
--- a/google-compute-engine/src/test/resources/instance_insert_simple.json
+++ b/google-compute-engine/src/test/resources/instance_insert_simple.json
@@ -1 +1 @@
-{"name":"test-1","machineType":"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1","serviceAccounts":[],"networkInterfaces":[{"network":"https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default","accessConfigs":[]}]}
\ No newline at end of file
+{"name":"test-1","machineType":"https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1","serviceAccounts":[],"disks":[],"networkInterfaces":[{"network":"https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default"}],"metadata":{}}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/jclouds-labs-google/blob/b41b0d04/google-compute-engine/src/test/resources/instance_list.json
----------------------------------------------------------------------
diff --git a/google-compute-engine/src/test/resources/instance_list.json b/google-compute-engine/src/test/resources/instance_list.json
index c8ed3be..0192eb8 100644
--- a/google-compute-engine/src/test/resources/instance_list.json
+++ b/google-compute-engine/src/test/resources/instance_list.json
@@ -60,7 +60,8 @@
},
"tags": {
"items": [
- "aTag"
+ "aTag",
+ "Group-port-42"
],
"fingerprint": "abcd"
}