diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Actions.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Actions.java index 29b80c90a2..64ae9c5125 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Actions.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Actions.java @@ -68,7 +68,7 @@ public class Actions { } } - public Actions() { + private Actions() { //For JAXB and builder use } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Link.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Link.java index f72b0f94b1..c4a6e4b5af 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Link.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Link.java @@ -123,7 +123,7 @@ public class Link extends BaseNamedResource { @Override public Link build() { - return new Link(href, name, type, rel); + return new Link(href, type, name, rel); } public Builder fromLink(Link in) { diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Links.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Links.java index f016c873aa..f3b41f82b3 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Links.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Links.java @@ -25,6 +25,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Wraps individual Link elements. * Needed because parsing is done with JAXB and it does not handle Generic collections @@ -32,36 +34,75 @@ import java.util.Set; */ public class Links { - private LinkedHashSet links = Sets.newLinkedHashSet(); + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } - @XmlElement(name = "Link") - public void setLink(Link link) { - this.links.add(link); - } + public Builder toBuilder() { + return new Builder().fromLinks(this); + } - public Set getLinks() { - return Collections.unmodifiableSet(links); - } + 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 links = Sets.newLinkedHashSet(); - Links links1 = (Links) o; + /** + * @see Links#getLinks + */ + public Builder links(Set links) { + this.links = Sets.newLinkedHashSet(checkNotNull(links, "links")); + return this; + } - if (!links.equals(links1.links)) return false; + public Builder addLink(Link link) { + links.add(checkNotNull(link,"link")); + return this; + } - return true; - } + public Links build() { + return new Links(links); + } - @Override - public int hashCode() { - return links.hashCode(); - } + public Builder fromLinks(Links in) { + return links(in.getLinks()); + } + } - public String toString() { - return "["+ links.toString()+"]"; - } + @XmlElement(name = "Link") + private LinkedHashSet links = Sets.newLinkedHashSet(); + + private Links() { + //For JAXB + } + + private Links(Set links) { + this.links = Sets.newLinkedHashSet(links); + } + + public Set getLinks() { + return Collections.unmodifiableSet(links); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Links links1 = (Links) o; + + if (!links.equals(links1.links)) return false; + + return true; + } + + @Override + public int hashCode() { + return links.hashCode(); + } + + public String toString() { + return "["+ links.toString()+"]"; + } } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Tasks.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Tasks.java index 8c411d3701..f3d5224fe6 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Tasks.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/Tasks.java @@ -36,37 +36,77 @@ import static com.google.common.base.Preconditions.checkNotNull; */ @XmlRootElement(name = "Tasks") public class Tasks { - //TODO: There is a total count field - private LinkedHashSet tasks = Sets.newLinkedHashSet(); - @XmlElement(name = "Task") - public void setTask(Task task) { - checkNotNull(task,"task"); - tasks.add(task); - } + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } - public Set getTasks() { - return Collections.unmodifiableSet(tasks); - } + public Builder toBuilder() { + return new Builder().fromTasks(this); + } - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + public static class Builder { - Tasks tasks1 = (Tasks) o; + private Set tasks = Sets.newLinkedHashSet(); - if (!tasks.equals(tasks1.tasks)) return false; + /** + * @see Tasks#getTasks + */ + public Builder tasks(Set tasks) { + this.tasks = Sets.newLinkedHashSet(checkNotNull(tasks, "tasks")); + return this; + } - return true; - } + public Builder addTask(Task task) { + tasks.add(checkNotNull(task,"task")); + return this; + } - @Override - public int hashCode() { - return tasks.hashCode(); - } + public Tasks build() { + return new Tasks(tasks); + } - public String toString() { - return "["+tasks.toString()+"]"; - } + public Builder fromTasks(Tasks in) { + return tasks(in.getTasks()); + } + } + + private Tasks() { + //For JAXB and builder use + } + + private Tasks(Set tasks) { + this.tasks = Sets.newLinkedHashSet(tasks); + } + + //TODO: There is a total count field + + @XmlElement(name = "Task") + private LinkedHashSet tasks = Sets.newLinkedHashSet(); + + public Set getTasks() { + return Collections.unmodifiableSet(tasks); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Tasks tasks1 = (Tasks) o; + + if (!tasks.equals(tasks1.tasks)) return false; + + return true; + } + + @Override + public int hashCode() { + return tasks.hashCode(); + } + + public String toString() { + return "["+tasks.toString()+"]"; + } } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/Disks.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/Disks.java index 3f336e6392..3334808429 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/Disks.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/Disks.java @@ -35,9 +35,52 @@ import static com.google.common.base.Preconditions.checkNotNull; */ public class Disks { - private LinkedHashSet disks = Sets.newLinkedHashSet(); + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } + + public Builder toBuilder() { + return new Builder().fromDisks(this); + } + + public static class Builder { + + private Set disks = Sets.newLinkedHashSet(); + + /** + * @see Disks#getVirtualDisks() + */ + public Builder disks(Set disks) { + this.disks = Sets.newLinkedHashSet(checkNotNull(disks, "disks")); + return this; + } + + public Builder addDisk(VirtualDisk disk) { + disks.add(checkNotNull(disk,"disk")); + return this; + } + + public Disks build() { + return new Disks(disks); + } + + public Builder fromDisks(Disks in) { + return disks(in.getVirtualDisks()); + } + } @XmlElement(name = "Disk") + private LinkedHashSet disks = Sets.newLinkedHashSet(); + + private Disks() { + //For JAXB and builder use + } + + private Disks(Set disks) { + this.disks = Sets.newLinkedHashSet(disks); + } + public void setVirtualDisk(VirtualDisk disk) { checkNotNull(disk,"disk"); this.disks.add(disk); diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/HardwareConfiguration.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/HardwareConfiguration.java index 6378452550..4bf0c2a196 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/HardwareConfiguration.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/HardwareConfiguration.java @@ -151,7 +151,7 @@ public class HardwareConfiguration extends BaseResource { } @XmlElement(name = "Actions", required = false) - private Actions actions = new Actions(); + private Actions actions = Actions.builder().build(); @XmlElement(name = "ProcessorCount", required = true) private int processorCount; @@ -160,16 +160,15 @@ public class HardwareConfiguration extends BaseResource { private Memory memory; @XmlElement(name = "Disks", required = false) - private Disks virtualDisks = new Disks(); + private Disks virtualDisks = Disks.builder().build(); @XmlElement(name = "Nics", required = false) - private Nics virtualNics = new Nics(); + private Nics virtualNics = Nics.builder().build(); public HardwareConfiguration(Set actions, int processorCount, @Nullable Memory memory, Set virtualDisks, Set virtualNics) { 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); - + this.virtualDisks = Disks.builder().disks(checkNotNull(virtualDisks,"virtualDisks")).build(); + this.virtualNics = Nics.builder().nics(checkNotNull(virtualNics, "virtualNics")).build(); this.processorCount = processorCount; this.memory = memory; } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/AssignedIpAddresses.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/AssignedIpAddresses.java index 301a1b7f91..52f880eeed 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/AssignedIpAddresses.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/AssignedIpAddresses.java @@ -37,7 +37,7 @@ public class AssignedIpAddresses extends BaseResource { //TODO links @XmlElement(name = "Actions", required = true) - private Actions actions = new Actions(); + private Actions actions = Actions.builder().build(); @XmlElement(name = "Networks", required = true) private DeviceNetworks networks = new DeviceNetworks(); diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/Nics.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/Nics.java index eb11a8f34b..eed23d9221 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/Nics.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/network/Nics.java @@ -25,6 +25,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Wraps individual VirtualNic elements. * Needed because parsing is done with JAXB and it does not handle Generic collections @@ -33,36 +35,74 @@ import java.util.Set; */ public class Nics { - private LinkedHashSet nics = Sets.newLinkedHashSet(); + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } - @XmlElement(name = "Nic") - public void setVirtualNic(VirtualNic nic) { - this.nics.add(nic); - } + public Builder toBuilder() { + return new Builder().fromNics(this); + } - public Set getVirtualNics() { - return Collections.unmodifiableSet(nics); - } + 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 nics = Sets.newLinkedHashSet(); - Nics nics1 = (Nics) o; + /** + * @see Nics#getVirtualNics() + */ + public Builder nics(Set nics) { + this.nics = Sets.newLinkedHashSet(checkNotNull(nics, "nics")); + return this; + } - if (!nics.equals(nics1.nics)) return false; + public Builder addVirtualNic(VirtualNic nic) { + nics.add(checkNotNull(nic,"nic")); + return this; + } - return true; - } + public Nics build() { + return new Nics(nics); + } - @Override - public int hashCode() { - return nics.hashCode(); - } + public Builder fromNics(Nics in) { + return nics(in.getVirtualNics()); + } + } - public String toString() { - return "["+ nics.toString()+"]"; - } + private Nics() { + //For JAXB and builder use + } + private Nics(Set nics) { + this.nics = Sets.newLinkedHashSet(nics); + } + + @XmlElement(name = "Nic") + private LinkedHashSet nics = Sets.newLinkedHashSet(); + + public Set getVirtualNics() { + return Collections.unmodifiableSet(nics); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Nics nics1 = (Nics) o; + + if (!nics.equals(nics1.nics)) return false; + + return true; + } + + @Override + public int hashCode() { + return nics.hashCode(); + } + + public String toString() { + return "["+ nics.toString()+"]"; + } } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachine.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachine.java index 29ff17e012..0d3ec7d5e5 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachine.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachine.java @@ -62,9 +62,9 @@ public class VirtualMachine extends BaseNamedResource { public static class Builder extends BaseNamedResource.Builder { //TODO There are some more fields - private Links links = new Links(); - private Actions actions = new Actions(); - private Tasks tasks = new Tasks(); + private Links links = Links.builder().build(); + private Actions actions = Actions.builder().build(); + private Tasks tasks = Tasks.builder().build(); private String description; private VirtualMachineStatus status; @@ -81,8 +81,7 @@ public class VirtualMachine extends BaseNamedResource { * @see VirtualMachine#getLinks */ public Builder links(Set links) { - checkNotNull(links,"links"); - for(Link link:links) this.links.setLink(link); + this.links = Links.builder().links(checkNotNull(links,"links")).build(); return this; } @@ -99,12 +98,10 @@ public class VirtualMachine extends BaseNamedResource { * @see VirtualMachine#getTasks */ public Builder tasks(Set tasks) { - checkNotNull(tasks,"tasks"); - for(Task task: tasks) this.tasks.setTask(task); + this.tasks = Tasks.builder().tasks(checkNotNull(tasks,"tasks")).build(); return this; } - /** * @see VirtualMachine#getDescription */ @@ -269,13 +266,13 @@ public class VirtualMachine extends BaseNamedResource { } @XmlElement(name = "Links", required = true) - private Links links = new Links(); + private Links links = Links.builder().build(); @XmlElement(name = "Tasks", required = true) - private Tasks tasks = new Tasks(); + private Tasks tasks = Tasks.builder().build(); @XmlElement(name = "Actions", required = true) - private Actions actions = new Actions(); + private Actions actions = Actions.builder().build(); @XmlElement(name = "Description", required = true) private String description; @@ -316,6 +313,7 @@ public class VirtualMachine extends BaseNamedResource { this.tasks = checkNotNull(tasks, "tasks"); this.actions = checkNotNull(actions, "actions"); this.status = checkNotNull(status, "status"); + this.ipAddresses = checkNotNull(ipAddresses, "ipAddresses"); this.layout = layout; this.poweredOn = poweredOn; @@ -324,7 +322,6 @@ public class VirtualMachine extends BaseNamedResource { this.customizationPending = customizationPending; this.operatingSystem = operatingSystem; this.hardwareConfiguation = hardwareConfiguration; - this.ipAddresses = checkNotNull(ipAddresses, "ipAddresses"); } protected VirtualMachine() { diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachines.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachines.java index 09a12eefd3..e687182747 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachines.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachines.java @@ -26,6 +26,8 @@ import java.util.Collections; import java.util.LinkedHashSet; import java.util.Set; +import static com.google.common.base.Preconditions.checkNotNull; + /** * Wraps individual VirtualMachine elements. * Needed because parsing is done with JAXB and it does not handle Generic collections @@ -35,35 +37,74 @@ import java.util.Set; @XmlRootElement(name="VirtualMachines") public class VirtualMachines { - private LinkedHashSet virtualMachines = Sets.newLinkedHashSet(); + @SuppressWarnings("unchecked") + public static Builder builder() { + return new Builder(); + } - @XmlElement(name = "VirtualMachine") - void setVirtualMachine(VirtualMachine nic) { - this.virtualMachines.add(nic); - } + public Builder toBuilder() { + return new Builder().fromVirtualMachines(this); + } - public Set getVirtualMachines() { - return Collections.unmodifiableSet(virtualMachines); - } + 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 virtualMachines = Sets.newLinkedHashSet(); - VirtualMachines vms1 = (VirtualMachines) o; + /** + * @see VirtualMachines#getVirtualMachines + */ + public Builder virtualMachines(Set virtualMachines) { + this.virtualMachines = Sets.newLinkedHashSet(checkNotNull(virtualMachines, "virtualMachines")); + return this; + } - if (!virtualMachines.equals(vms1.virtualMachines)) return false; + public Builder addVirtualMachine(VirtualMachine virtualMachine) { + virtualMachines.add(checkNotNull(virtualMachine,"virtualMachine")); + return this; + } - return true; - } + public VirtualMachines build() { + return new VirtualMachines(virtualMachines); + } - @Override - public int hashCode() { - return virtualMachines.hashCode(); - } + public Builder fromVirtualMachines(VirtualMachines in) { + return virtualMachines(in.getVirtualMachines()); + } + } - public String toString() { - return "["+ virtualMachines.toString()+"]"; - } + private VirtualMachines() { + //For JAXB and builder use + } + + private VirtualMachines(Set virtualMachines) { + this.virtualMachines = Sets.newLinkedHashSet(virtualMachines); + } + + @XmlElement(name = "VirtualMachine") + private LinkedHashSet virtualMachines = Sets.newLinkedHashSet(); + + public Set getVirtualMachines() { + return Collections.unmodifiableSet(virtualMachines); + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + VirtualMachines vms1 = (VirtualMachines) o; + + if (!virtualMachines.equals(vms1.virtualMachines)) return false; + + return true; + } + + @Override + public int hashCode() { + return virtualMachines.hashCode(); + } + + public String toString() { + return "["+ virtualMachines.toString()+"]"; + } } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/LinksTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/LinksTest.java new file mode 100644 index 0000000000..72eb78bd09 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/LinksTest.java @@ -0,0 +1,58 @@ +/** + * 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.jclouds.tmrk.enterprisecloud.domain.Link.Relationship; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * @author Jason King + */ +@Test(groups = "unit", testName = "LinksTest") +public class LinksTest { + + private Link link; + private Links links; + + @BeforeMethod() + public void setUp() throws URISyntaxException { + link = Link.builder().href(new URI("/1")).name("my link").type("test link").rel(Relationship.FIRST).build(); + links = Links.builder().addLink(link).build(); + + } + + @Test + public void testAddAction() throws URISyntaxException { + Link link2 = Link.builder().href(new URI("/2")).name("my link 2").type("test link").rel(Relationship.LAST).build(); + Links twoLinks = links.toBuilder().addLink(link2).build(); + Set linkSet = twoLinks.getLinks(); + + assertEquals(2, linkSet.size()); + assertTrue(linkSet.contains(link)); + assertTrue(linkSet.contains(link2)); + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/TasksTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/TasksTest.java new file mode 100644 index 0000000000..12b393fb45 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/TasksTest.java @@ -0,0 +1,89 @@ +/** + * 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.Date; +import java.util.Set; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertTrue; + +/** + * @author Jason King + */ +@Test(groups = "unit", testName = "TasksTest") +public class TasksTest { + + private Task task; + private Tasks tasks; + + @BeforeMethod() + public void setUp() throws URISyntaxException { + task = Task + .builder() + .href(URI.create("/tasks/1002")) + .type("application/vnd.tmrk.cloud.task") + .operation("test task") + .status(Task.Status.ERROR) + .impactedItem( + NamedResource.builder().href(URI.create("/item/1")).name("sample item 1") + .type("application/vnd.tmrk.cloud.nodeService").build()) + .startTime(new Date()) + .completedTime(new Date()) + .notes("Some notes about the operation.") + .errorMessage("sample error message 1 here") + .initiatedBy( + NamedResource.builder().href(URI.create("/users/1")).name("User 1") + .type("application/vnd.tmrk.cloud.admin.user").build()).build(); + + tasks = Tasks.builder().addTask(task).build(); + } + + @Test + public void testAddAction() throws URISyntaxException { + Task task2 = Task + .builder() + .href(URI.create("/tasks/1003")) + .type("application/vnd.tmrk.cloud.task") + .operation("test task 2") + .status(Task.Status.ERROR) + .impactedItem( + NamedResource.builder().href(URI.create("/item/2")).name("sample item 2") + .type("application/vnd.tmrk.cloud.nodeService").build()) + .startTime(new Date()) + .completedTime(new Date()) + .notes("Some notes about the operation.") + .errorMessage("sample error message 2 here") + .initiatedBy( + NamedResource.builder().href(URI.create("/users/2")).name("User 2") + .type("application/vnd.tmrk.cloud.admin.user").build()).build(); + + Tasks twoTasks = tasks.toBuilder().addTask(task2).build(); + Set taskSet = twoTasks.getTasks(); + + assertEquals(2,taskSet.size()); + assertTrue(taskSet.contains(task)); + assertTrue(taskSet.contains(task2)); + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/DisksTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/DisksTest.java new file mode 100644 index 0000000000..a9cabd7d95 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/hardware/DisksTest.java @@ -0,0 +1,56 @@ +/** + * 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.hardware; + +import org.jclouds.tmrk.enterprisecloud.domain.Size; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +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 = "DisksTest") +public class DisksTest { + + private VirtualDisk disk; + private Disks disks; + + @BeforeMethod() + public void setUp() throws URISyntaxException { + disk = VirtualDisk.builder().index(0).name("test disk").size(Size.builder().value(1).unit("GB").build()).build(); + disks = Disks.builder().addDisk(disk).build(); + } + + @Test + public void testAddDisk() throws URISyntaxException { + VirtualDisk disk2 = VirtualDisk.builder().index(1).name("test disk 1").size(Size.builder().value(1).unit("GB").build()).build(); + Disks twoDisks = disks.toBuilder().addDisk(disk2).build(); + Set virtualDisks = twoDisks.getVirtualDisks(); + + assertEquals(2, virtualDisks.size()); + assertTrue(virtualDisks.contains(disk)); + assertTrue(virtualDisks.contains(disk2)); + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/network/NicsTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/network/NicsTest.java new file mode 100644 index 0000000000..23319de659 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/network/NicsTest.java @@ -0,0 +1,58 @@ +/** + * 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.network; + +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 = "NicsTest") +public class NicsTest { + + private NetworkReference networkReference; + private VirtualNic nic; + private Nics nics; + + @BeforeMethod() + public void setUp() throws URISyntaxException { + networkReference = NetworkReference.builder().href(new URI("/netref")).type("a network ref").name("my network ref").build(); + nic = VirtualNic.builder().macAddress("aa:bb").name("my nic").network(networkReference).unitNumber(1).build(); + nics = Nics.builder().addVirtualNic(nic).build(); + } + + @Test + public void testAddDisk() throws URISyntaxException { + VirtualNic nic2 = VirtualNic.builder().macAddress("aa:cc").name("my nic 2").network(networkReference).unitNumber(2).build(); + Nics twoNics = nics.toBuilder().addVirtualNic(nic2).build(); + Set nicSet = twoNics.getVirtualNics(); + + assertEquals(2, nicSet.size()); + assertTrue(nicSet.contains(nic)); + assertTrue(nicSet.contains(nic2)); + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachinesTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachinesTest.java new file mode 100644 index 0000000000..8556f50602 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachinesTest.java @@ -0,0 +1,80 @@ +/** + * 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.vm; + +import org.jclouds.tmrk.enterprisecloud.domain.Actions; +import org.jclouds.tmrk.enterprisecloud.domain.Links; +import org.jclouds.tmrk.enterprisecloud.domain.Tasks; +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 VirtualMachinesTest { + + private VirtualMachine virtualMachine; + private VirtualMachines virtualMachines; + + @BeforeMethod() + public void setUp() throws URISyntaxException { + virtualMachine = VirtualMachine.builder() + .description("This is a test VM") + .name("Test VM") + .href(new URI("/test")) + .type("Test VM") + .actions(Actions.builder().build().getActions()) + .links(Links.builder().build().getLinks()) + .tasks(Tasks.builder().build().getTasks()) + .status(VirtualMachine.VirtualMachineStatus.NOT_DEPLOYED) + .ipAddresses(new VirtualMachineIpAddresses()) + .build(); + + virtualMachines = VirtualMachines.builder().addVirtualMachine(virtualMachine).build(); + } + + @Test + public void testAddAction() throws URISyntaxException { + VirtualMachine virtualMachine2 = VirtualMachine.builder() + .description("This is a test VM 2") + .name("Test VM 2") + .href(new URI("/test/2")) + .type("Test VM 2") + .actions(Actions.builder().build().getActions()) + .links(Links.builder().build().getLinks()) + .tasks(Tasks.builder().build().getTasks()) + .status(VirtualMachine.VirtualMachineStatus.NOT_DEPLOYED) + .ipAddresses(new VirtualMachineIpAddresses()) + .build(); + + VirtualMachines twoVirtualMachines = virtualMachines.toBuilder().addVirtualMachine(virtualMachine2).build(); + Set virtualMachineSet = twoVirtualMachines.getVirtualMachines(); + assertEquals(2, virtualMachineSet.size()); + assertTrue(virtualMachineSet.contains(virtualMachine)); + assertTrue(virtualMachineSet.contains(virtualMachine2)); + } +}