mirror of https://github.com/apache/jclouds.git
non-client operation tests (legacy login + get schema)
This commit is contained in:
parent
5dced71f42
commit
7d4f81a46c
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. jclouds licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*/
|
||||
package org.jclouds.vcloud.director.v1_5;
|
||||
|
||||
import static com.google.common.base.Preconditions.checkNotNull;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
|
||||
import org.jclouds.crypto.CryptoStreams;
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.OrgList;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
|
||||
import org.jclouds.vcloud.director.v1_5.features.AdminCatalogClient;
|
||||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
|
||||
import org.jclouds.xml.internal.JAXBParser;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests live behavior of {@link AdminCatalogClient}.
|
||||
*
|
||||
* @author danikov
|
||||
*/
|
||||
@Test(groups = { "live", "user", "nonClient" }, singleThreaded = true, testName = "NonClientOperationsLiveTest")
|
||||
public class NonClientOperationsLiveTest extends BaseVCloudDirectorClientLiveTest {
|
||||
|
||||
private JAXBParser parser = new JAXBParser();
|
||||
private SessionWithToken sessionWithToken;
|
||||
|
||||
@Override
|
||||
protected void setupRequiredClients() throws Exception {
|
||||
setupCredentials();
|
||||
}
|
||||
|
||||
@Test(testName = "POST /login")
|
||||
public void testPostLogin() throws IOException {
|
||||
testLoginWithMethod("POST");
|
||||
}
|
||||
|
||||
@Test(testName = "GET /login")
|
||||
public void testGetLogin() throws IOException {
|
||||
testLoginWithMethod("GET");
|
||||
}
|
||||
|
||||
private void testLoginWithMethod(String method) throws IOException {
|
||||
String user = identity.substring(0, identity.lastIndexOf('@'));
|
||||
String org = identity.substring(identity.lastIndexOf('@') + 1);
|
||||
String password = credential;
|
||||
|
||||
String authHeader = "Basic " + CryptoStreams.base64(String.format("%s@%s:%s",
|
||||
checkNotNull(user),
|
||||
checkNotNull(org),
|
||||
checkNotNull(password)).getBytes("UTF-8"));
|
||||
|
||||
HttpResponse response = context.getUtils().getHttpClient().invoke(HttpRequest.builder()
|
||||
.method(method)
|
||||
.endpoint(URI.create(endpoint+"/login"))
|
||||
.headers(ImmutableMultimap.of(
|
||||
"Authorization", authHeader,
|
||||
"Accept", "*/*"))
|
||||
.build());
|
||||
|
||||
sessionWithToken = SessionWithToken.builder()
|
||||
.session(session)
|
||||
.token(response.getFirstHeaderOrNull("x-vcloud-authorization"))
|
||||
.build();
|
||||
|
||||
assertEquals(sessionWithToken.getSession().getUser(), user);
|
||||
assertEquals(sessionWithToken.getSession().getOrg(), org);
|
||||
assertTrue(sessionWithToken.getSession().getLinks().size() > 0);
|
||||
assertNotNull(sessionWithToken.getToken());
|
||||
|
||||
OrgList orgList = parser.fromXML(
|
||||
Strings2.toStringAndClose(response.getPayload().getInput()), OrgList.class);
|
||||
|
||||
assertTrue(orgList.getOrgs().size() > 0, "must have orgs");
|
||||
|
||||
context.getApi().getOrgClient().getOrg(Iterables.getLast(orgList.getOrgs()).getHref());
|
||||
}
|
||||
|
||||
@Test(testName = "GET /schema/{schemaFileName}",
|
||||
dependsOnMethods = {"testPostLogin", "testGetLogin"} )
|
||||
public void testGetSchema() throws IOException {
|
||||
String schemafileName = "master.xsd";
|
||||
HttpResponse response = context.getUtils().getHttpClient().invoke(HttpRequest.builder()
|
||||
.method("GET")
|
||||
.endpoint(URI.create(endpoint+"/v1.5/schema/"+schemafileName))
|
||||
.headers(ImmutableMultimap.of(
|
||||
"x-vcloud-authorization", sessionWithToken.getToken(),
|
||||
"Accept", "*/*"))
|
||||
.build());
|
||||
|
||||
String schema = Strings2.toStringAndClose(response.getPayload().getInput());
|
||||
|
||||
// TODO: asserting something about the schema
|
||||
}
|
||||
}
|
|
@ -19,8 +19,10 @@
|
|||
package org.jclouds.vcloud.director.v1_5.features;
|
||||
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CONDITION_FMT;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CORRECT_VALUE_OBJECT_FMT;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.ENTITY_EQUAL;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.MATCHES_STRING_FMT;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.NOT_EMPTY_OBJECT_FMT;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.OBJ_FIELD_EQ;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.TASK_COMPLETE_TIMELY;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.ADMIN_USER;
|
||||
|
@ -28,8 +30,10 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType.MEDIA;
|
|||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkControlAccessParams;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkGuestCustomizationSection;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkLeaseSettingsSection;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadata;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataFor;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataKeyAbsentFor;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataValue;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkMetadataValueFor;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConfigSection;
|
||||
import static org.jclouds.vcloud.director.v1_5.domain.Checks.checkNetworkConnectionSection;
|
||||
|
@ -86,7 +90,6 @@ import org.jclouds.vcloud.director.v1_5.domain.ScreenTicket;
|
|||
import org.jclouds.vcloud.director.v1_5.domain.Task;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.UndeployVAppParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VApp;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Vm;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VmPendingQuestion;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VmQuestionAnswer;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.VmQuestionAnswerChoice;
|
||||
|
@ -116,6 +119,9 @@ import com.google.common.collect.Sets;
|
|||
@Test(groups = { "live", "user", "vapp" }, singleThreaded = true, testName = "VAppClientLiveTest")
|
||||
public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
||||
|
||||
private MetadataValue metadataValue;
|
||||
private String key;
|
||||
|
||||
/**
|
||||
* @see VAppClient#getVApp(URI)
|
||||
*/
|
||||
|
@ -1109,20 +1115,11 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
// See the description in testModifyVirtualHardwareSectionDisks
|
||||
}
|
||||
|
||||
@Test(testName = "GET /vApp/{id}/metadata", dependsOnMethods = { "testGetVApp" })
|
||||
public void testGetMetadata() {
|
||||
Metadata metadata = vAppClient.getMetadataClient().getMetadata(vApp.getHref());
|
||||
|
||||
// Check the retrieved object is well formed
|
||||
checkMetadataFor(VAPP, metadata);
|
||||
}
|
||||
|
||||
@Test(testName = "PUT /vApp/{id}/metadata", dependsOnMethods = { "testGetMetadata" })
|
||||
@Test(testName = "PUT /vApp/{id}/metadata", dependsOnMethods = { "testGetVApp" })
|
||||
public void testSetMetadataValue() {
|
||||
// Store a value
|
||||
String key = name("key-");
|
||||
key = name("key-");
|
||||
String value = name("value-");
|
||||
MetadataValue metadataValue = MetadataValue.builder().value(value).build();
|
||||
metadataValue = MetadataValue.builder().value(value).build();
|
||||
vAppClient.getMetadataClient().setMetadata(vApp.getHref(), key, metadataValue);
|
||||
|
||||
// Retrieve the value, and assert it was set correctly
|
||||
|
@ -1131,14 +1128,31 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
// Check the retrieved object is well formed
|
||||
checkMetadataValueFor(VAPP, newMetadataValue, value);
|
||||
}
|
||||
|
||||
@Test(testName = "GET /vApp/{id}/metadata", dependsOnMethods = { "testSetMetadataValue" })
|
||||
public void testGetMetadata() {
|
||||
// Call the method being tested
|
||||
Metadata metadata = vAppClient.getMetadataClient().getMetadata(vApp.getHref());
|
||||
|
||||
checkMetadata(metadata);
|
||||
|
||||
// Check requirements for this test
|
||||
assertFalse(Iterables.isEmpty(metadata.getMetadataEntries()), String.format(NOT_EMPTY_OBJECT_FMT, "MetadataEntry", "vApp"));
|
||||
}
|
||||
|
||||
@Test(testName = "GET /vApp/{id}/metadata/{key}", dependsOnMethods = { "testGetMetadata" })
|
||||
public void testGetOrgMetadataValue() {
|
||||
// Call the method being tested
|
||||
MetadataValue value = vAppClient.getMetadataClient().getMetadataValue(vApp.getHref(), key);
|
||||
|
||||
String expected = metadataValue.getValue();
|
||||
|
||||
checkMetadataValue(value);
|
||||
assertEquals(value.getValue(), expected, String.format(CORRECT_VALUE_OBJECT_FMT, "Value", "MetadataValue", expected, value.getValue()));
|
||||
}
|
||||
|
||||
@Test(testName = "DELETE /vApp/{id}/metadata/{key}", dependsOnMethods = { "testSetMetadataValue" })
|
||||
public void testDeleteMetadataEntry() {
|
||||
// Store a value, to be deleted
|
||||
String key = name("key-");
|
||||
MetadataValue metadataValue = MetadataValue.builder().value("myval").build();
|
||||
vAppClient.getMetadataClient().setMetadata(vApp.getHref(), key, metadataValue);
|
||||
|
||||
// Delete the entry
|
||||
Task task = vAppClient.getMetadataClient().deleteMetadataEntry(vApp.getHref(), key);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
|
|
@ -186,7 +186,7 @@ public class BaseVCloudDirectorRestClientExpectTest extends BaseRestClientExpect
|
|||
*
|
||||
* @author danikov
|
||||
*/
|
||||
protected class VcloudHttpRequestPrimer {
|
||||
public class VcloudHttpRequestPrimer {
|
||||
private Multimap<String, String> headers = LinkedListMultimap.create();
|
||||
private HttpRequest.Builder builder = HttpRequest.builder();
|
||||
|
||||
|
|
Loading…
Reference in New Issue