From 7525fc7a156f57b8a69bec35090e33c1cb083724 Mon Sep 17 00:00:00 2001 From: Jason King Date: Wed, 14 Dec 2011 16:41:55 +0000 Subject: [PATCH 1/4] Issue 695: Converted XML generation to use XMLBuilder --- .../tmrk-enterprisecloud/pom.xml | 10 ++++++ .../binders/BindSSHKeyToXmlPayload.java | 31 +++++++++++++------ ...remarkEnterpriseCloudRestClientModule.java | 7 ----- .../src/main/resources/editSSHKey.xml | 4 --- .../binders/BindSSHKeyToXmlPayloadTest.java | 23 ++++++-------- .../features/SSHKeyAsyncClientTest.java | 5 +-- 6 files changed, 41 insertions(+), 39 deletions(-) delete mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/resources/editSSHKey.xml diff --git a/sandbox-providers/tmrk-enterprisecloud/pom.xml b/sandbox-providers/tmrk-enterprisecloud/pom.xml index 398db07912..bc481936f1 100644 --- a/sandbox-providers/tmrk-enterprisecloud/pom.xml +++ b/sandbox-providers/tmrk-enterprisecloud/pom.xml @@ -60,6 +60,11 @@ jclouds-compute ${project.version} + + com.jamesmurty.utils + java-xmlbuilder + 0.4 + org.jclouds jclouds-core @@ -86,6 +91,11 @@ ${project.version} test + + com.jamesmurty.utils + java-xmlbuilder + 0.3 + diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindSSHKeyToXmlPayload.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindSSHKeyToXmlPayload.java index 3cbc5f6dc5..1720c1cad1 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindSSHKeyToXmlPayload.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindSSHKeyToXmlPayload.java @@ -18,16 +18,17 @@ */ package org.jclouds.tmrk.enterprisecloud.binders; -import com.google.common.collect.ImmutableMap; +import com.jamesmurty.utils.XMLBuilder; import org.jclouds.http.HttpRequest; import org.jclouds.rest.Binder; import org.jclouds.rest.binders.BindToStringPayload; import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKey; -import org.jclouds.util.Strings2; import javax.inject.Inject; -import javax.inject.Named; import javax.inject.Singleton; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; +import java.util.Properties; import static com.google.common.base.Preconditions.checkArgument; import static com.google.common.base.Preconditions.checkNotNull; @@ -39,13 +40,10 @@ import static com.google.common.base.Preconditions.checkNotNull; @Singleton public class BindSSHKeyToXmlPayload implements Binder { - private final String xmlTemplate; private final BindToStringPayload stringBinder; @Inject - BindSSHKeyToXmlPayload(@Named("EditSSHKey") String xmlTemplate, - BindToStringPayload stringBinder) { - this.xmlTemplate = xmlTemplate; + BindSSHKeyToXmlPayload(BindToStringPayload stringBinder) { this.stringBinder = stringBinder; } @@ -59,9 +57,22 @@ public class BindSSHKeyToXmlPayload implements Binder { String isDefault = Boolean.toString(sshKey.isDefaultKey()); String fingerPrint = sshKey.getFingerPrint(); - String payload = Strings2.replaceTokens(xmlTemplate, - ImmutableMap.of("name", name, "isDefault", isDefault, "fingerPrint", fingerPrint)); - + String payload = createXMLPayload(name,isDefault,fingerPrint); return stringBinder.bindToRequest(request, payload); } + + private String createXMLPayload(String name, String isDefault, String fingerPrint) { + try { + Properties outputProperties = new Properties(); + outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); + return XMLBuilder.create("SshKey").a("name",name) + .e("Default").t(isDefault).up() + .e("FingerPrint").t(fingerPrint) + .asString(outputProperties); + } catch (ParserConfigurationException e) { + throw new RuntimeException(e); + } catch (TransformerException t) { + throw new RuntimeException(t); + } + } } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java index 5cff6ef7aa..9e93968f74 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/config/TerremarkEnterpriseCloudRestClientModule.java @@ -82,11 +82,4 @@ public class TerremarkEnterpriseCloudRestClientModule extends protected void bindRetryHandlers() { bind(HttpRetryHandler.class).annotatedWith(ClientError.class).to(BackoffLimitedRetryHandler.class); } - - @Singleton - @Provides - @Named("EditSSHKey") - String provideEditSSHKey() throws IOException { - return Strings2.toStringAndClose(getClass().getResourceAsStream("/EditSSHKey.xml")); - } } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/resources/editSSHKey.xml b/sandbox-providers/tmrk-enterprisecloud/src/main/resources/editSSHKey.xml deleted file mode 100644 index bf23606594..0000000000 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/resources/editSSHKey.xml +++ /dev/null @@ -1,4 +0,0 @@ - - {isDefault} - {fingerPrint} - \ No newline at end of file diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindSSHKeyToXmlPayloadTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindSSHKeyToXmlPayloadTest.java index f13e59fd36..86ea476ffc 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindSSHKeyToXmlPayloadTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindSSHKeyToXmlPayloadTest.java @@ -46,28 +46,23 @@ public class BindSSHKeyToXmlPayloadTest { @Override protected void configure() { } - - @SuppressWarnings("unused") - @Singleton - @Provides - @Named("EditSSHKey") - String provideInstantiateVAppTemplateParams() throws IOException { - InputStream is = getClass().getResourceAsStream("/EditSSHKey.xml"); - return Strings2.toStringAndClose(is); - } }); - public void testApplyInputStream() throws IOException { - String expected = Strings2.toStringAndClose(getClass().getResourceAsStream( - "/EditSSHKey-test.xml")); + public void testPayloadXmlContent() throws IOException { + final String name = "newName"; + final boolean isDefault = false; + final String fingerPrint = "123"; + final String expected = String.format("%b%s", + name,isDefault,fingerPrint); + HttpRequest request = new HttpRequest("GET", URI.create("http://test")); BindSSHKeyToXmlPayload binder = injector .getInstance(BindSSHKeyToXmlPayload.class); SSHKey key = SSHKey.builder().type("application/vnd.tmrk.cloud.admin.sshKey") .href(URI.create("/cloudapi/ecloud/admin/sshkeys/77")) - .name("newName") - .defaultKey(false).fingerPrint("123").build(); + .name(name) + .defaultKey(isDefault).fingerPrint(fingerPrint).build(); binder.bindToRequest(request, key); assertEquals(request.getPayload().getRawContent(), expected); diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java index 25a600b390..30b37079ef 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java @@ -99,10 +99,7 @@ public class SSHKeyAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClie assertRequestLineEquals(httpRequest, "PUT https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/admin/sshkeys/77 HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.admin.sshKey\nx-tmrk-version: 2011-07-01\n"); - String xml = "\n" + - " false\n" + - " 123\n" + - ""; + String xml = "false123"; assertPayloadEquals(httpRequest, xml, "application/xml", false); assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class); From e71728d82ced2860973e0bdeb07f9e69a5de0e3c Mon Sep 17 00:00:00 2001 From: Jason King Date: Wed, 14 Dec 2011 17:08:35 +0000 Subject: [PATCH 2/4] Issue 695: Converted CreateSSHKey to use a XMLBuilder --- .../binders/BindCreateSSHKeyToXmlPayload.java | 78 +++++++++++++++++++ .../features/SshKeyAsyncClient.java | 6 +- .../BindCreateSSHKeyToXmlPayloadTest.java | 59 ++++++++++++++ .../features/SSHKeyAsyncClientTest.java | 2 +- 4 files changed, 141 insertions(+), 4 deletions(-) create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateSSHKeyToXmlPayload.java create mode 100644 sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateSSHKeyToXmlPayloadTest.java diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateSSHKeyToXmlPayload.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateSSHKeyToXmlPayload.java new file mode 100644 index 0000000000..f3bfd115b5 --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateSSHKeyToXmlPayload.java @@ -0,0 +1,78 @@ +/** + * 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.binders; + +import com.jamesmurty.utils.XMLBuilder; +import org.jclouds.http.HttpRequest; +import org.jclouds.rest.MapBinder; +import org.jclouds.rest.binders.BindToStringPayload; + +import javax.inject.Inject; +import javax.inject.Singleton; +import javax.xml.parsers.ParserConfigurationException; +import javax.xml.transform.TransformerException; +import java.util.Map; +import java.util.Properties; + +import static com.google.common.base.Preconditions.checkNotNull; + +/** + * + * @author Jason King + */ +@Singleton +public class BindCreateSSHKeyToXmlPayload implements MapBinder { + + private final BindToStringPayload stringBinder; + + @Inject + BindCreateSSHKeyToXmlPayload(BindToStringPayload stringBinder) { + this.stringBinder = stringBinder; + } + + @Override + public R bindToRequest(R request, Map params) { + checkNotNull(request, "request"); + checkNotNull(params, "params"); + String name = checkNotNull(params.get("name"), "name"); + String isDefault = checkNotNull(params.get("isDefault"), "isDefault"); + + String payload = createXMLPayload(name,isDefault); + return stringBinder.bindToRequest(request, payload); + } + + private String createXMLPayload(String name, String isDefault) { + try { + Properties outputProperties = new Properties(); + outputProperties.put(javax.xml.transform.OutputKeys.OMIT_XML_DECLARATION, "yes"); + return XMLBuilder.create("CreateSshKey").a("name",name) + .e("Default").t(isDefault) + .asString(outputProperties); + } catch (ParserConfigurationException e) { + throw new RuntimeException(e); + } catch (TransformerException t) { + throw new RuntimeException(t); + } + } + + @Override + public R bindToRequest(R request, Object input) { + throw new IllegalStateException("BindCreateKey needs parameters"); + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyAsyncClient.java index 9ad83e597f..b4b0c82e7a 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyAsyncClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyAsyncClient.java @@ -23,6 +23,7 @@ import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.*; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; +import org.jclouds.tmrk.enterprisecloud.binders.BindCreateSSHKeyToXmlPayload; import org.jclouds.tmrk.enterprisecloud.binders.BindSSHKeyToXmlPayload; import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKey; import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKeys; @@ -70,10 +71,9 @@ public interface SSHKeyAsyncClient { @Consumes("application/vnd.tmrk.cloud.admin.sshKey") @JAXBResponseParser @ExceptionParser(ReturnNullOnNotFoundOr404.class) - //TODO This would be done better with a template like editSSHKey - @Payload("{defaultKey}") @Produces(MediaType.APPLICATION_XML) - public ListenableFuture createSSHKey(@EndpointParam URI uri, @PayloadParam("name")String name, @PayloadParam("defaultKey")boolean defaultKey); + @MapBinder(BindCreateSSHKeyToXmlPayload.class) + public ListenableFuture createSSHKey(@EndpointParam URI uri, @PayloadParam("name")String name, @PayloadParam("isDefault")boolean defaultKey); /** * @see SSHKeyClient#editSSHKey diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateSSHKeyToXmlPayloadTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateSSHKeyToXmlPayloadTest.java new file mode 100644 index 0000000000..8edf6d37de --- /dev/null +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/binders/BindCreateSSHKeyToXmlPayloadTest.java @@ -0,0 +1,59 @@ +/** + * 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.binders; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.AbstractModule; +import com.google.inject.Guice; +import com.google.inject.Injector; +import org.jclouds.http.HttpRequest; +import org.testng.annotations.Test; + +import java.io.IOException; +import java.net.URI; + +import static org.testng.Assert.assertEquals; + +/** + * Tests behavior of {@code BindCreateSSHKeyToXmlPayloadTest} + * @author Jason King + */ +@Test(groups = "unit", testName = "BindCreateSSHKeyToXmlPayloadTest") +public class BindCreateSSHKeyToXmlPayloadTest { + Injector injector = Guice.createInjector(new AbstractModule() { + + @Override + protected void configure() { + } + }); + + public void testPayloadXmlContent() throws IOException { + final String name = "newName"; + final boolean isDefault = false; + final String expected = String.format("%b", + name,isDefault); + + HttpRequest request = new HttpRequest("GET", URI.create("http://test")); + BindCreateSSHKeyToXmlPayload binder = injector + .getInstance(BindCreateSSHKeyToXmlPayload.class); + + binder.bindToRequest(request, ImmutableMap.of("name", name, "isDefault", Boolean.toString(isDefault))); + assertEquals(request.getPayload().getRawContent(), expected); + } +} diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java index 30b37079ef..3e4501660c 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java @@ -78,7 +78,7 @@ public class SSHKeyAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClie assertRequestLineEquals(httpRequest, "POST https://services-beta.enterprisecloud.terremark.com/cloudapi/ecloud/admin/sshkeys/organizations/17/action/createsshkey HTTP/1.1"); assertNonPayloadHeadersEqual(httpRequest, "Accept: application/vnd.tmrk.cloud.admin.sshKey\nx-tmrk-version: 2011-07-01\n"); - String xml = "true"; + String xml = "true"; assertPayloadEquals(httpRequest, xml, "application/xml", false); assertResponseParserClassEquals(method, httpRequest, ParseXMLWithJAXB.class); From 831e35ecbc75db841dda6c2a8acc504cee137ecc Mon Sep 17 00:00:00 2001 From: Jason King Date: Wed, 14 Dec 2011 20:45:32 +0000 Subject: [PATCH 3/4] Issue 695: Converted deleteSSHKey to return boolean instead of void when 2xx return code --- .../tmrk/enterprisecloud/features/SshKeyAsyncClient.java | 7 +++---- .../tmrk/enterprisecloud/features/SshKeyClient.java | 2 +- .../enterprisecloud/features/SSHKeyAsyncClientTest.java | 8 ++++---- .../enterprisecloud/features/SSHKeyClientLiveTest.java | 8 ++++++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyAsyncClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyAsyncClient.java index b4b0c82e7a..81c63eb4ab 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyAsyncClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyAsyncClient.java @@ -21,8 +21,8 @@ package org.jclouds.tmrk.enterprisecloud.features; import com.google.common.util.concurrent.ListenableFuture; import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.annotations.*; +import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.tmrk.enterprisecloud.binders.BindCreateSSHKeyToXmlPayload; import org.jclouds.tmrk.enterprisecloud.binders.BindSSHKeyToXmlPayload; import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKey; @@ -87,11 +87,10 @@ public interface SSHKeyAsyncClient { /** * @see SSHKeyClient#createSSHKey - * TODO Should map the 204 header to a boolean to indicate that it was sucessful */ @DELETE - @ExceptionParser(ReturnVoidOnNotFoundOr404.class) - public ListenableFuture deleteSSHKey(@EndpointParam URI uri); + @ExceptionParser(ReturnFalseOnNotFoundOr404.class) + public ListenableFuture deleteSSHKey(@EndpointParam URI uri); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyClient.java b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyClient.java index 3ea252cb9c..b53b14aea4 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyClient.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/main/java/org/jclouds/tmrk/enterprisecloud/features/SshKeyClient.java @@ -94,6 +94,6 @@ public interface SSHKeyClient { * @param uri the uri of the ssk key to delete * e.g. /cloudapi/ecloud/admin/sshkeys/77 */ - public void deleteSSHKey(URI uri); + public boolean deleteSSHKey(URI uri); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java index 3e4501660c..925bb8ffce 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyAsyncClientTest.java @@ -21,9 +21,9 @@ package org.jclouds.tmrk.enterprisecloud.features; import com.google.inject.TypeLiteral; import org.jclouds.http.HttpRequest; import org.jclouds.http.functions.ParseXMLWithJAXB; -import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.http.functions.ReturnTrueIf2xx; +import org.jclouds.rest.functions.ReturnFalseOnNotFoundOr404; import org.jclouds.rest.functions.ReturnNullOnNotFoundOr404; -import org.jclouds.rest.functions.ReturnVoidOnNotFoundOr404; import org.jclouds.rest.internal.RestAnnotationProcessor; import org.jclouds.tmrk.enterprisecloud.domain.keys.SSHKey; import org.testng.annotations.Test; @@ -116,8 +116,8 @@ public class SSHKeyAsyncClientTest extends BaseTerremarkEnterpriseCloudAsyncClie assertNonPayloadHeadersEqual(httpRequest,"x-tmrk-version: 2011-07-01\n"); assertPayloadEquals(httpRequest, null, null, false); - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertExceptionParserClassEquals(method, ReturnVoidOnNotFoundOr404.class); + assertResponseParserClassEquals(method, httpRequest, ReturnTrueIf2xx.class); + assertExceptionParserClassEquals(method, ReturnFalseOnNotFoundOr404.class); checkFilters(httpRequest); } diff --git a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyClientLiveTest.java b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyClientLiveTest.java index d379519918..9fc3b52d98 100644 --- a/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyClientLiveTest.java +++ b/sandbox-providers/tmrk-enterprisecloud/src/test/java/org/jclouds/tmrk/enterprisecloud/features/SSHKeyClientLiveTest.java @@ -63,7 +63,7 @@ public class SSHKeyClientLiveTest extends BaseTerremarkEnterpriseCloudClientLive assertFalse(sshKey.isDefaultKey()); assertFalse(sshKey.getFingerPrint().isEmpty()); assertFalse(sshKey.getPrivateKey().isEmpty()); - client.deleteSSHKey(sshKey.getHref()); + assertTrue(client.deleteSSHKey(sshKey.getHref())); assertNull(client.getSSHKey(sshKey.getHref())); } @@ -76,7 +76,11 @@ public class SSHKeyClientLiveTest extends BaseTerremarkEnterpriseCloudClientLive SSHKey result = client.getSSHKey(sshKey.getHref()); assertEquals(result.getName(),"editedname"); - client.deleteSSHKey(sshKey.getHref()); + assertTrue(client.deleteSSHKey(sshKey.getHref())); assertNull(client.getSSHKey(sshKey.getHref())); } + + public void testDeleteWhenNoKey() { + assertFalse(client.deleteSSHKey(URI.create("/cloudapi/ecloud/admin/sshkeys/-1"))); + } } \ No newline at end of file From a116ac0d04619489972b8fd5beddfdc2f6a0483e Mon Sep 17 00:00:00 2001 From: Jason King Date: Wed, 14 Dec 2011 20:49:02 +0000 Subject: [PATCH 4/4] Issue 695: Just have latest version of com.jamesmurty.utils in pom.xml --- sandbox-providers/tmrk-enterprisecloud/pom.xml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/sandbox-providers/tmrk-enterprisecloud/pom.xml b/sandbox-providers/tmrk-enterprisecloud/pom.xml index bc481936f1..c054ed0233 100644 --- a/sandbox-providers/tmrk-enterprisecloud/pom.xml +++ b/sandbox-providers/tmrk-enterprisecloud/pom.xml @@ -91,11 +91,6 @@ ${project.version} test - - com.jamesmurty.utils - java-xmlbuilder - 0.3 -