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/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..e0ddd271d8 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,14 +160,14 @@ 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(); 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); + this.virtualDisks = Disks.builder().disks(checkNotNull(virtualDisks,"virtualDisks")).build(); for( VirtualNic virtualNic: checkNotNull(virtualNics, "virtualNics")) this.virtualNics.setVirtualNic(virtualNic); this.processorCount = processorCount; 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/vm/VirtualMachine.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/domain/vm/VirtualMachine.java index 29ff17e012..affdb76981 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 @@ -63,7 +63,7 @@ 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 Actions actions = Actions.builder().build(); private Tasks tasks = new Tasks(); private String description; private VirtualMachineStatus status; @@ -275,7 +275,7 @@ public class VirtualMachine extends BaseNamedResource { private Tasks tasks = new Tasks(); @XmlElement(name = "Actions", required = true) - private Actions actions = new Actions(); + private Actions actions = Actions.builder().build(); @XmlElement(name = "Description", required = true) private String description; diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/hardware/DisksTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/hardware/DisksTest.java new file mode 100644 index 0000000000..54ce6db170 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/hardware/DisksTest.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.hardware; + +import org.jclouds.tmrk.enterprisecloud.domain.Size; +import org.jclouds.tmrk.enterprisecloud.domain.hardware.Disks; +import org.jclouds.tmrk.enterprisecloud.domain.hardware.VirtualDisk; +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)); + } +}