Permalink
Browse files

Fixed payload assertions

  • Loading branch information...
1 parent 7088dd3 commit 5ff675579adcbab70df224cbec13e5835e1d73f6 @nacx nacx committed Jun 6, 2012
@@ -19,16 +19,18 @@
package org.jclouds.abiquo.binders.cloud;
-import static org.testng.Assert.assertEquals;
+import static org.jclouds.abiquo.domain.DomainUtils.withHeader;
+import static org.jclouds.abiquo.util.Assert.assertPayloadEquals;
+import java.io.IOException;
import java.net.URI;
import org.jclouds.abiquo.domain.CloudResources;
import org.jclouds.http.HttpRequest;
-import org.jclouds.xml.XMLParser;
import org.jclouds.xml.internal.JAXBParser;
import org.testng.annotations.Test;
+import com.abiquo.model.transport.LinksDto;
import com.abiquo.server.core.infrastructure.storage.DiskManagementDto;
/**
@@ -58,39 +60,36 @@ public void testInvalidTypeInput()
binder.bindToRequest(request, new Object());
}
- public void testBindEmptyArray()
+ public void testBindEmptyArray() throws IOException
{
BindHardDiskRefsToPayload binder = new BindHardDiskRefsToPayload(new JAXBParser("false"));
HttpRequest request =
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build();
request = binder.bindToRequest(request, new DiskManagementDto[] {});
- assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER
- + "<links/>");
+ assertPayloadEquals(request.getPayload(), withHeader("<links/>"), LinksDto.class);
}
- public void testBindSingleHardDisk()
+ public void testBindSingleHardDisk() throws IOException
{
DiskManagementDto hardDisk = CloudResources.hardDiskPut();
BindHardDiskRefsToPayload binder = new BindHardDiskRefsToPayload(new JAXBParser("false"));
HttpRequest request =
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build();
request = binder.bindToRequest(request, new DiskManagementDto[] {hardDisk});
- assertEquals(request.getPayload().getRawContent(),
- XMLParser.DEFAULT_XML_HEADER + "<links><link href=\""
- + hardDisk.getEditLink().getHref() + "\" rel=\"" + binder.getRelToUse(hardDisk)
- + "\"/></links>");
+ assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\""
+ + hardDisk.getEditLink().getHref() + "\" rel=\"" + binder.getRelToUse(hardDisk)
+ + "\"/></links>"), LinksDto.class);
}
- public void testBindMultipleHardDisks()
+ public void testBindMultipleHardDisks() throws IOException
{
DiskManagementDto hardDisk = CloudResources.hardDiskPut();
BindHardDiskRefsToPayload binder = new BindHardDiskRefsToPayload(new JAXBParser("false"));
HttpRequest request =
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build();
request = binder.bindToRequest(request, new DiskManagementDto[] {hardDisk, hardDisk});
- assertEquals(request.getPayload().getRawContent(),
- XMLParser.DEFAULT_XML_HEADER + "<links><link href=\""
- + hardDisk.getEditLink().getHref() + "\" rel=\"" + binder.getRelToUse(hardDisk)
- + "\"/></links>");
+ assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\""
+ + hardDisk.getEditLink().getHref() + "\" rel=\"" + binder.getRelToUse(hardDisk)
+ + "\"/></links>"), LinksDto.class);
}
}
@@ -19,17 +19,19 @@
package org.jclouds.abiquo.binders.cloud;
-import static org.testng.Assert.assertEquals;
+import static org.jclouds.abiquo.domain.DomainUtils.withHeader;
+import static org.jclouds.abiquo.util.Assert.assertPayloadEquals;
+import java.io.IOException;
import java.net.URI;
import org.jclouds.abiquo.domain.NetworkResources;
import org.jclouds.http.HttpRequest;
-import org.jclouds.xml.XMLParser;
import org.jclouds.xml.internal.JAXBParser;
import org.testng.annotations.Test;
import com.abiquo.model.rest.RESTLink;
+import com.abiquo.model.transport.LinksDto;
import com.abiquo.server.core.infrastructure.network.IpPoolManagementDto;
/**
@@ -59,16 +61,18 @@ public void testInvalidTypeInput()
binder.bindToRequest(request, new Object());
}
- public void testBindIpRef()
+ public void testBindIpRef() throws IOException
{
IpPoolManagementDto ip = NetworkResources.privateIpPut();
RESTLink selfLink = ip.searchLink("self");
BindIpRefToPayload binder = new BindIpRefToPayload(new JAXBParser("false"));
HttpRequest request =
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build();
request = binder.bindToRequest(request, ip);
- assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER
- + "<links><link href=\"" + selfLink.getHref() + "\" rel=\"" + selfLink.getTitle()
- + "\"/></links>");
+ assertPayloadEquals(
+ request.getPayload(),
+ withHeader("<links><link href=\"" + selfLink.getHref() + "\" rel=\""
+ + selfLink.getTitle() + "\"/></links>"), LinksDto.class);
+
}
}
@@ -19,16 +19,18 @@
package org.jclouds.abiquo.binders.cloud;
-import static org.testng.Assert.assertEquals;
+import static org.jclouds.abiquo.domain.DomainUtils.withHeader;
+import static org.jclouds.abiquo.util.Assert.assertPayloadEquals;
+import java.io.IOException;
import java.net.URI;
import org.jclouds.abiquo.domain.NetworkResources;
import org.jclouds.http.HttpRequest;
-import org.jclouds.xml.XMLParser;
import org.jclouds.xml.internal.JAXBParser;
import org.testng.annotations.Test;
+import com.abiquo.model.transport.LinksDto;
import com.abiquo.server.core.infrastructure.network.IpPoolManagementDto;
/**
@@ -58,37 +60,36 @@ public void testInvalidTypeInput()
binder.bindToRequest(request, new Object());
}
- public void testBindEmptyArray()
+ public void testBindEmptyArray() throws IOException
{
BindIpRefsToPayload binder = new BindIpRefsToPayload(new JAXBParser("false"));
HttpRequest request =
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build();
request = binder.bindToRequest(request, new IpPoolManagementDto[] {});
- assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER
- + "<links/>");
+ assertPayloadEquals(request.getPayload(), withHeader("<links/>"), LinksDto.class);
}
- public void testBindSingleIp()
+ public void testBindSingleIp() throws IOException
{
IpPoolManagementDto ip = NetworkResources.privateIpPut();
BindIpRefsToPayload binder = new BindIpRefsToPayload(new JAXBParser("false"));
HttpRequest request =
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build();
request = binder.bindToRequest(request, new IpPoolManagementDto[] {ip});
- assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER
- + "<links><link href=\"" + ip.searchLink("self").getHref() + "\" rel=\""
- + ip.searchLink("self").getTitle() + "\"/></links>");
+ assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\""
+ + ip.searchLink("self").getHref() + "\" rel=\"" + ip.searchLink("self").getTitle()
+ + "\"/></links>"), LinksDto.class);
}
- public void testBindMultipleIps()
+ public void testBindMultipleIps() throws IOException
{
IpPoolManagementDto ip = NetworkResources.privateIpPut();
BindIpRefsToPayload binder = new BindIpRefsToPayload(new JAXBParser("false"));
HttpRequest request =
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build();
request = binder.bindToRequest(request, new IpPoolManagementDto[] {ip, ip});
- assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER
- + "<links><link href=\"" + ip.searchLink("self").getHref() + "\" rel=\""
- + ip.searchLink("self").getTitle() + "\"/></links>");
+ assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\""
+ + ip.searchLink("self").getHref() + "\" rel=\"" + ip.searchLink("self").getTitle()
+ + "\"/></links>"), LinksDto.class);
}
}
@@ -20,8 +20,9 @@
package org.jclouds.abiquo.binders.cloud;
import static org.jclouds.abiquo.domain.DomainUtils.withHeader;
-import static org.testng.Assert.assertEquals;
+import static org.jclouds.abiquo.util.Assert.assertPayloadEquals;
+import java.io.IOException;
import java.lang.reflect.Method;
import java.net.URI;
import java.util.NoSuchElementException;
@@ -36,6 +37,7 @@
import org.jclouds.xml.internal.JAXBParser;
import org.testng.annotations.Test;
+import com.abiquo.model.transport.LinksDto;
import com.abiquo.server.core.cloud.VirtualMachineDto;
import com.abiquo.server.core.infrastructure.network.VLANNetworkDto;
import com.google.common.collect.ImmutableList;
@@ -122,7 +124,8 @@ public void testBindNetworkConfigurationRefWithoutVirtualMachine() throws Securi
binder.bindToRequest(request, network);
}
- public void testBindNetworkConfigurationRef() throws SecurityException, NoSuchMethodException
+ public void testBindNetworkConfigurationRef() throws SecurityException, NoSuchMethodException,
+ IOException
{
VirtualMachineDto vm = CloudResources.virtualMachinePut();
VLANNetworkDto network = NetworkResources.privateNetworkPut();
@@ -142,8 +145,8 @@ public void testBindNetworkConfigurationRef() throws SecurityException, NoSuchMe
String configLink = vm.searchLink("configurations").getHref() + "/" + network.getId();
GeneratedHttpRequest<TestNetworkConfig> newRequest = binder.bindToRequest(request, network);
- assertEquals(newRequest.getPayload().getRawContent(), withHeader("<links><link href=\""
- + configLink + "\" rel=\"network_configuration\"/></links>"));
+ assertPayloadEquals(newRequest.getPayload(), withHeader("<links><link href=\"" + configLink
+ + "\" rel=\"network_configuration\"/></links>"), LinksDto.class);
}
static interface TestNetworkConfig
@@ -19,16 +19,18 @@
package org.jclouds.abiquo.binders.cloud;
-import static org.testng.Assert.assertEquals;
+import static org.jclouds.abiquo.domain.DomainUtils.withHeader;
+import static org.jclouds.abiquo.util.Assert.assertPayloadEquals;
+import java.io.IOException;
import java.net.URI;
import org.jclouds.abiquo.domain.NetworkResources;
import org.jclouds.http.HttpRequest;
-import org.jclouds.xml.XMLParser;
import org.jclouds.xml.internal.JAXBParser;
import org.testng.annotations.Test;
+import com.abiquo.model.transport.LinksDto;
import com.abiquo.server.core.infrastructure.network.VLANNetworkDto;
/**
@@ -58,15 +60,15 @@ public void testInvalidTypeInput()
binder.bindToRequest(request, new Object());
}
- public void testBindNetworkRef()
+ public void testBindNetworkRef() throws IOException
{
VLANNetworkDto network = NetworkResources.privateNetworkPut();
BindNetworkRefToPayload binder = new BindNetworkRefToPayload(new JAXBParser("false"));
HttpRequest request =
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build();
request = binder.bindToRequest(request, network);
- assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER
- + "<links><link href=\"" + network.getEditLink().getHref()
- + "\" rel=\"internalnetwork\"/></links>");
+ assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\""
+ + network.getEditLink().getHref() + "\" rel=\"internalnetwork\"/></links>"),
+ LinksDto.class);
}
}
@@ -19,17 +19,19 @@
package org.jclouds.abiquo.binders.cloud;
-import static org.testng.Assert.assertEquals;
+import static org.jclouds.abiquo.domain.DomainUtils.withHeader;
+import static org.jclouds.abiquo.util.Assert.assertPayloadEquals;
+import java.io.IOException;
import java.net.URI;
import org.jclouds.abiquo.domain.NetworkResources;
import org.jclouds.http.HttpRequest;
-import org.jclouds.xml.XMLParser;
import org.jclouds.xml.internal.JAXBParser;
import org.testng.annotations.Test;
import com.abiquo.model.rest.RESTLink;
+import com.abiquo.model.transport.LinksDto;
import com.abiquo.server.core.infrastructure.network.VLANNetworkDto;
/**
@@ -44,7 +46,8 @@
@Test(expectedExceptions = NullPointerException.class)
public void testInvalidNullInput()
{
- BindUnmanagedIpRefToPayload binder = new BindUnmanagedIpRefToPayload(new JAXBParser("false"));
+ BindUnmanagedIpRefToPayload binder =
+ new BindUnmanagedIpRefToPayload(new JAXBParser("false"));
HttpRequest request =
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build();
binder.bindToRequest(request, null);
@@ -53,21 +56,24 @@ public void testInvalidNullInput()
@Test(expectedExceptions = IllegalArgumentException.class)
public void testInvalidTypeInput()
{
- BindUnmanagedIpRefToPayload binder = new BindUnmanagedIpRefToPayload(new JAXBParser("false"));
+ BindUnmanagedIpRefToPayload binder =
+ new BindUnmanagedIpRefToPayload(new JAXBParser("false"));
HttpRequest request =
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build();
binder.bindToRequest(request, new Object());
}
- public void testBindUnmanagedNetworkIpRef()
+ public void testBindUnmanagedNetworkIpRef() throws IOException
{
VLANNetworkDto network = NetworkResources.unmanagedNetworkPut();
RESTLink ipsLink = network.searchLink("ips");
- BindUnmanagedIpRefToPayload binder = new BindUnmanagedIpRefToPayload(new JAXBParser("false"));
+ BindUnmanagedIpRefToPayload binder =
+ new BindUnmanagedIpRefToPayload(new JAXBParser("false"));
HttpRequest request =
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build();
request = binder.bindToRequest(request, network);
- assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER
- + "<links><link href=\"" + ipsLink.getHref() + "\" rel=\"unmanagedip\"/></links>");
+ assertPayloadEquals(request.getPayload(),
+ withHeader("<links><link href=\"" + ipsLink.getHref()
+ + "\" rel=\"unmanagedip\"/></links>"), LinksDto.class);
}
}
@@ -19,16 +19,18 @@
package org.jclouds.abiquo.binders.cloud;
-import static org.testng.Assert.assertEquals;
+import static org.jclouds.abiquo.domain.DomainUtils.withHeader;
+import static org.jclouds.abiquo.util.Assert.assertPayloadEquals;
+import java.io.IOException;
import java.net.URI;
import org.jclouds.abiquo.domain.CloudResources;
import org.jclouds.http.HttpRequest;
-import org.jclouds.xml.XMLParser;
import org.jclouds.xml.internal.JAXBParser;
import org.testng.annotations.Test;
+import com.abiquo.model.transport.LinksDto;
import com.abiquo.server.core.cloud.VirtualDatacenterDto;
/**
@@ -60,16 +62,16 @@ public void testInvalidTypeInput()
binder.bindToRequest(request, new Object());
}
- public void testBindSingleVolume()
+ public void testBindSingleVolume() throws IOException
{
VirtualDatacenterDto vdc = CloudResources.virtualDatacenterPut();
BindVirtualDatacenterRefToPayload binder =
new BindVirtualDatacenterRefToPayload(new JAXBParser("false"));
HttpRequest request =
HttpRequest.builder().method("GET").endpoint(URI.create("http://localhost")).build();
request = binder.bindToRequest(request, vdc);
- assertEquals(request.getPayload().getRawContent(), XMLParser.DEFAULT_XML_HEADER
- + "<links><link href=\"" + vdc.getEditLink().getHref()
- + "\" rel=\"virtualdatacenter\"/></links>");
+ assertPayloadEquals(request.getPayload(), withHeader("<links><link href=\""
+ + vdc.getEditLink().getHref() + "\" rel=\"virtualdatacenter\"/></links>"),
+ LinksDto.class);
}
}
Oops, something went wrong.

0 comments on commit 5ff6755

Please sign in to comment.