use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class TestProvisionAWSSecurityGroup method setUp.
@Before
public void setUp() throws Exception {
CommandLineArgumentParser.parseFromProperties(this);
// ignore if any of the required properties are missing
org.junit.Assume.assumeTrue(TestUtils.isNull(this.privateKey, this.privateKeyId, this.region, this.vpcId, this.subnetId));
try {
PhotonModelServices.startServices(this.host);
PhotonModelMetricServices.startServices(this.host);
PhotonModelTaskServices.startServices(this.host);
PhotonModelAdaptersRegistryAdapters.startServices(this.host);
AWSAdaptersTestUtils.startServicesSynchronously(this.host);
// start the aws sg service
this.host.startService(Operation.createPost(UriUtils.buildUri(this.host, AWSSecurityGroupService.class)), new AWSSecurityGroupService());
this.provisionSecurityGroupFactory = UriUtils.buildUri(this.host, ProvisionSecurityGroupTaskService.FACTORY_LINK);
this.netClient = new AWSNetworkClient(TestUtils.getClient(this.privateKeyId, this.privateKey, this.region, false));
this.vpc = this.netClient.getVPC(this.vpcId);
assertNotNull(this.vpc);
AuthCredentialsServiceState creds = new AuthCredentialsServiceState();
creds.privateKey = this.privateKey;
creds.privateKeyId = this.privateKeyId;
TestContext ec2WaitContext = new TestContext(1, Duration.ofSeconds(30L));
AWSUtils.getEc2AsyncClient(creds, this.region, getExecutor()).exceptionally(t -> {
ec2WaitContext.fail(t);
throw new CompletionException(t);
}).thenAccept(ec2Client -> {
this.ec2client = ec2Client;
ec2WaitContext.complete();
});
ec2WaitContext.await();
} catch (Throwable e) {
throw new Exception(e);
}
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class BaseTestCase method waitForServiceAvailability.
protected void waitForServiceAvailability(ServiceHost h, String... serviceLinks) throws Throwable {
if (serviceLinks == null || serviceLinks.length == 0) {
throw new IllegalArgumentException("null or empty serviceLinks");
}
TestContext ctx = testCreate(serviceLinks.length);
h.registerForServiceAvailability(ctx.getCompletion(), serviceLinks);
ctx.await();
}
use of com.vmware.xenon.common.test.TestContext in project photon-model by vmware.
the class BaseTestCase method verifyService.
protected void verifyService(URI factoryUri, FactoryService factoryInstance, Class<? extends ServiceDocument> serviceDocumentType, TestServiceDocumentInitialization serviceDocumentInit, TestServiceDocumentAssertion assertion) throws Throwable {
int childCount = 1;
TestContext ctx = testCreate(childCount);
String prefix = "example-";
URI[] childURIs = new URI[childCount];
for (int i = 0; i < childCount; i++) {
ServiceDocument serviceDocument = serviceDocumentInit.create(prefix, i);
final int finalI = i;
// create a ServiceDocument instance.
Operation createPost = createForcedPost(factoryUri).setBody(serviceDocument).setCompletion((o, e) -> {
if (e != null) {
ctx.failIteration(e);
return;
}
ServiceDocument rsp = o.getBody(serviceDocumentType);
childURIs[finalI] = UriUtils.buildUri(this.host, rsp.documentSelfLink);
ctx.completeIteration();
});
this.host.send(createPost);
}
try {
// verify factory and service instance wiring.
factoryInstance.setHost(this.host);
Service serviceInstance = factoryInstance.createServiceInstance();
serviceInstance.setHost(this.host);
assertNotNull(serviceInstance);
ctx.await();
// do GET on all child URIs
Map<URI, ? extends ServiceDocument> childStates = this.host.getServiceState(null, serviceDocumentType, childURIs);
for (ServiceDocument s : childStates.values()) {
assertion.assertState(prefix, s);
}
// verify template GET works on factory
ServiceDocumentQueryResult templateResult = this.host.getServiceState(null, ServiceDocumentQueryResult.class, UriUtils.extendUri(factoryUri, ServiceHost.SERVICE_URI_SUFFIX_TEMPLATE));
assertTrue(templateResult.documentLinks.size() == templateResult.documents.size());
ServiceDocument childTemplate = Utils.fromJson(templateResult.documents.get(templateResult.documentLinks.iterator().next()), serviceDocumentType);
assertTrue(childTemplate.documentDescription != null);
assertTrue(childTemplate.documentDescription.propertyDescriptions != null && childTemplate.documentDescription.propertyDescriptions.size() > 0);
} catch (Throwable t) {
if (t instanceof RuntimeException) {
throw t;
}
throw new RuntimeException(t);
}
}
Aggregations