http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java b/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java deleted file mode 100644 index c7f455d..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/environment/InfrastructureTestEnvironment.java +++ /dev/null @@ -1,493 +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.abiquo.environment; - -import static com.google.common.collect.Iterables.find; -import static com.google.common.collect.Iterables.size; -import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; - -import java.io.IOException; -import java.net.URI; -import java.net.URL; -import java.nio.charset.Charset; -import java.util.UUID; - -import org.jclouds.abiquo.AbiquoContext; -import org.jclouds.abiquo.domain.config.License; -import org.jclouds.abiquo.domain.enterprise.Enterprise; -import org.jclouds.abiquo.domain.enterprise.Limits; -import org.jclouds.abiquo.domain.enterprise.Role; -import org.jclouds.abiquo.domain.enterprise.User; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.abiquo.domain.infrastructure.Datastore; -import org.jclouds.abiquo.domain.infrastructure.Machine; -import org.jclouds.abiquo.domain.infrastructure.NetworkInterface; -import org.jclouds.abiquo.domain.infrastructure.Rack; -import org.jclouds.abiquo.domain.infrastructure.RemoteService; -import org.jclouds.abiquo.domain.infrastructure.StorageDevice; -import org.jclouds.abiquo.domain.infrastructure.StorageDeviceMetadata; -import org.jclouds.abiquo.domain.infrastructure.StoragePool; -import org.jclouds.abiquo.domain.infrastructure.Tier; -import org.jclouds.abiquo.domain.network.ExternalNetwork; -import org.jclouds.abiquo.domain.network.NetworkServiceType; -import org.jclouds.abiquo.domain.network.PublicNetwork; -import org.jclouds.abiquo.domain.network.UnmanagedNetwork; -import org.jclouds.abiquo.features.AdminApi; -import org.jclouds.abiquo.features.ConfigApi; -import org.jclouds.abiquo.features.EnterpriseApi; -import org.jclouds.abiquo.features.InfrastructureApi; -import org.jclouds.abiquo.features.services.AdministrationService; -import org.jclouds.abiquo.util.Config; - -import com.abiquo.model.enumerator.HypervisorType; -import com.google.common.base.Predicate; -import com.google.common.io.LineProcessor; -import com.google.common.io.Resources; - -/** - * Test environment for infrastructure live tests. - */ -public class InfrastructureTestEnvironment implements TestEnvironment { - /** The rest context. */ - public AbiquoContext context; - - // Environment data made public so tests can use them easily - - public AdministrationService administrationService; - - public InfrastructureApi infrastructureApi; - - public EnterpriseApi enterpriseApi; - - public AdminApi adminApi; - - public ConfigApi configApi; - - // Resources - - public License license; - - public Datacenter datacenter; - - public PublicNetwork publicNetwork; - - public ExternalNetwork externalNetwork; - - public UnmanagedNetwork unmanagedNetwork; - - public Iterable<RemoteService> remoteServices; - - public Rack rack; - - public Machine machine; - - public Enterprise enterprise; - - public StorageDevice storageDevice; - - public StoragePool storagePool; - - public Tier tier; - - public User user; - - public User enterpriseAdmin; - - public Role role; - - public Role anotherRole; - - public InfrastructureTestEnvironment(final AbiquoContext context) { - super(); - this.context = context; - this.administrationService = context.getAdministrationService(); - this.context = context; - this.enterpriseApi = context.getApiContext().getApi().getEnterpriseApi(); - this.infrastructureApi = context.getApiContext().getApi().getInfrastructureApi(); - this.adminApi = context.getApiContext().getApi().getAdminApi(); - this.configApi = context.getApiContext().getApi().getConfigApi(); - } - - @Override - public void setup() throws Exception { - // Configuration - createLicense(); - - // Intrastructure - createDatacenter(); - createRack(); - createMachine(); - createStorageDevice(); - createStoragePool(); - createPublicNetwork(); - - // Enterprise - createEnterprise(); - createRoles(); - createUsers(); - - // Networking - createExternalNetwork(); - createUnmanagedNetwork(); - } - - @Override - public void tearDown() throws Exception { - deleteUsers(); - - deleteRole(role); - deleteRole(anotherRole); - - deleteUnmanagedNetwork(); - deleteExternalNetwork(); - deletePublicNetwork(); - deleteStoragePool(); - deleteStorageDevice(); - deleteMachine(); - deleteRack(); - deleteDatacenter(); - deleteEnterprise(); - - deleteLicense(); - } - - // Setup - - protected void createLicense() throws IOException { - license = License.builder(context.getApiContext(), readLicense()).build(); - - license.add(); - assertNotNull(license.getId()); - } - - protected void createDatacenter() { - // Assume a monolithic install - URI endpoint = URI.create(context.getApiContext().getProviderMetadata().getEndpoint()); - String remoteServicesAddress = endpoint.getHost(); - - datacenter = Datacenter.builder(context.getApiContext()).name(randomName()).location("Honolulu") - .remoteServices(remoteServicesAddress).build(); - datacenter.save(); - assertNotNull(datacenter.getId()); - - remoteServices = datacenter.listRemoteServices(); - assertEquals(size(remoteServices), 7); - } - - protected void createMachine() { - String ip = Config.get("abiquo.hypervisor.address"); - HypervisorType type = HypervisorType.valueOf(Config.get("abiquo.hypervisor.type")); - String user = Config.get("abiquo.hypervisor.user"); - String pass = Config.get("abiquo.hypervisor.pass"); - final String vswitchName = Config.get("abiquo.hypervisor.vswitch"); - final String datastoreName = Config.get("abiquo.hypervisor.datastore"); - - machine = datacenter.discoverSingleMachine(ip, type, user, pass); - - NetworkServiceType nst = datacenter.defaultNetworkServiceType(); - NetworkInterface vswitch = find(machine.getNetworkInterfaces(), new Predicate<NetworkInterface>() { - @Override - public boolean apply(NetworkInterface input) { - return input.getName().equals(vswitchName); - } - }); - vswitch.setNetworkServiceType(nst); - - Datastore datastore = find(machine.getDatastores(), new Predicate<Datastore>() { - @Override - public boolean apply(Datastore input) { - return input.getName().equals(datastoreName); - } - }); - datastore.setEnabled(true); - - machine.setRack(rack); - machine.save(); - assertNotNull(machine.getId()); - } - - protected void createRack() { - rack = Rack.builder(context.getApiContext(), datacenter).name(PREFIX + "Aloha").build(); - rack.save(); - assertNotNull(rack.getId()); - } - - protected void createStorageDevice() { - String ip = Config.get("abiquo.storage.address"); - final String type = Config.get("abiquo.storage.type"); - String user = Config.get("abiquo.storage.user"); - String pass = Config.get("abiquo.storage.pass"); - - Iterable<StorageDeviceMetadata> devices = datacenter.listSupportedStorageDevices(); - StorageDeviceMetadata metadata = find(devices, new Predicate<StorageDeviceMetadata>() { - @Override - public boolean apply(StorageDeviceMetadata input) { - return input.getType().equals(type); - } - }); - - storageDevice = StorageDevice.builder(context.getApiContext(), datacenter) // - .name(PREFIX + "Storage Device")// - .type(type)// - .managementIp(ip).managementPort(metadata.getDefaultManagementPort())// - .iscsiIp(ip).iscsiPort(metadata.getDefaultIscsiPort()) // - .username(user)// - .password(pass) // - .build(); - - storageDevice.save(); - assertNotNull(storageDevice.getId()); - } - - protected void createStoragePool() { - final String pool = Config.get("abiquo.storage.pool"); - - storagePool = find(storageDevice.listRemoteStoragePools(), new Predicate<StoragePool>() { - @Override - public boolean apply(StoragePool input) { - return input.getName().equals(pool); - } - }); - tier = find(datacenter.listTiers(), new Predicate<Tier>() { - @Override - public boolean apply(Tier input) { - return input.getName().equals("Default Tier 1"); - } - }); - - storagePool.setTier(tier); - storagePool.save(); - - assertNotNull(storagePool.getUUID()); - } - - protected void createUsers() { - Iterable<Role> roles = administrationService.listRoles(); - Role userRole = find(roles, role("USER")); - Role enterpriseAdminRole = find(roles, role("ENTERPRISE_ADMIN")); - - user = User.builder(context.getApiContext(), enterprise, userRole).name(randomName(), randomName()) - .nick("jclouds").authType("ABIQUO").description(randomName()).email(randomName() + "@abiquo.com") - .locale("en_US").password("user").build(); - - user.save(); - assertNotNull(user.getId()); - assertEquals(userRole.getId(), user.getRole().getId()); - - enterpriseAdmin = User.builder(context.getApiContext(), enterprise, enterpriseAdminRole) - .name(randomName(), randomName()).nick("jclouds-admin").authType("ABIQUO").description(randomName()) - .email(randomName() + "@abiquo.com").locale("en_US").password("admin").build(); - - enterpriseAdmin.save(); - assertNotNull(enterpriseAdmin.getId()); - assertEquals(enterpriseAdminRole.getId(), enterpriseAdmin.getRole().getId()); - } - - protected void createRoles() { - role = Role.builder(context.getApiContext()).name(randomName()).blocked(false).build(); - role.save(); - - anotherRole = Role.Builder.fromRole(role).build(); - anotherRole.setName("Another role"); - anotherRole.save(); - - assertNotNull(role.getId()); - assertNotNull(anotherRole.getId()); - } - - protected void createEnterprise() { - enterprise = Enterprise.builder(context.getApiContext()).name(randomName()).build(); - enterprise.save(); - assertNotNull(enterprise.getId()); - Limits limits = enterprise.allowDatacenter(datacenter); - assertNotNull(limits); - } - - protected void createPublicNetwork() { - publicNetwork = PublicNetwork.builder(context.getApiContext(), datacenter).name("PublicNetwork") - .gateway("80.80.80.1").address("80.80.80.0").mask(24).tag(5).build(); - publicNetwork.save(); - assertNotNull(publicNetwork.getId()); - } - - protected void createExternalNetwork() { - externalNetwork = ExternalNetwork.builder(context.getApiContext(), datacenter, enterprise) - .name("ExternalNetwork").gateway("10.0.0.1").address("10.0.0.0").mask(24).tag(7).build(); - externalNetwork.save(); - assertNotNull(externalNetwork.getId()); - } - - protected void createUnmanagedNetwork() { - unmanagedNetwork = UnmanagedNetwork.builder(context.getApiContext(), datacenter, enterprise) - .name("UnmanagedNetwork").gateway("10.0.1.1").address("10.0.1.0").mask(24).tag(8).build(); - unmanagedNetwork.save(); - assertNotNull(unmanagedNetwork.getId()); - } - - // Tear down - - protected void deleteUnmanagedNetwork() { - if (unmanagedNetwork != null) { - Integer id = unmanagedNetwork.getId(); - unmanagedNetwork.delete(); - assertNull(datacenter.getNetwork(id)); - } - } - - protected void deleteExternalNetwork() { - if (externalNetwork != null) { - Integer id = externalNetwork.getId(); - externalNetwork.delete(); - assertNull(datacenter.getNetwork(id)); - } - } - - protected void deletePublicNetwork() { - if (publicNetwork != null) { - Integer id = publicNetwork.getId(); - publicNetwork.delete(); - assertNull(datacenter.getNetwork(id)); - } - } - - protected void deleteUsers() { - if (user != null) { - String nick = user.getNick(); - user.delete(); - // Nick is unique in an enterprise - assertNull(find(enterprise.listUsers(), nick(nick), null)); - } - - if (enterpriseAdmin != null) { - String nick = enterpriseAdmin.getNick(); - enterpriseAdmin.delete(); - // Nick is unique in an enterprise - assertNull(find(enterprise.listUsers(), nick(nick), null)); - } - } - - protected void deleteRole(final Role role) { - if (role != null) { - Integer roleId = role.getId(); - role.delete(); - assertNull(adminApi.getRole(roleId)); - } - } - - protected void deleteStoragePool() { - if (storagePool != null) { - String idStoragePool = storagePool.getUUID(); - storagePool.delete(); - assertNull(infrastructureApi.getStoragePool(storageDevice.unwrap(), idStoragePool)); - } - - } - - protected void deleteStorageDevice() { - if (storageDevice != null) { - Integer idStorageDevice = storageDevice.getId(); - storageDevice.delete(); - assertNull(infrastructureApi.getStorageDevice(datacenter.unwrap(), idStorageDevice)); - } - } - - protected void deleteMachine() { - if (machine != null && rack != null) { - Integer idMachine = machine.getId(); - machine.delete(); - assertNull(infrastructureApi.getMachine(rack.unwrap(), idMachine)); - } - } - - protected void deleteRack() { - if (rack != null && datacenter != null) { - Integer idRack = rack.getId(); - rack.delete(); - assertNull(infrastructureApi.getRack(datacenter.unwrap(), idRack)); - } - } - - protected void deleteDatacenter() { - if (datacenter != null) { - // Remove limits first - enterprise.prohibitDatacenter(datacenter); - - Integer idDatacenter = datacenter.getId(); - datacenter.delete(); // Abiquo API will delete remote services too - assertNull(infrastructureApi.getDatacenter(idDatacenter)); - } - } - - protected void deleteEnterprise() { - if (enterprise != null) { - Integer idEnterprise = enterprise.getId(); - enterprise.delete(); - assertNull(enterpriseApi.getEnterprise(idEnterprise)); - } - } - - protected void deleteLicense() { - license.remove(); - } - - protected static String randomName() { - return PREFIX + UUID.randomUUID().toString().substring(0, 12); - } - - // Utility methods - - public static String readLicense() throws IOException { - URL url = CloudTestEnvironment.class.getResource("/license/expired"); - return Resources.readLines(url, Charset.defaultCharset(), new LineProcessor<String>() { - StringBuilder sb = new StringBuilder(); - - @Override - public String getResult() { - return sb.toString(); - } - - @Override - public boolean processLine(String line) throws IOException { - if (!line.startsWith("#")) { - sb.append(line); - } - return true; - } - }); - } - - private static Predicate<Role> role(final String role) { - return new Predicate<Role>() { - @Override - public boolean apply(Role input) { - return input.getName().equals(role); - } - }; - } - - private static Predicate<User> nick(final String nick) { - return new Predicate<User>() { - @Override - public boolean apply(User input) { - return input.getNick().equals(nick); - } - }; - } -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/environment/TestEnvironment.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/environment/TestEnvironment.java b/abiquo/src/test/java/org/jclouds/abiquo/environment/TestEnvironment.java deleted file mode 100644 index eb165b1..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/environment/TestEnvironment.java +++ /dev/null @@ -1,35 +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.abiquo.environment; - -/** - * Base class fot test environment populators. - * <p> - * This class should be used to populate and clean the test environment used in - * live tests. - */ -public interface TestEnvironment { - /** - * Builds the test environment. - */ - void setup() throws Exception; - - /** - * Cleans the test environment. - */ - void tearDown() throws Exception; -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/AppendApiVersionToAbiquoMimeTypeTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/AppendApiVersionToAbiquoMimeTypeTest.java b/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/AppendApiVersionToAbiquoMimeTypeTest.java deleted file mode 100644 index 141d220..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/AppendApiVersionToAbiquoMimeTypeTest.java +++ /dev/null @@ -1,60 +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.abiquo.fallbacks; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.functions.AppendApiVersionToAbiquoMimeType; -import org.testng.annotations.Test; - -import com.google.common.base.Function; - -/** - * Unit tests for the {@link AppendApiVersionToAbiquoMimeType} function. - */ -@Test(groups = "unit", testName = "AppendApiVersionToAbiquoMimeTypeTest") -public class AppendApiVersionToAbiquoMimeTypeTest { - @Test(expectedExceptions = NullPointerException.class) - public void testApplyWithNullInput() { - Function<String, String> function = new AppendApiVersionToAbiquoMimeType(AbiquoApi.API_VERSION); - function.apply(null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testApplyWithInvalidMediaType() { - Function<String, String> function = new AppendApiVersionToAbiquoMimeType(AbiquoApi.API_VERSION); - function.apply("foo"); - } - - public void testApplyToStandardMediaType() { - Function<String, String> function = new AppendApiVersionToAbiquoMimeType(AbiquoApi.API_VERSION); - assertEquals(function.apply("application/xml"), "application/xml"); - } - - public void testApplyToAbiquoMediaTypeWithVersion() { - Function<String, String> function = new AppendApiVersionToAbiquoMimeType(AbiquoApi.API_VERSION); - assertEquals(function.apply("application/vnd.abiquo.datacenters+xml;version=1.8.5"), - "application/vnd.abiquo.datacenters+xml;version=1.8.5"); - } - - public void testApplyToAbiquoMediaTypeWithoutVersion() { - Function<String, String> function = new AppendApiVersionToAbiquoMimeType(AbiquoApi.API_VERSION); - assertEquals(function.apply("application/vnd.abiquo.datacenters+xml"), - "application/vnd.abiquo.datacenters+xml;version=" + AbiquoApi.API_VERSION); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/FalseIfNotAvailableTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/FalseIfNotAvailableTest.java b/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/FalseIfNotAvailableTest.java deleted file mode 100644 index 8566e0d..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/FalseIfNotAvailableTest.java +++ /dev/null @@ -1,105 +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.abiquo.fallbacks; - -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; - -import org.easymock.EasyMock; -import org.jclouds.abiquo.AbiquoFallbacks.FalseIfNotAvailable; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpResponseException; -import org.jclouds.rest.ResourceNotFoundException; -import org.testng.annotations.Test; - -/** - * Unit tests for the {@link FalseIfNotAvailable} function. - */ -@Test(groups = "unit", testName = "FalseIfNotAvailableTest") -public class FalseIfNotAvailableTest { - public void testOriginalExceptionIfUnknownException() { - FalseIfNotAvailable function = new FalseIfNotAvailable(); - RuntimeException exception = new RuntimeException(); - - try { - function.createOrPropagate(exception); - } catch (Exception ex) { - assertEquals(ex, exception); - } - } - - public void testFalseIf5xx() throws Exception { - FalseIfNotAvailable function = new FalseIfNotAvailable(); - HttpResponse response = EasyMock.createMock(HttpResponse.class); - HttpResponseException exception = EasyMock.createMock(HttpResponseException.class); - - // Status code is called twice - expect(response.getStatusCode()).andReturn(503); - expect(response.getStatusCode()).andReturn(503); - // Get response gets called twice - expect(exception.getResponse()).andReturn(response); - expect(exception.getResponse()).andReturn(response); - // Get cause is called to determine the root cause - expect(exception.getCause()).andReturn(null); - - replay(response); - replay(exception); - - assertFalse(function.createOrPropagate(exception)); - - verify(response); - verify(exception); - } - - public void testExceptionIfNot5xx() { - FalseIfNotAvailable function = new FalseIfNotAvailable(); - HttpResponse response = EasyMock.createMock(HttpResponse.class); - HttpResponseException exception = EasyMock.createMock(HttpResponseException.class); - - // Status code is called twice - expect(response.getStatusCode()).andReturn(600); - expect(response.getStatusCode()).andReturn(600); - // Get response gets called twice - expect(exception.getResponse()).andReturn(response); - expect(exception.getResponse()).andReturn(response); - // Get cause is called to determine the root cause - expect(exception.getCause()).andReturn(null); - - replay(response); - replay(exception); - - try { - function.createOrPropagate(exception); - } catch (Exception ex) { - assertEquals(ex, exception); - } - - verify(response); - verify(exception); - } - - public void testFalseIfResourceNotFound() throws Exception { - FalseIfNotAvailable function = new FalseIfNotAvailable(); - ResourceNotFoundException exception = new ResourceNotFoundException(); - - assertFalse(function.createOrPropagate(exception)); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/FalseOn5xxTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/FalseOn5xxTest.java b/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/FalseOn5xxTest.java deleted file mode 100644 index 111cfeb..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/FalseOn5xxTest.java +++ /dev/null @@ -1,96 +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.abiquo.fallbacks; - -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; - -import org.easymock.EasyMock; -import org.jclouds.abiquo.AbiquoFallbacks.FalseOn5xx; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpResponseException; -import org.testng.annotations.Test; - -/** - * Unit tests for the {@link FalseOn5xx} function. - */ -@Test(groups = "unit", testName = "FalseOn5xxTest") -public class FalseOn5xxTest { - public void testOriginalExceptionIfNotHttpResponseException() { - FalseOn5xx function = new FalseOn5xx(); - RuntimeException exception = new RuntimeException(); - - try { - function.createOrPropagate(exception); - } catch (Exception ex) { - assertEquals(ex, exception); - } - } - - public void testFalseIf5xx() throws Exception { - FalseOn5xx function = new FalseOn5xx(); - HttpResponse response = EasyMock.createMock(HttpResponse.class); - HttpResponseException exception = EasyMock.createMock(HttpResponseException.class); - - // Status code is called twice - expect(response.getStatusCode()).andReturn(503); - expect(response.getStatusCode()).andReturn(503); - // Get response gets called twice - expect(exception.getResponse()).andReturn(response); - expect(exception.getResponse()).andReturn(response); - // Get cause is called to determine the root cause - expect(exception.getCause()).andReturn(null); - - replay(response); - replay(exception); - - assertFalse(function.createOrPropagate(exception)); - - verify(response); - verify(exception); - } - - public void testExceptionIfNot5xx() { - FalseOn5xx function = new FalseOn5xx(); - HttpResponse response = EasyMock.createMock(HttpResponse.class); - HttpResponseException exception = EasyMock.createMock(HttpResponseException.class); - - // Status code is called twice - expect(response.getStatusCode()).andReturn(600); - expect(response.getStatusCode()).andReturn(600); - // Get response gets called twice - expect(exception.getResponse()).andReturn(response); - expect(exception.getResponse()).andReturn(response); - // Get cause is called to determine the root cause - expect(exception.getCause()).andReturn(null); - - replay(response); - replay(exception); - - try { - function.createOrPropagate(exception); - } catch (Exception ex) { - assertEquals(ex, exception); - } - - verify(response); - verify(exception); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/MovedVolumeTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/MovedVolumeTest.java b/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/MovedVolumeTest.java deleted file mode 100644 index 8d372fa..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/MovedVolumeTest.java +++ /dev/null @@ -1,93 +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.abiquo.fallbacks; - -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.testng.Assert.assertEquals; - -import javax.ws.rs.core.Response.Status; - -import org.easymock.EasyMock; -import org.jclouds.abiquo.fallbacks.MovedVolume.ReturnMoveVolumeReference; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpResponseException; -import org.jclouds.io.Payload; -import org.jclouds.io.Payloads; -import org.jclouds.xml.internal.JAXBParser; -import org.testng.annotations.Test; - -import com.abiquo.server.core.infrastructure.storage.MovedVolumeDto; -import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; -import com.google.common.io.ByteSource; -import com.google.inject.TypeLiteral; - -/** - * Unit tests for the {@link MovedVolume} function. - */ -@Test(groups = "unit", testName = "MovedVolumeTest") -public class MovedVolumeTest { - public void testReturnOriginalExceptionIfNotHttpResponseException() { - MovedVolume function = new MovedVolume(new ReturnMoveVolumeReference(new JAXBParser("false"), - TypeLiteral.get(MovedVolumeDto.class))); - - RuntimeException exception = new RuntimeException(); - - try { - function.createOrPropagate(exception); - } catch (Exception ex) { - assertEquals(ex, exception); - } - } - - public void testReturnVolume() throws Exception { - JAXBParser xmlParser = new JAXBParser("false"); - MovedVolume function = new MovedVolume(new ReturnMoveVolumeReference(new JAXBParser("false"), - TypeLiteral.get(MovedVolumeDto.class))); - - VolumeManagementDto volume = new VolumeManagementDto(); - volume.setName("Test volume"); - MovedVolumeDto movedRef = new MovedVolumeDto(); - movedRef.setVolume(volume); - - HttpResponse response = EasyMock.createMock(HttpResponse.class); - HttpResponseException exception = EasyMock.createMock(HttpResponseException.class); - Payload payload = Payloads.newByteSourcePayload(ByteSource.wrap(xmlParser.toXML(movedRef).getBytes())); - - // Status code is called once - expect(response.getStatusCode()).andReturn(Status.MOVED_PERMANENTLY.getStatusCode()); - // Get response gets called twice - expect(exception.getResponse()).andReturn(response); - expect(exception.getResponse()).andReturn(response); - // Get payload is called three times: one to deserialize it, and twice to - // release it - expect(response.getPayload()).andReturn(payload); - expect(response.getPayload()).andReturn(payload); - expect(response.getPayload()).andReturn(payload); - // Get cause is called to determine the root cause - expect(exception.getCause()).andReturn(null); - - replay(response); - replay(exception); - - function.createOrPropagate(exception); - - verify(response); - verify(exception); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/NullOn303Test.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/NullOn303Test.java b/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/NullOn303Test.java deleted file mode 100644 index 6e6cda0..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/NullOn303Test.java +++ /dev/null @@ -1,94 +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.abiquo.fallbacks; - -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; - -import org.easymock.EasyMock; -import org.jclouds.abiquo.AbiquoFallbacks.NullOn303; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpResponseException; -import org.testng.annotations.Test; - -/** - * Unit tests for the {@link NullOn303} function. - */ -@Test(groups = "unit", testName = "NullOn303Test") -public class NullOn303Test { - public void testOriginalExceptionIfNotHttpResponseException() { - NullOn303 function = new NullOn303(); - RuntimeException exception = new RuntimeException(); - - try { - function.createOrPropagate(exception); - } catch (Exception ex) { - assertEquals(ex, exception); - } - } - - public void testNullIf303() throws Exception { - NullOn303 function = new NullOn303(); - HttpResponse response = EasyMock.createMock(HttpResponse.class); - HttpResponseException exception = EasyMock.createMock(HttpResponseException.class); - - // Status code is called once - expect(response.getStatusCode()).andReturn(303); - // Get response gets called twice - expect(exception.getResponse()).andReturn(response); - expect(exception.getResponse()).andReturn(response); - // Get cause is called to determine the root cause - expect(exception.getCause()).andReturn(null); - - replay(response); - replay(exception); - - assertNull(function.createOrPropagate(exception)); - - verify(response); - verify(exception); - } - - public void testExceptionIfNot303() { - NullOn303 function = new NullOn303(); - HttpResponse response = EasyMock.createMock(HttpResponse.class); - HttpResponseException exception = EasyMock.createMock(HttpResponseException.class); - - // Status code is called once - expect(response.getStatusCode()).andReturn(600); - // Get response gets called twice - expect(exception.getResponse()).andReturn(response); - expect(exception.getResponse()).andReturn(response); - // Get cause is called to determine the root cause - expect(exception.getCause()).andReturn(null); - - replay(response); - replay(exception); - - try { - function.createOrPropagate(exception); - } catch (Exception ex) { - assertEquals(ex, exception); - } - - verify(response); - verify(exception); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/PropagateAbiquoExceptionOnNotFoundOr4xxTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/PropagateAbiquoExceptionOnNotFoundOr4xxTest.java b/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/PropagateAbiquoExceptionOnNotFoundOr4xxTest.java deleted file mode 100644 index ecb472a..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/fallbacks/PropagateAbiquoExceptionOnNotFoundOr4xxTest.java +++ /dev/null @@ -1,68 +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.abiquo.fallbacks; - -import static org.testng.Assert.assertEquals; - -import javax.ws.rs.core.Response.Status; - -import org.jclouds.abiquo.AbiquoFallbacks.PropagateAbiquoExceptionOnNotFoundOr4xx; -import org.jclouds.abiquo.domain.exception.AbiquoException; -import org.jclouds.rest.ResourceNotFoundException; -import org.testng.annotations.Test; - -import com.abiquo.model.transport.error.ErrorsDto; - -/** - * Unit tests for the {@link PropagateAbiquoExceptionOnNotFoundOr4xx} function. - */ -@Test(groups = "unit", testName = "PropagateAbiquoExceptionOnNotFoundOr4xxTest") -public class PropagateAbiquoExceptionOnNotFoundOr4xxTest { - public void testOriginalExceptionIfNotResourceNotFound() { - PropagateAbiquoExceptionOnNotFoundOr4xx function = new PropagateAbiquoExceptionOnNotFoundOr4xx(); - RuntimeException exception = new RuntimeException(); - - try { - function.createOrPropagate(exception); - } catch (Exception ex) { - assertEquals(ex, exception); - } - } - - public void testOriginalExceptionIfNotAbiquoException() { - PropagateAbiquoExceptionOnNotFoundOr4xx function = new PropagateAbiquoExceptionOnNotFoundOr4xx(); - ResourceNotFoundException exception = new ResourceNotFoundException(); - - try { - function.createOrPropagate(exception); - } catch (Exception ex) { - assertEquals(ex, exception); - } - } - - public void testAbiquoException() { - PropagateAbiquoExceptionOnNotFoundOr4xx function = new PropagateAbiquoExceptionOnNotFoundOr4xx(); - AbiquoException abiquoException = new AbiquoException(Status.NOT_FOUND, new ErrorsDto()); - ResourceNotFoundException exception = new ResourceNotFoundException(abiquoException); - - try { - function.createOrPropagate(exception); - } catch (Exception ex) { - assertEquals(ex, abiquoException); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/features/AdminApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/features/AdminApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/features/AdminApiTest.java deleted file mode 100644 index dd2b91a..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/features/AdminApiTest.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.abiquo.features; - -import static org.jclouds.abiquo.domain.DomainUtils.withHeader; -import static org.jclouds.reflect.Reflection2.method; - -import java.io.IOException; - -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.abiquo.domain.AdminResources; -import org.jclouds.abiquo.domain.EnterpriseResources; -import org.jclouds.http.functions.ParseXMLWithJAXB; -import org.jclouds.http.functions.ReleasePayloadAndReturn; -import org.jclouds.reflect.Invocation; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.Test; - -import com.abiquo.server.core.enterprise.PrivilegesDto; -import com.abiquo.server.core.enterprise.RoleDto; -import com.abiquo.server.core.enterprise.RolesDto; -import com.abiquo.server.core.enterprise.UserDto; -import com.google.common.collect.ImmutableList; -import com.google.common.reflect.Invokable; - -/** - * Tests annotation parsing of {@code AdminApi} - */ -@Test(groups = "unit", testName = "AdminApiTest") -public class AdminApiTest extends BaseAbiquoApiTest<AdminApi> { - /*********************** Role ***********************/ - - public void testListRoles() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(AdminApi.class, "listRoles"); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList.of())); - - assertRequestLineEquals(request, "GET http://localhost/api/admin/roles HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + RolesDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testGetRoleFromUser() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(AdminApi.class, "getRole", UserDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList.<Object> of(EnterpriseResources.userPut()))); - - assertRequestLineEquals(request, "GET http://localhost/api/admin/roles/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + RoleDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testCreateRole() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(AdminApi.class, "createRole", RoleDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList.<Object> of(AdminResources.rolePost()))); - - assertRequestLineEquals(request, "POST http://localhost/api/admin/roles HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + RoleDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, withHeader(AdminResources.rolePostPayload()), RoleDto.class, - RoleDto.BASE_MEDIA_TYPE, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testDeleteRole() throws SecurityException, NoSuchMethodException { - Invokable<?, ?> method = method(AdminApi.class, "deleteRole", RoleDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList.<Object> of(AdminResources.rolePut()))); - - assertRequestLineEquals(request, "DELETE http://localhost/api/admin/roles/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, ""); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testUpdateRole() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(AdminApi.class, "updateRole", RoleDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList.<Object> of(AdminResources.rolePut()))); - - assertRequestLineEquals(request, "PUT http://localhost/api/admin/roles/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + RoleDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, withHeader(AdminResources.rolePutPayload()), RoleDto.class, RoleDto.BASE_MEDIA_TYPE, - false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - public void testGetRoleById() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(AdminApi.class, "getRole", Integer.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList.<Object> of(1))); - - assertRequestLineEquals(request, "GET http://localhost/api/admin/roles/1 HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + RoleDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(request); - } - - public void testListPrivilegesByRoles() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(AdminApi.class, "listPrivileges", RoleDto.class); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, - ImmutableList.<Object> of(AdminResources.rolePut()))); - - assertRequestLineEquals(request, "GET http://localhost/api/admin/roles/1/action/privileges HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + PrivilegesDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } - - /*********************** Current User **********************/ - - public void testGetCurrentUser() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(AdminApi.class, "getCurrentUser"); - GeneratedHttpRequest request = processor.apply(Invocation.create(method, ImmutableList.<Object> of(1))); - - assertRequestLineEquals(request, "GET http://localhost/api/login HTTP/1.1"); - assertNonPayloadHeadersEqual(request, "Accept: " + UserDto.BASE_MEDIA_TYPE + "\n"); - assertPayloadEquals(request, null, null, false); - - assertResponseParserClassEquals(method, request, ParseXMLWithJAXB.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(request); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/features/BaseAbiquoApiExpectTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/features/BaseAbiquoApiExpectTest.java b/abiquo/src/test/java/org/jclouds/abiquo/features/BaseAbiquoApiExpectTest.java deleted file mode 100644 index a9c242c..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/features/BaseAbiquoApiExpectTest.java +++ /dev/null @@ -1,89 +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.abiquo.features; - -import java.util.Properties; - -import javax.inject.Inject; -import javax.inject.Singleton; -import javax.ws.rs.core.MediaType; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.AbiquoApiMetadata; -import org.jclouds.abiquo.functions.auth.GetTokenFromApi; -import org.jclouds.apis.ApiMetadata; -import org.jclouds.domain.Credentials; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.jclouds.providers.ProviderMetadata; -import org.jclouds.rest.HttpClient; -import org.jclouds.rest.internal.BaseRestApiExpectTest; - -import com.google.common.base.Function; -import com.google.inject.AbstractModule; -import com.google.inject.Module; - -/** - * Base class for Abiquo expect tests. - */ -public abstract class BaseAbiquoApiExpectTest<S> extends BaseRestApiExpectTest<S> { - protected final String tokenAuth = "auth=mock-token"; - - public BaseAbiquoApiExpectTest() { - provider = "abiquo"; - } - - @Override - protected ApiMetadata createApiMetadata() { - return new AbiquoApiMetadata(); - } - - @Override - protected Module createModule() { - return new AbstractModule() { - @Override - protected void configure() { - bind(GetTokenFromApi.class).to(MockTokenFromApi.class); - } - }; - } - - @Override - public S createClient(final Function<HttpRequest, HttpResponse> fn, final Module module, final Properties props) { - return clientFrom(createInjector(fn, module, props).getInstance(AbiquoApi.class)); - } - - protected abstract S clientFrom(AbiquoApi api); - - protected String normalize(final String mediatType) { - return MediaType.valueOf(mediatType).toString(); - } - - @Singleton - private static class MockTokenFromApi extends GetTokenFromApi { - @Inject - public MockTokenFromApi(ProviderMetadata provider, HttpClient http) { - super(provider, http); - } - - @Override - public String apply(Credentials input) { - return "mock-token"; - } - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/features/BaseAbiquoApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/features/BaseAbiquoApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/features/BaseAbiquoApiTest.java deleted file mode 100644 index 6f2adf0..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/features/BaseAbiquoApiTest.java +++ /dev/null @@ -1,87 +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.abiquo.features; - -import static org.jclouds.Constants.PROPERTY_PRETTY_PRINT_PAYLOADS; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Properties; - -import org.jclouds.abiquo.AbiquoApiMetadata; -import org.jclouds.abiquo.config.AbiquoHttpApiModule; -import org.jclouds.abiquo.http.filters.AbiquoAuthentication; -import org.jclouds.abiquo.http.filters.AppendApiVersionToMediaType; -import org.jclouds.http.HttpRequest; -import org.jclouds.providers.AnonymousProviderMetadata; -import org.jclouds.providers.ProviderMetadata; -import org.jclouds.rest.internal.BaseRestAnnotationProcessingTest; -import org.jclouds.xml.XMLParser; -import org.testng.annotations.BeforeClass; - -import com.abiquo.model.transport.SingleResourceTransportDto; -import com.google.inject.Module; - -/** - * Base class for Abiquo api tests. - */ -public abstract class BaseAbiquoApiTest<T> extends BaseRestAnnotationProcessingTest<T> { - private XMLParser xml; - - @BeforeClass - @Override - protected void setupFactory() throws IOException { - super.setupFactory(); - xml = injector.getInstance(XMLParser.class); - } - - @Override - protected void checkFilters(final HttpRequest request) { - assertEquals(request.getFilters().size(), 2); - assertEquals(request.getFilters().get(0).getClass(), AbiquoAuthentication.class); - assertEquals(request.getFilters().get(1).getClass(), AppendApiVersionToMediaType.class); - } - - @Override - protected Module createModule() { - return new AbiquoHttpApiModule(); - } - - @Override - protected ProviderMetadata createProviderMetadata() { - return AnonymousProviderMetadata.forApiWithEndpoint(new AbiquoApiMetadata(), "http://localhost/api"); - } - - @Override - protected Properties setupProperties() { - Properties props = super.setupProperties(); - // Do not pretty print payloads in tests - props.setProperty(PROPERTY_PRETTY_PRINT_PAYLOADS, "false"); - return props; - } - - protected void assertPayloadEquals(final HttpRequest request, final String toMatch, - final Class<? extends SingleResourceTransportDto> entityClass, final String contentType, - final boolean contentMD5) throws IOException { - // Make sure we don't have formatting issues - SingleResourceTransportDto entity = xml.fromXML(toMatch, entityClass); - String stringToMatch = xml.toXML(entity, entityClass); - - super.assertPayloadEquals(request, stringToMatch, contentType, contentMD5); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/features/CloudApiExpectTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/features/CloudApiExpectTest.java b/abiquo/src/test/java/org/jclouds/abiquo/features/CloudApiExpectTest.java deleted file mode 100644 index 6a05030..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/features/CloudApiExpectTest.java +++ /dev/null @@ -1,590 +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.abiquo.features; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import java.net.URI; -import java.util.List; - -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.PaginatedCollection; -import org.jclouds.abiquo.domain.cloud.options.VirtualMachineOptions; -import org.jclouds.abiquo.domain.cloud.options.VirtualMachineTemplateOptions; -import org.jclouds.abiquo.domain.cloud.options.VolumeOptions; -import org.jclouds.abiquo.domain.network.options.IpOptions; -import org.jclouds.collect.PagedIterable; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.model.transport.AcceptedRequestDto; -import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; -import com.abiquo.server.core.appslibrary.VirtualMachineTemplatesDto; -import com.abiquo.server.core.cloud.VirtualApplianceDto; -import com.abiquo.server.core.cloud.VirtualDatacenterDto; -import com.abiquo.server.core.cloud.VirtualMachineDto; -import com.abiquo.server.core.cloud.VirtualMachineInstanceDto; -import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; -import com.abiquo.server.core.cloud.VirtualMachinesWithNodeExtendedDto; -import com.abiquo.server.core.infrastructure.network.PrivateIpDto; -import com.abiquo.server.core.infrastructure.network.PrivateIpsDto; -import com.abiquo.server.core.infrastructure.network.PublicIpDto; -import com.abiquo.server.core.infrastructure.network.PublicIpsDto; -import com.abiquo.server.core.infrastructure.network.VLANNetworkDto; -import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; -import com.abiquo.server.core.infrastructure.storage.VolumesManagementDto; - -/** - * Expect tests for the {@link CloudApi} class. - */ -@Test(groups = "unit", testName = "CloudApiExpectTest") -public class CloudApiExpectTest extends BaseAbiquoApiExpectTest<CloudApi> { - - public void testListAllVirtualMachinesWhenResponseIs2xx() { - CloudApi api = requestsSendResponses( - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://localhost/api/cloud/virtualmachines")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(VirtualMachinesWithNodeExtendedDto.MEDIA_TYPE)) // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/all-vms.xml", - normalize(VirtualMachinesWithNodeExtendedDto.MEDIA_TYPE))) // - .build(), - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://localhost/api/cloud/virtualmachines")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(VirtualMachinesWithNodeExtendedDto.MEDIA_TYPE)) // - .addQueryParam("startwith", "2").build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/all-vms-lastpage.xml", - normalize(VirtualMachinesWithNodeExtendedDto.MEDIA_TYPE))) // - .build()); - - PagedIterable<VirtualMachineWithNodeExtendedDto> result = api.listAllVirtualMachines(); - List<VirtualMachineWithNodeExtendedDto> vms = result.concat().toList(); - - assertEquals(vms.size(), 2); - assertEquals(vms.get(0).getId(), Integer.valueOf(1)); - assertEquals(vms.get(1).getId(), Integer.valueOf(2)); - assertEquals(vms.get(0).getName(), "VM"); - assertNotNull(vms.get(0).getEditLink()); - } - - public void testListAllVirtualMachinesWithPagination() { - CloudApi api = requestSendsResponse( - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://localhost/api/cloud/virtualmachines")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(VirtualMachinesWithNodeExtendedDto.MEDIA_TYPE)) // - .addQueryParam("startwith", "2").build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/all-vms-lastpage.xml", - normalize(VirtualMachinesWithNodeExtendedDto.MEDIA_TYPE))) // - .build()); - - VirtualMachineOptions options = VirtualMachineOptions.builder().startWith(2).build(); - PaginatedCollection<VirtualMachineWithNodeExtendedDto, VirtualMachinesWithNodeExtendedDto> vms = api - .listAllVirtualMachines(options); - - assertEquals(vms.size(), 1); - assertEquals(vms.getTotalSize().intValue(), 2); - assertEquals(vms.get(0).getId().intValue(), 2); - } - - public void testListVirtualMachinesWhenResponseIs2xx() { - CloudApi api = requestsSendResponses( - HttpRequest.builder() // - .method("GET") - // - .endpoint( - URI.create("http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(VirtualMachinesWithNodeExtendedDto.MEDIA_TYPE)) // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/vms-page.xml", - normalize(VirtualMachinesWithNodeExtendedDto.MEDIA_TYPE))) // - .build(), - HttpRequest.builder() // - .method("GET") - // - .endpoint( - URI.create("http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(VirtualMachinesWithNodeExtendedDto.MEDIA_TYPE)) // - .addQueryParam("startwith", "2").build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/vms-lastpage.xml", - normalize(VirtualMachinesWithNodeExtendedDto.MEDIA_TYPE))) // - .build()); - - VirtualApplianceDto vapp = new VirtualApplianceDto(); - vapp.addLink(new RESTLink("virtualmachines", - "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines")); - - PagedIterable<VirtualMachineWithNodeExtendedDto> result = api.listVirtualMachines(vapp); - List<VirtualMachineWithNodeExtendedDto> vms = result.concat().toList(); - - assertEquals(vms.size(), 2); - assertEquals(vms.get(0).getId(), Integer.valueOf(1)); - assertEquals(vms.get(1).getId(), Integer.valueOf(2)); - assertEquals(vms.get(0).getName(), "VM"); - assertNotNull(vms.get(0).getEditLink()); - } - - public void testLisVirtualMachinesWithPagination() { - CloudApi api = requestSendsResponse( - HttpRequest.builder() // - .method("GET") - // - .endpoint( - URI.create("http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(VirtualMachinesWithNodeExtendedDto.MEDIA_TYPE)) // - .addQueryParam("startwith", "2").build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/vms-lastpage.xml", - normalize(VirtualMachinesWithNodeExtendedDto.MEDIA_TYPE))) // - .build()); - - VirtualApplianceDto vapp = new VirtualApplianceDto(); - vapp.addLink(new RESTLink("virtualmachines", - "http://localhost/api/cloud/virtualdatacenters/1/virtualappliances/1/virtualmachines")); - - VirtualMachineOptions options = VirtualMachineOptions.builder().startWith(2).build(); - PaginatedCollection<VirtualMachineWithNodeExtendedDto, VirtualMachinesWithNodeExtendedDto> vms = api - .listVirtualMachines(vapp, options); - - assertEquals(vms.size(), 1); - assertEquals(vms.getTotalSize().intValue(), 2); - assertEquals(vms.get(0).getId().intValue(), 2); - } - - public void testSnapshotVirtualMachineReturns2xx() { - CloudApi api = requestSendsResponse( - HttpRequest - .builder() - .method("POST") - .endpoint( - URI.create("http://localhost/api/admin/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/action/instance")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(AcceptedRequestDto.MEDIA_TYPE)) // - .payload( - payloadFromResourceWithContentType("/payloads/vm-snapshot.xml", - normalize(VirtualMachineInstanceDto.MEDIA_TYPE))) // - .build(), // - HttpResponse - .builder() - .statusCode(202) - .payload( - payloadFromResourceWithContentType("/payloads/vm-accepted-request.xml", - normalize(VirtualMachineInstanceDto.MEDIA_TYPE))).build()); - - VirtualMachineDto vm = new VirtualMachineDto(); - vm.addLink(new RESTLink("instance", - "http://localhost/api/admin/virtualdatacenters/1/virtualappliances/1/virtualmachines/1/action/instance")); - VirtualMachineInstanceDto snapshotConfig = new VirtualMachineInstanceDto(); - snapshotConfig.setInstanceName("foo"); - - AcceptedRequestDto<String> taskRef = api.snapshotVirtualMachine(vm, snapshotConfig); - assertNotNull(taskRef); - } - - public void testListAvailablePublicIps() { - CloudApi api = requestsSendResponses( - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://localhost/api/cloud/virtualdatacenters/1/publicips/topurchase")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(PublicIpsDto.MEDIA_TYPE)) // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/publicips-available-page.xml", - normalize(PublicIpsDto.MEDIA_TYPE))) // - .build(), - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://localhost/api/cloud/virtualdatacenters/1/publicips/topurchase")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(PublicIpsDto.MEDIA_TYPE)) // - .addQueryParam("startwith", "3") // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/publicips-available-lastpage.xml", - normalize(PublicIpsDto.MEDIA_TYPE))) // - .build()); - - VirtualDatacenterDto vdc = new VirtualDatacenterDto(); - vdc.addLink(new RESTLink("topurchase", "http://localhost/api/cloud/virtualdatacenters/1/publicips/topurchase")); - - PagedIterable<PublicIpDto> publicIps = api.listAvailablePublicIps(vdc); - List<PublicIpDto> ips = publicIps.concat().toList(); - - assertEquals(ips.size(), 4); - assertEquals(ips.get(0).getId().intValue(), 1); - assertEquals(ips.get(1).getId().intValue(), 2); - assertEquals(ips.get(2).getId().intValue(), 3); - assertEquals(ips.get(3).getId().intValue(), 4); - } - - public void testListAvailablePublicIpsWithPagination() { - CloudApi api = requestSendsResponse( - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://localhost/api/cloud/virtualdatacenters/1/publicips/topurchase")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(PublicIpsDto.MEDIA_TYPE)) // - .addQueryParam("startwith", "3") // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/publicips-available-lastpage.xml", - normalize(PublicIpsDto.MEDIA_TYPE))) // - .build()); - - VirtualDatacenterDto vdc = new VirtualDatacenterDto(); - vdc.addLink(new RESTLink("topurchase", "http://localhost/api/cloud/virtualdatacenters/1/publicips/topurchase")); - - IpOptions options = IpOptions.builder().startWith(3).build(); - PaginatedCollection<PublicIpDto, PublicIpsDto> ips = api.listAvailablePublicIps(vdc, options); - - assertEquals(ips.size(), 2); - assertEquals(ips.getTotalSize().intValue(), 4); - assertEquals(ips.get(0).getId().intValue(), 3); - assertEquals(ips.get(1).getId().intValue(), 4); - } - - public void testListPurchasedPublicIps() { - CloudApi api = requestsSendResponses( - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://localhost/api/cloud/virtualdatacenters/1/publicips/purchased")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(PublicIpsDto.MEDIA_TYPE)) // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/publicips-purchased-page.xml", - normalize(PublicIpsDto.MEDIA_TYPE))) // - .build(), - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://localhost/api/cloud/virtualdatacenters/1/publicips/purchased")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(PublicIpsDto.MEDIA_TYPE)) // - .addQueryParam("startwith", "3") // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/publicips-purchased-lastpage.xml", - normalize(PublicIpsDto.MEDIA_TYPE))) // - .build()); - - VirtualDatacenterDto vdc = new VirtualDatacenterDto(); - vdc.addLink(new RESTLink("purchased", "http://localhost/api/cloud/virtualdatacenters/1/publicips/purchased")); - - PagedIterable<PublicIpDto> publicIps = api.listPurchasedPublicIps(vdc); - List<PublicIpDto> ips = publicIps.concat().toList(); - - assertEquals(ips.size(), 4); - assertEquals(ips.get(0).getId().intValue(), 1); - assertEquals(ips.get(1).getId().intValue(), 2); - assertEquals(ips.get(2).getId().intValue(), 3); - assertEquals(ips.get(3).getId().intValue(), 4); - } - - public void testListPurchasedPublicIpsWithPagination() { - CloudApi api = requestSendsResponse( - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://localhost/api/cloud/virtualdatacenters/1/publicips/purchased")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(PublicIpsDto.MEDIA_TYPE)) // - .addQueryParam("startwith", "3") // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/publicips-purchased-lastpage.xml", - normalize(PublicIpsDto.MEDIA_TYPE))) // - .build()); - - VirtualDatacenterDto vdc = new VirtualDatacenterDto(); - vdc.addLink(new RESTLink("purchased", "http://localhost/api/cloud/virtualdatacenters/1/publicips/purchased")); - - IpOptions options = IpOptions.builder().startWith(3).build(); - PaginatedCollection<PublicIpDto, PublicIpsDto> ips = api.listPurchasedPublicIps(vdc, options); - - assertEquals(ips.size(), 2); - assertEquals(ips.getTotalSize().intValue(), 4); - assertEquals(ips.get(0).getId().intValue(), 3); - assertEquals(ips.get(1).getId().intValue(), 4); - } - - public void testListPrivteIps() { - CloudApi api = requestsSendResponses( - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1/ips")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(PrivateIpsDto.MEDIA_TYPE)) // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/privateips-page.xml", - normalize(PublicIpsDto.MEDIA_TYPE))) // - .build(), - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1/ips")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(PrivateIpsDto.MEDIA_TYPE)) // - .addQueryParam("startwith", "1") // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/privateips-lastpage.xml", - normalize(PrivateIpsDto.MEDIA_TYPE))) // - .build()); - - VLANNetworkDto vlan = new VLANNetworkDto(); - vlan.addLink(new RESTLink("ips", "http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1/ips")); - - PagedIterable<PrivateIpDto> privateIps = api.listPrivateNetworkIps(vlan); - List<PrivateIpDto> ips = privateIps.concat().toList(); - - assertEquals(ips.size(), 2); - assertEquals(ips.get(0).getId().intValue(), 1); - assertEquals(ips.get(1).getId().intValue(), 2); - } - - public void testListPrivateIpsWithPagination() { - CloudApi api = requestSendsResponse( - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1/ips")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(PrivateIpsDto.MEDIA_TYPE)) // - .addQueryParam("startwith", "1") // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/privateips-lastpage.xml", - normalize(PrivateIpsDto.MEDIA_TYPE))) // - .build()); - - VLANNetworkDto vlan = new VLANNetworkDto(); - vlan.addLink(new RESTLink("ips", "http://localhost/api/cloud/virtualdatacenters/1/privatenetworks/1/ips")); - - IpOptions options = IpOptions.builder().startWith(1).build(); - PaginatedCollection<PrivateIpDto, PrivateIpsDto> ips = api.listPrivateNetworkIps(vlan, options); - - assertEquals(ips.size(), 1); - assertEquals(ips.getTotalSize().intValue(), 2); - assertEquals(ips.get(0).getId().intValue(), 2); - } - - public void testListAvailableTemplates() { - CloudApi api = requestsSendResponses( - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://example.com/api/cloud/virtualdatacenters/1/action/templates")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(VirtualMachineTemplatesDto.MEDIA_TYPE)) // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/available-templates-page.xml", - normalize(VirtualMachineTemplatesDto.MEDIA_TYPE))) // - .build(), - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://example.com/api/cloud/virtualdatacenters/1/action/templates")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(VirtualMachineTemplatesDto.MEDIA_TYPE)) // - .addQueryParam("startwith", "1") // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/available-templates-lastpage.xml", - normalize(VirtualMachineTemplatesDto.MEDIA_TYPE))) // - .build()); - - VirtualDatacenterDto vdc = new VirtualDatacenterDto(); - vdc.addLink(new RESTLink("templates", "http://example.com/api/cloud/virtualdatacenters/1/action/templates")); - - PagedIterable<VirtualMachineTemplateDto> templates = api.listAvailableTemplates(vdc); - List<VirtualMachineTemplateDto> all = templates.concat().toList(); - - assertEquals(all.size(), 2); - assertEquals(all.get(0).getId().intValue(), 15); - assertEquals(all.get(1).getId().intValue(), 16); - } - - public void testListAvailableTemplatesWithPagination() { - CloudApi api = requestSendsResponse( - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://example.com/api/cloud/virtualdatacenters/1/action/templates")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(VirtualMachineTemplatesDto.MEDIA_TYPE)) // - .addQueryParam("startwith", "1") // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/available-templates-lastpage.xml", - normalize(VirtualMachineTemplatesDto.MEDIA_TYPE))) // - .build()); - - VirtualDatacenterDto vdc = new VirtualDatacenterDto(); - vdc.addLink(new RESTLink("templates", "http://example.com/api/cloud/virtualdatacenters/1/action/templates")); - - VirtualMachineTemplateOptions options = VirtualMachineTemplateOptions.builder().startWith(1).build(); - PaginatedCollection<VirtualMachineTemplateDto, VirtualMachineTemplatesDto> templates = api - .listAvailableTemplates(vdc, options); - - assertEquals(templates.size(), 1); - assertEquals(templates.getTotalSize().intValue(), 2); - assertEquals(templates.get(0).getId().intValue(), 16); - } - - public void testListVolumes() { - CloudApi api = requestsSendResponses( - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://example.com/api/cloud/virtualdatacenters/1/volumes")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(VolumesManagementDto.MEDIA_TYPE)) // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/volumes-page.xml", - normalize(VolumesManagementDto.MEDIA_TYPE))) // - .build(), - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://example.com/api/cloud/virtualdatacenters/1/volumes")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(VolumesManagementDto.MEDIA_TYPE)) // - .addQueryParam("startwith", "1") // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/volumes-lastpage.xml", - normalize(VolumesManagementDto.MEDIA_TYPE))) // - .build()); - - VirtualDatacenterDto vdc = new VirtualDatacenterDto(); - vdc.addLink(new RESTLink("volumes", "http://example.com/api/cloud/virtualdatacenters/1/volumes")); - - PagedIterable<VolumeManagementDto> volumes = api.listVolumes(vdc); - List<VolumeManagementDto> all = volumes.concat().toList(); - - assertEquals(all.size(), 2); - assertEquals(all.get(0).getId().intValue(), 1530); - assertEquals(all.get(1).getId().intValue(), 1531); - } - - public void testListVolumesWithPagination() { - CloudApi api = requestSendsResponse( - HttpRequest.builder() // - .method("GET") // - .endpoint(URI.create("http://example.com/api/cloud/virtualdatacenters/1/volumes")) // - .addHeader("Cookie", tokenAuth) // - .addHeader("Accept", normalize(VolumesManagementDto.MEDIA_TYPE)) // - .addQueryParam("startwith", "1") // - .build(), - HttpResponse - .builder() - .statusCode(200) - .payload( - payloadFromResourceWithContentType("/payloads/volumes-lastpage.xml", - normalize(VolumesManagementDto.MEDIA_TYPE))) // - .build()); - - VirtualDatacenterDto vdc = new VirtualDatacenterDto(); - vdc.addLink(new RESTLink("volumes", "http://example.com/api/cloud/virtualdatacenters/1/volumes")); - - VolumeOptions options = VolumeOptions.builder().startWith(1).build(); - PaginatedCollection<VolumeManagementDto, VolumesManagementDto> templates = api.listVolumes(vdc, options); - - assertEquals(templates.size(), 1); - assertEquals(templates.getTotalSize().intValue(), 2); - assertEquals(templates.get(0).getId().intValue(), 1531); - } - - @Override - protected CloudApi clientFrom(AbiquoApi api) { - return api.getCloudApi(); - } - -}
