mirror of https://github.com/apache/jclouds.git
Issue 695: Added builder for Disks and removed setter, test. Used Actions builder externally and made constructor private
This commit is contained in:
parent
5cd43815af
commit
ca69fbf0f7
|
@ -68,7 +68,7 @@ public class Actions {
|
|||
}
|
||||
}
|
||||
|
||||
public Actions() {
|
||||
private Actions() {
|
||||
//For JAXB and builder use
|
||||
}
|
||||
|
||||
|
|
|
@ -35,9 +35,52 @@ import static com.google.common.base.Preconditions.checkNotNull;
|
|||
*/
|
||||
public class Disks {
|
||||
|
||||
private LinkedHashSet<VirtualDisk> 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<VirtualDisk> disks = Sets.newLinkedHashSet();
|
||||
|
||||
/**
|
||||
* @see Disks#getVirtualDisks()
|
||||
*/
|
||||
public Builder disks(Set<VirtualDisk> 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<VirtualDisk> disks = Sets.newLinkedHashSet();
|
||||
|
||||
private Disks() {
|
||||
//For JAXB and builder use
|
||||
}
|
||||
|
||||
private Disks(Set<VirtualDisk> disks) {
|
||||
this.disks = Sets.newLinkedHashSet(disks);
|
||||
}
|
||||
|
||||
public void setVirtualDisk(VirtualDisk disk) {
|
||||
checkNotNull(disk,"disk");
|
||||
this.disks.add(disk);
|
||||
|
|
|
@ -151,7 +151,7 @@ public class HardwareConfiguration extends BaseResource<HardwareConfiguration> {
|
|||
}
|
||||
|
||||
@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<HardwareConfiguration> {
|
|||
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<Action> actions, int processorCount, @Nullable Memory memory, Set<VirtualDisk> virtualDisks, Set<VirtualNic> 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;
|
||||
|
|
|
@ -37,7 +37,7 @@ public class AssignedIpAddresses extends BaseResource<AssignedIpAddresses> {
|
|||
//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();
|
||||
|
|
|
@ -63,7 +63,7 @@ public class VirtualMachine extends BaseNamedResource<VirtualMachine> {
|
|||
public static class Builder extends BaseNamedResource.Builder<VirtualMachine> {
|
||||
//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<VirtualMachine> {
|
|||
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;
|
||||
|
|
|
@ -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<VirtualDisk> virtualDisks = twoDisks.getVirtualDisks();
|
||||
|
||||
assertEquals(2, virtualDisks.size());
|
||||
assertTrue(virtualDisks.contains(disk));
|
||||
assertTrue(virtualDisks.contains(disk2));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue