mirror of https://github.com/apache/jclouds.git
added setDriveData to elastichosts impl
This commit is contained in:
parent
0ca3a686f5
commit
486ba28360
|
@ -29,7 +29,9 @@ import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
import org.jclouds.elastichosts.binders.BindCreateDriveRequestToPlainTextString;
|
import org.jclouds.elastichosts.binders.BindCreateDriveRequestToPlainTextString;
|
||||||
|
import org.jclouds.elastichosts.binders.BindDriveDataToPlainTextString;
|
||||||
import org.jclouds.elastichosts.domain.CreateDriveRequest;
|
import org.jclouds.elastichosts.domain.CreateDriveRequest;
|
||||||
|
import org.jclouds.elastichosts.domain.DriveData;
|
||||||
import org.jclouds.elastichosts.domain.DriveInfo;
|
import org.jclouds.elastichosts.domain.DriveInfo;
|
||||||
import org.jclouds.elastichosts.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
|
import org.jclouds.elastichosts.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
|
||||||
import org.jclouds.elastichosts.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
|
import org.jclouds.elastichosts.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
|
||||||
|
@ -99,6 +101,16 @@ public interface ElasticHostsAsyncClient {
|
||||||
ListenableFuture<DriveInfo> createDrive(
|
ListenableFuture<DriveInfo> createDrive(
|
||||||
@BinderParam(BindCreateDriveRequestToPlainTextString.class) CreateDriveRequest createDrive);
|
@BinderParam(BindCreateDriveRequestToPlainTextString.class) CreateDriveRequest createDrive);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @see ElasticHostsClient#setDriveData
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@ExceptionParser(ReturnNullOnNotFoundOr404.class)
|
||||||
|
@ResponseParser(KeyValuesDelimitedByBlankLinesToDriveInfo.class)
|
||||||
|
@Path("/drives/{uuid}/set")
|
||||||
|
ListenableFuture<DriveInfo> setDriveData(@PathParam("uuid") String uuid,
|
||||||
|
@BinderParam(BindDriveDataToPlainTextString.class) DriveData createDrive);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see ElasticHostsClient#deleteDrive
|
* @see ElasticHostsClient#deleteDrive
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
import org.jclouds.concurrent.Timeout;
|
import org.jclouds.concurrent.Timeout;
|
||||||
import org.jclouds.elastichosts.domain.CreateDriveRequest;
|
import org.jclouds.elastichosts.domain.CreateDriveRequest;
|
||||||
|
import org.jclouds.elastichosts.domain.DriveData;
|
||||||
import org.jclouds.elastichosts.domain.DriveInfo;
|
import org.jclouds.elastichosts.domain.DriveInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,6 +74,17 @@ public interface ElasticHostsClient {
|
||||||
*/
|
*/
|
||||||
DriveInfo createDrive(CreateDriveRequest createDrive);
|
DriveInfo createDrive(CreateDriveRequest createDrive);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* set extra drive data
|
||||||
|
*
|
||||||
|
* @param uuid
|
||||||
|
* what drive to change
|
||||||
|
* @param driveData
|
||||||
|
* what values to change
|
||||||
|
* @return new data
|
||||||
|
*/
|
||||||
|
DriveInfo setDriveData(String uuid, DriveData driveData);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Destroy a drive
|
* Destroy a drive
|
||||||
*
|
*
|
||||||
|
|
|
@ -0,0 +1,61 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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.elastichosts.binders;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.jclouds.elastichosts.domain.DriveData;
|
||||||
|
import org.jclouds.elastichosts.functions.DriveDataToMap;
|
||||||
|
import org.jclouds.elastichosts.functions.ListOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.rest.Binder;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class BindDriveDataToPlainTextString implements Binder {
|
||||||
|
private final DriveDataToMap createDriveRequestToMap;
|
||||||
|
private final ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public BindDriveDataToPlainTextString(DriveDataToMap createDriveRequestToMap,
|
||||||
|
ListOfMapsToListOfKeyValuesDelimitedByBlankLines listOfMapsToListOfKeyValuesDelimitedByBlankLines) {
|
||||||
|
this.createDriveRequestToMap = createDriveRequestToMap;
|
||||||
|
this.listOfMapsToListOfKeyValuesDelimitedByBlankLines = listOfMapsToListOfKeyValuesDelimitedByBlankLines;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void bindToRequest(HttpRequest request, Object payload) {
|
||||||
|
checkArgument(payload instanceof DriveData, "this binder is only valid for DriveData!");
|
||||||
|
DriveData create = DriveData.class.cast(payload);
|
||||||
|
Map<String, String> map = createDriveRequestToMap.apply(create);
|
||||||
|
request.setPayload(listOfMapsToListOfKeyValuesDelimitedByBlankLines.apply(ImmutableSet.of(map)));
|
||||||
|
request.getPayload().getContentMetadata().setContentType(MediaType.TEXT_PLAIN);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,93 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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.elastichosts.domain;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
|
import org.jclouds.elastichosts.domain.internal.BaseDrive;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
public class DriveData extends BaseDrive {
|
||||||
|
public static class Builder extends BaseDrive.Builder {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder claimType(ClaimType claimType) {
|
||||||
|
return Builder.class.cast(super.claimType(claimType));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder name(String name) {
|
||||||
|
return Builder.class.cast(super.name(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder readers(Iterable<String> readers) {
|
||||||
|
return Builder.class.cast(super.readers(readers));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder size(long size) {
|
||||||
|
return Builder.class.cast(super.size(size));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder tags(Iterable<String> tags) {
|
||||||
|
return Builder.class.cast(super.tags(tags));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public Builder userMetadata(Map<String, String> userMetadata) {
|
||||||
|
return Builder.class.cast(super.userMetadata(userMetadata));
|
||||||
|
}
|
||||||
|
|
||||||
|
public DriveData build() {
|
||||||
|
return new DriveData(name, size, claimType, readers, tags, userMetadata);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DriveData(String name, long size, @Nullable ClaimType claimType, Iterable<String> readers,
|
||||||
|
Iterable<String> tags, Map<String, String> userMetadata) {
|
||||||
|
super(name, size, claimType, readers, tags, userMetadata);
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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.elastichosts.functions;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Singleton;
|
||||||
|
|
||||||
|
import org.jclouds.elastichosts.domain.DriveData;
|
||||||
|
|
||||||
|
import com.google.common.base.Function;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Singleton
|
||||||
|
public class DriveDataToMap implements Function<DriveData, Map<String, String>> {
|
||||||
|
private final BaseDriveToMap baseDriveToMap;
|
||||||
|
|
||||||
|
@Inject
|
||||||
|
public DriveDataToMap(BaseDriveToMap baseDriveToMap) {
|
||||||
|
this.baseDriveToMap = baseDriveToMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, String> apply(DriveData from) {
|
||||||
|
ImmutableMap.Builder<String, String> builder = ImmutableMap.builder();
|
||||||
|
builder.putAll(baseDriveToMap.apply(from));
|
||||||
|
return builder.build();
|
||||||
|
}
|
||||||
|
}
|
|
@ -26,6 +26,7 @@ import java.io.IOException;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
||||||
import org.jclouds.elastichosts.domain.CreateDriveRequest;
|
import org.jclouds.elastichosts.domain.CreateDriveRequest;
|
||||||
|
import org.jclouds.elastichosts.domain.DriveData;
|
||||||
import org.jclouds.elastichosts.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
|
import org.jclouds.elastichosts.functions.KeyValuesDelimitedByBlankLinesToDriveInfo;
|
||||||
import org.jclouds.elastichosts.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
|
import org.jclouds.elastichosts.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet;
|
||||||
import org.jclouds.elastichosts.functions.SplitNewlines;
|
import org.jclouds.elastichosts.functions.SplitNewlines;
|
||||||
|
@ -142,6 +143,23 @@ public class ElasticHostsAsyncClientTest extends RestClientTest<ElasticHostsAsyn
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testSetDriveData() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
|
Method method = ElasticHostsAsyncClient.class.getMethod("setDriveData", String.class, DriveData.class);
|
||||||
|
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method, "100",
|
||||||
|
new DriveData.Builder().name("foo").size(10000l).build());
|
||||||
|
|
||||||
|
assertRequestLineEquals(httpRequest, "POST https://api.elastichosts.com/drives/100/set HTTP/1.1");
|
||||||
|
assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n");
|
||||||
|
assertPayloadEquals(httpRequest, "name foo\nsize 10000", "text/plain", false);
|
||||||
|
|
||||||
|
assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class);
|
||||||
|
assertSaxResponseParserClassEquals(method, null);
|
||||||
|
assertExceptionParserClassEquals(method, ReturnNullOnNotFoundOr404.class);
|
||||||
|
|
||||||
|
checkFilters(httpRequest);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public void testDestroyDrive() throws SecurityException, NoSuchMethodException, IOException {
|
public void testDestroyDrive() throws SecurityException, NoSuchMethodException, IOException {
|
||||||
Method method = ElasticHostsAsyncClient.class.getMethod("destroyDrive", String.class);
|
Method method = ElasticHostsAsyncClient.class.getMethod("destroyDrive", String.class);
|
||||||
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method, "uuid");
|
GeneratedHttpRequest<ElasticHostsAsyncClient> httpRequest = processor.createRequest(method, "uuid");
|
||||||
|
|
|
@ -29,7 +29,9 @@ import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
import org.jclouds.Constants;
|
import org.jclouds.Constants;
|
||||||
|
import org.jclouds.elastichosts.domain.ClaimType;
|
||||||
import org.jclouds.elastichosts.domain.CreateDriveRequest;
|
import org.jclouds.elastichosts.domain.CreateDriveRequest;
|
||||||
|
import org.jclouds.elastichosts.domain.DriveData;
|
||||||
import org.jclouds.elastichosts.domain.DriveInfo;
|
import org.jclouds.elastichosts.domain.DriveInfo;
|
||||||
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
||||||
import org.jclouds.rest.RestContext;
|
import org.jclouds.rest.RestContext;
|
||||||
|
@ -38,6 +40,7 @@ import org.testng.annotations.BeforeGroups;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
import com.google.common.base.Predicate;
|
import com.google.common.base.Predicate;
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
import com.google.common.collect.ImmutableSet;
|
import com.google.common.collect.ImmutableSet;
|
||||||
import com.google.common.collect.Iterables;
|
import com.google.common.collect.Iterables;
|
||||||
import com.google.inject.Module;
|
import com.google.inject.Module;
|
||||||
|
@ -128,27 +131,45 @@ public class ElasticHostsClientLiveTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
private String prefix = System.getProperty("user.name") + ".test";
|
private String prefix = System.getProperty("user.name") + ".test";
|
||||||
|
private DriveInfo info;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testCreateDestroy() throws Exception {
|
public void testCreate() throws Exception {
|
||||||
try {
|
try {
|
||||||
findAndDestroyDrive();
|
findAndDestroyDrive();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
String uuid = null;
|
|
||||||
try {
|
|
||||||
|
|
||||||
DriveInfo info = client.createDrive(new CreateDriveRequest.Builder().name(prefix).size(1024 * 1024l).build());
|
info = client.createDrive(new CreateDriveRequest.Builder().name(prefix).size(1024 * 1024l).build());
|
||||||
assertNotNull(uuid = info.getUuid());
|
assertNotNull(info.getUuid());
|
||||||
assertEquals(info.getName(), prefix);
|
assertEquals(info.getName(), prefix);
|
||||||
assertEquals(info.getSize(), 1024 * 1024l);
|
assertEquals(info.getSize(), 1024 * 1024l);
|
||||||
assertEquals(info, client.getDriveInfo(info.getUuid()));
|
assertEquals(info, client.getDriveInfo(info.getUuid()));
|
||||||
} finally {
|
|
||||||
findAndDestroyDrive();
|
}
|
||||||
}
|
|
||||||
if (uuid != null)
|
@Test(dependsOnMethods = "testCreate")
|
||||||
assertEquals(client.getDriveInfo(uuid), null);
|
public void testSetDriveData() throws Exception {
|
||||||
|
|
||||||
|
DriveInfo info2 = client.setDriveData(
|
||||||
|
info.getUuid(),
|
||||||
|
new DriveData.Builder().claimType(ClaimType.SHARED).name("rediculous")
|
||||||
|
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))
|
||||||
|
.tags(ImmutableSet.of("tag1", "tag2")).userMetadata(ImmutableMap.of("foo", "bar")).build());
|
||||||
|
assertNotNull(info2.getUuid(), info.getUuid());
|
||||||
|
assertEquals(info.getName(), "rediculous");
|
||||||
|
assertEquals(info.getClaimType(), ClaimType.SHARED);
|
||||||
|
assertEquals(info.getReaders(), ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"));
|
||||||
|
assertEquals(info.getTags(), ImmutableSet.of("tag1", "tag2"));
|
||||||
|
assertEquals(info.getUserMetadata(), ImmutableMap.of("foo", "bar"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods = "testSetDriveData")
|
||||||
|
public void testDestroyDrive() throws Exception {
|
||||||
|
|
||||||
|
findAndDestroyDrive();
|
||||||
|
assertEquals(client.getDriveInfo(info.getUuid()), null);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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.elastichosts.binders;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.net.URI;
|
||||||
|
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
import org.jclouds.elastichosts.domain.ClaimType;
|
||||||
|
import org.jclouds.elastichosts.domain.DriveData;
|
||||||
|
import org.jclouds.http.HttpRequest;
|
||||||
|
import org.jclouds.util.Utils;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = { "unit" })
|
||||||
|
public class BindDriveDataToPlainTextStringTest {
|
||||||
|
|
||||||
|
private static final BindDriveDataToPlainTextString FN = Guice.createInjector().getInstance(
|
||||||
|
BindDriveDataToPlainTextString.class);
|
||||||
|
|
||||||
|
public void testSimple() {
|
||||||
|
HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
|
||||||
|
FN.bindToRequest(request, new DriveData.Builder().name("foo").size(100l).build());
|
||||||
|
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
|
||||||
|
assertEquals(request.getPayload().getRawContent(), "name foo\nsize 100");
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testComplete() throws IOException {
|
||||||
|
DriveData input = new DriveData.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
|
||||||
|
//
|
||||||
|
.size(8589934592l)//
|
||||||
|
.claimType(ClaimType.SHARED)//
|
||||||
|
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
|
||||||
|
.tags(ImmutableSet.of("tag1", "tag2")).userMetadata(ImmutableMap.of("foo", "bar", "baz", "raz"))//
|
||||||
|
.build();
|
||||||
|
|
||||||
|
HttpRequest request = new HttpRequest("POST", URI.create("https://host/drives/create"));
|
||||||
|
FN.bindToRequest(request, input);
|
||||||
|
assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN);
|
||||||
|
assertEquals(request.getPayload().getRawContent(),
|
||||||
|
Utils.toStringAndClose(BindDriveDataToPlainTextStringTest.class
|
||||||
|
.getResourceAsStream("/drive_data.txt")));
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,66 @@
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* Copyright (C) 2010 Cloud Conscious, LLC. <info@cloudconscious.com>
|
||||||
|
*
|
||||||
|
* ====================================================================
|
||||||
|
* Licensed 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.elastichosts.functions;
|
||||||
|
|
||||||
|
import static org.testng.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import org.jclouds.elastichosts.domain.ClaimType;
|
||||||
|
import org.jclouds.elastichosts.domain.DriveData;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableMap;
|
||||||
|
import com.google.common.collect.ImmutableSet;
|
||||||
|
import com.google.inject.Guice;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @author Adrian Cole
|
||||||
|
*/
|
||||||
|
@Test(groups = { "unit" })
|
||||||
|
public class DriveDataToMapTest {
|
||||||
|
|
||||||
|
private static final DriveDataToMap BASEDRIVE_TO_MAP = Guice.createInjector().getInstance(DriveDataToMap.class);
|
||||||
|
|
||||||
|
public void testBasics() {
|
||||||
|
assertEquals(BASEDRIVE_TO_MAP.apply(new DriveData.Builder().name("foo").size(100l).build()),
|
||||||
|
ImmutableMap.of("name", "foo", "size", "100"));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void testComplete() throws IOException {
|
||||||
|
DriveData one = new DriveData.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
|
||||||
|
//
|
||||||
|
.size(8589934592l)//
|
||||||
|
.claimType(ClaimType.SHARED)//
|
||||||
|
.readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))//
|
||||||
|
.tags(ImmutableSet.of("tag1", "tag2")).userMetadata(ImmutableMap.of("foo", "bar", "baz", "raz"))//
|
||||||
|
.build();
|
||||||
|
assertEquals(
|
||||||
|
BASEDRIVE_TO_MAP.apply(one),
|
||||||
|
ImmutableMap.builder().put("name", "Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System")
|
||||||
|
.put("size", "8589934592").put("claim:type", "shared")
|
||||||
|
.put("readers", "ffffffff-ffff-ffff-ffff-ffffffffffff").put("tags", "tag1 tag2")
|
||||||
|
.put("user:foo", "bar").put("user:baz", "raz").build()
|
||||||
|
|
||||||
|
);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,7 @@
|
||||||
|
name Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System
|
||||||
|
size 8589934592
|
||||||
|
claim:type shared
|
||||||
|
readers ffffffff-ffff-ffff-ffff-ffffffffffff
|
||||||
|
tags tag1 tag2
|
||||||
|
user:foo bar
|
||||||
|
user:baz raz
|
Loading…
Reference in New Issue