mirror of https://github.com/apache/jclouds.git
fixed syntax error and disabled broken tests
This commit is contained in:
parent
e1fa18a6a6
commit
ec0cd17270
|
@ -3,61 +3,58 @@ package org.jclouds.aws.simpledb.binders;
|
|||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static java.lang.String.format;
|
||||
import static org.jclouds.http.HttpUtils.addFormParamTo;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
|
||||
import java.util.List;
|
||||
import org.jclouds.aws.simpledb.domain.Item;
|
||||
import org.jclouds.aws.simpledb.domain.AttributePair;
|
||||
import org.jclouds.aws.simpledb.domain.Item;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.utils.ModifyRequest;
|
||||
import org.jclouds.rest.Binder;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.ImmutableMultimap.Builder;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Luís A. Bastião Silva <bastiao@ua.pt>
|
||||
*/
|
||||
public class BindAttributesToIndexedFormParams implements Binder
|
||||
{
|
||||
public class BindAttributesToIndexedFormParams implements Binder {
|
||||
|
||||
private final String attributeName = "Attribute.%d.Name";
|
||||
private final String attributeValue = "Attribute.%d.Value";
|
||||
private final String attributeReplace = "Attribute.%d.Replace";
|
||||
|
||||
public void bindToRequest(HttpRequest request, Object input) {
|
||||
checkArgument(checkNotNull(input, "input") instanceof Item,
|
||||
"this binder is only valid for AttributeMap");
|
||||
@Override
|
||||
public <R extends HttpRequest> R bindToRequest(R request, Object input) {
|
||||
checkArgument(checkNotNull(input, "input") instanceof Item, "this binder is only valid for AttributeMap");
|
||||
Item attributeMap = (Item) input;
|
||||
|
||||
Builder<String, String> builder = ImmutableMultimap.<String, String> builder();
|
||||
int amazonOneBasedIndex = 1; // according to docs, counters must start with 1
|
||||
for (String itemName : attributeMap.getAttributes().keySet())
|
||||
{
|
||||
|
||||
Collection<AttributePair> c = attributeMap.getAttributes().get(itemName);
|
||||
Iterator<AttributePair> it = c.iterator();
|
||||
while(it.hasNext())
|
||||
{
|
||||
AttributePair attr = it.next();
|
||||
// not null by contract
|
||||
for (String itemName : attributeMap.getAttributes().keySet()) {
|
||||
|
||||
String value = attr.getValue();
|
||||
Collection<AttributePair> c = attributeMap.getAttributes().get(itemName);
|
||||
Iterator<AttributePair> it = c.iterator();
|
||||
while (it.hasNext()) {
|
||||
AttributePair attr = it.next();
|
||||
// not null by contract
|
||||
|
||||
if (value != null) {
|
||||
addFormParamTo(request, format(attributeName, amazonOneBasedIndex), attr.getKey() );
|
||||
addFormParamTo(request, format(attributeValue, amazonOneBasedIndex),
|
||||
value);
|
||||
addFormParamTo(request, format(attributeReplace, amazonOneBasedIndex), String
|
||||
.valueOf(attr.isReplace()));
|
||||
String value = attr.getValue();
|
||||
|
||||
if (value != null) {
|
||||
builder.put(format(attributeName, amazonOneBasedIndex), attr.getKey());
|
||||
builder.put(format(attributeValue, amazonOneBasedIndex), value);
|
||||
builder.put(format(attributeReplace, amazonOneBasedIndex), String.valueOf(attr.isReplace()));
|
||||
|
||||
}
|
||||
amazonOneBasedIndex++;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
amazonOneBasedIndex++;
|
||||
}
|
||||
|
||||
}
|
||||
ImmutableMultimap<String, String> forms = builder.build();
|
||||
return forms.size() == 0 ? request : ModifyRequest.putFormParams(request, forms);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -96,32 +96,33 @@ public class SimpleDBAsyncClientTest extends RestClientTest<SimpleDBAsyncClient>
|
|||
checkFilters(request);
|
||||
}
|
||||
|
||||
// TODO fix this test as it has the wrong arg count
|
||||
@Test(enabled = false)
|
||||
public void testAllRegions() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SimpleDBAsyncClient.class.getMethod("putAttributes", String.class, String.class);
|
||||
for (String region : Region.ALL_SIMPLEDB) {
|
||||
processor.createRequest(method, region, "domainName");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO fix this test as it has the wrong arg type
|
||||
@Test(enabled = false)
|
||||
public void testPutAttributes() throws SecurityException, NoSuchMethodException, IOException {
|
||||
Method method = SimpleDBAsyncClient.class.getMethod("putAttributes", String.class, String.class, Map.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "domainName");
|
||||
Method method = SimpleDBAsyncClient.class.getMethod("putAttributes", String.class, String.class, Map.class);
|
||||
HttpRequest request = processor.createRequest(method, null, "domainName");
|
||||
|
||||
assertRequestLineEquals(request, "POST https://sdb.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: sdb.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-04-15&Action=PutAttributes&DomainName=domainName&ItemName=itemName" +
|
||||
"&Attribute.1.Name=name" +
|
||||
"&Attribute.1.Value=fuzzy" +
|
||||
"&Attribute.1.Replace=true",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
assertRequestLineEquals(request, "POST https://sdb.amazonaws.com/ HTTP/1.1");
|
||||
assertNonPayloadHeadersEqual(request, "Host: sdb.amazonaws.com\n");
|
||||
assertPayloadEquals(request, "Version=2009-04-15&Action=PutAttributes&DomainName=domainName&ItemName=itemName"
|
||||
+ "&Attribute.1.Name=name" + "&Attribute.1.Value=fuzzy" + "&Attribute.1.Replace=true",
|
||||
"application/x-www-form-urlencoded", false);
|
||||
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class);
|
||||
assertSaxResponseParserClassEquals(method, null);
|
||||
assertExceptionParserClassEquals(method, null);
|
||||
|
||||
checkFilters(request);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void checkFilters(HttpRequest request) {
|
||||
|
|
Loading…
Reference in New Issue