mirror of https://github.com/apache/jclouds.git
Issue 695: Removed addAction method, and created Builder and added TestActions class
This commit is contained in:
parent
76cecee53a
commit
d8156f6717
|
@ -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()+"]";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -162,7 +162,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);
|
||||
|
||||
|
|
|
@ -87,7 +87,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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue