http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVolumeRefsToPayloadTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVolumeRefsToPayloadTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVolumeRefsToPayloadTest.java deleted file mode 100644 index 47d1841..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/cloud/BindVolumeRefsToPayloadTest.java +++ /dev/null @@ -1,77 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.binders.cloud; - -import static org.jclouds.abiquo.domain.DomainUtils.withHeader; -import static org.jclouds.abiquo.util.Assert.assertPayloadEquals; - -import java.io.IOException; -import java.net.URI; - -import org.jclouds.abiquo.domain.CloudResources; -import org.jclouds.http.HttpRequest; -import org.jclouds.xml.internal.JAXBParser; -import org.testng.annotations.Test; - -import com.abiquo.model.transport.LinksDto; -import com.abiquo.server.core.infrastructure.storage.VolumeManagementDto; - -/** - * Unit tests for the {@link BindVolumeRefsToPayload} binder. - */ -@Test(groups = "unit", testName = "BindVolumeRefsToPayloadTest") -public class BindVolumeRefsToPayloadTest { - - @Test(expectedExceptions = NullPointerException.class) - public void testInvalidNullInput() { - BindVolumeRefsToPayload binder = new BindVolumeRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testInvalidTypeInput() { - BindVolumeRefsToPayload binder = new BindVolumeRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.bindToRequest(request, new Object()); - } - - public void testBindEmptyArray() throws IOException { - BindVolumeRefsToPayload binder = new BindVolumeRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - request = binder.bindToRequest(request, new VolumeManagementDto[] {}); - assertPayloadEquals(request.getPayload(), withHeader("<links/>"), LinksDto.class); - } - - public void testBindSingleVolume() throws IOException { - VolumeManagementDto volume = CloudResources.volumePut(); - BindVolumeRefsToPayload binder = new BindVolumeRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - request = binder.bindToRequest(request, new VolumeManagementDto[] { volume }); - assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\"" + volume.getEditLink().getHref() - + "\" rel=\"" + binder.getRelToUse(volume) + "\"/></links>"), LinksDto.class); - } - - public void testBindMultipleVolumes() throws IOException { - VolumeManagementDto volume = CloudResources.volumePut(); - BindVolumeRefsToPayload binder = new BindVolumeRefsToPayload(new JAXBParser("false")); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - request = binder.bindToRequest(request, new VolumeManagementDto[] { volume, volume }); - assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\"" + volume.getEditLink().getHref() - + "\" rel=\"" + binder.getRelToUse(volume) + "\"/></links>"), LinksDto.class); - } -}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPathTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPathTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPathTest.java deleted file mode 100644 index 8b3e4bd..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendMachineIdToPathTest.java +++ /dev/null @@ -1,56 +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.binders.infrastructure; - -import static org.testng.Assert.assertEquals; - -import java.net.URI; - -import org.jclouds.abiquo.functions.infrastructure.ParseMachineId; -import org.jclouds.http.HttpRequest; -import org.testng.annotations.Test; - -import com.abiquo.server.core.infrastructure.MachineDto; - -/** - * Unit tests for the {@link AppendMachineIdToPath} binder. - */ -@Test(groups = "unit", testName = "AppendMachineIdToPathTest") -public class AppendMachineIdToPathTest { - @Test(expectedExceptions = NullPointerException.class) - public void testGetValueWithNullInput() { - AppendMachineIdToPath binder = new AppendMachineIdToPath(new ParseMachineId()); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.getValue(request, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testGetValueWithInvalidInput() { - AppendMachineIdToPath binder = new AppendMachineIdToPath(new ParseMachineId()); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.getValue(request, new Object()); - } - - public void testGetValue() { - AppendMachineIdToPath binder = new AppendMachineIdToPath(new ParseMachineId()); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - - MachineDto machine = new MachineDto(); - machine.setId(5); - assertEquals(binder.getValue(request, machine), "5"); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPathTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPathTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPathTest.java deleted file mode 100644 index f79a431..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/AppendRemoteServiceTypeToPathTest.java +++ /dev/null @@ -1,54 +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.binders.infrastructure; - -import static org.testng.Assert.assertEquals; - -import java.net.URI; - -import org.jclouds.abiquo.functions.infrastructure.ParseRemoteServiceType; -import org.jclouds.http.HttpRequest; -import org.testng.annotations.Test; - -import com.abiquo.model.enumerator.RemoteServiceType; - -/** - * Unit tests for the {@link AppendRemoteServiceTypeToPath} binder. - */ -@Test(groups = "unit", testName = "AppendRemoteServiceTypeToPathTest") -public class AppendRemoteServiceTypeToPathTest { - @Test(expectedExceptions = NullPointerException.class) - public void testGetValueWithNullInput() { - AppendRemoteServiceTypeToPath binder = new AppendRemoteServiceTypeToPath(new ParseRemoteServiceType()); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.getValue(request, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testGetValueWithInvalidInput() { - AppendRemoteServiceTypeToPath binder = new AppendRemoteServiceTypeToPath(new ParseRemoteServiceType()); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - binder.getValue(request, new Object()); - } - - public void testGetValue() { - AppendRemoteServiceTypeToPath binder = new AppendRemoteServiceTypeToPath(new ParseRemoteServiceType()); - HttpRequest request = HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build(); - - assertEquals(binder.getValue(request, RemoteServiceType.VIRTUAL_SYSTEM_MONITOR), "virtualsystemmonitor"); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPathTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPathTest.java b/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPathTest.java deleted file mode 100644 index 41c2386..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/binders/infrastructure/BindSupportedDevicesLinkToPathTest.java +++ /dev/null @@ -1,84 +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.binders.infrastructure; - -import static org.jclouds.reflect.Reflection2.method; -import static org.testng.Assert.assertEquals; - -import java.net.URI; - -import javax.ws.rs.HttpMethod; - -import org.jclouds.abiquo.features.InfrastructureApi; -import org.jclouds.reflect.Invocation; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.Test; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.infrastructure.DatacenterDto; -import com.google.common.collect.ImmutableList; -import com.google.common.reflect.Invokable; - -/** - * Unit tests for the {@link BindSupportedDevicesLinkToPath} class. - */ -@Test(groups = "unit", testName = "BindSupportedDevicesLinkToPathTest") -public class BindSupportedDevicesLinkToPathTest { - @Test(expectedExceptions = NullPointerException.class) - public void testGetNewEnpointNullInput() { - BindSupportedDevicesLinkToPath binder = new BindSupportedDevicesLinkToPath(); - binder.getNewEndpoint(null, null); - } - - @Test(expectedExceptions = IllegalArgumentException.class) - public void testGetNewEnpointInvalidInput() { - BindSupportedDevicesLinkToPath binder = new BindSupportedDevicesLinkToPath(); - binder.getNewEndpoint(null, new Object()); - } - - public void testGetNewEnpoint() throws Exception { - DatacenterDto datacenter = new DatacenterDto(); - datacenter.addLink(new RESTLink("devices", "http://foo/bar")); - - BindSupportedDevicesLinkToPath binder = new BindSupportedDevicesLinkToPath(); - - Invokable<?, ?> withEndpointLink = method(InfrastructureApi.class, "listSupportedStorageDevices", - DatacenterDto.class); - - GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .invocation(Invocation.create(withEndpointLink, ImmutableList.<Object> of(datacenter))) - .method(HttpMethod.GET).endpoint(URI.create("http://foo/bar")).build(); - - assertEquals(binder.getNewEndpoint(request, datacenter), "http://foo/bar/action/supported"); - } - - @Test(expectedExceptions = NullPointerException.class) - public void testGetNewEnpointWithoutLink() throws Exception { - DatacenterDto datacenter = new DatacenterDto(); - - BindSupportedDevicesLinkToPath binder = new BindSupportedDevicesLinkToPath(); - - Invokable<?, ?> withEndpointLink = method(InfrastructureApi.class, "listSupportedStorageDevices", - DatacenterDto.class); - - GeneratedHttpRequest request = GeneratedHttpRequest.builder() - .invocation(Invocation.create(withEndpointLink, ImmutableList.<Object> of(datacenter))) - .method(HttpMethod.GET).endpoint(URI.create("http://foo/bar")).build(); - - assertEquals(binder.getNewEndpoint(request, datacenter), "http://foo/bar/action/supported"); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java b/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java deleted file mode 100644 index f4d0252..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/compute/AbiquoComputeServiceLiveTest.java +++ /dev/null @@ -1,102 +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.compute; - -import static org.jclouds.compute.util.ComputeServiceUtils.getCores; -import static org.testng.Assert.assertEquals; - -import java.util.Properties; - -import org.jclouds.Constants; -import org.jclouds.compute.domain.ComputeType; -import org.jclouds.compute.domain.ExecResponse; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.internal.BaseComputeServiceLiveTest; -import org.jclouds.logging.config.LoggingModule; -import org.jclouds.logging.slf4j.config.SLF4JLoggingModule; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Module; - -/** - * Live tests for the Abiquo ComputeService. - */ -@Test(groups = "live", testName = "AbiquoComputeServiceLiveTest", singleThreaded = true) -// Since the base class has test configuration, even if we disable tests here, -// or comment them out, the ones in the base class will be executed. -// This class is still a work in progress and will fail until the race condition -// (when creating the virtual appliance) in the AbiquoComputeServiceAdapter is -// fixed and a proper test environment is configured. -public abstract class AbiquoComputeServiceLiveTest extends BaseComputeServiceLiveTest { - public AbiquoComputeServiceLiveTest() { - provider = "abiquo"; - } - - @Override - protected Properties setupProperties() { - Properties overrides = super.setupProperties(); - overrides.put(Constants.PROPERTY_MAX_RETRIES, "0"); - return overrides; - } - - @Override - protected LoggingModule getLoggingModule() { - return new SLF4JLoggingModule(); - } - - @Override - protected Module getSshModule() { - return new SshjSshClientModule(); - } - - @Override - public void testListSizes() throws Exception { - for (Hardware hardware : client.listHardwareProfiles()) { - assert hardware.getProviderId() != null : hardware; - assert getCores(hardware) > 0 : hardware; - assert hardware.getVolumes().size() >= 0 : hardware; - // There are some small images in Abiquo that have less than 1GB of RAM - // assert hardware.getRam() > 0 : hardware; - assertEquals(hardware.getType(), ComputeType.HARDWARE); - } - } - - // Abiquo does not set the hostname - @Override - protected void checkResponseEqualsHostname(final ExecResponse execResponse, final NodeMetadata node) { - assert node.getHostname() == null : node + " with hostname: " + node.getHostname(); - } - - // Abiquo does not support metadata - @Override - protected void checkUserMetadataContains(final NodeMetadata node, final ImmutableMap<String, String> userMetadata) { - assert node.getUserMetadata().equals(ImmutableMap.<String, String> of()) : String.format( - "node userMetadata did not match %s %s", userMetadata, node); - } - - // Abiquo does not support tags - @Override - protected void checkTagsInNodeEquals(final NodeMetadata node, final ImmutableSet<String> tags) { - assert node.getTags().equals(ImmutableSet.<String> of()) : String.format("node tags did not match %s %s", tags, - node); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/DatacenterToLocationTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/DatacenterToLocationTest.java b/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/DatacenterToLocationTest.java deleted file mode 100644 index 105cc7d..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/DatacenterToLocationTest.java +++ /dev/null @@ -1,46 +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.compute.functions; - -import static org.testng.Assert.assertEquals; - -import org.easymock.EasyMock; -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.domain.Location; -import org.jclouds.domain.LocationScope; -import org.jclouds.rest.ApiContext; -import org.testng.annotations.Test; - -/** - * Unit tests for the {@link DatacenterToLocation} function. - */ -@Test(groups = "unit", testName = "DatacenterToLocationTest") -public class DatacenterToLocationTest { - @SuppressWarnings("unchecked") - public void testDatacenterToLocation() { - ApiContext<AbiquoApi> context = EasyMock.createMock(ApiContext.class); - DatacenterToLocation function = new DatacenterToLocation(); - - Datacenter datacenter = Datacenter.builder(context).name("dc").location("New York").build(); - datacenter.unwrap().setId(5); - Location location = function.apply(datacenter); - - assertEquals(location.getId(), "5"); - assertEquals(location.getScope(), LocationScope.REGION); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualDatacenterToLocationTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualDatacenterToLocationTest.java b/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualDatacenterToLocationTest.java deleted file mode 100644 index 5b7beb1..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualDatacenterToLocationTest.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.compute.functions; - -import static org.easymock.EasyMock.anyObject; -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 java.util.Collections; -import java.util.Map; - -import org.easymock.EasyMock; -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.enterprise.Enterprise; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.abiquo.domain.network.PrivateNetwork; -import org.jclouds.domain.Location; -import org.jclouds.domain.LocationScope; -import org.jclouds.rest.ApiContext; -import org.testng.annotations.Test; - -import com.google.common.base.Function; -import com.google.common.base.Supplier; - -/** - * Unit tests for the {@link VirtualDatacenterToLocation} function. - */ -@Test(groups = "unit", testName = "VirtualDatacenterToLocationTest") -public class VirtualDatacenterToLocationTest { - public void testVirtualDatacenterToLocation() { - Function<Datacenter, Location> dcToLocation = mockDatacenterToLocation(); - Supplier<Map<Integer, Datacenter>> regionMap = mockRegionMap(); - VirtualDatacenterToLocation function = new VirtualDatacenterToLocation(dcToLocation, regionMap); - - VirtualDatacenter vdc = mockVirtualDatacenter(); - - Location location = function.apply(vdc); - - verify(regionMap); - verify(dcToLocation); - - assertEquals(location.getId(), "5"); - assertEquals(location.getScope(), LocationScope.ZONE); - } - - @SuppressWarnings("unchecked") - private static VirtualDatacenter mockVirtualDatacenter() { - ApiContext<AbiquoApi> context = EasyMock.createMock(ApiContext.class); - Datacenter datacenter = EasyMock.createMock(Datacenter.class); - Enterprise enterprise = EasyMock.createMock(Enterprise.class); - PrivateNetwork network = EasyMock.createMock(PrivateNetwork.class); - - VirtualDatacenter vdc = VirtualDatacenter.builder(context, datacenter, enterprise) // - .network(network) // - .name("mock").build(); - vdc.unwrap().setId(5); - - return vdc; - } - - @SuppressWarnings("unchecked") - private static Function<Datacenter, Location> mockDatacenterToLocation() { - Function<Datacenter, Location> mock = EasyMock.createMock(Function.class); - expect(mock.apply(anyObject(Datacenter.class))).andReturn(null); - replay(mock); - return mock; - } - - @SuppressWarnings("unchecked") - private static Supplier<Map<Integer, Datacenter>> mockRegionMap() { - Supplier<Map<Integer, Datacenter>> mock = EasyMock.createMock(Supplier.class); - expect(mock.get()).andReturn(Collections.EMPTY_MAP); - replay(mock); - return mock; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeStateTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeStateTest.java b/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeStateTest.java deleted file mode 100644 index 0cbcb62..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineStateToNodeStateTest.java +++ /dev/null @@ -1,43 +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.compute.functions; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.compute.domain.NodeMetadata.Status; -import org.testng.annotations.Test; - -import com.abiquo.server.core.cloud.VirtualMachineState; - -/** - * Unit tests for the {@link VirtualMachineStateToNodeState} function. - */ -@Test(groups = "unit", testName = "VirtualMachineStateToNodeStateTest") -public class VirtualMachineStateToNodeStateTest { - public void testVirtualMachineStateToNodeState() { - VirtualMachineStateToNodeState function = new VirtualMachineStateToNodeState(); - - assertEquals(function.apply(VirtualMachineState.ALLOCATED), Status.PENDING); - assertEquals(function.apply(VirtualMachineState.LOCKED), Status.PENDING); - assertEquals(function.apply(VirtualMachineState.CONFIGURED), Status.PENDING); - assertEquals(function.apply(VirtualMachineState.ON), Status.RUNNING); - assertEquals(function.apply(VirtualMachineState.OFF), Status.SUSPENDED); - assertEquals(function.apply(VirtualMachineState.PAUSED), Status.SUSPENDED); - assertEquals(function.apply(VirtualMachineState.NOT_ALLOCATED), Status.PENDING); - assertEquals(function.apply(VirtualMachineState.UNKNOWN), Status.UNRECOGNIZED); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateInVirtualDatacenterToHardwareTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateInVirtualDatacenterToHardwareTest.java b/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateInVirtualDatacenterToHardwareTest.java deleted file mode 100644 index 8a7bd4a..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateInVirtualDatacenterToHardwareTest.java +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.jclouds.abiquo.compute.functions; - -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.jclouds.abiquo.domain.DomainWrapper.wrap; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; - -import java.net.URI; - -import org.easymock.EasyMock; -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.cloud.VirtualDatacenter; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplateInVirtualDatacenter; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.Volume; -import org.jclouds.domain.Location; -import org.jclouds.rest.ApiContext; -import org.testng.annotations.Test; - -import com.abiquo.model.enumerator.HypervisorType; -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; -import com.abiquo.server.core.cloud.VirtualDatacenterDto; -import com.google.common.base.Function; - -/** - * Unit tests for the - * {@link VirtualMachineTemplateInVirtualDatacenterToHardware} function. - */ -@Test(groups = "unit", testName = "VirtualMachineTemplateInVirtualDatacenterToHardwareTest") -public class VirtualMachineTemplateInVirtualDatacenterToHardwareTest { - @SuppressWarnings("unchecked") - public void testVirtualMachineTemplateToHardware() { - ApiContext<AbiquoApi> context = EasyMock.createMock(ApiContext.class); - Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation(); - VirtualMachineTemplateInVirtualDatacenterToHardware function = new VirtualMachineTemplateInVirtualDatacenterToHardware( - vdcToLocation); - - VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); - dto.setId(5); - dto.setName("Template"); - dto.setDescription("Template description"); - dto.setHdRequired(50L * 1024 * 1024 * 1024); // 50 GB - dto.setCpuRequired(5); - dto.setRamRequired(2048); - dto.addLink(new RESTLink("edit", "http://foo/bar")); - VirtualMachineTemplate template = wrap(context, VirtualMachineTemplate.class, dto); - - VirtualDatacenterDto vdcDto = new VirtualDatacenterDto(); - vdcDto.setId(6); - vdcDto.setHypervisorType(HypervisorType.VMX_04); - VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto); - - Hardware hardware = function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc)); - - verify(vdcToLocation); - - assertEquals(hardware.getProviderId(), template.getId().toString()); - assertEquals(hardware.getId(), template.getId() + "/" + vdc.getId()); - assertEquals(hardware.getName(), template.getName()); - assertEquals(hardware.getUri(), URI.create("http://foo/bar")); - - assertEquals(hardware.getRam(), template.getRamRequired().intValue()); - assertEquals(hardware.getProcessors().size(), 1); - assertEquals(hardware.getProcessors().get(0).getCores(), (double) template.getCpuRequired()); - assertEquals(hardware.getProcessors().get(0).getSpeed(), - VirtualMachineTemplateInVirtualDatacenterToHardware.DEFAULT_CORE_SPEED); - - assertEquals(hardware.getVolumes().size(), 1); - assertEquals(hardware.getVolumes().get(0).getSize(), 50F); - assertEquals(hardware.getVolumes().get(0).getType(), Volume.Type.LOCAL); - assertEquals(hardware.getVolumes().get(0).isBootDevice(), true); - assertEquals(hardware.getVolumes().get(0).isDurable(), false); - } - - @SuppressWarnings("unchecked") - public void testConvertWithoutEditLink() { - ApiContext<AbiquoApi> context = EasyMock.createMock(ApiContext.class); - Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation(); - VirtualMachineTemplateInVirtualDatacenterToHardware function = new VirtualMachineTemplateInVirtualDatacenterToHardware( - vdcToLocation); - - VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); - dto.setId(5); - dto.setName("Template"); - dto.setDescription("Template description"); - dto.setHdRequired(50L * 1024 * 1024 * 1024); // 50 GB - dto.setCpuRequired(5); - dto.setRamRequired(2048); - VirtualMachineTemplate template = wrap(context, VirtualMachineTemplate.class, dto); - - VirtualDatacenterDto vdcDto = new VirtualDatacenterDto(); - vdcDto.setId(6); - vdcDto.setHypervisorType(HypervisorType.VMX_04); - VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, vdcDto); - - Hardware hardware = function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc)); - - verify(vdcToLocation); - - assertNull(hardware.getUri()); - } - - @SuppressWarnings("unchecked") - @Test(expectedExceptions = NullPointerException.class) - public void testConvertWithoutId() { - ApiContext<AbiquoApi> context = EasyMock.createMock(ApiContext.class); - Function<VirtualDatacenter, Location> vdcToLocation = mockVirtualDatacenterToLocation(); - VirtualMachineTemplateInVirtualDatacenterToHardware function = new VirtualMachineTemplateInVirtualDatacenterToHardware( - vdcToLocation); - - VirtualMachineTemplate template = wrap(context, VirtualMachineTemplate.class, new VirtualMachineTemplateDto()); - VirtualDatacenter vdc = wrap(context, VirtualDatacenter.class, new VirtualDatacenterDto()); - - function.apply(new VirtualMachineTemplateInVirtualDatacenter(template, vdc)); - } - - @SuppressWarnings("unchecked") - private static Function<VirtualDatacenter, Location> mockVirtualDatacenterToLocation() { - Function<VirtualDatacenter, Location> mock = EasyMock.createMock(Function.class); - expect(mock.apply(anyObject(VirtualDatacenter.class))).andReturn(null); - replay(mock); - return mock; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImageTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImageTest.java b/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImageTest.java deleted file mode 100644 index a684039..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineTemplateToImageTest.java +++ /dev/null @@ -1,125 +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.compute.functions; - -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.jclouds.abiquo.domain.DomainWrapper.wrap; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNull; - -import java.net.URI; -import java.util.Collections; -import java.util.Map; - -import org.easymock.EasyMock; -import org.jclouds.abiquo.AbiquoApi; -import org.jclouds.abiquo.domain.cloud.VirtualMachineTemplate; -import org.jclouds.abiquo.domain.infrastructure.Datacenter; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.OperatingSystem; -import org.jclouds.domain.Location; -import org.jclouds.rest.ApiContext; -import org.testng.annotations.Test; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.appslibrary.VirtualMachineTemplateDto; -import com.google.common.base.Function; -import com.google.common.base.Supplier; - -/** - * Unit tests for the {@link VirtualMachineTemplateToImage} class. - */ -@Test(groups = "unit", testName = "VirtualMachineTemplateToImageTest") -public class VirtualMachineTemplateToImageTest { - @SuppressWarnings("unchecked") - public void testVirtualMachineTemplateToImage() { - ApiContext<AbiquoApi> context = EasyMock.createMock(ApiContext.class); - Function<Datacenter, Location> dcToLocation = mockDatacenterToLocation(); - Supplier<Map<Integer, Datacenter>> regionMap = mockRegionMap(); - VirtualMachineTemplateToImage function = new VirtualMachineTemplateToImage(dcToLocation, regionMap); - - VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); - dto.setId(5); - dto.setName("Template"); - dto.setDescription("Template description"); - dto.addLink(new RESTLink("diskfile", "http://foo/bar")); - dto.addLink(new RESTLink("datacenter", "http://foo/bar/4")); - - Image image = function.apply(wrap(context, VirtualMachineTemplate.class, dto)); - - verify(regionMap); - verify(dcToLocation); - - assertEquals(image.getId(), dto.getId().toString()); - assertEquals(image.getName(), dto.getName()); - assertEquals(image.getDescription(), dto.getDescription()); - assertEquals(image.getUri(), URI.create("http://foo/bar")); - assertEquals(image.getOperatingSystem(), OperatingSystem.builder().description(dto.getName()).build()); - } - - @SuppressWarnings("unchecked") - public void testConvertWithoutDownloadLink() { - ApiContext<AbiquoApi> context = EasyMock.createMock(ApiContext.class); - Function<Datacenter, Location> dcToLocation = mockDatacenterToLocation(); - Supplier<Map<Integer, Datacenter>> regionMap = mockRegionMap(); - VirtualMachineTemplateToImage function = new VirtualMachineTemplateToImage(dcToLocation, regionMap); - - VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); - dto.setId(5); - dto.setName("Template"); - dto.setDescription("Template description"); - dto.addLink(new RESTLink("datacenter", "http://foo/bar/4")); - - Image image = function.apply(wrap(context, VirtualMachineTemplate.class, dto)); - - verify(regionMap); - verify(dcToLocation); - - assertNull(image.getUri()); - } - - @SuppressWarnings("unchecked") - @Test(expectedExceptions = NullPointerException.class) - public void testConvertWithoutId() { - ApiContext<AbiquoApi> context = EasyMock.createMock(ApiContext.class); - Function<Datacenter, Location> dcToLocation = mockDatacenterToLocation(); - Supplier<Map<Integer, Datacenter>> regionMap = mockRegionMap(); - VirtualMachineTemplateToImage function = new VirtualMachineTemplateToImage(dcToLocation, regionMap); - - VirtualMachineTemplateDto dto = new VirtualMachineTemplateDto(); - function.apply(wrap(context, VirtualMachineTemplate.class, dto)); - } - - @SuppressWarnings("unchecked") - private static Function<Datacenter, Location> mockDatacenterToLocation() { - Function<Datacenter, Location> mock = EasyMock.createMock(Function.class); - expect(mock.apply(anyObject(Datacenter.class))).andReturn(null); - replay(mock); - return mock; - } - - @SuppressWarnings("unchecked") - private static Supplier<Map<Integer, Datacenter>> mockRegionMap() { - Supplier<Map<Integer, Datacenter>> mock = EasyMock.createMock(Supplier.class); - expect(mock.get()).andReturn(Collections.EMPTY_MAP); - replay(mock); - return mock; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadataTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadataTest.java b/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadataTest.java deleted file mode 100644 index 392cd25..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/compute/functions/VirtualMachineToNodeMetadataTest.java +++ /dev/null @@ -1,218 +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.compute.functions; - -import static org.easymock.EasyMock.anyObject; -import static org.easymock.EasyMock.expect; -import static org.easymock.EasyMock.replay; -import static org.easymock.EasyMock.verify; -import static org.jclouds.abiquo.domain.DomainWrapper.wrap; -import static org.testng.Assert.assertEquals; - -import java.net.URI; - -import org.easymock.EasyMock; -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.cloud.VirtualMachineTemplateInVirtualDatacenter; -import org.jclouds.abiquo.domain.network.ExternalIp; -import org.jclouds.abiquo.domain.network.Ip; -import org.jclouds.abiquo.domain.network.PrivateIp; -import org.jclouds.abiquo.domain.network.PublicIp; -import org.jclouds.compute.domain.Hardware; -import org.jclouds.compute.domain.HardwareBuilder; -import org.jclouds.compute.domain.Image; -import org.jclouds.compute.domain.NodeMetadata; -import org.jclouds.compute.domain.NodeMetadata.Status; -import org.jclouds.domain.Location; -import org.jclouds.rest.ApiContext; -import org.testng.annotations.BeforeMethod; -import org.testng.annotations.Test; - -import com.abiquo.model.enumerator.HypervisorType; -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.cloud.VirtualMachineState; -import com.abiquo.server.core.cloud.VirtualMachineWithNodeExtendedDto; -import com.abiquo.server.core.infrastructure.network.ExternalIpDto; -import com.abiquo.server.core.infrastructure.network.PrivateIpDto; -import com.abiquo.server.core.infrastructure.network.PublicIpDto; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; - -/** - * Unit tests for the {@link VirtualMachineToNodeMetadata} class. - */ -@Test(groups = "unit", testName = "VirtualMachineToNodeMetadataTest") -public class VirtualMachineToNodeMetadataTest { - private VirtualMachineToNodeMetadata function; - - private VirtualMachineWithNodeExtendedDto vm; - - private PrivateIpDto privNic; - - private PublicIpDto pubNic; - - private ExternalIpDto extNic; - - private Hardware hardware; - - @BeforeMethod - public void setup() { - vm = new VirtualMachineWithNodeExtendedDto(); - vm.setNodeName("VM"); - vm.setName("Internal name"); - vm.setId(5); - vm.setVdrpPort(22); - vm.setRam(2048); - vm.setCpu(2); - vm.setState(VirtualMachineState.ON); - vm.addLink(new RESTLink("edit", "http://foo/bar")); - - privNic = new PrivateIpDto(); - privNic.setIp("192.168.1.2"); - privNic.setMac("2a:6e:40:69:84:e0"); - - pubNic = new PublicIpDto(); - pubNic.setIp("80.80.80.80"); - pubNic.setMac("2a:6e:40:69:84:e1"); - - extNic = new ExternalIpDto(); - extNic.setIp("10.10.10.10"); - extNic.setMac("2a:6e:40:69:84:e2"); - - hardware = new HardwareBuilder() // - .ids("1") // - .build(); - - function = new VirtualMachineToNodeMetadata(templateToImage(), templateToHardware(), stateToNodeState(), - virtualDatacenterToLocation()); - } - - public void testVirtualMachineToNodeMetadata() { - VirtualAppliance vapp = EasyMock.createMock(VirtualAppliance.class); - VirtualMachine mockVm = mockVirtualMachine(vapp); - - NodeMetadata node = function.apply(mockVm); - - verify(mockVm); - - assertEquals(node.getId(), vm.getId().toString()); - assertEquals(node.getUri(), URI.create("http://foo/bar")); - assertEquals(node.getName(), vm.getNodeName()); - assertEquals(node.getGroup(), "VAPP"); - assertEquals(node.getLocation().getId(), "1"); - assertEquals(node.getLocation().getDescription(), "Mock Location"); - assertEquals(node.getImageId(), "1"); - assertEquals(node.getHardware().getId(), "1"); - assertEquals(node.getHardware().getRam(), vm.getRam().intValue()); - assertEquals(node.getHardware().getProcessors().get(0).getCores(), (double) vm.getCpu()); - assertEquals(node.getLoginPort(), vm.getVdrpPort()); - assertEquals(node.getPrivateAddresses().size(), 1); - assertEquals(node.getPublicAddresses().size(), 2); - assertEquals(Iterables.get(node.getPrivateAddresses(), 0), privNic.getIp()); - assertEquals(Iterables.get(node.getPublicAddresses(), 0), pubNic.getIp()); - assertEquals(Iterables.get(node.getPublicAddresses(), 1), extNic.getIp()); - } - - private VirtualMachineTemplateToImage templateToImage() { - VirtualMachineTemplateToImage templateToImage = EasyMock.createMock(VirtualMachineTemplateToImage.class); - Image image = EasyMock.createMock(Image.class); - - expect(image.getId()).andReturn("1"); - expect(image.getOperatingSystem()).andReturn(null); - expect(templateToImage.apply(anyObject(VirtualMachineTemplate.class))).andReturn(image); - - replay(image); - replay(templateToImage); - - return templateToImage; - } - - private VirtualMachineTemplateInVirtualDatacenterToHardware templateToHardware() { - VirtualMachineTemplateInVirtualDatacenterToHardware virtualMachineTemplateToHardware = EasyMock - .createMock(VirtualMachineTemplateInVirtualDatacenterToHardware.class); - - expect(virtualMachineTemplateToHardware.apply(anyObject(VirtualMachineTemplateInVirtualDatacenter.class))) - .andReturn(hardware); - - replay(virtualMachineTemplateToHardware); - - return virtualMachineTemplateToHardware; - } - - private VirtualDatacenterToLocation virtualDatacenterToLocation() { - VirtualDatacenterToLocation datacenterToLocation = EasyMock.createMock(VirtualDatacenterToLocation.class); - Location location = EasyMock.createMock(Location.class); - - expect(location.getId()).andReturn("1"); - expect(location.getDescription()).andReturn("Mock Location"); - - expect(datacenterToLocation.apply(anyObject(VirtualDatacenter.class))).andReturn(location); - - replay(location); - replay(datacenterToLocation); - - return datacenterToLocation; - } - - private VirtualMachineStateToNodeState stateToNodeState() { - VirtualMachineStateToNodeState stateToNodeState = EasyMock.createMock(VirtualMachineStateToNodeState.class); - expect(stateToNodeState.apply(anyObject(VirtualMachineState.class))).andReturn(Status.RUNNING); - replay(stateToNodeState); - return stateToNodeState; - } - - private VirtualDatacenter mockVirtualDatacenter() { - VirtualDatacenter vdc = EasyMock.createMock(VirtualDatacenter.class); - expect(vdc.getHypervisorType()).andReturn(HypervisorType.VMX_04); - expect(vdc.getDatacenter()).andReturn(null); - replay(vdc); - return vdc; - } - - private VirtualMachineTemplate mockTemplate() { - return EasyMock.createMock(VirtualMachineTemplate.class); - } - - @SuppressWarnings("unchecked") - private VirtualMachine mockVirtualMachine(final VirtualAppliance vapp) { - VirtualMachine mockVm = EasyMock.createMock(VirtualMachine.class); - - Ip<?, ?> mockPrivNic = wrap(EasyMock.createMock(ApiContext.class), PrivateIp.class, privNic); - Ip<?, ?> mockPubNic = wrap(EasyMock.createMock(ApiContext.class), PublicIp.class, pubNic); - Ip<?, ?> mockExtNic = wrap(EasyMock.createMock(ApiContext.class), ExternalIp.class, extNic); - - expect(mockVm.getId()).andReturn(vm.getId()); - expect(mockVm.getURI()).andReturn(URI.create(vm.getEditLink().getHref())); - expect(mockVm.getNameLabel()).andReturn(vm.getNodeName()); - expect(mockVm.getTemplate()).andReturn(mockTemplate()); - expect(mockVm.getState()).andReturn(vm.getState()); - expect(mockVm.listAttachedNics()).andReturn(ImmutableList.<Ip<?, ?>> of(mockPubNic, mockPrivNic, mockExtNic)); - expect(mockVm.getVirtualAppliance()).andReturn(vapp); - expect(vapp.getName()).andReturn("VAPP"); - expect(mockVm.getVirtualDatacenter()).andReturn(mockVirtualDatacenter()); - expect(mockVm.getRam()).andReturn(vm.getRam()); - expect(mockVm.getCpu()).andReturn(vm.getCpu()); - - replay(mockVm); - replay(vapp); - - return mockVm; - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptionsTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptionsTest.java b/abiquo/src/test/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptionsTest.java deleted file mode 100644 index 38d2a2a..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/compute/options/AbiquoTemplateOptionsTest.java +++ /dev/null @@ -1,49 +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.compute.options; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.compute.options.TemplateOptions; -import org.testng.annotations.Test; - -/** - * Unit tests for the {@link AbiquoTemplateOptions} class. - */ -@Test(groups = "unit", testName = "AbiquoTemplateOptionsTest") -public class AbiquoTemplateOptionsTest { - public void testAs() { - TemplateOptions options = new AbiquoTemplateOptions(); - assertEquals(options.as(AbiquoTemplateOptions.class), options); - } - - public void testOverrideCores() { - TemplateOptions options = new AbiquoTemplateOptions().overrideCores(5); - assertEquals(options.as(AbiquoTemplateOptions.class).getOverrideCores(), Integer.valueOf(5)); - } - - public void testOverrideRam() { - TemplateOptions options = new AbiquoTemplateOptions().overrideRam(2048); - assertEquals(options.as(AbiquoTemplateOptions.class).getOverrideRam(), Integer.valueOf(2048)); - } - - public void testVncPassword() { - TemplateOptions options = new AbiquoTemplateOptions().vncPassword("foo"); - assertEquals(options.as(AbiquoTemplateOptions.class).getVncPassword(), "foo"); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/config/SchedulerModuleTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/config/SchedulerModuleTest.java b/abiquo/src/test/java/org/jclouds/abiquo/config/SchedulerModuleTest.java deleted file mode 100644 index d9147b8..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/config/SchedulerModuleTest.java +++ /dev/null @@ -1,39 +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.config; - -import static org.testng.Assert.assertNotNull; - -import java.util.concurrent.ScheduledExecutorService; - -import org.jclouds.Constants; -import org.jclouds.abiquo.internal.BaseInjectionTest; -import org.testng.annotations.Test; - -import com.google.inject.Key; -import com.google.inject.name.Names; - -/** - * Unit tests for the {@link SchedulerModule} class. - */ -@Test(groups = "unit", testName = "SchedulerModuleTest") -public class SchedulerModuleTest extends BaseInjectionTest { - public void testScheduledExecutorIsProvided() { - assertNotNull(injector.getInstance(Key.get(ScheduledExecutorService.class, - Names.named(Constants.PROPERTY_SCHEDULER_THREADS)))); - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/AbiquoVersionLiveApiTest.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/AbiquoVersionLiveApiTest.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/AbiquoVersionLiveApiTest.java deleted file mode 100644 index 25f76be..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/AbiquoVersionLiveApiTest.java +++ /dev/null @@ -1,50 +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; - -import static org.jclouds.abiquo.util.Assert.assertHasError; -import static org.testng.Assert.fail; - -import java.util.Properties; - -import javax.ws.rs.core.Response.Status; - -import org.jclouds.abiquo.domain.exception.AbiquoException; -import org.jclouds.abiquo.internal.BaseAbiquoLiveApiTest; -import org.testng.annotations.Test; - -/** - * Live integration tests for the Abiquo versioning support. - */ -@Test(groups = "api", testName = "AbiquoVersionLiveApiTest") -public class AbiquoVersionLiveApiTest extends BaseAbiquoLiveApiTest { - @Override - protected Properties setupProperties() { - Properties overrides = super.setupProperties(); - overrides.setProperty("abiquo.api-version", "0.0"); - return overrides; - } - - public void testUnsupportedVersion() { - try { - view.getAdministrationService().getCurrentUser(); - fail("Unsupported versions in mime types should not be allowed"); - } catch (AbiquoException ex) { - assertHasError(ex, Status.NOT_ACCEPTABLE, "406-NOT-ACCEPTABLE"); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/1b689dc1/abiquo/src/test/java/org/jclouds/abiquo/domain/AdminResources.java ---------------------------------------------------------------------- diff --git a/abiquo/src/test/java/org/jclouds/abiquo/domain/AdminResources.java b/abiquo/src/test/java/org/jclouds/abiquo/domain/AdminResources.java deleted file mode 100644 index 3766cbd..0000000 --- a/abiquo/src/test/java/org/jclouds/abiquo/domain/AdminResources.java +++ /dev/null @@ -1,194 +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; - -import static org.jclouds.abiquo.domain.DomainUtils.link; - -import com.abiquo.model.rest.RESTLink; -import com.abiquo.server.core.enterprise.DatacenterLimitsDto; -import com.abiquo.server.core.enterprise.EnterpriseDto; -import com.abiquo.server.core.enterprise.RoleDto; -import com.abiquo.server.core.enterprise.UserDto; - -/** - * Enterprise domain utilities. - */ -public class AdminResources { - public static RoleDto rolePost() { - RoleDto role = new RoleDto(); - role.addLink(new RESTLink("privileges", "http://localhost/api/admin/roles/1/action/privileges")); - role.setName("HAWAIAN_ADMIN"); - return role; - } - - public static RoleDto rolePut() { - RoleDto role = rolePost(); - role.setId(1); - role.addLink(new RESTLink("edit", "http://localhost/api/admin/roles/1")); - - return role; - } - - public static String rolePostPayload() { - StringBuilder buffer = new StringBuilder(); - buffer.append("<role>"); - buffer.append(link("/admin/roles/1/action/privileges", "privileges")); - buffer.append("<blocked>false</blocked>"); - buffer.append("<name>HAWAIAN_ADMIN</name>"); - buffer.append("</role>"); - return buffer.toString(); - } - - public static String rolePutPayload() { - StringBuilder buffer = new StringBuilder(); - buffer.append("<role>"); - buffer.append(link("/admin/roles/1/action/privileges", "privileges")); - buffer.append(link("/admin/roles/1", "edit")); - buffer.append("<blocked>false</blocked>"); - buffer.append("<id>1</id>"); - buffer.append("<name>HAWAIAN_ADMIN</name>"); - buffer.append("</role>"); - return buffer.toString(); - } - - public static DatacenterLimitsDto datacenterLimitsPost() { - DatacenterLimitsDto limits = new DatacenterLimitsDto(); - limits.setCpuCountLimits(0, 0); - limits.setHdLimitsInMb(0, 0); - limits.setPublicIPLimits(0, 0); - limits.setRamLimitsInMb(0, 0); - limits.setStorageLimits(0, 0); - limits.setVlansLimits(0, 0); - limits.setRepositoryHardLimitsInMb(0); - limits.setRepositorySoftLimitsInMb(0); - return limits; - } - - public static DatacenterLimitsDto datacenterLimitsPut(final EnterpriseDto enterprise) { - DatacenterLimitsDto limits = datacenterLimitsPost(); - limits.setId(1); - limits.addLink(new RESTLink("edit", "http://localhost/api/admin/enterprises/" + enterprise.getId() + "/limits/1")); - return limits; - } - - public static String datacenterLimitsPostPayload() { - StringBuilder buffer = new StringBuilder(); - buffer.append("<limit>"); - buffer.append("<cpuHard>0</cpuHard>"); - buffer.append("<cpuSoft>0</cpuSoft>"); - buffer.append("<hdHard>0</hdHard>"); - buffer.append("<hdSoft>0</hdSoft>"); - buffer.append("<publicIpsHard>0</publicIpsHard>"); - buffer.append("<publicIpsSoft>0</publicIpsSoft>"); - buffer.append("<ramHard>0</ramHard>"); - buffer.append("<ramSoft>0</ramSoft>"); - buffer.append("<storageHard>0</storageHard>"); - buffer.append("<storageSoft>0</storageSoft>"); - buffer.append("<vlansHard>0</vlansHard>"); - buffer.append("<vlansSoft>0</vlansSoft>"); - buffer.append("<repositoryHard>0</repositoryHard>"); - buffer.append("<repositorySoft>0</repositorySoft>"); - buffer.append("</limit>"); - return buffer.toString(); - } - - public static String datacenterLimitsPutPayload(final EnterpriseDto enterprise) { - StringBuilder buffer = new StringBuilder(); - buffer.append("<limit>"); - buffer.append(link("/admin/enterprises/" + enterprise.getId() + "/limits/1", "edit")); - buffer.append("<cpuHard>0</cpuHard>"); - buffer.append("<cpuSoft>0</cpuSoft>"); - buffer.append("<hdHard>0</hdHard>"); - buffer.append("<hdSoft>0</hdSoft>"); - buffer.append("<publicIpsHard>0</publicIpsHard>"); - buffer.append("<publicIpsSoft>0</publicIpsSoft>"); - buffer.append("<ramHard>0</ramHard>"); - buffer.append("<ramSoft>0</ramSoft>"); - buffer.append("<storageHard>0</storageHard>"); - buffer.append("<storageSoft>0</storageSoft>"); - buffer.append("<vlansHard>0</vlansHard>"); - buffer.append("<vlansSoft>0</vlansSoft>"); - buffer.append("<id>1</id>"); - buffer.append("<repositoryHard>0</repositoryHard>"); - buffer.append("<repositorySoft>0</repositorySoft>"); - buffer.append("</limit>"); - return buffer.toString(); - } - - public static String userPostPayload() { - StringBuilder buffer = new StringBuilder(); - buffer.append("<user>"); - buffer.append(link("/admin/roles/1", "role")); - buffer.append("<active>true</active>"); - buffer.append("<authType>ABIQUO</authType>"); - buffer.append("<description>A hawaian user</description>"); - buffer.append("<email>[email protected]</email>"); - buffer.append("<locale>en_US</locale>"); - buffer.append("<name>Aberahama</name>"); - buffer.append("<nick>abejo</nick>"); - buffer.append("<password>c69a39bd64ffb77ea7ee3369dce742f3</password>"); - buffer.append("<surname>Johanson</surname>"); - buffer.append("</user>"); - return buffer.toString(); - } - - public static UserDto userPost() { - UserDto user = new UserDto(); - user.setName("Aberahama"); - user.setSurname("Johanson"); - user.setDescription("A hawaian user"); - user.setEmail("[email protected]"); - user.setNick("abejo"); - user.setAuthType("ABIQUO"); - user.setLocale("en_US"); - user.setActive(true); - user.setPassword("c69a39bd64ffb77ea7ee3369dce742f3"); - user.addLink(new RESTLink("role", "http://localhost/api/admin/roles/1")); - return user; - } - - public static String userPutPayload() { - StringBuilder buffer = new StringBuilder(); - buffer.append("<user>"); - buffer.append(link("/admin/roles/1", "role")); - buffer.append(link("/admin/enterprises/1/users/1", "edit")); - buffer.append(link("/admin/enterprises/1", "enterprise")); - buffer.append(link("/admin/enterprises/1/users/1/action/virtualmachines", "virtualmachines")); - buffer.append("<active>true</active>"); - buffer.append("<authType>ABIQUO</authType>"); - buffer.append("<description>A hawaian user</description>"); - buffer.append("<email>[email protected]</email>"); - buffer.append("<id>1</id>"); - buffer.append("<locale>en_US</locale>"); - buffer.append("<name>Aberahama</name>"); - buffer.append("<nick>abejo</nick>"); - buffer.append("<password>c69a39bd64ffb77ea7ee3369dce742f3</password>"); - buffer.append("<surname>Johanson</surname>"); - buffer.append("</user>"); - return buffer.toString(); - } - - public static UserDto userPut() { - UserDto user = userPost(); - user.setId(1); - user.addLink(new RESTLink("edit", "http://localhost/api/admin/enterprises/1/users/1")); - user.addLink(new RESTLink("enterprise", "http://localhost/api/admin/enterprises/1")); - user.addLink(new RESTLink("virtualmachines", - "http://localhost/api/admin/enterprises/1/users/1/action/virtualmachines")); - return user; - } -}
