http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaApiTest.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaApiTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaApiTest.java deleted file mode 100644 index 4dfcb45..0000000 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaApiTest.java +++ /dev/null @@ -1,644 +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.cloudsigma; - -import static org.jclouds.reflect.Reflection2.method; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; - -import org.jclouds.Fallbacks.NullOnNotFoundOr404; -import org.jclouds.Fallbacks.VoidOnNotFoundOr404; -import org.jclouds.apis.ApiMetadata; -import org.jclouds.cloudsigma.binders.BindServerToPlainTextStringTest; -import org.jclouds.cloudsigma.domain.CreateDriveRequest; -import org.jclouds.cloudsigma.domain.Drive; -import org.jclouds.cloudsigma.domain.DriveData; -import org.jclouds.cloudsigma.domain.Server; -import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInfo; -import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToProfileInfo; -import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToServerInfo; -import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToStaticIPInfo; -import org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToVLANInfo; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToStaticIPInfoSet; -import org.jclouds.cloudsigma.functions.ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSet; -import org.jclouds.cloudsigma.functions.SplitNewlines; -import org.jclouds.cloudsigma.functions.SplitNewlinesAndReturnSecondField; -import org.jclouds.cloudsigma.options.CloneDriveOptions; -import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.filters.BasicAuthentication; -import org.jclouds.http.functions.ReleasePayloadAndReturn; -import org.jclouds.rest.internal.BaseAsyncClientTest; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Iterables; -import com.google.common.reflect.Invokable; -/** - * Tests behavior of {@code CloudSigmaApi} - */ -// NOTE:without testName, this will not call @Before* and fail w/NPE during surefire -@Test(groups = "unit", testName = "CloudSigmaApiTest") -public class CloudSigmaApiTest extends BaseAsyncClientTest<CloudSigmaApi> { - - public void testGetProfileInfo() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "getProfileInfo"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/profile/info HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToProfileInfo.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testListStandardDrives() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "listStandardDrives"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/standard/list HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(httpRequest); - } - - public void testListStandardCds() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "listStandardCds"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/standard/cd/list HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(httpRequest); - } - - public void testListStandardImages() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "listStandardImages"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/standard/img/list HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(httpRequest); - } - - public void testListDriveInfo() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "listDriveInfo"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/info HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ListOfKeyValuesDelimitedByBlankLinesToDriveInfoSet.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(httpRequest); - } - - public void testGetDriveInfo() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "getDriveInfo", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("uuid")); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/uuid/info HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testCreateDrive() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "createDrive", Drive.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of( - new CreateDriveRequest.Builder().name("foo").use(ImmutableList.of("production", "candy")).size(10000l) - .build())); - - assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/create HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, "name foo\nsize 10000\nuse production candy", "text/plain", false); - - assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testCloneDrive() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "cloneDrive", String.class, String.class, - CloneDriveOptions[].class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("sourceid", "newname")); - - assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/sourceid/clone HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, "name newname", "text/plain", false); - - assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); - - checkFilters(httpRequest); - - } - - public void testCloneDriveOptions() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "cloneDrive", String.class, String.class, - CloneDriveOptions[].class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("sourceid", "newname", - new CloneDriveOptions().size(1024l))); - - assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/sourceid/clone HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, "name newname\nsize 1024", "text/plain", false); - - assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); - - checkFilters(httpRequest); - - } - - public void testSetDriveData() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "setDriveData", String.class, DriveData.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("100", new DriveData.Builder().name("foo").size(10000l) - .use(ImmutableList.of("production", "candy")).build())); - - assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/drives/100/set HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, "name foo\nsize 10000\nuse production candy", "text/plain", false); - - assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToDriveInfo.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); - - checkFilters(httpRequest); - - } - - public void testListServers() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "listServers"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/servers/list HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - // now make sure request filters apply by replaying - httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/servers/list HTTP/1.1"); - // for example, using basic authentication, we should get "only one" - // header - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n"); - assertPayloadEquals(httpRequest, null, null, false); - - // TODO: insert expected response class, which probably extends ParseJson - assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(httpRequest); - - } - - public void testListServerInfo() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "listServerInfo"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/servers/info HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ListOfKeyValuesDelimitedByBlankLinesToServerInfoSet.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(httpRequest); - } - - public void testGetServerInfo() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "getServerInfo", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("uuid")); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/servers/uuid/info HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToServerInfo.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testCreateServer() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "createServer", Server.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of(BindServerToPlainTextStringTest.SERVER)); - - assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/create HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, BindServerToPlainTextStringTest.CREATED_SERVER, "text/plain", false); - - assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToServerInfo.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testSetServerConfiguration() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "setServerConfiguration", String.class, Server.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("100", BindServerToPlainTextStringTest.SERVER)); - - assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/100/set HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, BindServerToPlainTextStringTest.CREATED_SERVER, "text/plain", false); - - assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToServerInfo.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testDestroyServer() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "destroyServer", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("uuid")); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/servers/uuid/destroy HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testStartServer() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "startServer", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("uuid")); - - assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/uuid/start HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); - - checkFilters(httpRequest); - - } - - public void testStopServer() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "stopServer", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("uuid")); - - assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/uuid/stop HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); - - checkFilters(httpRequest); - - } - - public void testShutdownServer() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "shutdownServer", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("uuid")); - - assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/uuid/shutdown HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); - - checkFilters(httpRequest); - - } - - public void testResetServer() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "resetServer", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("uuid")); - - assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/servers/uuid/reset HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); - - checkFilters(httpRequest); - - } - - public void testListDrives() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "listDrives"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/list HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - // now make sure request filters apply by replaying - httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/list HTTP/1.1"); - // for example, using basic authentication, we should get "only one" - // header - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n"); - assertPayloadEquals(httpRequest, null, null, false); - - // TODO: insert expected response class, which probably extends ParseJson - assertResponseParserClassEquals(method, httpRequest, SplitNewlines.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(httpRequest); - - } - - public void testDestroyDrive() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "destroyDrive", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("uuid")); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/drives/uuid/destroy HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testListVLANs() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "listVLANs"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/vlan/list HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - // now make sure request filters apply by replaying - httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/vlan/list HTTP/1.1"); - // for example, using basic authentication, we should get "only one" - // header - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n"); - assertPayloadEquals(httpRequest, null, null, false); - - // TODO: insert expected response class, which probably extends ParseJson - assertResponseParserClassEquals(method, httpRequest, SplitNewlinesAndReturnSecondField.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(httpRequest); - - } - - public void testListVLANInfo() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "listVLANInfo"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/vlan/info HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ListOfKeyValuesDelimitedByBlankLinesToVLANInfoSet.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(httpRequest); - } - - public void testGetVLANInfo() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "getVLANInfo", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("uuid")); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/vlan/uuid/info HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToVLANInfo.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testCreateVLAN() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "createVLAN", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("poohbear")); - - assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/resources/vlan/create HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, "name poohbear\n", "text/plain", false); - - assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToVLANInfo.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testRenameVLAN() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "renameVLAN", String.class, String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("100", "poohbear")); - - assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/resources/vlan/100/set HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, "name poohbear\n", "text/plain", false); - - assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToVLANInfo.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); - - checkFilters(httpRequest); - - } - - public void testDestroyVLAN() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "destroyVLAN", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("uuid")); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/vlan/uuid/destroy HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testListStaticIPs() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "listStaticIPs"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/ip/list HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - // now make sure request filters apply by replaying - httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - httpRequest = (GeneratedHttpRequest) Iterables.getOnlyElement(httpRequest.getFilters()).filter(httpRequest); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/ip/list HTTP/1.1"); - // for example, using basic authentication, we should get "only one" - // header - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\nAuthorization: Basic aWRlbnRpdHk6Y3JlZGVudGlhbA==\n"); - assertPayloadEquals(httpRequest, null, null, false); - - // TODO: insert expected response class, which probably extends ParseJson - assertResponseParserClassEquals(method, httpRequest, SplitNewlinesAndReturnSecondField.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(httpRequest); - - } - - public void testListStaticIPInfo() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "listStaticIPInfo"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/ip/info HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ListOfKeyValuesDelimitedByBlankLinesToStaticIPInfoSet.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, null); - - checkFilters(httpRequest); - } - - public void testGetStaticIPInfo() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "getStaticIPInfo", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("uuid")); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/ip/uuid/info HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToStaticIPInfo.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testCreateStaticIP() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "createStaticIP"); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.of()); - - assertRequestLineEquals(httpRequest, "POST https://api.cloudsigma.com/resources/ip/create HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, KeyValuesDelimitedByBlankLinesToStaticIPInfo.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, NullOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - public void testDestroyStaticIP() throws SecurityException, NoSuchMethodException, IOException { - Invokable<?, ?> method = method(CloudSigmaApi.class, "destroyStaticIP", String.class); - GeneratedHttpRequest httpRequest = processor.createRequest(method, ImmutableList.<Object> of("uuid")); - - assertRequestLineEquals(httpRequest, "GET https://api.cloudsigma.com/resources/ip/uuid/destroy HTTP/1.1"); - assertNonPayloadHeadersEqual(httpRequest, "Accept: text/plain\n"); - assertPayloadEquals(httpRequest, null, null, false); - - assertResponseParserClassEquals(method, httpRequest, ReleasePayloadAndReturn.class); - assertSaxResponseParserClassEquals(method, null); - assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); - - checkFilters(httpRequest); - - } - - @Override - protected void checkFilters(HttpRequest request) { - assertEquals(request.getFilters().size(), 1); - assertEquals(request.getFilters().get(0).getClass(), BasicAuthentication.class); - } - - @Override - protected ApiMetadata createApiMetadata() { - return new CloudSigmaApiMetadata(); - } - -}
http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java deleted file mode 100644 index f3c59eb..0000000 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/CloudSigmaClientLiveTest.java +++ /dev/null @@ -1,441 +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.cloudsigma; -import static java.util.concurrent.TimeUnit.SECONDS; -import static org.jclouds.util.Predicates2.retry; -import static org.testng.Assert.assertEquals; -import static org.testng.Assert.assertNotNull; - -import java.io.IOException; -import java.util.Set; -import java.util.logging.Logger; - -import org.jclouds.cloudsigma.domain.ClaimType; -import org.jclouds.cloudsigma.domain.CreateDriveRequest; -import org.jclouds.cloudsigma.domain.DriveData; -import org.jclouds.cloudsigma.domain.DriveInfo; -import org.jclouds.cloudsigma.domain.DriveStatus; -import org.jclouds.cloudsigma.domain.DriveType; -import org.jclouds.cloudsigma.domain.IDEDevice; -import org.jclouds.cloudsigma.domain.Model; -import org.jclouds.cloudsigma.domain.ProfileInfo; -import org.jclouds.cloudsigma.domain.Server; -import org.jclouds.cloudsigma.domain.ServerInfo; -import org.jclouds.cloudsigma.domain.ServerStatus; -import org.jclouds.cloudsigma.domain.StaticIPInfo; -import org.jclouds.cloudsigma.domain.VLANInfo; -import org.jclouds.cloudsigma.options.CloneDriveOptions; -import org.jclouds.cloudsigma.predicates.DriveClaimed; -import org.jclouds.cloudsigma.util.Servers; -import org.jclouds.compute.domain.ExecResponse; -import org.jclouds.compute.internal.BaseComputeServiceContextLiveTest; -import org.jclouds.domain.LoginCredentials; -import org.jclouds.predicates.SocketOpen; -import org.jclouds.ssh.SshClient; -import org.jclouds.sshj.config.SshjSshClientModule; -import org.testng.annotations.AfterGroups; -import org.testng.annotations.BeforeGroups; -import org.testng.annotations.Test; - -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.common.net.HostAndPort; -import com.google.gson.Gson; -import com.google.inject.Guice; - -/** - * Tests behavior of {@code CloudSigmaApi} - */ -@Test(groups = "live", singleThreaded = true, testName = "CloudSigmaClientLiveTest") -public class CloudSigmaClientLiveTest extends BaseComputeServiceContextLiveTest { - - public CloudSigmaClientLiveTest() { - provider = "cloudsigma"; - } - - protected long driveSize = 8 * 1024 * 1024 * 1024l; - protected int maxDriveImageTime = 300; - protected String vncPassword = "Il0veVNC"; - protected CloudSigmaApi client; - protected Predicate<HostAndPort> socketTester; - - protected Predicate<DriveInfo> driveNotClaimed; - protected String imageId; - - @BeforeGroups(groups = { "integration", "live" }) - @Override - public void setupContext() { - super.setupContext(); - - client = view.utils().injector().getInstance(CloudSigmaApi.class); - driveNotClaimed = retry(Predicates.not(new DriveClaimed(client)), maxDriveImageTime, 1, SECONDS); - SocketOpen socketOpten = context.utils().injector().getInstance(SocketOpen.class); - socketTester = retry(socketOpten, maxDriveImageTime, 1, SECONDS); - - if (template == null || template.getImageId() == null) { - imageId = view.getComputeService().templateBuilder().build().getImage().getId(); - } - } - - @Test - public void testGetProfileInfo() throws Exception { - ProfileInfo profile = client.getProfileInfo(); - assertNotNull(profile); - } - - @Test - public void testListVLANs() throws Exception { - Set<String> vlans = client.listVLANs(); - assertNotNull(vlans); - } - - @Test - public void testListVLANInfo() throws Exception { - Set<? extends VLANInfo> vlans = client.listVLANInfo(); - assertNotNull(vlans); - } - - @Test - public void testGetVLAN() throws Exception { - for (String vlanUUID : client.listVLANs()) { - assert !"".equals(vlanUUID); - assertNotNull(client.getVLANInfo(vlanUUID)); - } - } - - @Test - public void testListStaticIPs() throws Exception { - Set<String> ips = client.listStaticIPs(); - assertNotNull(ips); - } - - @Test - public void testListStaticIPInfo() throws Exception { - Set<? extends StaticIPInfo> ips = client.listStaticIPInfo(); - assertNotNull(ips); - } - - @Test - public void testGetStaticIP() throws Exception { - for (String ipUUID : client.listStaticIPs()) { - assert !"".equals(ipUUID); - assertNotNull(client.getStaticIPInfo(ipUUID)); - } - } - - @Test - public void testListServers() throws Exception { - Set<String> servers = client.listServers(); - assertNotNull(servers); - } - - @Test - public void testListServerInfo() throws Exception { - Set<? extends ServerInfo> servers = client.listServerInfo(); - assertNotNull(servers); - } - - @Test - public void testGetServer() throws Exception { - for (String serverUUID : client.listServers()) { - assert !"".equals(serverUUID); - assertNotNull(client.getServerInfo(serverUUID)); - } - } - - @Test - public void testListDrives() throws Exception { - Set<String> drives = client.listDrives(); - assertNotNull(drives); - } - - @Test - public void testListDriveInfo() throws Exception { - Set<? extends DriveInfo> drives = client.listDriveInfo(); - assertNotNull(drives); - } - - @Test - public void testGetDrive() throws Exception { - for (String driveUUID : client.listStandardDrives()) { - assert !"".equals(driveUUID); - DriveInfo drive = client.getDriveInfo(driveUUID); - assertNotNull(drive); - assert !drive.getType().equals(DriveType.UNRECOGNIZED) : drive; - if (drive.getType() == DriveType.DISK && drive.getDriveType().contains("preinstalled")) - System.out.println(drive.getName()); - } - } - - protected String prefix = System.getProperty("user.name") + ".test"; - protected DriveInfo drive; - - @Test - public void testCreateDrive() throws Exception { - drive = client.createDrive(new CreateDriveRequest.Builder().name(prefix).size(driveSize).build()); - checkCreatedDrive(); - - DriveInfo newInfo = client.getDriveInfo(drive.getUuid()); - checkDriveMatchesGet(newInfo); - - } - - protected void checkDriveMatchesGet(DriveInfo newInfo) { - assertEquals(newInfo.getUuid(), drive.getUuid()); - assertEquals(newInfo.getType(), DriveType.DISK); - } - - protected void checkCreatedDrive() { - assertNotNull(drive.getUuid()); - assertNotNull(drive.getUser()); - assertEquals(drive.getName(), prefix); - assertEquals(drive.getSize(), driveSize); - assertEquals(drive.getStatus(), DriveStatus.ACTIVE); - // for some reason, these occasionally return as 4096,1 - // assertEquals(info.getReadBytes(), 0l); - // assertEquals(info.getWriteBytes(), 0l); - // assertEquals(info.getReadRequests(), 0l); - // assertEquals(info.getWriteRequests(), 0l); - assertEquals(drive.getEncryptionCipher(), "aes-xts-plain"); - assertEquals(drive.getType(), null); - } - - @Test(dependsOnMethods = "testCreateDrive") - public void testSetDriveData() throws Exception { - - DriveInfo drive2 = client.setDriveData( - drive.getUuid(), - new DriveData.Builder().claimType(ClaimType.SHARED).name("rediculous") - .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff")) - .use(ImmutableSet.of("networking", "security", "gateway")).build()); - - assertNotNull(drive2.getUuid(), drive.getUuid()); - assertEquals(drive2.getName(), "rediculous"); - assertEquals(drive2.getClaimType(), ClaimType.SHARED); - assertEquals(drive2.getReaders(), ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff")); - assertEquals(drive2.getUse(), ImmutableSet.of("networking", "security", "gateway")); - drive = drive2; - } - - @Test - public void testCreateAndDestroyVLAN() throws Exception { - VLANInfo vlan = client.createVLAN(prefix); - String id = vlan.getUuid(); - try { - vlan = client.getVLANInfo(vlan.getUuid()); - assertEquals(vlan.getName(), prefix); - - String prefix2 = prefix + "2"; - vlan = client.renameVLAN(vlan.getUuid(), prefix2); - assertEquals(vlan.getName(), prefix2); - } finally { - client.destroyVLAN(id); - } - } - - @Test(dependsOnMethods = "testSetDriveData") - public void testCreateAndDestroyStaticIP() throws Exception { - StaticIPInfo ip = client.createStaticIP(); - StaticIPInfo ip2 = client.createStaticIP(); - Server server = null; - try { - ip = client.getStaticIPInfo(ip.getAddress()); - assertNotNull(ip); - Logger.getAnonymousLogger().info("preparing drive"); - prepareDrive(); - - Server serverRequest = Servers.smallWithStaticIP(prefix, drive.getUuid(), vncPassword, ip.getAddress()) - .build(); - - Logger.getAnonymousLogger().info("starting server"); - server = client.createServer(serverRequest); - assertEquals(server.getNics().get(0).getDhcp(), ip.getAddress()); - client.stopServer(server.getUuid()); - server = client.setServerConfiguration(server.getUuid(), Servers.changeIP(server, ip2.getAddress())); - assertEquals(server.getNics().get(0).getDhcp(), ip2.getAddress()); - } finally { - if (server != null) { - client.destroyServer(server.getUuid()); - client.destroyDrive(drive.getUuid()); - } - client.destroyStaticIP(ip.getAddress()); - client.destroyStaticIP(ip2.getAddress()); - } - } - - protected ServerInfo server; - - @Test(dependsOnMethods = "testCreateAndDestroyStaticIP") - public void testCreateAndStartServer() throws Exception { - Logger.getAnonymousLogger().info("preparing drive"); - prepareDrive(); - - Server serverRequest = Servers.small(prefix, drive.getUuid(), vncPassword).build(); - - Logger.getAnonymousLogger().info("starting server"); - server = client.createServer(serverRequest); - client.startServer(server.getUuid()); - server = client.getServerInfo(server.getUuid()); - checkStartedServer(); - - Server newInfo = client.getServerInfo(server.getUuid()); - checkServerMatchesGet(newInfo); - - } - - protected void checkServerMatchesGet(Server newInfo) { - assertEquals(newInfo.getUuid(), server.getUuid()); - } - - protected void checkStartedServer() { - System.out.println(new Gson().toJson(server)); - assertNotNull(server.getUuid()); - assertNotNull(server.getUser()); - assertEquals(server.getName(), prefix); - assertEquals(server.isPersistent(), true); - assertEquals(server.getDevices(), - ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid(drive.getUuid()).build())); - assertEquals(server.getBootDeviceIds(), ImmutableSet.of("ide:0:0")); - assertEquals(server.getNics().get(0).getDhcp(), server.getVnc().getIp()); - assertEquals(server.getNics().get(0).getModel(), Model.E1000); - assertEquals(server.getStatus(), ServerStatus.ACTIVE); - } - - @Test(dependsOnMethods = "testCreateAndStartServer") - public void testConnectivity() throws Exception { - Logger.getAnonymousLogger().info("awaiting vnc"); - assert socketTester.apply(HostAndPort.fromParts(server.getVnc().getIp(), 5900)) : server; - Logger.getAnonymousLogger().info("awaiting ssh"); - assert socketTester.apply(HostAndPort.fromParts(server.getNics().get(0).getDhcp(), 22)) : server; - doConnectViaSsh(server, getSshCredentials(server)); - } - - @Test(dependsOnMethods = "testConnectivity") - public void testLifeCycle() throws Exception { - client.stopServer(server.getUuid()); - assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED); - - client.startServer(server.getUuid()); - assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE); - - client.resetServer(server.getUuid()); - assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.ACTIVE); - - client.shutdownServer(server.getUuid()); - // behavior on shutdown depends on how your server OS is set up to respond - // to an ACPI power - // button signal - assert client.getServerInfo(server.getUuid()).getStatus() == ServerStatus.ACTIVE || client.getServerInfo( - server.getUuid()).getStatus() == ServerStatus.STOPPED; - } - - @Test(dependsOnMethods = "testLifeCycle") - public void testSetServerConfiguration() throws Exception { - client.stopServer(server.getUuid()); - assertEquals(client.getServerInfo(server.getUuid()).getStatus(), ServerStatus.STOPPED); - - ServerInfo server2 = client.setServerConfiguration( - server.getUuid(), - Server.Builder.fromServer(server).name("rediculous") - .use(ImmutableSet.of("networking", "security", "gateway")).build()); - - assertNotNull(server2.getUuid(), server.getUuid()); - assertEquals(server2.getName(), "rediculous"); - checkUse(server2); - server = server2; - } - - protected void checkUse(ServerInfo server2) { - // bug where use aren't updated - assertEquals(server2.getUse(), ImmutableSet.<String> of()); - } - - @Test(dependsOnMethods = "testSetServerConfiguration") - public void testDestroyServer() throws Exception { - client.destroyServer(server.getUuid()); - assertEquals(client.getServerInfo(server.getUuid()), null); - } - - @Test(dependsOnMethods = "testDestroyServer") - public void testDestroyDrive() throws Exception { - client.destroyDrive(drive.getUuid()); - assertEquals(client.getDriveInfo(drive.getUuid()), null); - } - - protected void doConnectViaSsh(Server server, LoginCredentials creds) throws IOException { - SshClient ssh = Guice.createInjector(new SshjSshClientModule()).getInstance(SshClient.Factory.class) - .create(HostAndPort.fromParts(server.getVnc().getIp(), 22), creds); - try { - ssh.connect(); - ExecResponse hello = ssh.exec("echo hello"); - assertEquals(hello.getOutput().trim(), "hello"); - System.err.println(ssh.exec("df -k").getOutput()); - System.err.println(ssh.exec("mount").getOutput()); - System.err.println(ssh.exec("uname -a").getOutput()); - } finally { - if (ssh != null) - ssh.disconnect(); - } - } - - @AfterGroups(groups = "live") - @Override - protected void tearDownContext() { - if (server != null) - client.destroyServer(server.getUuid()); - if (server != null) - client.destroyDrive(drive.getUuid()); - super.tearDownContext(); - } - - @Test - public void testListStandardDrives() throws Exception { - Set<String> drives = client.listStandardDrives(); - assertNotNull(drives); - } - - @Test - public void testListStandardCds() throws Exception { - Set<String> drives = client.listStandardCds(); - assertNotNull(drives); - } - - @Test - public void testListStandardImages() throws Exception { - Set<String> drives = client.listStandardImages(); - assertNotNull(drives); - } - - protected LoginCredentials getSshCredentials(Server server) { - return LoginCredentials.builder().user("root").password(vncPassword).build(); - } - - protected void prepareDrive() { - client.destroyDrive(drive.getUuid()); - drive = client.cloneDrive(imageId, drive.getName(), - new CloneDriveOptions().size(driveSize).tags("cat:mouse", "monkey:banana")); - // Block until the async clone operation has completed. - assert driveNotClaimed.apply(drive) : client.getDriveInfo(drive.getUuid()); - - DriveInfo clonedDrive = client.getDriveInfo(drive.getUuid()); - System.err.println("after prepare" + clonedDrive); - assertEquals(clonedDrive.getTags(), ImmutableSet.of("cat:mouse", "monkey:banana")); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java deleted file mode 100644 index 0cc18a6..0000000 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindCloneDriveOptionsToPlainTextStringTest.java +++ /dev/null @@ -1,67 +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.cloudsigma.binders; - -import static org.jclouds.reflect.Reflection2.method; -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.net.URI; -import java.util.List; -import java.util.Map; - -import org.jclouds.cloudsigma.options.CloneDriveOptions; -import org.jclouds.reflect.Invocation; -import org.jclouds.rest.internal.GeneratedHttpRequest; -import org.testng.annotations.Test; - -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; -import com.google.inject.Guice; -@Test(groups = "unit") -public class BindCloneDriveOptionsToPlainTextStringTest { - - private static final BindCloneDriveOptionsToPlainTextString binder = Guice.createInjector().getInstance( - BindCloneDriveOptionsToPlainTextString.class); - - public void testDefault() throws IOException { - String expected = "name newdrive"; - GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of()); - - Map<String, Object> map = ImmutableMap.<String, Object> of("name", "newdrive"); - assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected); - } - - public void testWithSize() throws IOException { - String expected = "name newdrive\nsize 1024"; - GeneratedHttpRequest request = requestForArgs(ImmutableList.<Object> of(new CloneDriveOptions().size(1024))); - - Map<String, Object> map = ImmutableMap.<String, Object> of("name", "newdrive"); - assertEquals(binder.bindToRequest(request, map).getPayload().getRawContent(), expected); - } - - protected GeneratedHttpRequest requestForArgs(List<Object> args) { - try { - Invocation invocation = Invocation.create(method(String.class, "toString"), args); - return GeneratedHttpRequest.builder().method("POST").endpoint(URI.create("http://localhost/key")) - .invocation(invocation).build(); - } catch (SecurityException e) { - throw Throwables.propagate(e); - } - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.java deleted file mode 100644 index b876a3b..0000000 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveDataToPlainTextStringTest.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.cloudsigma.binders; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; - -import javax.ws.rs.core.MediaType; - -import org.jclouds.cloudsigma.domain.ClaimType; -import org.jclouds.cloudsigma.domain.Drive; -import org.jclouds.cloudsigma.domain.DriveData; -import org.jclouds.cloudsigma.functions.BaseDriveToMap; -import org.jclouds.cloudsigma.functions.DriveDataToMap; -import org.jclouds.http.HttpRequest; -import org.jclouds.util.Strings2; -import org.testng.annotations.Test; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.TypeLiteral; - -@Test(groups = { "unit" }) -public class BindDriveDataToPlainTextStringTest { - - private static final BindDriveDataToPlainTextString FN = Guice.createInjector(new AbstractModule() { - - @Override - protected void configure() { - bind(new TypeLiteral<Function<Drive, Map<String, String>>>() { - }).to(BaseDriveToMap.class); - bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() { - }).to(DriveDataToMap.class); - } - - }).getInstance(BindDriveDataToPlainTextString.class); - - public void testSimple() { - HttpRequest request = HttpRequest.builder().method("POST").endpoint("https://host/drives/create").build(); - FN.bindToRequest(request, new DriveData.Builder().name("foo").size(100l).build()); - assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN); - assertEquals(request.getPayload().getRawContent(), "name foo\nsize 100"); - } - - public void testComplete() throws IOException { - DriveData input = new DriveData.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System") - // - .size(8589934592l)// - .claimType(ClaimType.SHARED)// - .tags(ImmutableSet.of("foo", "bar", "baz"))// - .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))// - .use(ImmutableSet.of("tag1", "tag2"))// - .build(); - - HttpRequest request = HttpRequest.builder().method("POST").endpoint("https://host/drives/create").build(); - FN.bindToRequest(request, input); - assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN); - assertEquals(request.getPayload().getRawContent(), - Strings2.toStringAndClose(BindDriveDataToPlainTextStringTest.class.getResourceAsStream("/drive_data.txt"))); - - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextStringTest.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextStringTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextStringTest.java deleted file mode 100644 index 1e7b10e..0000000 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindDriveToPlainTextStringTest.java +++ /dev/null @@ -1,83 +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.cloudsigma.binders; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; - -import javax.ws.rs.core.MediaType; - -import org.jclouds.cloudsigma.domain.ClaimType; -import org.jclouds.cloudsigma.domain.CreateDriveRequest; -import org.jclouds.cloudsigma.domain.Drive; -import org.jclouds.cloudsigma.domain.DriveData; -import org.jclouds.cloudsigma.functions.BaseDriveToMap; -import org.jclouds.cloudsigma.functions.DriveDataToMap; -import org.jclouds.http.HttpRequest; -import org.jclouds.util.Strings2; -import org.testng.annotations.Test; - -import com.google.common.base.Function; -import com.google.common.collect.ImmutableSet; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.TypeLiteral; - -@Test(groups = { "unit" }) -public class BindDriveToPlainTextStringTest { - - private static final BindDriveToPlainTextString FN = Guice.createInjector(new AbstractModule() { - - @Override - protected void configure() { - bind(new TypeLiteral<Function<Drive, Map<String, String>>>() { - }).to(BaseDriveToMap.class); - bind(new TypeLiteral<Function<DriveData, Map<String, String>>>() { - }).to(DriveDataToMap.class); - } - - }).getInstance(BindDriveToPlainTextString.class); - - public void testSimple() { - HttpRequest request = HttpRequest.builder().method("POST").endpoint("https://host/drives/create").build(); - FN.bindToRequest(request, new CreateDriveRequest.Builder().name("foo").size(100l).build()); - assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN); - assertEquals(request.getPayload().getRawContent(), "name foo\nsize 100"); - } - - public void testComplete() throws IOException { - CreateDriveRequest input = new CreateDriveRequest.Builder() - .name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System") - // - .size(8589934592l)// - .claimType(ClaimType.SHARED)// - .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))// - .use(ImmutableSet.of("tag1", "tag2"))// - .encryptionCipher("aes-xts-plain").avoid(ImmutableSet.of("avoid1")).build(); - - HttpRequest request = HttpRequest.builder().method("POST").endpoint("https://host/drives/create").build(); - FN.bindToRequest(request, input); - assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN); - assertEquals(request.getPayload().getRawContent(), - Strings2.toStringAndClose(BindDriveToPlainTextStringTest.class - .getResourceAsStream("/create_drive.txt"))); - - } - -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextStringTest.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextStringTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextStringTest.java deleted file mode 100644 index efcf460..0000000 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/binders/BindServerToPlainTextStringTest.java +++ /dev/null @@ -1,85 +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.cloudsigma.binders; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; - -import javax.ws.rs.core.MediaType; - -import org.jclouds.cloudsigma.domain.IDEDevice; -import org.jclouds.cloudsigma.domain.Model; -import org.jclouds.cloudsigma.domain.NIC; -import org.jclouds.cloudsigma.domain.Server; -import org.jclouds.cloudsigma.domain.VNC; -import org.jclouds.cloudsigma.functions.ServerToMap; -import org.jclouds.http.HttpRequest; -import org.jclouds.util.Strings2; -import org.testng.annotations.Test; - -import com.google.common.base.Function; -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.TypeLiteral; - -@Test(groups = { "unit" }) -public class BindServerToPlainTextStringTest { - - public static final String CREATED_SERVER; - static { - try { - CREATED_SERVER = Strings2.toStringAndClose(BindServerToPlainTextStringTest.class - .getResourceAsStream("/create_server.txt")); - } catch (IOException e) { - throw Throwables.propagate(e); - } - } - public static final Server SERVER = new Server.Builder() - .name("TestServer") - .cpu(2000) - .mem(1024) - .devices( - ImmutableMap.of("ide:0:0", new IDEDevice.Builder(0, 0).uuid("08c92dd5-70a0-4f51-83d2-835919d254df") - .build())).bootDeviceIds(ImmutableSet.of("ide:0:0")) - .nics(ImmutableSet.of(new NIC.Builder().model(Model.E1000). - - build())).vnc(new VNC(null, "XXXXXXXX", false)).build(); - private static final BindServerToPlainTextString FN = Guice.createInjector(new AbstractModule() { - - @Override - protected void configure() { - bind(new TypeLiteral<Function<Server, Map<String, String>>>() { - }).to(ServerToMap.class); - bind(new TypeLiteral<Function<Server, Map<String, String>>>() { - }).to(ServerToMap.class); - } - - }).getInstance(BindServerToPlainTextString.class); - - public void testSimple() throws IOException { - HttpRequest request = HttpRequest.builder().method("POST").endpoint("https://host/drives/create").build(); - FN.bindToRequest(request, SERVER); - assertEquals(request.getPayload().getContentMetadata().getContentType(), MediaType.TEXT_PLAIN); - assertEquals(request.getPayload().getRawContent(), CREATED_SERVER); - } - -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java deleted file mode 100644 index c52ce3b..0000000 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/compute/CloudSigmaComputeServiceLiveTest.java +++ /dev/null @@ -1,64 +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.cloudsigma.compute; - -import org.jclouds.compute.domain.ExecResponse; -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; - -@Test(groups = "live", testName = "CloudSigmaComputeServiceLiveTest") -public class CloudSigmaComputeServiceLiveTest extends BaseComputeServiceLiveTest { - - public CloudSigmaComputeServiceLiveTest() { - provider = "cloudsigma"; - } - - @Override - protected Module getSshModule() { - return new SshjSshClientModule(); - } - - // cloudsigma does not support metadata - @Override - protected void checkUserMetadataContains(NodeMetadata node, ImmutableMap<String, String> userMetadata) { - assert node.getUserMetadata().equals(ImmutableMap.<String, String> of()) : String.format( - "node userMetadata did not match %s %s", userMetadata, node); - } - - // cloudsigma does not support tags - @Override - protected void checkTagsInNodeEquals(final NodeMetadata node, final ImmutableSet<String> tags) { - assert node.getTags().equals(ImmutableSet.<String> of()) : String.format("node tags did not match %s %s", tags, - node); - } - - protected void checkResponseEqualsHostname(ExecResponse execResponse, NodeMetadata node1) { - // hostname is not predictable based on node metadata - assert execResponse.getOutput().trim().equals("ubuntu"); - } - - @Override - public void testOptionToNotBlock() { - // start call has to block until we have a pool of reserved pre-cloned drives. - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/BaseDriveToMapTest.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/BaseDriveToMapTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/BaseDriveToMapTest.java deleted file mode 100644 index fe7f7b4..0000000 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/BaseDriveToMapTest.java +++ /dev/null @@ -1,60 +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.cloudsigma.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; - -import org.jclouds.cloudsigma.domain.ClaimType; -import org.jclouds.cloudsigma.domain.Drive; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; - -@Test(groups = { "unit" }) -public class BaseDriveToMapTest { - - private static final BaseDriveToMap BASEDRIVE_TO_MAP = new BaseDriveToMap(); - - public void testBasics() { - assertEquals(BASEDRIVE_TO_MAP.apply(new Drive.Builder().name("foo").size(100l).build()), - ImmutableMap.of("name", "foo", "size", "100")); - } - - public void testComplete() throws IOException { - Drive one = new Drive.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System") - // - .size(8589934592l)// - .claimType(ClaimType.SHARED)// - .tags(ImmutableSet.of("foo", "bar", "baz"))// - .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))// - .use(ImmutableSet.of("tag1", "tag2"))// - .build(); - assertEquals( - BASEDRIVE_TO_MAP.apply(one), - ImmutableMap.builder().put("name", "Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System") - .put("size", "8589934592") - .put("claim:type", "shared") - .put("tags", "foo bar baz") - .put("readers", "ffffffff-ffff-ffff-ffff-ffffffffffff").put("use", "tag1 tag2").build() - - ); - - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java deleted file mode 100644 index 4140ab3..0000000 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/DriveDataToMapTest.java +++ /dev/null @@ -1,74 +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.cloudsigma.functions; - -import static org.testng.Assert.assertEquals; - -import java.io.IOException; -import java.util.Map; - -import org.jclouds.cloudsigma.domain.ClaimType; -import org.jclouds.cloudsigma.domain.DriveData; -import org.testng.annotations.Test; - -import com.google.common.collect.ImmutableMap; -import com.google.common.collect.ImmutableSet; -import com.google.inject.Guice; - -@Test(groups = { "unit" }) -public class DriveDataToMapTest { - - public void testRenameKeyWhenNotFound() { - Map<String, String> nothing = ImmutableMap.of(); - assertEquals(DriveDataToMap.renameKey(nothing, "foo", "bar"), nothing); - } - - public void testRenameKeyWhenFound() { - Map<String, String> nothing = ImmutableMap.of("foo", "bar"); - assertEquals(DriveDataToMap.renameKey(nothing, "foo", "bar"), ImmutableMap.of("bar", "bar")); - } - - private static final DriveDataToMap BASEDRIVE_TO_MAP = Guice.createInjector().getInstance(DriveDataToMap.class); - - public void testBasics() { - assertEquals(BASEDRIVE_TO_MAP.apply(new DriveData.Builder().name("foo").size(100l).build()), - ImmutableMap.of("name", "foo", "size", "100")); - } - - public void testComplete() throws IOException { - DriveData one = new DriveData.Builder().name("Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System") - // - .size(8589934592l)// - .claimType(ClaimType.SHARED)// - .tags(ImmutableSet.of("foo", "bar", "baz"))// - .readers(ImmutableSet.of("ffffffff-ffff-ffff-ffff-ffffffffffff"))// - .use(ImmutableSet.of("tag1", "tag2"))// - .build(); - assertEquals( - BASEDRIVE_TO_MAP.apply(one), - ImmutableMap.builder() - .put("name", "Ubuntu 10.10 Server Edition Linux 64bit Preinstalled System") - .put("size", "8589934592") - .put("claim:type", "shared") - .put("tags", "foo bar baz") - .put("readers", "ffffffff-ffff-ffff-ffff-ffffffffffff") - .put("use", "tag1 tag2").build() - - ); - - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java deleted file mode 100644 index 7898203..0000000 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToDriveInfoTest.java +++ /dev/null @@ -1,42 +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.cloudsigma.functions; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -import com.google.inject.Guice; - -@Test(groups = { "unit" }) -public class KeyValuesDelimitedByBlankLinesToDriveInfoTest { - - private static final KeyValuesDelimitedByBlankLinesToDriveInfo FN = Guice.createInjector().getInstance( - KeyValuesDelimitedByBlankLinesToDriveInfo.class); - - public void testNone() { - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").payload("").build()), null); - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").payload("\n\n").build()), null); - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").build()), null); - } - - public void testOne() { - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").payload(MapToDriveInfoTest.class - .getResourceAsStream("/drive.txt")).build()), MapToDriveInfoTest.ONE); - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToProfileInfoTest.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToProfileInfoTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToProfileInfoTest.java deleted file mode 100644 index ed86af8..0000000 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToProfileInfoTest.java +++ /dev/null @@ -1,42 +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.cloudsigma.functions; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -import com.google.inject.Guice; - -@Test(groups = { "unit" }) -public class KeyValuesDelimitedByBlankLinesToProfileInfoTest { - - private static final KeyValuesDelimitedByBlankLinesToProfileInfo FN = Guice.createInjector().getInstance( - KeyValuesDelimitedByBlankLinesToProfileInfo.class); - - public void testNone() { - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").payload("").build()), null); - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").payload("\n\n").build()), null); - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").build()), null); - } - - public void testOne() { - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").payload(MapToProfileInfoTest.class - .getResourceAsStream("/profile.txt")).build()), MapToProfileInfoTest.ONE); - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java deleted file mode 100644 index eb7f4d3..0000000 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToServerInfoTest.java +++ /dev/null @@ -1,73 +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.cloudsigma.functions; - -import static org.testng.Assert.assertEquals; - -import java.util.List; -import java.util.Map; - -import org.jclouds.cloudsigma.domain.Device; -import org.jclouds.cloudsigma.domain.DriveMetrics; -import org.jclouds.cloudsigma.domain.NIC; -import org.jclouds.cloudsigma.domain.ServerMetrics; -import org.jclouds.cloudsigma.functions.MapToDevices.DeviceToId; -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -import com.google.common.base.Function; -import com.google.inject.AbstractModule; -import com.google.inject.Guice; -import com.google.inject.TypeLiteral; - -@Test(groups = { "unit" }) -public class KeyValuesDelimitedByBlankLinesToServerInfoTest { - - private static final KeyValuesDelimitedByBlankLinesToServerInfo FN = Guice.createInjector(new AbstractModule() { - - @Override - protected void configure() { - bind(new TypeLiteral<Function<Map<String, String>, List<NIC>>>() { - }).to(MapToNICs.class); - bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends Device>>>() { - }).to(MapToDevices.class); - bind(new TypeLiteral<Function<Map<String, String>, Map<String, ? extends DriveMetrics>>>() { - }).to(MapToDriveMetrics.class); - bind(new TypeLiteral<Function<Map<String, String>, ServerMetrics>>() { - }).to(MapToServerMetrics.class); - bind(new TypeLiteral<Function<Device, String>>() { - }).to(DeviceToId.class); - } - - }).getInstance(KeyValuesDelimitedByBlankLinesToServerInfo.class); - - public void testNone() { - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").payload("").build()), null); - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").payload("\n\n").build()), null); - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").build()), null); - } - - public void testOne() { - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").payload(MapToServerInfoTest.class - .getResourceAsStream("/servers.txt")).build()), MapToServerInfoTest.ONE); - } - - public void testNew() { - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").payload(MapToServerInfoTest.class - .getResourceAsStream("/new_server.txt")).build()), MapToServerInfoTest.NEW); - } -} http://git-wip-us.apache.org/repos/asf/jclouds/blob/f7aea987/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToVLANInfoTest.java ---------------------------------------------------------------------- diff --git a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToVLANInfoTest.java b/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToVLANInfoTest.java deleted file mode 100644 index 8624b23..0000000 --- a/apis/cloudsigma/src/test/java/org/jclouds/cloudsigma/functions/KeyValuesDelimitedByBlankLinesToVLANInfoTest.java +++ /dev/null @@ -1,42 +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.cloudsigma.functions; - -import static org.testng.Assert.assertEquals; - -import org.jclouds.http.HttpResponse; -import org.testng.annotations.Test; - -import com.google.inject.Guice; - -@Test(groups = { "unit" }) -public class KeyValuesDelimitedByBlankLinesToVLANInfoTest { - - private static final KeyValuesDelimitedByBlankLinesToVLANInfo FN = Guice.createInjector().getInstance( - KeyValuesDelimitedByBlankLinesToVLANInfo.class); - - public void testNone() { - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").payload("").build()), null); - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").payload("\n\n").build()), null); - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").build()), null); - } - - public void testOne() { - assertEquals(FN.apply(HttpResponse.builder().statusCode(200).message("").payload(MapToVLANInfoTest.class - .getResourceAsStream("/vlan.txt")).build()), MapToVLANInfoTest.ONE); - } -}
