http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/CatalogApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/CatalogApiTest.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/CatalogApiTest.java new file mode 100644 index 0000000..c5094d5 --- /dev/null +++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/CatalogApiTest.java @@ -0,0 +1,129 @@ +/* + * 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.vcloud.features; + +import static org.jclouds.reflect.Reflection2.method; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.vcloud.internal.BaseVCloudApiTest; +import org.jclouds.vcloud.options.CatalogItemOptions; +import org.jclouds.vcloud.xml.CatalogHandler; +import org.jclouds.vcloud.xml.CatalogItemHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; +/** + * Tests behavior of {@code CatalogApi} + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "CatalogApiTest") +public class CatalogApiTest extends BaseVCloudApiTest<CatalogApi> { + + public void testCatalog() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(CatalogApi.class, "getCatalog", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"))); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalog/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, CatalogHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCatalogInOrg() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(CatalogApi.class, "findCatalogInOrgNamed", String.class, String.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("org", "catalog")); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalog/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalog+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, CatalogHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCatalogItemURI() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(CatalogApi.class, "getCatalogItem", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2"))); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, CatalogItemHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testFindCatalogItemInOrgCatalogNamed() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(CatalogApi.class, "findCatalogItemInOrgCatalogNamed", String.class, + String.class, String.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("org", "catalog", "item")); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/catalogItem/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, CatalogItemHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testAddVAppTemplateOrMediaImageToCatalogAndNameItem() throws SecurityException, NoSuchMethodException, + IOException { + Invokable<?, ?> method = method(CatalogApi.class, "addVAppTemplateOrMediaImageToCatalogAndNameItem", URI.class, + URI.class, String.class, CatalogItemOptions[].class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI.create("http://fooentity"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/catalog/1"), "myname", CatalogItemOptions.Builder + .description("mydescription"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/catalog/1/catalogItems HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.catalogItem+xml\n"); + assertPayloadEquals( + request, + "<CatalogItem xmlns=\"http://www.vmware.com/vcloud/v1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" name=\"myname\" xsi:schemaLocation=\"http://www.vmware.com/vcloud/v1 http://vcloud.safesecureweb.com/ns/vcloud.xsd\"><Description>mydescription</Description><Entity href=\"http://fooentity\"/></CatalogItem>", + "application/vnd.vmware.vcloud.catalogItem+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, CatalogItemHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + +}
http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/NetworkApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/NetworkApiLiveTest.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/NetworkApiLiveTest.java new file mode 100644 index 0000000..b7d7102 --- /dev/null +++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/NetworkApiLiveTest.java @@ -0,0 +1,26 @@ +/* + * 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.vcloud.features; + +import org.jclouds.vcloud.internal.BaseVCloudApiLiveTest; +import org.testng.annotations.Test; + +@Test(groups = "live", enabled = true, singleThreaded = true, testName = "NetworkApiLiveTest") +public class NetworkApiLiveTest extends BaseVCloudApiLiveTest { + + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/NetworkApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/NetworkApiTest.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/NetworkApiTest.java new file mode 100644 index 0000000..d6ce452 --- /dev/null +++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/NetworkApiTest.java @@ -0,0 +1,73 @@ +/* + * 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.vcloud.features; + +import static org.jclouds.reflect.Reflection2.method; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.vcloud.internal.BaseVCloudApiTest; +import org.jclouds.vcloud.xml.OrgNetworkHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; +/** + * Tests behavior of {@code NetworkApi} + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "NetworkApiTest") +public class NetworkApiTest extends BaseVCloudApiTest<NetworkApi> { + + public void testNetwork() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(NetworkApi.class, "getNetwork", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/network/2"))); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/network/2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, OrgNetworkHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testFindNetworkInOrgVDCNamed() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(NetworkApi.class, "findNetworkInOrgVDCNamed", String.class, String.class, + String.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("org", "vdc", "network")); + + assertRequestLineEquals(request, "GET https://vcloud.safesecureweb.com/network/1990 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.network+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, OrgNetworkHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/OrgApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/OrgApiLiveTest.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/OrgApiLiveTest.java new file mode 100644 index 0000000..d1c8528 --- /dev/null +++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/OrgApiLiveTest.java @@ -0,0 +1,39 @@ +/* + * 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.vcloud.features; + +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.internal.BaseVCloudApiLiveTest; +import org.testng.annotations.Test; + +@Test(groups = "live", enabled = true, singleThreaded = true, testName = "OrgApiLiveTest") +public class OrgApiLiveTest extends BaseVCloudApiLiveTest { + + @Test + public void testListOrgs() throws Exception { + for (ReferenceType response : getVCloudApi().getOrgApi().listOrgs().values()) { + assertNotNull(response); + assertNotNull(response.getName()); + assertNotNull(response.getHref()); + assertEquals(getVCloudApi().getOrgApi().getOrg(response.getHref()).getName(), response.getName()); + assertEquals(getVCloudApi().getOrgApi().findOrgNamed(response.getName()).getName(), response.getName()); + } + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/OrgApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/OrgApiTest.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/OrgApiTest.java new file mode 100644 index 0000000..1080dde --- /dev/null +++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/OrgApiTest.java @@ -0,0 +1,89 @@ +/* + * 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.vcloud.features; + +import static org.jclouds.reflect.Reflection2.method; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.fallbacks.MapHttp4xxCodesToExceptions; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.vcloud.internal.BaseVCloudApiTest; +import org.jclouds.vcloud.xml.OrgHandler; +import org.jclouds.vcloud.xml.OrgListHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; +/** + * Tests behavior of {@code OrgApi} + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "OrgApiTest") +public class OrgApiTest extends BaseVCloudApiTest<OrgApi> { + + public void testlistOrgs() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(OrgApi.class, "listOrgs"); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.of()); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/org HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.orgList+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, OrgListHandler.class); + assertFallbackClassEquals(method, MapHttp4xxCodesToExceptions.class); + + checkFilters(request); + } + + public void testOrg() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(OrgApi.class, "getOrg", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/org/1"))); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/org/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, OrgHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testFindOrgNamed() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(OrgApi.class, "findOrgNamed", String.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("org")); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/org/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.org+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, OrgHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/TaskApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/TaskApiLiveTest.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/TaskApiLiveTest.java new file mode 100644 index 0000000..5be4bf4 --- /dev/null +++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/TaskApiLiveTest.java @@ -0,0 +1,26 @@ +/* + * 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.vcloud.features; + +import org.jclouds.vcloud.internal.BaseVCloudApiLiveTest; +import org.testng.annotations.Test; + +@Test(groups = "live", enabled = true, singleThreaded = true, testName = "TaskApiLiveTest") +public class TaskApiLiveTest extends BaseVCloudApiLiveTest { + + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/TaskApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/TaskApiTest.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/TaskApiTest.java new file mode 100644 index 0000000..75518f0 --- /dev/null +++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/TaskApiTest.java @@ -0,0 +1,106 @@ +/* + * 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.vcloud.features; + +import static org.jclouds.reflect.Reflection2.method; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.vcloud.internal.BaseVCloudApiTest; +import org.jclouds.vcloud.xml.TaskHandler; +import org.jclouds.vcloud.xml.TasksListHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; +/** + * Tests behavior of {@code TaskApi} + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "TaskApiTest") +public class TaskApiTest extends BaseVCloudApiTest<TaskApi> { + + public void testGetTasksList() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(TaskApi.class, "getTasksList", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/tasksList/1"))); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/tasksList/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TasksListHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testFindTasksListInOrgNamed() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(TaskApi.class, "findTasksListInOrgNamed", String.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("org")); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/tasksList/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.tasksList+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TasksListHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testGetTask() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(TaskApi.class, "getTask", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/task/1"))); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/task/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testCancelTask() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(TaskApi.class, "cancelTask", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/task/1"))); + + assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/task/1/action/cancel HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppApiLiveTest.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppApiLiveTest.java new file mode 100644 index 0000000..cf4aca3 --- /dev/null +++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppApiLiveTest.java @@ -0,0 +1,49 @@ +/* + * 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.vcloud.features; + +import static org.testng.Assert.assertNotNull; + +import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.domain.Org; +import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VDC; +import org.jclouds.vcloud.internal.BaseVCloudApiLiveTest; +import org.testng.annotations.Test; + +@Test(groups = "live", enabled = true, singleThreaded = true, testName = "VAppApiLiveTest") +public class VAppApiLiveTest extends BaseVCloudApiLiveTest { + + @Test + public void testGetVApp() throws Exception { + Org org = getVCloudApi().getOrgApi().findOrgNamed(null); + for (ReferenceType vdc : org.getVDCs().values()) { + VDC response = getVCloudApi().getVDCApi().getVDC(vdc.getHref()); + for (ReferenceType item : response.getResourceEntities().values()) { + if (item.getType().equals(VCloudMediaType.VAPP_XML)) { + try { + VApp app = getVCloudApi().getVAppApi().getVApp(item.getHref()); + assertNotNull(app); + } catch (RuntimeException e) { + + } + } + } + } + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppApiTest.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppApiTest.java new file mode 100644 index 0000000..73ca9a1 --- /dev/null +++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppApiTest.java @@ -0,0 +1,313 @@ +/* + * 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.vcloud.features; + +import static org.jclouds.reflect.Reflection2.method; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.Fallbacks.VoidOnNotFoundOr404; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.http.functions.ReleasePayloadAndReturn; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.util.Strings2; +import org.jclouds.vcloud.internal.BaseVCloudApiTest; +import org.jclouds.vcloud.options.CloneVAppOptions; +import org.jclouds.vcloud.xml.TaskHandler; +import org.jclouds.vcloud.xml.VAppHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; +/** + * Tests behavior of {@code VAppApi} + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "VAppApiTest") +public class VAppApiTest extends BaseVCloudApiTest<VAppApi> { + + public void testopyVAppToVDCAndName() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "copyVAppToVDCAndName", URI.class, URI.class, String.class, + CloneVAppOptions[].class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "my-vapp")); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp-default.xml")), + "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testCopyVAppToVDCAndNameOptions() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "copyVAppToVDCAndName", URI.class, URI.class, String.class, + CloneVAppOptions[].class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "new-linux-server", new CloneVAppOptions() + .deploy().powerOn().description("The description of the new vApp"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVApp.xml")), + "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testMoveVAppToVDCAndRenameOptions() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "moveVAppToVDCAndRename", URI.class, URI.class, String.class, + CloneVAppOptions[].class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "new-linux-server", new CloneVAppOptions() + .deploy().powerOn().description("The description of the new vApp"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVApp HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/moveVApp.xml")), + "application/vnd.vmware.vcloud.cloneVAppParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testDeployVApp() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "deployVApp", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"))); + + assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>", + "application/vnd.vmware.vcloud.deployVAppParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testDeployAndPowerOnVApp() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "deployAndPowerOnVApp", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"))); + + assertRequestLineEquals(request, "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/deploy HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, "<DeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" powerOn=\"true\"/>", + "application/vnd.vmware.vcloud.deployVAppParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testGetVApp() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "getVApp", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"))); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testRebootVApp() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "rebootVApp", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reboot HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testUndeployVApp() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "undeployVApp", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\"/>", + "application/vnd.vmware.vcloud.undeployVAppParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testUndeployAndSaveStateOfVAppSaveState() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "undeployAndSaveStateOfVApp", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/action/undeploy HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, + "<UndeployVAppParams xmlns=\"http://www.vmware.com/vcloud/v1\" saveState=\"true\"/>", + "application/vnd.vmware.vcloud.undeployVAppParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testDeleteVApp() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "deleteVApp", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"))); + + assertRequestLineEquals(request, "DELETE https://vcenterprise.bluelock.com/api/v1.0/vApp/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, VoidOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testPowerOnVApp() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "powerOnVApp", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOn HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testPowerOffVApp() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "powerOffVApp", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/powerOff HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testResetVApp() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "resetVApp", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/reset HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testSuspendVApp() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "suspendVApp", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/suspend HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testShutdownVApp() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppApi.class, "shutdownVApp", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vApp/1"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vApp/1/power/action/shutdown HTTP/1.1"); + assertNonPayloadHeadersEqual(request, ""); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ReleasePayloadAndReturn.class); + assertSaxResponseParserClassEquals(method, null); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppTemplateApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppTemplateApiLiveTest.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppTemplateApiLiveTest.java new file mode 100644 index 0000000..e883235 --- /dev/null +++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppTemplateApiLiveTest.java @@ -0,0 +1,164 @@ +/* + * 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.vcloud.features; + +import static com.google.common.collect.Iterables.getOnlyElement; +import static java.util.concurrent.TimeUnit.SECONDS; +import static org.jclouds.util.Predicates2.retry; +import static org.testng.Assert.assertEquals; + +import java.net.URI; + +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.domain.Catalog; +import org.jclouds.vcloud.domain.CatalogItem; +import org.jclouds.vcloud.domain.Org; +import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.domain.Status; +import org.jclouds.vcloud.domain.Task; +import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VAppTemplate; +import org.jclouds.vcloud.internal.BaseVCloudApiLiveTest; +import org.jclouds.vcloud.options.CatalogItemOptions; +import org.jclouds.vcloud.predicates.TaskSuccess; +import org.testng.annotations.Test; + +import com.google.common.base.Predicate; +import com.google.common.collect.ImmutableMap; + +@Test(groups = "live", enabled = true, singleThreaded = true, testName = "VAppTemplateApiLiveTest") +public class VAppTemplateApiLiveTest extends BaseVCloudApiLiveTest { + @Test + public void testGetVAppTemplate() throws Exception { + Org org = getVCloudApi().getOrgApi().findOrgNamed(null); + for (ReferenceType cat : org.getCatalogs().values()) { + Catalog response = getVCloudApi().getCatalogApi().getCatalog(cat.getHref()); + for (ReferenceType resource : response.values()) { + if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { + CatalogItem item = getVCloudApi().getCatalogApi().getCatalogItem(resource.getHref()); + if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) { + VAppTemplate template = getVCloudApi().getVAppTemplateApi().getVAppTemplate(item.getEntity().getHref()); + if (template != null) { + // the UUID in the href is the only way to actually link templates + assertEquals(template.getHref(), item.getEntity().getHref()); + } else { + // null can be no longer available or auth exception + } + } + } + } + } + } + + @Test + public void testGetOvfEnvelopeForVAppTemplate() throws Exception { + Org org = getVCloudApi().getOrgApi().findOrgNamed(null); + for (ReferenceType cat : org.getCatalogs().values()) { + Catalog response = getVCloudApi().getCatalogApi().getCatalog(cat.getHref()); + for (ReferenceType resource : response.values()) { + if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { + CatalogItem item = getVCloudApi().getCatalogApi().getCatalogItem(resource.getHref()); + if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) { + getVCloudApi().getVAppTemplateApi().getOvfEnvelopeForVAppTemplate(item.getEntity().getHref()); + // null can be no longer available or auth exception + } + } + } + } + } + + @Test + public void testFindVAppTemplate() throws Exception { + Org org = getVCloudApi().getOrgApi().findOrgNamed(null); + for (ReferenceType cat : org.getCatalogs().values()) { + Catalog response = getVCloudApi().getCatalogApi().getCatalog(cat.getHref()); + for (ReferenceType resource : response.values()) { + if (resource.getType().equals(VCloudMediaType.CATALOGITEM_XML)) { + CatalogItem item = getVCloudApi().getCatalogApi().getCatalogItem(resource.getHref()); + if (item.getEntity().getType().equals(VCloudMediaType.VAPPTEMPLATE_XML)) { + VAppTemplate template = getVCloudApi().getVAppTemplateApi().findVAppTemplateInOrgCatalogNamed( + org.getName(), response.getName(), item.getEntity().getName()); + if (template != null) { + // the UUID in the href is the only way to actually link templates + assertEquals(template.getHref(), item.getEntity().getHref()); + } else { + // null can be no longer available or auth exception + } + } + } + } + } + } + + @Test + public void testCaptureVApp() throws Exception { + String group = prefix + "cap"; + NodeMetadata node = null; + VAppTemplate vappTemplate = null; + CatalogItem item = null; + try { + + node = getOnlyElement(client.createNodesInGroup(group, 1)); + + Predicate<URI> taskTester = retry(new TaskSuccess(getVCloudApi()), 600, 5, SECONDS); + + // I have to undeploy first + Task task = getVCloudApi().getVAppApi().undeployVApp(URI.create(node.getId())); + + // wait up to ten minutes per above + assert taskTester.apply(task.getHref()) : node; + + VApp vApp = getVCloudApi().getVAppApi().getVApp(URI.create(node.getId())); + + // wait up to ten minutes per above + assertEquals(vApp.getStatus(), Status.OFF); + + // vdc is equiv to the node's location + // vapp uri is the same as the node's id + vappTemplate = getVCloudApi().getVAppTemplateApi().captureVAppAsTemplateInVDC(URI.create(node.getId()), + group, URI.create(node.getLocation().getId())); + + assertEquals(vappTemplate.getName(), group); + + task = vappTemplate.getTasks().get(0); + + // wait up to ten minutes per above + assert taskTester.apply(task.getHref()) : vappTemplate; + + item = getVCloudApi().getCatalogApi().addVAppTemplateOrMediaImageToCatalogAndNameItem( + vappTemplate.getHref(), + getVCloudApi().getCatalogApi().findCatalogInOrgNamed(null, null).getHref(), "fooname", + CatalogItemOptions.Builder.description("description").properties(ImmutableMap.of("foo", "bar"))); + + assertEquals(item.getName(), "fooname"); + assertEquals(item.getDescription(), "description"); + assertEquals(item.getProperties(), ImmutableMap.of("foo", "bar")); + assertEquals(item.getEntity().getName(), "fooname"); + assertEquals(item.getEntity().getHref(), vappTemplate.getHref()); + assertEquals(item.getEntity().getType(), vappTemplate.getType()); + + } finally { + if (item != null) + getVCloudApi().getCatalogApi().deleteCatalogItem(item.getHref()); + if (vappTemplate != null) + getVCloudApi().getVAppTemplateApi().deleteVAppTemplate(vappTemplate.getHref()); + if (node != null) + client.destroyNode(node.getId()); + } + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppTemplateApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppTemplateApiTest.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppTemplateApiTest.java new file mode 100644 index 0000000..12bef2e --- /dev/null +++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VAppTemplateApiTest.java @@ -0,0 +1,236 @@ +/* + * 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.vcloud.features; + +import static org.jclouds.reflect.Reflection2.method; +import static org.jclouds.vcloud.options.InstantiateVAppTemplateOptions.Builder.addNetworkConfig; + +import java.io.IOException; +import java.net.URI; + +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.ovf.xml.EnvelopeHandler; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.util.Strings2; +import org.jclouds.vcloud.domain.network.FenceMode; +import org.jclouds.vcloud.domain.network.NetworkConfig; +import org.jclouds.vcloud.internal.BaseVCloudApiTest; +import org.jclouds.vcloud.options.CaptureVAppOptions; +import org.jclouds.vcloud.options.CloneVAppTemplateOptions; +import org.jclouds.vcloud.options.InstantiateVAppTemplateOptions; +import org.jclouds.vcloud.xml.TaskHandler; +import org.jclouds.vcloud.xml.VAppHandler; +import org.jclouds.vcloud.xml.VAppTemplateHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.reflect.Invokable; +/** + * Tests behavior of {@code VAppTemplateApi} + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "VAppTemplateApiTest") +public class VAppTemplateApiTest extends BaseVCloudApiTest<VAppTemplateApi> { + + public void testCreateVAppInVDCByInstantiatingTemplate() throws SecurityException, NoSuchMethodException, + IOException { + Invokable<?, ?> method = method(VAppTemplateApi.class, "createVAppInVDCByInstantiatingTemplate", String.class, + URI.class, URI.class, InstantiateVAppTemplateOptions[].class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("my-vapp", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/3"), + addNetworkConfig(new NetworkConfig("aloha", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), FenceMode.NAT_ROUTED)))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/instantiateVAppTemplate HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vApp+xml\n"); + assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream( + "/instantiationparams-network.xml")), "application/vnd.vmware.vcloud.instantiateVAppTemplateParams+xml", + false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testCreateVAppInVDCByInstantiatingTemplateOptionsIllegalName() throws SecurityException, + NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppTemplateApi.class, "createVAppInVDCByInstantiatingTemplate", String.class, + URI.class, URI.class, InstantiateVAppTemplateOptions[].class); + processor.createRequest(method, ImmutableList.<Object> of("CentOS 01", URI.create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), addNetworkConfig(new NetworkConfig(null, + URI.create("https://vcenterprise.bluelock.com/api/v1.0/network/1991"), null)))); + } + + public void testcopyVAppTemplateToVDCAndName() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppTemplateApi.class, "copyVAppTemplateToVDCAndName", URI.class, URI.class, + String.class, CloneVAppTemplateOptions[].class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/4181"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "my-vapptemplate")); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVAppTemplate HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream( + "/copyVAppTemplate-default.xml")), "application/vnd.vmware.vcloud.cloneVAppTemplateParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testcopyVAppTemplateToVDCAndNameOptions() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppTemplateApi.class, "copyVAppTemplateToVDCAndName", URI.class, URI.class, + String.class, CloneVAppTemplateOptions[].class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "new-linux-server", + new CloneVAppTemplateOptions().description("The description of the new vAppTemplate"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVAppTemplate HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/copyVAppTemplate.xml")), + "application/vnd.vmware.vcloud.cloneVAppTemplateParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testmoveVAppTemplateToVDCAndRenameOptions() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppTemplateApi.class, "moveVAppTemplateToVDCAndRename", URI.class, URI.class, + String.class, CloneVAppTemplateOptions[].class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/201"), URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), "new-linux-server", + new CloneVAppTemplateOptions().description("The description of the new vAppTemplate"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/cloneVAppTemplate HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.task+xml\n"); + assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/moveVAppTemplate.xml")), + "application/vnd.vmware.vcloud.cloneVAppTemplateParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, TaskHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testcaptureVAppAsTemplateInVDC() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppTemplateApi.class, "captureVAppAsTemplateInVDC", URI.class, String.class, + URI.class, CaptureVAppOptions[].class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/4181"), "my-template", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); + assertPayloadEquals(request, Strings2 + .toStringAndClose(getClass().getResourceAsStream("/captureVApp-default.xml")), + "application/vnd.vmware.vcloud.captureVAppParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testcaptureVAppAsTemplateInVDCOptions() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppTemplateApi.class, "captureVAppAsTemplateInVDC", URI.class, String.class, + URI.class, CaptureVAppOptions[].class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vapp/201"), "my-template", URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"), new CaptureVAppOptions() + .withDescription("The description of the new vApp Template"))); + + assertRequestLineEquals(request, + "POST https://vcenterprise.bluelock.com/api/v1.0/vdc/1/action/captureVApp HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); + assertPayloadEquals(request, Strings2.toStringAndClose(getClass().getResourceAsStream("/captureVApp.xml")), + "application/vnd.vmware.vcloud.captureVAppParams+xml", false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class); + assertFallbackClassEquals(method, null); + + checkFilters(request); + } + + public void testFindVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppTemplateApi.class, "findVAppTemplateInOrgCatalogNamed", String.class, + String.class, String.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of("org", "catalog", "template")); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testVAppTemplateURI() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppTemplateApi.class, "getVAppTemplate", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2"))); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vAppTemplate+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VAppTemplateHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testGetOvfEnvelopeForVAppTemplate() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VAppTemplateApi.class, "getOvfEnvelopeForVAppTemplate", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2"))); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vAppTemplate/2/ovf HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: text/xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, EnvelopeHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VDCApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VDCApiLiveTest.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VDCApiLiveTest.java new file mode 100644 index 0000000..be1efdc --- /dev/null +++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VDCApiLiveTest.java @@ -0,0 +1,26 @@ +/* + * 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.vcloud.features; + +import org.jclouds.vcloud.internal.BaseVCloudApiLiveTest; +import org.testng.annotations.Test; + +@Test(groups = "live", enabled = true, singleThreaded = true, testName = "VDCApiLiveTest") +public class VDCApiLiveTest extends BaseVCloudApiLiveTest { + + +} http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VDCApiTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VDCApiTest.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VDCApiTest.java new file mode 100644 index 0000000..0296453 --- /dev/null +++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VDCApiTest.java @@ -0,0 +1,100 @@ +/* + * 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.vcloud.features; + +import static org.jclouds.reflect.Reflection2.method; + +import java.io.IOException; +import java.net.URI; +import java.util.NoSuchElementException; + +import org.jclouds.Fallbacks.NullOnNotFoundOr404; +import org.jclouds.http.functions.ParseSax; +import org.jclouds.rest.internal.GeneratedHttpRequest; +import org.jclouds.vcloud.internal.BaseVCloudApiTest; +import org.jclouds.vcloud.xml.VDCHandler; +import org.testng.annotations.Test; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Lists; +import com.google.common.reflect.Invokable; +/** + * Tests behavior of {@code VDCApi} + */ +// NOTE:without testName, this will not call @Before* and fail w/NPE during +// surefire +@Test(groups = "unit", testName = "VDCApiTest") +public class VDCApiTest extends BaseVCloudApiTest<VDCApi> { + + @Test(expectedExceptions = NoSuchElementException.class) + public void testFindVDCInOrgNamedBadVDC() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VDCApi.class, "findVDCInOrgNamed", String.class, String.class); + processor.createRequest(method, ImmutableList.<Object> of("org", "vdc1")); + } + + @Test(expectedExceptions = NoSuchElementException.class) + public void testFindVDCInOrgNamedBadOrg() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VDCApi.class, "findVDCInOrgNamed", String.class, String.class); + processor.createRequest(method, ImmutableList.<Object> of("org1", "vdc")); + } + + public void testFindVDCInOrgNamedNullOrg() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VDCApi.class, "findVDCInOrgNamed", String.class, String.class); + GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, "vdc")); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VDCHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testFindVDCInOrgNamedNullOrgAndVDC() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VDCApi.class, "findVDCInOrgNamed", String.class, String.class); + GeneratedHttpRequest request = processor.createRequest(method, Lists.<Object> newArrayList(null, null)); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VDCHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } + + public void testGetVDC() throws SecurityException, NoSuchMethodException, IOException { + Invokable<?, ?> method = method(VDCApi.class, "getVDC", URI.class); + GeneratedHttpRequest request = processor.createRequest(method, ImmutableList.<Object> of(URI + .create("https://vcenterprise.bluelock.com/api/v1.0/vdc/1"))); + + assertRequestLineEquals(request, "GET https://vcenterprise.bluelock.com/api/v1.0/vdc/1 HTTP/1.1"); + assertNonPayloadHeadersEqual(request, "Accept: application/vnd.vmware.vcloud.vdc+xml\n"); + assertPayloadEquals(request, null, null, false); + + assertResponseParserClassEquals(method, request, ParseSax.class); + assertSaxResponseParserClassEquals(method, VDCHandler.class); + assertFallbackClassEquals(method, NullOnNotFoundOr404.class); + + checkFilters(request); + } +} http://git-wip-us.apache.org/repos/asf/stratos/blob/6573fbed/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VmApiLiveTest.java ---------------------------------------------------------------------- diff --git a/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VmApiLiveTest.java b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VmApiLiveTest.java new file mode 100644 index 0000000..f6b3d92 --- /dev/null +++ b/dependencies/jclouds/apis/vcloud/1.8.1-stratos/src/test/java/org/jclouds/vcloud/features/VmApiLiveTest.java @@ -0,0 +1,161 @@ +/* + * 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.vcloud.features; + +import static com.google.common.base.Charsets.UTF_8; +import static com.google.common.collect.Iterables.get; +import static com.google.common.collect.Iterables.getOnlyElement; +import static com.google.common.io.BaseEncoding.base64; +import static org.jclouds.compute.options.RunScriptOptions.Builder.wrapInInitScript; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertNotNull; + +import org.jclouds.compute.domain.ExecResponse; +import org.jclouds.compute.domain.NodeMetadata; +import org.jclouds.compute.options.TemplateOptions; +import org.jclouds.vcloud.VCloudApi; +import org.jclouds.vcloud.VCloudMediaType; +import org.jclouds.vcloud.compute.options.VCloudTemplateOptions; +import org.jclouds.vcloud.domain.Org; +import org.jclouds.vcloud.domain.ReferenceType; +import org.jclouds.vcloud.domain.VApp; +import org.jclouds.vcloud.domain.VDC; +import org.jclouds.vcloud.domain.Vm; +import org.jclouds.vcloud.internal.BaseVCloudApiLiveTest; +import org.testng.annotations.Test; + +import com.google.common.collect.Iterables; +import com.google.common.net.HostAndPort; + +/** + * This tests that we can use guest customization as an alternative to bootstrapping with ssh. There + * are a few advantages to this, including the fact that it can work inside google appengine where + * network sockets (ssh:22) are prohibited. + */ +@Test(groups = "live", enabled = true, singleThreaded = true, testName = "VmApiLiveTest") +public class VmApiLiveTest extends BaseVCloudApiLiveTest { + + @Test + public void testGetThumbnailOfVm() throws Exception { + Org org = getVCloudApi().getOrgApi().findOrgNamed(null); + for (ReferenceType vdc : org.getVDCs().values()) { + VDC response = getVCloudApi().getVDCApi().getVDC(vdc.getHref()); + for (ReferenceType item : response.getResourceEntities().values()) { + if (item.getType().equals(VCloudMediaType.VAPP_XML)) { + try { + VApp app = getVCloudApi().getVAppApi().getVApp(item.getHref()); + assertNotNull(app); + for (Vm vm : app.getChildren()) { + assert getVCloudApi().getVmApi().getScreenThumbnailForVm(vm.getHref()) != null; + } + } catch (RuntimeException e) { + + } + } + } + } + } + + @Test + public void testGetVm() throws Exception { + Org org = getVCloudApi().getOrgApi().findOrgNamed(null); + for (ReferenceType vdc : org.getVDCs().values()) { + VDC response = getVCloudApi().getVDCApi().getVDC(vdc.getHref()); + for (ReferenceType item : response.getResourceEntities().values()) { + if (item.getType().equals(VCloudMediaType.VAPP_XML)) { + try { + VApp app = getVCloudApi().getVAppApi().getVApp(item.getHref()); + assertNotNull(app); + for (Vm vm : app.getChildren()) { + assertEquals(getVCloudApi().getVmApi().getVm(vm.getHref()).getHref(), vm.getHref()); + } + } catch (RuntimeException e) { + + } + } + } + } + } + + @Test + public void testExtendedOptionsWithCustomizationScript() throws Exception { + String PARSE_VMTOOLSD = "vmtoolsd --cmd=\"info-get guestinfo.ovfenv\" |grep vCloud_CustomizationInfo|sed 's/.*value=\"\\(.*\\)\".*/\\1/g'"; + + String group = prefix + "cus"; + + NodeMetadata node = null; + try { + + TemplateOptions options = client.templateOptions(); + options.blockOnPort(22, 180); + options.as(VCloudTemplateOptions.class).customizationScript(script); + options.as(VCloudTemplateOptions.class).description(group); + node = getOnlyElement(client.createNodesInGroup(group, 1, options)); + + VApp vapp = client.getContext().unwrapApi(VCloudApi.class).getVAppApi().getVApp( + node.getUri()); + assertEquals(vapp.getDescription(), group); + + Vm vm = Iterables.get(vapp.getChildren(), 0); + String apiOutput = vm.getGuestCustomizationSection().getCustomizationScript(); + checkApiOutput(apiOutput); + + ExecResponse vmTools = client.runScriptOnNode(node.getId(), PARSE_VMTOOLSD, + wrapInInitScript(false).runAsRoot(false)); + checkApiOutput(new String(base64().decode(vmTools.getOutput().trim()), UTF_8)); + + ExecResponse foo = client.runScriptOnNode(node.getId(), "cat /root/foo.txt", wrapInInitScript(false) + .runAsRoot(false)); + checkCustomizationOccurred(foo); + + } finally { + if (node != null) + client.destroyNode(node.getId()); + } + } + + protected void checkCustomizationOccurred(ExecResponse exec) { + // note that vmwaretools throws in \r characters when executing scripts + assert exec.getOutput().equals(iLoveAscii + "\r\n") : exec; + } + + protected void checkApiOutput(String apiOutput) { + checkApiOutput1_0_1(apiOutput); + } + + // make sure the script has a lot of screwy characters, knowing our parser + // throws-out \r + protected String iLoveAscii = "I '\"love\"' {asc|!}*&"; + + String script = "cat > /root/foo.txt<<EOF\n" + iLoveAscii + "\nEOF\n"; + + protected void checkApiOutput1_0_1(String apiOutput) { + // in 1.0.1, vcloud director seems to pass through characters via api + // flawlessly + assertEquals(apiOutput, script); + } + + protected void checkApiOutput1_0_0(String apiOutput) { + // in 1.0.0, vcloud director seems to remove all newlines + assertEquals(apiOutput, script.replace("\n", "")); + } + + protected HostAndPort getSocket(NodeMetadata node) { + return HostAndPort.fromParts(get(node.getPublicAddresses(), 0), 22); + } + +}
