From 349d74bfaa3e58808a3ddac8eff9105f890980d1 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Wed, 25 Apr 2012 13:50:05 -0700 Subject: [PATCH] Issue 734: skeleton for joyent --- labs/joyent-sdc/pom.xml | 123 ++++++++++++++++++ .../joyent/sdc/v6_5/SDCApiMetadata.java | 93 +++++++++++++ .../joyent/sdc/v6_5/SDCAsyncClient.java | 40 ++++++ .../jclouds/joyent/sdc/v6_5/SDCClient.java | 44 +++++++ .../joyent/sdc/v6_5/config/SDCProperties.java | 28 ++++ .../sdc/v6_5/config/SDCRestClientModule.java | 66 ++++++++++ .../v6_5/features/DatacenterAsyncClient.java | 36 +++++ .../sdc/v6_5/features/DatacenterClient.java | 35 +++++ .../sdc/v6_5/handlers/SDCErrorHandler.java | 65 +++++++++ .../services/org.jclouds.apis.ApiMetadata | 1 + .../joyent/sdc/v6_5/SDCApiMetadataTest.java | 37 ++++++ .../features/DatacenterClientExpectTest.java | 30 +++++ .../features/DatacenterClientLiveTest.java | 30 +++++ .../v6_5/handlers/SDCErrorHandlerTest.java | 91 +++++++++++++ .../BaseSDCAsyncClientExpectTest.java | 39 ++++++ .../internal/BaseSDCClientExpectTest.java | 30 +++++ .../v6_5/internal/BaseSDCClientLiveTest.java | 64 +++++++++ .../sdc/v6_5/internal/BaseSDCExpectTest.java | 33 +++++ .../joyent-sdc/src/test/resources/logback.xml | 51 ++++++++ labs/pom.xml | 1 + 20 files changed, 937 insertions(+) create mode 100644 labs/joyent-sdc/pom.xml create mode 100644 labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCApiMetadata.java create mode 100644 labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCAsyncClient.java create mode 100644 labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCClient.java create mode 100644 labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/config/SDCProperties.java create mode 100644 labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/config/SDCRestClientModule.java create mode 100644 labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterAsyncClient.java create mode 100644 labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterClient.java create mode 100644 labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/handlers/SDCErrorHandler.java create mode 100644 labs/joyent-sdc/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata create mode 100644 labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/SDCApiMetadataTest.java create mode 100644 labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterClientExpectTest.java create mode 100644 labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterClientLiveTest.java create mode 100644 labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/handlers/SDCErrorHandlerTest.java create mode 100644 labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCAsyncClientExpectTest.java create mode 100644 labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCClientExpectTest.java create mode 100644 labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCClientLiveTest.java create mode 100644 labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCExpectTest.java create mode 100644 labs/joyent-sdc/src/test/resources/logback.xml diff --git a/labs/joyent-sdc/pom.xml b/labs/joyent-sdc/pom.xml new file mode 100644 index 0000000000..58f0315af9 --- /dev/null +++ b/labs/joyent-sdc/pom.xml @@ -0,0 +1,123 @@ + + + + 4.0.0 + + org.jclouds + jclouds-project + 1.5.0-SNAPSHOT + ../../project/pom.xml + + org.jclouds.labs + joyent-sdc + jcloud joyent-sdc api + jclouds components to access an implementation of Joyent SDC + bundle + + + https://api.joyentcloud.com + ~6.5 + + FIXME_IDENTITY + FIXME_CREDENTIALS + + + + + org.jclouds + jclouds-core + ${project.version} + + + org.jclouds + jclouds-core + ${project.version} + test-jar + test + + + org.jclouds.driver + jclouds-slf4j + ${project.version} + test + + + ch.qos.logback + logback-classic + 1.0.0 + test + + + + + + live + + + + org.apache.maven.plugins + maven-surefire-plugin + + + integration + integration-test + + test + + + + ${test.joyent-sdc.endpoint} + ${test.joyent-sdc.api-version} + ${test.joyent-sdc.build-version} + ${test.joyent-sdc.identity} + ${test.joyent-sdc.credential} + + + + + + + + + + + + + + org.apache.felix + maven-bundle-plugin + + + ${project.artifactId} + org.jclouds.joyent.sdc.v6_5*;version="${project.version}" + + org.jclouds.rest.internal;version="${project.version}", + org.jclouds*;version="${project.version}", + * + + + + + + + + diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCApiMetadata.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCApiMetadata.java new file mode 100644 index 0000000000..c3042a9dfe --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCApiMetadata.java @@ -0,0 +1,93 @@ +/** + * 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.joyent.sdc.v6_5; + +import java.net.URI; +import java.util.Properties; + +import org.jclouds.apis.ApiMetadata; +import org.jclouds.joyent.sdc.v6_5.config.SDCRestClientModule; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.BaseRestApiMetadata; + +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; +import com.google.inject.Module; + +/** + * Implementation of {@link ApiMetadata} for SDC ~6.5 API + * + * @author Adrian Cole + */ +public class SDCApiMetadata extends BaseRestApiMetadata { + + /** The serialVersionUID */ + private static final long serialVersionUID = 6725672099385580694L; + + public static final TypeToken> CONTEXT_TOKEN = new TypeToken>() { + private static final long serialVersionUID = -5070937833892503232L; + }; + + @Override + public Builder toBuilder() { + return new Builder().fromApiMetadata(this); + } + + public SDCApiMetadata() { + this(new Builder()); + } + + protected SDCApiMetadata(Builder builder) { + super(builder); + } + + public static Properties defaultProperties() { + Properties properties = BaseRestApiMetadata.defaultProperties(); + return properties; + } + + public static class Builder extends BaseRestApiMetadata.Builder { + + protected Builder() { + super(SDCClient.class, SDCAsyncClient.class); + id("joyent-sdc") + .name("Joyent SDC API") + .identityName("username") + .credentialName("password") + .documentation(URI.create("http://sdc.joyent.org/sdcapi.html")) + .version("~6.5") + .defaultEndpoint("https://api.joyentcloud.com") + .defaultProperties(SDCApiMetadata.defaultProperties()) + .defaultModules(ImmutableSet.>of(SDCRestClientModule.class)); + } + + @Override + public SDCApiMetadata build() { + return new SDCApiMetadata(this); + } + + @Override + public Builder fromApiMetadata(ApiMetadata in) { + super.fromApiMetadata(in); + return this; + } + + } + +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCAsyncClient.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCAsyncClient.java new file mode 100644 index 0000000000..e4e42de97b --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCAsyncClient.java @@ -0,0 +1,40 @@ +/** + * 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.joyent.sdc.v6_5; + +import org.jclouds.joyent.sdc.v6_5.features.DatacenterAsyncClient; +import org.jclouds.rest.annotations.Delegate; + +/** + * Provides asynchronous access to SDC via their REST API. + *

+ * + * @see SDCClient + * @see api doc + * @author Adrian Cole + */ +public interface SDCAsyncClient { + + /** + * Provides asynchronous access to Datacenter features. + */ + @Delegate + DatacenterAsyncClient getDatacenterClient(); + +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCClient.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCClient.java new file mode 100644 index 0000000000..47ebe9fa27 --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/SDCClient.java @@ -0,0 +1,44 @@ +/** + * 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.joyent.sdc.v6_5; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.joyent.sdc.v6_5.features.DatacenterClient; +import org.jclouds.rest.annotations.Delegate; + +/** + * Provides synchronous access to SDC. + *

+ * + * @see SDCAsyncClient + * @see api doc + * @author Adrian Cole + */ +@Timeout(duration = 60, timeUnit = TimeUnit.SECONDS) +public interface SDCClient { + + /** + * Provides synchronous access to Datacenter features. + */ + @Delegate + DatacenterClient getDatacenterClient(); + +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/config/SDCProperties.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/config/SDCProperties.java new file mode 100644 index 0000000000..dd0190e258 --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/config/SDCProperties.java @@ -0,0 +1,28 @@ +/** + * 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.joyent.sdc.v6_5.config; + +/** + * Configuration properties and constants used in joyent SDC connections. + * + * @author Adrian Cole + */ +public class SDCProperties { + +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/config/SDCRestClientModule.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/config/SDCRestClientModule.java new file mode 100644 index 0000000000..201cb77bd4 --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/config/SDCRestClientModule.java @@ -0,0 +1,66 @@ +/** + * 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.joyent.sdc.v6_5.config; + +import java.util.Map; + +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.annotation.ClientError; +import org.jclouds.http.annotation.Redirection; +import org.jclouds.http.annotation.ServerError; +import org.jclouds.joyent.sdc.v6_5.SDCAsyncClient; +import org.jclouds.joyent.sdc.v6_5.SDCClient; +import org.jclouds.joyent.sdc.v6_5.features.DatacenterAsyncClient; +import org.jclouds.joyent.sdc.v6_5.features.DatacenterClient; +import org.jclouds.joyent.sdc.v6_5.handlers.SDCErrorHandler; +import org.jclouds.json.config.GsonModule.DateAdapter; +import org.jclouds.json.config.GsonModule.Iso8601DateAdapter; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.config.RestClientModule; + +import com.google.common.collect.ImmutableMap; + +/** + * Configures the SDC connection. + * + * @author Adrian Cole + */ +@ConfiguresRestClient +public class SDCRestClientModule extends RestClientModule { + public static final Map, Class> DELEGATE_MAP = ImmutableMap., Class> builder() + .put(DatacenterClient.class, DatacenterAsyncClient.class) + .build(); + + public SDCRestClientModule() { + super(DELEGATE_MAP); + } + + @Override + protected void configure() { + bind(DateAdapter.class).to(Iso8601DateAdapter.class); + super.configure(); + } + + @Override + protected void bindErrorHandlers() { + bind(HttpErrorHandler.class).annotatedWith(Redirection.class).to(SDCErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ClientError.class).to(SDCErrorHandler.class); + bind(HttpErrorHandler.class).annotatedWith(ServerError.class).to(SDCErrorHandler.class); + } +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterAsyncClient.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterAsyncClient.java new file mode 100644 index 0000000000..f189732787 --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterAsyncClient.java @@ -0,0 +1,36 @@ +/** + * 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.joyent.sdc.v6_5.features; + +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.SkipEncoding; + +/** + * Datacenter Services + * + * @see DatacenterClient + * @author Adrian Cole + * @see api doc + */ +@SkipEncoding( { '/', '=' }) +@RequestFilters(BasicAuthentication.class) +public interface DatacenterAsyncClient { + +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterClient.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterClient.java new file mode 100644 index 0000000000..e1735c4d1e --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterClient.java @@ -0,0 +1,35 @@ +/** + * 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.joyent.sdc.v6_5.features; + +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; + +/** + * Datacenter Services + * + * @see DatacenterAsyncClient + * @author Adrian Cole + * @see api doc + */ +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) +public interface DatacenterClient { + +} diff --git a/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/handlers/SDCErrorHandler.java b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/handlers/SDCErrorHandler.java new file mode 100644 index 0000000000..856ee47b45 --- /dev/null +++ b/labs/joyent-sdc/src/main/java/org/jclouds/joyent/sdc/v6_5/handlers/SDCErrorHandler.java @@ -0,0 +1,65 @@ +/** + * 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.joyent.sdc.v6_5.handlers; + +import static org.jclouds.http.HttpUtils.closeClientButKeepContentStream; + +import javax.inject.Singleton; + +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpErrorHandler; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpResponseException; +import org.jclouds.rest.AuthorizationException; +import org.jclouds.rest.ResourceNotFoundException; + +/** + * This will parse and set an appropriate exception on the command object. + * + * @author Adrian Cole + * + */ +// TODO: is there error spec someplace? let's type errors, etc. +@Singleton +public class SDCErrorHandler implements HttpErrorHandler { + public void handleError(HttpCommand command, HttpResponse response) { + // it is important to always read fully and close streams + byte[] data = closeClientButKeepContentStream(response); + String message = data != null ? new String(data) : null; + + Exception exception = message != null ? new HttpResponseException(command, response, message) + : new HttpResponseException(command, response); + message = message != null ? message : String.format("%s -> %s", command.getCurrentRequest().getRequestLine(), + response.getStatusLine()); + switch (response.getStatusCode()) { + case 400: + break; + case 401: + case 403: + exception = new AuthorizationException(message, exception); + break; + case 404: + if (!command.getCurrentRequest().getMethod().equals("DELETE")) { + exception = new ResourceNotFoundException(message, exception); + } + break; + } + command.setException(exception); + } +} diff --git a/labs/joyent-sdc/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata b/labs/joyent-sdc/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata new file mode 100644 index 0000000000..88003aa840 --- /dev/null +++ b/labs/joyent-sdc/src/main/resources/META-INF/services/org.jclouds.apis.ApiMetadata @@ -0,0 +1 @@ +org.jclouds.joyent.sdc.v6_5.SDCApiMetadata diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/SDCApiMetadataTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/SDCApiMetadataTest.java new file mode 100644 index 0000000000..c78131f27f --- /dev/null +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/SDCApiMetadataTest.java @@ -0,0 +1,37 @@ +/** + * 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.joyent.sdc.v6_5; + +import org.jclouds.View; +import org.jclouds.apis.internal.BaseApiMetadataTest; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSet; +import com.google.common.reflect.TypeToken; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "SDCApiMetadataTest") +public class SDCApiMetadataTest extends BaseApiMetadataTest { + public SDCApiMetadataTest() { + super(new SDCApiMetadata(), ImmutableSet.> of()); + } +} diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterClientExpectTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterClientExpectTest.java new file mode 100644 index 0000000000..86928f54b0 --- /dev/null +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterClientExpectTest.java @@ -0,0 +1,30 @@ +/** + * 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 + * + * Unles 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 expres or implied. See the License for the + * specific language governing permisions and limitations + * under the License. + */ +package org.jclouds.joyent.sdc.v6_5.features; + +import org.jclouds.joyent.sdc.v6_5.internal.BaseSDCClientExpectTest; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "DatacenterClientExpectTest") +public class DatacenterClientExpectTest extends BaseSDCClientExpectTest { + +} diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterClientLiveTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterClientLiveTest.java new file mode 100644 index 0000000000..24b9847966 --- /dev/null +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/features/DatacenterClientLiveTest.java @@ -0,0 +1,30 @@ +/** + * 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.joyent.sdc.v6_5.features; + +import org.jclouds.joyent.sdc.v6_5.internal.BaseSDCClientLiveTest; +import org.testng.annotations.Test; + +/** + * @author Adrian Cole + */ +@Test(groups = "live", testName = "DatacenterClientLiveTest") +public class DatacenterClientLiveTest extends BaseSDCClientLiveTest { + +} diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/handlers/SDCErrorHandlerTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/handlers/SDCErrorHandlerTest.java new file mode 100644 index 0000000000..8d5db2ad6a --- /dev/null +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/handlers/SDCErrorHandlerTest.java @@ -0,0 +1,91 @@ +/** + * 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.joyent.sdc.v6_5.handlers; + +import static org.easymock.EasyMock.createMockBuilder; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.replay; +import static org.easymock.EasyMock.reportMatcher; +import static org.easymock.EasyMock.verify; + +import java.net.URI; + +import org.easymock.IArgumentMatcher; +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.io.Payloads; +import org.jclouds.util.Strings2; +import org.testng.annotations.Test; + +/** + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "SDCErrorHandlerTest") +public class SDCErrorHandlerTest { + + + private void assertCodeMakes(String method, URI uri, int statusCode, String message, String content, + Class expected) { + assertCodeMakes(method, uri, statusCode, message, "text/plain", content, expected); + } + + private void assertCodeMakes(String method, URI uri, int statusCode, String message, String contentType, + String content, Class expected) { + + SDCErrorHandler function = new SDCErrorHandler(); + + HttpCommand command = createMockBuilder(HttpCommand.class).createMock(); + HttpRequest request = new HttpRequest(method, uri); + HttpResponse response = new HttpResponse(statusCode, message, Payloads.newInputStreamPayload(Strings2 + .toInputStream(content))); + response.getPayload().getContentMetadata().setContentType(contentType); + + expect(command.getCurrentRequest()).andReturn(request).atLeastOnce(); + command.setException(classEq(expected)); + + replay(command); + + function.handleError(command, response); + + verify(command); + } + + public static Exception classEq(final Class in) { + reportMatcher(new IArgumentMatcher() { + + @Override + public void appendTo(StringBuffer buffer) { + buffer.append("classEq("); + buffer.append(in); + buffer.append(")"); + } + + @Override + public boolean matches(Object arg) { + return arg.getClass() == in; + } + + }); + return null; + } + + +} diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCAsyncClientExpectTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCAsyncClientExpectTest.java new file mode 100644 index 0000000000..2c8436dad3 --- /dev/null +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCAsyncClientExpectTest.java @@ -0,0 +1,39 @@ +/** + * 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.joyent.sdc.v6_5.internal; + +import java.util.Properties; + +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpResponse; +import org.jclouds.joyent.sdc.v6_5.SDCAsyncClient; + +import com.google.common.base.Function; +import com.google.inject.Module; + +/** + * Base class for writing KeyStone Rest Client Expect tests + * + * @author Adrian Cole + */ +public class BaseSDCAsyncClientExpectTest extends BaseSDCExpectTest { + public SDCAsyncClient createClient(Function fn, Module module, Properties props) { + return createInjector(fn, module, props).getInstance(SDCAsyncClient.class); + } +} diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCClientExpectTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCClientExpectTest.java new file mode 100644 index 0000000000..cd342cee76 --- /dev/null +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCClientExpectTest.java @@ -0,0 +1,30 @@ +/** + * 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.joyent.sdc.v6_5.internal; + +import org.jclouds.joyent.sdc.v6_5.SDCClient; + +/** + * Base class for writing KeyStone Rest Client Expect tests + * + * @author Adrian Cole + */ +public class BaseSDCClientExpectTest extends BaseSDCExpectTest { + +} diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCClientLiveTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCClientLiveTest.java new file mode 100644 index 0000000000..39ab68f913 --- /dev/null +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCClientLiveTest.java @@ -0,0 +1,64 @@ +/** + * 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.joyent.sdc.v6_5.internal; + +import org.jclouds.apis.BaseContextLiveTest; +import org.jclouds.joyent.sdc.v6_5.SDCApiMetadata; +import org.jclouds.joyent.sdc.v6_5.SDCAsyncClient; +import org.jclouds.joyent.sdc.v6_5.SDCClient; +import org.jclouds.rest.RestContext; +import org.testng.annotations.AfterGroups; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import com.google.common.reflect.TypeToken; + +/** + * Tests behavior of {@code SDCClient} + * + * @author Adrian Cole + */ +@Test(groups = "live") +public class BaseSDCClientLiveTest extends BaseContextLiveTest> { + + public BaseSDCClientLiveTest() { + provider = "joyent-sdc"; + } + + protected RestContext sdcContext; + + @BeforeGroups(groups = { "integration", "live" }) + @Override + public void setupContext() { + super.setupContext(); + sdcContext = context; + } + + @AfterGroups(groups = "live") + protected void tearDown() { + if (sdcContext != null) + sdcContext.close(); + } + + @Override + protected TypeToken> contextType() { + return SDCApiMetadata.CONTEXT_TOKEN; + } + +} diff --git a/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCExpectTest.java b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCExpectTest.java new file mode 100644 index 0000000000..095b171888 --- /dev/null +++ b/labs/joyent-sdc/src/test/java/org/jclouds/joyent/sdc/v6_5/internal/BaseSDCExpectTest.java @@ -0,0 +1,33 @@ +/** + * 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.joyent.sdc.v6_5.internal; + +import org.jclouds.rest.internal.BaseRestClientExpectTest; + +/** + * Base class for writing SDC Expect tests + * + * @author Adrian Cole + */ +public class BaseSDCExpectTest extends BaseRestClientExpectTest { + + public BaseSDCExpectTest() { + provider = "joyent-sdc"; + } +} diff --git a/labs/joyent-sdc/src/test/resources/logback.xml b/labs/joyent-sdc/src/test/resources/logback.xml new file mode 100644 index 0000000000..b77c1b041f --- /dev/null +++ b/labs/joyent-sdc/src/test/resources/logback.xml @@ -0,0 +1,51 @@ + + + + target/test-data/jclouds.log + + + %d %-5p [%c] [%thread] %m%n + + + + + target/test-data/jclouds-wire.log + + + %d %-5p [%c] [%thread] %m%n + + + + + target/test-data/jclouds-compute.log + + + %d %-5p [%c] [%thread] %m%n + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/labs/pom.xml b/labs/pom.xml index d951337b1c..737e6602c1 100644 --- a/labs/pom.xml +++ b/labs/pom.xml @@ -45,5 +45,6 @@ jenkins cdmi openstack-glance + joyent-sdc