http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/93aff921/profitbricks/src/test/java/org/jclouds/profitbricks/compute/config/StatusPredicateTest.java ---------------------------------------------------------------------- diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/compute/config/StatusPredicateTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/compute/config/StatusPredicateTest.java deleted file mode 100644 index 9c2b228..0000000 --- a/profitbricks/src/test/java/org/jclouds/profitbricks/compute/config/StatusPredicateTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * 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.profitbricks.compute.config; - -import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer; -import static org.testng.Assert.assertEquals; - -import java.util.concurrent.TimeUnit; - -import org.jclouds.profitbricks.ProfitBricksApi; -import org.jclouds.profitbricks.compute.config.ProfitBricksComputeServiceContextModule.DataCenterProvisioningStatePredicate; -import org.jclouds.profitbricks.compute.config.ProfitBricksComputeServiceContextModule.ServerStatusPredicate; -import org.jclouds.profitbricks.compute.config.ProfitBricksComputeServiceContextModule.SnapshotProvisioningStatePredicate; -import org.jclouds.profitbricks.domain.ProvisioningState; -import org.jclouds.profitbricks.domain.Server; -import org.jclouds.profitbricks.domain.Snapshot; -import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; -import org.jclouds.util.Predicates2; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; - - -/** - * Test class for {@link DataCenterProvisioningStatePredicate} and {@link ServerStatusPredicate} - */ -@Test(groups = "unit", testName = "ProvisioningStatusPollingPredicateTest") -public class StatusPredicateTest extends BaseProfitBricksMockTest { - - @Test - public void testDataCenterPredicate() throws Exception { - MockWebServer server = mockWebServer(); - - byte[] payloadInProcess = payloadFromResource("/datacenter/datacenter-state-inprocess.xml"); - byte[] payloadAvailable = payloadFromResource("/datacenter/datacenter-state.xml"); - - // wait 3 times - server.enqueue(new MockResponse().setBody(payloadInProcess)); - server.enqueue(new MockResponse().setBody(payloadInProcess)); - server.enqueue(new MockResponse().setBody(payloadInProcess)); - server.enqueue(new MockResponse().setBody(payloadAvailable)); - - server.enqueue(new MockResponse().setBody(payloadAvailable)); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - - Predicate<String> waitUntilAvailable = Predicates2.retry( - new DataCenterProvisioningStatePredicate(pbApi, ProvisioningState.AVAILABLE), - 30l, 1l, TimeUnit.SECONDS); - - String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; - try { - waitUntilAvailable.apply(id); - ProvisioningState finalState = pbApi.dataCenterApi().getDataCenterState(id); - assertRequestHasCommonProperties(server.takeRequest()); - assertEquals(finalState, ProvisioningState.AVAILABLE); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testServerPredicate() throws Exception { - MockWebServer server = mockWebServer(); - - byte[] payloadInProcess = payloadFromResource("/server/server-state-inprocess.xml"); - byte[] payloadAvailable = payloadFromResource("/server/server.xml"); - - // wait 3 times - server.enqueue(new MockResponse().setBody(payloadInProcess)); - server.enqueue(new MockResponse().setBody(payloadInProcess)); - server.enqueue(new MockResponse().setBody(payloadInProcess)); - server.enqueue(new MockResponse().setBody(payloadAvailable)); - - server.enqueue(new MockResponse().setBody(payloadAvailable)); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - - Predicate<String> waitUntilAvailable = Predicates2.retry( - new ServerStatusPredicate(pbApi, Server.Status.RUNNING), - 30l, 1l, TimeUnit.SECONDS); - - String id = "qwertyui-qwer-qwer-qwer-qwertyyuiiop"; - try { - waitUntilAvailable.apply(id); - Server remoteServer = pbApi.serverApi().getServer(id); - assertEquals(remoteServer.status(), Server.Status.RUNNING); - assertRequestHasCommonProperties(server.takeRequest()); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testSnapshotPredicate() throws Exception { - MockWebServer server = mockWebServer(); - - byte[] payloadInProcess = payloadFromResource("/snapshot/snapshot-state-inprocess.xml"); - byte[] payloadAvailable = payloadFromResource("/snapshot/snapshot.xml"); - - // wait 3 times - server.enqueue(new MockResponse().setBody(payloadInProcess)); - server.enqueue(new MockResponse().setBody(payloadInProcess)); - server.enqueue(new MockResponse().setBody(payloadInProcess)); - server.enqueue(new MockResponse().setBody(payloadAvailable)); - - server.enqueue(new MockResponse().setBody(payloadAvailable)); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - - Predicate<String> waitUntilAvailable = Predicates2.retry( - new SnapshotProvisioningStatePredicate(pbApi, ProvisioningState.AVAILABLE), - 30l, 1l, TimeUnit.SECONDS); - - String id = "qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh"; - try { - waitUntilAvailable.apply(id); - Snapshot snapshot = pbApi.snapshotApi().getSnapshot(id); - assertEquals(snapshot.state(), ProvisioningState.AVAILABLE); - assertRequestHasCommonProperties(server.takeRequest()); - } finally { - pbApi.close(); - server.shutdown(); - } - } - -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/93aff921/profitbricks/src/test/java/org/jclouds/profitbricks/compute/function/ProvisionableToImageTest.java ---------------------------------------------------------------------- diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/compute/function/ProvisionableToImageTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/compute/function/ProvisionableToImageTest.java deleted file mode 100644 index ddecc83..0000000 --- a/profitbricks/src/test/java/org/jclouds/profitbricks/compute/function/ProvisionableToImageTest.java +++ /dev/null @@ -1,271 +0,0 @@ -/* - * 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.profitbricks.compute.function; - -import static org.jclouds.profitbricks.domain.Location.US_LAS; -import static org.testng.Assert.assertEquals; - -import java.util.Calendar; -import java.util.Date; -import java.util.Set; - -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.ImageBuilder; -import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.compute.domain.OsFamily; -import org.jclouds.domain.Location; -import org.jclouds.domain.LocationBuilder; -import org.jclouds.domain.LocationScope; -import org.jclouds.profitbricks.domain.OsType; -import org.jclouds.profitbricks.domain.ProvisioningState; -import org.jclouds.profitbricks.domain.Snapshot; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -import com.google.common.base.Suppliers; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -@Test(groups = "unit", testName = "ProvisionableToImageTest") -public class ProvisionableToImageTest { - - private ProvisionableToImage fnImage; - - private final Location location = new LocationBuilder().id("us/las").description("us/las").scope(LocationScope.ZONE) - .parent(new LocationBuilder().id("us").description("us").scope(LocationScope.REGION).build()).build(); - - @BeforeTest - public void setup() { - this.fnImage = new ProvisionableToImage(Suppliers.<Set<? extends Location>> ofInstance(ImmutableSet.of(location))); - } - - @Test - public void testImageToImage() { - org.jclouds.profitbricks.domain.Image image - = org.jclouds.profitbricks.domain.Image.builder() - .isBootable(true) - .isCpuHotPlug(true) - .isCpuHotUnPlug(false) - .isDiscVirtioHotPlug(true) - .isDiscVirtioHotUnPlug(true) - .id("5ad99c9e-9166-11e4-9d74-52540066fee9") - .name("Ubuntu-14.04-LTS-server-2015-01-01") - .size(2048f) - .type(org.jclouds.profitbricks.domain.Image.Type.HDD) - .location(US_LAS) - .isNicHotPlug(true) - .isNicHotUnPlug(true) - .osType(OsType.LINUX) - .isPublic(true) - .isRamHotPlug(true) - .isRamHotUnPlug(false) - .isWriteable(true) - .build(); - - Image actual = fnImage.apply(image); - - Image expected = new ImageBuilder() - .ids(image.id()) - .name(image.name()) - .location(location) - .status(Image.Status.AVAILABLE) - .operatingSystem(OperatingSystem.builder() - .description("UBUNTU") - .family(OsFamily.UBUNTU) - .version("14.04") - .is64Bit(false) - .build()) - .userMetadata(ImmutableMap.of("provisionableType", "image")) - .build(); - - assertEquals(actual, expected); - } - - @Test - public void testImageDescriptionParsing() { - org.jclouds.profitbricks.domain.Image image1 - = org.jclouds.profitbricks.domain.Image.builder() - .id("f4742db0-9160-11e4-9d74-52540066fee9") - .name("Fedora-19-server-2015-01-01") - .size(2048f) - .type(org.jclouds.profitbricks.domain.Image.Type.HDD) - .location(US_LAS) - .osType(OsType.LINUX) - .build(); - - Image actual1 = fnImage.apply(image1); - - Image expected1 = new ImageBuilder() - .ids(image1.id()) - .name(image1.name()) - .location(location) - .status(Image.Status.AVAILABLE) - .operatingSystem(OperatingSystem.builder() - .description("FEDORA") - .family(OsFamily.FEDORA) - .version("7") - .is64Bit(true) - .build()) - .userMetadata(ImmutableMap.of("provisionableType", "image")) - .build(); - - assertEquals(actual1, expected1); - - org.jclouds.profitbricks.domain.Image image2 - = org.jclouds.profitbricks.domain.Image.builder() - .id("457bf707-d5d1-11e3-8b4f-52540066fee9") - .name("clearos-community-6.5.0-x86_64.iso") - .size(2048f) - .type(org.jclouds.profitbricks.domain.Image.Type.CDROM) - .location(US_LAS) - .osType(OsType.LINUX) - .build(); - - Image actual2 = fnImage.apply(image2); - - Image expected2 = new ImageBuilder() - .ids(image2.id()) - .name(image2.name()) - .location(location) - .status(Image.Status.AVAILABLE) - .operatingSystem(OperatingSystem.builder() - .description("UNRECOGNIZED") - .family(OsFamily.UNRECOGNIZED) - .version("6.5.0") - .is64Bit(true) - .build()) - .userMetadata(ImmutableMap.of("provisionableType", "image")) - .build(); - - assertEquals(actual2, expected2); - - org.jclouds.profitbricks.domain.Image image3 - = org.jclouds.profitbricks.domain.Image.builder() - .id("e54af701-53b8-11e3-8f17-52540066fee9") - .name("windows-2008-r2-server-setup.iso") - .size(2048f) - .type(org.jclouds.profitbricks.domain.Image.Type.CDROM) - .location(US_LAS) - .osType(OsType.WINDOWS) - .build(); - - Image actual3 = fnImage.apply(image3); - - Image expected3 = new ImageBuilder() - .ids(image3.id()) - .name(image3.name()) - .location(location) - .status(Image.Status.AVAILABLE) - .operatingSystem(OperatingSystem.builder() - .description("WINDOWS") - .family(OsFamily.WINDOWS) - .version("2008") - .is64Bit(false) - .build()) - .userMetadata(ImmutableMap.of("provisionableType", "image")) - .build(); - - assertEquals(actual3, expected3); - - } - - @Test - public void testSnapshotToImage() { - Calendar calendar = Calendar.getInstance(); - calendar.set(2015, 4, 13); - Date date = calendar.getTime(); - - Snapshot snapshot1 = Snapshot.builder() - .isBootable(true) - .isCpuHotPlug(true) - .isCpuHotUnPlug(false) - .isDiscVirtioHotPlug(true) - .isDiscVirtioHotUnPlug(true) - .id("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh") - .name("placeholder-snapshot-04/13/2015") - .description("Created from \"placeholder\" in Data Center \"sbx-computeservice\"") - .size(2048f) - .location(US_LAS) - .isNicHotPlug(true) - .isNicHotUnPlug(true) - .osType(OsType.LINUX) - .isRamHotPlug(true) - .isRamHotUnPlug(false) - .creationTime(date) - .lastModificationTime(new Date()) - .state(ProvisioningState.AVAILABLE) - .build(); - - Image actual1 = fnImage.apply(snapshot1); - - Image expected1 = new ImageBuilder() - .ids(snapshot1.id()) - .name(snapshot1.name()) - .location(location) - .status(Image.Status.AVAILABLE) - .operatingSystem(OperatingSystem.builder() - .description(snapshot1.description()) - .family(OsFamily.LINUX) - .is64Bit(true) - .build()) - .userMetadata(ImmutableMap.of("provisionableType", "snapshot")) - .build(); - - assertEquals(actual1, expected1); - - Snapshot snapshot2 = Snapshot.builder() - .isBootable(true) - .isCpuHotPlug(true) - .isCpuHotUnPlug(false) - .isDiscVirtioHotPlug(true) - .isDiscVirtioHotUnPlug(true) - .id("d80bf9c0-ce6e-4283-9ea4-2906635f6137") - .name("jclouds-ubuntu14.10-template") - .description("Created from \"jclouds-ubuntu14.10 Storage\" in Data Center \"jclouds-computeservice\"") - .size(10240f) - .location(US_LAS) - .isNicHotPlug(true) - .isNicHotUnPlug(true) - .osType(OsType.LINUX) - .isRamHotPlug(true) - .isRamHotUnPlug(false) - .creationTime(date) - .lastModificationTime(new Date()) - .state(ProvisioningState.INPROCESS) - .build(); - - Image actual2 = fnImage.apply(snapshot2); - - Image expected2 = new ImageBuilder() - .ids(snapshot2.id()) - .name(snapshot2.name()) - .location(location) - .status(Image.Status.PENDING) - .operatingSystem(OperatingSystem.builder() - .description("ubuntu") - .family(OsFamily.UBUNTU) - .is64Bit(true) - .version("00.00") - .build()) - .userMetadata(ImmutableMap.of("provisionableType", "snapshot")) - .build(); - - assertEquals(actual2, expected2); - assertEquals(actual2.getOperatingSystem(), expected2.getOperatingSystem()); - - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/93aff921/profitbricks/src/test/java/org/jclouds/profitbricks/compute/function/ServerToNodeMetadataTest.java ---------------------------------------------------------------------- diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/compute/function/ServerToNodeMetadataTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/compute/function/ServerToNodeMetadataTest.java deleted file mode 100644 index 60f43ec..0000000 --- a/profitbricks/src/test/java/org/jclouds/profitbricks/compute/function/ServerToNodeMetadataTest.java +++ /dev/null @@ -1,204 +0,0 @@ -/* - * 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.profitbricks.compute.function; - -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.jclouds.profitbricks.domain.Location.DE_FRA; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import java.util.Set; - -import org.easymock.EasyMock; -import org.jclouds.compute.domain.HardwareBuilder; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.NodeMetadataBuilder; -import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.compute.domain.OsFamily; -import org.jclouds.compute.domain.Processor; -import org.jclouds.compute.domain.Volume; -import org.jclouds.compute.domain.VolumeBuilder; -import org.jclouds.compute.functions.GroupNamingConvention; -import org.jclouds.domain.Location; -import org.jclouds.domain.LocationBuilder; -import org.jclouds.domain.LocationScope; -import org.jclouds.profitbricks.ProfitBricksApi; -import org.jclouds.profitbricks.ProfitBricksApiMetadata; -import org.jclouds.profitbricks.domain.AvailabilityZone; -import org.jclouds.profitbricks.domain.DataCenter; -import org.jclouds.profitbricks.domain.Nic; -import org.jclouds.profitbricks.domain.OsType; -import org.jclouds.profitbricks.domain.ProvisioningState; -import org.jclouds.profitbricks.domain.Server; -import org.jclouds.profitbricks.domain.Storage; -import org.jclouds.profitbricks.features.DataCenterApi; -import org.testng.annotations.AfterMethod; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.google.common.base.Supplier; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableSet; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.name.Names; - -@Test(groups = "unit", testName = "ServerToNodeMetadataTest") -public class ServerToNodeMetadataTest { - - private ServerToNodeMetadata fnNodeMetadata; - - private ProfitBricksApi api; - - private DataCenterApi dataCenterApi; - - @BeforeMethod - public void setup() { - Supplier<Set<? extends Location>> locationsSupply = new Supplier<Set<? extends Location>>() { - @Override - public Set<? extends Location> get() { - return ImmutableSet.of( - new LocationBuilder() - .id("de/fra") - .description("de/fra") - .scope(LocationScope.ZONE) - .parent(new LocationBuilder() - .id("de") - .description("de") - .scope(LocationScope.REGION) - .build()) - .build()); - } - }; - - GroupNamingConvention.Factory namingConvention = Guice.createInjector(new AbstractModule() { - @Override - protected void configure() { - Names.bindProperties(binder(), new ProfitBricksApiMetadata().getDefaultProperties()); - } - }).getInstance(GroupNamingConvention.Factory.class); - - dataCenterApi = EasyMock.createMock(DataCenterApi.class); - api = EasyMock.createMock(ProfitBricksApi.class); - - expect(dataCenterApi.getDataCenter("mock")).andReturn( - DataCenter.builder().id("mock").version(10).location(DE_FRA).build()); - expect(api.dataCenterApi()).andReturn(dataCenterApi); - - replay(dataCenterApi, api); - - this.fnNodeMetadata = new ServerToNodeMetadata(new StorageToVolume(), locationsSupply, api, namingConvention); - } - - @AfterMethod - public void tearDown() { - verify(api, dataCenterApi); - } - - @Test - public void testServerToNodeMetadata() { - Server server = Server.builder() - .dataCenter(DataCenter.builder() - .id("mock") - .version(10) - .location(org.jclouds.profitbricks.domain.Location.DE_FRA) - .build()) - .id("qwertyui-qwer-qwer-qwer-qwertyyuiiop") - .name("mock-facebook-node") - .cores(4) - .ram(4096) - .hasInternetAccess(true) - .state(ProvisioningState.AVAILABLE) - .status(Server.Status.RUNNING) - .osType(OsType.LINUX) - .availabilityZone(AvailabilityZone.AUTO) - .isCpuHotPlug(true) - .isRamHotPlug(true) - .isNicHotPlug(true) - .isNicHotUnPlug(true) - .isDiscVirtioHotPlug(true) - .isDiscVirtioHotUnPlug(true) - .storages(ImmutableList.<Storage>of( - Storage.builder() - .bootDevice(true) - .busType(Storage.BusType.VIRTIO) - .deviceNumber(1) - .size(40f) - .id("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh") - .name("facebook-storage") - .build() - ) - ) - .nics(ImmutableList.<Nic>of( - Nic.builder() - .id("qwqwqwqw-wewe-erer-rtrt-tytytytytyty") - .lanId(1) - .dataCenterId("12345678-abcd-efgh-ijkl-987654321000") - .internetAccess(true) - .serverId("qwertyui-qwer-qwer-qwer-qwertyyuiiop") - .macAddress("02:01:09:cd:f0:b0") - .ips( ImmutableList.<String>of("173.252.120.6")) - .build() - ) - ) - .build(); - - NodeMetadata expected = fnNodeMetadata.apply(server); - assertNotNull(expected); - - NodeMetadata actual = new NodeMetadataBuilder() - .group("mock") - .ids(server.id()) - .name(server.name()) - .backendStatus("AVAILABLE") - .status(NodeMetadata.Status.RUNNING) - .hardware(new HardwareBuilder() - .ids("cpu=4,ram=4096,disk=40") - .name("cpu=4,ram=4096,disk=40") - .ram(server.ram()) - .processor(new Processor(server.cores(), 1d)) - .hypervisor("kvm") - .volume(new VolumeBuilder() - .bootDevice(true) - .size(40f) - .id("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh") - .durable(true) - .type(Volume.Type.LOCAL) - .build()) - .build()) - .operatingSystem(new OperatingSystem.Builder() - .description(OsFamily.LINUX.value()) - .family(OsFamily.LINUX) - .build()) - .location(new LocationBuilder() - .id("de/fra") - .description("de/fra") - .scope(LocationScope.ZONE) - .parent(new LocationBuilder() - .id("de") - .description("de") - .scope(LocationScope.REGION) - .build()) - .build()) - .publicAddresses(ImmutableList.<String>of("173.252.120.6")) - .build(); - - assertEquals(actual, expected); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/93aff921/profitbricks/src/test/java/org/jclouds/profitbricks/compute/function/StorageToVolumeTest.java ---------------------------------------------------------------------- diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/compute/function/StorageToVolumeTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/compute/function/StorageToVolumeTest.java deleted file mode 100644 index 8a782e7..0000000 --- a/profitbricks/src/test/java/org/jclouds/profitbricks/compute/function/StorageToVolumeTest.java +++ /dev/null @@ -1,61 +0,0 @@ -/* - * 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.profitbricks.compute.function; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.compute.domain.Volume; -import org.jclouds.compute.domain.VolumeBuilder; -import org.jclouds.profitbricks.domain.Storage; -import org.testng.annotations.BeforeTest; -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "StorageToVolumeTest") -public class StorageToVolumeTest { - - private StorageToVolume fnVolume; - - @BeforeTest - public void setup() { - this.fnVolume = new StorageToVolume(); - } - - @Test - public void testStorageToVolume() { - Storage storage = Storage.builder() - .id("qswdefrg-qaws-qaws-defe-rgrgdsvcxbrh") - .size(40) - .name("hdd-1") - .busType(Storage.BusType.VIRTIO) - .bootDevice(true) - .deviceNumber(1) - .build(); - - Volume actual = fnVolume.apply(storage); - - Volume expected = new VolumeBuilder() - .id(storage.id()) - .size(40f) - .bootDevice(true) - .device("1") - .type(Volume.Type.LOCAL) - .durable(true) - .build(); - - assertEquals(actual, expected); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/93aff921/profitbricks/src/test/java/org/jclouds/profitbricks/domain/FirewallRuleBuilderTest.java ---------------------------------------------------------------------- diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/domain/FirewallRuleBuilderTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/domain/FirewallRuleBuilderTest.java deleted file mode 100644 index 6f43604..0000000 --- a/profitbricks/src/test/java/org/jclouds/profitbricks/domain/FirewallRuleBuilderTest.java +++ /dev/null @@ -1,82 +0,0 @@ -/* - * 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.profitbricks.domain; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; - -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "FirewallRuleBuilderTest") -public class FirewallRuleBuilderTest { - - private final String _name = "rule-name"; - private final Integer _portRangeEnd = 45678; - private final Integer _portRangeStart = 12345; - private final Firewall.Protocol _protocol = Firewall.Protocol.TCP; - private final String _sourceIp = "192.168.0.1"; - private final String _sourceMac = "aa:bb:cc:dd:ee:ff"; - private final String _targetIp = "192.168.0.2"; - - private final Integer _icmpType = 2; - private final Integer _icmpCode = 24; - - @Test - public void testAutoValueFirewallRulePropertiesSettingCorrectly() { - Firewall.Rule actual = Firewall.Rule.builder() - .name(_name) - .portRangeEnd(_portRangeEnd) - .portRangeStart(_portRangeStart) - .protocol(_protocol) - .sourceIp(_sourceIp) - .sourceMac(_sourceMac) - .targetIp(_targetIp) - .build(); - - assertEquals(actual.name(), _name); - assertEquals(actual.portRangeEnd(), _portRangeEnd); - assertEquals(actual.portRangeStart(), _portRangeStart); - assertEquals(actual.protocol(), _protocol); - assertEquals(actual.sourceIp(), _sourceIp); - assertEquals(actual.sourceMac(), _sourceMac); - assertEquals(actual.targetIp(), _targetIp); - } - - @Test - public void testAutoValueFirewallRuleWithIcmpPropertiesSettingCorrectly() { - Firewall.Rule actual = Firewall.Rule.builder() - .name(_name) - .icmpCode(_icmpCode) - .icmpType(_icmpType) - .protocol(Firewall.Protocol.ICMP) - .sourceIp(_sourceIp) - .sourceMac(_sourceMac) - .targetIp(_targetIp) - .build(); - - assertEquals(actual.name(), _name); - assertNull(actual.portRangeEnd()); - assertNull(actual.portRangeStart()); - assertEquals(actual.protocol(), Firewall.Protocol.ICMP); - assertEquals(actual.sourceIp(), _sourceIp); - assertEquals(actual.sourceMac(), _sourceMac); - assertEquals(actual.targetIp(), _targetIp); - assertEquals(actual.icmpCode(), _icmpCode); - assertEquals(actual.icmpType(), _icmpType); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/93aff921/profitbricks/src/test/java/org/jclouds/profitbricks/domain/ServerBuilderTest.java ---------------------------------------------------------------------- diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/domain/ServerBuilderTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/domain/ServerBuilderTest.java deleted file mode 100644 index 6cad856..0000000 --- a/profitbricks/src/test/java/org/jclouds/profitbricks/domain/ServerBuilderTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * 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.profitbricks.domain; - -import java.util.Date; -import static org.testng.Assert.assertEquals; -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "ServerBuilderTest") -public class ServerBuilderTest { - - private final Boolean _isCpuHotPlug = true; - private final Boolean _isRamHotPlug = false; - private final Boolean _isNicHotPlug = true; - private final Boolean _isNicHotUnPlug = false; - private final Boolean _isDiscVirtioHotPlug = true; - private final Boolean _isDiscVirtioHotUnPlug = false; - private final Integer _cores = 8; - private final Integer _ram = 8 * 1024; - private final String _id = "some-random-server-id"; - private final String _name = "jclouds-node"; - private final Boolean _hasInternetAccess = true; - private final ProvisioningState _state = ProvisioningState.INACTIVE; - private final Server.Status _status = Server.Status.SHUTOFF; - private final OsType _osType = OsType.LINUX; - private final AvailabilityZone _availabilityZone = AvailabilityZone.ZONE_1; - private final Date _creationTime = new Date(); - private final Date _lastModificationTime = new Date(); - - private final Integer _lanId = 5; - private final String _dataCenterId = "some-random-datacenter-id"; - private final String _bootFromStorageId = "some-random-storage-id"; - private final String _bootFromImageId = "some-random-image-id"; - - @Test - public void testAutoValueServerPropertiesSettingCorrectly() { - Server actual = Server.builder() - .availabilityZone(_availabilityZone) - .creationTime(_creationTime) - .cores(_cores) - .hasInternetAccess(_hasInternetAccess) - .id(_id) - .name(_name) - .isCpuHotPlug(_isCpuHotPlug) - .isDiscVirtioHotPlug(_isDiscVirtioHotPlug) - .isDiscVirtioHotUnPlug(_isDiscVirtioHotUnPlug) - .isNicHotPlug(_isNicHotPlug) - .isNicHotUnPlug(_isNicHotUnPlug) - .isRamHotPlug(_isRamHotPlug) - .lastModificationTime(_lastModificationTime) - .ram(_ram) - .osType(_osType) - .state(_state) - .status(_status) - .build(); - - assertEquals(actual.availabilityZone(), _availabilityZone); - assertEquals(actual.cores(), _cores); - assertEquals(actual.creationTime(), _creationTime); - assertEquals(actual.hasInternetAccess(), _hasInternetAccess); - assertEquals(actual.id(), _id); - assertEquals(actual.name(), _name); - assertEquals(actual.isCpuHotPlug(), _isCpuHotPlug); - assertEquals(actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug); - assertEquals(actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug); - assertEquals(actual.isNicHotPlug(), _isNicHotPlug); - assertEquals(actual.isNicHotUnPlug(), _isNicHotUnPlug); - assertEquals(actual.isRamHotPlug(), _isRamHotPlug); - assertEquals(actual.lastModificationTime(), _lastModificationTime); - assertEquals(actual.ram(), _ram); - assertEquals(actual.osType(), _osType); - assertEquals(actual.state(), _state); - } - - @Test - public void testAutoValueServerRequestCreatePayloadPropertiesSettingCorrectly() { - Server.Request.CreatePayload actual = Server.Request.creatingBuilder() - .availabilityZone(_availabilityZone) - .bootFromImageId(_bootFromImageId) - .bootFromStorageId(_bootFromStorageId) - .cores(_cores) - .dataCenterId(_dataCenterId) - .hasInternetAccess(_hasInternetAccess) - .name(_name) - .isCpuHotPlug(_isCpuHotPlug) - .isDiscVirtioHotPlug(_isDiscVirtioHotPlug) - .isDiscVirtioHotUnPlug(_isDiscVirtioHotUnPlug) - .isNicHotPlug(_isNicHotPlug) - .isNicHotUnPlug(_isNicHotUnPlug) - .isRamHotPlug(_isRamHotPlug) - .lanId(_lanId) - .ram(_ram) - .osType(_osType) - .build(); - - assertEquals(actual.availabilityZone(), _availabilityZone); - assertEquals(actual.bootFromImageId(), _bootFromImageId); - assertEquals(actual.bootFromStorageId(), _bootFromStorageId); - assertEquals(actual.cores(), _cores.intValue()); - assertEquals(actual.dataCenterId(), _dataCenterId); - assertEquals(actual.hasInternetAccess(), _hasInternetAccess); - assertEquals(actual.name(), _name); - assertEquals(actual.isCpuHotPlug(), _isCpuHotPlug); - assertEquals(actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug); - assertEquals(actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug); - assertEquals(actual.isNicHotPlug(), _isNicHotPlug); - assertEquals(actual.isNicHotUnPlug(), _isNicHotUnPlug); - assertEquals(actual.isRamHotPlug(), _isRamHotPlug); - assertEquals(actual.lanId(), _lanId); - assertEquals(actual.ram(), _ram.intValue()); - assertEquals(actual.osType(), _osType); - } - - @Test - public void testAutoValueServerRequestUpdatePayloadPropertiesSettingCorrectly() { - Server.Request.UpdatePayload actual = Server.Request.updatingBuilder() - .availabilityZone(_availabilityZone) - .bootFromImageId(_bootFromImageId) - .bootFromStorageId(_bootFromStorageId) - .cores(_cores) - .name(_name) - .id(_id) - .isCpuHotPlug(_isCpuHotPlug) - .isDiscVirtioHotPlug(_isDiscVirtioHotPlug) - .isDiscVirtioHotUnPlug(_isDiscVirtioHotUnPlug) - .isNicHotPlug(_isNicHotPlug) - .isNicHotUnPlug(_isNicHotUnPlug) - .isRamHotPlug(_isRamHotPlug) - .ram(_ram) - .osType(_osType) - .build(); - - assertEquals(actual.availabilityZone(), _availabilityZone); - assertEquals(actual.bootFromImageId(), _bootFromImageId); - assertEquals(actual.bootFromStorageId(), _bootFromStorageId); - assertEquals(actual.cores(), _cores); - assertEquals(actual.name(), _name); - assertEquals(actual.id(), _id); - assertEquals(actual.isCpuHotPlug(), _isCpuHotPlug); - assertEquals(actual.isDiscVirtioHotPlug(), _isDiscVirtioHotPlug); - assertEquals(actual.isDiscVirtioHotUnPlug(), _isDiscVirtioHotUnPlug); - assertEquals(actual.isNicHotPlug(), _isNicHotPlug); - assertEquals(actual.isNicHotUnPlug(), _isNicHotUnPlug); - assertEquals(actual.isRamHotPlug(), _isRamHotPlug); - assertEquals(actual.ram(), _ram); - assertEquals(actual.osType(), _osType); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/93aff921/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiLiveTest.java ---------------------------------------------------------------------- diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiLiveTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiLiveTest.java deleted file mode 100644 index 33a086c..0000000 --- a/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiLiveTest.java +++ /dev/null @@ -1,123 +0,0 @@ -/* - * 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.profitbricks.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -import java.util.List; - -import org.jclouds.profitbricks.BaseProfitBricksLiveTest; -import org.jclouds.profitbricks.domain.DataCenter; -import org.jclouds.profitbricks.domain.Location; -import org.jclouds.profitbricks.domain.ProvisioningState; - -import org.testng.annotations.AfterClass; -import org.testng.annotations.Test; - -@Test(groups = "live", testName = "DataCenterApiLiveTest") -public class DataCenterApiLiveTest extends BaseProfitBricksLiveTest { - - private String dcId; - - @Test - public void testCreateDataCenter() { - DataCenter dc = api.dataCenterApi().createDataCenter( - DataCenter.Request.creatingPayload("JClouds", Location.DE_FKB) - ); - - assertNotNull(dc); - assertDataCenterAvailable(dc); - - dcId = dc.id(); - } - - @Test(dependsOnMethods = "testCreateDataCenter") - public void testGetDataCenter() { - assertNotNull(dcId, "No available datacenter found."); - - DataCenter dataCenter = api.dataCenterApi().getDataCenter(dcId); - - assertNotNull(dataCenter); - assertEquals(dataCenter.id(), dcId); - } - - @Test(dependsOnMethods = "testCreateDataCenter") - public void testGetAllDataCenters() { - List<DataCenter> dataCenters = api.dataCenterApi().getAllDataCenters(); - - assertNotNull(dataCenters); - assertFalse(dataCenters.isEmpty(), "No datacenter found."); - } - - @Test(dependsOnMethods = "testCreateDataCenter") - public void testGetDataCenterState() { - assertNotNull(dcId, "No available datacenter found."); - - ProvisioningState state = api.dataCenterApi().getDataCenterState(dcId); - - assertNotNull(state); - } - - @Test(dependsOnMethods = "testGetDataCenter") - public void testUpdateDataCenter() { - assertNotNull(dcId, "No available datacenter found."); - - final String newName = "Apache"; - DataCenter dataCenter = api.dataCenterApi().updateDataCenter( - DataCenter.Request.updatingPayload(dcId, newName) - ); - - assertNotNull(dataCenter); - assertDataCenterAvailable(dataCenter); - - DataCenter fetchedDc = api.dataCenterApi().getDataCenter(dcId); - - assertNotNull(fetchedDc); - assertEquals(newName, fetchedDc.name()); - } - - @Test(dependsOnMethods = "testUpdateDataCenter") - public void testClearDataCenter() { - DataCenter dataCenter = api.dataCenterApi().clearDataCenter(dcId); - - assertNotNull(dataCenter); - } - - @Test - public void testGetNonExistingDataCenter() { - DataCenter dataCenter = api.dataCenterApi().getDataCenter("random-non-existing-id"); - - assertNull(dataCenter); - } - - @Test - public void testDeleteNonExistingDataCenterMustReturnFalse() { - boolean result = api.dataCenterApi().deleteDataCenter("random-non-existing-id"); - - assertFalse(result); - } - - @AfterClass(alwaysRun = true) - public void testDeleteDataCenter() { - boolean result = api.dataCenterApi().deleteDataCenter(dcId); - assertTrue(result, "Created test data center was not deleted."); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/93aff921/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java ---------------------------------------------------------------------- diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java deleted file mode 100644 index 262d34a..0000000 --- a/profitbricks/src/test/java/org/jclouds/profitbricks/features/DataCenterApiMockTest.java +++ /dev/null @@ -1,271 +0,0 @@ -/* - * 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.profitbricks.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; - -import java.util.List; - -import org.jclouds.profitbricks.ProfitBricksApi; -import org.jclouds.profitbricks.domain.DataCenter; -import org.jclouds.profitbricks.domain.Location; -import org.jclouds.profitbricks.domain.ProvisioningState; -import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; -import org.testng.annotations.Test; - -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; - -/** - * Mock tests for the {@link org.jclouds.profitbricks.features.DataCenterApi} class - */ -@Test(groups = "unit", testName = "DataCenterApiMockTest") -public class DataCenterApiMockTest extends BaseProfitBricksMockTest { - - @Test - public void testGetAllDataCenters() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/datacenter/datacenters.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - DataCenterApi api = pbApi.dataCenterApi(); - - try { - List<DataCenter> dataCenters = api.getAllDataCenters(); - assertRequestHasCommonProperties(server.takeRequest(), "<ws:getAllDataCenters/>"); - assertNotNull(dataCenters); - assertEquals(dataCenters.size(), 2); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testGetAllDataCentersReturning404() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - DataCenterApi api = pbApi.dataCenterApi(); - - try { - List<DataCenter> dataCenters = api.getAllDataCenters(); - assertRequestHasCommonProperties(server.takeRequest()); - assertTrue(dataCenters.isEmpty()); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testGetDataCenter() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/datacenter/datacenter.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - DataCenterApi api = pbApi.dataCenterApi(); - - String id = "12345678-abcd-efgh-ijkl-987654321000"; - String content = "<ws:getDataCenter><dataCenterId>" + id + "</dataCenterId></ws:getDataCenter>"; - try { - DataCenter dataCenter = api.getDataCenter(id); - assertRequestHasCommonProperties(server.takeRequest(), content); - assertNotNull(dataCenter); - assertEquals(dataCenter.id(), id); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testGetNonExistingDataCenter() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - DataCenterApi api = pbApi.dataCenterApi(); - - String id = "random-non-existing-id"; - try { - DataCenter dataCenter = api.getDataCenter(id); - assertRequestHasCommonProperties(server.takeRequest()); - assertNull(dataCenter); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testGetDataCenterState() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/datacenter/datacenter-state.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - DataCenterApi api = pbApi.dataCenterApi(); - - String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; - String content = "<ws:getDataCenterState><dataCenterId>" + id + "</dataCenterId></ws:getDataCenterState>"; - try { - ProvisioningState state = api.getDataCenterState(id); - assertRequestHasCommonProperties(server.takeRequest(), content); - assertNotNull(state); - assertEquals(state, ProvisioningState.AVAILABLE); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testCreateDataCenter() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/datacenter/datacenter-created.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - DataCenterApi api = pbApi.dataCenterApi(); - - String content = "<ws:createDataCenter><request>" - + "<dataCenterName>JClouds-DC</dataCenterName>" - + "<location>de/fra</location>" - + "</request></ws:createDataCenter>"; - try { - DataCenter dataCenter = api.createDataCenter( - DataCenter.Request.creatingPayload("JClouds-DC", Location.DE_FRA) - ); - assertRequestHasCommonProperties(server.takeRequest(), content); - assertNotNull(dataCenter); - assertEquals(dataCenter.id(), "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); - assertEquals(dataCenter.version(), 1); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testCreateDataCenterWithIllegalArguments() throws Exception { - String[] names = {"JCl@ouds", "JC|ouds", "^clouds", ""}; - for (String name : names) - try { - DataCenter.Request.creatingPayload(name, Location.US_LAS); - fail("Should have failed for name: ".concat(name)); - } catch (IllegalArgumentException ex) { - // expected exception - } - } - - @Test - public void testUpdateDataCenter() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/datacenter/datacenter-updated.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - DataCenterApi api = pbApi.dataCenterApi(); - - String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; - String newName = "Apache"; - - String content = "<ws:updateDataCenter><request>" - + "<dataCenterId>" + id + "</dataCenterId>" - + "<dataCenterName>" + newName + "</dataCenterName>" - + "</request></ws:updateDataCenter>"; - try { - DataCenter dataCenter = api.updateDataCenter( - DataCenter.Request.updatingPayload(id, newName) - ); - assertRequestHasCommonProperties(server.takeRequest(), content); - assertNotNull(dataCenter); - assertEquals(dataCenter.id(), id); - assertEquals(dataCenter.version(), 2); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testClearDataCenter() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/datacenter/datacenter-cleared.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - DataCenterApi api = pbApi.dataCenterApi(); - - String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; - - String content = "<ws:clearDataCenter><dataCenterId>" + id + "</dataCenterId></ws:clearDataCenter>"; - try { - DataCenter dataCenter = api.clearDataCenter(id); - - assertRequestHasCommonProperties(server.takeRequest(), content); - assertNotNull(dataCenter); - assertEquals(dataCenter.id(), id); - assertEquals(dataCenter.version(), 3); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testDeleteDataCenter() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/datacenter/datacenter-deleted.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - DataCenterApi api = pbApi.dataCenterApi(); - - String id = "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"; - - String content = "<ws:deleteDataCenter><dataCenterId>" + id + "</dataCenterId></ws:deleteDataCenter>"; - try { - boolean result = api.deleteDataCenter(id); - assertRequestHasCommonProperties(server.takeRequest(), content); - assertTrue(result); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testDeleteNonExistingDataCenter() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - DataCenterApi api = pbApi.dataCenterApi(); - - try { - boolean result = api.deleteDataCenter("aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee"); - assertRequestHasCommonProperties(server.takeRequest()); - assertFalse(result); - } finally { - pbApi.close(); - server.shutdown(); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/93aff921/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiLiveTest.java ---------------------------------------------------------------------- diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiLiveTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiLiveTest.java deleted file mode 100644 index ff4dbb4..0000000 --- a/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiLiveTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * 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.profitbricks.features; - -import static org.testng.Assert.assertNotNull; - -import org.jclouds.profitbricks.BaseProfitBricksLiveTest; -import org.jclouds.profitbricks.domain.DataCenter; -import org.jclouds.profitbricks.domain.Drive; -import org.jclouds.profitbricks.domain.Image; -import org.jclouds.profitbricks.domain.Server; -import org.testng.annotations.Test; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; - -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; - -@Test(groups = "live", testName = "DrivesApiLiveTest") -public class DrivesApiLiveTest extends BaseProfitBricksLiveTest { - - private DataCenter dataCenter; - private Server server; - private Image image; - - @BeforeClass - public void setupTest() { - dataCenter = findOrCreateDataCenter("drivesApiLiveTest" + System.currentTimeMillis()); - server = findOrCreateServer(dataCenter); - image = Iterables.tryFind(api.imageApi().getAllImages(), new Predicate<Image>() { - - @Override - public boolean apply(Image input) { - return input.location() == dataCenter.location() - && input.type() == Image.Type.CDROM; - } - }).get(); - } - - @Test - public void addRomDriveToServerTest() { - assertDataCenterAvailable(dataCenter); - String requestId = api.drivesApi().addRomDriveToServer( - Drive.Request.AddRomDriveToServerPayload.builder() - .serverId(server.id()) - .imageId(image.id()) - .deviceNumber("0") - .build()); - assertNotNull(requestId); - } - - @Test(dependsOnMethods = "addRomDriveToServerTest") - public void removeRomDriveFromServerTest() { - assertDataCenterAvailable(dataCenter); - String requestId = api.drivesApi().removeRomDriveFromServer(image.id(), server.id()); - assertNotNull(requestId); - } - - @AfterClass(alwaysRun = true) - public void cleanUp() { - destroyDataCenter(dataCenter); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/93aff921/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiMockTest.java ---------------------------------------------------------------------- diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiMockTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiMockTest.java deleted file mode 100644 index 38cdcf0..0000000 --- a/profitbricks/src/test/java/org/jclouds/profitbricks/features/DrivesApiMockTest.java +++ /dev/null @@ -1,81 +0,0 @@ -/* - * 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.profitbricks.features; - -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import org.jclouds.profitbricks.ProfitBricksApi; -import org.jclouds.profitbricks.domain.Drive; -import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; -import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer; -import static org.testng.Assert.assertNotNull; -import org.testng.annotations.Test; - -@Test(groups = "unit", testName = "DrivesApiMockTest") -public class DrivesApiMockTest extends BaseProfitBricksMockTest { - - @Test - public void addRomDriveToServerTest() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/drives/drives-add.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - DrivesApi api = pbApi.drivesApi(); - - String content = "<ws:addRomDriveToServer>" - + "<request>" - + "<imageId>image-id</imageId>" - + "<serverId>server-id</serverId>" - + "<deviceNumber>device-number</deviceNumber>" - + "</request>" - + "</ws:addRomDriveToServer>"; - try { - String requestId = api.addRomDriveToServer(Drive.Request.AddRomDriveToServerPayload.builder() - .serverId("server-id") - .imageId("image-id") - .deviceNumber("device-number") - .build()); - assertRequestHasCommonProperties(server.takeRequest(), content); - assertNotNull(requestId); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void removeRomDriveFromServerTest() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/drives/drives-remove.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - DrivesApi api = pbApi.drivesApi(); - - String content = "<ws:removeRomDriveFromServer>" - + "<imageId>image-id</imageId>" - + "<serverId>server-id</serverId>" - + "</ws:removeRomDriveFromServer>"; - try { - String requestId = api.removeRomDriveFromServer("image-id", "server-id"); - assertRequestHasCommonProperties(server.takeRequest(), content); - assertNotNull(requestId); - } finally { - pbApi.close(); - server.shutdown(); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/93aff921/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiLiveTest.java ---------------------------------------------------------------------- diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiLiveTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiLiveTest.java deleted file mode 100644 index c5b63f2..0000000 --- a/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiLiveTest.java +++ /dev/null @@ -1,139 +0,0 @@ -/* - * 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.profitbricks.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.util.List; - -import org.jclouds.profitbricks.BaseProfitBricksLiveTest; -import org.jclouds.profitbricks.domain.DataCenter; -import org.jclouds.profitbricks.domain.Firewall; -import org.jclouds.profitbricks.domain.Nic; -import org.jclouds.profitbricks.domain.Firewall.Protocol; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; - - -@Test(groups = "live", testName = "FirewallApiLiveTest") -public class FirewallApiLiveTest extends BaseProfitBricksLiveTest { - - private DataCenter dataCenter; - private Nic nic; - - private Firewall createdFirewall; - - @BeforeClass - public void setupTest() { - dataCenter = findOrCreateDataCenter("firewallApiLiveTest" + System.currentTimeMillis()); - nic = findOrCreateNic(dataCenter); - } - - @Test - public void testAddFirewallRuleToNic() { - assertDataCenterAvailable(dataCenter); - Firewall firewall = api.firewallApi().addFirewallRuleToNic( - Firewall.Request.createAddRulePayload( - nic.id(), ImmutableList.of( - Firewall.Rule.builder() - .name("test-rule-tcp") - .protocol(Protocol.TCP) - .build() - ) - ) - ); - - assertNotNull(firewall); - assertFalse(firewall.rules().isEmpty()); - assertDataCenterAvailable(dataCenter); - - createdFirewall = firewall; - } - - @Test(dependsOnMethods = "testAddFirewallRuleToNic") - public void testGetAllFirewalls() { - List<Firewall> firewalls = api.firewallApi().getAllFirewalls(); - - assertNotNull(firewalls); - assertFalse(firewalls.isEmpty()); - } - - @Test(dependsOnMethods = "testAddFirewallRuleToNic") - public void testGetFirewall() { - Firewall firewall = api.firewallApi().getFirewall(createdFirewall.id()); - - assertNotNull(firewall); - assertEquals(createdFirewall.id(), firewall.id()); - } - - @Test(dependsOnMethods = "testAddFirewallRuleToNic") - public void testActivateFirewall() { - assertDataCenterAvailable(dataCenter); - boolean result = api.firewallApi().activateFirewall( - ImmutableList.of(createdFirewall.id())); - assertDataCenterAvailable(dataCenter); - assertTrue(result); - - Firewall firewall = api.firewallApi().getFirewall(createdFirewall.id()); - assertTrue(firewall.active(), "Firewall wasn't activated"); - } - - @Test(dependsOnMethods = "testActivateFirewall") - void testDeactivateFirewall() { - assertDataCenterAvailable(dataCenter); - boolean result = api.firewallApi().deactivateFirewall( - ImmutableList.of(createdFirewall.id())); - assertDataCenterAvailable(dataCenter); - assertTrue(result); - - Firewall firewall = api.firewallApi().getFirewall(createdFirewall.id()); - assertFalse(firewall.active(), "Firewall wasn't deactivated"); - } - - @Test(dependsOnMethods = "testDeactivateFirewall") - void testRemoveFirewallRule() { - assertDataCenterAvailable(dataCenter); - for (Firewall.Rule rule : createdFirewall.rules()) { - boolean result = api.firewallApi().removeFirewallRules( - ImmutableList.of(rule.id())); - - assertTrue(result); - assertDataCenterAvailable(dataCenter); - - } - Firewall firewall = api.firewallApi().getFirewall(createdFirewall.id()); - assertTrue(firewall.rules().isEmpty(), "Not all rules removed"); - } - - @Test(dependsOnMethods = "testRemoveFirewallRule") - public void testDeleteFirewall() { - assertDataCenterAvailable(dataCenter); - boolean result = api.firewallApi().deleteFirewall(ImmutableList.of(createdFirewall.id())); - assertTrue(result, "Created firewall was not deleted."); - } - - @AfterClass(alwaysRun = true) - public void cleanUp() { - destroyDataCenter(dataCenter); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/93aff921/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiMockTest.java ---------------------------------------------------------------------- diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiMockTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiMockTest.java deleted file mode 100644 index d9531cb..0000000 --- a/profitbricks/src/test/java/org/jclouds/profitbricks/features/FirewallApiMockTest.java +++ /dev/null @@ -1,324 +0,0 @@ -/* - * 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.profitbricks.features; - -import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; - -import java.util.List; - -import org.jclouds.profitbricks.ProfitBricksApi; -import org.jclouds.profitbricks.domain.Firewall; -import org.jclouds.profitbricks.domain.Firewall.Protocol; -import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; - -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; - -@Test(groups = "live", testName = "FirewallApiMockTest", singleThreaded = true) -public class FirewallApiMockTest extends BaseProfitBricksMockTest { - - @Test - public void testGetAllFirewalls() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewalls.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - - FirewallApi api = pbApi.firewallApi(); - - try { - List<Firewall> firewalls = api.getAllFirewalls(); - assertRequestHasCommonProperties(server.takeRequest(), "<ws:getAllFirewalls/>"); - assertNotNull(firewalls); - assertEquals(firewalls.size(), 2); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testGetFirewall() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - - FirewallApi api = pbApi.firewallApi(); - - String id = "firewall-id"; - String firewallruleid = "firewall-rule-id"; - - String content = "<ws:getFirewall><firewallId>" + id + "</firewallId></ws:getFirewall>"; - - try { - Firewall firewall = api.getFirewall(id); - assertRequestHasCommonProperties(server.takeRequest(), content); - assertNotNull(firewall); - assertEquals(firewall.id(), id); - assertFalse(firewall.rules().isEmpty()); - assertEquals(firewall.rules().get(0).id(), firewallruleid); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testGetNonExistingFirewall() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - FirewallApi api = pbApi.firewallApi(); - - String id = "firewall-id"; - - try { - Firewall firewall = api.getFirewall(id); - assertRequestHasCommonProperties(server.takeRequest()); - assertNull(firewall); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testAddFirewallRuleToNic() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-addtonic.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - FirewallApi api = pbApi.firewallApi(); - - String content = "<ws:addFirewallRulesToNic>" - + "<nicId>nic-id</nicId>" - + "<request>" - + "<name>name</name>" - + "<portRangeEnd>45678</portRangeEnd>" - + "<portRangeStart>12345</portRangeStart>" - + "<protocol>TCP</protocol>" - + "<sourceIp>192.168.0.1</sourceIp>" - + "<sourceMac>aa:bb:cc:dd:ee:ff</sourceMac>" - + "<targetIp>192.168.0.2</targetIp>" - + "</request>" - + "</ws:addFirewallRulesToNic>"; - try { - Firewall.Request.AddRulePayload payload = Firewall.Request.createAddRulePayload( - "nic-id", ImmutableList.of( - Firewall.Rule.builder() - .name("name") - .portRangeEnd(45678) - .portRangeStart(12345) - .protocol(Protocol.TCP) - .sourceIp("192.168.0.1") - .sourceMac("aa:bb:cc:dd:ee:ff") - .targetIp("192.168.0.2") - .build() - )); - Firewall response = api.addFirewallRuleToNic(payload); - - assertRequestHasCommonProperties(server.takeRequest(), content); - assertNotNull(response); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testRemoveFirewall() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-remove.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - FirewallApi api = pbApi.firewallApi(); - - String firewallId = "12345"; - String content = "<ws:removeFirewallRules>" - + "<firewallRuleIds>" + firewallId + "</firewallRuleIds>" - + "</ws:removeFirewallRules>"; - - try { - boolean result = api.removeFirewallRules(ImmutableList.of(firewallId)); - assertRequestHasCommonProperties(server.takeRequest(), content); - assertTrue(result); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testRemoveNonExitingFirewall() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - FirewallApi api = pbApi.firewallApi(); - - String firewallRuleId = "12345"; - - try { - boolean result = api.removeFirewallRules(ImmutableList.of(firewallRuleId)); - assertRequestHasCommonProperties(server.takeRequest()); - assertFalse(result); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testActivateFirewall() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-activate.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - FirewallApi api = pbApi.firewallApi(); - - String firewallId = "12345"; - String content = "<ws:activateFirewalls>" - + "<firewallIds>" + firewallId + "</firewallIds>" - + "</ws:activateFirewalls>"; - - try { - boolean result = api.activateFirewall(ImmutableList.of(firewallId)); - assertRequestHasCommonProperties(server.takeRequest(), content); - assertTrue(result); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testActivateNonExitingFirewall() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - FirewallApi api = pbApi.firewallApi(); - - String firewallId = "12345"; - - try { - boolean result = api.activateFirewall(ImmutableList.of(firewallId)); - assertRequestHasCommonProperties(server.takeRequest()); - assertFalse(result); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testDeactivateFirewall() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-deactivate.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - FirewallApi api = pbApi.firewallApi(); - - String firewallId = "12345"; - String content = "<ws:deactivateFirewalls>" - + "<firewallIds>" + firewallId + "</firewallIds>" - + "</ws:deactivateFirewalls>"; - - try { - boolean result = api.deactivateFirewall(ImmutableList.of(firewallId)); - assertRequestHasCommonProperties(server.takeRequest(), content); - assertTrue(result); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testDeactivateNonExitingFirewall() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - FirewallApi api = pbApi.firewallApi(); - - String firewallId = "12345"; - - try { - boolean result = api.deactivateFirewall(ImmutableList.of(firewallId)); - assertRequestHasCommonProperties(server.takeRequest()); - assertFalse(result); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testDeleteFirewall() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/firewall/firewall-delete.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - FirewallApi api = pbApi.firewallApi(); - - String firewallId = "12345"; - String content = "<ws:deleteFirewalls>" - + "<firewallIds>" + firewallId + "</firewallIds>" - + "</ws:deleteFirewalls>"; - - try { - boolean result = api.deleteFirewall(ImmutableList.of(firewallId)); - assertRequestHasCommonProperties(server.takeRequest(), content); - assertTrue(result); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testDeleteNonExitingFirewall() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - FirewallApi api = pbApi.firewallApi(); - - String firewallId = "12345"; - - try { - boolean result = api.deleteFirewall(ImmutableList.of(firewallId)); - assertRequestHasCommonProperties(server.takeRequest()); - assertFalse(result); - } finally { - pbApi.close(); - server.shutdown(); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/93aff921/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiLiveTest.java ---------------------------------------------------------------------- diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiLiveTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiLiveTest.java deleted file mode 100644 index b71cd8d..0000000 --- a/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiLiveTest.java +++ /dev/null @@ -1,62 +0,0 @@ -/* - * 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.profitbricks.features; - -import static org.testng.Assert.assertEquals; - -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; - -import java.util.List; - -import org.jclouds.profitbricks.BaseProfitBricksLiveTest; -import org.jclouds.profitbricks.domain.Image; -import org.testng.annotations.Test; - -import com.google.common.collect.Iterables; - -@Test(groups = "live", testName = "ImageApiLiveTest") -public class ImageApiLiveTest extends BaseProfitBricksLiveTest { - - private Image image; - - @Test - public void testGetAllImages() { - List<Image> images = api.imageApi().getAllImages(); - - assertNotNull(images); - assertFalse(images.isEmpty(), "No images found."); - - image = Iterables.getFirst(images, null); - assertNotNull(image); - } - - @Test(dependsOnMethods = "testGetAllImages") - public void testGetImage() { - Image fetchedImage = api.imageApi().getImage(image.id()); - - assertNotNull(fetchedImage); - assertEquals(fetchedImage, image); - } - - @Test - public void testGetNonExistingImage() { - String id = "random-non-existing-id"; - assertNull(api.imageApi().getImage(id), "Should've just returned null"); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/93aff921/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiMockTest.java ---------------------------------------------------------------------- diff --git a/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiMockTest.java b/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiMockTest.java deleted file mode 100644 index 6e97541..0000000 --- a/profitbricks/src/test/java/org/jclouds/profitbricks/features/ImageApiMockTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * 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.profitbricks.features; - -import com.squareup.okhttp.mockwebserver.MockResponse; -import com.squareup.okhttp.mockwebserver.MockWebServer; -import java.util.List; -import org.jclouds.profitbricks.ProfitBricksApi; -import org.jclouds.profitbricks.domain.Image; -import org.jclouds.profitbricks.internal.BaseProfitBricksMockTest; -import static org.jclouds.profitbricks.internal.BaseProfitBricksMockTest.mockWebServer; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; -import org.testng.annotations.Test; - -/** - * Mock tests for the {@link org.jclouds.profitbricks.features.ImageApi} class - */ -@Test(groups = "unit", testName = "ImageApiMockTest") -public class ImageApiMockTest extends BaseProfitBricksMockTest { - - @Test - public void testGetAllImages() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/image/images.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - ImageApi api = pbApi.imageApi(); - - try { - List<Image> images = api.getAllImages(); - assertRequestHasCommonProperties(server.takeRequest(), "<ws:getAllImages/>"); - assertNotNull(images); - assertTrue(images.size() == 7); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testGetAllImagesReturning404() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - ImageApi api = pbApi.imageApi(); - - try { - List<Image> images = api.getAllImages(); - assertRequestHasCommonProperties(server.takeRequest()); - assertTrue(images.isEmpty()); - } finally { - pbApi.close(); - server.shutdown(); - } - } - - @Test - public void testGetImage() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setBody(payloadFromResource("/image/image.xml"))); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - ImageApi api = pbApi.imageApi(); - - String id = "5ad99c9e-9166-11e4-9d74-52540066fee9"; - - String content = "<ws:getImage><imageId>" + id + "</imageId></ws:getImage>"; - try { - Image image = api.getImage(id); - assertRequestHasCommonProperties(server.takeRequest(), content); - assertNotNull(image); - assertEquals(image.id(), id); - } finally { - pbApi.close(); - server.shutdown(); - } - - } - - @Test - public void testGetNonExistingImage() throws Exception { - MockWebServer server = mockWebServer(); - server.enqueue(new MockResponse().setResponseCode(404)); - - ProfitBricksApi pbApi = api(server.getUrl(rootUrl)); - ImageApi api = pbApi.imageApi(); - - String id = "random-non-existing-id"; - try { - Image image = api.getImage(id); - assertRequestHasCommonProperties(server.takeRequest()); - assertNull(image); - } finally { - pbApi.close(); - server.shutdown(); - } - } -}
