http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/UserLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/UserLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/UserLiveApiTest.java deleted file mode 100644 index d113abc..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/enterprise/UserLiveApiTest.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.domain.enterprise; - -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.find; -import static com.google.common.collect.Iterables.size; -import static org.jclouds.abiquo.util.Assert.assertHasError; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.fail; - -import javax.ws.rs.core.Response.Status; - -import org.jclouds.abiquo.domain.exception.AbiquoException; -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.testng.annotations.Test; - -import com.abiquo.server.core.enterprise.UserDto; -import com.google.common.base.Predicate; - -/** - * Live integration tests for the {@link User} domain class. - */ -@Test(groups = "api", testName = "UserLiveApiTest") -public class UserLiveApiTest extends BaseAbiquoApiLiveApiTest { - - public void testUpdate() { - String username = env.user.getName(); - env.user.setName("Manolo"); - env.user.update(); - - // Recover the updated user - UserDto updated = env.enterpriseApi.getUser(env.enterprise.unwrap(), env.user.getId()); - - assertEquals(updated.getName(), "Manolo"); - - env.user.setName(username); - env.user.update(); - } - - public void testCreateRepeated() { - User repeated = User.Builder.fromUser(env.user).build(); - - try { - repeated.save(); - fail("Should not be able to create users with the same nick"); - } catch (AbiquoException ex) { - assertHasError(ex, Status.CONFLICT, "USER-4"); - } - } - - public void testChangeRoleAndUpdate() { - env.user.setRole(env.anotherRole); - env.user.update(); - - Role role2 = find(env.enterprise.listUsers(), nick(env.user.getNick())).getRole(); - - assertEquals(env.anotherRole.getId(), role2.getId()); - assertEquals(role2.getName(), "Another role"); - - env.user.setRole(env.role); - env.user.update(); - } - - public void testListUser() { - Iterable<User> users = env.enterprise.listUsers(); - assertEquals(size(users), 2); - - users = filter(env.enterprise.listUsers(), nick(env.user.getNick())); - assertEquals(size(users), 1); - - users = filter(env.enterprise.listUsers(), nick(env.user.getName() + "FAIL")); - assertEquals(size(users), 0); - } - - public void testGetCurrentUser() { - User user = env.context.getAdministrationService().getCurrentUser(); - assertNotNull(user); - assertEquals(user.getNick(), env.context.getApiContext().getIdentity()); - } - - 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/domain/event/EventLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/event/EventLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/event/EventLiveApiTest.java deleted file mode 100644 index 33fe3a9..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/event/EventLiveApiTest.java +++ /dev/null @@ -1,251 +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.domain.event; - -import static com.google.common.collect.Iterables.find; -import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; - -import java.util.Date; -import java.util.UUID; - -import org.jclouds.abiquo.domain.cloud.VirtualMachine; -import org.jclouds.abiquo.domain.cloud.Volume; -import org.jclouds.abiquo.domain.enterprise.User; -import org.jclouds.abiquo.domain.event.options.EventOptions; -import org.jclouds.abiquo.domain.infrastructure.Tier; -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.testng.annotations.Test; - -import com.abiquo.model.enumerator.ComponentType; -import com.abiquo.model.enumerator.EventType; -import com.abiquo.model.enumerator.SeverityType; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; - -/** - * Live integration tests for the {@link Event} domain class. - */ -@Test(groups = "api", testName = "EventLiveApiTest") -public class EventLiveApiTest extends BaseAbiquoApiLiveApiTest { - public void testListEventsFilteredByDatacenter() { - String name = randomName(); - env.datacenter.setName(name); - env.datacenter.update(); - - EventOptions options = EventOptions.builder().dateFrom(new Date()).datacenterName(name).build(); - assertEvents(options); - } - - public void testListEventsFilteredByRack() { - String name = randomName(); - env.rack.setName(name); - env.rack.update(); - - EventOptions options = EventOptions.builder().dateFrom(new Date()).rackName(name).build(); - assertEvents(options); - } - - public void testListEventsFilteredByPM() { - String name = randomName(); - env.machine.setName(name); - env.machine.update(); - - EventOptions options = EventOptions.builder().dateFrom(new Date()).physicalMachineName(name).build(); - assertEvents(options); - } - - public void testListEventsFilteredByStorageDevice() { - String name = randomName(); - env.storageDevice.setName(name); - env.storageDevice.update(); - - EventOptions options = EventOptions.builder().dateFrom(new Date()).storageSystemName(name).build(); - assertEvents(options); - } - - public void testListEventsFilteredByStoragePool() { - Tier tier = find(env.datacenter.listTiers(), new Predicate<Tier>() { - @Override - public boolean apply(Tier input) { - return input.getName().equals("Default Tier 2"); - } - }); - - try { - env.storagePool.setTier(tier); - env.storagePool.update(); - - EventOptions options = EventOptions.builder().dateFrom(new Date()).storagePoolName(env.storagePool.getName()) - .build(); - assertEvents(options); - } finally { - // Restore the original tier - env.storagePool.setTier(env.tier); - env.storagePool.update(); - } - } - - public void testListEventsFilteredByEnterprise() { - String entName = env.enterprise.getName(); - String name = randomName(); - env.enterprise.setName(name); - env.enterprise.update(); - - // Enterprise current = - // env.enterpriseAdminContext.getAdministrationService().getCurrentEnterprise(); - // current.setName("Enterprise updated"); - // current.update(); - - EventOptions options = EventOptions.builder().dateFrom(new Date()).enterpriseName(name).build(); - assertEvents(options); - - env.enterprise.setName(entName); - env.enterprise.update(); - } - - /** - * TODO: Using the painUserContext, modifying the user returns this error: - * HTTP/1.1 401 Unauthorized - **/ - @Test(enabled = false) - public void testListEventsFilteredByUser() { - User current = env.plainUserContext.getAdministrationService().getCurrentUser(); - current.setEmail("[email protected]"); - current.update(); - - EventOptions options = EventOptions.builder().dateFrom(new Date()).userName(current.getName()).build(); - assertEvents(options); - } - - public void testListEventsFilteredByVDC() { - String name = randomName(); - env.virtualDatacenter.setName(name); - env.virtualDatacenter.update(); - - EventOptions options = EventOptions.builder().dateFrom(new Date()).virtualDatacenterName(name).build(); - assertEvents(options); - } - - public void testListEventsFilteredByVapp() { - String name = randomName(); - env.virtualAppliance.setName(name); - env.virtualAppliance.update(); - - EventOptions options = EventOptions.builder().dateFrom(new Date()).virtualAppName(name).build(); - assertEvents(options); - } - - public void testListEventsFilteredByVM() { - VirtualMachine vm = createVirtualMachine(); - vm.delete(); - - EventOptions options = EventOptions.builder().dateFrom(new Date()).actionPerformed(EventType.VM_DELETE).build(); - assertEvents(options); - } - - public void testListEventsFilteredByVolume() { - String name = randomName(); - Volume volume = createVolume(); - volume.setName(name); - volume.update(); - volume.delete(); // We don't need it any more. events already exist - - EventOptions options = EventOptions.builder().dateFrom(new Date()).volumeName(name).build(); - assertEvents(options); - } - - public void testListEventsFilteredBySeverity() { - String name = randomName(); - env.virtualAppliance.setName(name); - env.virtualAppliance.update(); - - EventOptions options = EventOptions.builder().dateFrom(new Date()).virtualAppName(name) - .severity(SeverityType.INFO).build(); - assertEvents(options); - } - - public void testListEventsFilteredByActionPerformed() { - String name = randomName(); - env.virtualAppliance.setName(name); - env.virtualAppliance.update(); - - EventOptions options = EventOptions.builder().dateFrom(new Date()).virtualAppName(name) - .actionPerformed(EventType.VAPP_MODIFY).build(); - assertEvents(options); - } - - public void testListEventsFilteredByComponent() { - String name = randomName(); - env.virtualAppliance.setName(name); - env.virtualAppliance.update(); - - EventOptions options = EventOptions.builder().dateFrom(new Date()).virtualAppName(name) - .component(ComponentType.VIRTUAL_APPLIANCE).build(); - assertEvents(options); - } - - public void testListEventsFilteredByDescription() { - String name = randomName(); - env.virtualAppliance.setName(name); - env.virtualAppliance.update(); - - EventOptions options = EventOptions.builder().dateFrom(new Date()).virtualAppName(name) - .description("Virtual appliance '" + name + "' has been modified.").build(); - assertEvents(options); - } - - // Helpers - - private void assertEvents(final EventOptions options) { - Iterable<Event> events = env.eventService.listEvents(options); - assertTrue(Iterables.size(events) >= 1); - } - - private Volume createVolume() { - Tier tier = find(env.virtualDatacenter.listStorageTiers(), new Predicate<Tier>() { - @Override - public boolean apply(Tier input) { - return input.getName().equals(env.tier.getName()); - } - }); - - Volume volume = Volume.builder(env.context.getApiContext(), env.virtualDatacenter, tier) - .name(PREFIX + "Event vol").sizeInMb(32).build(); - - volume.save(); - assertNotNull(volume.getId()); - - return volume; - } - - private VirtualMachine createVirtualMachine() { - VirtualMachine virtualMachine = VirtualMachine - .builder(env.context.getApiContext(), env.virtualAppliance, env.template).cpu(2).ram(128) - .nameLabel(PREFIX + "events").build(); - - virtualMachine.save(); - assertNotNull(virtualMachine.getId()); - - return virtualMachine; - } - - private static String randomName() { - return PREFIX + UUID.randomUUID().toString().substring(0, 12); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/DatacenterLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/DatacenterLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/DatacenterLiveApiTest.java deleted file mode 100644 index b80b485..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/DatacenterLiveApiTest.java +++ /dev/null @@ -1,76 +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.domain.infrastructure; - -import static com.google.common.collect.Iterables.size; -import static org.jclouds.abiquo.util.Assert.assertHasError; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; - -import javax.ws.rs.core.Response.Status; - -import org.jclouds.abiquo.domain.enterprise.Limits; -import org.jclouds.abiquo.domain.exception.AbiquoException; -import org.jclouds.abiquo.domain.infrastructure.Datacenter.Builder; -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.testng.annotations.Test; - -import com.abiquo.model.enumerator.HypervisorType; -import com.abiquo.server.core.infrastructure.DatacenterDto; - -/** - * Live integration tests for the {@link Datacenter} domain class. - */ -@Test(groups = "api", testName = "DatacenterLiveApiTest") -public class DatacenterLiveApiTest extends BaseAbiquoApiLiveApiTest { - - public void testUpdate() { - env.datacenter.setLocation("New York"); - env.datacenter.update(); - - // Recover the updated datacenter - DatacenterDto updated = env.infrastructureApi.getDatacenter(env.datacenter.getId()); - - assertEquals(updated.getLocation(), "New York"); - } - - public void testCheckHypervisorType() { - HypervisorType type = env.datacenter.getHypervisorType(env.machine.getIp()); - - assertEquals(env.machine.getType(), type); - } - - public void testCreateRepeated() { - Datacenter repeated = Builder.fromDatacenter(env.datacenter).build(); - - try { - repeated.save(); - fail("Should not be able to create datacenters with the same name"); - } catch (AbiquoException ex) { - assertHasError(ex, Status.CONFLICT, "DC-3"); - } - } - - public void testListLimits() { - Iterable<Limits> limits = env.datacenter.listLimits(); - assertNotNull(limits); - assertTrue(size(limits) > 0); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/MachineLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/MachineLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/MachineLiveApiTest.java deleted file mode 100644 index 00e9ea6..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/MachineLiveApiTest.java +++ /dev/null @@ -1,138 +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.domain.infrastructure; - -import static com.google.common.collect.Iterables.find; -import static org.jclouds.abiquo.util.Assert.assertHasError; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; - -import java.net.URI; - -import javax.ws.rs.core.Response.Status; - -import org.jclouds.abiquo.domain.cloud.VirtualMachine; -import org.jclouds.abiquo.domain.enterprise.Enterprise; -import org.jclouds.abiquo.domain.exception.AbiquoException; -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.jclouds.abiquo.util.Config; -import org.testng.annotations.Test; - -import com.abiquo.model.enumerator.HypervisorType; -import com.abiquo.model.enumerator.MachineState; -import com.abiquo.model.enumerator.RemoteServiceType; -import com.abiquo.server.core.infrastructure.MachineDto; -import com.google.common.base.Predicate; - -/** - * Live integration tests for the {@link Machine} domain class. - */ -@Test(groups = "api", testName = "MachineLiveApiTest") -public class MachineLiveApiTest extends BaseAbiquoApiLiveApiTest { - public void testDiscoverMachineWithouRemoteService() { - // Delete node collector - RemoteService nc = find(env.datacenter.listRemoteServices(), new Predicate<RemoteService>() { - @Override - public boolean apply(RemoteService input) { - return input.getType().equals(RemoteServiceType.NODE_COLLECTOR); - } - }); - nc.delete(); - - try { - 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"); - - env.datacenter.discoverSingleMachine(ip, type, user, pass); - } catch (AbiquoException ex) { - assertHasError(ex, Status.NOT_FOUND, "RS-2"); - } - - URI endpoint = URI.create(env.context.getApiContext().getProviderMetadata().getEndpoint()); - - // Restore rs - nc = RemoteService.builder(env.context.getApiContext(), env.datacenter).type(RemoteServiceType.NODE_COLLECTOR) - .ip(endpoint.getHost()).build(); - nc.save(); - } - - public void testUpdate() { - env.machine.setName("API Machine"); - env.machine.update(); - - // Recover the updated machine - MachineDto updated = env.infrastructureApi.getMachine(env.rack.unwrap(), env.machine.getId()); - assertEquals(updated.getName(), "API Machine"); - } - - public void testCheck() { - MachineState state = env.machine.check(); - - // Recover the machine with same state that has been returned - MachineDto machine = env.infrastructureApi.getMachine(env.rack.unwrap(), env.machine.getId()); - assertEquals(machine.getState(), state); - } - - public void testCheckFromDatacenter() { - 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"); - - MachineState state = env.datacenter.checkMachineState(ip, type, user, pass); - - // Recover the same machine and compare states - MachineDto machine = env.infrastructureApi.getMachine(env.rack.unwrap(), env.machine.getId()); - assertEquals(machine.getState(), state); - } - - public void testGetRack() { - Rack rack = env.machine.getRack(); - assertNotNull(rack); - assertEquals(rack.getId(), env.rack.getId()); - } - - public void testListVirtualMachines() { - Iterable<VirtualMachine> machines = env.machine.listRemoteVirtualMachines(); - assertNotNull(machines); - } - - public void testReserveMachine() { - assertFalse(env.machine.isReserved()); - - env.machine.reserveFor(env.enterprise); - assertTrue(env.machine.isReserved()); - - Enterprise owner = env.machine.getOwnerEnterprise(); - assertNotNull(owner); - assertEquals(owner.getId(), env.enterprise.getId()); - } - - @Test(dependsOnMethods = "testReserveMachine") - public void testCancelReservation() { - env.machine.cancelReservationFor(env.enterprise); - assertFalse(env.machine.isReserved()); - - Enterprise owner = env.machine.getOwnerEnterprise(); - assertNull(owner); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/NetworkServiceTypeLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/NetworkServiceTypeLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/NetworkServiceTypeLiveApiTest.java deleted file mode 100644 index 6abddcb..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/NetworkServiceTypeLiveApiTest.java +++ /dev/null @@ -1,64 +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.domain.infrastructure; - -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; - -import org.jclouds.abiquo.domain.network.NetworkServiceType; -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.testng.annotations.Test; - -/** - * Live integration tests for the {@link NetworkServiceType} domain class. - */ -@Test(groups = "api", testName = "NetworkServiceTypeLiveApiTest") -public class NetworkServiceTypeLiveApiTest extends BaseAbiquoApiLiveApiTest { - - private NetworkServiceType nst = null; - - @Test - public void testCreate() { - nst = NetworkServiceType.builder(env.context.getApiContext(), env.datacenter).name("Storage Network").build(); - nst.save(); - - assertNotNull(nst.getId()); - NetworkServiceType copy = env.datacenter.getNetworkServiceType(nst.getId()); - assertEquals(copy.getName(), nst.getName()); - - } - - @Test(dependsOnMethods = "testCreate") - public void testUpdate() { - nst.setName("Storage Network Updated"); - nst.update(); - - NetworkServiceType copy = env.datacenter.getNetworkServiceType(nst.getId()); - assertEquals(copy.getName(), nst.getName()); - } - - @Test(dependsOnMethods = "testUpdate") - public void testDelete() { - Integer deleteId = nst.getId(); - nst.delete(); - - // Assert it is deleted - assertNull(env.datacenter.getNetworkServiceType(deleteId)); - - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RackLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RackLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RackLiveApiTest.java deleted file mode 100644 index a916e0b..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RackLiveApiTest.java +++ /dev/null @@ -1,65 +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.domain.infrastructure; - -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.size; -import static org.testng.Assert.assertEquals; - -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.testng.annotations.Test; - -import com.abiquo.server.core.infrastructure.RackDto; -import com.google.common.base.Predicate; - -/** - * Live integration tests for the {@link Rack} domain class. - */ -@Test(groups = "api", testName = "RackLiveApiTest") -public class RackLiveApiTest extends BaseAbiquoApiLiveApiTest { - - public void testUpdate() { - env.rack.setName("Updated rack"); - env.rack.update(); - - // Recover the updated rack - RackDto updated = env.infrastructureApi.getRack(env.datacenter.unwrap(), env.rack.getId()); - - assertEquals(updated.getName(), "Updated rack"); - } - - public void testListRacks() { - Iterable<Rack> racks = env.datacenter.listRacks(); - assertEquals(size(racks), 1); - - racks = filter(env.datacenter.listRacks(), name(env.rack.getName())); - assertEquals(size(racks), 1); - - racks = filter(env.datacenter.listRacks(), name(env.rack.getName() + "FAIL")); - assertEquals(size(racks), 0); - } - - private static Predicate<Rack> name(final String name) { - return new Predicate<Rack>() { - @Override - public boolean apply(Rack input) { - return input.getName().equals(name); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RemoteServiceLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RemoteServiceLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RemoteServiceLiveApiTest.java deleted file mode 100644 index 7a45ffe..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/RemoteServiceLiveApiTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.domain.infrastructure; - -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.find; -import static com.google.common.collect.Iterables.get; -import static com.google.common.collect.Iterables.size; -import static org.jclouds.abiquo.util.Assert.assertHasError; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.assertTrue; -import static org.testng.Assert.fail; - -import java.net.URI; - -import javax.ws.rs.core.Response.Status; - -import org.jclouds.abiquo.domain.exception.AbiquoException; -import org.jclouds.abiquo.domain.infrastructure.RemoteService.Builder; -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.testng.annotations.Test; - -import com.abiquo.model.enumerator.RemoteServiceType; -import com.abiquo.server.core.infrastructure.RemoteServiceDto; -import com.google.common.base.Predicate; - -/** - * Live integration tests for the {@link RemoteService} domain class. - */ -@Test(groups = "api", testName = "RemoteServiceLiveApiTest") -public class RemoteServiceLiveApiTest extends BaseAbiquoApiLiveApiTest { - public void testUpdate() { - // Update the remote service - RemoteService rs = find(env.datacenter.listRemoteServices(), type(RemoteServiceType.VIRTUAL_FACTORY)); - rs.setUri(rs.getUri()); - rs.update(); - - // Recover the updated remote service - RemoteServiceDto updated = env.infrastructureApi.getRemoteService(env.datacenter.unwrap(), - RemoteServiceType.VIRTUAL_FACTORY); - - assertEquals(updated.getUri(), rs.getUri()); - } - - public void testDelete() { - RemoteService rs = find(env.datacenter.listRemoteServices(), type(RemoteServiceType.BPM_SERVICE)); - rs.delete(); - - // Recover the deleted remote service - RemoteServiceDto deleted = env.infrastructureApi.getRemoteService(env.datacenter.unwrap(), - RemoteServiceType.BPM_SERVICE); - - assertNull(deleted); - - URI endpoint = URI.create(env.context.getApiContext().getProviderMetadata().getEndpoint()); - - // Restore rs - RemoteService bpm = RemoteService.builder(env.context.getApiContext(), env.datacenter) - .type(RemoteServiceType.BPM_SERVICE).ip(endpoint.getHost()).build(); - bpm.save(); - } - - public void testIsAvailableNonCheckeable() { - RemoteService rs = find(env.datacenter.listRemoteServices(), type(RemoteServiceType.DHCP_SERVICE)); - assertTrue(rs.isAvailable()); - } - - public void testIsAvailable() { - RemoteService rs = find(env.datacenter.listRemoteServices(), type(RemoteServiceType.NODE_COLLECTOR)); - assertTrue(rs.isAvailable()); - } - - public void testCreateRepeated() { - RemoteService repeated = Builder.fromRemoteService(get(env.remoteServices, 1)).build(); - - try { - repeated.save(); - fail("Should not be able to create duplicated remote services in the datacenter"); - } catch (AbiquoException ex) { - assertHasError(ex, Status.CONFLICT, "RS-6"); - } - } - - public void testListRemoteServices() { - Iterable<RemoteService> remoteServices = env.datacenter.listRemoteServices(); - assertEquals(size(remoteServices), size(env.remoteServices)); - - remoteServices = filter(env.datacenter.listRemoteServices(), type(RemoteServiceType.NODE_COLLECTOR)); - assertEquals(size(remoteServices), 1); - } - - private static Predicate<RemoteService> type(final RemoteServiceType type) { - return new Predicate<RemoteService>() { - @Override - public boolean apply(RemoteService input) { - return input.getType().equals(type); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceLiveApiTest.java deleted file mode 100644 index a22fddb..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StorageDeviceLiveApiTest.java +++ /dev/null @@ -1,66 +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.domain.infrastructure; - -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.size; -import static org.testng.Assert.assertEquals; - -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.testng.annotations.Test; - -import com.abiquo.server.core.infrastructure.storage.StorageDeviceDto; -import com.google.common.base.Predicate; - -/** - * Live integration tests for the {@link StorageDevice} domain class. - */ -@Test(groups = "api", testName = "StorageDeviceLiveApiTest") -public class StorageDeviceLiveApiTest extends BaseAbiquoApiLiveApiTest { - - public void testUpdate() { - env.storageDevice.setName("Updated storage device"); - env.storageDevice.update(); - - // Recover the updated storage device - StorageDeviceDto updated = env.infrastructureApi.getStorageDevice(env.datacenter.unwrap(), - env.storageDevice.getId()); - - assertEquals(updated.getName(), "Updated storage device"); - } - - public void testListStorageDevices() { - Iterable<StorageDevice> storageDevices = env.datacenter.listStorageDevices(); - assertEquals(size(storageDevices), 1); - - storageDevices = filter(env.datacenter.listStorageDevices(), name(env.storageDevice.getName())); - assertEquals(size(storageDevices), 1); - - storageDevices = filter(env.datacenter.listStorageDevices(), name(env.storageDevice.getName() + "FAIL")); - assertEquals(size(storageDevices), 0); - } - - private static Predicate<StorageDevice> name(final String name) { - return new Predicate<StorageDevice>() { - @Override - public boolean apply(StorageDevice input) { - return input.getName().equals(name); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StoragePoolLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StoragePoolLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StoragePoolLiveApiTest.java deleted file mode 100644 index 0c3bdc0..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/StoragePoolLiveApiTest.java +++ /dev/null @@ -1,85 +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.domain.infrastructure; - -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.find; -import static com.google.common.collect.Iterables.size; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; - -/** - * Live integration tests for the {@link StorageDevice} domain class. - */ -@Test(groups = "api", testName = "StoragePoolLiveApiTest") -public class StoragePoolLiveApiTest extends BaseAbiquoApiLiveApiTest { - public void testGetDevice() { - StorageDevice device = env.storagePool.getStorageDevice(); - assertNotNull(device); - assertEquals(device.getId(), env.storageDevice.getId()); - } - - public void testUpdate() { - try { - Tier tier3 = find(env.datacenter.listTiers(), new Predicate<Tier>() { - @Override - public boolean apply(Tier input) { - return input.getName().equals("Default Tier 3"); - } - }); - env.storagePool.setTier(tier3); - env.storagePool.update(); - - assertEquals(env.storagePool.getTier().getName(), "Default Tier 3"); - } finally { - // Restore the original tier - env.storagePool.setTier(env.tier); - env.storagePool.update(); - assertEquals(env.storagePool.getTier().getId(), env.tier.getId()); - } - } - - public void testListStoragePool() { - Iterable<StoragePool> storagePools = env.storageDevice.listStoragePools(); - assertEquals(size(storagePools), 1); - - storagePools = filter(env.storageDevice.listStoragePools(), name(env.storagePool.getName())); - assertEquals(size(storagePools), 1); - - storagePools = filter(env.storageDevice.listStoragePools(), name(env.storagePool.getName() + "FAIL")); - assertEquals(size(storagePools), 0); - } - - public void testRefreshStoragePool() { - env.storagePool.refresh(); - } - - private static Predicate<StoragePool> name(final String name) { - return new Predicate<StoragePool>() { - @Override - public boolean apply(StoragePool input) { - return input.getName().equals(name); - } - }; - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/TierLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/TierLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/TierLiveApiTest.java deleted file mode 100644 index de5460b..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/infrastructure/TierLiveApiTest.java +++ /dev/null @@ -1,67 +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.domain.infrastructure; - -import static com.google.common.collect.Iterables.filter; -import static com.google.common.collect.Iterables.find; -import static com.google.common.collect.Iterables.getLast; -import static com.google.common.collect.Iterables.size; -import static org.testng.Assert.assertEquals; - -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; - -/** - * Live integration tests for the {@link StorageDevice} domain class. - */ -@Test(groups = "api", testName = "TierLiveApiTest") -public class TierLiveApiTest extends BaseAbiquoApiLiveApiTest { - - public void testUpdate() { - Tier tier = getLast(env.datacenter.listTiers()); - - String previousName = tier.getName(); - tier.setName("Updated tier"); - tier.update(); - - // Verify the tier has been updated - find(env.datacenter.listTiers(), name("Updated tier")); - - // Restore the original name - tier.setName(previousName); - tier.update(); - } - - public void testListTiers() { - Iterable<Tier> tiers = env.datacenter.listTiers(); - assertEquals(size(tiers), 4); - - tiers = filter(env.datacenter.listTiers(), name("FAIL")); - assertEquals(size(tiers), 0); - } - - private static Predicate<Tier> name(final String name) { - return new Predicate<Tier>() { - @Override - public boolean apply(Tier input) { - return input.getName().equals(name); - } - }; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/network/ExternalNetworkLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/ExternalNetworkLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/network/ExternalNetworkLiveApiTest.java deleted file mode 100644 index 34e3afe..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/ExternalNetworkLiveApiTest.java +++ /dev/null @@ -1,160 +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.domain.network; - -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.jclouds.abiquo.util.Assert.assertHasError; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.fail; - -import javax.ws.rs.core.Response.Status; - -import org.jclouds.abiquo.domain.PaginatedCollection; -import org.jclouds.abiquo.domain.exception.AbiquoException; -import org.jclouds.abiquo.domain.network.options.IpOptions; -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.jclouds.abiquo.predicates.IpPredicates; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.abiquo.server.core.infrastructure.network.ExternalIpDto; -import com.abiquo.server.core.infrastructure.network.ExternalIpsDto; -import com.google.common.base.Predicate; - -/** - * Live integration tests for the {@link ExternalNetwork} domain class. - */ -@Test(groups = "api", testName = "ExternalNetworkLiveApiTest") -public class ExternalNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest { - private ExternalNetwork externalNetwork; - - @BeforeClass - public void setupNetwork() { - externalNetwork = createNetwork(env.externalNetwork, PREFIX + "-externalnetwork-test"); - } - - @AfterClass - public void tearDownNetwork() { - externalNetwork.delete(); - } - - public void testListIps() { - PaginatedCollection<ExternalIpDto, ExternalIpsDto> ipsDto = env.context.getApiContext().getApi() - .getInfrastructureApi().listExternalIps(externalNetwork.unwrap(), IpOptions.builder().limit(1).build()); - int totalIps = ipsDto.getTotalSize(); - - Iterable<ExternalIp> ips = externalNetwork.listIps(); - assertEquals(size(ips), totalIps); - } - - public void testListIpsWithOptions() { - Iterable<ExternalIp> ips = externalNetwork.listIps(IpOptions.builder().limit(5).build()); - assertEquals(size(ips), 5); - } - - public void testListUnusedIps() { - PaginatedCollection<ExternalIpDto, ExternalIpsDto> ipsDto = env.context.getApiContext().getApi() - .getInfrastructureApi().listExternalIps(externalNetwork.unwrap(), IpOptions.builder().limit(1).build()); - int totalIps = ipsDto.getTotalSize(); - - Iterable<ExternalIp> ips = externalNetwork.listUnusedIps(); - assertEquals(size(ips), totalIps); - } - - public void testUpdateBasicInfo() { - externalNetwork.setName("External network Updated"); - externalNetwork.setPrimaryDNS("8.8.8.8"); - externalNetwork.setSecondaryDNS("8.8.8.8"); - externalNetwork.update(); - - assertEquals(externalNetwork.getName(), "External network Updated"); - assertEquals(externalNetwork.getPrimaryDNS(), "8.8.8.8"); - assertEquals(externalNetwork.getSecondaryDNS(), "8.8.8.8"); - - // Refresh the external network - ExternalNetwork en = find(env.enterprise.listExternalNetworks(env.datacenter), new Predicate<ExternalNetwork>() { - @Override - public boolean apply(ExternalNetwork input) { - return input.getName().equals(externalNetwork.getName()); - } - }); - - assertEquals(en.getId(), externalNetwork.getId()); - assertEquals(en.getName(), "External network Updated"); - assertEquals(en.getPrimaryDNS(), "8.8.8.8"); - assertEquals(en.getSecondaryDNS(), "8.8.8.8"); - } - - public void testUpdateReadOnlyFields() { - ExternalNetwork toUpdate = createNetwork(externalNetwork, PREFIX + "-exttoupdate-test"); - - try { - toUpdate.setTag(20); - toUpdate.setAddress("10.1.0.0"); - toUpdate.setMask(16); - toUpdate.update(); - - fail("Tag field should not be editable"); - } catch (AbiquoException ex) { - assertHasError(ex, Status.CONFLICT, "VLAN-19"); - } finally { - toUpdate.delete(); - } - } - - public void testUpdateWithInvalidValues() { - ExternalNetwork toUpdate = createNetwork(externalNetwork, PREFIX + "-exttoupdate-test"); - - try { - toUpdate.setMask(60); - toUpdate.update(); - - fail("Invalid mask value"); - } catch (AbiquoException ex) { - assertHasError(ex, Status.BAD_REQUEST, "CONSTR-MAX"); - } finally { - toUpdate.delete(); - } - } - - public void testGetEnterprise() { - assertEquals(externalNetwork.getEnterprise().getId(), env.enterprise.getId()); - } - - public void testGetDatacenter() { - assertEquals(externalNetwork.getDatacenter().getId(), env.datacenter.getId()); - } - - public void testGetNetworkFromIp() { - ExternalIp ip = find(externalNetwork.listIps(), IpPredicates.<ExternalIp> notUsed()); - ExternalNetwork network = ip.getNetwork(); - - assertEquals(network.getId(), externalNetwork.getId()); - } - - private ExternalNetwork createNetwork(final ExternalNetwork from, final String name) { - ExternalNetwork network = ExternalNetwork.Builder.fromExternalNetwork(from).build(); - network.setName(name); - network.save(); - assertNotNull(network.getId()); - return network; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/network/GenericNetworkLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/GenericNetworkLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/network/GenericNetworkLiveApiTest.java deleted file mode 100644 index 1f8f3d1..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/GenericNetworkLiveApiTest.java +++ /dev/null @@ -1,79 +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.domain.network; - -import static com.google.common.collect.Iterables.get; -import static com.google.common.collect.Iterables.size; -import static org.jclouds.abiquo.util.Assert.assertHasError; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import javax.ws.rs.core.Response.Status; - -import org.jclouds.abiquo.domain.exception.AbiquoException; -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.testng.annotations.Test; - -import com.abiquo.model.enumerator.NetworkType; - -/** - * Live integration tests for the {@link Network} domain class. - */ -@Test(groups = "api", testName = "GenericNetworkLiveApiTest") -public class GenericNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest { - public void testListDatacenterNetworks() { - // Make sure all network types are listed - Iterable<Network<?>> networks = env.datacenter.listNetworks(); - assertNotNull(networks); - assertEquals(size(networks), 3); - } - - public void testListPublicNetworks() { - Iterable<Network<?>> networks = env.datacenter.listNetworks(NetworkType.PUBLIC); - assertNotNull(networks); - assertEquals(size(networks), 1); - - // Make sure it can be converted - get(networks, 0).toPublicNetwork(); - } - - public void testListExternaletworks() { - Iterable<Network<?>> networks = env.datacenter.listNetworks(NetworkType.EXTERNAL); - assertNotNull(networks); - assertEquals(size(networks), 1); - - // Make sure it can be converted - get(networks, 0).toExternalNetwork(); - } - - public void testListUnmanagedNetworks() { - Iterable<Network<?>> networks = env.datacenter.listNetworks(NetworkType.UNMANAGED); - assertNotNull(networks); - assertEquals(size(networks), 1); - - // Make sure it can be converted - get(networks, 0).toUnmanagedNetwork(); - } - - public void testListPrivateNetworks() { - try { - env.datacenter.listNetworks(NetworkType.INTERNAL); - } catch (AbiquoException ex) { - assertHasError(ex, Status.BAD_REQUEST, "QUERY-1"); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PrivateNetworkLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PrivateNetworkLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PrivateNetworkLiveApiTest.java deleted file mode 100644 index 532a919..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PrivateNetworkLiveApiTest.java +++ /dev/null @@ -1,146 +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.domain.network; - -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.jclouds.abiquo.util.Assert.assertHasError; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.fail; - -import javax.ws.rs.core.Response.Status; - -import org.jclouds.abiquo.domain.PaginatedCollection; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.exception.AbiquoException; -import org.jclouds.abiquo.domain.network.options.IpOptions; -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.jclouds.abiquo.predicates.IpPredicates; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.abiquo.server.core.infrastructure.network.PrivateIpDto; -import com.abiquo.server.core.infrastructure.network.PrivateIpsDto; - -/** - * Live integration tests for the {@link PrivateNetwork} domain class. - */ -@Test(groups = "api", testName = "PrivateNetworkLiveApiTest") -public class PrivateNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest { - private PrivateNetwork privateNetwork; - - @BeforeClass - public void setupNetwork() { - privateNetwork = createNetwork(env.virtualDatacenter, env.privateNetwork, PREFIX + "-privatenetwork-test"); - } - - @AfterClass - public void tearDownNetwork() { - privateNetwork.delete(); - } - - public void testListIps() { - PaginatedCollection<PrivateIpDto, PrivateIpsDto> ipsDto = env.context.getApiContext().getApi().getCloudApi() - .listPrivateNetworkIps(privateNetwork.unwrap(), IpOptions.builder().limit(1).build()); - int totalIps = ipsDto.getTotalSize(); - - Iterable<PrivateIp> ips = privateNetwork.listIps(); - assertEquals(size(ips), totalIps); - } - - public void testListIpsWithOptions() { - Iterable<PrivateIp> ips = privateNetwork.listIps(IpOptions.builder().limit(5).build()); - assertEquals(size(ips), 5); - } - - public void testListUnusedIps() { - PaginatedCollection<PrivateIpDto, PrivateIpsDto> ipsDto = env.context.getApiContext().getApi().getCloudApi() - .listPrivateNetworkIps(privateNetwork.unwrap(), IpOptions.builder().limit(1).build()); - int totalIps = ipsDto.getTotalSize(); - - Iterable<PrivateIp> ips = privateNetwork.listUnusedIps(); - assertEquals(size(ips), totalIps); - } - - public void testUpdateBasicInfo() { - privateNetwork.setName("Private network Updated"); - privateNetwork.setPrimaryDNS("8.8.8.8"); - privateNetwork.setSecondaryDNS("8.8.8.8"); - privateNetwork.update(); - - assertEquals(privateNetwork.getName(), "Private network Updated"); - assertEquals(privateNetwork.getPrimaryDNS(), "8.8.8.8"); - assertEquals(privateNetwork.getSecondaryDNS(), "8.8.8.8"); - - // Refresh the private network - PrivateNetwork pn = env.virtualDatacenter.getPrivateNetwork(privateNetwork.getId()); - - assertEquals(pn.getName(), "Private network Updated"); - assertEquals(pn.getPrimaryDNS(), "8.8.8.8"); - assertEquals(pn.getSecondaryDNS(), "8.8.8.8"); - } - - public void testUpdateReadOnlyFields() { - PrivateNetwork toUpdate = createNetwork(env.virtualDatacenter, privateNetwork, PREFIX + "-privtoupdate-test"); - - try { - toUpdate.setTag(20); - toUpdate.setAddress("10.1.1.0"); - toUpdate.setMask(16); - toUpdate.update(); - - fail("Tag field should not be editable"); - } catch (AbiquoException ex) { - assertHasError(ex, Status.CONFLICT, "VLAN-10"); - } finally { - toUpdate.delete(); - } - } - - public void testUpdateWithInvalidValues() { - PrivateNetwork toUpdate = createNetwork(env.virtualDatacenter, privateNetwork, PREFIX + "-privtoupdate-test"); - - try { - toUpdate.setMask(60); - toUpdate.update(); - - fail("Invalid mask value"); - } catch (AbiquoException ex) { - assertHasError(ex, Status.BAD_REQUEST, "CONSTR-MAX"); - } finally { - toUpdate.delete(); - } - } - - public void testGetNetworkFromIp() { - PrivateIp ip = find(privateNetwork.listIps(), IpPredicates.<PrivateIp> notUsed()); - PrivateNetwork network = ip.getNetwork(); - - assertEquals(network.getId(), privateNetwork.getId()); - } - - private PrivateNetwork createNetwork(final VirtualDatacenter vdc, final PrivateNetwork from, final String name) { - PrivateNetwork network = PrivateNetwork.Builder.fromPrivateNetwork(from).virtualDatacenter(vdc).build(); - network.setName(name); - network.save(); - assertNotNull(network.getId()); - return network; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PublicNetworkLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PublicNetworkLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PublicNetworkLiveApiTest.java deleted file mode 100644 index e655f5d..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/PublicNetworkLiveApiTest.java +++ /dev/null @@ -1,150 +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.domain.network; - -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.jclouds.abiquo.util.Assert.assertHasError; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.fail; - -import javax.ws.rs.core.Response.Status; - -import org.jclouds.abiquo.domain.PaginatedCollection; -import org.jclouds.abiquo.domain.exception.AbiquoException; -import org.jclouds.abiquo.domain.network.options.IpOptions; -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.jclouds.abiquo.predicates.IpPredicates; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.abiquo.server.core.infrastructure.network.PublicIpDto; -import com.abiquo.server.core.infrastructure.network.PublicIpsDto; - -/** - * Live integration tests for the {@link PublicNetwork} domain class. - */ -@Test(groups = "api", testName = "PublicNetworkLiveApiTest") -public class PublicNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest { - private PublicNetwork publicNetwork; - - @BeforeClass - public void setupNetwork() { - publicNetwork = createNetwork(env.publicNetwork, PREFIX + "-publicnetwork-test"); - } - - @AfterClass - public void tearDownNetwork() { - publicNetwork.delete(); - } - - public void testListIps() { - PaginatedCollection<PublicIpDto, PublicIpsDto> ipsDto = env.context.getApiContext().getApi() - .getInfrastructureApi().listPublicIps(publicNetwork.unwrap(), IpOptions.builder().limit(1).build()); - int totalIps = ipsDto.getTotalSize(); - - Iterable<PublicIp> ips = publicNetwork.listIps(); - assertEquals(size(ips), totalIps); - } - - public void testListIpsWithOptions() { - Iterable<PublicIp> ips = publicNetwork.listIps(IpOptions.builder().limit(5).build()); - assertEquals(size(ips), 5); - } - - public void testListUnusedIps() { - PaginatedCollection<PublicIpDto, PublicIpsDto> ipsDto = env.context.getApiContext().getApi() - .getInfrastructureApi().listPublicIps(publicNetwork.unwrap(), IpOptions.builder().limit(1).build()); - int totalIps = ipsDto.getTotalSize(); - - Iterable<PublicIp> ips = publicNetwork.listUnusedIps(); - assertEquals(size(ips), totalIps); - } - - public void testUpdateBasicInfo() { - publicNetwork.setName("Public network Updated"); - publicNetwork.setPrimaryDNS("8.8.8.8"); - publicNetwork.setSecondaryDNS("8.8.8.8"); - publicNetwork.update(); - - assertEquals(publicNetwork.getName(), "Public network Updated"); - assertEquals(publicNetwork.getPrimaryDNS(), "8.8.8.8"); - assertEquals(publicNetwork.getSecondaryDNS(), "8.8.8.8"); - - // Refresh the public network - PublicNetwork pn = env.datacenter.getNetwork(publicNetwork.getId()).toPublicNetwork(); - - assertEquals(pn.getId(), publicNetwork.getId()); - assertEquals(pn.getName(), "Public network Updated"); - assertEquals(pn.getPrimaryDNS(), "8.8.8.8"); - assertEquals(pn.getSecondaryDNS(), "8.8.8.8"); - } - - public void testUpdateReadOnlyFields() { - PublicNetwork toUpdate = createNetwork(publicNetwork, PREFIX + "-pubtoupdate-test"); - - try { - toUpdate.setTag(20); - toUpdate.setAddress("80.81.81.0"); - toUpdate.setMask(16); - toUpdate.update(); - - fail("Tag field should not be editable"); - } catch (AbiquoException ex) { - assertHasError(ex, Status.CONFLICT, "VLAN-19"); - } finally { - toUpdate.delete(); - } - } - - public void testUpdateWithInvalidValues() { - PublicNetwork toUpdate = createNetwork(publicNetwork, PREFIX + "-pubtoupdate-test"); - - try { - toUpdate.setMask(60); - toUpdate.update(); - - fail("Invalid mask value"); - } catch (AbiquoException ex) { - assertHasError(ex, Status.BAD_REQUEST, "CONSTR-MAX"); - } finally { - toUpdate.delete(); - } - } - - public void testGetDatacenter() { - assertEquals(publicNetwork.getDatacenter().getId(), env.datacenter.getId()); - } - - public void testGetNetworkFromIp() { - PublicIp ip = find(publicNetwork.listIps(), IpPredicates.<PublicIp> notUsed()); - PublicNetwork network = ip.getNetwork(); - - assertEquals(network.getId(), publicNetwork.getId()); - } - - private PublicNetwork createNetwork(final PublicNetwork from, final String name) { - PublicNetwork network = PublicNetwork.Builder.fromPublicNetwork(from).build(); - network.setName(name); - network.save(); - assertNotNull(network.getId()); - return network; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/network/UnmanagedNetworkLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/UnmanagedNetworkLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/network/UnmanagedNetworkLiveApiTest.java deleted file mode 100644 index 2fb06ee..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/network/UnmanagedNetworkLiveApiTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.domain.network; - -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.jclouds.abiquo.util.Assert.assertHasError; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; -import static org.testng.Assert.fail; - -import javax.ws.rs.core.Response.Status; - -import org.jclouds.abiquo.domain.PaginatedCollection; -import org.jclouds.abiquo.domain.exception.AbiquoException; -import org.jclouds.abiquo.domain.network.options.IpOptions; -import org.jclouds.abiquo.internal.BaseAbiquoApiLiveApiTest; -import org.jclouds.abiquo.predicates.IpPredicates; -import org.testng.annotations.AfterClass; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; - -import com.abiquo.server.core.infrastructure.network.UnmanagedIpDto; -import com.abiquo.server.core.infrastructure.network.UnmanagedIpsDto; -import com.google.common.base.Predicate; - -/** - * Live integration tests for the {@link UnmanagedNetwork} domain class. - */ -@Test(groups = "api", testName = "UnmanagedNetworkLiveApiTest") -public class UnmanagedNetworkLiveApiTest extends BaseAbiquoApiLiveApiTest { - private UnmanagedNetwork unmanagedNetwork; - - @BeforeClass - public void setupNetwork() { - unmanagedNetwork = createNetwork(env.unmanagedNetwork, PREFIX + "-unmanagednetwork-test"); - } - - @AfterClass - public void tearDownNetwork() { - unmanagedNetwork.delete(); - } - - public void testListIps() { - PaginatedCollection<UnmanagedIpDto, UnmanagedIpsDto> ipsDto = env.context.getApiContext().getApi() - .getInfrastructureApi().listUnmanagedIps(unmanagedNetwork.unwrap(), IpOptions.builder().limit(1).build()); - int totalIps = ipsDto.getTotalSize(); - - Iterable<UnmanagedIp> ips = unmanagedNetwork.listIps(); - assertEquals(size(ips), totalIps); - } - - public void testListIpsWithOptions() { - Iterable<UnmanagedIp> ips = unmanagedNetwork.listIps(IpOptions.builder().limit(5).build()); - // Unmanaged networks do not have IPs until attached to VMs - assertEquals(size(ips), 0); - } - - public void testListUnusedIps() { - PaginatedCollection<UnmanagedIpDto, UnmanagedIpsDto> ipsDto = env.context.getApiContext().getApi() - .getInfrastructureApi().listUnmanagedIps(unmanagedNetwork.unwrap(), IpOptions.builder().limit(1).build()); - int totalIps = ipsDto.getTotalSize(); - - Iterable<UnmanagedIp> ips = unmanagedNetwork.listUnusedIps(); - assertEquals(size(ips), totalIps); - } - - public void testUpdateBasicInfo() { - unmanagedNetwork.setName("Unmanaged network Updated"); - unmanagedNetwork.setPrimaryDNS("8.8.8.8"); - unmanagedNetwork.setSecondaryDNS("8.8.8.8"); - unmanagedNetwork.update(); - - assertEquals(unmanagedNetwork.getName(), "Unmanaged network Updated"); - assertEquals(unmanagedNetwork.getPrimaryDNS(), "8.8.8.8"); - assertEquals(unmanagedNetwork.getSecondaryDNS(), "8.8.8.8"); - - // Refresh the unmanaged network - UnmanagedNetwork en = find(env.enterprise.listUnmanagedNetworks(env.datacenter), - new Predicate<UnmanagedNetwork>() { - @Override - public boolean apply(UnmanagedNetwork input) { - return input.getName().equals(unmanagedNetwork.getName()); - } - }); - - assertEquals(en.getId(), unmanagedNetwork.getId()); - assertEquals(en.getName(), "Unmanaged network Updated"); - assertEquals(en.getPrimaryDNS(), "8.8.8.8"); - assertEquals(en.getSecondaryDNS(), "8.8.8.8"); - } - - public void testUpdateReadOnlyFields() { - UnmanagedNetwork toUpdate = createNetwork(unmanagedNetwork, PREFIX + "-umtoupdate-test"); - - try { - toUpdate.setTag(20); - toUpdate.setAddress("10.2.0.0"); - toUpdate.setMask(16); - toUpdate.update(); - - fail("Tag field should not be editable"); - } catch (AbiquoException ex) { - assertHasError(ex, Status.CONFLICT, "VLAN-19"); - } finally { - toUpdate.delete(); - } - } - - public void testUpdateWithInvalidValues() { - UnmanagedNetwork toUpdate = createNetwork(unmanagedNetwork, PREFIX + "-umtoupdate-test"); - - try { - toUpdate.setMask(60); - toUpdate.update(); - - fail("Invalid mask value"); - } catch (AbiquoException ex) { - assertHasError(ex, Status.BAD_REQUEST, "CONSTR-MAX"); - } finally { - toUpdate.delete(); - } - } - - public void testGetEnterprise() { - assertEquals(unmanagedNetwork.getEnterprise().getId(), env.enterprise.getId()); - } - - public void testGetDatacenter() { - assertEquals(unmanagedNetwork.getDatacenter().getId(), env.datacenter.getId()); - } - - public void testGetNetworkFromIp() { - UnmanagedIp ip = find(unmanagedNetwork.listIps(), IpPredicates.<UnmanagedIp> notUsed(), null); - // Unmanaged networks do not have IPs until attached to VMs - assertNull(ip); - } - - private UnmanagedNetwork createNetwork(final UnmanagedNetwork from, final String name) { - UnmanagedNetwork network = UnmanagedNetwork.Builder.fromUnmanagedNetwork(from).build(); - network.setName(name); - network.save(); - assertNotNull(network.getId()); - return network; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/environment/CloudTestEnvironment.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/environment/CloudTestEnvironment.java b/abiquo/src/test/java/org/jclouds/abiquo/environment/CloudTestEnvironment.java deleted file mode 100644 index 72dd187..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/environment/CloudTestEnvironment.java +++ /dev/null @@ -1,221 +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.base.Preconditions.checkNotNull; -import static com.google.common.collect.Iterables.find; -import static com.google.common.collect.Iterables.isEmpty; -import static org.jclouds.abiquo.reference.AbiquoTestConstants.PREFIX; -import static org.testng.Assert.assertFalse; -import static org.testng.Assert.assertNotNull; -import static org.testng.Assert.assertNull; - -import org.jclouds.ContextBuilder; -import org.jclouds.abiquo.AbiquoApiMetadata; -import org.jclouds.abiquo.AbiquoContext; -import org.jclouds.abiquo.domain.cloud.VirtualAppliance; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.cloud.VirtualMachine; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; -import org.jclouds.abiquo.domain.enterprise.Enterprise; -import org.jclouds.abiquo.domain.network.PrivateNetwork; -import org.jclouds.abiquo.features.CloudApi; -import org.jclouds.abiquo.features.services.EventService; - -import com.google.common.base.Predicate; -import com.google.common.collect.Ordering; -import com.google.common.primitives.Longs; - -/** - * Test environment for cloud live tests. - */ -public class CloudTestEnvironment extends InfrastructureTestEnvironment { - - // Environment data made public so tests can use them easily - public CloudApi cloudApi; - - public EventService eventService; - - public VirtualDatacenter virtualDatacenter; - - public VirtualAppliance virtualAppliance; - - public VirtualMachine virtualMachine; - - public VirtualMachineTemplate template; - - public PrivateNetwork privateNetwork; - - public Enterprise defaultEnterprise; - - public AbiquoContext plainUserContext; - - public AbiquoContext enterpriseAdminContext; - - public CloudTestEnvironment(final AbiquoContext context) { - super(context); - this.cloudApi = context.getApiContext().getApi().getCloudApi(); - this.eventService = context.getEventService(); - } - - @Override - public void setup() throws Exception { - // Create base infrastructure - super.setup(); - - createUserContext(); - createEnterpriseAdminContext(); - - findDefaultEnterprise(); - createVirtualDatacenter(); - createVirtualAppliance(); - refreshTemplateRepository(); - createVirtualMachine(); - } - - @Override - public void tearDown() throws Exception { - closeEnterpriseAdminContext(); - closeUserContext(); - - deleteVirtualMachine(); - deleteVirtualAppliance(); - deleteVirtualDatacenter(); - - // Delete base infrastructure - super.tearDown(); - } - - // Setup - - private void createUserContext() { - String endpoint = checkNotNull(System.getProperty("test.abiquo.endpoint"), "test.abiquo.endpoint"); - - plainUserContext = ContextBuilder.newBuilder(new AbiquoApiMetadata()) // - .endpoint(endpoint) // - .credentials("abiquo", "jclouds") // - .build(AbiquoContext.class); - } - - private void createEnterpriseAdminContext() { - String endpoint = checkNotNull(System.getProperty("test.abiquo.endpoint"), "test.abiquo.endpoint"); - - enterpriseAdminContext = ContextBuilder.newBuilder(new AbiquoApiMetadata()) // - .endpoint(endpoint) // - .credentials("jclouds-admin", "admin") // - .build(AbiquoContext.class); - } - - protected void findDefaultEnterprise() { - defaultEnterprise = find(context.getAdministrationService().listEnterprises(), new Predicate<Enterprise>() { - @Override - public boolean apply(Enterprise input) { - return input.getName().equals("Abiquo"); - } - }); - } - - protected void createVirtualDatacenter() { - privateNetwork = PrivateNetwork.builder(context.getApiContext()).name("DefaultNetwork").gateway("192.168.1.1") - .address("192.168.1.0").mask(24).build(); - - virtualDatacenter = VirtualDatacenter.builder(context.getApiContext(), datacenter, defaultEnterprise) - .name(PREFIX + "Virtual Aloha").cpuCountLimits(18, 20).hdLimitsInMb(279172872, 279172872) - .publicIpsLimits(2, 3).ramLimits(19456, 20480).storageLimits(289910292, 322122547).vlansLimits(3, 4) - .hypervisorType(machine.getType()).network(privateNetwork).build(); - - virtualDatacenter.save(); - assertNotNull(virtualDatacenter.getId()); - - privateNetwork = find(virtualDatacenter.listPrivateNetworks(), new Predicate<PrivateNetwork>() { - @Override - public boolean apply(PrivateNetwork input) { - return input.getName().equals(privateNetwork.getName()); - } - }); - } - - protected void createVirtualAppliance() { - virtualAppliance = VirtualAppliance.builder(context.getApiContext(), virtualDatacenter) - .name(PREFIX + "Virtual AppAloha").build(); - - virtualAppliance.save(); - assertNotNull(virtualAppliance.getId()); - } - - protected void createVirtualMachine() { - Iterable<VirtualMachineTemplate> templates = virtualDatacenter.listAvailableTemplates(); - assertFalse(isEmpty(templates)); - - template = templateBySize().min(templates); - - virtualMachine = VirtualMachine.builder(context.getApiContext(), virtualAppliance, template).cpu(2) - .nameLabel(PREFIX + "VM Aloha").ram(128).build(); - - virtualMachine.save(); - assertNotNull(virtualMachine.getId()); - - } - - protected void refreshTemplateRepository() { - defaultEnterprise.refreshTemplateRepository(datacenter); - } - - // Tear down - - private void closeUserContext() { - plainUserContext.close(); - } - - private void closeEnterpriseAdminContext() { - enterpriseAdminContext.close(); - } - - protected void deleteVirtualDatacenter() { - if (virtualDatacenter != null && enterprise != null && datacenter != null) { - Integer idVirtualDatacenter = virtualDatacenter.getId(); - virtualDatacenter.delete(); - assertNull(cloudApi.getVirtualDatacenter(idVirtualDatacenter)); - } - } - - protected void deleteVirtualAppliance() { - if (virtualAppliance != null && virtualDatacenter != null) { - Integer idVirtualAppliance = virtualAppliance.getId(); - virtualAppliance.delete(); - assertNull(cloudApi.getVirtualAppliance(virtualDatacenter.unwrap(), idVirtualAppliance)); - } - } - - protected void deleteVirtualMachine() { - if (virtualMachine != null && virtualAppliance != null && virtualDatacenter != null) { - Integer idVirtualMachine = virtualMachine.getId(); - virtualMachine.delete(); - assertNull(cloudApi.getVirtualMachine(virtualAppliance.unwrap(), idVirtualMachine)); - } - } - - public static Ordering<VirtualMachineTemplate> templateBySize() { - return new Ordering<VirtualMachineTemplate>() { - @Override - public int compare(final VirtualMachineTemplate left, final VirtualMachineTemplate right) { - return Longs.compare(left.getDiskFileSize(), right.getDiskFileSize()); - } - }; - } - -}
