mirror of https://github.com/apache/jclouds.git
Issue 830: Fix random names
This commit is contained in:
parent
a8c1228f7b
commit
5b4dbcd659
|
@ -29,7 +29,6 @@ import static org.testng.Assert.assertTrue;
|
|||
import static org.testng.Assert.fail;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Random;
|
||||
|
||||
import org.jclouds.vcloud.director.v1_5.VCloudDirectorException;
|
||||
import org.jclouds.vcloud.director.v1_5.domain.AdminCatalog;
|
||||
|
@ -67,7 +66,6 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
* Shared state between dependant tests.
|
||||
*/
|
||||
|
||||
private final Random random = new Random();
|
||||
private Reference orgRef;
|
||||
private AdminCatalog catalog;
|
||||
private Owner owner;
|
||||
|
@ -82,7 +80,7 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
@Test(testName = "POST /admin/org/{id}/catalogs")
|
||||
public void testCreateCatalog() {
|
||||
AdminCatalog newCatalog = AdminCatalog.builder()
|
||||
.name("Test Catalog " + random.nextInt())
|
||||
.name(name("Test Catalog "))
|
||||
.description("created by testCreateCatalog()")
|
||||
.build();
|
||||
catalog = catalogClient.createCatalog(orgRef.getHref(), newCatalog);
|
||||
|
@ -196,7 +194,7 @@ public class AdminCatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest
|
|||
// String.format(OBJ_FIELD_EMPTY_TO_DELETE, "Catalog", "CatalogItems",
|
||||
// catalog.getCatalogItems().getCatalogItems().toString()));
|
||||
AdminCatalog deleteCatalog = AdminCatalog.builder()
|
||||
.name("Test Catalog " + random.nextInt())
|
||||
.name(name("Test Catalog "))
|
||||
.description("created by testCreateCatalog()")
|
||||
.build();
|
||||
deleteCatalog = catalogClient.createCatalog(orgRef.getHref(), deleteCatalog);
|
||||
|
|
|
@ -93,7 +93,7 @@ public class AdminVdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
@Test(testName = "PUT /admin/vdc/{id}", enabled=false)
|
||||
public void testEditVdc() throws Exception {
|
||||
String origName = vdcClient.getVdc(adminVdcUri).getName();
|
||||
String newName = "a"+random.nextInt(Integer.MAX_VALUE);
|
||||
String newName = name("a");
|
||||
Exception exception = null;
|
||||
|
||||
AdminVdc vdc = AdminVdc.builder()
|
||||
|
@ -175,8 +175,8 @@ public class AdminVdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
// TODO insufficient permissions to test
|
||||
@Test(testName = "PUT /admin/vdc/{id}/metadata", enabled=false)
|
||||
public void testSetMetadata() throws Exception {
|
||||
metadataKey = ""+random.nextInt(Integer.MAX_VALUE);
|
||||
metadataValue = ""+random.nextInt(Integer.MAX_VALUE);
|
||||
metadataKey = name("key-");
|
||||
metadataValue = name("value-");
|
||||
Metadata metadata = Metadata.builder()
|
||||
.entry(MetadataEntry.builder().entry(metadataKey, metadataValue).build())
|
||||
.build();
|
||||
|
@ -200,7 +200,7 @@ public class AdminVdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
// TODO insufficient permissions to test
|
||||
@Test(testName = "PUT /admin/vdc/{id}/metadata", dependsOnMethods = { "testGetMetadataValue" }, enabled=false )
|
||||
public void testSetMetadataValue() throws Exception {
|
||||
metadataValue = ""+random.nextInt(Integer.MAX_VALUE);
|
||||
metadataValue = name("value-");
|
||||
MetadataValue newV = MetadataValue.builder().value(metadataValue).build();
|
||||
|
||||
Task task = metadataClient.setMetadata(adminVdcUri, metadataKey, newV);
|
||||
|
|
|
@ -73,7 +73,7 @@ public class CatalogClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
Reference orgRef = Iterables.getFirst(context.getApi().getOrgClient().getOrgList().getOrgs(), null).toAdminReference(endpoint);
|
||||
|
||||
AdminCatalog newCatalog = AdminCatalog.builder()
|
||||
.name("Test Catalog " + random.nextInt())
|
||||
.name(name("Test Catalog "))
|
||||
.description("created by CatalogClientLiveTest")
|
||||
.build();
|
||||
|
||||
|
|
|
@ -127,7 +127,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
|
||||
public static User randomTestUser(String prefix, Reference role) {
|
||||
return User.builder()
|
||||
.name(prefix+random.nextInt())
|
||||
.name(name(prefix))
|
||||
.fullName("testFullName")
|
||||
.emailAddress("test@test.com")
|
||||
.telephone("555-1234")
|
||||
|
@ -267,7 +267,7 @@ public class UserClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
dependsOnMethods = { "testCreateUser" } )
|
||||
public void testDeleteUser() {
|
||||
// Create a user to be deleted (so we remove dependencies on test ordering)
|
||||
String name = "a"+random.nextInt();
|
||||
String name = name("a");
|
||||
User newUser = User.builder()
|
||||
.name(name)
|
||||
.role(Reference.builder() // FIXME: auto-fetch a role? or inject
|
||||
|
|
|
@ -142,7 +142,7 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
@Test(testName = "PUT /vApp/{id}", dependsOnMethods = { "testGetVApp" })
|
||||
public void testModifyVApp() {
|
||||
VApp newVApp = VApp.builder()
|
||||
.name("new-name-" + Integer.toString(random.nextInt(Integer.MAX_VALUE)))
|
||||
.name(name("new-name-"))
|
||||
.description("New Description")
|
||||
.build();
|
||||
vAppNames.add(newVApp.getName());
|
||||
|
@ -1095,8 +1095,8 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
@Test(testName = "PUT & GET /vApp/{id}/metadata", dependsOnMethods = { "testGetMetadata" })
|
||||
public void testSetAndGetMetadataValue() {
|
||||
// Store a value
|
||||
String key = Integer.toString(random.nextInt(Integer.MAX_VALUE));
|
||||
String value = Integer.toString(random.nextInt(Integer.MAX_VALUE));
|
||||
String key = name("key-");
|
||||
String value = name("value-");
|
||||
MetadataValue metadataValue = MetadataValue.builder().value(value).build();
|
||||
vAppClient.getMetadataClient().setMetadata(vApp.getHref(), key, metadataValue);
|
||||
|
||||
|
@ -1110,7 +1110,7 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
@Test(testName = "DELETE /vApp/{id}/metadata/{key}", dependsOnMethods = { "testSetAndGetMetadataValue" })
|
||||
public void testDeleteMetadataEntry() {
|
||||
// Store a value, to be deleted
|
||||
String key = Integer.toString(random.nextInt(Integer.MAX_VALUE));
|
||||
String key = name("key-");
|
||||
MetadataValue metadataValue = MetadataValue.builder().value("myval").build();
|
||||
vAppClient.getMetadataClient().setMetadata(vApp.getHref(), key, metadataValue);
|
||||
|
||||
|
@ -1131,8 +1131,8 @@ public class VAppClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
Map<String, String> oldMetadataMap = Checks.metadataToMap(oldMetadata);
|
||||
|
||||
// Store a value, to be deleted
|
||||
String key = Integer.toString(random.nextInt(Integer.MAX_VALUE));
|
||||
String value = Integer.toString(random.nextInt(Integer.MAX_VALUE));
|
||||
String key = name("key-");
|
||||
String value = name("value-");
|
||||
Metadata addedMetadata = Metadata.builder()
|
||||
.entry(MetadataEntry.builder().key(key).value(value).build())
|
||||
.build();
|
||||
|
|
|
@ -191,9 +191,8 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testEditVAppTemplate() {
|
||||
String uid = ""+random.nextInt();
|
||||
String name = "myname-"+uid;
|
||||
String description = "mydescr-"+uid;
|
||||
String name = name("myname-");
|
||||
String description = name("Description ");
|
||||
VAppTemplate template = VAppTemplate.builder()
|
||||
.name(name)
|
||||
.description(description)
|
||||
|
@ -214,9 +213,8 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
Metadata oldMetadata = vAppTemplateClient.getMetadataClient().getMetadata(vAppTemplateURI);
|
||||
Map<String,String> oldMetadataMap = metadataToMap(oldMetadata);
|
||||
|
||||
String uid = ""+random.nextInt();
|
||||
String key = "mykey-"+uid;
|
||||
String val = "myval-"+uid;
|
||||
String key = name("key-");
|
||||
String val = name("value-");
|
||||
MetadataEntry metadataEntry = MetadataEntry.builder().entry(key, val).build();
|
||||
Metadata metadata = Metadata.builder().fromMetadata(oldMetadata).entry(metadataEntry).build();
|
||||
|
||||
|
@ -235,9 +233,8 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
public void testEditMetadataValue() {
|
||||
// TODO Cleanup after ourselves..
|
||||
|
||||
String uid = ""+random.nextInt();
|
||||
String key = "mykey-"+uid;
|
||||
String val = "myval-"+uid;
|
||||
String key = name("key-");
|
||||
String val = name("value-");
|
||||
MetadataValue metadataValue = MetadataValue.builder().value(val).build();
|
||||
|
||||
final Task task = vAppTemplateClient.getMetadataClient().setMetadata(vAppTemplateURI, key, metadataValue);
|
||||
|
@ -250,7 +247,7 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
@Test
|
||||
public void testDeleteVAppTemplateMetadataValue() {
|
||||
// First store a value
|
||||
String key = "mykey-"+random.nextInt();
|
||||
String key = name("key-");
|
||||
MetadataValue metadataValue = MetadataValue.builder().value("myval").build();
|
||||
final Task task = vAppTemplateClient.getMetadataClient().setMetadata(vAppTemplateURI, key, metadataValue);
|
||||
retryTaskSuccess.apply(task);
|
||||
|
@ -266,7 +263,7 @@ public class VAppTemplateClientLiveTest extends AbstractVAppClientLiveTest {
|
|||
|
||||
@Test
|
||||
public void testEditGuestCustomizationSection() {
|
||||
String computerName = "a"+random.nextInt(Integer.MAX_VALUE);
|
||||
String computerName = name("server-");
|
||||
GuestCustomizationSection newSection = GuestCustomizationSection.builder()
|
||||
.info("my info")
|
||||
.computerName(computerName)
|
||||
|
|
|
@ -127,7 +127,7 @@ public class VdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
|
||||
@Test(testName = "POST /vdc/{id}/action/captureVApp", dependsOnMethods = { "testInstantiateVAppTemplate" } )
|
||||
public void testCaptureVApp() {
|
||||
String name = "captured-"+random.nextInt(Integer.MAX_VALUE);
|
||||
String name = name("captured-");
|
||||
|
||||
CaptureVAppParams captureVappParams = CaptureVAppParams.builder()
|
||||
.name(name)
|
||||
|
@ -191,7 +191,7 @@ public class VdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
|
||||
@Test(testName = "POST /vdc/{id}/action/composeVApp")
|
||||
public void testComposeVApp() {
|
||||
String name = "composed-"+random.nextInt(Integer.MAX_VALUE);
|
||||
String name = name("composed-");
|
||||
|
||||
composedVApp = vdcClient.composeVApp(vdcURI, ComposeVAppParams.builder()
|
||||
.name(name)
|
||||
|
@ -257,7 +257,7 @@ public class VdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
.build();
|
||||
|
||||
InstantiateVAppTemplateParams instantiate = InstantiateVAppTemplateParams.builder()
|
||||
.name("test-vapp-"+random.nextInt(Integer.MAX_VALUE))
|
||||
.name(name("test-vapp-"))
|
||||
.notDeploy()
|
||||
.notPowerOn()
|
||||
.description("Test VApp")
|
||||
|
@ -280,7 +280,7 @@ public class VdcClientLiveTest extends BaseVCloudDirectorClientLiveTest {
|
|||
// 3. uploading disks described from the OVF
|
||||
// 4. finishing task for uploading
|
||||
|
||||
String name = "uploaded-"+random.nextInt(Integer.MAX_VALUE);
|
||||
String name = name("uploaded-");
|
||||
|
||||
UploadVAppTemplateParams uploadVAppTemplateParams = UploadVAppTemplateParams.builder()
|
||||
.name(name)
|
||||
|
|
|
@ -253,7 +253,7 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
|
|||
* @return the VApp that is being instantiated
|
||||
*/
|
||||
protected VApp instantiateVApp() {
|
||||
return instantiateVApp("test-vapp-" + random.nextInt(Integer.MAX_VALUE));
|
||||
return instantiateVApp(name("test-vapp-"));
|
||||
}
|
||||
|
||||
protected VApp instantiateVApp(String name) {
|
||||
|
@ -396,4 +396,8 @@ public abstract class BaseVCloudDirectorClientLiveTest extends BaseVersionedServ
|
|||
logger.warn(e, "Deleting vApp failed: vApp="+vApp);
|
||||
}
|
||||
}
|
||||
|
||||
public static String name(String prefix) {
|
||||
return prefix + Integer.toString(random.nextInt(Integer.MAX_VALUE));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue