mirror of https://github.com/apache/jclouds.git
Merge pull request #180 from jsonking/695-1
Issue 695: Removed addAction method, and created Builder and added Test
This commit is contained in:
commit
db54e0c426
|
@ -22,7 +22,6 @@ import com.google.common.collect.Sets;
|
|||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
|
@ -34,37 +33,74 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
*/
|
||||
public class Actions {
|
||||
|
||||
@XmlElement(name = "Action")
|
||||
private LinkedHashSet<Action> actions = Sets.newLinkedHashSet();
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Builder builder() {
|
||||
return new Builder();
|
||||
}
|
||||
|
||||
void addAction(Action action) {
|
||||
checkNotNull(action,"action");
|
||||
this.actions.add(action);
|
||||
}
|
||||
public Builder toBuilder() {
|
||||
return new Builder().fromActions(this);
|
||||
}
|
||||
|
||||
public Set<Action> getActions() {
|
||||
return Collections.unmodifiableSet(actions);
|
||||
}
|
||||
public static class Builder {
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
private Set<Action> actions = Sets.newLinkedHashSet();
|
||||
|
||||
Actions actions1 = (Actions) o;
|
||||
/**
|
||||
* @see Actions#getActions
|
||||
*/
|
||||
public Builder actions(Set<Action> actions) {
|
||||
this.actions = Sets.newLinkedHashSet(checkNotNull(actions, "actions"));
|
||||
return this;
|
||||
}
|
||||
|
||||
if (!actions.equals(actions1.actions)) return false;
|
||||
public Builder addAction(Action action) {
|
||||
actions.add(checkNotNull(action,"action"));
|
||||
return this;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
public Actions build() {
|
||||
return new Actions(actions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return actions.hashCode();
|
||||
}
|
||||
public Builder fromActions(Actions in) {
|
||||
return actions(in.getActions());
|
||||
}
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "["+ actions.toString()+"]";
|
||||
}
|
||||
public Actions() {
|
||||
//For JAXB and builder use
|
||||
}
|
||||
|
||||
private Actions(Set<Action> actions) {
|
||||
this.actions = Sets.newLinkedHashSet(actions);
|
||||
}
|
||||
|
||||
@XmlElement(name = "Action")
|
||||
private Set<Action> actions = Sets.newLinkedHashSet();
|
||||
|
||||
public Set<Action> getActions() {
|
||||
return Collections.unmodifiableSet(actions);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Actions actions1 = (Actions) o;
|
||||
|
||||
if (!actions.equals(actions1.actions)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return actions.hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "["+ actions.toString()+"]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
|
@ -16,12 +16,16 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.Action;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.Actions;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.Nics;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import java.net.URI;
|
||||
|
@ -162,7 +166,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
|||
private Nics virtualNics = new Nics();
|
||||
|
||||
public HardwareConfiguration(Set<Action> actions, int processorCount, @Nullable Memory memory, Set<VirtualDisk> virtualDisks, Set<VirtualNic> virtualNics) {
|
||||
for( Action action: checkNotNull(actions, "actions")) this.actions.addAction(action);
|
||||
this.actions = Actions.builder().actions(checkNotNull(actions, "actions")).build();
|
||||
for( VirtualDisk disk: checkNotNull(virtualDisks, "virtualDisks")) this.virtualDisks.setVirtualDisk(disk);
|
||||
for( VirtualNic virtualNic: checkNotNull(virtualNics, "virtualNics")) this.virtualNics.setVirtualNic(virtualNic);
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
|
||||
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.ResourceCapacity;
|
||||
|
|
@ -16,9 +16,10 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.hardware;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.Size;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
|
@ -16,8 +16,9 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.network;
|
||||
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.Actions;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
|
@ -47,7 +48,7 @@ public class AssignedIpAddresses extends BaseResource<AssignedIpAddresses> {
|
|||
checkNotNull(networks,"networks");
|
||||
}
|
||||
|
||||
protected AssignedIpAddresses() {
|
||||
public AssignedIpAddresses() {
|
||||
//For JAXB
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.network;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.network;
|
||||
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.network;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.network;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.network;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
||||
|
@ -36,7 +36,7 @@ public class Nics {
|
|||
private LinkedHashSet<VirtualNic> nics = Sets.newLinkedHashSet();
|
||||
|
||||
@XmlElement(name = "Nic")
|
||||
void setVirtualNic(VirtualNic nic) {
|
||||
public void setVirtualNic(VirtualNic nic) {
|
||||
this.nics.add(nic);
|
||||
}
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.network;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.software;
|
||||
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.software;
|
||||
|
||||
import javax.xml.bind.annotation.XmlEnum;
|
||||
import javax.xml.bind.annotation.XmlEnumValue;
|
|
@ -16,11 +16,15 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.vm;
|
||||
|
||||
import org.jclouds.javax.annotation.Nullable;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.*;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseNamedResource;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.internal.BaseResource;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.software.ToolsStatus;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlEnum;
|
||||
|
@ -87,7 +91,7 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
|||
*/
|
||||
public Builder actions(Set<Action> actions) {
|
||||
checkNotNull(actions,"actions");
|
||||
for(Action action:actions) this.actions.addAction(action);
|
||||
this.actions = Actions.builder().actions(actions).build();
|
||||
return this;
|
||||
}
|
||||
|
|
@ -16,15 +16,11 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.vm;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||
|
||||
import javax.xml.bind.annotation.XmlElement;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* <xs:complexType name="VirtualMachineIpAddresses">
|
|
@ -16,7 +16,7 @@
|
|||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.tmrk.enterprisecloud.domain;
|
||||
package org.jclouds.tmrk.enterprisecloud.domain.vm;
|
||||
|
||||
import com.google.common.collect.Sets;
|
||||
|
|
@ -22,9 +22,9 @@ import com.google.common.util.concurrent.ListenableFuture;
|
|||
import org.jclouds.http.filters.BasicAuthentication;
|
||||
import org.jclouds.rest.annotations.*;
|
||||
import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachines;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
|
||||
|
||||
import javax.ws.rs.Consumes;
|
||||
import javax.ws.rs.GET;
|
||||
|
|
|
@ -19,9 +19,9 @@
|
|||
package org.jclouds.tmrk.enterprisecloud.features;
|
||||
|
||||
import org.jclouds.concurrent.Timeout;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachines;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
|
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds 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.tmrk.enterprisecloud.domain;
|
||||
|
||||
import org.testng.annotations.BeforeMethod;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* @author Jason King
|
||||
*/
|
||||
@Test(groups = "unit", testName = "ActionsTest")
|
||||
public class ActionsTest {
|
||||
|
||||
private Action action;
|
||||
private Actions actions;
|
||||
|
||||
@BeforeMethod()
|
||||
public void setUp() throws URISyntaxException {
|
||||
action = Action.builder().href(new URI("/1")).name("my action").type("test action").build();
|
||||
actions = Actions.builder().addAction(action).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddAction() throws URISyntaxException {
|
||||
Action action2 = Action.builder().href(new URI("/2")).name("my action 2").type("test action 2").build();
|
||||
Actions twoActions = actions.toBuilder().addAction(action2).build();
|
||||
Set<Action> actionSet = twoActions.getActions();
|
||||
|
||||
assertEquals(2,actionSet.size());
|
||||
assertTrue(actionSet.contains(action));
|
||||
assertTrue(actionSet.contains(action2));
|
||||
}
|
||||
|
||||
}
|
|
@ -19,10 +19,10 @@
|
|||
package org.jclouds.tmrk.enterprisecloud.features;
|
||||
|
||||
import com.google.common.collect.Iterables;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.DeviceNetwork;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachines;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.DeviceNetwork;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachines;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
|
@ -63,7 +63,7 @@ public class VirtualMachineClientLiveTest extends BaseTerremarkEnterpriseCloudCl
|
|||
// TODO: don't hard-code uri
|
||||
VirtualMachine virtualMachine = client.getVirtualMachine(new URI("/cloudapi/ecloud/virtualMachines/5504"));
|
||||
assert null != virtualMachine;
|
||||
assertEquals(virtualMachine.getStatus(),VirtualMachine.VirtualMachineStatus.DEPLOYED);
|
||||
assertEquals(virtualMachine.getStatus(), VirtualMachine.VirtualMachineStatus.DEPLOYED);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -35,8 +35,8 @@ import org.jclouds.rest.AuthorizationException;
|
|||
import org.jclouds.rest.BaseRestClientTest;
|
||||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.*;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine.VirtualMachineStatus;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.DeviceNetwork;
|
||||
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
|
|
@ -36,7 +36,18 @@ import org.jclouds.rest.BaseRestClientTest;
|
|||
import org.jclouds.rest.RestContextSpec;
|
||||
import org.jclouds.rest.internal.RestAnnotationProcessor;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.*;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.VirtualMachine.VirtualMachineStatus;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.HardwareConfiguration;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.Memory;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.hardware.VirtualDisk;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.AssignedIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.DeviceNetwork;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.NetworkReference;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.network.VirtualNic;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.software.OperatingSystem;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.software.ToolsStatus;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine.VirtualMachineStatus;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachine;
|
||||
import org.jclouds.tmrk.enterprisecloud.domain.vm.VirtualMachineIpAddresses;
|
||||
import org.jclouds.tmrk.enterprisecloud.features.VirtualMachineAsyncClient;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.BeforeClass;
|
||||
|
|
Loading…
Reference in New Issue