mirror of https://github.com/apache/jclouds.git
Merge pull request #107 from grkvlt/master
Issue 612: Fix problem with XML parsing
This commit is contained in:
commit
e3e423df3d
|
@ -20,8 +20,6 @@ package org.jclouds.aws.ec2.xml;
|
|||
|
||||
import static org.jclouds.util.SaxUtils.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.jclouds.aws.ec2.domain.SpotInstanceRequest;
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.xml;
|
||||
|
||||
import static org.jclouds.util.SaxUtils.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
|
@ -40,7 +42,6 @@ public class TagSetHandler extends ParseSax.HandlerForGeneratedRequestWithResult
|
|||
|
||||
public TagSetHandler() {
|
||||
super();
|
||||
this.result = ImmutableMap.<String, String>builder();
|
||||
}
|
||||
|
||||
public Map<String, String> getResult() {
|
||||
|
@ -49,7 +50,9 @@ public class TagSetHandler extends ParseSax.HandlerForGeneratedRequestWithResult
|
|||
|
||||
@Override
|
||||
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
|
||||
if (qName.equals("item")) {
|
||||
if (equalsOrSuffix(qName, "tagSet")) {
|
||||
result = ImmutableMap.<String, String>builder();
|
||||
} else if (qName.equals("item")) {
|
||||
inItem = true;
|
||||
key = null;
|
||||
value = null;
|
||||
|
@ -67,9 +70,9 @@ public class TagSetHandler extends ParseSax.HandlerForGeneratedRequestWithResult
|
|||
}
|
||||
if (inItem) {
|
||||
if (qName.equals("key")) {
|
||||
key = currentText.toString().trim();
|
||||
key = currentOrNull(currentText);
|
||||
} else if (qName.equals("value")) {
|
||||
value = currentText.toString().trim();
|
||||
value = currentOrNull(currentText);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,12 +18,12 @@
|
|||
*/
|
||||
package org.jclouds.aws.ec2.xml;
|
||||
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.classextension.EasyMock.createMock;
|
||||
import static org.easymock.classextension.EasyMock.replay;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.classextension.EasyMock.*;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.jclouds.aws.ec2.domain.SpotInstanceRequest;
|
||||
|
@ -36,7 +36,12 @@ import org.jclouds.rest.internal.GeneratedHttpRequest;
|
|||
import org.testng.annotations.BeforeTest;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import com.google.common.collect.ImmutableMap;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.google.inject.AbstractModule;
|
||||
import com.google.inject.Guice;
|
||||
|
||||
|
@ -85,6 +90,27 @@ public class SpotInstancesHandlerTest extends BaseEC2HandlerTest {
|
|||
assertEquals(result.size(), 3);
|
||||
}
|
||||
|
||||
public void testParseTags() {
|
||||
Set<SpotInstanceRequest> result = factory.create(injector.getInstance(SpotInstancesHandler.class)).parse(
|
||||
getClass().getResourceAsStream("/describe_spot_instance_tags.xml"));
|
||||
Iterable<Map<String, String>> tags = Iterables.transform(result, new Function<SpotInstanceRequest, Map<String, String>>() {
|
||||
@Override
|
||||
public Map<String, String> apply(SpotInstanceRequest input) {
|
||||
return input.getTags();
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(
|
||||
Iterables.get(tags, 0),
|
||||
ImmutableMap.of("One", "one", "Two", "one"));
|
||||
assertEquals(
|
||||
Iterables.get(tags, 1),
|
||||
ImmutableMap.of("One", "two", "Two", "two"));
|
||||
assertEquals(
|
||||
Iterables.get(tags, 2),
|
||||
ImmutableMap.of("Two", "three", "Three", "three", "Four", ""));
|
||||
}
|
||||
|
||||
public void testParseNoNPE() {
|
||||
factory.create(injector.getInstance(SpotInstancesHandler.class)).parse(
|
||||
getClass().getResourceAsStream("/describe_spot_instances_1.xml"));
|
||||
|
|
|
@ -0,0 +1,115 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<DescribeSpotInstanceRequestsResponse xmlns="http://ec2.amazonaws.com/doc/2011-05-15/">
|
||||
<requestId>f2247378-7df0-4725-b55f-8ef58b557dcd</requestId>
|
||||
<spotInstanceRequestSet>
|
||||
<item>
|
||||
<spotInstanceRequestId>sir-f4d44212</spotInstanceRequestId>
|
||||
<spotPrice>0.300000</spotPrice>
|
||||
<type>one-time</type>
|
||||
<state>cancelled</state>
|
||||
<launchSpecification>
|
||||
<imageId>ami-8e1fece7</imageId>
|
||||
<keyName>ec2-o</keyName>
|
||||
<groupSet>
|
||||
<item>
|
||||
<groupName>jclouds#ec2-o#us-east-1</groupName>
|
||||
</item>
|
||||
<item>
|
||||
<groupName>ec2-o</groupName>
|
||||
</item>
|
||||
</groupSet>
|
||||
<instanceType>t1.micro</instanceType>
|
||||
<blockDeviceMapping/>
|
||||
<monitoring>
|
||||
<enabled>true</enabled>
|
||||
</monitoring>
|
||||
</launchSpecification>
|
||||
<createTime>2011-07-29T04:01:12.000Z</createTime>
|
||||
<productDescription>Linux/UNIX</productDescription>
|
||||
<tagSet>
|
||||
<item>
|
||||
<key>One</key>
|
||||
<value>one</value>
|
||||
</item>
|
||||
<item>
|
||||
<key>Two</key>
|
||||
<value>one</value>
|
||||
</item>
|
||||
</tagSet>
|
||||
<launchedAvailabilityZone>us-east-1b</launchedAvailabilityZone>
|
||||
</item>
|
||||
<item>
|
||||
<spotInstanceRequestId>sir-43408412</spotInstanceRequestId>
|
||||
<spotPrice>0.300000</spotPrice>
|
||||
<type>one-time</type>
|
||||
<state>cancelled</state>
|
||||
<launchSpecification>
|
||||
<imageId>ami-8e1fece7</imageId>
|
||||
<keyName>jclouds#adriancole-ec2unssh</keyName>
|
||||
<groupSet>
|
||||
<item>
|
||||
<groupName>jclouds#adriancole-ec2unssh#us-east-1</groupName>
|
||||
</item>
|
||||
</groupSet>
|
||||
<instanceType>t1.micro</instanceType>
|
||||
<blockDeviceMapping/>
|
||||
<monitoring>
|
||||
<enabled>false</enabled>
|
||||
</monitoring>
|
||||
</launchSpecification>
|
||||
<createTime>2011-07-29T04:02:53.000Z</createTime>
|
||||
<productDescription>Linux/UNIX</productDescription>
|
||||
<tagSet>
|
||||
<item>
|
||||
<key>One</key>
|
||||
<value>two</value>
|
||||
</item>
|
||||
<item>
|
||||
<key>Two</key>
|
||||
<value>two</value>
|
||||
</item>
|
||||
</tagSet>
|
||||
<launchedAvailabilityZone>us-east-1b</launchedAvailabilityZone>
|
||||
</item>
|
||||
<item>
|
||||
<spotInstanceRequestId>sir-e4c3fa14</spotInstanceRequestId>
|
||||
<spotPrice>0.300000</spotPrice>
|
||||
<type>one-time</type>
|
||||
<state>closed</state>
|
||||
<launchSpecification>
|
||||
<imageId>ami-8e1fece7</imageId>
|
||||
<keyName>ec2-o</keyName>
|
||||
<groupSet>
|
||||
<item>
|
||||
<groupName>jclouds#ec2-o#us-east-1</groupName>
|
||||
</item>
|
||||
<item>
|
||||
<groupName>ec2-o</groupName>
|
||||
</item>
|
||||
</groupSet>
|
||||
<instanceType>t1.micro</instanceType>
|
||||
<blockDeviceMapping/>
|
||||
<monitoring>
|
||||
<enabled>true</enabled>
|
||||
</monitoring>
|
||||
</launchSpecification>
|
||||
<createTime>2011-07-29T05:25:49.000Z</createTime>
|
||||
<productDescription>Linux/UNIX</productDescription>
|
||||
<tagSet>
|
||||
<item>
|
||||
<key>Two</key>
|
||||
<value>three</value>
|
||||
</item>
|
||||
<item>
|
||||
<key>Three</key>
|
||||
<value>three</value>
|
||||
</item>
|
||||
<item>
|
||||
<key>Four</key>
|
||||
<value />
|
||||
</item>
|
||||
</tagSet>
|
||||
<launchedAvailabilityZone>us-east-1c</launchedAvailabilityZone>
|
||||
</item>
|
||||
</spotInstanceRequestSet>
|
||||
</DescribeSpotInstanceRequestsResponse>
|
Loading…
Reference in New Issue