Updated Branches: refs/heads/master 82fe701c7 -> dae2c67d7
http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/dae2c67d/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestAsyncClientTest.java ---------------------------------------------------------------------- diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestAsyncClientTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestAsyncClientTest.java deleted file mode 100644 index 4869658..0000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestAsyncClientTest.java +++ /dev/null @@ -1,175 +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.softlayer.features; - -import static org.jclouds.reflect.Reflection2.method; - -import java.io.IOException; - -import org.jclouds.Fallbacks.EmptySetOnNotFoundOr404; -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.Fallbacks.VoidOnNotFoundOr404; -import org.jclouds.http.functions.ParseJson; -import org.jclouds.http.functions.ReleasePayloadAndReturn; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.reflect.Invokable; -/** - * Tests annotation parsing of {@code VirtualGuestAsyncClient} - * - * @author Adrian Cole - */ -@Test(groups = "unit") -public class VirtualGuestAsyncClientTest extends BaseSoftLayerAsyncClientTest<VirtualGuestAsyncClient> { - - public void testListVirtualGuests() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(VirtualGuestAsyncClient.class, "listVirtualGuests"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals( - httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json?objectMask=virtualGuests.powerState%3BvirtualGuests.networkVlans%3BvirtualGuests.operatingSystem.passwords%3BvirtualGuests.datacenter%3BvirtualGuests.billingItem HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - // now make sure request filters apply by replaying - httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - - assertRequestLineEquals( - httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Account/VirtualGuests.json?objectMask=virtualGuests.powerState%3BvirtualGuests.networkVlans%3BvirtualGuests.operatingSystem.passwords%3BvirtualGuests.datacenter%3BvirtualGuests.billingItem HTTP/1.1"); - // for example, using basic authentication, we should get "only one" - // header - assertNonPayloadHeadersEqual(httpRequest, - "Accept: application/json\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ParseJson.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, EmptySetOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testGetVirtualGuest() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(VirtualGuestAsyncClient.class, "getVirtualGuest", long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234)); - - assertRequestLineEquals( - httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234.json?objectMask=powerState%3BnetworkVlans%3BoperatingSystem.passwords%3Bdatacenter%3BbillingItem HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ParseJson.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testRebootHardVirtualGuest() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(VirtualGuestAsyncClient.class, "rebootHardVirtualGuest", long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234)); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/rebootHard.json HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testPowerOffVirtualGuest() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(VirtualGuestAsyncClient.class, "powerOffVirtualGuest", long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234)); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/powerOff.json HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testPowerOnVirtualGuest() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(VirtualGuestAsyncClient.class, "powerOnVirtualGuest", long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234)); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/powerOn.json HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testPauseVirtualGuest() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(VirtualGuestAsyncClient.class, "pauseVirtualGuest", long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234)); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/pause.json HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testResumeVirtualGuest() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(VirtualGuestAsyncClient.class, "resumeVirtualGuest", long.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(1234)); - - assertRequestLineEquals(httpRequest, - "GET https://api.softlayer.com/rest/v3/SoftLayer_Virtual_Guest/1234/resume.json HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: application/json\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } -} http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/dae2c67d/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientExpectTest.java ---------------------------------------------------------------------- diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientExpectTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientExpectTest.java deleted file mode 100644 index 45a3fa8..0000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientExpectTest.java +++ /dev/null @@ -1,58 +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.softlayer.features; - -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.rest.internal.BaseRestClientExpectTest; -import org.jclouds.softlayer.SoftLayerClient; -import org.testng.annotations.Test; - -/** - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "SoftLayerClientExpectTest") -public class VirtualGuestClientExpectTest extends BaseRestClientExpectTest<SoftLayerClient> { - - - public VirtualGuestClientExpectTest() { - provider = "softlayer"; - } - - public void testCancelGuestReturnsTrueOn200AndFalseOn404() { - - HttpRequest cancelGuest11 = HttpRequest.builder().method("GET") - .endpoint("https://api.softlayer.com/rest/v3/SoftLayer_Billing_Item/11/cancelService.json") - .addHeader("Accept", "application/json") - .addHeader("Authorization", "Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==").build(); - - HttpResponse found = HttpResponse.builder().statusCode(200).build(); - - SoftLayerClient clientWhenServiceExists = requestSendsResponse(cancelGuest11, found); - - assert clientWhenServiceExists.getVirtualGuestClient().cancelService(11l); - - - HttpResponse notFound = HttpResponse.builder().statusCode(404).build(); - - SoftLayerClient clientWhenServiceDoesntExist = requestSendsResponse(cancelGuest11, notFound); - - assert !clientWhenServiceDoesntExist.getVirtualGuestClient().cancelService(11l); - - } -} http://git-wip-us.apache.org/repos/asf/incubator-jclouds/blob/dae2c67d/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientLiveTest.java ---------------------------------------------------------------------- diff --git a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientLiveTest.java b/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientLiveTest.java deleted file mode 100644 index ad9a4fb..0000000 --- a/providers/softlayer/src/test/java/org/jclouds/softlayer/features/VirtualGuestClientLiveTest.java +++ /dev/null @@ -1,169 +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.softlayer.features; - -import static org.jclouds.softlayer.predicates.ProductItemPredicates.capacity; -import static org.jclouds.softlayer.predicates.ProductItemPredicates.categoryCode; -import static org.jclouds.softlayer.predicates.ProductItemPredicates.units; -import static org.jclouds.softlayer.predicates.ProductPackagePredicates.named; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.util.Map; -import java.util.Properties; -import java.util.Random; -import java.util.Set; - -import org.jclouds.softlayer.SoftLayerClient; -import org.jclouds.softlayer.compute.functions.ProductItems; -import org.jclouds.softlayer.domain.ProductItem; -import org.jclouds.softlayer.domain.ProductItemPrice; -import org.jclouds.softlayer.domain.ProductOrder; -import org.jclouds.softlayer.domain.ProductOrderReceipt; -import org.jclouds.softlayer.domain.ProductPackage; -import org.jclouds.softlayer.domain.VirtualGuest; -import org.testng.annotations.Test; - -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableSet; -import com.google.common.collect.ImmutableSet.Builder; -import com.google.common.collect.Iterables; -import com.google.common.collect.Maps; -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.Module; -import com.google.inject.TypeLiteral; - -/** - * Tests behavior of {@code VirtualGuestClient} - * - * @author Adrian Cole - */ -@Test(groups = "live") -public class VirtualGuestClientLiveTest extends BaseSoftLayerClientLiveTest { - - private static final String TEST_HOSTNAME_PREFIX = "livetest"; - - @Test - public void testListVirtualGuests() throws Exception { - Set<VirtualGuest> response = api().listVirtualGuests(); - assert null != response; - assertTrue(response.size() >= 0); - for (VirtualGuest vg : response) { - VirtualGuest newDetails = api().getVirtualGuest(vg.getId()); - assertEquals(vg.getId(), newDetails.getId()); - checkVirtualGuest(vg); - } - } - - @Test(enabled = false, groups = "live") - public void testCancelAndPlaceOrder() { - - // This method was not working needs testing out. - - // TODO: Should also check if there are active transactions before trying to cancel. - // objectMask: virtualGuests.activeTransaction - for (VirtualGuest guest : api().listVirtualGuests()) { - if (guest.getHostname().startsWith(TEST_HOSTNAME_PREFIX)) { - if (guest.getBillingItemId() != -1) { - api().cancelService(guest.getBillingItemId()); - } - } - } - - int pkgId = Iterables.find(api.getAccountClient().getActivePackages(), - named(ProductPackageClientLiveTest.CLOUD_SERVER_PACKAGE_NAME)).getId(); - ProductPackage productPackage = api.getProductPackageClient().getProductPackage(pkgId); - - Iterable<ProductItem> ramItems = Iterables.filter(productPackage.getItems(), Predicates.and(categoryCode("ram"), - capacity(2.0f))); - - Map<Float, ProductItem> ramToProductItem = Maps.uniqueIndex(ramItems, ProductItems.capacity()); - - ProductItemPrice ramPrice = ProductItems.price().apply(ramToProductItem.get(2.0f)); - - Iterable<ProductItem> cpuItems = Iterables.filter(productPackage.getItems(), Predicates.and( - units("PRIVATE_CORE"), capacity(2.0f))); - Map<Float, ProductItem> coresToProductItem = Maps.uniqueIndex(cpuItems, ProductItems.capacity()); - - ProductItemPrice cpuPrice = ProductItems.price().apply(coresToProductItem.get(2.0f)); - - Iterable<ProductItem> operatingSystems = Iterables.filter(productPackage.getItems(), categoryCode("os")); - Map<String, ProductItem> osToProductItem = Maps.uniqueIndex(operatingSystems, ProductItems.description()); - ProductItemPrice osPrice = ProductItems.price().apply( - osToProductItem.get("Ubuntu Linux 8 LTS Hardy Heron - Minimal Install (64 bit)")); - - Builder<ProductItemPrice> prices = ImmutableSet.builder(); - prices.addAll(defaultPrices); - prices.add(ramPrice); - prices.add(cpuPrice); - prices.add(osPrice); - - VirtualGuest guest = VirtualGuest.builder().domain("jclouds.org").hostname( - TEST_HOSTNAME_PREFIX + new Random().nextInt()).build(); - - ProductOrder order = ProductOrder.builder().packageId(pkgId).quantity(1).useHourlyPricing(true).prices( - prices.build()).virtualGuests(guest).build(); - - ProductOrderReceipt receipt = api().orderVirtualGuest(order); - ProductOrder order2 = receipt.getOrderDetails(); - VirtualGuest result = Iterables.get(order2.getVirtualGuests(), 0); - - ProductOrder order3 = api().getOrderTemplate(result.getId()); - - assertEquals(order.getPrices(), order3.getPrices()); - assertNotNull(receipt); - } - - private Iterable<ProductItemPrice> defaultPrices; - - @Override - protected SoftLayerClient create(Properties props, Iterable<Module> modules) { - Injector injector = newBuilder().modules(modules).overrides(props).buildInjector(); - defaultPrices = injector.getInstance(Key.get(new TypeLiteral<Iterable<ProductItemPrice>>() { - })); - return injector.getInstance(SoftLayerClient.class); - } - - private VirtualGuestClient api() { - return api.getVirtualGuestClient(); - } - - private void checkVirtualGuest(VirtualGuest vg) { - if (vg.getBillingItemId() == -1) - return;// Quotes and shutting down guests - - assert vg.getAccountId() > 0 : vg; - assert vg.getCreateDate() != null : vg; - assert vg.getDomain() != null : vg; - assert vg.getFullyQualifiedDomainName() != null : vg; - assert vg.getHostname() != null : vg; - assert vg.getId() > 0 : vg; - assert vg.getMaxCpu() > 0 : vg; - assert vg.getMaxCpuUnits() != null : vg; - assert vg.getMaxMemory() > 0 : vg; - assert vg.getMetricPollDate() != null : vg; - assert vg.getModifyDate() != null : vg; - assert vg.getStartCpus() > 0 : vg; - assert vg.getStatusId() >= 0 : vg; - assert vg.getUuid() != null : vg; - assert vg.getPrimaryBackendIpAddress() != null : vg; - assert vg.getPrimaryIpAddress() != null : vg; - } - -}
