mirror of https://github.com/apache/jclouds.git
Merge pull request #565 from grkvlt/vcloud-testing
Issue 830: vCloud Director live test setup
This commit is contained in:
commit
919f3ccc71
|
@ -82,8 +82,7 @@ public abstract class BaseContextLiveTest<C extends Closeable> {
|
|||
}
|
||||
|
||||
protected void initializeContext() {
|
||||
if (context != null)
|
||||
Closeables.closeQuietly(context);
|
||||
Closeables.closeQuietly(context);
|
||||
context = createContext(setupProperties(), setupModules());
|
||||
}
|
||||
|
||||
|
|
|
@ -18,6 +18,12 @@
|
|||
*/
|
||||
package org.jclouds.vcloud.director.v1_5;
|
||||
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.vcloud.director.v1_5.login.SessionAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.login.SessionClient;
|
||||
|
||||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Constants used by VCloudDirector clients
|
||||
*
|
||||
|
@ -63,4 +69,11 @@ public class VCloudDirectorConstants {
|
|||
|
||||
/** TODO javadoc */
|
||||
public static final String PROPERTY_NS_NAME_LEN_MAX = "jclouds.dns_name_length_max";
|
||||
|
||||
/** TODO javadoc */
|
||||
public static final TypeToken<RestContext<SessionClient, SessionAsyncClient>> SESSION_CONTEXT_TYPE =
|
||||
new TypeToken<RestContext<SessionClient, SessionAsyncClient>>() {
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = -3625362618882122604L;
|
||||
};
|
||||
}
|
||||
|
|
|
@ -196,6 +196,8 @@ public class VCloudDirectorMediaType {
|
|||
public static final String NETWORK_POOL = "application/vnd.vmware.admin.networkPool+xml";
|
||||
|
||||
public static final String ENTITY = "application/vnd.vmware.vcloud.entity+xml";
|
||||
|
||||
public static final String ADMIN = "application/vnd.vmware.admin.vcloud+xml";
|
||||
|
||||
/**
|
||||
* All acceptable media types.
|
||||
|
@ -220,7 +222,7 @@ public class VCloudDirectorMediaType {
|
|||
ADMIN_ORG_NETWORK, USER, ROLE, DEPLOY_VAPP_PARAMS, RECOMPOSE_VAPP_PARAMS,
|
||||
RELOCATE_VM_PARAMS, UNDEPLOY_VAPP_PARAMS, ADMIN_VDC, MEDIA_PARAMS,
|
||||
RUNTIME_INFO_SECTION, SCREEN_TICKET, VAPP_NETWORK,
|
||||
TEXT_XML, ADMIN_VDC, NETWORK_POOL, ADMIN_ORG, ENTITY
|
||||
TEXT_XML, ADMIN_VDC, NETWORK_POOL, ADMIN_ORG, ENTITY, ADMIN
|
||||
);
|
||||
|
||||
// NOTE These lists must be updated whenever a new media type constant is added.
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/**
|
||||
/*
|
||||
* Licensed to jclouds, Inc. (jclouds) under one or more
|
||||
* contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
|
@ -37,15 +37,9 @@ import com.google.common.collect.ImmutableList;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Maps;
|
||||
|
||||
|
||||
/**
|
||||
* Represents a network connection.
|
||||
* <p/>
|
||||
* <p/>
|
||||
* <p>Java class for NetworkConnection complex type.
|
||||
* <p/>
|
||||
* <p>The following schema fragment specifies the expected content contained within this class.
|
||||
* <p/>
|
||||
*
|
||||
* <pre>
|
||||
* <complexType name="NetworkConnection">
|
||||
* <complexContent>
|
||||
|
@ -83,7 +77,7 @@ public class NetworkConnection {
|
|||
@XmlEnumValue("dhcp") DHCP("dhcp"),
|
||||
@XmlEnumValue("manual") MANUAL("manual"),
|
||||
@XmlEnumValue("none") NONE("none"),
|
||||
UNRECOGNIZED("unrecognized");
|
||||
@XmlEnumValue("") UNRECOGNIZED("unrecognized");
|
||||
|
||||
public static final List<IpAddressAllocationMode> ALL = ImmutableList.of(POOL, DHCP, MANUAL, NONE);
|
||||
|
||||
|
@ -126,7 +120,7 @@ public class NetworkConnection {
|
|||
private String externalIpAddress;
|
||||
private boolean isConnected;
|
||||
private String macAddress;
|
||||
private String ipAddressAllocationMode;
|
||||
private IpAddressAllocationMode ipAddressAllocationMode;
|
||||
private String network;
|
||||
private Boolean needsCustomization;
|
||||
|
||||
|
@ -173,11 +167,19 @@ public class NetworkConnection {
|
|||
/**
|
||||
* @see NetworkConnection#getIpAddressAllocationMode()
|
||||
*/
|
||||
public Builder ipAddressAllocationMode(String ipAddressAllocationMode) {
|
||||
public Builder ipAddressAllocationMode(IpAddressAllocationMode ipAddressAllocationMode) {
|
||||
this.ipAddressAllocationMode = ipAddressAllocationMode;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see NetworkConnection#getIpAddressAllocationMode()
|
||||
*/
|
||||
public Builder ipAddressAllocationMode(String ipAddressAllocationMode) {
|
||||
this.ipAddressAllocationMode = IpAddressAllocationMode.valueOf(ipAddressAllocationMode);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see NetworkConnection#getNetwork()
|
||||
*/
|
||||
|
@ -214,11 +216,11 @@ public class NetworkConnection {
|
|||
}
|
||||
|
||||
public NetworkConnection(int networkConnectionIndex, String ipAddress, String externalIpAddress, boolean connected,
|
||||
String macAddress, String ipAddressAllocationMode, String network, Boolean needsCustomization) {
|
||||
String macAddress, IpAddressAllocationMode ipAddressAllocationMode, String network, Boolean needsCustomization) {
|
||||
this.networkConnectionIndex = networkConnectionIndex;
|
||||
this.ipAddress = ipAddress;
|
||||
this.externalIpAddress = externalIpAddress;
|
||||
isConnected = connected;
|
||||
this.isConnected = connected;
|
||||
this.macAddress = macAddress;
|
||||
this.ipAddressAllocationMode = ipAddressAllocationMode;
|
||||
this.network = network;
|
||||
|
@ -241,7 +243,7 @@ public class NetworkConnection {
|
|||
@XmlElement(name = "MACAddress")
|
||||
protected String macAddress;
|
||||
@XmlElement(name = "IpAddressAllocationMode", required = true)
|
||||
protected String ipAddressAllocationMode;
|
||||
protected IpAddressAllocationMode ipAddressAllocationMode;
|
||||
@XmlAttribute(required = true)
|
||||
protected String network;
|
||||
@XmlAttribute
|
||||
|
@ -297,7 +299,7 @@ public class NetworkConnection {
|
|||
* @return possible object is
|
||||
* {@link String }
|
||||
*/
|
||||
public String getIpAddressAllocationMode() {
|
||||
public IpAddressAllocationMode getIpAddressAllocationMode() {
|
||||
return ipAddressAllocationMode;
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ public class UndeployVAppParams {
|
|||
@XmlEnumValue("suspend") SUSPEND("suspend"),
|
||||
@XmlEnumValue("shutdown") SHUTDOWN("shutdown"),
|
||||
@XmlEnumValue("force") FORCE("force"),
|
||||
UNRECOGNIZED("unrecognized");
|
||||
@XmlEnumValue("") UNRECOGNIZED("unrecognized");
|
||||
|
||||
public static final List<PowerAction> ALL = ImmutableList.of( POWER_OFF, SUSPEND, SHUTDOWN, FORCE );
|
||||
|
||||
|
@ -97,13 +97,21 @@ public class UndeployVAppParams {
|
|||
|
||||
public static class Builder {
|
||||
|
||||
private String undeployPowerAction;
|
||||
private PowerAction undeployPowerAction;
|
||||
|
||||
/**
|
||||
* @see UndeployVAppParams#getUndeployPowerAction()
|
||||
*/
|
||||
public Builder undeployPowerAction(PowerAction undeployPowerAction) {
|
||||
this.undeployPowerAction = undeployPowerAction;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see UndeployVAppParams#getUndeployPowerAction()
|
||||
*/
|
||||
public Builder undeployPowerAction(String undeployPowerAction) {
|
||||
this.undeployPowerAction = undeployPowerAction;
|
||||
this.undeployPowerAction = PowerAction.valueOf(undeployPowerAction);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -123,7 +131,7 @@ public class UndeployVAppParams {
|
|||
}
|
||||
|
||||
@XmlElement(name = "UndeployPowerAction")
|
||||
protected String undeployPowerAction;
|
||||
protected PowerAction undeployPowerAction;
|
||||
|
||||
/**
|
||||
* The specified action is applied to all VMs in the vApp.
|
||||
|
@ -140,7 +148,7 @@ public class UndeployVAppParams {
|
|||
*
|
||||
* @since 1.5
|
||||
*/
|
||||
public String getUndeployPowerAction() {
|
||||
public PowerAction getUndeployPowerAction() {
|
||||
return undeployPowerAction;
|
||||
}
|
||||
|
||||
|
|
|
@ -246,7 +246,7 @@ public abstract class AbstractVAppClientLiveTest extends BaseVCloudDirectorClien
|
|||
}
|
||||
|
||||
/**
|
||||
* Power on a VApp.
|
||||
* Power on a {@link VApp}s {@link Vm}s.
|
||||
*/
|
||||
protected VApp powerOn(final URI testVAppURI) {
|
||||
VApp testVApp = vAppClient.getVApp(testVAppURI);
|
||||
|
|
|
@ -32,7 +32,6 @@ import org.jclouds.http.HttpResponse;
|
|||
import org.jclouds.util.Strings2;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.OrgList;
|
||||
import org.jclouds.vcloud.director.v1_5.features.admin.AdminCatalogClient;
|
||||
import org.jclouds.vcloud.director.v1_5.internal.BaseVCloudDirectorClientLiveTest;
|
||||
import org.jclouds.xml.internal.JAXBParser;
|
||||
import org.testng.annotations.Test;
|
||||
|
@ -41,7 +40,7 @@ import com.google.common.collect.ImmutableMultimap;
|
|||
import com.google.common.collect.Iterables;
|
||||
|
||||
/**
|
||||
* Tests live behavior of {@link AdminCatalogClient}.
|
||||
* Tests live behavior of operations that use {@link HttpClient}.
|
||||
*
|
||||
* @author danikov
|
||||
*/
|
||||
|
|
|
@ -36,6 +36,7 @@ import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.R
|
|||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REQUIRED_VALUE_OBJECT_FMT;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotEquals;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
@ -73,23 +74,22 @@ import org.jclouds.vcloud.director.v1_5.domain.network.NetworkServiceType;
|
|||
import org.jclouds.vcloud.director.v1_5.domain.network.RouterInfo;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.network.SyslogServerSettings;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.network.VAppNetworkConfiguration;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.network.NetworkConnection.IpAddressAllocationMode;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.AdminOrg;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.CustomOrgLdapSettings;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.CustomOrgLdapSettings.AuthenticationMechanism;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.CustomOrgLdapSettings.ConnectorType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.Org;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.OrgEmailSettings;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.OrgGeneralSettings;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.OrgLdapGroupAttributes;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.OrgLdapSettings;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.OrgLdapSettings.LdapMode;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.OrgLdapUserAttributes;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.OrgLeaseSettings;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.OrgNetwork;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.OrgPasswordPolicySettings;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.OrgSettings;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.OrgVAppTemplateLeaseSettings;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.CustomOrgLdapSettings.AuthenticationMechanism;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.CustomOrgLdapSettings.ConnectorType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.org.OrgLdapSettings.LdapMode;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.params.ControlAccessParams;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.query.ContainerType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.query.QueryResultRecordType;
|
||||
|
@ -1255,9 +1255,8 @@ public class Checks {
|
|||
// Check required fields
|
||||
assertNotNull(val.getNetwork(), String.format(NOT_NULL_OBJ_FIELD_FMT, "Network", "NetworkConnection"));
|
||||
assertNotNull(val.getIpAddressAllocationMode(), String.format(NOT_NULL_OBJ_FIELD_FMT, "IpAddressAllocationMode", "NetworkConnection"));
|
||||
IpAddressAllocationMode mode = NetworkConnection.IpAddressAllocationMode.valueOf(val.getIpAddressAllocationMode());
|
||||
assertTrue(NetworkConnection.IpAddressAllocationMode.ALL.contains(mode),
|
||||
String.format(REQUIRED_VALUE_OBJECT_FMT, "IpAddressAllocationMode", "NetworkConnection", val.getIpAddressAllocationMode(), Iterables.toString(NetworkConnection.IpAddressAllocationMode.ALL)));
|
||||
assertNotEquals(val.getIpAddressAllocationMode(), NetworkConnection.IpAddressAllocationMode.UNRECOGNIZED,
|
||||
String.format(REQUIRED_VALUE_OBJECT_FMT, "IpAddressAllocationMode", "NetworkConnection", val.getIpAddressAllocationMode(), Iterables.toString(NetworkConnection.IpAddressAllocationMode.ALL)));
|
||||
|
||||
// Check optional fields
|
||||
if (val.getIpAddress() != null) {
|
||||
|
|
|
@ -19,8 +19,8 @@
|
|||
package org.jclouds.vcloud.director.v1_5.features;
|
||||
|
||||
import static com.google.common.base.Predicates.and;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static com.google.common.collect.Iterables.contains;
|
||||
import static com.google.common.collect.Iterables.find;
|
||||
import static com.google.common.collect.Iterables.getFirst;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CONDITION_FMT;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.CORRECT_VALUE_OBJECT_FMT;
|
||||
|
@ -58,8 +58,8 @@ import static org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates.typeEqu
|
|||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertFalse;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.fail;
|
||||
|
||||
import java.math.BigInteger;
|
||||
import java.net.URI;
|
||||
|
@ -68,15 +68,14 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.dmtf.cim.OSType;
|
||||
import org.jclouds.dmtf.cim.ResourceAllocationSettingData;
|
||||
import org.jclouds.dmtf.ovf.MsgType;
|
||||
import org.jclouds.dmtf.ovf.NetworkSection;
|
||||
import org.jclouds.dmtf.ovf.ProductSection;
|
||||
import org.jclouds.dmtf.ovf.StartupSection;
|
||||
import org.jclouds.io.Payloads;
|
||||
import org.jclouds.vcloud.director.v1_5.AbstractVAppClientLiveTest;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.AccessSetting;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Checks;
|
||||
|
@ -1286,11 +1285,7 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
Task deleteVApp = vAppClient.deleteVApp(temp.getHref());
|
||||
assertTrue(retryTaskSuccess.apply(deleteVApp), String.format(TASK_COMPLETE_TIMELY, "deleteVApp"));
|
||||
|
||||
try {
|
||||
vAppClient.getVApp(temp.getHref());
|
||||
fail("The VApp "+temp+" should have been deleted");
|
||||
} catch (VCloudDirectorException vcde) {
|
||||
assertEquals(vcde.getError().getMajorErrorCode(), Integer.valueOf(403), "The error code for deleted vApp should have been 'Forbidden' (403)");
|
||||
}
|
||||
VApp deleted = vAppClient.getVApp(temp.getHref());
|
||||
assertNull(deleted, "The VApp "+temp.getName()+" should have been deleted");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -179,8 +179,6 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseContextLiveTe
|
|||
.overrides(overrides)
|
||||
.build();
|
||||
|
||||
System.err.println("*** " + endpoint + " ***");
|
||||
|
||||
context = testSession.getUserContext();
|
||||
adminContext = testSession.getAdminContext();
|
||||
|
||||
|
@ -407,7 +405,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseContextLiveTe
|
|||
// Build the configuration object
|
||||
NetworkConfiguration networkConfiguration = NetworkConfiguration.builder()
|
||||
.parentNetwork(parentNetwork.get())
|
||||
.fenceMode(Network.FenceMode.ISOLATED)
|
||||
.fenceMode(Network.FenceMode.BRIDGED)
|
||||
.build();
|
||||
|
||||
return networkConfiguration;
|
||||
|
@ -452,7 +450,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseContextLiveTe
|
|||
}
|
||||
|
||||
// Shutdown and power off the VApp if necessary
|
||||
if (vApp.getStatus().equals(Status.POWERED_ON.getValue())) {
|
||||
if (vApp.getStatus() == Status.POWERED_ON) {
|
||||
try {
|
||||
Task shutdownTask = vAppClient.shutdown(vAppURI);
|
||||
taskDoneEventually(shutdownTask);
|
||||
|
|
|
@ -1,12 +1,8 @@
|
|||
package org.jclouds.vcloud.director.v1_5.internal;
|
||||
|
||||
import static com.google.common.base.Objects.equal;
|
||||
import static org.jclouds.vcloud.director.v1_5.VCloudDirectorLiveTestConstants.REF_REQ_LIVE;
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
import static org.testng.Assert.assertTrue;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
|
||||
import java.io.Closeable;
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.ContextBuilder;
|
||||
|
@ -14,16 +10,17 @@ import org.jclouds.logging.log4j.config.Log4JLoggingModule;
|
|||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.sshj.config.SshjSshClientModule;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorContext;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorMediaType;
|
||||
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.admin.VCloudDirectorAdminClient;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Link;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Reference;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.Role.DefaultRoles;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.User;
|
||||
import org.jclouds.vcloud.director.v1_5.predicates.LinkPredicates;
|
||||
import org.jclouds.vcloud.director.v1_5.predicates.ReferencePredicates;
|
||||
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorAsyncClient;
|
||||
import org.jclouds.vcloud.director.v1_5.user.VCloudDirectorClient;
|
||||
|
||||
import com.google.common.base.Predicates;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import com.google.common.collect.Iterables;
|
||||
import com.google.common.io.Closeables;
|
||||
|
@ -73,11 +70,8 @@ public class VCloudDirectorTestSession implements Closeable {
|
|||
}
|
||||
}
|
||||
|
||||
private VCloudDirectorContext userContext;
|
||||
private RestContext<VCloudDirectorAdminClient, VCloudDirectorAdminAsyncClient> adminContext;
|
||||
private RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> userContext;
|
||||
|
||||
private User createdAdminUser;
|
||||
private User createdUser;
|
||||
|
||||
private VCloudDirectorTestSession(String provider, String identity, String credential, Properties overrides, String endpoint) {
|
||||
ContextBuilder builder = ContextBuilder.newBuilder(provider)
|
||||
|
@ -85,77 +79,39 @@ public class VCloudDirectorTestSession implements Closeable {
|
|||
.endpoint(endpoint)
|
||||
.modules(ImmutableSet.<Module> of(new Log4JLoggingModule(), new SshjSshClientModule()))
|
||||
.overrides(overrides);
|
||||
VCloudDirectorContext rootContext = VCloudDirectorContext.class.cast(builder.build());
|
||||
userContext = VCloudDirectorContext.class.cast(builder.build());
|
||||
|
||||
if (rootContext.getApi().getCurrentSession().getLinks().contains(Link.builder()
|
||||
.rel("down")
|
||||
.type("application/vnd.vmware.admin.vcloud+xml")
|
||||
.href(URI.create(endpoint+"/admin/"))
|
||||
.build())) {
|
||||
// Look for the admin link in the current session
|
||||
Link admin = Iterables.tryFind(
|
||||
userContext.getApi().getCurrentSession().getLinks(),
|
||||
Predicates.and(LinkPredicates.relEquals(Link.Rel.DOWN), ReferencePredicates.typeEquals(VCloudDirectorMediaType.ADMIN)))
|
||||
.orNull();
|
||||
|
||||
adminContext = rootContext.getAdminContext();
|
||||
// Get the admin context if the link exists
|
||||
if (admin != null) {
|
||||
adminContext = userContext.getAdminContext();
|
||||
|
||||
Reference orgRef = Iterables.getFirst(rootContext.getApi().getOrgClient().getOrgList().getOrgs(), null)
|
||||
// Lookup the user details
|
||||
Reference orgRef = Iterables.getFirst(userContext.getApi().getOrgClient().getOrgList().getOrgs(), null)
|
||||
.toAdminReference(endpoint);
|
||||
assertNotNull(orgRef, String.format(REF_REQ_LIVE, "admin org"));
|
||||
|
||||
Reference userRef = Iterables.find(adminContext.getApi().getOrgClient().getOrg(orgRef.getHref()).getUsers(),
|
||||
Reference userRef = Iterables.find(
|
||||
adminContext.getApi().getOrgClient().getOrg(orgRef.getHref()).getUsers(),
|
||||
ReferencePredicates.nameEquals(adminContext.getApi().getCurrentSession().getUser()));
|
||||
|
||||
User user = adminContext.getApi().getUserClient().getUser(userRef.getHref());
|
||||
Reference orgAdmin = user.getRole();
|
||||
assertTrue(equal(orgAdmin.getName(), DefaultRoles.ORG_ADMIN.value()), "must give org admin or user-only credentials");
|
||||
|
||||
String adminIdentity = "testAdmin"+BaseVCloudDirectorClientLiveTest.getTestDateTimeStamp();
|
||||
String adminCredential = "testAdminPassword";
|
||||
|
||||
createdAdminUser = rootContext.getAdminContext().getApi().getUserClient().createUser(orgRef.getHref(), User.builder()
|
||||
.name(adminIdentity)
|
||||
.password(adminCredential)
|
||||
.description("test user with user-level privileges")
|
||||
.role(orgAdmin)
|
||||
.deployedVmQuota(BaseVCloudDirectorClientLiveTest.REQUIRED_ADMIN_VM_QUOTA)
|
||||
.isEnabled(true)
|
||||
.build());
|
||||
|
||||
Closeables.closeQuietly(rootContext);
|
||||
|
||||
builder.credentials(adminIdentity, adminCredential);
|
||||
adminContext = VCloudDirectorContext.class.cast(builder.build()).getAdminContext();
|
||||
|
||||
String userIdentity = "test"+BaseVCloudDirectorClientLiveTest.getTestDateTimeStamp();
|
||||
String userCredential = "testPassword";
|
||||
|
||||
createdUser = adminContext.getApi().getUserClient().createUser(orgRef.getHref(), User.builder()
|
||||
.name(userIdentity)
|
||||
.password(userCredential)
|
||||
.description("test user with user-level privileges")
|
||||
.role(BaseVCloudDirectorClientLiveTest.getRoleReferenceFor(DefaultRoles.USER.value(), adminContext))
|
||||
.deployedVmQuota(BaseVCloudDirectorClientLiveTest.REQUIRED_USER_VM_QUOTA)
|
||||
.isEnabled(true)
|
||||
.build());
|
||||
|
||||
builder.credentials(userIdentity, userCredential);
|
||||
userContext = VCloudDirectorContext.class.cast(builder.build());
|
||||
} else {
|
||||
userContext = rootContext;
|
||||
// Check that the user has the org admin role
|
||||
Reference userRole = user.getRole();
|
||||
assertEquals(userRole.getName(), DefaultRoles.ORG_ADMIN.value());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() {
|
||||
if (createdUser != null) {
|
||||
adminContext.getApi().getUserClient().deleteUser(createdUser.getHref());
|
||||
}
|
||||
if (userContext != null) userContext.close();
|
||||
if (createdAdminUser != null) {
|
||||
// TODO: may have to preserve root context if we can't delete the user for it's own context here
|
||||
adminContext.getApi().getUserClient().deleteUser(createdAdminUser.getHref());
|
||||
}
|
||||
if (adminContext != null) adminContext.close();
|
||||
Closeables.closeQuietly(userContext);
|
||||
Closeables.closeQuietly(adminContext);
|
||||
}
|
||||
|
||||
public RestContext<VCloudDirectorClient, VCloudDirectorAsyncClient> getUserContext() {
|
||||
public VCloudDirectorContext getUserContext() {
|
||||
return userContext;
|
||||
}
|
||||
|
||||
|
|
|
@ -23,14 +23,14 @@ import static org.testng.Assert.assertNotNull;
|
|||
import static org.testng.Assert.assertTrue;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.jclouds.Constants;
|
||||
import org.jclouds.apis.ApiMetadata;
|
||||
import org.jclouds.ContextBuilder;
|
||||
import org.jclouds.apis.BaseContextLiveTest;
|
||||
import org.jclouds.rest.AnonymousRestApiMetadata;
|
||||
import org.jclouds.providers.AnonymousProviderMetadata;
|
||||
import org.jclouds.providers.ProviderMetadata;
|
||||
import org.jclouds.rest.RestContext;
|
||||
import org.jclouds.vcloud.director.testng.FormatApiResultsListener;
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorConstants;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.SessionWithToken;
|
||||
import org.testng.annotations.BeforeGroups;
|
||||
import org.testng.annotations.Listeners;
|
||||
|
@ -39,18 +39,20 @@ import org.testng.annotations.Test;
|
|||
import com.google.common.reflect.TypeToken;
|
||||
|
||||
/**
|
||||
* Tests behavior of {@code SessionClient}. Note this class is tested completely independently of
|
||||
* VCloudClient as it is a dependency of the VCloud context working.
|
||||
* Tests behavior of {@link SessionClient}. Note this class is tested completely independently of
|
||||
* {@link VCloudDirectorClient} as it is a dependency of the {@code vcloud-director} context working.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Listeners(FormatApiResultsListener.class)
|
||||
@Test(groups = { "live", "user", "login" }, testName = "SessionClientLiveTest")
|
||||
@Test(groups = { "live", "user" }, testName = "SessionClientLiveTest")
|
||||
public class SessionClientLiveTest extends BaseContextLiveTest<RestContext<SessionClient, SessionAsyncClient>> {
|
||||
|
||||
public SessionClientLiveTest() {
|
||||
provider = "vcloud-director";
|
||||
}
|
||||
|
||||
@Override
|
||||
@BeforeGroups(groups = { "live" })
|
||||
public void setupContext() {
|
||||
super.setupContext();
|
||||
|
@ -60,25 +62,6 @@ public class SessionClientLiveTest extends BaseContextLiveTest<RestContext<Sessi
|
|||
|
||||
private SessionClient client;
|
||||
private SessionWithToken sessionWithToken;
|
||||
|
||||
//temporary until we marry up the test fixtures
|
||||
|
||||
protected String identity;
|
||||
protected String credential;
|
||||
protected String endpoint;
|
||||
|
||||
@Override
|
||||
protected Properties setupProperties() {
|
||||
Properties overrides = new Properties();
|
||||
overrides.setProperty(Constants.PROPERTY_TRUST_ALL_CERTS, "true");
|
||||
overrides.setProperty(Constants.PROPERTY_RELAX_HOSTNAME, "true");
|
||||
identity = setIfTestSystemPropertyPresent(overrides, provider + ".identity");
|
||||
credential = setIfTestSystemPropertyPresent(overrides, provider + ".credential");
|
||||
endpoint = setIfTestSystemPropertyPresent(overrides, provider + ".endpoint");
|
||||
setIfTestSystemPropertyPresent(overrides, provider + ".api-version");
|
||||
setIfTestSystemPropertyPresent(overrides, provider + ".build-version");
|
||||
return overrides;
|
||||
}
|
||||
|
||||
@Test(testName = "POST /sessions")
|
||||
public void testLogin() {
|
||||
|
@ -103,17 +86,22 @@ public class SessionClientLiveTest extends BaseContextLiveTest<RestContext<Sessi
|
|||
public void testLogout() {
|
||||
client.logoutSessionWithToken(sessionWithToken.getSession().getHref(), sessionWithToken.getToken());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ApiMetadata createApiMetadata() {
|
||||
return AnonymousRestApiMetadata.forClientMappedToAsyncClient(SessionClient.class, SessionAsyncClient.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected TypeToken<RestContext<SessionClient, SessionAsyncClient>> contextType() {
|
||||
return new TypeToken<RestContext<SessionClient, SessionAsyncClient>>(){
|
||||
|
||||
/** The serialVersionUID */
|
||||
private static final long serialVersionUID = -3625362618882122604L;};
|
||||
return VCloudDirectorConstants.SESSION_CONTEXT_TYPE;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ProviderMetadata createProviderMetadata() {
|
||||
return AnonymousProviderMetadata.forClientMappedToAsyncClientOnEndpoint(SessionClient.class, SessionAsyncClient.class, endpoint);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected ContextBuilder newBuilder() {
|
||||
ProviderMetadata pm = createProviderMetadata();
|
||||
ContextBuilder builder = ContextBuilder.newBuilder(pm);
|
||||
return builder;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue