You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jclouds.apache.org by na...@apache.org on 2015/11/02 12:43:19 UTC
[3/5] jclouds-labs git commit: Remove DigitalOcean v1
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/handlers/DigitalOceanErrorHandler.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/handlers/DigitalOceanErrorHandler.java b/digitalocean/src/main/java/org/jclouds/digitalocean/handlers/DigitalOceanErrorHandler.java
deleted file mode 100644
index e223e51..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/handlers/DigitalOceanErrorHandler.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.digitalocean.handlers;
-
-import javax.inject.Singleton;
-
-import org.jclouds.http.HttpCommand;
-import org.jclouds.http.HttpErrorHandler;
-import org.jclouds.http.HttpResponse;
-import org.jclouds.http.HttpResponseException;
-import org.jclouds.rest.AuthorizationException;
-import org.jclouds.rest.ResourceNotFoundException;
-
-/**
- * Parse the errors in the response and propagate an appropriate exception.
- *
- *
- * @see org.jclouds.digitalocean.http.ResponseStatusFromPayloadHttpCommandExecutorService
- */
-@Singleton
-public class DigitalOceanErrorHandler implements HttpErrorHandler {
-
- @Override
- public void handleError(HttpCommand command, HttpResponse response) {
- Exception exception = null;
-
- try {
- // The response message is already properly populated by the
- // ResponseStatusFromPayloadHttpCommandExecutorService
- switch (response.getStatusCode()) {
- case 401:
- exception = new AuthorizationException(response.getMessage(), exception);
- break;
- case 404:
- exception = new ResourceNotFoundException(response.getMessage(), exception);
- break;
- default:
- exception = new HttpResponseException(response.getMessage(), command, response);
- break;
- }
- } finally {
- command.setException(exception);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/http/ResponseStatusFromPayloadHttpCommandExecutorService.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/http/ResponseStatusFromPayloadHttpCommandExecutorService.java b/digitalocean/src/main/java/org/jclouds/digitalocean/http/ResponseStatusFromPayloadHttpCommandExecutorService.java
deleted file mode 100644
index 997709c..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/http/ResponseStatusFromPayloadHttpCommandExecutorService.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * 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.digitalocean.http;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static org.jclouds.io.Payloads.newInputStreamPayload;
-import static org.jclouds.util.Closeables2.closeQuietly;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.net.HttpURLConnection;
-import java.net.Proxy;
-import java.net.URI;
-
-import javax.inject.Inject;
-import javax.inject.Named;
-import javax.inject.Singleton;
-import javax.net.ssl.HostnameVerifier;
-import javax.net.ssl.SSLContext;
-
-import org.jclouds.digitalocean.domain.BaseResponse;
-import org.jclouds.digitalocean.domain.BaseResponse.Status;
-import org.jclouds.http.HttpResponse;
-import org.jclouds.http.HttpUtils;
-import org.jclouds.http.IOExceptionRetryHandler;
-import org.jclouds.http.functions.ParseJson;
-import org.jclouds.http.handlers.DelegatingErrorHandler;
-import org.jclouds.http.handlers.DelegatingRetryHandler;
-import org.jclouds.http.internal.HttpWire;
-import org.jclouds.http.internal.JavaUrlHttpCommandExecutorService;
-import org.jclouds.io.ContentMetadataCodec;
-import org.jclouds.io.Payload;
-
-import com.google.common.base.Function;
-import com.google.common.base.Supplier;
-import com.google.common.io.ByteStreams;
-
-/**
- * Custom implementation of the HTTP driver to read the response body in order to get the real response status.
- * <p>
- * The DigitalOcean API always return 200 codes even if a request failed due to some internal error, but populates an
- * <code>ERROR</code> string in the response payload.
- * <p>
- * This class will read the body of the response and populate a 500 status code if an error is found.
- */
-@Singleton
-public class ResponseStatusFromPayloadHttpCommandExecutorService extends JavaUrlHttpCommandExecutorService {
-
- public static final String ACCESS_DENIED = "Access Denied";
- public static final String NOT_FOUND = "Not Found";
-
- private final ParseJson<BaseResponse> errorParser;
-
- @Inject
- ResponseStatusFromPayloadHttpCommandExecutorService(HttpUtils utils, ContentMetadataCodec contentMetadataCodec,
- DelegatingRetryHandler retryHandler, IOExceptionRetryHandler ioRetryHandler,
- DelegatingErrorHandler errorHandler, HttpWire wire, @Named("untrusted") HostnameVerifier verifier,
- @Named("untrusted") Supplier<SSLContext> untrustedSSLContextProvider, Function<URI, Proxy> proxyForURI,
- ParseJson<BaseResponse> errorParser) throws SecurityException, NoSuchFieldException {
- super(utils, contentMetadataCodec, retryHandler, ioRetryHandler, errorHandler, wire, verifier,
- untrustedSSLContextProvider, proxyForURI);
- this.errorParser = checkNotNull(errorParser, "errorParser cannot be null");
- }
-
- @Override
- protected HttpResponse invoke(HttpURLConnection connection) throws IOException, InterruptedException {
- HttpResponse original = super.invoke(connection);
- HttpResponse.Builder<?> response = original.toBuilder();
-
- if (hasPayload(original)) {
- // As we need to read the response body to determine if there are errors, but we may need to process the body
- // again later in the response parsers if everything is OK, we buffer the body into an InputStream we can reset
- InputStream in = null;
- InputStream originalInputStream = original.getPayload().openStream();
-
- if (originalInputStream instanceof ByteArrayInputStream) {
- in = originalInputStream;
- } else {
- try {
- in = new ByteArrayInputStream(ByteStreams.toByteArray(originalInputStream));
- } finally {
- closeQuietly(originalInputStream);
- }
- }
-
- // Process the payload and look for errors
- BaseResponse responseContent = errorParser.apply(in);
- if (responseContent != null && responseContent.getStatus() == Status.ERROR) {
- // Yes, this is ugly, but the DigitalOcean API sometimes sets the status code to 200 for these errors and
- // the only way to know what happened is parsing the error message
- String message = responseContent.getMessage();
- if (ACCESS_DENIED.equals(message)) {
- response.statusCode(401);
- } else if (NOT_FOUND.equals(message)) {
- response.statusCode(404);
- } else {
- response.statusCode(500);
- }
- response.message(responseContent.getDetails());
- }
-
- // Reset the input stream and set the payload, so it can be read again
- // by the response and error parsers
- in.reset();
- Payload payload = newInputStreamPayload(in);
- contentMetadataCodec.fromHeaders(payload.getContentMetadata(), original.getHeaders());
- response.payload(payload);
- }
-
- return response.build();
- }
-
- private static boolean hasPayload(final HttpResponse response) {
- return response.getPayload() != null && response.getPayload().getRawContent() != null;
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/http/filters/AuthenticationFilter.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/http/filters/AuthenticationFilter.java b/digitalocean/src/main/java/org/jclouds/digitalocean/http/filters/AuthenticationFilter.java
deleted file mode 100644
index a1dae73..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/http/filters/AuthenticationFilter.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * 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.digitalocean.http.filters;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.jclouds.domain.Credentials;
-import org.jclouds.http.HttpException;
-import org.jclouds.http.HttpRequest;
-import org.jclouds.http.HttpRequestFilter;
-import org.jclouds.location.Provider;
-
-import com.google.common.base.Supplier;
-
-/**
- * Adds the authentication query parameters to the requests.
- */
-@Singleton
-public class AuthenticationFilter implements HttpRequestFilter {
-
- public static final String IDENTITY_PARAM = "client_id";
- public static final String CREDENTIAL_PARAM = "api_key";
-
- private final Supplier<Credentials> credentials;
-
- @Inject
- AuthenticationFilter(@Provider final Supplier<Credentials> credentials) {
- this.credentials = checkNotNull(credentials, "credential supplier cannot be null");
- }
-
- @Override
- public HttpRequest filter(HttpRequest request) throws HttpException {
- Credentials creds = credentials.get();
- return request.toBuilder().addQueryParam(IDENTITY_PARAM, creds.identity)
- .addQueryParam(CREDENTIAL_PARAM, creds.credential).build();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/predicates/SameFingerprint.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/predicates/SameFingerprint.java b/digitalocean/src/main/java/org/jclouds/digitalocean/predicates/SameFingerprint.java
deleted file mode 100644
index f7d414a..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/predicates/SameFingerprint.java
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- * 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.digitalocean.predicates;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-
-import java.security.PublicKey;
-import java.security.interfaces.DSAPublicKey;
-import java.security.interfaces.RSAPublicKey;
-
-import org.jclouds.digitalocean.domain.SshKey;
-import org.jclouds.digitalocean.ssh.DSAKeys;
-import org.jclouds.ssh.SshKeys;
-
-import com.google.common.base.Predicate;
-
-/**
- * Predicate to compare SSH keys by fingerprint.
- */
-public class SameFingerprint implements Predicate<SshKey> {
-
- public final String fingerprint;
-
- public SameFingerprint(PublicKey key) {
- this.fingerprint = computeFingerprint(checkNotNull(key, "key cannot be null"));
- }
-
- @Override
- public boolean apply(SshKey key) {
- checkNotNull(key, "key cannot be null");
- checkNotNull(key.getPublicKey(), "public key cannot be null");
- return fingerprint.equals(computeFingerprint(key.getPublicKey()));
- }
-
- public static String computeFingerprint(PublicKey key) {
- if (key instanceof RSAPublicKey) {
- RSAPublicKey rsaKey = (RSAPublicKey) key;
- return SshKeys.fingerprint(rsaKey.getPublicExponent(), rsaKey.getModulus());
- } else if (key instanceof DSAPublicKey) {
- DSAPublicKey dsaKey = (DSAPublicKey) key;
- return DSAKeys.fingerprint(dsaKey.getParams().getP(), dsaKey.getParams().getQ(), dsaKey.getParams().getG(),
- dsaKey.getY());
- } else {
- throw new IllegalArgumentException("Only RSA and DSA keys are supported");
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/ssh/DSAKeys.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/ssh/DSAKeys.java b/digitalocean/src/main/java/org/jclouds/digitalocean/ssh/DSAKeys.java
deleted file mode 100644
index c13750c..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/ssh/DSAKeys.java
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * 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.digitalocean.ssh;
-
-import static com.google.common.base.Joiner.on;
-import static com.google.common.base.Preconditions.checkArgument;
-import static com.google.common.base.Splitter.fixedLength;
-import static com.google.common.base.Throwables.propagate;
-import static com.google.common.collect.Iterables.get;
-import static com.google.common.collect.Iterables.size;
-import static com.google.common.io.BaseEncoding.base16;
-import static com.google.common.io.BaseEncoding.base64;
-import static org.jclouds.util.Strings2.toStringAndClose;
-
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.math.BigInteger;
-import java.security.interfaces.DSAParams;
-import java.security.interfaces.DSAPublicKey;
-import java.security.spec.DSAPublicKeySpec;
-
-import com.google.common.base.Charsets;
-import com.google.common.base.Splitter;
-import com.google.common.hash.HashCode;
-import com.google.common.hash.Hashing;
-import com.google.common.io.ByteSource;
-import com.google.common.io.ByteStreams;
-
-/**
- * Utility methods to work with DSA SSH keys.
- * <p>
- * Methods in this class should be moved to the {@link org.jclouds.ssh.SshKeys} class.
- *
- *
- * @see org.jclouds.ssh.SshKeys
- */
-public class DSAKeys {
-
- public static String encodeAsOpenSSH(DSAPublicKey key) {
- DSAParams params = key.getParams();
- byte[] keyBlob = keyBlob(params.getP(), params.getQ(), params.getG(), key.getY());
- return "ssh-dss " + base64().encode(keyBlob);
- }
-
- /**
- * Executes {@link org.jclouds.crypto.Pems#publicKeySpecFromOpenSSH(com.google.common.io.InputSupplier)} on the
- * string which was OpenSSH Base64 Encoded {@code id_rsa.pub}
- *
- * @param idRsaPub formatted {@code ssh-dss AAAAB3NzaC1yc2EAAAADAQABAAAB...}
- * @see org.jclouds.crypto.Pems#publicKeySpecFromOpenSSH(com.google.common.io.InputSupplier)
- */
- public static DSAPublicKeySpec publicKeySpecFromOpenSSH(String idDsaPub) {
- try {
- return publicKeySpecFromOpenSSH(ByteSource.wrap(idDsaPub.getBytes(Charsets.UTF_8)));
- } catch (IOException e) {
- throw propagate(e);
- }
- }
-
- /**
- * Returns {@link DSAPublicKeySpec} which was OpenSSH Base64 Encoded {@code id_rsa.pub}
- *
- * @param supplier the input stream factory, formatted {@code ssh-dss AAAAB3NzaC1yc2EAAAADAQABAAAB...}
- *
- * @return the {@link DSAPublicKeySpec} which was OpenSSH Base64 Encoded {@code id_rsa.pub}
- * @throws IOException if an I/O error occurs
- */
- public static DSAPublicKeySpec publicKeySpecFromOpenSSH(ByteSource supplier) throws IOException {
- InputStream stream = supplier.openStream();
- Iterable<String> parts = Splitter.on(' ').split(toStringAndClose(stream).trim());
- checkArgument(size(parts) >= 2 && "ssh-dss".equals(get(parts, 0)), "bad format, should be: ssh-dss AAAAB3...");
- stream = new ByteArrayInputStream(base64().decode(get(parts, 1)));
- String marker = new String(readLengthFirst(stream));
- checkArgument("ssh-dss".equals(marker), "looking for marker ssh-dss but got %s", marker);
- BigInteger p = new BigInteger(readLengthFirst(stream));
- BigInteger q = new BigInteger(readLengthFirst(stream));
- BigInteger g = new BigInteger(readLengthFirst(stream));
- BigInteger y = new BigInteger(readLengthFirst(stream));
- return new DSAPublicKeySpec(y, p, q, g);
- }
-
- /**
- * @param publicKeyOpenSSH RSA public key in OpenSSH format
- * @return fingerprint ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9}
- */
- public static String fingerprintPublicKey(String publicKeyOpenSSH) {
- DSAPublicKeySpec publicKeySpec = publicKeySpecFromOpenSSH(publicKeyOpenSSH);
- return fingerprint(publicKeySpec.getP(), publicKeySpec.getQ(), publicKeySpec.getG(), publicKeySpec.getY());
- }
-
- /**
- * Create a fingerprint per the following <a href="http://tools.ietf.org/html/draft-friedl-secsh-fingerprint-00"
- * >spec</a>
- *
- * @return hex fingerprint ex. {@code 2b:a9:62:95:5b:8b:1d:61:e0:92:f7:03:10:e9:db:d9}
- */
- public static String fingerprint(BigInteger p, BigInteger q, BigInteger g, BigInteger y) {
- byte[] keyBlob = keyBlob(p, q, g, y);
- return hexColonDelimited(Hashing.md5().hashBytes(keyBlob));
- }
-
- /**
- * @see org.jclouds.ssh.SshKeys
- */
- private static String hexColonDelimited(HashCode hc) {
- return on(':').join(fixedLength(2).split(base16().lowerCase().encode(hc.asBytes())));
- }
-
- /**
- * @see org.jclouds.ssh.SshKeys
- */
- private static byte[] keyBlob(BigInteger p, BigInteger q, BigInteger g, BigInteger y) {
- try {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- writeLengthFirst("ssh-dss".getBytes(), out);
- writeLengthFirst(p.toByteArray(), out);
- writeLengthFirst(q.toByteArray(), out);
- writeLengthFirst(g.toByteArray(), out);
- writeLengthFirst(y.toByteArray(), out);
- return out.toByteArray();
- } catch (IOException e) {
- throw propagate(e);
- }
- }
-
- /**
- * @see org.jclouds.ssh.SshKeys
- */
- // http://www.ietf.org/rfc/rfc4253.txt
- private static byte[] readLengthFirst(InputStream in) throws IOException {
- int byte1 = in.read();
- int byte2 = in.read();
- int byte3 = in.read();
- int byte4 = in.read();
- int length = (byte1 << 24) + (byte2 << 16) + (byte3 << 8) + (byte4 << 0);
- byte[] val = new byte[length];
- ByteStreams.readFully(in, val);
- return val;
- }
-
- /**
- * @see org.jclouds.ssh.SshKeys
- */
- // http://www.ietf.org/rfc/rfc4253.txt
- private static void writeLengthFirst(byte[] array, ByteArrayOutputStream out) throws IOException {
- out.write(array.length >>> 24 & 0xFF);
- out.write(array.length >>> 16 & 0xFF);
- out.write(array.length >>> 8 & 0xFF);
- out.write(array.length >>> 0 & 0xFF);
- if (array.length == 1 && array[0] == (byte) 0x00) {
- out.write(new byte[0]);
- } else {
- out.write(array);
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/main/java/org/jclouds/digitalocean/strategy/ListSshKeys.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/main/java/org/jclouds/digitalocean/strategy/ListSshKeys.java b/digitalocean/src/main/java/org/jclouds/digitalocean/strategy/ListSshKeys.java
deleted file mode 100644
index a51cb60..0000000
--- a/digitalocean/src/main/java/org/jclouds/digitalocean/strategy/ListSshKeys.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.digitalocean.strategy;
-
-import static com.google.common.base.Preconditions.checkNotNull;
-import static com.google.common.collect.Iterables.transform;
-import static com.google.common.util.concurrent.Futures.allAsList;
-import static com.google.common.util.concurrent.Futures.getUnchecked;
-
-import java.util.List;
-import java.util.concurrent.Callable;
-
-import javax.inject.Inject;
-import javax.inject.Singleton;
-
-import org.jclouds.digitalocean.DigitalOceanApi;
-import org.jclouds.digitalocean.domain.SshKey;
-import org.jclouds.digitalocean.features.KeyPairApi;
-
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.ListeningExecutorService;
-import com.google.inject.assistedinject.Assisted;
-
-/**
- * The {@link org.jclouds.digitalocean.features.KeyPairApi} only returns the id and name of each key but not the actual
- * public key when listing all keys.
- * <p>
- * This strategy provides a helper to get all the keys with all details populated.
- */
-@Singleton
-public class ListSshKeys {
-
- public interface Factory {
- ListSshKeys create(ListeningExecutorService executor);
- }
-
- private final KeyPairApi keyPairApi;
- private final ListeningExecutorService executor;
-
- @Inject
- ListSshKeys(DigitalOceanApi api, @Assisted ListeningExecutorService executor) {
- checkNotNull(api, "api cannot be null");
- this.executor = checkNotNull(executor, "executor cannot be null");
- this.keyPairApi = api.getKeyPairApi();
- }
-
- public List<SshKey> execute() {
- List<SshKey> keys = keyPairApi.list();
-
- ListenableFuture<List<SshKey>> futures = allAsList(transform(keys,
- new Function<SshKey, ListenableFuture<SshKey>>() {
- @Override
- public ListenableFuture<SshKey> apply(final SshKey input) {
- return executor.submit(new Callable<SshKey>() {
- @Override
- public SshKey call() throws Exception {
- return keyPairApi.get(input.getId());
- }
- });
- }
- }));
-
- return getUnchecked(futures);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/DigitalOceanProviderMetadataTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/DigitalOceanProviderMetadataTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/DigitalOceanProviderMetadataTest.java
deleted file mode 100644
index 1354055..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/DigitalOceanProviderMetadataTest.java
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * 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.digitalocean;
-
-import org.jclouds.providers.internal.BaseProviderMetadataTest;
-import org.testng.annotations.Test;
-
-/**
- * Unit tests for the {@link DigitalOceanApiMetadata}.
- */
-@Test(groups = "unit", testName = "DigitalOceanProviderMetadataTest")
-public class DigitalOceanProviderMetadataTest extends BaseProviderMetadataTest {
-
- public DigitalOceanProviderMetadataTest() {
- super(new DigitalOceanProviderMetadata(), new DigitalOceanApiMetadata());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/compute/DigitalOceanComputeServiceLiveTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/DigitalOceanComputeServiceLiveTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/DigitalOceanComputeServiceLiveTest.java
deleted file mode 100644
index d52eacf..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/DigitalOceanComputeServiceLiveTest.java
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * 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.digitalocean.compute;
-
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.internal.BaseComputeServiceLiveTest;
-import org.jclouds.sshj.config.SshjSshClientModule;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.inject.Module;
-
-/**
- * Live tests for the {@link org.jclouds.compute.ComputeService} integration.
- */
-@Test(groups = "live", singleThreaded = true, testName = "DigitalOceanComputeServiceLiveTest")
-public class DigitalOceanComputeServiceLiveTest extends BaseComputeServiceLiveTest {
-
- public DigitalOceanComputeServiceLiveTest() {
- provider = "digitalocean";
- }
-
- @Override
- protected Module getSshModule() {
- return new SshjSshClientModule();
- }
-
- @Override
- public void testOptionToNotBlock() throws Exception {
- // DigitalOcean ComputeService implementation has to block until the node
- // is provisioned, to be able to return it.
- }
-
- @Override
- protected void checkTagsInNodeEquals(NodeMetadata node, ImmutableSet<String> tags) {
- // DigitalOcean does not support tags
- }
-
- @Override
- protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap<String, String> userMetadata) {
- // DigitalOcean does not support user metadata
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/compute/DigitalOceanImageExtensionLiveTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/DigitalOceanImageExtensionLiveTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/DigitalOceanImageExtensionLiveTest.java
deleted file mode 100644
index 56179b3..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/DigitalOceanImageExtensionLiveTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * 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.digitalocean.compute;
-
-import org.jclouds.compute.extensions.internal.BaseImageExtensionLiveTest;
-import org.jclouds.sshj.config.SshjSshClientModule;
-import org.testng.annotations.Test;
-
-import com.google.inject.Module;
-
-/**
- * Live tests for the {@link org.jclouds.compute.extensions.ImageExtension} integration.
- */
-@Test(groups = "live", singleThreaded = true, testName = "DigitalOceanImageExtensionLiveTest")
-public class DigitalOceanImageExtensionLiveTest extends BaseImageExtensionLiveTest {
-
- public DigitalOceanImageExtensionLiveTest() {
- provider = "digitalocean";
- }
-
- @Override
- protected Module getSshModule() {
- return new SshjSshClientModule();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/compute/config/EventDonePredicateTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/config/EventDonePredicateTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/config/EventDonePredicateTest.java
deleted file mode 100644
index 70ac19e..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/config/EventDonePredicateTest.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/*
- * 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.digitalocean.compute.config;
-
-import static org.easymock.EasyMock.anyInt;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-import static org.testng.Assert.fail;
-
-import org.easymock.EasyMock;
-import org.jclouds.digitalocean.DigitalOceanApi;
-import org.jclouds.digitalocean.compute.config.DigitalOceanComputeServiceContextModule.EventDonePredicate;
-import org.jclouds.digitalocean.domain.Event;
-import org.jclouds.digitalocean.domain.Event.Status;
-import org.jclouds.digitalocean.features.EventApi;
-import org.testng.annotations.Test;
-
-/**
- * Unit tests for the {@link EventDonePredicate} class.
- */
-@Test(groups = "unit", testName = "EventDonePredicateTest")
-public class EventDonePredicateTest {
-
- public void testEventProgress() {
- EventApi eventApi = EasyMock.createMock(EventApi.class);
- DigitalOceanApi api = EasyMock.createMock(DigitalOceanApi.class);
-
- expect(eventApi.get(1)).andReturn(event(Status.DONE));
- expect(eventApi.get(2)).andReturn(event(Status.PENDING));
- expect(api.getEventApi()).andReturn(eventApi).times(2);
- replay(eventApi, api);
-
- EventDonePredicate predicate = new EventDonePredicate(api);
- assertTrue(predicate.apply(1));
- assertFalse(predicate.apply(2));
- }
-
- public void testEventFailed() {
- EventApi eventApi = EasyMock.createMock(EventApi.class);
- DigitalOceanApi api = EasyMock.createMock(DigitalOceanApi.class);
-
- expect(eventApi.get(anyInt())).andReturn(event(Status.ERROR));
- expect(api.getEventApi()).andReturn(eventApi);
- replay(eventApi, api);
-
- EventDonePredicate predicate = new EventDonePredicate(api);
-
- try {
- predicate.apply(1);
- fail("Method should have thrown an IllegalStateException");
- } catch (IllegalStateException ex) {
- assertEquals(ex.getMessage(), "Resource is in invalid status: ERROR");
- }
- }
-
- private static Event event(Status status) {
- return new Event(0, status, 0, "0", 0);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletStatusToStatusTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletStatusToStatusTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletStatusToStatusTest.java
deleted file mode 100644
index deddcee..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletStatusToStatusTest.java
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * 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.digitalocean.compute.functions;
-
-import static org.jclouds.compute.domain.NodeMetadata.Status.UNRECOGNIZED;
-import static org.testng.Assert.assertNotEquals;
-
-import org.jclouds.digitalocean.domain.Droplet.Status;
-import org.testng.annotations.Test;
-
-/**
- * Unit tests for the {@link DropletStatusToStatus} class.
- */
-@Test(groups = "unit", testName = "DropletStatusToStatusTest")
-public class DropletStatusToStatusTest {
-
- @Test
- public void testAllStatesHaveMapping() {
- DropletStatusToStatus function = new DropletStatusToStatus();
- for (Status status : Status.values()) {
- assertNotEquals(function.apply(status), UNRECOGNIZED);
- }
-
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletToNodeMetadataTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletToNodeMetadataTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletToNodeMetadataTest.java
deleted file mode 100644
index d55854b..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/DropletToNodeMetadataTest.java
+++ /dev/null
@@ -1,198 +0,0 @@
-/*
- * 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.digitalocean.compute.functions;
-
-import static com.google.common.collect.Iterables.getOnlyElement;
-import static org.jclouds.compute.domain.Image.Status.AVAILABLE;
-import static org.jclouds.compute.domain.NodeMetadata.Status.RUNNING;
-import static org.jclouds.digitalocean.domain.Droplet.Status.ACTIVE;
-import static org.testng.Assert.assertEquals;
-
-import java.text.ParseException;
-import java.util.Date;
-import java.util.Map;
-import java.util.Set;
-
-import org.jclouds.compute.domain.Hardware;
-import org.jclouds.compute.domain.HardwareBuilder;
-import org.jclouds.compute.domain.Image;
-import org.jclouds.compute.domain.ImageBuilder;
-import org.jclouds.compute.domain.NodeMetadata;
-import org.jclouds.compute.domain.NodeMetadataBuilder;
-import org.jclouds.compute.domain.OperatingSystem;
-import org.jclouds.compute.domain.OsFamily;
-import org.jclouds.compute.domain.Processor;
-import org.jclouds.compute.domain.Volume.Type;
-import org.jclouds.compute.domain.VolumeBuilder;
-import org.jclouds.compute.functions.GroupNamingConvention;
-import org.jclouds.digitalocean.DigitalOceanApiMetadata;
-import org.jclouds.digitalocean.domain.Droplet;
-import org.jclouds.domain.Credentials;
-import org.jclouds.domain.Location;
-import org.jclouds.domain.LocationBuilder;
-import org.jclouds.domain.LocationScope;
-import org.jclouds.domain.LoginCredentials;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Function;
-import com.google.common.base.Supplier;
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-import com.google.common.collect.ImmutableSet;
-import com.google.common.collect.Maps;
-import com.google.inject.AbstractModule;
-import com.google.inject.Guice;
-import com.google.inject.name.Names;
-
-/**
- * Unit tests for the {@link DropletToNodeMetadata} class.
- */
-@Test(groups = "unit", testName = "DropletToNodeMetadataTest")
-public class DropletToNodeMetadataTest {
-
- private Set<Hardware> hardwares;
-
- private Set<Image> images;
-
- private Set<Location> locations;
-
- private LoginCredentials credentials;
-
- private DropletToNodeMetadata function;
-
- @BeforeMethod
- public void setup() {
- images = ImmutableSet.of(new ImageBuilder()
- .id("ubuntu-1404-x86")
- .providerId("1")
- .name("mock image")
- .status(AVAILABLE)
- .operatingSystem(
- OperatingSystem.builder().name("Ubuntu 14.04 x86_64").description("Ubuntu").family(OsFamily.UBUNTU)
- .version("10.04").arch("x86_64").is64Bit(true).build()).build());
-
- hardwares = ImmutableSet.of(new HardwareBuilder().id("2gb").providerId("1").name("mock hardware")
- .processor(new Processor(1.0, 1.0)).ram(2048)
- .volume(new VolumeBuilder().size(20f).type(Type.LOCAL).build()).build());
-
- locations = ImmutableSet.of(new LocationBuilder()
- .id("1")
- .description("1/mock location")
- .scope(LocationScope.REGION)
- .parent(
- new LocationBuilder().id("0").description("mock parent location").scope(LocationScope.PROVIDER)
- .build()).build());
-
- credentials = LoginCredentials.builder().user("foo").password("bar").build();
-
- function = createNodeParser(hardwares, images, locations, ImmutableMap.of("node#1", (Credentials) credentials));
- }
-
- @Test
- public void testConvertDroplet() throws ParseException {
- Droplet droplet = new Droplet(1, "mock-droplet", 1, 1, 1, false, ImmutableList.of(), ImmutableList.of(),
- "84.45.69.3", "192.168.2.5", false, ACTIVE, new Date());
-
- NodeMetadata expected = new NodeMetadataBuilder().ids("1").hardware(getOnlyElement(hardwares))
- .imageId("ubuntu-1404-x86").status(RUNNING).location(getOnlyElement(locations)).name("mock-droplet")
- .hostname("mock-droplet").group("mock").credentials(credentials)
- .publicAddresses(ImmutableSet.of("84.45.69.3")).privateAddresses(ImmutableSet.of("192.168.2.5"))
- .providerId("1").backendStatus(ACTIVE.name()).operatingSystem(getOnlyElement(images).getOperatingSystem())
- .build();
-
- NodeMetadata actual = function.apply(droplet);
- assertNodeEquals(actual, expected);
- }
-
- @Test
- public void testConvertDropletOldImage() throws ParseException {
- // Use an image id that is not in the list of images
- Droplet droplet = new Droplet(1, "mock-droplet", 9999, 1, 1, false, ImmutableList.of(), ImmutableList.of(),
- "84.45.69.3", "192.168.2.5", false, ACTIVE, new Date());
-
- NodeMetadata expected = new NodeMetadataBuilder().ids("1").hardware(getOnlyElement(hardwares)).imageId(null)
- .status(RUNNING).location(getOnlyElement(locations)).name("mock-droplet").hostname("mock-droplet")
- .group("mock").credentials(credentials).publicAddresses(ImmutableSet.of("84.45.69.3"))
- .privateAddresses(ImmutableSet.of("192.168.2.5")).providerId("1").backendStatus(ACTIVE.name())
- .operatingSystem(null).build();
-
- NodeMetadata actual = function.apply(droplet);
- assertNodeEquals(actual, expected);
- }
-
- private static void assertNodeEquals(NodeMetadata actual, NodeMetadata expected) {
- assertEquals(actual, expected);
- // NodeMetadata equals method does not use all fields in equals. It assumes that same ids in same locations
- // determine the equivalence
- assertEquals(actual.getStatus(), expected.getStatus());
- assertEquals(actual.getBackendStatus(), expected.getBackendStatus());
- assertEquals(actual.getLoginPort(), expected.getLoginPort());
- assertEquals(actual.getPublicAddresses(), expected.getPublicAddresses());
- assertEquals(actual.getPrivateAddresses(), expected.getPrivateAddresses());
- assertEquals(actual.getCredentials(), expected.getCredentials());
- assertEquals(actual.getGroup(), expected.getGroup());
- assertEquals(actual.getImageId(), expected.getImageId());
- assertEquals(actual.getHardware(), expected.getHardware());
- assertEquals(actual.getOperatingSystem(), expected.getOperatingSystem());
- assertEquals(actual.getHostname(), expected.getHostname());
- }
-
- private DropletToNodeMetadata createNodeParser(final Set<Hardware> hardware, final Set<Image> images,
- final Set<Location> locations, Map<String, Credentials> credentialStore) {
- Supplier<Set<? extends Location>> locationSupplier = new Supplier<Set<? extends Location>>() {
- @Override
- public Set<? extends Location> get() {
- return locations;
- }
- };
-
- Supplier<Map<String, ? extends Hardware>> hardwareSupplier = new Supplier<Map<String, ? extends Hardware>>() {
- @Override
- public Map<String, ? extends Hardware> get() {
- return Maps.uniqueIndex(hardware, new Function<Hardware, String>() {
- @Override
- public String apply(Hardware input) {
- return input.getId();
- }
- });
- }
- };
-
- Supplier<Map<String, ? extends Image>> imageSupplier = new Supplier<Map<String, ? extends Image>>() {
- @Override
- public Map<String, ? extends Image> get() {
- return Maps.uniqueIndex(images, new Function<Image, String>() {
- @Override
- public String apply(Image input) {
- return input.getId();
- }
- });
- }
- };
-
- GroupNamingConvention.Factory namingConvention = Guice.createInjector(new AbstractModule() {
- @Override
- protected void configure() {
- Names.bindProperties(binder(), new DigitalOceanApiMetadata().getDefaultProperties());
- }
- }).getInstance(GroupNamingConvention.Factory.class);
-
- return new DropletToNodeMetadata(imageSupplier, hardwareSupplier, locationSupplier, new DropletStatusToStatus(),
- namingConvention, credentialStore);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/ImageToImageTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/ImageToImageTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/ImageToImageTest.java
deleted file mode 100644
index 0c00b57..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/ImageToImageTest.java
+++ /dev/null
@@ -1,58 +0,0 @@
-/*
- * 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.digitalocean.compute.functions;
-
-import static org.jclouds.compute.domain.Image.Status.AVAILABLE;
-import static org.testng.Assert.assertEquals;
-
-import org.jclouds.compute.domain.ImageBuilder;
-import org.jclouds.compute.domain.OperatingSystem;
-import org.jclouds.compute.domain.OsFamily;
-import org.jclouds.digitalocean.domain.Image;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableList;
-import com.google.common.collect.ImmutableMap;
-
-/**
- * Unit tests for the {@link ImageToImage} class.
- */
-@Test(groups = "unit", testName = "ImageToImageTest")
-public class ImageToImageTest {
-
- @Test
- public void testConvertImage() {
- Image image = new Image(1, "14.04 x64", "Ubuntu", true, "ubuntu-1404-x86", ImmutableList.<Integer> of(),
- ImmutableList.<String> of());
- org.jclouds.compute.domain.Image expected = new ImageBuilder()
- .id("ubuntu-1404-x86")
- .providerId("1")
- .name("14.04 x64")
- .description("Ubuntu 14.04 x64")
- .status(AVAILABLE)
- .operatingSystem(
- OperatingSystem.builder().name("Ubuntu").description("Ubuntu 14.04 x64").family(OsFamily.UBUNTU)
- .version("14.04").arch("x64").is64Bit(true).build())
- .userMetadata(ImmutableMap.of("publicImage", "true")).build();
-
- org.jclouds.compute.domain.Image result = new ImageToImage().apply(image);
- assertEquals(result, expected);
- assertEquals(result.getDescription(), expected.getDescription());
- assertEquals(result.getOperatingSystem(), expected.getOperatingSystem());
- assertEquals(result.getStatus(), expected.getStatus());
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/RegionToLocationTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/RegionToLocationTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/RegionToLocationTest.java
deleted file mode 100644
index 17a3fb3..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/RegionToLocationTest.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/*
- * 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.digitalocean.compute.functions;
-
-import static com.google.common.collect.Iterables.getOnlyElement;
-import static org.testng.Assert.assertEquals;
-
-import java.net.URI;
-
-import org.jclouds.digitalocean.DigitalOceanProviderMetadata;
-import org.jclouds.digitalocean.domain.Region;
-import org.jclouds.domain.Location;
-import org.jclouds.domain.LocationBuilder;
-import org.jclouds.domain.LocationScope;
-import org.jclouds.location.suppliers.all.JustProvider;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Suppliers;
-import com.google.common.collect.ImmutableSet;
-
-/**
- * Unit tests for the {@link RegionToLocation} class.
- */
-@Test(groups = "unit", testName = "RegionToLocationTest")
-public class RegionToLocationTest {
-
- @Test
- public void testConvertRegion() {
- DigitalOceanProviderMetadata metadata = new DigitalOceanProviderMetadata();
- JustProvider locationsSupplier = new JustProvider(metadata.getId(), Suppliers.<URI> ofInstance(URI
- .create(metadata.getEndpoint())), ImmutableSet.<String> of());
-
- Region region = new Region(1, "Region 1", "reg1");
- Location expected = new LocationBuilder().id("reg1").description("1/Region 1")
- .parent(getOnlyElement(locationsSupplier.get())).scope(LocationScope.REGION).build();
-
- RegionToLocation function = new RegionToLocation(locationsSupplier);
- assertEquals(function.apply(region), expected);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/SizeToHardwareTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/SizeToHardwareTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/SizeToHardwareTest.java
deleted file mode 100644
index eaf9a45..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/SizeToHardwareTest.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * 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.digitalocean.compute.functions;
-
-import static org.testng.Assert.assertEquals;
-
-import org.jclouds.compute.domain.Hardware;
-import org.jclouds.compute.domain.HardwareBuilder;
-import org.jclouds.compute.domain.Processor;
-import org.jclouds.compute.domain.Volume.Type;
-import org.jclouds.compute.domain.VolumeBuilder;
-import org.jclouds.digitalocean.domain.Size;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableMap;
-
-/**
- * Unit tests for the {@link SizeToHardware} class.
- */
-@Test(groups = "unit", testName = "SizeToHardwareTest")
-public class SizeToHardwareTest {
-
- @Test
- public void testConvertSize() {
- Size size = new Size(1, "Medium", "2gb", 2048, 1, 20, "0.05", "10");
- Hardware expected = new HardwareBuilder().id("2gb").providerId("1").name("Medium")
- .processor(new Processor(1.0, 1.0)).ram(2048)
- .volume(new VolumeBuilder().size(20f).type(Type.LOCAL).build())
- .userMetadata(ImmutableMap.of("costPerHour", "0.05", "costPerMonth", "10")).build();
-
- SizeToHardware function = new SizeToHardware();
- assertEquals(function.apply(size), expected);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/TemplateOptionsToStatementWithoutPublicKeyTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/TemplateOptionsToStatementWithoutPublicKeyTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/TemplateOptionsToStatementWithoutPublicKeyTest.java
deleted file mode 100644
index 20e6714..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/functions/TemplateOptionsToStatementWithoutPublicKeyTest.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * 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.digitalocean.compute.functions;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertNull;
-import static org.testng.Assert.assertTrue;
-
-import java.util.Map;
-
-import org.jclouds.compute.options.TemplateOptions;
-import org.jclouds.scriptbuilder.domain.OsFamily;
-import org.jclouds.scriptbuilder.domain.Statement;
-import org.jclouds.scriptbuilder.domain.StatementList;
-import org.jclouds.scriptbuilder.statements.ssh.InstallRSAPrivateKey;
-import org.jclouds.ssh.SshKeys;
-import org.testng.annotations.Test;
-
-/**
- * Unit tests for the {@link TemplateOptionsToStatementWithoutPublicKey} class.
- */
-@Test(groups = "unit", testName = "TemplateOptionsToStatementWithoutPublicKeyTest")
-public class TemplateOptionsToStatementWithoutPublicKeyTest {
-
- @Test
- public void testPublicKeyDoesNotGenerateAuthorizePublicKeyStatementIfOnlyPublicKeyOptionsConfigured() {
- Map<String, String> keys = SshKeys.generate();
- TemplateOptions options = TemplateOptions.Builder.authorizePublicKey(keys.get("public"));
-
- TemplateOptionsToStatementWithoutPublicKey function = new TemplateOptionsToStatementWithoutPublicKey();
- assertNull(function.apply(options));
- }
-
- @Test
- public void testPublicAndRunScriptKeyDoesNotGenerateAuthorizePublicKeyStatementIfRunScriptPresent() {
- Map<String, String> keys = SshKeys.generate();
- TemplateOptions options = TemplateOptions.Builder.authorizePublicKey(keys.get("public")).runScript("uptime");
-
- TemplateOptionsToStatementWithoutPublicKey function = new TemplateOptionsToStatementWithoutPublicKey();
- Statement statement = function.apply(options);
-
- assertEquals(statement.render(OsFamily.UNIX), "uptime\n");
- }
-
- @Test
- public void testPublicAndPrivateKeyAndRunScriptDoesNotGenerateAuthorizePublicKeyStatementIfOtherOptionsPresent() {
- Map<String, String> keys = SshKeys.generate();
- TemplateOptions options = TemplateOptions.Builder.authorizePublicKey(keys.get("public"))
- .installPrivateKey(keys.get("private")).runScript("uptime");
-
- TemplateOptionsToStatementWithoutPublicKey function = new TemplateOptionsToStatementWithoutPublicKey();
- Statement statement = function.apply(options);
-
- assertTrue(statement instanceof StatementList);
- StatementList statements = (StatementList) statement;
-
- assertEquals(statements.size(), 2);
- assertEquals(statements.get(0).render(OsFamily.UNIX), "uptime\n");
- assertTrue(statements.get(1) instanceof InstallRSAPrivateKey);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/compute/options/DigitalOceanTemplateOptionsTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/options/DigitalOceanTemplateOptionsTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/options/DigitalOceanTemplateOptionsTest.java
deleted file mode 100644
index de60c5e..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/options/DigitalOceanTemplateOptionsTest.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/*
- * 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.digitalocean.compute.options;
-
-import static org.testng.Assert.assertEquals;
-
-import org.jclouds.compute.options.TemplateOptions;
-import org.testng.annotations.Test;
-
-import com.google.common.collect.ImmutableSet;
-
-/**
- * Unit tests for the {@link DigitalOceanTemplateOptions} class.
- */
-@Test(groups = "unit", testName = "DigitalOceanTemplateOptionsTest")
-public class DigitalOceanTemplateOptionsTest {
-
- @Test
- public void testSShKeyIds() {
- TemplateOptions options = new DigitalOceanTemplateOptions().sshKeyIds(ImmutableSet.of(1, 2, 3));
- assertEquals(options.as(DigitalOceanTemplateOptions.class).getSshKeyIds(), ImmutableSet.of(1, 2, 3));
- }
-
- @Test
- public void testPrivateNetworking() {
- TemplateOptions options = new DigitalOceanTemplateOptions().privateNetworking(true);
- assertEquals(options.as(DigitalOceanTemplateOptions.class).getPrivateNetworking(), Boolean.TRUE);
- }
-
- @Test
- public void testBackupsEnabled() {
- TemplateOptions options = new DigitalOceanTemplateOptions().backupsEnabled(true);
- assertEquals(options.as(DigitalOceanTemplateOptions.class).getBackupsEnabled(), Boolean.TRUE);
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/compute/util/LocationNamingUtilsTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/util/LocationNamingUtilsTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/compute/util/LocationNamingUtilsTest.java
deleted file mode 100644
index 9f9a0b1..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/compute/util/LocationNamingUtilsTest.java
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- * 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.digitalocean.compute.util;
-
-import static org.jclouds.digitalocean.compute.util.LocationNamingUtils.encodeRegionIdAndName;
-import static org.jclouds.digitalocean.compute.util.LocationNamingUtils.extractRegionId;
-import static org.jclouds.digitalocean.compute.util.LocationNamingUtils.extractRegionName;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.fail;
-
-import org.jclouds.digitalocean.domain.Region;
-import org.jclouds.domain.Location;
-import org.jclouds.domain.LocationBuilder;
-import org.jclouds.domain.LocationScope;
-import org.testng.annotations.Test;
-
-/**
- * Unit tests for the {@link LocationNamingUtils} class.
- */
-@Test(groups = "unit", testName = "LocationNamingUtilsTest")
-public class LocationNamingUtilsTest {
-
- @Test
- public void testExtractRegionId() {
- assertEquals(1, extractRegionId(location("1/foo")));
- assertEquals(1, extractRegionId(location("1///foo")));
- assertEquals(1, extractRegionId(location("1/2/3/foo")));
- }
-
- @Test
- public void testExtractRegionIdInvalidEncodedForms() {
- assertInvalidRegionIdFormat("/");
- assertInvalidRegionIdFormat("/foo");
- assertInvalidRegionIdFormat("/1/2/foo");
- }
-
- @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "location cannot be null")
- public void testExtractRegionIdNullLocation() {
- extractRegionId(null);
- }
-
- @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "location description should be in the form 'regionId/regionName' but was: foobar")
- public void testExtractRegionIdWithoutEncodedForm() {
- extractRegionId(location("foobar"));
- }
-
- @Test
- public void testExtractRegionName() {
- assertEquals("foo", extractRegionName(location("1/foo")));
- assertEquals("//foo", extractRegionName(location("1///foo")));
- assertEquals("2/3/foo", extractRegionName(location("1/2/3/foo")));
- }
-
- @Test
- public void testExtractRegionNameInvalidEncodedForms() {
- assertEquals("", extractRegionName(location("/")));
- assertEquals("foo", extractRegionName(location("/foo")));
- assertEquals("1/2/foo", extractRegionName(location("/1/2/foo")));
- }
-
- @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "location cannot be null")
- public void testExtractRegionNameNullLocation() {
- extractRegionId(null);
- }
-
- @Test(expectedExceptions = IllegalArgumentException.class, expectedExceptionsMessageRegExp = "location description should be in the form 'regionId/regionName' but was: foobar")
- public void testExtractRegionNameWithoutEncodedForm() {
- extractRegionId(location("foobar"));
- }
-
- @Test(expectedExceptions = NullPointerException.class, expectedExceptionsMessageRegExp = "region cannot be null")
- public void testEncodeRegionAndNameNullRegion() {
- encodeRegionIdAndName(null);
- }
-
- @Test
- public void testEncodeRegionAndName() {
- assertEquals("1/foo", encodeRegionIdAndName(new Region(1, "foo", "bar")));
- assertEquals("1/1", encodeRegionIdAndName(new Region(1, "1", "1")));
- assertEquals("1///", encodeRegionIdAndName(new Region(1, "//", "1")));
- }
-
- private static void assertInvalidRegionIdFormat(String encoded) {
- try {
- extractRegionId(location(encoded));
- fail("Encoded form [" + encoded + "] shouldn't produce a valid region id");
- } catch (NumberFormatException ex) {
- // Success
- }
- }
-
- private static Location location(String description) {
- return new LocationBuilder().id("location").description(description).scope(LocationScope.REGION).build();
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/domain/OperatingSystemTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/domain/OperatingSystemTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/domain/OperatingSystemTest.java
deleted file mode 100644
index fcd33ad..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/domain/OperatingSystemTest.java
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * 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.digitalocean.domain;
-
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertTrue;
-
-import org.testng.annotations.Test;
-
-/**
- * Unit tests for the {@link OperatingSystem} class.
- */
-@Test(groups = "unit", testName = "OperatingSystemTest")
-public class OperatingSystemTest {
-
- public void testParseStandard64bit() {
- OperatingSystem os = OperatingSystem.builder().from("12.10 x64", "Ubuntu").build();
-
- assertEquals(os.getDistribution(), Distribution.UBUNTU);
- assertEquals(os.getVersion(), "12.10");
- assertEquals(os.getArch(), "x64");
- assertTrue(os.is64bit());
- }
-
- public void testLongVersionStandard64bit() {
- OperatingSystem os = OperatingSystem.builder().from("12.10.1 x64", "Ubuntu").build();
-
- assertEquals(os.getDistribution(), Distribution.UBUNTU);
- assertEquals(os.getVersion(), "12.10.1");
- assertEquals(os.getArch(), "x64");
- assertTrue(os.is64bit());
- }
-
- public void testParseStandard64bitWithPrefix() {
- OperatingSystem os = OperatingSystem.builder().from("Arch Linux 12.10 x64 Desktop", "Arch Linux").build();
-
- assertEquals(os.getDistribution(), Distribution.ARCHLINUX);
- assertEquals(os.getVersion(), "12.10");
- assertEquals(os.getArch(), "x64");
- assertTrue(os.is64bit());
- }
-
- public void testParseStandard() {
- OperatingSystem os = OperatingSystem.builder().from("12.10 x32", "Ubuntu").build();
-
- assertEquals(os.getDistribution(), Distribution.UBUNTU);
- assertEquals(os.getVersion(), "12.10");
- assertEquals(os.getArch(), "x32");
- assertFalse(os.is64bit());
-
- os = OperatingSystem.builder().from("6.5 x64", "CentOS").build();
-
- assertEquals(os.getDistribution(), Distribution.CENTOS);
- assertEquals(os.getVersion(), "6.5");
- assertEquals(os.getArch(), "x64");
- assertTrue(os.is64bit());
-
- os = OperatingSystem.builder().from("6.5 x64", "Centos").build();
-
- assertEquals(os.getDistribution(), Distribution.CENTOS);
- assertEquals(os.getVersion(), "6.5");
- assertEquals(os.getArch(), "x64");
- assertTrue(os.is64bit());
- }
-
- public void testParseNoArch() {
- OperatingSystem os = OperatingSystem.builder().from("12.10", "Ubuntu").build();
-
- assertEquals(os.getDistribution(), Distribution.UBUNTU);
- assertEquals(os.getVersion(), "12.10");
- assertEquals(os.getArch(), "");
- assertFalse(os.is64bit());
- }
-
- public void testParseNoVersion() {
- OperatingSystem os = OperatingSystem.builder().from("x64", "Ubuntu").build();
-
- assertEquals(os.getDistribution(), Distribution.UBUNTU);
- assertEquals(os.getVersion(), "");
- assertEquals(os.getArch(), "x64");
- assertTrue(os.is64bit());
- }
-
- public void testParseUnknownDistribution() {
- OperatingSystem os = OperatingSystem.builder().from("12.04 x64", "Foo").build();
-
- assertEquals(os.getDistribution(), Distribution.UNRECOGNIZED);
- assertEquals(os.getVersion(), "12.04");
- assertEquals(os.getArch(), "x64");
- assertTrue(os.is64bit());
- }
-}
http://git-wip-us.apache.org/repos/asf/jclouds-labs/blob/114b3528/digitalocean/src/test/java/org/jclouds/digitalocean/features/DropletApiLiveTest.java
----------------------------------------------------------------------
diff --git a/digitalocean/src/test/java/org/jclouds/digitalocean/features/DropletApiLiveTest.java b/digitalocean/src/test/java/org/jclouds/digitalocean/features/DropletApiLiveTest.java
deleted file mode 100644
index e1f1cf7..0000000
--- a/digitalocean/src/test/java/org/jclouds/digitalocean/features/DropletApiLiveTest.java
+++ /dev/null
@@ -1,205 +0,0 @@
-/*
- * 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.digitalocean.features;
-
-import static com.google.common.collect.Iterables.tryFind;
-import static org.testng.Assert.assertEquals;
-import static org.testng.Assert.assertFalse;
-import static org.testng.Assert.assertNotNull;
-import static org.testng.Assert.assertTrue;
-
-import java.util.List;
-
-import org.jclouds.digitalocean.domain.Droplet;
-import org.jclouds.digitalocean.domain.DropletCreation;
-import org.jclouds.digitalocean.domain.Image;
-import org.jclouds.digitalocean.domain.Size;
-import org.jclouds.digitalocean.internal.BaseDigitalOceanLiveTest;
-import org.testng.annotations.AfterClass;
-import org.testng.annotations.Test;
-
-import com.google.common.base.Optional;
-import com.google.common.base.Predicate;
-
-/**
- * Live tests for the {@link DropletApi} class.
- */
-@Test(groups = "live", testName = "DropletApiLiveTest")
-public class DropletApiLiveTest extends BaseDigitalOceanLiveTest {
-
- private DropletCreation dropletCreation;
- private DropletCreation dropletCreationUsingSlugs;
- private Droplet droplet;
- private Droplet dropletUsingSlugs;
- private Image snapshot;
-
- @Override
- protected void initialize() {
- super.initialize();
- initializeImageSizeAndRegion();
- }
-
- @AfterClass
- public void cleanup() {
- if (droplet != null) {
- int event = api.getDropletApi().destroy(droplet.getId(), true);
- assertTrue(event > 0, "The event id should not be null");
- }
- if (dropletUsingSlugs != null) {
- int event = api.getDropletApi().destroy(dropletUsingSlugs.getId(), true);
- assertTrue(event > 0, "The event id should not be null");
- }
- if (snapshot != null) {
- api.getImageApi().delete(snapshot.getId());
- }
- }
-
- public void testCreateDroplet() {
- dropletCreation = api.getDropletApi().create("droplettest", defaultImage.getId(), defaultSize.getId(),
- defaultRegion.getId());
-
- assertTrue(dropletCreation.getId() > 0, "Created droplet id should be > 0");
- assertTrue(dropletCreation.getEventId() > 0, "Droplet creation event id should be > 0");
- }
-
- public void testCreateDropletUsingSlugs() {
- dropletCreationUsingSlugs = api.getDropletApi().create("droplettestwithslugs", defaultImage.getSlug(),
- defaultSize.getSlug(), defaultRegion.getSlug());
-
- assertTrue(dropletCreationUsingSlugs.getId() > 0, "Created droplet id should be > 0");
- assertTrue(dropletCreationUsingSlugs.getEventId() > 0, "Droplet creation event id should be > 0");
- }
-
- @Test(dependsOnMethods = { "testCreateDroplet", "testCreateDropletUsingSlugs" })
- public void testGetDroplet() {
- waitForEvent(dropletCreation.getEventId());
- waitForEvent(dropletCreationUsingSlugs.getEventId());
-
- droplet = api.getDropletApi().get(dropletCreation.getId());
- dropletUsingSlugs = api.getDropletApi().get(dropletCreationUsingSlugs.getId());
-
- assertNotNull(droplet, "Created droplet should not be null");
- assertNotNull(dropletUsingSlugs, "Created droplet using slugs should not be null");
- }
-
- @Test(dependsOnMethods = "testGetDroplet")
- public void testListDroplets() {
- List<Droplet> droplets = api.getDropletApi().list();
-
- assertFalse(droplets.isEmpty(), "Droplet list should not be empty");
- }
-
- @Test(dependsOnMethods = "testGetDroplet")
- public void testPowerOffDroplet() {
- int event = api.getDropletApi().powerOff(droplet.getId());
- assertTrue(event > 0, "The event id should be > 0");
- waitForEvent(event);
- }
-
- @Test(dependsOnMethods = "testPowerOffDroplet")
- public void testPowerOnDroplet() {
- int event = api.getDropletApi().powerOn(droplet.getId());
- assertTrue(event > 0, "The event id should be > 0");
- waitForEvent(event);
- }
-
- @Test(dependsOnMethods = "testPowerOnDroplet")
- public void testRebootDroplet() {
- int event = api.getDropletApi().reboot(droplet.getId());
- assertTrue(event > 0, "The event id should be > 0");
- waitForEvent(event);
- }
-
- @Test(dependsOnMethods = "testRebootDroplet")
- public void testPowerCycleDroplet() {
- int event = api.getDropletApi().powerCycle(droplet.getId());
- assertTrue(event > 0, "The event id should be > 0");
- waitForEvent(event);
- }
-
- @Test(dependsOnMethods = "testPowerCycleDroplet")
- public void testResetPasswordForDroplet() {
- int event = api.getDropletApi().resetPassword(droplet.getId());
- assertTrue(event > 0, "The event id should be > 0");
- waitForEvent(event);
- }
-
- @Test(dependsOnMethods = "testResetPasswordForDroplet")
- public void testRenameDroplet() {
- int event = api.getDropletApi().rename(droplet.getId(), "droplettestupdated");
- assertTrue(event > 0, "The event id should be > 0");
- waitForEvent(event);
- droplet = api.getDropletApi().get(droplet.getId());
- assertEquals(droplet.getName(), "droplettestupdated", "The renamed droplet should have the new name");
- }
-
- @Test(dependsOnMethods = "testRenameDroplet")
- public void testRebuildDroplet() {
- int event = api.getDropletApi().rebuild(droplet.getId(), defaultImage.getId());
- assertTrue(event > 0, "The event id should be > 0");
- waitForEvent(event);
- }
-
- @Test(dependsOnMethods = "testRebuildDroplet")
- public void testRestoreDroplet() {
- int event = api.getDropletApi().restore(droplet.getId(), defaultImage.getId());
- assertTrue(event > 0, "The event id should be > 0");
- waitForEvent(event);
- }
-
- @Test(dependsOnMethods = "testRestoreDroplet")
- public void testSnapshotDroplet() {
- // Snapshot requires the droplet to be powered off
- int powerOffEvent = api.getDropletApi().powerOff(droplet.getId());
- assertTrue(powerOffEvent > 0, "The event id should be > 0");
- waitForEvent(powerOffEvent);
-
- int event = api.getDropletApi().snapshot(droplet.getId(), "testsnapshot");
- assertTrue(event > 0, "The event id should be > 0");
- waitForEvent(event);
-
- Optional<Image> snapshot = tryFind(api.getImageApi().list(), new Predicate<Image>() {
- @Override
- public boolean apply(Image input) {
- return input.getName().equals("testsnapshot");
- }
- });
-
- assertTrue(snapshot.isPresent(), "The created snapshot should exist in the image list");
- this.snapshot = snapshot.get();
- }
-
- @Test(dependsOnMethods = "testSnapshotDroplet")
- public void testResizeDroplet() {
- // Resize requires the droplet to be powered off
- int powerOffEvent = api.getDropletApi().powerOff(droplet.getId());
- assertTrue(powerOffEvent > 0, "The event id should be > 0");
- waitForEvent(powerOffEvent);
-
- Size newSize = sizes.get(1);
- int resizeEvent = api.getDropletApi().resize(droplet.getId(), newSize.getId());
- assertTrue(resizeEvent > 0, "The event id should be > 0");
- waitForEvent(resizeEvent);
- }
-
- @Test(dependsOnMethods = "testResizeDroplet")
- public void testShutdownDroplet() {
- int event = api.getDropletApi().shutdown(droplet.getId());
- assertTrue(event > 0, "The event id should be > 0");
- waitForEvent(event);
- }
-}