http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseImageTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseImageTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseImageTest.java new file mode 100644 index 0000000..99cfd6f --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseImageTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.Image; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class ParseImageTest extends BaseGoogleComputeEngineParseTest<Image> { + + @Override + public String resource() { + return "/image_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Image expected() { + return Image.builder() + .id("12941197498378735318") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-07-16T22:16:13.468")) + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/centos-cloud/global/images/centos-6-2" + + "-v20120326")) + .name("centos-6-2-v20120326") + .description("DEPRECATED. CentOS 6.2 image; Created Mon, 26 Mar 2012 21:19:09 +0000") + .sourceType("RAW") + .rawDisk( + Image.RawDisk.builder() + .source("") + .containerType("TAR") + .build() + ).build(); + } +}
http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceListTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceListTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceListTest.java new file mode 100644 index 0000000..ad6041b --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceListTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.domain.Instance; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.domain.Resource; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; + +import com.google.common.collect.ImmutableSet; + +public class ParseInstanceListTest extends BaseGoogleComputeEngineParseTest<ListPage<Instance>> { + + @Override + public String resource() { + return "/instance_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage<Instance> expected() { + return ListPage.<Instance>builder() + .kind(Resource.Kind.INSTANCE_LIST) + .id("projects/myproject/zones/us-central1-a/instances") + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/instances")) + .items(ImmutableSet.of(new ParseInstanceTest().expected())) + .build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceSerialOutputTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceSerialOutputTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceSerialOutputTest.java new file mode 100644 index 0000000..f44baa1 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceSerialOutputTest.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.domain.Instance; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; + +public class ParseInstanceSerialOutputTest extends BaseGoogleComputeEngineParseTest<Instance.SerialPortOutput> { + + @Override + public String resource() { + return "/instance_serial_port.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Instance.SerialPortOutput expected() { + return Instance.SerialPortOutput.builder() + .contents("console output").build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceTest.java new file mode 100644 index 0000000..5abdf6a --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseInstanceTest.java @@ -0,0 +1,81 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.Instance; +import org.jclouds.googlecomputeengine.domain.Metadata; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; + +import com.google.common.collect.ImmutableMap; + +public class ParseInstanceTest extends BaseGoogleComputeEngineParseTest<Instance> { + + @Override + public String resource() { + return "/instance_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Instance expected() { + return Instance.builder() + .id("13051190678907570425") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-11-25T23:48:20.758")) + .selfLink(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/zones/us-central1-a/instances/test-0")) + .description("desc") + .name("test-0") + .machineType(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1" + + "-standard-1")) + .status(Instance.Status.RUNNING) + .zone(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a")) + .addNetworkInterface( + Instance.NetworkInterface.builder() + .name("nic0") + .networkIP("10.240.121.115") + .network(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/global/networks/default")) + .build() + ) + .addDisk( + Instance.PersistentAttachedDisk.builder() + .index(0) + .mode(Instance.PersistentAttachedDisk.Mode.READ_WRITE) + .deviceName("test") + .source(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/zones/us-central1-a/disks/test")) + .boot(true) + .build() + ) + .tags(Instance.Tags.builder().fingerprint("abcd").addItem("aTag").build()) + .metadata(Metadata.builder() + .items(ImmutableMap.of("aKey", "aValue", + "jclouds-image", + "https://www.googleapis.com/compute/v1/projects/debian-cloud/global/images/debian-7-wheezy-v20140718", + "jclouds-delete-boot-disk", "true")) + .fingerprint("efgh") + .build()) + .addServiceAccount(Instance.ServiceAccount.builder().email("default").addScopes("myscope").build()) + .build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeListTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeListTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeListTest.java new file mode 100644 index 0000000..f8146d2 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeListTest.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import static org.jclouds.googlecomputeengine.domain.Resource.Kind.MACHINE_TYPE_LIST; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.domain.MachineType; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; + +public class ParseMachineTypeListTest extends BaseGoogleComputeEngineParseTest<ListPage<MachineType>> { + + + @Override + public String resource() { + return "/machinetype_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage<MachineType> expected() { + SimpleDateFormatDateService dateService = new SimpleDateFormatDateService(); + return ListPage.<MachineType>builder() + .kind(MACHINE_TYPE_LIST) + .id("projects/myproject/machineTypes") + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes")) + .addItem(MachineType.builder() + .id("4618642685664990776") + .creationTimestamp(dateService.iso8601DateParse("2013-04-25T13:32:49.088-07:00")) + .selfLink(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/f1-micro")) + .zone("us-central1-a") + .name("f1-micro") + .description("1 vCPU (shared physical core) and 0.6 GB RAM") + .guestCpus(1) + .memoryMb(614) + .maximumPersistentDisks(4) + .maximumPersistentDisksSizeGb(3072) + .build()) + .addItem(MachineType.builder() + .id("12907738072351752276") + .creationTimestamp(dateService.iso8601DateParse("2012-06-07T20:48:14.670")) + .selfLink(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-1")) + .zone("us-central1-a") + .name("n1-standard-1") + .description("1 vCPU, 3.75 GB RAM, and a 10 GB ephemeral root disk") + .guestCpus(1) + .memoryMb(3840) + .maximumPersistentDisks(16) + .maximumPersistentDisksSizeGb(128) + .build()) + .addItem(MachineType.builder() + .id("12908560709887590691") + .creationTimestamp(dateService.iso8601DateParse("2012-06-07T20:51:19.936")) + .selfLink(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1-standard-8-d")) + .zone("us-central1-a") + .name("n1-standard-8-d") + .description("8 vCPUs, 30 GB RAM, a 10 GB ephemeral root disk, " + + "and 2 extra 1770 GB ephemeral disks") + .guestCpus(8) + .memoryMb(30720) + .addScratchDisk(1770) + .addScratchDisk(1770) + .maximumPersistentDisks(16) + .maximumPersistentDisksSizeGb(1024) + .build()) + .build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeTest.java new file mode 100644 index 0000000..c1f1fad --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMachineTypeTest.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.MachineType; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; + +public class ParseMachineTypeTest extends BaseGoogleComputeEngineParseTest<MachineType> { + + + @Override + public String resource() { + return "/machinetype.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public MachineType expected() { + SimpleDateFormatDateService dateService = new SimpleDateFormatDateService(); + return MachineType.builder() + .id("12907738072351752276") + .creationTimestamp(dateService.iso8601DateParse("2012-06-07T20:48:14.670")) + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/machineTypes/n1" + + "-standard-1")) + .zone("us-central1-a") + .name("n1-standard-1") + .description("1 vCPU, 3.75 GB RAM, and a 10 GB ephemeral root disk") + .guestCpus(1) + .memoryMb(3840) + .addScratchDisk(1770) + .addScratchDisk(1770) + .maximumPersistentDisks(16) + .maximumPersistentDisksSizeGb(128) + .build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMetadataTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMetadataTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMetadataTest.java new file mode 100644 index 0000000..877bc31 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseMetadataTest.java @@ -0,0 +1,45 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.domain.Metadata; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; + +@Test(groups = "unit") +public class ParseMetadataTest extends BaseGoogleComputeEngineParseTest<Metadata> { + + @Override + public String resource() { + return "/metadata.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Metadata expected() { + return new Metadata("efgh", + ImmutableMap.<String, String>builder() + .put("propA", "valueA") + .put("propB", "valueB") + .build()); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkListTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkListTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkListTest.java new file mode 100644 index 0000000..61d56ba --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkListTest.java @@ -0,0 +1,49 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.domain.Network; +import org.jclouds.googlecomputeengine.domain.Resource; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; + +import com.google.common.collect.ImmutableSet; + +public class ParseNetworkListTest extends BaseGoogleComputeEngineParseTest<ListPage<Network>> { + + @Override + public String resource() { + return "/network_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage<Network> expected() { + return ListPage.<Network>builder() + .kind(Resource.Kind.NETWORK_LIST) + .id("projects/myproject/networks") + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/networks")) + .items(ImmutableSet.of(new ParseNetworkTest().expected())) + .build(); + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkTest.java new file mode 100644 index 0000000..cd0fdcf --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseNetworkTest.java @@ -0,0 +1,48 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.Network; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; + +public class ParseNetworkTest extends BaseGoogleComputeEngineParseTest<Network> { + + @Override + public String resource() { + return "/network_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Network expected() { + return Network.builder() + .id("13024414170909937976") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-10-24T20:13:19.967")) + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/networks/jclouds-test")) + .name("default") + .description("Default network for the project") + .IPv4Range("10.0.0.0/8") + .gatewayIPv4("10.0.0.1") + .build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationListTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationListTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationListTest.java new file mode 100644 index 0000000..ec407a3 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationListTest.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.domain.Operation; +import org.jclouds.googlecomputeengine.domain.Resource; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; + +public class ParseOperationListTest extends BaseGoogleComputeEngineParseTest<ListPage<Operation>> { + + @Override + public String resource() { + return "/global_operation_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage<Operation> expected() { + return ListPage.<Operation>builder() + .kind(Resource.Kind.OPERATION_LIST) + .id("projects/myproject/global/operations") + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/operations")) + .addItem(new ParseOperationTest().expected()) + .build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationTest.java new file mode 100644 index 0000000..cb561bf --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseOperationTest.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.Operation; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class ParseOperationTest extends BaseGoogleComputeEngineParseTest<Operation> { + + @Override + public String resource() { + return "/global_operation.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Operation expected() { + SimpleDateFormatDateService dateService = new SimpleDateFormatDateService(); + return Operation.builder().id("13053095055850848306") + .selfLink(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/global/operations/operation-1354084865060-4cf88735faeb8" + + "-bbbb12cb")) + .name("operation-1354084865060-4cf88735faeb8-bbbb12cb") + .targetLink(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/global/firewalls/jclouds-test-delete")) + .targetId("13053094017547040099") + .status(Operation.Status.DONE) + .user("[email protected]") + .progress(100) + .insertTime(dateService.iso8601DateParse("2012-11-28T06:41:05.060")) + .startTime(dateService.iso8601DateParse("2012-11-28T06:41:05.142")) + .endTime(dateService.iso8601DateParse("2012-11-28T06:41:06.142")) + .operationType("insert") + .build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseProjectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseProjectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseProjectTest.java new file mode 100644 index 0000000..3e549df --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseProjectTest.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; +import java.util.Date; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.domain.Metadata; +import org.jclouds.googlecomputeengine.domain.Project; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableMap; + +@Test(groups = "unit") +public class ParseProjectTest extends BaseGoogleComputeEngineParseTest<Project> { + + @Override + public String resource() { + return "/project.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Project expected() { + return Project.builder() + .id("13024414184846275913") + .creationTimestamp(new Date(Long.parseLong("1351109596252"))) + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject")) + .name("myproject") + .description("") + .commonInstanceMetadata(Metadata.builder() + .items(ImmutableMap.<String, String>builder() + .put("propA", "valueA") + .put("propB", "valueB") + .build()) + .fingerprint("efgh") + .build()) + .addQuota("INSTANCES", 0, 8) + .addQuota("CPUS", 0, 8) + .addQuota("EPHEMERAL_ADDRESSES", 0, 8) + .addQuota("DISKS", 0, 8) + .addQuota("DISKS_TOTAL_GB", 0, 100) + .addQuota("SNAPSHOTS", 0, 1000) + .addQuota("NETWORKS", 1, 5) + .addQuota("FIREWALLS", 2, 100) + .addQuota("IMAGES", 0, 100) + .build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseQuotaTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseQuotaTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseQuotaTest.java new file mode 100644 index 0000000..894dd0e --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseQuotaTest.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.googlecomputeengine.domain.Quota; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class ParseQuotaTest extends BaseGoogleComputeEngineParseTest<Quota> { + + @Override + public String resource() { + return "/quota.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Quota expected() { + return Quota.builder().metric("INSTANCES").usage(0.0).limit(8.0).build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionListTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionListTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionListTest.java new file mode 100644 index 0000000..8dfdea1 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionListTest.java @@ -0,0 +1,72 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.domain.Region; +import org.jclouds.googlecomputeengine.domain.Resource; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseRegionListTest extends BaseGoogleComputeEngineParseTest<ListPage<Region>> { + + @Override + public String resource() { + return "/region_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage<Region> expected() { + return ListPage.<Region>builder() + .kind(Resource.Kind.REGION_LIST) + .id("projects/myproject/regions") + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions")) + .items(ImmutableSet.of( + new ParseRegionTest().expected(), + Region.builder() + .id("6396763663251190992") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse + ("2013-07-08T14:40:37.939-07:00")) + .selfLink(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/regions/us-central2")) + .name("us-central2") + .description("us-central2") + .status(Region.Status.UP) + .zone(URI.create("https://www.googleapis.com/compute/v1/zones/us-central2-a")) + .addQuota("INSTANCES", 0, 8) + .addQuota("CPUS", 0, 8) + .addQuota("EPHEMERAL_ADDRESSES", 0, 8) + .addQuota("DISKS", 0, 8) + .addQuota("DISKS_TOTAL_GB", 0, 100) + .addQuota("SNAPSHOTS", 0, 1000) + .addQuota("NETWORKS", 1, 5) + .addQuota("FIREWALLS", 2, 100) + .addQuota("IMAGES", 0, 100) + .build())) + .build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionTest.java new file mode 100644 index 0000000..fab9915 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRegionTest.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.Region; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseRegionTest extends BaseGoogleComputeEngineParseTest<Region> { + + @Override + public String resource() { + return "/region_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Region expected() { + return Region.builder() + .id("12912210600542709766") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-08T14:40:37.939-07:00")) + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/regions/us-central1")) + .name("us-central1") + .description("us-central1") + .status(Region.Status.UP) + .zones(ImmutableSet.of(URI.create("https://www.googleapis.com/compute/v1/zones/us-central1-a"), + URI.create("https://www.googleapis.com/compute/v1/zones/us-central1-b"))) + .addQuota("INSTANCES", 0, 8) + .addQuota("CPUS", 0, 8) + .addQuota("EPHEMERAL_ADDRESSES", 0, 8) + .addQuota("DISKS", 0, 8) + .addQuota("DISKS_TOTAL_GB", 0, 100) + .addQuota("SNAPSHOTS", 0, 1000) + .addQuota("NETWORKS", 1, 5) + .addQuota("FIREWALLS", 2, 100) + .addQuota("IMAGES", 0, 100) + .build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteListTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteListTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteListTest.java new file mode 100644 index 0000000..3a378aa --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteListTest.java @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.domain.Resource.Kind; +import org.jclouds.googlecomputeengine.domain.Route; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseRouteListTest extends BaseGoogleComputeEngineParseTest<ListPage<Route>> { + + @Override + public String resource() { + return "/route_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage<Route> expected() { + return ListPage.<Route>builder() + .kind(Kind.ROUTE_LIST) + .id("projects/myproject/global/routes") + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/routes")) + .items(ImmutableSet.of(new ParseRouteTest().expected(), + Route.builder() + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/routes/default-route-fc92a41ecb5a8d17")) + .id("507025480040058551") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-08T14:40:38.502-07:00")) + .name("default-route-fc92a41ecb5a8d17") + .description("Default route to the Internet.") + .network(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default")) + .destRange("0.0.0.0/0") + .priority(1000) + .nextHopGateway(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/gateways/default-internet-gateway")) + .build()) + ).build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteTest.java new file mode 100644 index 0000000..5ffd845 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseRouteTest.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.Route; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseRouteTest extends BaseGoogleComputeEngineParseTest<Route> { + + @Override + public String resource() { + return "/route_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Route expected() { + return Route.builder() + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/routes/default-route-c99ebfbed0e1f375")) + .id("7241926205630356071") + .name("default-route-c99ebfbed0e1f375") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-08T14:40:38.502-07:00")) + .description("Default route to the virtual network.") + .network(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default")) + .destRange("10.240.0.0/16") + .priority(1000) + .nextHopNetwork(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/networks/default")) + .tags(ImmutableSet.of("fooTag", "barTag")) + .build(); + + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotListTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotListTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotListTest.java new file mode 100644 index 0000000..f52aa3f --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotListTest.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.domain.Resource.Kind; +import org.jclouds.googlecomputeengine.domain.Snapshot; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseSnapshotListTest extends BaseGoogleComputeEngineParseTest<ListPage<Snapshot>> { + + @Override + public String resource() { + return "/snapshot_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage<Snapshot> expected() { + return ListPage.<Snapshot>builder() + .kind(Kind.SNAPSHOT_LIST) + .id("projects/myproject/global/snapshots") + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/snapshots")) + .items(ImmutableSet.of( + new ParseSnapshotTest().expected(), Snapshot.builder() + .selfLink(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/global/snapshots/test-snap2")) + .id("13895715048576107883") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse + ("2013-07-26T12:57:01.927-07:00")) + .status("READY") + .sizeGb(10) + .sourceDisk(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1")) + .name("test-snap2") + .description("") + .sourceDiskId("8243603669926824540") + .build())) + .build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotTest.java new file mode 100644 index 0000000..f3e7a01 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseSnapshotTest.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.Snapshot; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class ParseSnapshotTest extends BaseGoogleComputeEngineParseTest<Snapshot> { + + @Override + public String resource() { + return "/snapshot_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Snapshot expected() { + return Snapshot.builder() + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/global/snapshots/test-snap")) + .id("9734455566806191190") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2013-07-26T12:54:23.173-07:00")) + .status("READY") + .sizeGb(10) + .sourceDisk(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a/disks/testimage1")) + .name("test-snap") + .description("") + .sourceDiskId("8243603669926824540") + .build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneListTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneListTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneListTest.java new file mode 100644 index 0000000..54fe1a2 --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneListTest.java @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.ListPage; +import org.jclouds.googlecomputeengine.domain.Resource; +import org.jclouds.googlecomputeengine.domain.Zone; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; + +@Test(groups = "unit") +public class ParseZoneListTest extends BaseGoogleComputeEngineParseTest<ListPage<Zone>> { + + @Override + public String resource() { + return "/zone_list.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public ListPage<Zone> expected() { + return ListPage.<Zone>builder() + .kind(Resource.Kind.ZONE_LIST) + .id("projects/myproject/zones") + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones")) + .items(ImmutableSet.of( + new ParseZoneTest().expected() + , Zone.builder() + .id("13024414164050619686") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse + ("2012-10-24T20:13:19.271")) + .selfLink(URI.create("https://www.googleapis" + + ".com/compute/v1/projects/myproject/zones/us-central1-b")) + .name("us-central1-b") + .description("us-central1-b") + .status(Zone.Status.UP) + .addMaintenanceWindow(Zone.MaintenanceWindow.builder() + .name("2013-02-17-planned-outage") + .description("maintenance zone") + .beginTime(new SimpleDateFormatDateService().iso8601DateParse + ("2013-02-17T08:00:00.000")) + .endTime(new SimpleDateFormatDateService().iso8601DateParse + ("2013-03-03T08:00:00.000")) + .build()) + .build())) + .build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneTest.java new file mode 100644 index 0000000..48cdbfc --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/parse/ParseZoneTest.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.googlecomputeengine.parse; + +import java.net.URI; + +import javax.ws.rs.Consumes; +import javax.ws.rs.core.MediaType; + +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.jclouds.googlecomputeengine.domain.Zone; +import org.jclouds.googlecomputeengine.internal.BaseGoogleComputeEngineParseTest; +import org.testng.annotations.Test; + +@Test(groups = "unit") +public class ParseZoneTest extends BaseGoogleComputeEngineParseTest<Zone> { + + @Override + public String resource() { + return "/zone_get.json"; + } + + @Override + @Consumes(MediaType.APPLICATION_JSON) + public Zone expected() { + return Zone.builder() + .id("13020128040171887099") + .creationTimestamp(new SimpleDateFormatDateService().iso8601DateParse("2012-10-19T16:42:54.131")) + .selfLink(URI.create("https://www.googleapis.com/compute/v1/projects/myproject/zones/us-central1-a")) + .name("us-central1-a") + .description("us-central1-a") + .status(Zone.Status.DOWN) + .addMaintenanceWindow(Zone.MaintenanceWindow.builder() + .name("2012-11-10-planned-outage") + .description("maintenance zone") + .beginTime(new SimpleDateFormatDateService().iso8601DateParse("2012-11-10T20:00:00.000")) + .endTime(new SimpleDateFormatDateService().iso8601DateParse("2012-12-02T20:00:00.000")) + .build()) + .build(); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java new file mode 100644 index 0000000..58ed81c --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/googlecomputeengine/predicates/NetworkFirewallPredicatesTest.java @@ -0,0 +1,162 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +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; +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; + +@Test(groups = "unit") +public class NetworkFirewallPredicatesTest { + + 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(); + } + + 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(); + } + + @Test + public void testHasProtocol() { + assertTrue(hasProtocol(IpProtocol.TCP).apply(fwForTest()), + "Firewall " + fwForTest() + " should contain a TCP rule."); + } + + @Test + public void testHasProtocolFails() { + assertFalse(hasProtocol(IpProtocol.UDP).apply(fwForTest()), + "Firewall " + fwForTest() + " should NOT contain a UDP rule."); + } + + @Test + public void testHasPortRange() { + assertTrue(hasPortRange(Range.closed(2, 9)).apply(fwForTest()), + "Firewall " + fwForTest() + " should contain the port range 2-9."); + } + + @Test + public void testHasPortRangeFails() { + assertFalse(hasPortRange(Range.closed(11, 15)).apply(fwForTest()), + "Firewall " + fwForTest() + " should NOT contain the port range 11-15."); + } + + @Test + public void testHasSourceTag() { + assertTrue(hasSourceTag("tag-1").apply(getFwForTestSourceTags()), + "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'."); + } + + @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'."); + } + + @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'."); + } + + @Test + public void testEqualsIpPermission() { + 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."); + } + + @Test + public void testEqualsIpPermissionFails() { + 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."); + } + + @Test + public void testProvidesIpPermission() { + 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."); + + assertTrue(providesIpPermission(perm).apply(getFwForTestSourceTags()), + "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(); + + assertFalse(providesIpPermission(perm).apply(fwForTest()), + "Firewall " + fwForTest() + " should not provide IpPermission " + perm + " but does."); + } +} + http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthApiMetadataTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthApiMetadataTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthApiMetadataTest.java new file mode 100644 index 0000000..d6ea17f --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthApiMetadataTest.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.oauth.v2; + +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; +import org.jclouds.View; +import org.jclouds.apis.internal.BaseApiMetadataTest; +import org.testng.annotations.Test; + +/** + * Tests that OAuthApiMetadata is properly registered in ServiceLoader + * <p/> + * <pre> + * META-INF/services/org.jclouds.apis.ApiMetadata + * </pre> + */ +@Test(groups = "unit") +public class OAuthApiMetadataTest extends BaseApiMetadataTest { + + public OAuthApiMetadataTest() { + super(new OAuthApiMetadata(), ImmutableSet.<TypeToken<? extends View>>of()); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java new file mode 100644 index 0000000..901cdfe --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/OAuthTestUtils.java @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.oauth.v2; + +import com.google.common.base.Charsets; +import com.google.common.base.Throwables; +import com.google.common.io.Files; +import org.jclouds.oauth.v2.config.CredentialType; +import org.jclouds.oauth.v2.config.OAuthProperties; + +import java.io.File; +import java.io.IOException; +import java.util.Properties; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.oauth.v2.config.OAuthProperties.AUDIENCE; + +/** + * Utils for OAuth tests. + */ +public class OAuthTestUtils { + + public static Properties defaultProperties(Properties properties) { + try { + properties = properties == null ? new Properties() : properties; + properties.put("oauth.identity", "foo"); + properties.put("oauth.credential", + Files.asCharSource(new File("src/test/resources/testpk.pem"), Charsets.UTF_8).read()); + properties.put("oauth.endpoint", "http://localhost:5000/o/oauth2/token"); + properties.put(AUDIENCE, "https://accounts.google.com/o/oauth2/token"); + return properties; + } catch (IOException e) { + throw Throwables.propagate(e); + } + } + + public static Properties bearerTokenAuthProperties(Properties properties) { + properties = properties == null ? new Properties() : properties; + properties.put("oauth.identity", "761326798069-r5mljlln1rd4lrbhg75efgigp36m7...@developer.gserviceaccount.com"); + properties.put("oauth.credential", "1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M"); + properties.put("oauth.endpoint", "http://localhost:5000/o/oauth2/token"); + properties.put(AUDIENCE, "https://accounts.google.com/o/oauth2/token"); + properties.put(OAuthProperties.CREDENTIAL_TYPE, CredentialType.BEARER_TOKEN_CREDENTIALS.toString()); + return properties; + } + + public static String setCredential(Properties overrides, String key) { + String val = null; + String credentialFromFile = null; + String testKey = "test." + key; + + if (System.getProperties().containsKey(testKey)) { + val = System.getProperty(testKey); + } + checkNotNull(val, String.format("the property %s must be set (pem private key file path or private key as a string)", testKey)); + + if (val.startsWith("-----BEGIN")) { + return val; + } + + try { + credentialFromFile = Files.toString(new File(val), Charsets.UTF_8); + } catch (IOException e) { + throw Throwables.propagate(e); + } + overrides.setProperty(key, credentialFromFile); + return credentialFromFile; + } + + public static String getMandatoryProperty(Properties properties, String key) { + checkNotNull(properties); + checkNotNull(key); + String value = properties.getProperty(key); + return checkNotNull(value, String.format("mandatory property %s or test.%s was not present", key, key)); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/b45ae00e/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/features/OAuthApiExpectTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/features/OAuthApiExpectTest.java b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/features/OAuthApiExpectTest.java new file mode 100644 index 0000000..2008e5d --- /dev/null +++ b/dependencies/jclouds/apis/gce/1.8.1-stratos/src/test/java/org/jclouds/oauth/v2/features/OAuthApiExpectTest.java @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.jclouds.oauth.v2.features; + +import static com.google.common.base.Charsets.UTF_8; +import static com.google.common.io.BaseEncoding.base64Url; +import static org.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.Properties; + +import javax.ws.rs.core.MediaType; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.oauth.v2.OAuthApi; +import org.jclouds.oauth.v2.OAuthTestUtils; +import org.jclouds.oauth.v2.domain.ClaimSet; +import org.jclouds.oauth.v2.domain.Header; +import org.jclouds.oauth.v2.domain.Token; +import org.jclouds.oauth.v2.domain.TokenRequest; +import org.jclouds.oauth.v2.internal.BaseOAuthApiExpectTest; +import org.testng.annotations.Test; + +/** + * Tests that a token requess is well formed. + */ +@Test(groups = "unit") +public class OAuthApiExpectTest extends BaseOAuthApiExpectTest { + + private static final String header = "{\"alg\":\"RS256\",\"typ\":\"JWT\"}"; + + private static final String claims = "{\"iss\":\"761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer" + + ".gserviceaccount.com\"," + + "\"scope\":\"https://www.googleapis.com/auth/prediction\",\"aud\":\"https://accounts.google" + + ".com/o/oauth2/token\",\"exp\":1328573381,\"iat\":1328569781}"; + + private static final Token TOKEN = new Token.Builder().accessToken + ("1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M").tokenType("Bearer").expiresIn(3600).build(); + + private static final ClaimSet CLAIM_SET = new ClaimSet.Builder().addClaim("iss", + "761326798069-r5mljlln1rd4lrbhg75efgigp36m78j5@developer" + + ".gserviceaccount.com") + .addClaim("scope", "https://www.googleapis.com/auth/prediction") + .addClaim("aud", "https://accounts.google.com/o/oauth2/token") + .expirationTime(1328573381) + .emissionTime(1328569781).build(); + + private static final Header HEADER = new Header.Builder().signerAlgorithm("RS256").type("JWT").build(); + + private static final String URL_ENCODED_TOKEN_REQUEST = + "grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer&" + + // Base64 Encoded Header + "assertion=" + base64Url().omitPadding().encode(header.getBytes(UTF_8)) + "." + + // Base64 Encoded Claims + base64Url().omitPadding().encode(claims.getBytes(UTF_8)) + "." + + // Base64 encoded {header}.{claims} signature (using SHA256) + "W2Lesr_98AzVYiMbzxFqmwcOjpIWlwqkC6pNn1fXND9oSDNNnFhy-AAR6DKH-x9ZmxbY80" + + "R5fH-OCeWumXlVgceKN8Z2SmgQsu8ElTpypQA54j_5j8vUImJ5hsOUYPeyF1U2BUzZ3L5g" + + "03PXBA0YWwRU9E1ChH28dQBYuGiUmYw"; + + private static final HttpRequest TOKEN_REQUEST = HttpRequest.builder() + .method("POST") + .endpoint(URI.create("http://localhost:5000/o/oauth2/token")) + .addHeader("Accept", MediaType.APPLICATION_JSON) + .payload(payloadFromStringWithContentType(URL_ENCODED_TOKEN_REQUEST, "application/x-www-form-urlencoded")) + .build(); + + private static final HttpResponse TOKEN_RESPONSE = HttpResponse.builder().statusCode(200).payload( + payloadFromString("{\n" + + " \"access_token\" : \"1/8xbJqaOZXSUZbHLl5EOtu1pxz3fmmetKx9W8CV4t79M\",\n" + + " \"token_type\" : \"Bearer\",\n" + + " \"expires_in\" : 3600\n" + + "}")).build(); + + @Override + protected Properties setupProperties() { + return OAuthTestUtils.defaultProperties(super.setupProperties()); + } + + public void testGenerateJWTRequest() { + OAuthApi api = requestSendsResponse(TOKEN_REQUEST, TOKEN_RESPONSE); + assertEquals(api.authenticate(new TokenRequest(HEADER, CLAIM_SET)), TOKEN); + } +}
