use of com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription in project photon-model by vmware.
the class AzureSubscriptionEndpointsEnumerationServiceTest method testAddSecondAzureSubscription.
private void testAddSecondAzureSubscription() throws Throwable {
// Request for creating computes for 1 Azure Subscriptions
AzureSubscription subscription = getAzureSubscription(SUBSCRIPTION_ID_2, ACCOUNT_ID_2);
createAzureEndpointsForSubscriptions(Collections.singletonList(subscription));
// Query the Endpoints to assert
ServiceDocumentQueryResult result = this.host.getExpandedFactoryState(UriUtils.buildUri(this.host, EndpointService.FACTORY_LINK));
Assert.assertEquals(3, result.documents.size());
// Assert the created Endpoint and other resources
result.documents.remove(this.endpointLink);
// Remove the endpoints created earlier
this.createdEndpointLinks.forEach(endpoint -> result.documents.remove(endpoint));
EndpointState endpointStateCreated = Utils.fromJson(result.documents.values().iterator().next(), EndpointState.class);
assertCreatedEndpoint(endpointStateCreated, SUBSCRIPTION_ID_2);
this.createdEndpointLinks.add(endpointStateCreated.documentSelfLink);
// Assert the root compute under the endpoint
ComputeState computeStateCreated = getServiceSynchronously(endpointStateCreated.computeLink, ComputeState.class);
assertCreatedComputeState(computeStateCreated, SUBSCRIPTION_ID_2, ACCOUNT_ID_2);
// Assert the partial AuthCredentialsState
AuthCredentialsServiceState authCreated = getServiceSynchronously(endpointStateCreated.authCredentialsLink, AuthCredentialsServiceState.class);
assertAuthCredentialState(authCreated, SUBSCRIPTION_ID_2);
}
use of com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription in project photon-model by vmware.
the class AzureSubscriptionsEnumerationServiceTest method testConstructSubscriptionName.
@Test
public void testConstructSubscriptionName() {
String subzId = "subscriptionId";
String accountOwnerId = "account@ownerId.com";
String accountName = "Account Name";
String subzName = "Subscription Name";
AzureSubscription subz = new AzureSubscription();
subz.entityId = subzId;
subz.parentEntityId = accountOwnerId;
subz.parentEntityName = accountName;
subz.entityName = subzName;
String constructedSubzName = AzureUtils.constructSubscriptionName(subz);
String correctSubzName = accountName + COMPUTE_NAME_SEPARATOR + subzName;
Assert.assertEquals("Subscription name is not correct.", correctSubzName, constructedSubzName);
// if account name is not available, subscription ID should be displayed
subz.parentEntityName = null;
correctSubzName = subzId;
constructedSubzName = AzureUtils.constructSubscriptionName(subz);
Assert.assertEquals("Subscription name is not correct.", correctSubzName, constructedSubzName);
// if account name is not available, subscription ID should be displayed
subz.parentEntityName = " ";
correctSubzName = subzId;
constructedSubzName = AzureUtils.constructSubscriptionName(subz);
Assert.assertEquals("Subscription name is not correct.", correctSubzName, constructedSubzName);
// if subscription name is not available, subscription ID should be displayed
subz.entityName = " ";
correctSubzName = subzId;
constructedSubzName = AzureUtils.constructSubscriptionName(subz);
Assert.assertEquals("Subscription name is not correct.", correctSubzName, constructedSubzName);
}
use of com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription in project photon-model by vmware.
the class AzureSubscriptionsEnumerationServiceTest method testAddMoreAzureSubscriptions.
private void testAddMoreAzureSubscriptions() throws Throwable {
// Request for creating computes for another Azure Subscriptions
AzureSubscription subscription = getAzureSubscription(SUBSCRIPTION_ID_2, ACCOUNT_EMAIL_ID_2);
createAzureCostComputesForSubscriptions(Collections.singletonList(subscription));
// Query for Azure Computes created with CLIENT_ID as enrollment Number
QueryTask task = createQueryTaskForAzureComputes(ENROLLMENT_NUMNBER, Collections.singletonList(TENANT_ID));
QueryTask queryTaskResponse = executQuerySynchronously(task);
assertQueryTaskResponse(queryTaskResponse, 4);
// Remove compute for existing subscription
ComputeState existingSubsCs = Utils.fromJson(queryTaskResponse.results.documents.remove(this.existingSubsComputeLink1), ComputeState.class);
Assert.assertNotNull(existingSubsCs);
Assert.assertNull(existingSubsCs.customProperties.get(PhotonModelConstants.AUTO_DISCOVERED_ENTITY));
// Remove the already asserted computes
this.createdComputeLinks.stream().forEach(computeLnk -> {
queryTaskResponse.results.documents.remove(computeLnk);
});
// Get and assert the returned compute
ComputeState cs = Utils.fromJson(queryTaskResponse.results.documents.values().iterator().next(), ComputeState.class);
assertPropertiesOfComputeState(cs, ENROLLMENT_NUMNBER, SUBSCRIPTION_ID_2, ACCOUNT_EMAIL_ID_2, this.compute.endpointLink, this.compute.tenantLinks);
this.createdComputeLinks.add(cs.documentSelfLink);
}
use of com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription in project photon-model by vmware.
the class AzureSubscriptionsEnumerationServiceTest method testAddNonEaAzureSubscriptionLater.
private void testAddNonEaAzureSubscriptionLater() throws Throwable {
// Create Azure non-ea endpoints
EndpointState nonEaEp3 = createNonEaEndpointState(SUBSCRIPTION_ID_2);
EndpointAllocationTaskState state3 = createEndpoint(nonEaEp3);
this.existingSubsComputeLink3 = state3.endpointState.computeLink;
AzureSubscription subscription1 = getAzureSubscription(SUBSCRIPTION_ID_1, ACCOUNT_EMAIL_ID_1);
AzureSubscription subscription2 = getAzureSubscription(SUBSCRIPTION_ID_2, ACCOUNT_EMAIL_ID_2);
AzureSubscription existingSubscription2 = getAzureSubscription(SUBSCRIPTION_EXISTING_2, ACCOUNT_EMAIL_ID_2);
createAzureCostComputesForSubscriptions(Arrays.asList(subscription1, subscription2, existingSubscription2));
// Query for Azure Computes created with CLIENT_ID as enrollment Number
QueryTask task = createQueryTaskForAzureComputes(ENROLLMENT_NUMNBER, Collections.singletonList(TENANT_ID));
QueryTask queryTaskResponse = executQuerySynchronously(task);
assertQueryTaskResponse(queryTaskResponse, 7);
}
use of com.vmware.photon.controller.model.adapters.azure.model.cost.AzureSubscription in project photon-model by vmware.
the class AzureSubscriptionsEnumerationServiceTest method getAzureSubscription.
private AzureSubscription getAzureSubscription(String subscriptionId, String accountId) {
AzureSubscription subscription = new AzureSubscription();
subscription.entityId = subscriptionId;
subscription.parentEntityId = accountId;
return subscription;
}
Aggregations