From 6a37d171f0273ae61d508212ce3550f194eaa299 Mon Sep 17 00:00:00 2001 From: Alex Yarmula Date: Wed, 24 Feb 2010 22:23:01 -0800 Subject: [PATCH 01/13] initial commit with gogrid code - raw from archetype --- gogrid/.svnignore | 7 + gogrid/pom.xml | 76 ++++ gogrid/src/main/java/org/jclouds/GoGrid.java | 62 +++ .../java/org/jclouds/GoGridAsyncClient.java | 74 ++++ .../main/java/org/jclouds/GoGridClient.java | 63 +++ .../org/jclouds/GoGridContextBuilder.java | 80 ++++ .../org/jclouds/GoGridContextFactory.java | 80 ++++ .../org/jclouds/GoGridPropertiesBuilder.java | 85 ++++ .../jclouds/config/GoGridContextModule.java | 81 ++++ .../config/GoGridRestClientModule.java | 118 ++++++ .../main/java/org/jclouds/domain/Status.java | 220 ++++++++++ .../main/java/org/jclouds/domain/User.java | 387 ++++++++++++++++++ .../ParseStatusesFromJsonResponse.java | 81 ++++ .../jclouds/reference/GoGridConstants.java | 53 +++ .../org/jclouds/GoGridAsyncClientTest.java | 127 ++++++ .../org/jclouds/GoGridClientLiveTest.java | 78 ++++ .../org/jclouds/GoGridContextBuilderTest.java | 116 ++++++ .../config/GoGridContextModuleTest.java | 134 ++++++ .../ParseStatusesFromJsonResponseTest.java | 167 ++++++++ gogrid/src/test/resources/log4j.xml | 110 +++++ gogrid/src/test/resources/test_mentions.json | 77 ++++ pom.xml | 9 +- 22 files changed, 2280 insertions(+), 5 deletions(-) create mode 100644 gogrid/.svnignore create mode 100644 gogrid/pom.xml create mode 100644 gogrid/src/main/java/org/jclouds/GoGrid.java create mode 100644 gogrid/src/main/java/org/jclouds/GoGridAsyncClient.java create mode 100644 gogrid/src/main/java/org/jclouds/GoGridClient.java create mode 100644 gogrid/src/main/java/org/jclouds/GoGridContextBuilder.java create mode 100644 gogrid/src/main/java/org/jclouds/GoGridContextFactory.java create mode 100644 gogrid/src/main/java/org/jclouds/GoGridPropertiesBuilder.java create mode 100644 gogrid/src/main/java/org/jclouds/config/GoGridContextModule.java create mode 100644 gogrid/src/main/java/org/jclouds/config/GoGridRestClientModule.java create mode 100644 gogrid/src/main/java/org/jclouds/domain/Status.java create mode 100644 gogrid/src/main/java/org/jclouds/domain/User.java create mode 100644 gogrid/src/main/java/org/jclouds/functions/ParseStatusesFromJsonResponse.java create mode 100644 gogrid/src/main/java/org/jclouds/reference/GoGridConstants.java create mode 100644 gogrid/src/test/java/org/jclouds/GoGridAsyncClientTest.java create mode 100644 gogrid/src/test/java/org/jclouds/GoGridClientLiveTest.java create mode 100644 gogrid/src/test/java/org/jclouds/GoGridContextBuilderTest.java create mode 100644 gogrid/src/test/java/org/jclouds/config/GoGridContextModuleTest.java create mode 100644 gogrid/src/test/java/org/jclouds/functions/ParseStatusesFromJsonResponseTest.java create mode 100644 gogrid/src/test/resources/log4j.xml create mode 100644 gogrid/src/test/resources/test_mentions.json diff --git a/gogrid/.svnignore b/gogrid/.svnignore new file mode 100644 index 0000000000..68ece06ea0 --- /dev/null +++ b/gogrid/.svnignore @@ -0,0 +1,7 @@ +target +.settings +.classpath +.project +jclouds-gogrid.iml +jclouds-gogrid.ipr +jclouds-gogrid.iws \ No newline at end of file diff --git a/gogrid/pom.xml b/gogrid/pom.xml new file mode 100644 index 0000000000..18685b396e --- /dev/null +++ b/gogrid/pom.xml @@ -0,0 +1,76 @@ + + + + org.jclouds + jclouds-multi + 1.0-SNAPSHOT + ../pom.xml + + 4.0.0 + org.jclouds + jclouds-gogrid + jclouds GoGrid core + jar + jclouds components to access GoGrid + + + scm:svn:http://jclouds.googlecode.com/svn/trunk/gogrid + scm:svn:https://jclouds.googlecode.com/svn/trunk/gogrid + http://jclouds.googlecode.com/svn/trunk/gogrid + + + apiKey + secret + + + + ${project.groupId} + jclouds-core + ${project.version} + + + ${project.groupId} + jclouds-core + ${project.version} + test-jar + test + + + log4j + log4j + 1.2.14 + test + + + ${project.groupId} + jclouds-log4j + ${project.version} + test + + + diff --git a/gogrid/src/main/java/org/jclouds/GoGrid.java b/gogrid/src/main/java/org/jclouds/GoGrid.java new file mode 100644 index 0000000000..6adb66e1de --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/GoGrid.java @@ -0,0 +1,62 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +import javax.inject.Qualifier; + +/** + * Related to a GoGrid resource. + * + * @author Adrian Cole + * + */ +@Retention(value = RetentionPolicy.RUNTIME) +@Target(value = { ElementType.FIELD, ElementType.PARAMETER, ElementType.METHOD }) +@Qualifier +public @interface GoGrid { + +} \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/GoGridAsyncClient.java b/gogrid/src/main/java/org/jclouds/GoGridAsyncClient.java new file mode 100644 index 0000000000..8d394f1c2f --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/GoGridAsyncClient.java @@ -0,0 +1,74 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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; + +import java.util.SortedSet; +import com.google.common.util.concurrent.ListenableFuture; + +import javax.ws.rs.GET; +import javax.ws.rs.Path; + +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.annotations.Endpoint; +import org.jclouds.rest.annotations.RequestFilters; +import org.jclouds.rest.annotations.ResponseParser; +import org.jclouds.domain.Status; +import org.jclouds.functions.ParseStatusesFromJsonResponse; + +/** + * Provides asynchronous access to GoGrid via their REST API. + *

+ * + * @see GoGridClient + * @see + * @author Adrian Cole + */ +@Endpoint(GoGrid.class) +@RequestFilters(BasicAuthentication.class) +public interface GoGridAsyncClient { + + @GET + @ResponseParser(ParseStatusesFromJsonResponse.class) + @Path("/statuses/mentions.json") + ListenableFuture> getMyMentions(); + +} diff --git a/gogrid/src/main/java/org/jclouds/GoGridClient.java b/gogrid/src/main/java/org/jclouds/GoGridClient.java new file mode 100644 index 0000000000..5bf2a6ba32 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/GoGridClient.java @@ -0,0 +1,63 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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; + +import java.util.SortedSet; +import java.util.concurrent.TimeUnit; + +import org.jclouds.concurrent.Timeout; +import org.jclouds.domain.Status; + +/** + * Provides synchronous access to GoGrid. + *

+ * + * @see GoGridAsyncClient + * @see + * @author Adrian Cole + */ +@Timeout(duration = 4, timeUnit = TimeUnit.SECONDS) +public interface GoGridClient { + + SortedSet getMyMentions(); + +} diff --git a/gogrid/src/main/java/org/jclouds/GoGridContextBuilder.java b/gogrid/src/main/java/org/jclouds/GoGridContextBuilder.java new file mode 100644 index 0000000000..130b709ca4 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/GoGridContextBuilder.java @@ -0,0 +1,80 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.List; +import java.util.Properties; + +import org.jclouds.rest.RestContextBuilder; +import org.jclouds.config.GoGridContextModule; +import org.jclouds.config.GoGridRestClientModule; +import org.jclouds.reference.GoGridConstants; + +import com.google.inject.Module; +import com.google.inject.TypeLiteral; + +/** + * + * @author Adrian Cole + */ +public class GoGridContextBuilder extends RestContextBuilder { + + public GoGridContextBuilder(Properties props) { + super(new TypeLiteral() { + }, new TypeLiteral() { + }, props); + checkNotNull(properties.getProperty(GoGridConstants.PROPERTY_GOGRID_USER)); + checkNotNull(properties.getProperty(GoGridConstants.PROPERTY_GOGRID_PASSWORD)); + } + + protected void addClientModule(List modules) { + modules.add(new GoGridRestClientModule()); + } + + @Override + protected void addContextModule(List modules) { + modules.add(new GoGridContextModule()); + } + +} diff --git a/gogrid/src/main/java/org/jclouds/GoGridContextFactory.java b/gogrid/src/main/java/org/jclouds/GoGridContextFactory.java new file mode 100644 index 0000000000..bf63f3db99 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/GoGridContextFactory.java @@ -0,0 +1,80 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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; + +import java.util.Properties; + +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.logging.jdk.config.JDKLoggingModule; +import org.jclouds.rest.RestContext; + +import com.google.inject.Module; + +/** + * Creates {@link RestContext} for {@link GoGridClient} instances based on the most commonly + * requested arguments. + *

+ * Note that Threadsafe objects will be bound as singletons to the Injector or Context provided. + *

+ *

+ * If no Modules are specified, the default {@link JDKLoggingModule logging} and + * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. + * + * @author Adrian Cole + * @see RestContext + * @see GoGridClient + * @see GoGridAsyncClient + */ +public class GoGridContextFactory { + + public static RestContext createContext(String user, String password, + Module... modules) { + return new GoGridContextBuilder(new GoGridPropertiesBuilder(user, password).build()) + .withModules(modules).buildContext(); + } + + public static RestContext createContext(Properties properties, Module... modules) { + return new GoGridContextBuilder(new GoGridPropertiesBuilder(properties).build()) + .withModules(modules).buildContext(); + } + +} diff --git a/gogrid/src/main/java/org/jclouds/GoGridPropertiesBuilder.java b/gogrid/src/main/java/org/jclouds/GoGridPropertiesBuilder.java new file mode 100644 index 0000000000..14ee65cd47 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/GoGridPropertiesBuilder.java @@ -0,0 +1,85 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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; + +import static com.google.common.base.Preconditions.checkNotNull; +import static org.jclouds.reference.GoGridConstants.PROPERTY_GOGRID_ENDPOINT; +import static org.jclouds.reference.GoGridConstants.PROPERTY_GOGRID_PASSWORD; +import static org.jclouds.reference.GoGridConstants.PROPERTY_GOGRID_USER; + +import java.net.URI; +import java.util.Properties; + +/** + * Builds properties used in GoGrid Clients + * + * @author Adrian Cole + */ +public class GoGridPropertiesBuilder extends PropertiesBuilder { + @Override + protected Properties defaultProperties() { + Properties properties = super.defaultProperties(); + properties.setProperty(PROPERTY_GOGRID_ENDPOINT, "https://api.gogrid.com/api"); + return properties; + } + + public GoGridPropertiesBuilder(Properties properties) { + super(properties); + } + + public GoGridPropertiesBuilder(String id, String secret) { + super(); + withCredentials(id, secret); + } + + public GoGridPropertiesBuilder withCredentials(String id, String secret) { + properties.setProperty(PROPERTY_GOGRID_USER, checkNotNull(id, "user")); + properties.setProperty(PROPERTY_GOGRID_PASSWORD, checkNotNull(secret, "password")); + return this; + } + + public GoGridPropertiesBuilder withEndpoint(URI endpoint) { + properties.setProperty(PROPERTY_GOGRID_ENDPOINT, checkNotNull(endpoint, "endpoint") + .toString()); + return this; + } +} diff --git a/gogrid/src/main/java/org/jclouds/config/GoGridContextModule.java b/gogrid/src/main/java/org/jclouds/config/GoGridContextModule.java new file mode 100644 index 0000000000..ed8464c9b8 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/config/GoGridContextModule.java @@ -0,0 +1,81 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.config; + +import java.net.URI; + +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.http.functions.config.ParserModule.CDateAdapter; +import org.jclouds.http.functions.config.ParserModule.DateAdapter; +import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.lifecycle.Closer; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.RestContextImpl; +import org.jclouds.GoGrid; +import org.jclouds.GoGridAsyncClient; +import org.jclouds.GoGridClient; +import org.jclouds.reference.GoGridConstants; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; + +/** + * Configures the GoGrid connection, including logging and http transport. + * + * @author Adrian Cole + */ +public class GoGridContextModule extends AbstractModule { + @Override + protected void configure() { + bind(DateAdapter.class).to(CDateAdapter.class); + } + + @Provides + @Singleton + RestContext provideContext(Closer closer, GoGridAsyncClient asyncApi, + GoGridClient syncApi, @GoGrid URI endPoint, @Named(GoGridConstants.PROPERTY_GOGRID_USER) String account) { + return new RestContextImpl(closer, asyncApi, syncApi, endPoint, account); + } + +} \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/config/GoGridRestClientModule.java b/gogrid/src/main/java/org/jclouds/config/GoGridRestClientModule.java new file mode 100644 index 0000000000..c4ee8cdd06 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/config/GoGridRestClientModule.java @@ -0,0 +1,118 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.config; + +import java.io.UnsupportedEncodingException; +import java.net.URI; + +import javax.inject.Named; +import javax.inject.Singleton; + +import org.jclouds.concurrent.internal.SyncProxy; +import org.jclouds.http.RequiresHttp; +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.ConfiguresRestClient; +import org.jclouds.rest.RestClientFactory; +import org.jclouds.encryption.EncryptionService; + +import org.jclouds.GoGrid; +import org.jclouds.GoGridClient; +import org.jclouds.GoGridAsyncClient; +import org.jclouds.reference.GoGridConstants; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; + +/** + * Configures the GoGrid connection. + * + * @author Adrian Cole + */ +@RequiresHttp +@ConfiguresRestClient +public class GoGridRestClientModule extends AbstractModule { + + @Override + protected void configure() { + bindErrorHandlers(); + bindRetryHandlers(); + } + + @Provides + @Singleton + public BasicAuthentication provideBasicAuthentication( + @Named(GoGridConstants.PROPERTY_GOGRID_USER) String user, + @Named(GoGridConstants.PROPERTY_GOGRID_PASSWORD) String password, + EncryptionService encryptionService) + throws UnsupportedEncodingException { + return new BasicAuthentication(user, password, encryptionService); + } + + @Provides + @Singleton + protected GoGridAsyncClient provideClient(RestClientFactory factory) { + return factory.create(GoGridAsyncClient.class); + } + + @Provides + @Singleton + public GoGridClient provideClient(GoGridAsyncClient client) throws IllegalArgumentException, + SecurityException, NoSuchMethodException { + return SyncProxy.create(GoGridClient.class, client); + } + + @Provides + @Singleton + @GoGrid + protected URI provideURI(@Named(GoGridConstants.PROPERTY_GOGRID_ENDPOINT) String endpoint) { + return URI.create(endpoint); + } + + protected void bindErrorHandlers() { + // TODO + } + + protected void bindRetryHandlers() { + // TODO + } + +} \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/domain/Status.java b/gogrid/src/main/java/org/jclouds/domain/Status.java new file mode 100644 index 0000000000..2ec515fbbb --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/domain/Status.java @@ -0,0 +1,220 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + *Date + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.domain; + +import java.util.Date; + +import com.google.gson.annotations.SerializedName; + +/** + * + * @author Adrian Cole + * + */ +public class Status implements Comparable { + @SerializedName("created_at") + private Date createdAt; + private boolean favorited; + private String geo; + private long id; + @SerializedName("in_reply_to_screen_name") + private String inReplyToScreenName; + @SerializedName("in_reply_to_status_id") + private Integer inReplyToStatusId; + @SerializedName("in_reply_to_user_id") + private Integer inReplyToUserId; + private String source; + private String text; + private boolean truncated; + private User user; + + public Status() { + } + + public Status(Date createdAt, boolean favorited, String geo, long id, + String inReplyToScreenName, Integer inReplyToStatusId, Integer inReplyToUserId, + String source, String text, boolean truncated, User user) { + this.createdAt = createdAt; + this.favorited = favorited; + this.geo = geo; + this.id = id; + this.inReplyToScreenName = inReplyToScreenName; + this.inReplyToStatusId = inReplyToStatusId; + this.inReplyToUserId = inReplyToUserId; + this.source = source; + this.text = text; + this.truncated = truncated; + this.user = user; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + ((createdAt == null) ? 0 : createdAt.hashCode()); + result = prime * result + (int) (id ^ (id >>> 32)); + result = prime * result + ((text == null) ? 0 : text.hashCode()); + result = prime * result + ((user == null) ? 0 : user.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + Status other = (Status) obj; + if (createdAt == null) { + if (other.createdAt != null) + return false; + } else if (!createdAt.equals(other.createdAt)) + return false; + if (id != other.id) + return false; + if (text == null) { + if (other.text != null) + return false; + } else if (!text.equals(other.text)) + return false; + if (user == null) { + if (other.user != null) + return false; + } else if (!user.equals(other.user)) + return false; + return true; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getText() { + return text; + } + + public void setText(String text) { + this.text = text; + } + + public String getSource() { + return source; + } + + public void setSource(String source) { + this.source = source; + } + + public boolean isTruncated() { + return truncated; + } + + public void setTruncated(boolean truncated) { + this.truncated = truncated; + } + + public Integer getInReplyToStatusId() { + return inReplyToStatusId; + } + + public void setInReplyToStatusId(Integer inReplyToStatusId) { + this.inReplyToStatusId = inReplyToStatusId; + } + + public Integer getInReplyToUserId() { + return inReplyToUserId; + } + + public void setInReplyToUserId(Integer inReplyToUserId) { + this.inReplyToUserId = inReplyToUserId; + } + + public boolean isFavorited() { + return favorited; + } + + public void setFavorited(boolean favorited) { + this.favorited = favorited; + } + + public String getInReplyToScreenName() { + return inReplyToScreenName; + } + + public void setInReplyToScreenName(String inReplyToScreenName) { + this.inReplyToScreenName = inReplyToScreenName; + } + + public User getUser() { + return user; + } + + public void setUser(User user) { + this.user = user; + } + + public int compareTo(Status o) { + return (int) ((this == o) ? 0 : id + "".compareTo(o.id + "")); + } + + public void setGeo(String geo) { + this.geo = geo; + } + + public String getGeo() { + return geo; + } +} \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/domain/User.java b/gogrid/src/main/java/org/jclouds/domain/User.java new file mode 100644 index 0000000000..46be23b532 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/domain/User.java @@ -0,0 +1,387 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.domain; + +import java.net.URI; + +import java.util.Date; + +import com.google.gson.annotations.SerializedName; + +/** + * + * @author Adrian Cole + */ +public class User implements Comparable { + @SerializedName("created_at") + private Date createdAt; + private String description; + @SerializedName("favourites_count") + private int favouritesCount; + @SerializedName("followers_count") + private int followersCount; + private boolean following; + @SerializedName("friends_count") + private int friendsCount; + @SerializedName("geo_enabled") + private boolean geoEnabled; + private long id; + private String location; + private String name; + private boolean notifications; + @SerializedName("profile_background_color") + private String profileBackgroundColor; + @SerializedName("profile_background_image_url") + private URI profileBackgroundImageUrl; + @SerializedName("profile_background_tile") + private boolean profileBackgroundTile; + @SerializedName("profile_image_url") + private URI profileImageUrl; + @SerializedName("profile_link_color") + private String profileLinkColor; + @SerializedName("profile_sidebar_border_color") + private String profileSidebarBorderColor; + @SerializedName("profile_sidebar_fill_color") + private String profileSidebarFillColor; + @SerializedName("profile_text_color") + private String profileTextColor; + @SerializedName("protected") + private boolean isProtected; + @SerializedName("screen_name") + private String screenName; + @SerializedName("statuses_count") + private int statusesCount; + @SerializedName("time_zone") + private String timeZone; + private URI url; + @SerializedName("utc_offset") + private int utcOffset; + private boolean verified; + + public User() { + + } + + public User(Date createdAt, String description, int favouritesCount, int followersCount, + boolean following, int friendsCount, boolean geoEnabled, long id, String location, + String name, boolean notifications, String profileBackgroundColor, + URI profileBackgroundImageUrl, boolean profileBackgroundTile, URI profileImageUrl, + String profileLinkColor, String profileSidebarBorderColor, + String profileSidebarFillColor, String profileTextColor, boolean isProtected, + String screenName, int statusesCount, String timeZone, URI url, int utcOffset, + boolean verified) { + this.createdAt = createdAt; + this.description = description; + this.favouritesCount = favouritesCount; + this.followersCount = followersCount; + this.following = following; + this.friendsCount = friendsCount; + this.setGeoEnabled(geoEnabled); + this.id = id; + this.location = location; + this.name = name; + this.notifications = notifications; + this.profileBackgroundColor = profileBackgroundColor; + this.profileBackgroundImageUrl = profileBackgroundImageUrl; + this.profileBackgroundTile = profileBackgroundTile; + this.profileImageUrl = profileImageUrl; + this.profileLinkColor = profileLinkColor; + this.profileSidebarBorderColor = profileSidebarBorderColor; + this.profileSidebarFillColor = profileSidebarFillColor; + this.profileTextColor = profileTextColor; + this.isProtected = isProtected; + this.screenName = screenName; + this.statusesCount = statusesCount; + this.timeZone = timeZone; + this.url = url; + this.utcOffset = utcOffset; + this.verified = verified; + } + + @Override + public int hashCode() { + final int prime = 31; + int result = 1; + result = prime * result + (int) (id ^ (id >>> 32)); + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((screenName == null) ? 0 : screenName.hashCode()); + return result; + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null) + return false; + if (getClass() != obj.getClass()) + return false; + User other = (User) obj; + if (id != other.id) + return false; + if (name == null) { + if (other.name != null) + return false; + } else if (!name.equals(other.name)) + return false; + if (screenName == null) { + if (other.screenName != null) + return false; + } else if (!screenName.equals(other.screenName)) + return false; + return true; + } + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getScreenName() { + return screenName; + } + + public void setScreenName(String screenName) { + this.screenName = screenName; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public URI getProfileImageUrl() { + return profileImageUrl; + } + + public void setProfileImageUrl(URI profileImageUrl) { + this.profileImageUrl = profileImageUrl; + } + + public URI getUrl() { + return url; + } + + public void setUrl(URI url) { + this.url = url; + } + + public boolean isProtected() { + return isProtected; + } + + public void setProtected(boolean isProtected) { + this.isProtected = isProtected; + } + + public int getFollowersCount() { + return followersCount; + } + + public void setFollowersCount(int followersCount) { + this.followersCount = followersCount; + } + + public String getProfileBackgroundColor() { + return profileBackgroundColor; + } + + public void setProfileBackgroundColor(String profileBackgroundColor) { + this.profileBackgroundColor = profileBackgroundColor; + } + + public String getProfileTextColor() { + return profileTextColor; + } + + public void setProfileTextColor(String profileTextColor) { + this.profileTextColor = profileTextColor; + } + + public String getProfileLinkColor() { + return profileLinkColor; + } + + public void setProfileLinkColor(String profileLinkColor) { + this.profileLinkColor = profileLinkColor; + } + + public String getProfileSidebarFillColor() { + return profileSidebarFillColor; + } + + public void setProfileSidebarFillColor(String profileSidebarFillColor) { + this.profileSidebarFillColor = profileSidebarFillColor; + } + + public String getProfileSidebarBorderColor() { + return profileSidebarBorderColor; + } + + public void setProfileSidebarBorderColor(String profileSidebarBorderColor) { + this.profileSidebarBorderColor = profileSidebarBorderColor; + } + + public int getFriendsCount() { + return friendsCount; + } + + public void setFriendsCount(int friendsCount) { + this.friendsCount = friendsCount; + } + + public Date getCreatedAt() { + return createdAt; + } + + public void setCreatedAt(Date createdAt) { + this.createdAt = createdAt; + } + + public int getFavouritesCount() { + return favouritesCount; + } + + public void setFavouritesCount(int favouritesCount) { + this.favouritesCount = favouritesCount; + } + + public int getUtcOffset() { + return utcOffset; + } + + public void setUtcOffset(int utcOffset) { + this.utcOffset = utcOffset; + } + + public String getTimeZone() { + return timeZone; + } + + public void setTimeZone(String timeZone) { + this.timeZone = timeZone; + } + + public URI getProfileBackgroundImageUrl() { + return profileBackgroundImageUrl; + } + + public void setProfileBackgroundImageUrl(URI profileBackgroundImageUrl) { + this.profileBackgroundImageUrl = profileBackgroundImageUrl; + } + + public boolean isProfileBackgroundTile() { + return profileBackgroundTile; + } + + public void setProfileBackgroundTile(boolean profileBackgroundTile) { + this.profileBackgroundTile = profileBackgroundTile; + } + + public int getStatusesCount() { + return statusesCount; + } + + public void setStatusesCount(int statusesCount) { + this.statusesCount = statusesCount; + } + + public boolean isNotifications() { + return notifications; + } + + public void setNotifications(boolean notifications) { + this.notifications = notifications; + } + + public boolean isFollowing() { + return following; + } + + public void setFollowing(boolean following) { + this.following = following; + } + + public boolean isVerified() { + return verified; + } + + public void setVerified(boolean verified) { + this.verified = verified; + } + + public int compareTo(User o) { + if (screenName == null) + return -1; + return (this == o) ? 0 : screenName.compareTo(o.screenName); + } + + public void setGeoEnabled(boolean geoEnabled) { + this.geoEnabled = geoEnabled; + } + + public boolean isGeoEnabled() { + return geoEnabled; + } +} \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/functions/ParseStatusesFromJsonResponse.java b/gogrid/src/main/java/org/jclouds/functions/ParseStatusesFromJsonResponse.java new file mode 100644 index 0000000000..994ef95760 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/functions/ParseStatusesFromJsonResponse.java @@ -0,0 +1,81 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.functions; + +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Type; +import java.util.SortedSet; + +import javax.inject.Inject; +import javax.inject.Singleton; + +import org.jclouds.http.functions.ParseJson; +import org.jclouds.domain.Status; + +import com.google.gson.Gson; +import com.google.gson.reflect.TypeToken; + +/** + * This parses {@link Status} from a json string. + * + * @author Adrian Cole + */ +@Singleton +public class ParseStatusesFromJsonResponse extends ParseJson> { + + @Inject + public ParseStatusesFromJsonResponse(Gson gson) { + super(gson); + } + + public SortedSet apply(InputStream stream) { + Type setType = new TypeToken>() { + }.getType(); + try { + return gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("jclouds requires UTF-8 encoding", e); + } + } +} \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/reference/GoGridConstants.java b/gogrid/src/main/java/org/jclouds/reference/GoGridConstants.java new file mode 100644 index 0000000000..f239a18d4f --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/reference/GoGridConstants.java @@ -0,0 +1,53 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.reference; + +/** + * Configuration properties and constants used in GoGrid connections. + * + * @author Adrian Cole + */ +public interface GoGridConstants { + public static final String PROPERTY_GOGRID_ENDPOINT = "jclouds.gogrid.endpoint"; + public static final String PROPERTY_GOGRID_USER = "jclouds.gogrid.user"; + public static final String PROPERTY_GOGRID_PASSWORD = "jclouds.gogrid.password"; +} diff --git a/gogrid/src/test/java/org/jclouds/GoGridAsyncClientTest.java b/gogrid/src/test/java/org/jclouds/GoGridAsyncClientTest.java new file mode 100644 index 0000000000..040293825d --- /dev/null +++ b/gogrid/src/test/java/org/jclouds/GoGridAsyncClientTest.java @@ -0,0 +1,127 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Method; +import java.net.URI; + +import javax.inject.Singleton; + +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; +import org.jclouds.rest.RestClientTest; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.functions.ParseStatusesFromJsonResponse; +import org.jclouds.encryption.EncryptionService; +import org.testng.annotations.Test; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code GoGridAsyncClient} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "gogrid.GoGridAsyncClientTest") +public class GoGridAsyncClientTest extends RestClientTest { + + public void testGetMyMentions() throws SecurityException, NoSuchMethodException, IOException { + Method method = GoGridAsyncClient.class.getMethod("TODO: insert test method name"); + GeneratedHttpRequest httpMethod = processor.createRequest(method); + + assertRequestLineEquals(httpMethod, "TODO: insert expected request"); + assertHeadersEqual(httpMethod, ""); + assertPayloadEquals(httpMethod, null); + + assertResponseParserClassEquals(method, httpMethod, ParseStatusesFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpMethod); + } + + @Override + protected void checkFilters(GeneratedHttpRequest httpMethod) { + assertEquals(httpMethod.getFilters().size(), 1); + assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } + + @Override + protected Module createModule() { + return new AbstractModule() { + @Override + protected void configure() { + bind(URI.class).annotatedWith(GoGrid.class).toInstance( + URI.create("https://api.gogrid.com/api")); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); + } + + @SuppressWarnings("unused") + @Provides + @Singleton + public BasicAuthentication provideBasicAuthentication(EncryptionService encryptionService) + throws UnsupportedEncodingException { + return new BasicAuthentication("foo", "bar", encryptionService); + } + + }; + } +} diff --git a/gogrid/src/test/java/org/jclouds/GoGridClientLiveTest.java b/gogrid/src/test/java/org/jclouds/GoGridClientLiveTest.java new file mode 100644 index 0000000000..8d41f00818 --- /dev/null +++ b/gogrid/src/test/java/org/jclouds/GoGridClientLiveTest.java @@ -0,0 +1,78 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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; + +import static com.google.common.base.Preconditions.checkNotNull; + +import java.util.SortedSet; + +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.jclouds.domain.Status; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +/** + * Tests behavior of {@code GoGridClient} + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "gogrid.GoGridClientLiveTest") +public class GoGridClientLiveTest { + + private GoGridClient connection; + + @BeforeGroups(groups = { "live" }) + public void setupClient() { + String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); + String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); + + connection = GoGridContextFactory.createContext(user, password, new Log4JLoggingModule()) + .getApi(); + } + + @Test + public void testGetMyMentions() { + SortedSet response = connection.getMyMentions(); + assert (response.size() > 0); + } + +} diff --git a/gogrid/src/test/java/org/jclouds/GoGridContextBuilderTest.java b/gogrid/src/test/java/org/jclouds/GoGridContextBuilderTest.java new file mode 100644 index 0000000000..630aa8e821 --- /dev/null +++ b/gogrid/src/test/java/org/jclouds/GoGridContextBuilderTest.java @@ -0,0 +1,116 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.RestContextImpl; +import org.jclouds.config.GoGridRestClientModule; +import org.jclouds.reference.GoGridConstants; +import org.testng.annotations.Test; + +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.Module; +import com.google.inject.TypeLiteral; + +/** + * Tests behavior of modules configured in GoGridContextBuilder + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "gogrid.GoGridContextBuilderTest") +public class GoGridContextBuilderTest { + + public void testNewBuilder() { + GoGridContextBuilder builder = newBuilder(); + assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_ENDPOINT), + "https://api.gogrid.com/api"); + assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_USER), + "user"); + assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_PASSWORD), + "password"); + } + + public void testBuildContext() { + RestContext context = newBuilder().buildContext(); + assertEquals(context.getClass(), RestContextImpl.class); + assertEquals(context.getAccount(), "user"); + assertEquals(context.getEndPoint(), URI.create("https://api.gogrid.com/api")); + } + + public void testBuildInjector() { + Injector i = newBuilder().buildInjector(); + assert i.getInstance(Key.get(new TypeLiteral>() { + })) != null; // TODO: test all things taken from context + assert i.getInstance(BasicAuthentication.class) != null; + } + + protected void testAddContextModule() { + List modules = new ArrayList(); + GoGridContextBuilder builder = newBuilder(); + builder.addContextModule(modules); + assertEquals(modules.size(), 1); + assertEquals(modules.get(0).getClass(), GoGridRestClientModule.class); + } + + private GoGridContextBuilder newBuilder() { + GoGridContextBuilder builder = new GoGridContextBuilder(new GoGridPropertiesBuilder( + "user", "password").build()); + return builder; + } + + protected void addClientModule() { + List modules = new ArrayList(); + GoGridContextBuilder builder = newBuilder(); + builder.addClientModule(modules); + assertEquals(modules.size(), 1); + assertEquals(modules.get(0).getClass(), GoGridRestClientModule.class); + } + +} diff --git a/gogrid/src/test/java/org/jclouds/config/GoGridContextModuleTest.java b/gogrid/src/test/java/org/jclouds/config/GoGridContextModuleTest.java new file mode 100644 index 0000000000..bf04515f81 --- /dev/null +++ b/gogrid/src/test/java/org/jclouds/config/GoGridContextModuleTest.java @@ -0,0 +1,134 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.config; + +import static org.testng.Assert.assertEquals; +import static com.google.common.util.concurrent.Executors.sameThreadExecutor; + +import org.jclouds.concurrent.config.ExecutorServiceModule; +import org.jclouds.http.HttpRetryHandler; +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.http.functions.config.ParserModule.CDateAdapter; +import org.jclouds.http.functions.config.ParserModule.DateAdapter; +import org.jclouds.http.handlers.CloseContentAndSetExceptionErrorHandler; +import org.jclouds.http.handlers.DelegatingErrorHandler; +import org.jclouds.http.handlers.DelegatingRetryHandler; +import org.jclouds.http.handlers.RedirectionRetryHandler; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; +import org.jclouds.reference.GoGridConstants; +import org.jclouds.util.Jsr330; +import org.jclouds.Constants; +import org.testng.annotations.Test; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "gogrid.GoGridContextModule") +public class GoGridContextModuleTest { + + Injector createInjector() { + return Guice.createInjector(new GoGridRestClientModule(), new GoGridContextModule() { + @Override + protected void configure() { + bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_USER)).to( + "user"); + bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_PASSWORD)) + .to("password"); + bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_ENDPOINT)) + .to("http://localhost"); + bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)) + .to("1"); + bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)) + .to("0"); + bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)) + .to("1"); + bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)) + .to("1"); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); + super.configure(); + } + }, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(), + new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor())); + } + + @Test + void testServerErrorHandler() { + DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); + assertEquals(handler.getServerErrorHandler().getClass(), + CloseContentAndSetExceptionErrorHandler.class); + } + + @Test + void testDateTimeAdapter() { + assertEquals(this.createInjector().getInstance(DateAdapter.class).getClass(), + CDateAdapter.class); + } + + @Test + void testClientErrorHandler() { + DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); + assertEquals(handler.getClientErrorHandler().getClass(), + CloseContentAndSetExceptionErrorHandler.class); + } + + @Test + void testClientRetryHandler() { + DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); + assertEquals(handler.getClientErrorRetryHandler(), HttpRetryHandler.NEVER_RETRY); + } + + @Test + void testRedirectionRetryHandler() { + DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); + assertEquals(handler.getRedirectionRetryHandler().getClass(), RedirectionRetryHandler.class); + } + +} \ No newline at end of file diff --git a/gogrid/src/test/java/org/jclouds/functions/ParseStatusesFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/functions/ParseStatusesFromJsonResponseTest.java new file mode 100644 index 0000000000..eb65374518 --- /dev/null +++ b/gogrid/src/test/java/org/jclouds/functions/ParseStatusesFromJsonResponseTest.java @@ -0,0 +1,167 @@ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2009 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.functions; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; +import java.net.UnknownHostException; +import java.util.SortedSet; + +import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.domain.Status; +import org.jclouds.domain.User; +import org.jclouds.date.DateService; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSortedSet; +import com.google.gson.Gson; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code ParseStatusesFromJsonResponse} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "twitter.ParseStatusesFromJsonResponseTest") +public class ParseStatusesFromJsonResponseTest { + + Injector i = Guice.createInjector(new ParserModule() { + @Override + protected void configure() { + bind(DateAdapter.class).to(CDateAdapter.class); + super.configure(); + } + }); + DateService dateService = new SimpleDateFormatDateService(); + + public void testApplyInputStreamDetails() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/test_mentions.json"); + + SortedSet expects = ImmutableSortedSet + .of( + + new Status( + dateService.cDateParse("Sat Oct 31 01:45:14 +0000 2009"), + false, + null, + 5303839785l, + null, + null, + null, + "TweetDeck", + "RT @jclouds: come find out about #cloud storage and how to access it from #java in palo alto this Tuesday: http://is.gd/4IFA9", + false, + new User( + dateService.cDateParse("Sat Apr 26 06:13:08 +0000 2008"), + "Jack of All Trades: Dad to anZel and Arden, VMware, vCloud, Security, Compliance, Former Developer", + 0, + 474, + false, + 199, + false, + 14540593, + "Bay Area, CA", + "Jian Zhen", + false, + "C6E2EE", + URI + .create("http://s.twimg.com/a/1256778767/images/themes/theme2/bg.gif"), + false, + URI + .create("http://a3.twimg.com/profile_images/64445411/30b8b19_bigger_normal.jpg"), + "1F98C7", "C6E2EE", "DAECF4", "663B12", false, "zhenjl", + 1981, "Pacific Time (US & Canada)", URI + .create("http://zhen.org"), -28800, false)), + + new Status( + dateService.cDateParse("Sat Oct 31 09:35:27 +0000 2009"), + false, + null, + 5310690603l, + null, + null, + null, + "TweetDeck", + "RT @jclouds: live multi #cloud demo of jclouds connecting to 3 storage clouds from google appengine http://is.gd/4IXMh", + false, + new User( + dateService.cDateParse("Tue Apr 28 15:29:42 +0000 2009"), + "Some random guy who seems to care about cloud collisions at siliconANGLE.com", + 245, + 572, + false, + 325, + false, + 36093693, + "San Francisco ", + "James Watters", + false, + "C6E2EE", + URI + .create("http://a1.twimg.com/profile_background_images/24067016/17361976.jpg"), + true, + URI + .create("http://a3.twimg.com/profile_images/445071063/tiktaalik-transitional-fossil_normal.png"), + "1F98C7", + "C6E2EE", + "DAECF4", + "663B12", + false, + "wattersjames", + 1964, + "Pacific Time (US & Canada)", + URI + .create("http://siliconangle.net/ver2/author/jwatters/"), + -28800, false)) + + ); + + ParseStatusesFromJsonResponse parser = new ParseStatusesFromJsonResponse(i + .getInstance(Gson.class)); + SortedSet response = parser.apply(is); + assertEquals(response, expects); + } +} diff --git a/gogrid/src/test/resources/log4j.xml b/gogrid/src/test/resources/log4j.xml new file mode 100644 index 0000000000..6e388b9373 --- /dev/null +++ b/gogrid/src/test/resources/log4j.xml @@ -0,0 +1,110 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/gogrid/src/test/resources/test_mentions.json b/gogrid/src/test/resources/test_mentions.json new file mode 100644 index 0000000000..19e6deb04a --- /dev/null +++ b/gogrid/src/test/resources/test_mentions.json @@ -0,0 +1,77 @@ +[ { "created_at" : "Sat Oct 31 09:35:27 +0000 2009", + "favorited" : false, + "geo" : null, + "id" : 5310690603, + "in_reply_to_screen_name" : null, + "in_reply_to_status_id" : null, + "in_reply_to_user_id" : null, + "source" : "TweetDeck", + "text" : "RT @jclouds: live multi #cloud demo of jclouds connecting to 3 storage clouds from google appengine http://is.gd/4IXMh", + "truncated" : false, + "user" : { "created_at" : "Tue Apr 28 15:29:42 +0000 2009", + "description" : "Some random guy who seems to care about cloud collisions at siliconANGLE.com", + "favourites_count" : 245, + "followers_count" : 572, + "following" : false, + "friends_count" : 325, + "geo_enabled" : false, + "id" : 36093693, + "location" : "San Francisco ", + "name" : "James Watters", + "notifications" : false, + "profile_background_color" : "C6E2EE", + "profile_background_image_url" : "http://a1.twimg.com/profile_background_images/24067016/17361976.jpg", + "profile_background_tile" : true, + "profile_image_url" : "http://a3.twimg.com/profile_images/445071063/tiktaalik-transitional-fossil_normal.png", + "profile_link_color" : "1F98C7", + "profile_sidebar_border_color" : "C6E2EE", + "profile_sidebar_fill_color" : "DAECF4", + "profile_text_color" : "663B12", + "protected" : false, + "screen_name" : "wattersjames", + "statuses_count" : 1964, + "time_zone" : "Pacific Time (US & Canada)", + "url" : "http://siliconangle.net/ver2/author/jwatters/", + "utc_offset" : -28800, + "verified" : false + } + }, + { "created_at" : "Sat Oct 31 01:45:14 +0000 2009", + "favorited" : false, + "geo" : null, + "id" : 5303839785, + "in_reply_to_screen_name" : null, + "in_reply_to_status_id" : null, + "in_reply_to_user_id" : null, + "source" : "TweetDeck", + "text" : "RT @jclouds: come find out about #cloud storage and how to access it from #java in palo alto this Tuesday: http://is.gd/4IFA9", + "truncated" : false, + "user" : { "created_at" : "Sat Apr 26 06:13:08 +0000 2008", + "description" : "Jack of All Trades: Dad to anZel and Arden, VMware, vCloud, Security, Compliance, Former Developer", + "favourites_count" : 0, + "followers_count" : 474, + "following" : false, + "friends_count" : 199, + "geo_enabled" : false, + "id" : 14540593, + "location" : "Bay Area, CA", + "name" : "Jian Zhen", + "notifications" : false, + "profile_background_color" : "C6E2EE", + "profile_background_image_url" : "http://s.twimg.com/a/1256778767/images/themes/theme2/bg.gif", + "profile_background_tile" : false, + "profile_image_url" : "http://a3.twimg.com/profile_images/64445411/30b8b19_bigger_normal.jpg", + "profile_link_color" : "1F98C7", + "profile_sidebar_border_color" : "C6E2EE", + "profile_sidebar_fill_color" : "DAECF4", + "profile_text_color" : "663B12", + "protected" : false, + "screen_name" : "zhenjl", + "statuses_count" : 1981, + "time_zone" : "Pacific Time (US & Canada)", + "url" : "http://zhen.org", + "utc_offset" : -28800, + "verified" : false + } + } +] \ No newline at end of file diff --git a/pom.xml b/pom.xml index 5244513952..10496d33ad 100644 --- a/pom.xml +++ b/pom.xml @@ -18,9 +18,7 @@ limitations under the License. ==================================================================== ---> - - +--> 4.0.0 jclouds-project @@ -51,7 +49,8 @@ rimuhosting twitter vcloud - + gogrid + @@ -141,4 +140,4 @@ pageTracker._trackPageview(); - + \ No newline at end of file From 23a14354170412cb6a5961b722447f6ce6d2910d Mon Sep 17 00:00:00 2001 From: Alex Yarmula Date: Fri, 26 Feb 2010 20:48:19 -0800 Subject: [PATCH 02/13] Finished with the first method, getServerList --- gogrid/pom.xml | 50 +-- .../main/java/org/jclouds/domain/Status.java | 220 ---------- .../main/java/org/jclouds/domain/User.java | 387 ------------------ .../java/org/jclouds/{ => gogrid}/GoGrid.java | 22 +- .../{ => gogrid}/GoGridAsyncClient.java | 33 +- .../jclouds/{ => gogrid}/GoGridClient.java | 34 +- .../{ => gogrid}/GoGridContextBuilder.java | 14 +- .../{ => gogrid}/GoGridContextFactory.java | 24 +- .../{ => gogrid}/GoGridPropertiesBuilder.java | 16 +- .../config/GoGridContextModule.java | 37 +- .../config/GoGridRestClientModule.java | 116 +++--- .../jclouds/gogrid/domain/BillingToken.java | 60 +++ .../org/jclouds/gogrid/domain/Customer.java | 49 +++ .../java/org/jclouds/gogrid/domain/Ip.java | 75 ++++ .../org/jclouds/gogrid/domain/Option.java | 58 +++ .../org/jclouds/gogrid/domain/Server.java | 124 ++++++ .../jclouds/gogrid/domain/ServerImage.java | 175 ++++++++ .../internal/GenericResponseContainer.java | 57 +++ .../filters/SharedKeyLiteAuthentication.java | 73 ++++ .../ParseServerListFromJsonResponse.java} | 44 +- .../reference/GoGridConstants.java | 20 +- .../gogrid/reference/GoGridHeaders.java | 8 + .../org/jclouds/GoGridAsyncClientTest.java | 127 ------ .../org/jclouds/GoGridClientLiveTest.java | 78 ---- .../org/jclouds/GoGridContextBuilderTest.java | 116 ------ .../config/GoGridContextModuleTest.java | 134 ------ .../ParseStatusesFromJsonResponseTest.java | 167 -------- .../jclouds/gogrid/GoGridAsyncClientTest.java | 138 +++++++ .../jclouds/gogrid/GoGridClientLiveTest.java | 60 +++ .../gogrid/GoGridContextBuilderTest.java | 119 ++++++ .../config/GoGridContextModuleTest.java | 117 ++++++ .../ParseStatusesFromJsonResponseTest.java | 96 +++++ gogrid/src/test/resources/log4j.xml | 2 +- .../test/resources/test_get_server_list.json | 104 +++++ gogrid/src/test/resources/test_mentions.json | 77 ---- 35 files changed, 1524 insertions(+), 1507 deletions(-) delete mode 100644 gogrid/src/main/java/org/jclouds/domain/Status.java delete mode 100644 gogrid/src/main/java/org/jclouds/domain/User.java rename gogrid/src/main/java/org/jclouds/{ => gogrid}/GoGrid.java (61%) rename gogrid/src/main/java/org/jclouds/{ => gogrid}/GoGridAsyncClient.java (71%) rename gogrid/src/main/java/org/jclouds/{ => gogrid}/GoGridClient.java (52%) rename gogrid/src/main/java/org/jclouds/{ => gogrid}/GoGridContextBuilder.java (86%) rename gogrid/src/main/java/org/jclouds/{ => gogrid}/GoGridContextFactory.java (72%) rename gogrid/src/main/java/org/jclouds/{ => gogrid}/GoGridPropertiesBuilder.java (88%) rename gogrid/src/main/java/org/jclouds/{ => gogrid}/config/GoGridContextModule.java (71%) rename gogrid/src/main/java/org/jclouds/{ => gogrid}/config/GoGridRestClientModule.java (51%) create mode 100644 gogrid/src/main/java/org/jclouds/gogrid/domain/BillingToken.java create mode 100644 gogrid/src/main/java/org/jclouds/gogrid/domain/Customer.java create mode 100644 gogrid/src/main/java/org/jclouds/gogrid/domain/Ip.java create mode 100644 gogrid/src/main/java/org/jclouds/gogrid/domain/Option.java create mode 100644 gogrid/src/main/java/org/jclouds/gogrid/domain/Server.java create mode 100644 gogrid/src/main/java/org/jclouds/gogrid/domain/ServerImage.java create mode 100644 gogrid/src/main/java/org/jclouds/gogrid/domain/internal/GenericResponseContainer.java create mode 100644 gogrid/src/main/java/org/jclouds/gogrid/filters/SharedKeyLiteAuthentication.java rename gogrid/src/main/java/org/jclouds/{functions/ParseStatusesFromJsonResponse.java => gogrid/functions/ParseServerListFromJsonResponse.java} (66%) rename gogrid/src/main/java/org/jclouds/{ => gogrid}/reference/GoGridConstants.java (71%) create mode 100644 gogrid/src/main/java/org/jclouds/gogrid/reference/GoGridHeaders.java delete mode 100644 gogrid/src/test/java/org/jclouds/GoGridAsyncClientTest.java delete mode 100644 gogrid/src/test/java/org/jclouds/GoGridClientLiveTest.java delete mode 100644 gogrid/src/test/java/org/jclouds/GoGridContextBuilderTest.java delete mode 100644 gogrid/src/test/java/org/jclouds/config/GoGridContextModuleTest.java delete mode 100644 gogrid/src/test/java/org/jclouds/functions/ParseStatusesFromJsonResponseTest.java create mode 100644 gogrid/src/test/java/org/jclouds/gogrid/GoGridAsyncClientTest.java create mode 100644 gogrid/src/test/java/org/jclouds/gogrid/GoGridClientLiveTest.java create mode 100644 gogrid/src/test/java/org/jclouds/gogrid/GoGridContextBuilderTest.java create mode 100644 gogrid/src/test/java/org/jclouds/gogrid/config/GoGridContextModuleTest.java create mode 100644 gogrid/src/test/java/org/jclouds/gogrid/functions/ParseStatusesFromJsonResponseTest.java create mode 100644 gogrid/src/test/resources/test_get_server_list.json delete mode 100644 gogrid/src/test/resources/test_mentions.json diff --git a/gogrid/pom.xml b/gogrid/pom.xml index 18685b396e..d9ce63083c 100644 --- a/gogrid/pom.xml +++ b/gogrid/pom.xml @@ -1,29 +1,29 @@ - org.jclouds diff --git a/gogrid/src/main/java/org/jclouds/domain/Status.java b/gogrid/src/main/java/org/jclouds/domain/Status.java deleted file mode 100644 index 2ec515fbbb..0000000000 --- a/gogrid/src/main/java/org/jclouds/domain/Status.java +++ /dev/null @@ -1,220 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. - * ==================================================================== - */ -/** - *Date - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.domain; - -import java.util.Date; - -import com.google.gson.annotations.SerializedName; - -/** - * - * @author Adrian Cole - * - */ -public class Status implements Comparable { - @SerializedName("created_at") - private Date createdAt; - private boolean favorited; - private String geo; - private long id; - @SerializedName("in_reply_to_screen_name") - private String inReplyToScreenName; - @SerializedName("in_reply_to_status_id") - private Integer inReplyToStatusId; - @SerializedName("in_reply_to_user_id") - private Integer inReplyToUserId; - private String source; - private String text; - private boolean truncated; - private User user; - - public Status() { - } - - public Status(Date createdAt, boolean favorited, String geo, long id, - String inReplyToScreenName, Integer inReplyToStatusId, Integer inReplyToUserId, - String source, String text, boolean truncated, User user) { - this.createdAt = createdAt; - this.favorited = favorited; - this.geo = geo; - this.id = id; - this.inReplyToScreenName = inReplyToScreenName; - this.inReplyToStatusId = inReplyToStatusId; - this.inReplyToUserId = inReplyToUserId; - this.source = source; - this.text = text; - this.truncated = truncated; - this.user = user; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + ((createdAt == null) ? 0 : createdAt.hashCode()); - result = prime * result + (int) (id ^ (id >>> 32)); - result = prime * result + ((text == null) ? 0 : text.hashCode()); - result = prime * result + ((user == null) ? 0 : user.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - Status other = (Status) obj; - if (createdAt == null) { - if (other.createdAt != null) - return false; - } else if (!createdAt.equals(other.createdAt)) - return false; - if (id != other.id) - return false; - if (text == null) { - if (other.text != null) - return false; - } else if (!text.equals(other.text)) - return false; - if (user == null) { - if (other.user != null) - return false; - } else if (!user.equals(other.user)) - return false; - return true; - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getText() { - return text; - } - - public void setText(String text) { - this.text = text; - } - - public String getSource() { - return source; - } - - public void setSource(String source) { - this.source = source; - } - - public boolean isTruncated() { - return truncated; - } - - public void setTruncated(boolean truncated) { - this.truncated = truncated; - } - - public Integer getInReplyToStatusId() { - return inReplyToStatusId; - } - - public void setInReplyToStatusId(Integer inReplyToStatusId) { - this.inReplyToStatusId = inReplyToStatusId; - } - - public Integer getInReplyToUserId() { - return inReplyToUserId; - } - - public void setInReplyToUserId(Integer inReplyToUserId) { - this.inReplyToUserId = inReplyToUserId; - } - - public boolean isFavorited() { - return favorited; - } - - public void setFavorited(boolean favorited) { - this.favorited = favorited; - } - - public String getInReplyToScreenName() { - return inReplyToScreenName; - } - - public void setInReplyToScreenName(String inReplyToScreenName) { - this.inReplyToScreenName = inReplyToScreenName; - } - - public User getUser() { - return user; - } - - public void setUser(User user) { - this.user = user; - } - - public int compareTo(Status o) { - return (int) ((this == o) ? 0 : id + "".compareTo(o.id + "")); - } - - public void setGeo(String geo) { - this.geo = geo; - } - - public String getGeo() { - return geo; - } -} \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/domain/User.java b/gogrid/src/main/java/org/jclouds/domain/User.java deleted file mode 100644 index 46be23b532..0000000000 --- a/gogrid/src/main/java/org/jclouds/domain/User.java +++ /dev/null @@ -1,387 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. - * ==================================================================== - */ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.domain; - -import java.net.URI; - -import java.util.Date; - -import com.google.gson.annotations.SerializedName; - -/** - * - * @author Adrian Cole - */ -public class User implements Comparable { - @SerializedName("created_at") - private Date createdAt; - private String description; - @SerializedName("favourites_count") - private int favouritesCount; - @SerializedName("followers_count") - private int followersCount; - private boolean following; - @SerializedName("friends_count") - private int friendsCount; - @SerializedName("geo_enabled") - private boolean geoEnabled; - private long id; - private String location; - private String name; - private boolean notifications; - @SerializedName("profile_background_color") - private String profileBackgroundColor; - @SerializedName("profile_background_image_url") - private URI profileBackgroundImageUrl; - @SerializedName("profile_background_tile") - private boolean profileBackgroundTile; - @SerializedName("profile_image_url") - private URI profileImageUrl; - @SerializedName("profile_link_color") - private String profileLinkColor; - @SerializedName("profile_sidebar_border_color") - private String profileSidebarBorderColor; - @SerializedName("profile_sidebar_fill_color") - private String profileSidebarFillColor; - @SerializedName("profile_text_color") - private String profileTextColor; - @SerializedName("protected") - private boolean isProtected; - @SerializedName("screen_name") - private String screenName; - @SerializedName("statuses_count") - private int statusesCount; - @SerializedName("time_zone") - private String timeZone; - private URI url; - @SerializedName("utc_offset") - private int utcOffset; - private boolean verified; - - public User() { - - } - - public User(Date createdAt, String description, int favouritesCount, int followersCount, - boolean following, int friendsCount, boolean geoEnabled, long id, String location, - String name, boolean notifications, String profileBackgroundColor, - URI profileBackgroundImageUrl, boolean profileBackgroundTile, URI profileImageUrl, - String profileLinkColor, String profileSidebarBorderColor, - String profileSidebarFillColor, String profileTextColor, boolean isProtected, - String screenName, int statusesCount, String timeZone, URI url, int utcOffset, - boolean verified) { - this.createdAt = createdAt; - this.description = description; - this.favouritesCount = favouritesCount; - this.followersCount = followersCount; - this.following = following; - this.friendsCount = friendsCount; - this.setGeoEnabled(geoEnabled); - this.id = id; - this.location = location; - this.name = name; - this.notifications = notifications; - this.profileBackgroundColor = profileBackgroundColor; - this.profileBackgroundImageUrl = profileBackgroundImageUrl; - this.profileBackgroundTile = profileBackgroundTile; - this.profileImageUrl = profileImageUrl; - this.profileLinkColor = profileLinkColor; - this.profileSidebarBorderColor = profileSidebarBorderColor; - this.profileSidebarFillColor = profileSidebarFillColor; - this.profileTextColor = profileTextColor; - this.isProtected = isProtected; - this.screenName = screenName; - this.statusesCount = statusesCount; - this.timeZone = timeZone; - this.url = url; - this.utcOffset = utcOffset; - this.verified = verified; - } - - @Override - public int hashCode() { - final int prime = 31; - int result = 1; - result = prime * result + (int) (id ^ (id >>> 32)); - result = prime * result + ((name == null) ? 0 : name.hashCode()); - result = prime * result + ((screenName == null) ? 0 : screenName.hashCode()); - return result; - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; - User other = (User) obj; - if (id != other.id) - return false; - if (name == null) { - if (other.name != null) - return false; - } else if (!name.equals(other.name)) - return false; - if (screenName == null) { - if (other.screenName != null) - return false; - } else if (!screenName.equals(other.screenName)) - return false; - return true; - } - - public long getId() { - return id; - } - - public void setId(long id) { - this.id = id; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getScreenName() { - return screenName; - } - - public void setScreenName(String screenName) { - this.screenName = screenName; - } - - public String getLocation() { - return location; - } - - public void setLocation(String location) { - this.location = location; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public URI getProfileImageUrl() { - return profileImageUrl; - } - - public void setProfileImageUrl(URI profileImageUrl) { - this.profileImageUrl = profileImageUrl; - } - - public URI getUrl() { - return url; - } - - public void setUrl(URI url) { - this.url = url; - } - - public boolean isProtected() { - return isProtected; - } - - public void setProtected(boolean isProtected) { - this.isProtected = isProtected; - } - - public int getFollowersCount() { - return followersCount; - } - - public void setFollowersCount(int followersCount) { - this.followersCount = followersCount; - } - - public String getProfileBackgroundColor() { - return profileBackgroundColor; - } - - public void setProfileBackgroundColor(String profileBackgroundColor) { - this.profileBackgroundColor = profileBackgroundColor; - } - - public String getProfileTextColor() { - return profileTextColor; - } - - public void setProfileTextColor(String profileTextColor) { - this.profileTextColor = profileTextColor; - } - - public String getProfileLinkColor() { - return profileLinkColor; - } - - public void setProfileLinkColor(String profileLinkColor) { - this.profileLinkColor = profileLinkColor; - } - - public String getProfileSidebarFillColor() { - return profileSidebarFillColor; - } - - public void setProfileSidebarFillColor(String profileSidebarFillColor) { - this.profileSidebarFillColor = profileSidebarFillColor; - } - - public String getProfileSidebarBorderColor() { - return profileSidebarBorderColor; - } - - public void setProfileSidebarBorderColor(String profileSidebarBorderColor) { - this.profileSidebarBorderColor = profileSidebarBorderColor; - } - - public int getFriendsCount() { - return friendsCount; - } - - public void setFriendsCount(int friendsCount) { - this.friendsCount = friendsCount; - } - - public Date getCreatedAt() { - return createdAt; - } - - public void setCreatedAt(Date createdAt) { - this.createdAt = createdAt; - } - - public int getFavouritesCount() { - return favouritesCount; - } - - public void setFavouritesCount(int favouritesCount) { - this.favouritesCount = favouritesCount; - } - - public int getUtcOffset() { - return utcOffset; - } - - public void setUtcOffset(int utcOffset) { - this.utcOffset = utcOffset; - } - - public String getTimeZone() { - return timeZone; - } - - public void setTimeZone(String timeZone) { - this.timeZone = timeZone; - } - - public URI getProfileBackgroundImageUrl() { - return profileBackgroundImageUrl; - } - - public void setProfileBackgroundImageUrl(URI profileBackgroundImageUrl) { - this.profileBackgroundImageUrl = profileBackgroundImageUrl; - } - - public boolean isProfileBackgroundTile() { - return profileBackgroundTile; - } - - public void setProfileBackgroundTile(boolean profileBackgroundTile) { - this.profileBackgroundTile = profileBackgroundTile; - } - - public int getStatusesCount() { - return statusesCount; - } - - public void setStatusesCount(int statusesCount) { - this.statusesCount = statusesCount; - } - - public boolean isNotifications() { - return notifications; - } - - public void setNotifications(boolean notifications) { - this.notifications = notifications; - } - - public boolean isFollowing() { - return following; - } - - public void setFollowing(boolean following) { - this.following = following; - } - - public boolean isVerified() { - return verified; - } - - public void setVerified(boolean verified) { - this.verified = verified; - } - - public int compareTo(User o) { - if (screenName == null) - return -1; - return (this == o) ? 0 : screenName.compareTo(o.screenName); - } - - public void setGeoEnabled(boolean geoEnabled) { - this.geoEnabled = geoEnabled; - } - - public boolean isGeoEnabled() { - return geoEnabled; - } -} \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/GoGrid.java b/gogrid/src/main/java/org/jclouds/gogrid/GoGrid.java similarity index 61% rename from gogrid/src/main/java/org/jclouds/GoGrid.java rename to gogrid/src/main/java/org/jclouds/gogrid/GoGrid.java index 6adb66e1de..356a046281 100644 --- a/gogrid/src/main/java/org/jclouds/GoGrid.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/GoGrid.java @@ -1,24 +1,6 @@ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. - * ==================================================================== - */ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -39,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds; +package org.jclouds.gogrid; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/gogrid/src/main/java/org/jclouds/GoGridAsyncClient.java b/gogrid/src/main/java/org/jclouds/gogrid/GoGridAsyncClient.java similarity index 71% rename from gogrid/src/main/java/org/jclouds/GoGridAsyncClient.java rename to gogrid/src/main/java/org/jclouds/gogrid/GoGridAsyncClient.java index 8d394f1c2f..2482a6bd04 100644 --- a/gogrid/src/main/java/org/jclouds/GoGridAsyncClient.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/GoGridAsyncClient.java @@ -1,6 +1,6 @@ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ */ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -39,36 +39,39 @@ * under the License. * ==================================================================== */ -package org.jclouds; +package org.jclouds.gogrid; -import java.util.SortedSet; import com.google.common.util.concurrent.ListenableFuture; import javax.ws.rs.GET; import javax.ws.rs.Path; -import org.jclouds.http.filters.BasicAuthentication; -import org.jclouds.rest.annotations.Endpoint; -import org.jclouds.rest.annotations.RequestFilters; -import org.jclouds.rest.annotations.ResponseParser; -import org.jclouds.domain.Status; -import org.jclouds.functions.ParseStatusesFromJsonResponse; +import org.jclouds.gogrid.domain.Server; +import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication; +import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse; +import org.jclouds.rest.annotations.*; + +import java.util.Set; + +import static org.jclouds.gogrid.reference.GoGridHeaders.VERSION; /** * Provides asynchronous access to GoGrid via their REST API. *

* * @see GoGridClient - * @see + * @see * @author Adrian Cole + * @author Oleksiy Yarmula */ @Endpoint(GoGrid.class) -@RequestFilters(BasicAuthentication.class) +@RequestFilters(SharedKeyLiteAuthentication.class) +@QueryParams(keys = VERSION, values = "1.3") public interface GoGridAsyncClient { @GET - @ResponseParser(ParseStatusesFromJsonResponse.class) - @Path("/statuses/mentions.json") - ListenableFuture> getMyMentions(); + @ResponseParser(ParseServerListFromJsonResponse.class) + @Path("/grid/server/list") + ListenableFuture> getServerList(); } diff --git a/gogrid/src/main/java/org/jclouds/GoGridClient.java b/gogrid/src/main/java/org/jclouds/gogrid/GoGridClient.java similarity index 52% rename from gogrid/src/main/java/org/jclouds/GoGridClient.java rename to gogrid/src/main/java/org/jclouds/gogrid/GoGridClient.java index 5bf2a6ba32..0428f68bd3 100644 --- a/gogrid/src/main/java/org/jclouds/GoGridClient.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/GoGridClient.java @@ -1,24 +1,6 @@ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. - * ==================================================================== - */ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -39,25 +21,27 @@ * under the License. * ==================================================================== */ -package org.jclouds; +package org.jclouds.gogrid; -import java.util.SortedSet; +import java.util.Set; import java.util.concurrent.TimeUnit; import org.jclouds.concurrent.Timeout; -import org.jclouds.domain.Status; +import org.jclouds.gogrid.domain.Server; /** * Provides synchronous access to GoGrid. *

* * @see GoGridAsyncClient - * @see + * @see + * * @author Adrian Cole + * @author Oleksiy Yarmula */ -@Timeout(duration = 4, timeUnit = TimeUnit.SECONDS) +@Timeout(duration = 30, timeUnit = TimeUnit.SECONDS) public interface GoGridClient { - SortedSet getMyMentions(); + Set getServerList(); } diff --git a/gogrid/src/main/java/org/jclouds/GoGridContextBuilder.java b/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java similarity index 86% rename from gogrid/src/main/java/org/jclouds/GoGridContextBuilder.java rename to gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java index 130b709ca4..59987938a6 100644 --- a/gogrid/src/main/java/org/jclouds/GoGridContextBuilder.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextBuilder.java @@ -1,6 +1,6 @@ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ */ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -39,17 +39,19 @@ * under the License. * ==================================================================== */ -package org.jclouds; +package org.jclouds.gogrid; import static com.google.common.base.Preconditions.checkNotNull; import java.util.List; import java.util.Properties; +import org.jclouds.gogrid.GoGridClient; +import org.jclouds.gogrid.GoGridAsyncClient; import org.jclouds.rest.RestContextBuilder; -import org.jclouds.config.GoGridContextModule; -import org.jclouds.config.GoGridRestClientModule; -import org.jclouds.reference.GoGridConstants; +import org.jclouds.gogrid.config.GoGridContextModule; +import org.jclouds.gogrid.config.GoGridRestClientModule; +import org.jclouds.gogrid.reference.GoGridConstants; import com.google.inject.Module; import com.google.inject.TypeLiteral; diff --git a/gogrid/src/main/java/org/jclouds/GoGridContextFactory.java b/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextFactory.java similarity index 72% rename from gogrid/src/main/java/org/jclouds/GoGridContextFactory.java rename to gogrid/src/main/java/org/jclouds/gogrid/GoGridContextFactory.java index bf63f3db99..bc4fd5f002 100644 --- a/gogrid/src/main/java/org/jclouds/GoGridContextFactory.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/GoGridContextFactory.java @@ -1,24 +1,6 @@ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. - * ==================================================================== - */ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -39,7 +21,7 @@ * under the License. * ==================================================================== */ -package org.jclouds; +package org.jclouds.gogrid; import java.util.Properties; @@ -60,6 +42,8 @@ import com.google.inject.Module; * {@link JavaUrlHttpCommandExecutorServiceModule http transports} will be installed. * * @author Adrian Cole + * @author Oleksiy Yarmula + * * @see RestContext * @see GoGridClient * @see GoGridAsyncClient diff --git a/gogrid/src/main/java/org/jclouds/GoGridPropertiesBuilder.java b/gogrid/src/main/java/org/jclouds/gogrid/GoGridPropertiesBuilder.java similarity index 88% rename from gogrid/src/main/java/org/jclouds/GoGridPropertiesBuilder.java rename to gogrid/src/main/java/org/jclouds/gogrid/GoGridPropertiesBuilder.java index 14ee65cd47..c3ccb5eed6 100644 --- a/gogrid/src/main/java/org/jclouds/GoGridPropertiesBuilder.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/GoGridPropertiesBuilder.java @@ -1,6 +1,6 @@ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ */ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -39,12 +39,12 @@ * under the License. * ==================================================================== */ -package org.jclouds; +package org.jclouds.gogrid; + +import org.jclouds.PropertiesBuilder; import static com.google.common.base.Preconditions.checkNotNull; -import static org.jclouds.reference.GoGridConstants.PROPERTY_GOGRID_ENDPOINT; -import static org.jclouds.reference.GoGridConstants.PROPERTY_GOGRID_PASSWORD; -import static org.jclouds.reference.GoGridConstants.PROPERTY_GOGRID_USER; +import static org.jclouds.gogrid.reference.GoGridConstants.*; import java.net.URI; import java.util.Properties; @@ -53,12 +53,16 @@ import java.util.Properties; * Builds properties used in GoGrid Clients * * @author Adrian Cole + * @author Oleksiy Yarmula + * */ public class GoGridPropertiesBuilder extends PropertiesBuilder { @Override protected Properties defaultProperties() { Properties properties = super.defaultProperties(); properties.setProperty(PROPERTY_GOGRID_ENDPOINT, "https://api.gogrid.com/api"); + properties.setProperty(PROPERTY_GOGRID_SESSIONINTERVAL, 60 + ""); + return properties; } diff --git a/gogrid/src/main/java/org/jclouds/config/GoGridContextModule.java b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridContextModule.java similarity index 71% rename from gogrid/src/main/java/org/jclouds/config/GoGridContextModule.java rename to gogrid/src/main/java/org/jclouds/gogrid/config/GoGridContextModule.java index ed8464c9b8..b303e9ebb1 100644 --- a/gogrid/src/main/java/org/jclouds/config/GoGridContextModule.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridContextModule.java @@ -1,6 +1,6 @@ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ */ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -39,23 +39,28 @@ * under the License. * ==================================================================== */ -package org.jclouds.config; +package org.jclouds.gogrid.config; +import java.lang.reflect.Type; import java.net.URI; +import java.util.Date; +import javax.inject.Inject; import javax.inject.Named; import javax.inject.Singleton; +import com.google.gson.*; +import org.jclouds.date.DateService; import org.jclouds.http.functions.config.ParserModule.CDateAdapter; import org.jclouds.http.functions.config.ParserModule.DateAdapter; import org.jclouds.http.functions.config.ParserModule; import org.jclouds.lifecycle.Closer; import org.jclouds.rest.RestContext; import org.jclouds.rest.internal.RestContextImpl; -import org.jclouds.GoGrid; -import org.jclouds.GoGridAsyncClient; -import org.jclouds.GoGridClient; -import org.jclouds.reference.GoGridConstants; +import org.jclouds.gogrid.GoGrid; +import org.jclouds.gogrid.GoGridAsyncClient; +import org.jclouds.gogrid.GoGridClient; +import org.jclouds.gogrid.reference.GoGridConstants; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -64,11 +69,12 @@ import com.google.inject.Provides; * Configures the GoGrid connection, including logging and http transport. * * @author Adrian Cole + * @author Oleksiy Yarmula */ public class GoGridContextModule extends AbstractModule { @Override protected void configure() { - bind(DateAdapter.class).to(CDateAdapter.class); + bind(DateAdapter.class).to(DateSecondsAdapter.class); } @Provides @@ -78,4 +84,19 @@ public class GoGridContextModule extends AbstractModule { return new RestContextImpl(closer, asyncApi, syncApi, endPoint, account); } + @Singleton + public static class DateSecondsAdapter implements DateAdapter { + + public JsonElement serialize(Date src, Type typeOfSrc, JsonSerializationContext context) { + return new JsonPrimitive(src.getTime()); + } + + public Date deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) + throws JsonParseException { + String toParse = json.getAsJsonPrimitive().getAsString(); + return new Date(Long.valueOf(toParse)); + } + + } + } \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/config/GoGridRestClientModule.java b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridRestClientModule.java similarity index 51% rename from gogrid/src/main/java/org/jclouds/config/GoGridRestClientModule.java rename to gogrid/src/main/java/org/jclouds/gogrid/config/GoGridRestClientModule.java index c4ee8cdd06..21628a49d0 100644 --- a/gogrid/src/main/java/org/jclouds/config/GoGridRestClientModule.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/config/GoGridRestClientModule.java @@ -1,6 +1,6 @@ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ */ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -39,80 +39,100 @@ * under the License. * ==================================================================== */ -package org.jclouds.config; +package org.jclouds.gogrid.config; import java.io.UnsupportedEncodingException; import java.net.URI; +import java.text.DateFormat; +import java.util.concurrent.TimeUnit; import javax.inject.Named; import javax.inject.Singleton; +import com.google.common.base.Supplier; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import org.jclouds.concurrent.ExpirableSupplier; import org.jclouds.concurrent.internal.SyncProxy; +import org.jclouds.date.DateService; +import org.jclouds.date.TimeStamp; import org.jclouds.http.RequiresHttp; -import org.jclouds.http.filters.BasicAuthentication; import org.jclouds.rest.ConfiguresRestClient; import org.jclouds.rest.RestClientFactory; -import org.jclouds.encryption.EncryptionService; -import org.jclouds.GoGrid; -import org.jclouds.GoGridClient; -import org.jclouds.GoGridAsyncClient; -import org.jclouds.reference.GoGridConstants; +import org.jclouds.gogrid.GoGrid; +import org.jclouds.gogrid.GoGridClient; +import org.jclouds.gogrid.GoGridAsyncClient; +import org.jclouds.gogrid.reference.GoGridConstants; import com.google.inject.AbstractModule; import com.google.inject.Provides; +import static org.jclouds.gogrid.reference.GoGridConstants.*; + /** * Configures the GoGrid connection. - * + * * @author Adrian Cole + * @author Oleksiy Yarmula */ @RequiresHttp @ConfiguresRestClient public class GoGridRestClientModule extends AbstractModule { - @Override - protected void configure() { - bindErrorHandlers(); - bindRetryHandlers(); - } + @Override + protected void configure() { + bindErrorHandlers(); + bindRetryHandlers(); + } - @Provides - @Singleton - public BasicAuthentication provideBasicAuthentication( - @Named(GoGridConstants.PROPERTY_GOGRID_USER) String user, - @Named(GoGridConstants.PROPERTY_GOGRID_PASSWORD) String password, - EncryptionService encryptionService) - throws UnsupportedEncodingException { - return new BasicAuthentication(user, password, encryptionService); - } + @Provides + @Singleton + protected GoGridAsyncClient provideClient(RestClientFactory factory) { + return factory.create(GoGridAsyncClient.class); + } - @Provides - @Singleton - protected GoGridAsyncClient provideClient(RestClientFactory factory) { - return factory.create(GoGridAsyncClient.class); - } - - @Provides - @Singleton - public GoGridClient provideClient(GoGridAsyncClient client) throws IllegalArgumentException, + @Provides + @Singleton + public GoGridClient provideClient(GoGridAsyncClient client) throws IllegalArgumentException, SecurityException, NoSuchMethodException { - return SyncProxy.create(GoGridClient.class, client); - } - - @Provides - @Singleton - @GoGrid - protected URI provideURI(@Named(GoGridConstants.PROPERTY_GOGRID_ENDPOINT) String endpoint) { - return URI.create(endpoint); - } + return SyncProxy.create(GoGridClient.class, client); + } - protected void bindErrorHandlers() { - // TODO - } + @Provides + @Singleton + @GoGrid + protected URI provideURI(@Named(GoGridConstants.PROPERTY_GOGRID_ENDPOINT) String endpoint) { + return URI.create(endpoint); + } - protected void bindRetryHandlers() { - // TODO - } + @Provides + @TimeStamp + protected Long provideTimeStamp(@TimeStamp Supplier cache) { + return cache.get(); + } + + /** + * borrowing concurrency code to ensure that caching takes place properly + */ + @Provides + @TimeStamp + Supplier provideTimeStampCache( + @Named(PROPERTY_GOGRID_SESSIONINTERVAL) long seconds, + final DateService dateService) { + return new ExpirableSupplier(new Supplier() { + public Long get() { + return System.currentTimeMillis() / 1000; + } + }, seconds, TimeUnit.SECONDS); + } + + protected void bindErrorHandlers() { + // TODO + } + + protected void bindRetryHandlers() { + // TODO + } } \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/gogrid/domain/BillingToken.java b/gogrid/src/main/java/org/jclouds/gogrid/domain/BillingToken.java new file mode 100644 index 0000000000..d317a66ddb --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/domain/BillingToken.java @@ -0,0 +1,60 @@ +package org.jclouds.gogrid.domain; + +/** + * @author Oleksiy Yarmula + */ +public class BillingToken { + + private long id; + private String name; + private double price; + + /** + * A no-args constructor is required for deserialization + */ + public BillingToken() { + } + + public BillingToken(long id, String name, double price) { + this.id = id; + this.name = name; + this.price = price; + } + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + public double getPrice() { + return price; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + BillingToken that = (BillingToken) o; + + if (id != that.id) return false; + if (Double.compare(that.price, price) != 0) return false; + if (!name.equals(that.name)) return false; + + return true; + } + + @Override + public int hashCode() { + int result; + long temp; + result = (int) (id ^ (id >>> 32)); + result = 31 * result + name.hashCode(); + temp = price != +0.0d ? Double.doubleToLongBits(price) : 0L; + result = 31 * result + (int) (temp ^ (temp >>> 32)); + return result; + } +} diff --git a/gogrid/src/main/java/org/jclouds/gogrid/domain/Customer.java b/gogrid/src/main/java/org/jclouds/gogrid/domain/Customer.java new file mode 100644 index 0000000000..fd54771f6f --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/domain/Customer.java @@ -0,0 +1,49 @@ +package org.jclouds.gogrid.domain; + +/** + * @author Oleksiy Yarmula + */ +public class Customer { + + private long id; + private String name; + + public Customer(long id, String name) { + this.id = id; + this.name = name; + } + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + /** + * A no-args constructor is required for deserialization + */ + public Customer() { + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Customer customer = (Customer) o; + + if (id != customer.id) return false; + if (name != null ? !name.equals(customer.name) : customer.name != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + return result; + } +} diff --git a/gogrid/src/main/java/org/jclouds/gogrid/domain/Ip.java b/gogrid/src/main/java/org/jclouds/gogrid/domain/Ip.java new file mode 100644 index 0000000000..0759dad8bd --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/domain/Ip.java @@ -0,0 +1,75 @@ +package org.jclouds.gogrid.domain; + +/** + * @author Oleksiy Yarmula + */ +public class Ip { + + private long id; + + private String ip; + private String subnet; + + private boolean isPublic; + private Option state; + + /** + * A no-args constructor is required for deserialization + */ + public Ip() { + } + + public Ip(long id, String ip, String subnet, boolean isPublic, Option state) { + this.id = id; + this.ip = ip; + this.subnet = subnet; + this.isPublic = isPublic; + this.state = state; + } + + public long getId() { + return id; + } + + public String getIp() { + return ip; + } + + public String getSubnet() { + return subnet; + } + + public boolean isPublic() { + return isPublic; + } + + public Option getState() { + return state; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Ip ip1 = (Ip) o; + + if (id != ip1.id) return false; + if (isPublic != ip1.isPublic) return false; + if (!ip.equals(ip1.ip)) return false; + if (state != null ? !state.equals(ip1.state) : ip1.state != null) return false; + if (subnet != null ? !subnet.equals(ip1.subnet) : ip1.subnet != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + ip.hashCode(); + result = 31 * result + (subnet != null ? subnet.hashCode() : 0); + result = 31 * result + (isPublic ? 1 : 0); + result = 31 * result + (state != null ? state.hashCode() : 0); + return result; + } +} diff --git a/gogrid/src/main/java/org/jclouds/gogrid/domain/Option.java b/gogrid/src/main/java/org/jclouds/gogrid/domain/Option.java new file mode 100644 index 0000000000..0a2e5a12cd --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/domain/Option.java @@ -0,0 +1,58 @@ +package org.jclouds.gogrid.domain; + +/** + * @author Oleksiy Yarmula + */ +public class Option { + + private long id; + private String name; + private String description; + + + /** + * A no-args constructor is required for deserialization + */ + public Option() { + } + + public Option(long id, String name, String description) { + this.id = id; + this.name = name; + this.description = description; + } + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Option option = (Option) o; + + if (id != option.id) return false; + if (description != null ? !description.equals(option.description) : option.description != null) return false; + if (name != null ? !name.equals(option.name) : option.name != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (name != null ? name.hashCode() : 0); + result = 31 * result + (description != null ? description.hashCode() : 0); + return result; + } +} diff --git a/gogrid/src/main/java/org/jclouds/gogrid/domain/Server.java b/gogrid/src/main/java/org/jclouds/gogrid/domain/Server.java new file mode 100644 index 0000000000..1bbb1fecd4 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/domain/Server.java @@ -0,0 +1,124 @@ +package org.jclouds.gogrid.domain; + +import com.google.common.primitives.Longs; + +/** + * @author Oleksiy Yarmula + */ +public class Server implements Comparable { + + private long id; + private boolean isSandbox; + private String name; + private String description; + private Option state; + + private Option type; + private Option ram; + private Option os; + private Ip ip; + + private ServerImage image; + + /** + * A no-args constructor is required for deserialization + */ + public Server() { + } + + public Server(long id, boolean sandbox, String name, + String description, Option state, Option type, + Option ram, Option os, Ip ip, ServerImage image) { + this.id = id; + isSandbox = sandbox; + this.name = name; + this.description = description; + this.state = state; + this.type = type; + this.ram = ram; + this.os = os; + this.ip = ip; + this.image = image; + } + + public long getId() { + return id; + } + + public boolean isSandbox() { + return isSandbox; + } + + public String getName() { + return name; + } + + public String getDescription() { + return description; + } + + public Option getState() { + return state; + } + + public Option getType() { + return type; + } + + public Option getRam() { + return ram; + } + + public Option getOs() { + return os; + } + + public Ip getIp() { + return ip; + } + + public ServerImage getImage() { + return image; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + Server server = (Server) o; + + if (id != server.id) return false; + if (isSandbox != server.isSandbox) return false; + if (description != null ? !description.equals(server.description) : server.description != null) return false; + if (image != null ? !image.equals(server.image) : server.image != null) return false; + if (ip != null ? !ip.equals(server.ip) : server.ip != null) return false; + if (!name.equals(server.name)) return false; + if (os != null ? !os.equals(server.os) : server.os != null) return false; + if (ram != null ? !ram.equals(server.ram) : server.ram != null) return false; + if (!state.equals(server.state)) return false; + if (!type.equals(server.type)) return false; + + return true; + } + + @Override + public int hashCode() { + int result = (int) (id ^ (id >>> 32)); + result = 31 * result + (isSandbox ? 1 : 0); + result = 31 * result + name.hashCode(); + result = 31 * result + (description != null ? description.hashCode() : 0); + result = 31 * result + state.hashCode(); + result = 31 * result + type.hashCode(); + result = 31 * result + (ram != null ? ram.hashCode() : 0); + result = 31 * result + (os != null ? os.hashCode() : 0); + result = 31 * result + (ip != null ? ip.hashCode() : 0); + result = 31 * result + (image != null ? image.hashCode() : 0); + return result; + } + + @Override + public int compareTo(Server o) { + return Longs.compare(id, o.getId()); + } +} diff --git a/gogrid/src/main/java/org/jclouds/gogrid/domain/ServerImage.java b/gogrid/src/main/java/org/jclouds/gogrid/domain/ServerImage.java new file mode 100644 index 0000000000..249a8c2543 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/domain/ServerImage.java @@ -0,0 +1,175 @@ +package org.jclouds.gogrid.domain; + +import com.google.common.collect.ImmutableList; +import com.google.gson.annotations.SerializedName; + +import java.util.Date; +import java.util.List; + +/** + * @author Oleksiy Yarmula + */ +public class ServerImage { + + private long id; + private String name; + private String friendlyName; + private String description; + private Option os; + private Option architecture; + private Option type; + private Option state; + private double price; + private String location; + private boolean isActive; + private boolean isPublic; + private Date createdTime; + private Date updatedTime; + @SerializedName("billingtokens") + private List billingTokens; + private Customer owner; + + /** + * A no-args constructor is required for deserialization + */ + public ServerImage() { + } + + public ServerImage(long id, String name, String friendlyName, + String description, Option os, Option architecture, + Option type, Option state, double price, String location, + boolean active, boolean aPublic, Date createdTime, + Date updatedTime, List billingTokens, Customer owner) { + this.id = id; + this.name = name; + this.friendlyName = friendlyName; + this.description = description; + this.os = os; + this.architecture = architecture; + this.type = type; + this.state = state; + this.price = price; + this.location = location; + isActive = active; + isPublic = aPublic; + this.createdTime = createdTime; + this.updatedTime = updatedTime; + this.billingTokens = billingTokens; + this.owner = owner; + } + + public long getId() { + return id; + } + + public String getName() { + return name; + } + + public String getFriendlyName() { + return friendlyName; + } + + public String getDescription() { + return description; + } + + public Option getOs() { + return os; + } + + public Option getArchitecture() { + return architecture; + } + + public Option getType() { + return type; + } + + public Option getState() { + return state; + } + + public double getPrice() { + return price; + } + + public String getLocation() { + return location; + } + + public boolean isActive() { + return isActive; + } + + public boolean isPublic() { + return isPublic; + } + + public Date getCreatedTime() { + return createdTime; + } + + public Date getUpdatedTime() { + return updatedTime; + } + + public List getBillingTokens() { + return ImmutableList.copyOf(billingTokens); + } + + public Customer getOwner() { + return owner; + } + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + ServerImage that = (ServerImage) o; + + if (id != that.id) return false; + if (isActive != that.isActive) return false; + if (isPublic != that.isPublic) return false; + if (Double.compare(that.price, price) != 0) return false; + if (architecture != null ? !architecture.equals(that.architecture) : that.architecture != null) return false; + if (billingTokens != null ? !billingTokens.equals(that.billingTokens) : that.billingTokens != null) + return false; + if (!createdTime.equals(that.createdTime)) return false; + if (description != null ? !description.equals(that.description) : that.description != null) return false; + if (friendlyName != null ? !friendlyName.equals(that.friendlyName) : that.friendlyName != null) return false; + if (location != null ? !location.equals(that.location) : that.location != null) return false; + if (!name.equals(that.name)) return false; + if (!os.equals(that.os)) return false; + if (owner != null ? !owner.equals(that.owner) : that.owner != null) return false; + if (!state.equals(that.state)) return false; + if (!type.equals(that.type)) return false; + if (updatedTime != null ? !updatedTime.equals(that.updatedTime) : that.updatedTime != null) return false; + + return true; + } + + @Override + public int hashCode() { + int result; + long temp; + result = (int) (id ^ (id >>> 32)); + result = 31 * result + name.hashCode(); + result = 31 * result + (friendlyName != null ? friendlyName.hashCode() : 0); + result = 31 * result + (description != null ? description.hashCode() : 0); + result = 31 * result + os.hashCode(); + result = 31 * result + type.hashCode(); + result = 31 * result + state.hashCode(); + temp = price != +0.0d ? Double.doubleToLongBits(price) : 0L; + result = 31 * result + (int) (temp ^ (temp >>> 32)); + result = 31 * result + (location != null ? location.hashCode() : 0); + result = 31 * result + (isActive ? 1 : 0); + result = 31 * result + (isPublic ? 1 : 0); + result = 31 * result + createdTime.hashCode(); + result = 31 * result + (updatedTime != null ? updatedTime.hashCode() : 0); + result = 31 * result + (billingTokens != null ? billingTokens.hashCode() : 0); + result = 31 * result + (owner != null ? owner.hashCode() : 0); + return result; + } +} diff --git a/gogrid/src/main/java/org/jclouds/gogrid/domain/internal/GenericResponseContainer.java b/gogrid/src/main/java/org/jclouds/gogrid/domain/internal/GenericResponseContainer.java new file mode 100644 index 0000000000..b1067e187d --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/domain/internal/GenericResponseContainer.java @@ -0,0 +1,57 @@ +package org.jclouds.gogrid.domain.internal; + +import com.google.common.base.Throwables; + +import java.lang.reflect.Field; +import java.util.SortedSet; + +/** + * @author Oleksiy Yarmula + */ +public class GenericResponseContainer { + + private Summary summary; + private String status; + private String method; + private SortedSet list; + + public Summary getSummary() { + return summary; + } + + public String getStatus() { + return status; + } + + public String getMethod() { + return method; + } + + public SortedSet getList() { + return list; + } + + static class Summary { + private int total; + private int start; + private int numPages; + private int returned; + + public int getTotal() { + return total; + } + + public int getStart() { + return start; + } + + public int getNumPages() { + return numPages; + } + + public int getReturned() { + return returned; + } + } + +} diff --git a/gogrid/src/main/java/org/jclouds/gogrid/filters/SharedKeyLiteAuthentication.java b/gogrid/src/main/java/org/jclouds/gogrid/filters/SharedKeyLiteAuthentication.java new file mode 100644 index 0000000000..ef49f69e57 --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/filters/SharedKeyLiteAuthentication.java @@ -0,0 +1,73 @@ +package org.jclouds.gogrid.filters; + +import com.google.common.base.Throwables; +import org.jclouds.Constants; +import org.jclouds.date.TimeStamp; +import org.jclouds.encryption.EncryptionService; +import org.jclouds.gogrid.reference.GoGridConstants; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpRequestFilter; +import org.jclouds.http.HttpUtils; +import org.jclouds.logging.Logger; +import org.jclouds.rest.internal.GeneratedHttpRequest; + +import javax.annotation.Resource; +import javax.inject.Inject; +import javax.inject.Named; + +import static com.google.common.base.Preconditions.checkArgument; +import static com.google.common.base.Preconditions.checkNotNull; +import static java.lang.String.format; + +/** + * @author Oleksiy Yarmula + */ +public class SharedKeyLiteAuthentication implements HttpRequestFilter { + + private final String apiKey; + private final String secret; + private final Long timeStamp; + private final EncryptionService encryptionService; + @Resource + @Named(Constants.LOGGER_SIGNATURE) + Logger signatureLog = Logger.NULL; + + @Inject + public SharedKeyLiteAuthentication(@Named(GoGridConstants.PROPERTY_GOGRID_USER) String apiKey, + @Named(GoGridConstants.PROPERTY_GOGRID_PASSWORD) String secret, + @TimeStamp Long timeStamp, + EncryptionService encryptionService) { + this.encryptionService = encryptionService; + this.apiKey = apiKey; + this.secret = secret; + this.timeStamp = timeStamp; + } + + public void filter(HttpRequest request) { + checkArgument(checkNotNull(request, "input") instanceof GeneratedHttpRequest, + "this decorator is only valid for GeneratedHttpRequests!"); + GeneratedHttpRequest generatedRequest = (GeneratedHttpRequest) request; + + String toSign = createStringToSign(); + String signatureMd5 = getMd5For(toSign); + + generatedRequest.addQueryParam("sig", signatureMd5); + generatedRequest.addQueryParam("api_key", apiKey); + + HttpUtils.logRequest(signatureLog, request, "<<"); + } + + private String createStringToSign() { + return format("%s%s%s", apiKey, secret, timeStamp); + } + + private String getMd5For(String stringToHash) { + try { + return encryptionService.md5Hex(stringToHash.getBytes()); + } catch(Exception e) { + throw Throwables.propagate(e); + } + + } + +} diff --git a/gogrid/src/main/java/org/jclouds/functions/ParseStatusesFromJsonResponse.java b/gogrid/src/main/java/org/jclouds/gogrid/functions/ParseServerListFromJsonResponse.java similarity index 66% rename from gogrid/src/main/java/org/jclouds/functions/ParseStatusesFromJsonResponse.java rename to gogrid/src/main/java/org/jclouds/gogrid/functions/ParseServerListFromJsonResponse.java index 994ef95760..9f9ff8ba54 100644 --- a/gogrid/src/main/java/org/jclouds/functions/ParseStatusesFromJsonResponse.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/functions/ParseServerListFromJsonResponse.java @@ -1,6 +1,6 @@ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ */ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -39,7 +39,7 @@ * under the License. * ==================================================================== */ -package org.jclouds.functions; +package org.jclouds.gogrid.functions; import java.io.InputStream; import java.io.InputStreamReader; @@ -50,32 +50,36 @@ import java.util.SortedSet; import javax.inject.Inject; import javax.inject.Singleton; +import com.google.common.collect.Sets; +import org.jclouds.gogrid.domain.Server; +import org.jclouds.gogrid.domain.internal.GenericResponseContainer; import org.jclouds.http.functions.ParseJson; -import org.jclouds.domain.Status; import com.google.gson.Gson; import com.google.gson.reflect.TypeToken; /** - * This parses {@link Status} from a json string. - * + * This parses {@link Server servers} from a json string. + * * @author Adrian Cole */ @Singleton -public class ParseStatusesFromJsonResponse extends ParseJson> { +public class ParseServerListFromJsonResponse extends ParseJson> { - @Inject - public ParseStatusesFromJsonResponse(Gson gson) { - super(gson); - } + @Inject + public ParseServerListFromJsonResponse(Gson gson) { + super(gson); + } - public SortedSet apply(InputStream stream) { - Type setType = new TypeToken>() { - }.getType(); - try { - return gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException("jclouds requires UTF-8 encoding", e); - } - } + public SortedSet apply(InputStream stream) { + Type setType = new TypeToken>() { + }.getType(); + GenericResponseContainer response; + try { + response = gson.fromJson(new InputStreamReader(stream, "UTF-8"), setType); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException("jclouds requires UTF-8 encoding", e); + } + return response.getList(); + } } \ No newline at end of file diff --git a/gogrid/src/main/java/org/jclouds/reference/GoGridConstants.java b/gogrid/src/main/java/org/jclouds/gogrid/reference/GoGridConstants.java similarity index 71% rename from gogrid/src/main/java/org/jclouds/reference/GoGridConstants.java rename to gogrid/src/main/java/org/jclouds/gogrid/reference/GoGridConstants.java index f239a18d4f..afc22f518d 100644 --- a/gogrid/src/main/java/org/jclouds/reference/GoGridConstants.java +++ b/gogrid/src/main/java/org/jclouds/gogrid/reference/GoGridConstants.java @@ -1,6 +1,6 @@ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed under the Apache License, Version 2.0 (the "License"); @@ -18,7 +18,7 @@ */ /** * - * Copyright (C) 2009 Cloud Conscious, LLC. + * Copyright (C) 2010 Cloud Conscious, LLC. * * ==================================================================== * Licensed to the Apache Software Foundation (ASF) under one @@ -39,15 +39,21 @@ * under the License. * ==================================================================== */ -package org.jclouds.reference; +package org.jclouds.gogrid.reference; /** * Configuration properties and constants used in GoGrid connections. - * + * * @author Adrian Cole */ public interface GoGridConstants { - public static final String PROPERTY_GOGRID_ENDPOINT = "jclouds.gogrid.endpoint"; - public static final String PROPERTY_GOGRID_USER = "jclouds.gogrid.user"; - public static final String PROPERTY_GOGRID_PASSWORD = "jclouds.gogrid.password"; + public static final String PROPERTY_GOGRID_ENDPOINT = "jclouds.gogrid.endpoint"; + //TODO: see if "users" needs to be renamed to "apiKey" + public static final String PROPERTY_GOGRID_USER = "jclouds.gogrid.api.key"; + //TODO: see if "password" needs to be renamed to "secret" + public static final String PROPERTY_GOGRID_PASSWORD = "jclouds.gogrid.secret"; + /** + * how long do we wait before obtaining a new timestamp for requests. + */ + public static final String PROPERTY_GOGRID_SESSIONINTERVAL = "jclouds.gogrid.sessioninterval"; } diff --git a/gogrid/src/main/java/org/jclouds/gogrid/reference/GoGridHeaders.java b/gogrid/src/main/java/org/jclouds/gogrid/reference/GoGridHeaders.java new file mode 100644 index 0000000000..cda6bdee0a --- /dev/null +++ b/gogrid/src/main/java/org/jclouds/gogrid/reference/GoGridHeaders.java @@ -0,0 +1,8 @@ +package org.jclouds.gogrid.reference; + +/** + * @author Oleksiy Yarmula + */ +public interface GoGridHeaders { + public static final String VERSION = "v"; +} diff --git a/gogrid/src/test/java/org/jclouds/GoGridAsyncClientTest.java b/gogrid/src/test/java/org/jclouds/GoGridAsyncClientTest.java deleted file mode 100644 index 040293825d..0000000000 --- a/gogrid/src/test/java/org/jclouds/GoGridAsyncClientTest.java +++ /dev/null @@ -1,127 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. - * ==================================================================== - */ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.lang.reflect.Method; -import java.net.URI; - -import javax.inject.Singleton; - -import org.jclouds.http.filters.BasicAuthentication; -import org.jclouds.logging.Logger; -import org.jclouds.logging.Logger.LoggerFactory; -import org.jclouds.rest.RestClientTest; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.jclouds.rest.internal.RestAnnotationProcessor; -import org.jclouds.functions.ParseStatusesFromJsonResponse; -import org.jclouds.encryption.EncryptionService; -import org.testng.annotations.Test; - -import com.google.inject.AbstractModule; -import com.google.inject.Module; -import com.google.inject.Provides; -import com.google.inject.TypeLiteral; - -/** - * Tests annotation parsing of {@code GoGridAsyncClient} - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "gogrid.GoGridAsyncClientTest") -public class GoGridAsyncClientTest extends RestClientTest { - - public void testGetMyMentions() throws SecurityException, NoSuchMethodException, IOException { - Method method = GoGridAsyncClient.class.getMethod("TODO: insert test method name"); - GeneratedHttpRequest httpMethod = processor.createRequest(method); - - assertRequestLineEquals(httpMethod, "TODO: insert expected request"); - assertHeadersEqual(httpMethod, ""); - assertPayloadEquals(httpMethod, null); - - assertResponseParserClassEquals(method, httpMethod, ParseStatusesFromJsonResponse.class); - assertSaxResponseParserClassEquals(method, null); - assertExceptionParserClassEquals(method, null); - - checkFilters(httpMethod); - } - - @Override - protected void checkFilters(GeneratedHttpRequest httpMethod) { - assertEquals(httpMethod.getFilters().size(), 1); - assertEquals(httpMethod.getFilters().get(0).getClass(), BasicAuthentication.class); - } - - @Override - protected TypeLiteral> createTypeLiteral() { - return new TypeLiteral>() { - }; - } - - @Override - protected Module createModule() { - return new AbstractModule() { - @Override - protected void configure() { - bind(URI.class).annotatedWith(GoGrid.class).toInstance( - URI.create("https://api.gogrid.com/api")); - bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { - public Logger getLogger(String category) { - return Logger.NULL; - } - }); - } - - @SuppressWarnings("unused") - @Provides - @Singleton - public BasicAuthentication provideBasicAuthentication(EncryptionService encryptionService) - throws UnsupportedEncodingException { - return new BasicAuthentication("foo", "bar", encryptionService); - } - - }; - } -} diff --git a/gogrid/src/test/java/org/jclouds/GoGridClientLiveTest.java b/gogrid/src/test/java/org/jclouds/GoGridClientLiveTest.java deleted file mode 100644 index 8d41f00818..0000000000 --- a/gogrid/src/test/java/org/jclouds/GoGridClientLiveTest.java +++ /dev/null @@ -1,78 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. - * ==================================================================== - */ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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; - -import static com.google.common.base.Preconditions.checkNotNull; - -import java.util.SortedSet; - -import org.jclouds.logging.log4j.config.Log4JLoggingModule; -import org.jclouds.domain.Status; -import org.testng.annotations.BeforeGroups; -import org.testng.annotations.Test; - -/** - * Tests behavior of {@code GoGridClient} - * - * @author Adrian Cole - */ -@Test(groups = "live", testName = "gogrid.GoGridClientLiveTest") -public class GoGridClientLiveTest { - - private GoGridClient connection; - - @BeforeGroups(groups = { "live" }) - public void setupClient() { - String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); - String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); - - connection = GoGridContextFactory.createContext(user, password, new Log4JLoggingModule()) - .getApi(); - } - - @Test - public void testGetMyMentions() { - SortedSet response = connection.getMyMentions(); - assert (response.size() > 0); - } - -} diff --git a/gogrid/src/test/java/org/jclouds/GoGridContextBuilderTest.java b/gogrid/src/test/java/org/jclouds/GoGridContextBuilderTest.java deleted file mode 100644 index 630aa8e821..0000000000 --- a/gogrid/src/test/java/org/jclouds/GoGridContextBuilderTest.java +++ /dev/null @@ -1,116 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. - * ==================================================================== - */ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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; - -import static org.testng.Assert.assertEquals; - -import java.net.URI; -import java.util.ArrayList; -import java.util.List; - -import org.jclouds.http.filters.BasicAuthentication; -import org.jclouds.rest.RestContext; -import org.jclouds.rest.internal.RestContextImpl; -import org.jclouds.config.GoGridRestClientModule; -import org.jclouds.reference.GoGridConstants; -import org.testng.annotations.Test; - -import com.google.inject.Injector; -import com.google.inject.Key; -import com.google.inject.Module; -import com.google.inject.TypeLiteral; - -/** - * Tests behavior of modules configured in GoGridContextBuilder - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "gogrid.GoGridContextBuilderTest") -public class GoGridContextBuilderTest { - - public void testNewBuilder() { - GoGridContextBuilder builder = newBuilder(); - assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_ENDPOINT), - "https://api.gogrid.com/api"); - assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_USER), - "user"); - assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_PASSWORD), - "password"); - } - - public void testBuildContext() { - RestContext context = newBuilder().buildContext(); - assertEquals(context.getClass(), RestContextImpl.class); - assertEquals(context.getAccount(), "user"); - assertEquals(context.getEndPoint(), URI.create("https://api.gogrid.com/api")); - } - - public void testBuildInjector() { - Injector i = newBuilder().buildInjector(); - assert i.getInstance(Key.get(new TypeLiteral>() { - })) != null; // TODO: test all things taken from context - assert i.getInstance(BasicAuthentication.class) != null; - } - - protected void testAddContextModule() { - List modules = new ArrayList(); - GoGridContextBuilder builder = newBuilder(); - builder.addContextModule(modules); - assertEquals(modules.size(), 1); - assertEquals(modules.get(0).getClass(), GoGridRestClientModule.class); - } - - private GoGridContextBuilder newBuilder() { - GoGridContextBuilder builder = new GoGridContextBuilder(new GoGridPropertiesBuilder( - "user", "password").build()); - return builder; - } - - protected void addClientModule() { - List modules = new ArrayList(); - GoGridContextBuilder builder = newBuilder(); - builder.addClientModule(modules); - assertEquals(modules.size(), 1); - assertEquals(modules.get(0).getClass(), GoGridRestClientModule.class); - } - -} diff --git a/gogrid/src/test/java/org/jclouds/config/GoGridContextModuleTest.java b/gogrid/src/test/java/org/jclouds/config/GoGridContextModuleTest.java deleted file mode 100644 index bf04515f81..0000000000 --- a/gogrid/src/test/java/org/jclouds/config/GoGridContextModuleTest.java +++ /dev/null @@ -1,134 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. - * ==================================================================== - */ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.config; - -import static org.testng.Assert.assertEquals; -import static com.google.common.util.concurrent.Executors.sameThreadExecutor; - -import org.jclouds.concurrent.config.ExecutorServiceModule; -import org.jclouds.http.HttpRetryHandler; -import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; -import org.jclouds.http.functions.config.ParserModule; -import org.jclouds.http.functions.config.ParserModule.CDateAdapter; -import org.jclouds.http.functions.config.ParserModule.DateAdapter; -import org.jclouds.http.handlers.CloseContentAndSetExceptionErrorHandler; -import org.jclouds.http.handlers.DelegatingErrorHandler; -import org.jclouds.http.handlers.DelegatingRetryHandler; -import org.jclouds.http.handlers.RedirectionRetryHandler; -import org.jclouds.logging.Logger; -import org.jclouds.logging.Logger.LoggerFactory; -import org.jclouds.reference.GoGridConstants; -import org.jclouds.util.Jsr330; -import org.jclouds.Constants; -import org.testng.annotations.Test; - -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "gogrid.GoGridContextModule") -public class GoGridContextModuleTest { - - Injector createInjector() { - return Guice.createInjector(new GoGridRestClientModule(), new GoGridContextModule() { - @Override - protected void configure() { - bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_USER)).to( - "user"); - bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_PASSWORD)) - .to("password"); - bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_ENDPOINT)) - .to("http://localhost"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)) - .to("1"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)) - .to("0"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)) - .to("1"); - bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)) - .to("1"); - bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { - public Logger getLogger(String category) { - return Logger.NULL; - } - }); - super.configure(); - } - }, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(), - new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor())); - } - - @Test - void testServerErrorHandler() { - DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); - assertEquals(handler.getServerErrorHandler().getClass(), - CloseContentAndSetExceptionErrorHandler.class); - } - - @Test - void testDateTimeAdapter() { - assertEquals(this.createInjector().getInstance(DateAdapter.class).getClass(), - CDateAdapter.class); - } - - @Test - void testClientErrorHandler() { - DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); - assertEquals(handler.getClientErrorHandler().getClass(), - CloseContentAndSetExceptionErrorHandler.class); - } - - @Test - void testClientRetryHandler() { - DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); - assertEquals(handler.getClientErrorRetryHandler(), HttpRetryHandler.NEVER_RETRY); - } - - @Test - void testRedirectionRetryHandler() { - DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); - assertEquals(handler.getRedirectionRetryHandler().getClass(), RedirectionRetryHandler.class); - } - -} \ No newline at end of file diff --git a/gogrid/src/test/java/org/jclouds/functions/ParseStatusesFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/functions/ParseStatusesFromJsonResponseTest.java deleted file mode 100644 index eb65374518..0000000000 --- a/gogrid/src/test/java/org/jclouds/functions/ParseStatusesFromJsonResponseTest.java +++ /dev/null @@ -1,167 +0,0 @@ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * 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. - * ==================================================================== - */ -/** - * - * Copyright (C) 2009 Cloud Conscious, LLC. - * - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF 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.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.InputStream; -import java.net.URI; -import java.net.UnknownHostException; -import java.util.SortedSet; - -import org.jclouds.http.functions.config.ParserModule; -import org.jclouds.domain.Status; -import org.jclouds.domain.User; -import org.jclouds.date.DateService; -import org.jclouds.date.internal.SimpleDateFormatDateService; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableSortedSet; -import com.google.gson.Gson; -import com.google.inject.Guice; -import com.google.inject.Injector; - -/** - * Tests behavior of {@code ParseStatusesFromJsonResponse} - * - * @author Adrian Cole - */ -@Test(groups = "unit", testName = "twitter.ParseStatusesFromJsonResponseTest") -public class ParseStatusesFromJsonResponseTest { - - Injector i = Guice.createInjector(new ParserModule() { - @Override - protected void configure() { - bind(DateAdapter.class).to(CDateAdapter.class); - super.configure(); - } - }); - DateService dateService = new SimpleDateFormatDateService(); - - public void testApplyInputStreamDetails() throws UnknownHostException { - InputStream is = getClass().getResourceAsStream("/test_mentions.json"); - - SortedSet expects = ImmutableSortedSet - .of( - - new Status( - dateService.cDateParse("Sat Oct 31 01:45:14 +0000 2009"), - false, - null, - 5303839785l, - null, - null, - null, - "TweetDeck", - "RT @jclouds: come find out about #cloud storage and how to access it from #java in palo alto this Tuesday: http://is.gd/4IFA9", - false, - new User( - dateService.cDateParse("Sat Apr 26 06:13:08 +0000 2008"), - "Jack of All Trades: Dad to anZel and Arden, VMware, vCloud, Security, Compliance, Former Developer", - 0, - 474, - false, - 199, - false, - 14540593, - "Bay Area, CA", - "Jian Zhen", - false, - "C6E2EE", - URI - .create("http://s.twimg.com/a/1256778767/images/themes/theme2/bg.gif"), - false, - URI - .create("http://a3.twimg.com/profile_images/64445411/30b8b19_bigger_normal.jpg"), - "1F98C7", "C6E2EE", "DAECF4", "663B12", false, "zhenjl", - 1981, "Pacific Time (US & Canada)", URI - .create("http://zhen.org"), -28800, false)), - - new Status( - dateService.cDateParse("Sat Oct 31 09:35:27 +0000 2009"), - false, - null, - 5310690603l, - null, - null, - null, - "TweetDeck", - "RT @jclouds: live multi #cloud demo of jclouds connecting to 3 storage clouds from google appengine http://is.gd/4IXMh", - false, - new User( - dateService.cDateParse("Tue Apr 28 15:29:42 +0000 2009"), - "Some random guy who seems to care about cloud collisions at siliconANGLE.com", - 245, - 572, - false, - 325, - false, - 36093693, - "San Francisco ", - "James Watters", - false, - "C6E2EE", - URI - .create("http://a1.twimg.com/profile_background_images/24067016/17361976.jpg"), - true, - URI - .create("http://a3.twimg.com/profile_images/445071063/tiktaalik-transitional-fossil_normal.png"), - "1F98C7", - "C6E2EE", - "DAECF4", - "663B12", - false, - "wattersjames", - 1964, - "Pacific Time (US & Canada)", - URI - .create("http://siliconangle.net/ver2/author/jwatters/"), - -28800, false)) - - ); - - ParseStatusesFromJsonResponse parser = new ParseStatusesFromJsonResponse(i - .getInstance(Gson.class)); - SortedSet response = parser.apply(is); - assertEquals(response, expects); - } -} diff --git a/gogrid/src/test/java/org/jclouds/gogrid/GoGridAsyncClientTest.java b/gogrid/src/test/java/org/jclouds/gogrid/GoGridAsyncClientTest.java new file mode 100644 index 0000000000..4ce68f3a42 --- /dev/null +++ b/gogrid/src/test/java/org/jclouds/gogrid/GoGridAsyncClientTest.java @@ -0,0 +1,138 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.gogrid; + +import static org.testng.Assert.assertEquals; + +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.lang.reflect.Method; +import java.net.URI; + +import javax.inject.Singleton; + +import com.google.common.collect.Iterables; +import org.jclouds.date.TimeStamp; +import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication; +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; +import org.jclouds.rest.RestClientTest; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.rest.internal.RestAnnotationProcessor; +import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse; +import org.jclouds.encryption.EncryptionService; +import org.testng.annotations.Test; + +import com.google.inject.AbstractModule; +import com.google.inject.Module; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; + +/** + * Tests annotation parsing of {@code GoGridAsyncClient} + * + * @author Adrian Cole + * @author Oleksiy Yarmula + */ +@Test(groups = "unit", testName = "gogrid.GoGridAsyncClientTest") +public class GoGridAsyncClientTest extends RestClientTest { + + @Test + public void testGetServerList() throws SecurityException, NoSuchMethodException, IOException { + Method method = GoGridAsyncClient.class.getMethod("getServerList"); + GeneratedHttpRequest httpRequest = processor.createRequest(method); + + assertRequestLineEquals(httpRequest, "GET https://api.gogrid.com/api/grid/server/list?v=1.3 HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + + assertResponseParserClassEquals(method, httpRequest, ParseServerListFromJsonResponse.class); + assertSaxResponseParserClassEquals(method, null); + assertExceptionParserClassEquals(method, null); + + checkFilters(httpRequest); + Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); + + assertRequestLineEquals(httpRequest, + "GET https://api.gogrid.com/api/grid/server/list?" + + "v=1.3&sig=3f446f171455fbb5574aecff4997b273&api_key=foo " + + "HTTP/1.1"); + assertHeadersEqual(httpRequest, ""); + assertPayloadEquals(httpRequest, null); + } + + @Override + protected void checkFilters(GeneratedHttpRequest httpMethod) { + assertEquals(httpMethod.getFilters().size(), 1); + assertEquals(httpMethod.getFilters().get(0).getClass(), SharedKeyLiteAuthentication.class); + } + + @Override + protected TypeLiteral> createTypeLiteral() { + return new TypeLiteral>() { + }; + } + + @Override + protected Module createModule() { + return new AbstractModule() { + @Override + protected void configure() { + bind(URI.class).annotatedWith(GoGrid.class).toInstance( + URI.create("https://api.gogrid.com/api")); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); + } + + @Provides + @Singleton + public SharedKeyLiteAuthentication provideAuthentication(EncryptionService encryptionService) + throws UnsupportedEncodingException { + return new SharedKeyLiteAuthentication("foo", "bar", 1267243795L, encryptionService); + } + }; + } +} diff --git a/gogrid/src/test/java/org/jclouds/gogrid/GoGridClientLiveTest.java b/gogrid/src/test/java/org/jclouds/gogrid/GoGridClientLiveTest.java new file mode 100644 index 0000000000..c39eef0105 --- /dev/null +++ b/gogrid/src/test/java/org/jclouds/gogrid/GoGridClientLiveTest.java @@ -0,0 +1,60 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.gogrid; + +import static com.google.common.base.Preconditions.checkNotNull; + +import org.jclouds.gogrid.domain.Server; +import org.jclouds.logging.log4j.config.Log4JLoggingModule; +import org.testng.annotations.BeforeGroups; +import org.testng.annotations.Test; + +import java.util.Set; + +/** + * Tests behavior of {@code GoGridClient} + * + * @author Adrian Cole + */ +@Test(groups = "live", testName = "gogrid.GoGridClientLiveTest") +public class GoGridClientLiveTest { + + private GoGridClient connection; + + @BeforeGroups(groups = { "live" }) + public void setupClient() { + String user = checkNotNull(System.getProperty("jclouds.test.user"), "jclouds.test.user"); + String password = checkNotNull(System.getProperty("jclouds.test.key"), "jclouds.test.key"); + + connection = GoGridContextFactory.createContext(user, password, new Log4JLoggingModule()) + .getApi(); + } + + @Test + public void testGetServerList() { + Set response = connection.getServerList(); + assert (response.size() > 0); + } + +} diff --git a/gogrid/src/test/java/org/jclouds/gogrid/GoGridContextBuilderTest.java b/gogrid/src/test/java/org/jclouds/gogrid/GoGridContextBuilderTest.java new file mode 100644 index 0000000000..64a8397b07 --- /dev/null +++ b/gogrid/src/test/java/org/jclouds/gogrid/GoGridContextBuilderTest.java @@ -0,0 +1,119 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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. + * ==================================================================== + */ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.gogrid; + +import static org.testng.Assert.assertEquals; + +import java.net.URI; +import java.util.ArrayList; +import java.util.List; + +import org.jclouds.gogrid.filters.SharedKeyLiteAuthentication; +import org.jclouds.gogrid.functions.ParseServerListFromJsonResponse; +import org.jclouds.http.filters.BasicAuthentication; +import org.jclouds.rest.RestContext; +import org.jclouds.rest.internal.RestContextImpl; +import org.jclouds.gogrid.config.GoGridRestClientModule; +import org.jclouds.gogrid.reference.GoGridConstants; +import org.testng.annotations.Test; + +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.Module; +import com.google.inject.TypeLiteral; + +/** + * Tests behavior of modules configured in GoGridContextBuilder + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "gogrid.GoGridContextBuilderTest") +public class GoGridContextBuilderTest { + + public void testNewBuilder() { + GoGridContextBuilder builder = newBuilder(); + assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_ENDPOINT), + "https://api.gogrid.com/api"); + assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_USER), + "user"); + assertEquals(builder.getProperties().getProperty(GoGridConstants.PROPERTY_GOGRID_PASSWORD), + "password"); + } + + public void testBuildContext() { + RestContext context = newBuilder().buildContext(); + assertEquals(context.getClass(), RestContextImpl.class); + assertEquals(context.getAccount(), "user"); + assertEquals(context.getEndPoint(), URI.create("https://api.gogrid.com/api")); + } + + public void testBuildInjector() { + Injector i = newBuilder().buildInjector(); + assert i.getInstance(Key.get(new TypeLiteral>() { + })) != null; + assert i.getInstance(SharedKeyLiteAuthentication.class) != null; + assert i.getInstance(ParseServerListFromJsonResponse.class) != null; + } + + protected void testAddContextModule() { + List modules = new ArrayList(); + GoGridContextBuilder builder = newBuilder(); + builder.addContextModule(modules); + assertEquals(modules.size(), 1); + assertEquals(modules.get(0).getClass(), GoGridRestClientModule.class); + } + + private GoGridContextBuilder newBuilder() { + GoGridContextBuilder builder = new GoGridContextBuilder(new GoGridPropertiesBuilder( + "user", "password").build()); + return builder; + } + + protected void addClientModule() { + List modules = new ArrayList(); + GoGridContextBuilder builder = newBuilder(); + builder.addClientModule(modules); + assertEquals(modules.size(), 1); + assertEquals(modules.get(0).getClass(), GoGridRestClientModule.class); + } + +} diff --git a/gogrid/src/test/java/org/jclouds/gogrid/config/GoGridContextModuleTest.java b/gogrid/src/test/java/org/jclouds/gogrid/config/GoGridContextModuleTest.java new file mode 100644 index 0000000000..d3cf3a497d --- /dev/null +++ b/gogrid/src/test/java/org/jclouds/gogrid/config/GoGridContextModuleTest.java @@ -0,0 +1,117 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * 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.gogrid.config; + +import static org.testng.Assert.assertEquals; +import static com.google.common.util.concurrent.Executors.sameThreadExecutor; + +import org.jclouds.concurrent.config.ExecutorServiceModule; +import org.jclouds.http.HttpRetryHandler; +import org.jclouds.http.config.JavaUrlHttpCommandExecutorServiceModule; +import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.http.functions.config.ParserModule.CDateAdapter; +import org.jclouds.http.functions.config.ParserModule.DateAdapter; +import org.jclouds.http.handlers.CloseContentAndSetExceptionErrorHandler; +import org.jclouds.http.handlers.DelegatingErrorHandler; +import org.jclouds.http.handlers.DelegatingRetryHandler; +import org.jclouds.http.handlers.RedirectionRetryHandler; +import org.jclouds.logging.Logger; +import org.jclouds.logging.Logger.LoggerFactory; +import org.jclouds.gogrid.reference.GoGridConstants; +import org.jclouds.util.Jsr330; +import org.jclouds.Constants; +import org.testng.annotations.Test; + +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "gogrid.GoGridContextModule") +public class GoGridContextModuleTest { + + Injector createInjector() { + return Guice.createInjector(new GoGridRestClientModule(), new GoGridContextModule() { + @Override + protected void configure() { + bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_USER)).to( + "user"); + bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_PASSWORD)) + .to("password"); + bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_ENDPOINT)) + .to("http://localhost"); + bindConstant().annotatedWith(Jsr330.named(GoGridConstants.PROPERTY_GOGRID_SESSIONINTERVAL)) + .to("30"); + bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_HOST)) + .to("1"); + bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_MAX_CONNECTIONS_PER_CONTEXT)) + .to("0"); + bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_IO_WORKER_THREADS)) + .to("1"); + bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_USER_THREADS)) + .to("1"); + bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_CONNECTION_TIMEOUT)) + .to("30"); + bindConstant().annotatedWith(Jsr330.named(Constants.PROPERTY_SO_TIMEOUT)) + .to("10"); + bind(Logger.LoggerFactory.class).toInstance(new LoggerFactory() { + public Logger getLogger(String category) { + return Logger.NULL; + } + }); + super.configure(); + } + }, new ParserModule(), new JavaUrlHttpCommandExecutorServiceModule(), + new ExecutorServiceModule(sameThreadExecutor(), sameThreadExecutor())); + } + + @Test + void testServerErrorHandler() { + DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); + assertEquals(handler.getServerErrorHandler().getClass(), + CloseContentAndSetExceptionErrorHandler.class); + } + + @Test + void testDateTimeAdapter() { + assertEquals(this.createInjector().getInstance(DateAdapter.class).getClass(), + GoGridContextModule.DateSecondsAdapter.class); + } + + @Test + void testClientErrorHandler() { + DelegatingErrorHandler handler = createInjector().getInstance(DelegatingErrorHandler.class); + assertEquals(handler.getClientErrorHandler().getClass(), + CloseContentAndSetExceptionErrorHandler.class); + } + + @Test + void testClientRetryHandler() { + DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); + assertEquals(handler.getClientErrorRetryHandler(), HttpRetryHandler.NEVER_RETRY); + } + + @Test + void testRedirectionRetryHandler() { + DelegatingRetryHandler handler = createInjector().getInstance(DelegatingRetryHandler.class); + assertEquals(handler.getRedirectionRetryHandler().getClass(), RedirectionRetryHandler.class); + } + +} \ No newline at end of file diff --git a/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseStatusesFromJsonResponseTest.java b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseStatusesFromJsonResponseTest.java new file mode 100644 index 0000000000..c0e0e6678b --- /dev/null +++ b/gogrid/src/test/java/org/jclouds/gogrid/functions/ParseStatusesFromJsonResponseTest.java @@ -0,0 +1,96 @@ +/** + * + * Copyright (C) 2010 Cloud Conscious, LLC. + * + * ==================================================================== + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF 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.gogrid.functions; + +import static org.testng.Assert.assertEquals; + +import java.io.InputStream; +import java.net.URI; +import java.net.UnknownHostException; +import java.util.Arrays; +import java.util.Date; +import java.util.SortedSet; + +import com.google.common.collect.Iterables; +import org.jclouds.gogrid.config.GoGridContextModule; +import org.jclouds.gogrid.domain.*; +import org.jclouds.http.functions.config.ParserModule; +import org.jclouds.date.DateService; +import org.jclouds.date.internal.SimpleDateFormatDateService; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableSortedSet; +import com.google.gson.Gson; +import com.google.inject.Guice; +import com.google.inject.Injector; + +/** + * Tests behavior of {@code ParseStatusesFromJsonResponse} + * + * @author Adrian Cole + */ +@Test(groups = "unit", testName = "twitter.ParseStatusesFromJsonResponseTest") +public class ParseStatusesFromJsonResponseTest { + + Injector i = Guice.createInjector(new ParserModule() { + @Override + protected void configure() { + bind(DateAdapter.class).to(GoGridContextModule.DateSecondsAdapter.class); + super.configure(); + } + }); + DateService dateService = new SimpleDateFormatDateService(); + + public void testApplyInputStreamDetails() throws UnknownHostException { + InputStream is = getClass().getResourceAsStream("/test_get_server_list.json"); + + ParseServerListFromJsonResponse parser = new ParseServerListFromJsonResponse(i + .getInstance(Gson.class)); + SortedSet response = parser.apply(is); + + Option centOs = new Option(13L, "CentOS 5.2 (32-bit)", "CentOS 5.2 (32-bit)"); + Option webServer = new Option(1L, "Web Server", "Web or Application Server"); + Server server = new Server(75245L, false, "PowerServer", "server to test the api. created by Alex", + new Option(1L, "On", "Server is in active state."), + webServer, + new Option(1L, "512MB", "Server with 512MB RAM"), + centOs, + new Ip(1313079L, "204.51.240.178", "204.51.240.176/255.255.255.240", false, + new Option(2L, "Assigned", "IP is reserved or in use")), + new ServerImage(1946L, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", + "BitNami Gallery 2.3.1-0", "http://bitnami.org/stack/gallery", + centOs, null, webServer, + new Option(2L, "Available", "Image is available for adds"), + 0.0, "24732/GSI-f8979644-e646-4711-ad58-d98a5fa3612c.img", + true, true, + new Date(1261504577971L), + new Date(1262649582180L), + Arrays.asList( + new BillingToken(38L, "CentOS 5.2 32bit", 0.0), + new BillingToken(56L, "BitNami: Gallery", 0.0) + ), + new Customer(24732L, "BitRock"))); + assertEquals(Iterables.getOnlyElement(response), server); + } +} diff --git a/gogrid/src/test/resources/log4j.xml b/gogrid/src/test/resources/log4j.xml index 6e388b9373..8557b4b8f3 100644 --- a/gogrid/src/test/resources/log4j.xml +++ b/gogrid/src/test/resources/log4j.xml @@ -2,7 +2,7 @@