Search in sources :

Example 11 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project photon-model by vmware.

the class TestAWSClientManagement method testAWSClientManagementArnDr.

@Test
public void testAWSClientManagementArnDr() throws Throwable {
    this.ec2ClientReferenceCount = getClientReferenceCount(AwsClientType.EC2);
    this.host.setTimeoutSeconds(60);
    // Getting a reference to client managers in the test
    AWSClientManager ec2ClientManager = getClientManager(AwsClientType.EC2);
    ec2ClientManager.cleanUpArnCache();
    assertEquals(this.ec2ClientReferenceCount + 1, getClientReferenceCount(AwsClientType.EC2));
    this.creds = new AuthCredentialsServiceState();
    this.creds.customProperties = new HashMap<>();
    this.creds.customProperties.put(ARN_KEY, this.arn);
    this.creds.customProperties.put(EXTERNAL_ID_KEY, this.externalId);
    TestContext waitContext = new TestContext(1, Duration.ofSeconds(30L));
    ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
        waitContext.fail(t);
        throw new CompletionException(t);
    }).thenAccept(ec2Client -> {
        this.client = ec2Client;
        waitContext.complete();
    });
    waitContext.await();
    Assert.assertNotNull(this.client);
    this.clientCacheCount = ec2ClientManager.getCacheCount();
    // Requesting another AWS client with the same set of credentials will not
    // create a new entry in the cache
    AmazonEC2AsyncClient oldClient = this.client;
    TestContext nextContext = new TestContext(1, Duration.ofSeconds(30L));
    ec2ClientManager.getOrCreateEC2ClientAsync(this.creds, TestAWSSetupUtils.regionId, this.instanceService).exceptionally(t -> {
        nextContext.fail(t);
        throw new CompletionException(t);
    }).thenAccept(ec2Client -> {
        this.client = ec2Client;
        nextContext.complete();
    });
    nextContext.await();
    Assert.assertNotNull(this.client);
    Assert.assertEquals(oldClient, this.client);
    assertEquals(this.clientCacheCount, ec2ClientManager.getCacheCount());
}
Also used : AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) BeforeClass(org.junit.BeforeClass) HashMap(java.util.HashMap) AWSClientManagerFactory.returnClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory.returnClientManager) AWSClientManagerFactory.getClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory.getClientManager) AWSClientManagerFactory.getClientReferenceCount(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory.getClientReferenceCount) ArrayList(java.util.ArrayList) Level(java.util.logging.Level) CommandLineArgumentParser(com.vmware.xenon.common.CommandLineArgumentParser) AWSSecurityTokenServiceException(com.amazonaws.services.securitytoken.model.AWSSecurityTokenServiceException) Duration(java.time.Duration) After(org.junit.After) EXTERNAL_ID_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.EXTERNAL_ID_KEY) AWS_ARN_DEFAULT_SESSION_DURATION_SECONDS_PROPERTY(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.AWS_ARN_DEFAULT_SESSION_DURATION_SECONDS_PROPERTY) AwsClientType(com.vmware.photon.controller.model.adapters.awsadapter.AWSConstants.AwsClientType) BasicReusableHostTestCase(com.vmware.xenon.common.BasicReusableHostTestCase) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) Before(org.junit.Before) StatelessService(com.vmware.xenon.common.StatelessService) AWS_MASTER_ACCOUNT_ACCESS_KEY_PROPERTY(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.AWS_MASTER_ACCOUNT_ACCESS_KEY_PROPERTY) Operation(com.vmware.xenon.common.Operation) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test) AmazonS3Client(com.amazonaws.services.s3.AmazonS3Client) Assert.assertNotEquals(org.junit.Assert.assertNotEquals) AWS_MASTER_ACCOUNT_SECRET_KEY_PROPERTY(com.vmware.photon.controller.model.adapters.awsadapter.AWSUtils.AWS_MASTER_ACCOUNT_SECRET_KEY_PROPERTY) TimeUnit(java.util.concurrent.TimeUnit) List(java.util.List) TestContext(com.vmware.xenon.common.test.TestContext) Ignore(org.junit.Ignore) ARN_KEY(com.vmware.photon.controller.model.adapterapi.EndpointConfigRequest.ARN_KEY) UriUtils(com.vmware.xenon.common.UriUtils) Assume.assumeTrue(org.junit.Assume.assumeTrue) AWSClientManagerFactory(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManagerFactory) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) AWSClientManager(com.vmware.photon.controller.model.adapters.awsadapter.util.AWSClientManager) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) AmazonEC2AsyncClient(com.amazonaws.services.ec2.AmazonEC2AsyncClient) TestContext(com.vmware.xenon.common.test.TestContext) CompletionException(java.util.concurrent.CompletionException) Test(org.junit.Test)

Example 12 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project photon-model by vmware.

the class TestAzureLongRunningEnumeration method testLongRunEnumeration.

@Test
public void testLongRunEnumeration() throws Throwable {
    // Log node stats at the beginning of the test
    logNodeStats(this.host.getServiceStats(this.nodeStatsUri));
    // 1. Provision VMs
    List<ProvisionComputeTaskState> taskStates = new ArrayList<>();
    for (int i = 0; i < numOfVMsToTest; i++) {
        this.storageDescriptions.add(createDefaultStorageAccountDescription(this.host, this.mockedStorageAccountName, computeHost, endpointState));
        this.resourceGroupStates.add(createDefaultResourceGroupState(this.host, this.mockedStorageAccountName, computeHost, endpointState, ResourceGroupStateType.AzureResourceGroup));
        this.diskStates.add(createDefaultDiskState(this.host, this.mockedStorageAccountName, this.mockedStorageAccountName, computeHost, endpointState));
        // create an Azure VM compute resource (this also creates a disk and a storage account)
        this.vmStates.add(createDefaultVMResource(this.host, azureVMNames.get(i), computeHost, endpointState, nicSpecs.get(i)));
        // kick off a provision task to do the actual VM creation
        ProvisionComputeTaskState provisionTask = new ProvisionComputeTaskState();
        provisionTask.computeLink = this.vmStates.get(i).documentSelfLink;
        provisionTask.isMockRequest = this.isMock;
        provisionTask.taskSubStage = SubStage.CREATING_HOST;
        taskStates.add(TestUtils.doPost(this.host, provisionTask, ProvisionComputeTaskState.class, UriUtils.buildUri(this.host, ProvisionComputeTaskService.FACTORY_LINK)));
    }
    for (ProvisionComputeTaskState taskState : taskStates) {
        this.host.waitForFinishedTask(ProvisionComputeTaskState.class, taskState.documentSelfLink);
    }
    this.host.log(Level.INFO, "VMs provisioned successfully.");
    // Check resources have been created
    // expected VM count = numOfVMsToTest + 1 (1 compute host instance + numOfVMsToTest vm compute state)
    ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.host, numOfVMsToTest + 1, ComputeService.FACTORY_LINK, false);
    ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.host, numOfVMsToTest, StorageDescriptionService.FACTORY_LINK, false);
    ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.host, numOfVMsToTest, ResourceGroupService.FACTORY_LINK, false);
    ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.host, numOfVMsToTest, DiskService.FACTORY_LINK, false);
    Map<String, ComputeState> azLrtComputeStates = getVMComputeStatesWithPrefix();
    Assert.assertEquals(numOfVMsToTest, azLrtComputeStates.size());
    if (this.isMock) {
        runEnumeration(this.host, computeHost.documentSelfLink, computeHost.resourcePoolLink, endpointState, this.isMock);
        for (int i = 0; i < numOfVMsToTest; i++) {
            deleteVMs(this.host, this.vmStates.get(i).documentSelfLink, this.isMock, 1);
            this.vmStates.set(i, null);
            ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.host, numOfVMsToTest - i, ComputeService.FACTORY_LINK, false);
            deleteServiceDocument(this.host, this.storageDescriptions.get(i).documentSelfLink);
            this.storageDescriptions.set(i, null);
            ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.host, numOfVMsToTest - i - 1, StorageDescriptionService.FACTORY_LINK, true);
            deleteServiceDocument(this.host, this.resourceGroupStates.get(i).documentSelfLink);
            this.resourceGroupStates.set(i, null);
            ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.host, numOfVMsToTest - i - 1, ResourceGroupService.FACTORY_LINK, false);
            deleteServiceDocument(this.host, this.diskStates.get(i).documentSelfLink);
            this.diskStates.set(i, null);
            ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.host, numOfVMsToTest - i - 1, DiskService.FACTORY_LINK, false);
        }
        return;
    }
    // 2. Create extra resources
    createStaleResource();
    tagAzureResources();
    // stale resources + 1 compute host instance + 1 vm compute state
    ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.host, STALE_VM_RESOURCES_COUNT + (numOfVMsToTest + 1), ComputeService.FACTORY_LINK, false);
    ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.host, STALE_STORAGE_ACCOUNTS_COUNT + numOfVMsToTest, StorageDescriptionService.FACTORY_LINK, false);
    ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.host, STALE_CONTAINERS_COUNT + STALE_RG_COUNT + 1, ResourceGroupService.FACTORY_LINK, false);
    ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.host, STALE_DISKS_COUNT + numOfVMsToTest, DiskService.FACTORY_LINK, false);
    ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.host, STALE_SECURITY_GROUPS_COUNT, SecurityGroupService.FACTORY_LINK, false);
    this.vmCount = getAzureVMCount(this.computeManagementClient);
    this.host.log(Level.INFO, "Initial VM Count: %d", this.vmCount);
    // 3. Run multiple enumerations over a period of time.
    this.host.log(Level.INFO, "Waiting for multiple enumeration runs...");
    ScheduledFuture<?> enums = runEnumerationAndLogNodeStatsPeriodically();
    this.host.waitFor("Timeout while waiting for test run duration", () -> {
        TimeUnit.MINUTES.sleep(this.testRunDurationInMinutes);
        enums.cancel(false);
        return true;
    });
    this.host.waitFor("Timeout while waiting for last enumeration to clear out.", () -> {
        TimeUnit.MINUTES.sleep(1);
        return true;
    });
    verifyResourceDuplicates();
    // 4. Validate extra resources
    assertRemoteResources();
    assertStaleResources();
    ServiceDocumentQueryResult result = ProvisioningUtils.queryDocumentsAndAssertExpectedCount(this.host, this.vmCount, ComputeService.FACTORY_LINK, false);
    // validate type field for enumerated VMs
    result.documents.entrySet().stream().map(e -> Utils.fromJson(e.getValue(), ComputeState.class)).filter(c -> !c.documentSelfLink.equals(computeHost.documentSelfLink)).forEach(c -> assertEquals(ComputeType.VM_GUEST, c.type));
    // validate internal tags for enumerated VMs
    TagService.TagState expectedInternalTypeTag = newTagState(TAG_KEY_TYPE, AzureConstants.AzureResourceType.azure_vm.toString(), false, endpointState.tenantLinks);
    result.documents.entrySet().stream().map(e -> Utils.fromJson(e.getValue(), ComputeState.class)).filter(c -> c.type.equals(ComputeType.VM_GUEST)).forEach(c -> {
        assertNotNull(c.tagLinks);
        assertTrue(c.tagLinks.contains(expectedInternalTypeTag.documentSelfLink));
    });
    // validate environment name field for enumerated VMs
    result.documents.entrySet().stream().map(e -> Utils.fromJson(e.getValue(), ComputeState.class)).forEach(c -> assertEquals(ComputeDescription.ENVIRONMENT_NAME_AZURE, c.environmentName));
    // 5. Validate enumerated compute states have not changed.
    Map<String, ComputeState> azLrtComputeStatesEnd = getVMComputeStatesWithPrefix();
    assertTrue(numOfVMsToTest <= azLrtComputeStatesEnd.size());
    assertComputeStatesEqual(azLrtComputeStates, azLrtComputeStatesEnd);
    // 1 network per each stale vm resource + 1 network for original vm compute state.
    ServiceDocumentQueryResult networkResults = ProvisioningUtils.queryAllFactoryResources(this.host, NetworkService.FACTORY_LINK);
    // validate internal tags for enumerated networks
    TagService.TagState expectedNetworkInternalTypeTag = newTagState(TAG_KEY_TYPE, NETWORK_TAG_TYPE_VALUE, false, endpointState.tenantLinks);
    networkResults.documents.entrySet().stream().map(e -> Utils.fromJson(e.getValue(), NetworkState.class)).forEach(c -> {
        assertNotNull(c.tagLinks);
        assertTrue(c.tagLinks.contains(expectedNetworkInternalTypeTag.documentSelfLink));
    });
    // 1 subnet per network, 1 network per each stale vm resource + 1 subnet for the original
    // compute state.
    ServiceDocumentQueryResult subnetResults = ProvisioningUtils.queryAllFactoryResources(this.host, SubnetService.FACTORY_LINK);
    // validate internal tags for enumerated subnets
    TagService.TagState expectedSubnetInternalTypeTag = newTagState(TAG_KEY_TYPE, SUBNET_TAG_TYPE_VALUE, false, endpointState.tenantLinks);
    subnetResults.documents.entrySet().stream().map(e -> Utils.fromJson(e.getValue(), SubnetState.class)).forEach(c -> {
        assertNotNull(c.tagLinks);
        assertTrue(c.tagLinks.contains(expectedSubnetInternalTypeTag.documentSelfLink));
    });
    ServiceDocumentQueryResult nicResults = ProvisioningUtils.queryAllFactoryResources(this.host, NetworkInterfaceService.FACTORY_LINK);
    // validate internal tags for enumerated network interfaces
    TagService.TagState expectedNicInternalTypeTag = newTagState(TAG_KEY_TYPE, NETWORK_INTERFACE_TAG_TYPE_VALUE, false, endpointState.tenantLinks);
    nicResults.documents.entrySet().stream().map(e -> Utils.fromJson(e.getValue(), NetworkInterfaceState.class)).forEach(c -> {
        assertNotNull(c.tagLinks);
        assertTrue(c.tagLinks.contains(expectedNicInternalTypeTag.documentSelfLink));
    });
    for (int i = 0; i < numOfVMsToTest; i++) {
        this.host.log(Level.INFO, "Deleting vm: %s", azureVMNames.get(i));
        this.computeManagementClient.virtualMachines().beginDelete(azureVMNames.get(i), azureVMNames.get(i));
    }
    runEnumeration(this.host, computeHost.documentSelfLink, computeHost.resourcePoolLink, endpointState, this.isMock);
    for (int i = 0; i < numOfVMsToTest; i++) {
        assertResourceDisassociated(this.host, ComputeService.FACTORY_LINK, azureVMNames.get(i), true);
        // clean up
        this.vmStates.set(i, null);
        this.resourceManagementClient.resourceGroups().beginDelete(azureVMNames.get(i));
        this.host.log(Level.INFO, "Deleting vm resource group %s", azureVMNames.get(i));
    }
    // Log node stats at the end of the test
    logNodeStats(this.host.getServiceStats(this.nodeStatsUri));
}
Also used : Arrays(java.util.Arrays) NetworkManagementClientImpl(com.microsoft.azure.management.network.implementation.NetworkManagementClientImpl) ProvisionComputeTaskService(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService) AzureTestUtil.deleteVMs(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.deleteVMs) VirtualNetworkInner(com.microsoft.azure.management.network.implementation.VirtualNetworkInner) StorageManagementClientImpl(com.microsoft.azure.management.storage.implementation.StorageManagementClientImpl) ResourceGroupState(com.vmware.photon.controller.model.resources.ResourceGroupService.ResourceGroupState) Utils(com.vmware.xenon.common.Utils) SubnetState(com.vmware.photon.controller.model.resources.SubnetService.SubnetState) AzureTestUtil.createDefaultComputeHost(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultComputeHost) Map(java.util.Map) StorageDescription(com.vmware.photon.controller.model.resources.StorageDescriptionService.StorageDescription) AzureEnvironment(com.microsoft.azure.AzureEnvironment) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) AzureTestUtil.deleteServiceDocument(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.deleteServiceDocument) ProvisioningUtils(com.vmware.photon.controller.model.tasks.ProvisioningUtils) SubnetService(com.vmware.photon.controller.model.resources.SubnetService) NetworkInterfaceState(com.vmware.photon.controller.model.resources.NetworkInterfaceService.NetworkInterfaceState) Set(java.util.Set) AzureTestUtil.createDefaultStorageAccountDescription(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultStorageAccountDescription) AzureTestUtil.updateAzureSecurityGroup(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.updateAzureSecurityGroup) NetworkInterfaceService(com.vmware.photon.controller.model.resources.NetworkInterfaceService) TagService(com.vmware.photon.controller.model.resources.TagService) AzureTestUtil.assertResourceDisassociated(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.assertResourceDisassociated) AzureAdaptersTestUtils(com.vmware.photon.controller.model.adapters.azure.base.AzureAdaptersTestUtils) StorageDescriptionService(com.vmware.photon.controller.model.resources.StorageDescriptionService) UriUtils(com.vmware.xenon.common.UriUtils) ComputeService(com.vmware.photon.controller.model.resources.ComputeService) AzureTestUtil.initializeNicSpecs(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.initializeNicSpecs) AzureTestUtil.createDefaultResourceGroupState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourceGroupState) ResourceGroupStateType(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.ResourceGroupStateType) AzureTestUtil.getAzureVMCount(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getAzureVMCount) ResourcePoolState(com.vmware.photon.controller.model.resources.ResourcePoolService.ResourcePoolState) AzureTestUtil.validateDiskInternalTag(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.validateDiskInternalTag) AzureResourceType.azure_net_interface(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType.azure_net_interface) SYSTEM(com.vmware.photon.controller.model.resources.TagService.TagState.TagOrigin.SYSTEM) ArrayList(java.util.ArrayList) SecurityGroupState(com.vmware.photon.controller.model.resources.SecurityGroupService.SecurityGroupState) ServiceUriPaths(com.vmware.xenon.services.common.ServiceUriPaths) LinkedHashMap(java.util.LinkedHashMap) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) USER_DEFINED(com.vmware.photon.controller.model.resources.TagService.TagState.TagOrigin.USER_DEFINED) Query(com.vmware.xenon.services.common.QueryTask.Query) AzureTestUtil.assertDiskExist(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.assertDiskExist) VirtualMachineInner(com.microsoft.azure.management.compute.implementation.VirtualMachineInner) AzureTestUtil(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil) Before(org.junit.Before) ResourceState(com.vmware.photon.controller.model.resources.ResourceState) AzureTestUtil.assertResourceExists(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.assertResourceExists) QueryUtils(com.vmware.photon.controller.model.query.QueryUtils) SecurityGroupService(com.vmware.photon.controller.model.resources.SecurityGroupService) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) AzureTestUtil.updateAzureVirtualMachine(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.updateAzureVirtualMachine) QueryTop(com.vmware.photon.controller.model.query.QueryUtils.QueryTop) NetworkService(com.vmware.photon.controller.model.resources.NetworkService) ClusterUtil(com.vmware.photon.controller.model.util.ClusterUtil) PhotonModelConstants(com.vmware.photon.controller.model.constants.PhotonModelConstants) AzureTestUtil.createDefaultEndpointState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultEndpointState) ApplicationTokenCredentials(com.microsoft.azure.credentials.ApplicationTokenCredentials) NetworkState(com.vmware.photon.controller.model.resources.NetworkService.NetworkState) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) DISCOVERED(com.vmware.photon.controller.model.resources.TagService.TagState.TagOrigin.DISCOVERED) ModelUtils.createSecurityGroup(com.vmware.photon.controller.model.ModelUtils.createSecurityGroup) PhotonModelUtils.createOriginTagQuery(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.createOriginTagQuery) CoreMatchers(org.hamcrest.CoreMatchers) NicSpec(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AzureNicSpecs.NicSpec) AuthCredentialsServiceState(com.vmware.xenon.services.common.AuthCredentialsService.AuthCredentialsServiceState) ScheduledFuture(java.util.concurrent.ScheduledFuture) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest) QueryTask(com.vmware.xenon.services.common.QueryTask) PhotonModelServices(com.vmware.photon.controller.model.PhotonModelServices) ServiceDocument(com.vmware.xenon.common.ServiceDocument) AzureTestUtil.getAzureVirtualMachine(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getAzureVirtualMachine) AzureTestUtil.createDefaultResourcePool(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultResourcePool) ComputeType(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription.ComputeType) Assert.assertThat(org.junit.Assert.assertThat) AzureResourceType.azure_subnet(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType.azure_subnet) ResourceManagementClientImpl(com.microsoft.azure.management.resources.implementation.ResourceManagementClientImpl) AzureTestUtil.updateAzureVirtualNetwork(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.updateAzureVirtualNetwork) AzureTestUtil.runEnumeration(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.runEnumeration) After(org.junit.After) Assert.fail(org.junit.Assert.fail) URI(java.net.URI) TagsUtil.newTagState(com.vmware.photon.controller.model.adapters.util.TagsUtil.newTagState) EndpointState(com.vmware.photon.controller.model.resources.EndpointService.EndpointState) AzureTestUtil.randomString(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.randomString) AzureConstants(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants) ComputeDescription(com.vmware.photon.controller.model.resources.ComputeDescriptionService.ComputeDescription) AZURE_SECURITY_GROUP_NAME(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AZURE_SECURITY_GROUP_NAME) TestUtils(com.vmware.photon.controller.model.tasks.TestUtils) DiskState(com.vmware.photon.controller.model.resources.DiskService.DiskState) Collectors(java.util.stream.Collectors) QueryStrategy(com.vmware.photon.controller.model.query.QueryStrategy) ResourceGroupService(com.vmware.photon.controller.model.resources.ResourceGroupService) List(java.util.List) TAG_KEY_TYPE(com.vmware.photon.controller.model.constants.PhotonModelConstants.TAG_KEY_TYPE) PhotonModelUtils.waitToComplete(com.vmware.photon.controller.model.resources.util.PhotonModelUtils.waitToComplete) NetworkSecurityGroupInner(com.microsoft.azure.management.network.implementation.NetworkSecurityGroupInner) DiskService(com.vmware.photon.controller.model.resources.DiskService) QueryByPages(com.vmware.photon.controller.model.query.QueryUtils.QueryByPages) BeforeClass(org.junit.BeforeClass) ServiceHostManagementService(com.vmware.xenon.services.common.ServiceHostManagementService) HashMap(java.util.HashMap) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) AzureTestUtil.createDefaultVMResource(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultVMResource) Level(java.util.logging.Level) HashSet(java.util.HashSet) AzureTestUtil.createDefaultAuthCredentials(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultAuthCredentials) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) AzureTestUtil.getAzureVirtualNetwork(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getAzureVirtualNetwork) SubStage(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState.SubStage) AzureNicSpecs(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.AzureNicSpecs) PhotonModelTaskServices(com.vmware.photon.controller.model.tasks.PhotonModelTaskServices) ComputeManagementClientImpl(com.microsoft.azure.management.compute.implementation.ComputeManagementClientImpl) Assert.assertNotNull(org.junit.Assert.assertNotNull) AzureResourceType.azure_vnet(com.vmware.photon.controller.model.adapters.azure.constants.AzureConstants.AzureResourceType.azure_vnet) Operation(com.vmware.xenon.common.Operation) AzureTestUtil.createDefaultDiskState(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.createDefaultDiskState) AzureTestUtil.getAzureSecurityGroup(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.getAzureSecurityGroup) ServiceStat(com.vmware.xenon.common.ServiceStats.ServiceStat) ProvisioningUtils.createServiceURI(com.vmware.photon.controller.model.tasks.ProvisioningUtils.createServiceURI) TimeUnit(java.util.concurrent.TimeUnit) PhotonModelAdaptersRegistryAdapters(com.vmware.photon.controller.model.adapters.registry.PhotonModelAdaptersRegistryAdapters) AzureTestUtil.generateName(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.generateName) ComputeState(com.vmware.photon.controller.model.resources.ComputeService.ComputeState) TagState(com.vmware.photon.controller.model.resources.TagService.TagState) ProvisionComputeTaskState(com.vmware.photon.controller.model.tasks.ProvisionComputeTaskService.ProvisionComputeTaskState) TagService(com.vmware.photon.controller.model.resources.TagService) ArrayList(java.util.ArrayList) AzureTestUtil.randomString(com.vmware.photon.controller.model.adapters.azure.instance.AzureTestUtil.randomString) ServiceDocumentQueryResult(com.vmware.xenon.common.ServiceDocumentQueryResult) Test(org.junit.Test) BaseModelTest(com.vmware.photon.controller.model.helpers.BaseModelTest)

Example 13 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project evosuite by EvoSuite.

the class PrivateReflectionSystemTest method testPrivateConstructor.

private TestSuiteChromosome testPrivateConstructor() {
    Properties.P_REFLECTION_ON_PRIVATE = 0.9;
    Properties.REFLECTION_START_PERCENT = 0.0;
    GeneticAlgorithm ga = do100percentLineTestOnStandardCriteriaWithMethodTrace(PrivateConstructor.class);
    TestSuiteChromosome best = (TestSuiteChromosome) ga.getBestIndividual();
    System.out.println("EvolvedTestSuite:\n" + best);
    assertTrue(!best.getTests().isEmpty());
    double cov = best.getCoverageInstanceOf(MethodCoverageSuiteFitness.class);
    Assert.assertEquals("Non-optimal method coverage: ", 1d, cov, 0.001);
    Optional<FitnessFunction<?>> ff = ga.getFitnessFunctions().stream().filter(m -> m instanceof MethodCoverageSuiteFitness).findAny();
    assertEquals(1, best.getNumOfCoveredGoals(ff.get()));
    cov = best.getCoverageInstanceOf(MethodTraceCoverageSuiteFitness.class);
    Assert.assertEquals("Non-optimal method trace coverage: ", 1d, cov, 0.001);
    ff = ga.getFitnessFunctions().stream().filter(m -> m instanceof MethodTraceCoverageSuiteFitness).findAny();
    assertEquals(1, best.getNumOfCoveredGoals(ff.get()));
    return best;
}
Also used : Arrays(java.util.Arrays) GeneticAlgorithm(org.evosuite.ga.metaheuristics.GeneticAlgorithm) RuntimeVariable(org.evosuite.statistics.RuntimeVariable) MethodCoverageFitnessFunctionSystemTest(org.evosuite.coverage.method.MethodCoverageFitnessFunctionSystemTest) OutputVariable(org.evosuite.statistics.OutputVariable) ArrayList(java.util.ArrayList) MethodTraceCoverageSuiteFitness(org.evosuite.coverage.method.MethodTraceCoverageSuiteFitness) FitnessFunction(org.evosuite.ga.FitnessFunction) SystemTestBase(org.evosuite.SystemTestBase) Properties(org.evosuite.Properties) com.examples.with.different.packagename.reflection(com.examples.with.different.packagename.reflection) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) TestCaseExecutor(org.evosuite.testcase.execution.TestCaseExecutor) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) EvoSuite(org.evosuite.EvoSuite) List(java.util.List) Assert.assertNull(org.junit.Assert.assertNull) MethodCoverageSuiteFitness(org.evosuite.coverage.method.MethodCoverageSuiteFitness) LineCoverageSuiteFitness(org.evosuite.coverage.line.LineCoverageSuiteFitness) Optional(java.util.Optional) Assert(org.junit.Assert) TestSuiteFitnessFunction(org.evosuite.testsuite.TestSuiteFitnessFunction) Assert.assertEquals(org.junit.Assert.assertEquals) TestSuiteChromosome(org.evosuite.testsuite.TestSuiteChromosome) MethodTraceCoverageSuiteFitness(org.evosuite.coverage.method.MethodTraceCoverageSuiteFitness) FitnessFunction(org.evosuite.ga.FitnessFunction) TestSuiteFitnessFunction(org.evosuite.testsuite.TestSuiteFitnessFunction) MethodCoverageSuiteFitness(org.evosuite.coverage.method.MethodCoverageSuiteFitness) GeneticAlgorithm(org.evosuite.ga.metaheuristics.GeneticAlgorithm)

Example 14 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project gridss by PapenfussLab.

the class ExtractSVReadsTest method regression_should_extract_split_read_alignments_as_group_2.

// @Test
@Category(Hg38Tests.class)
public void regression_should_extract_split_read_alignments_as_group_2() throws IOException {
    File ref = Hg38Tests.findHg38Reference();
    ReferenceLookup lookup = new SynchronousReferenceLookupAdapter(new IndexedFastaSequenceFile(ref));
    Files.copy(new File("src/test/resources/sa.split/test2.sam"), input);
    ExtractSVReads extract = new ExtractSVReads();
    // new ProcessingContext(getFSContext(), ref, lookup, null, getConfig());
    extract.setReference(lookup);
    extract.MIN_CLIP_LENGTH = 4;
    extract.INSERT_SIZE_METRICS = new File("src/test/resources/sa.split/test.insert_size_metrics");
    extract.READ_PAIR_CONCORDANCE_METHOD = ReadPairConcordanceMethod.PERCENTAGE;
    extract.OUTPUT = output;
    extract.INPUT = input;
    try (SamReader reader = SamReaderFactory.make().open(input)) {
        extract.setup(reader.getFileHeader(), input);
    }
    List<SAMRecord> records = getRecords(input);
    List<Boolean> result = records.stream().map(r -> extract.shouldExtract(ImmutableList.of(r), lookup)[0]).collect(Collectors.toList());
    /*
		for (int i = 0; i < records.size(); i++) {
			SAMRecord r = records.get(i);
			System.out.print(r.getSupplementaryAlignmentFlag() ? "S" : " ");
			System.out.print(r.getFirstOfPairFlag() ? "1" : "2");
			System.out.print(" Extracted=" + (result.get(i) ? "y" : "n"));
			System.out.print(" HasConcPair=" + (ExtractSVReads.hasReadPairingConsistentWithReference(extract.getReadPairConcordanceCalculator(), ImmutableList.of(r)) ? "y" : "n"));
			boolean[] ra = ExtractSVReads.hasReadAlignmentConsistentWithReference(ImmutableList.of(r));
			System.out.print(" HasConcRead=" + (ra[0] ? "y" : "n") + (ra[1] ? "y" : "n"));
			System.out.println(" " + new ChimericAlignment(r).toString());
		}*/
    // primary read pair alignment implies an unexpected library fragment size = extract them all
    Assert.assertEquals(ImmutableList.of(true, true, true, true), result);
    lookup.close();
}
Also used : FixedSizeReadPairConcordanceCalculator(au.edu.wehi.idsv.FixedSizeReadPairConcordanceCalculator) Iterables(com.google.common.collect.Iterables) ReadPairConcordanceMethod(au.edu.wehi.idsv.ReadPairConcordanceMethod) Iterators(com.google.common.collect.Iterators) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Files(com.google.common.io.Files) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) StructuralVariantReadMetrics(gridss.analysis.StructuralVariantReadMetrics) ChimericAlignment(au.edu.wehi.idsv.sam.ChimericAlignment) ReferenceLookup(au.edu.wehi.idsv.picard.ReferenceLookup) IntermediateFilesTest(au.edu.wehi.idsv.IntermediateFilesTest) Assert.assertTrue(org.junit.Assert.assertTrue) IOException(java.io.IOException) Test(org.junit.Test) SynchronousReferenceLookupAdapter(au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter) Category(org.junit.experimental.categories.Category) SamReader(htsjdk.samtools.SamReader) MetricsFile(htsjdk.samtools.metrics.MetricsFile) Collectors(java.util.stream.Collectors) File(java.io.File) SAMRecord(htsjdk.samtools.SAMRecord) List(java.util.List) Hg38Tests(au.edu.wehi.idsv.Hg38Tests) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) Assert.assertFalse(org.junit.Assert.assertFalse) Assert(org.junit.Assert) SamReaderFactory(htsjdk.samtools.SamReaderFactory) Assert.assertEquals(org.junit.Assert.assertEquals) SamReader(htsjdk.samtools.SamReader) ReferenceLookup(au.edu.wehi.idsv.picard.ReferenceLookup) SAMRecord(htsjdk.samtools.SAMRecord) MetricsFile(htsjdk.samtools.metrics.MetricsFile) File(java.io.File) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) IndexedFastaSequenceFile(htsjdk.samtools.reference.IndexedFastaSequenceFile) SynchronousReferenceLookupAdapter(au.edu.wehi.idsv.picard.SynchronousReferenceLookupAdapter) Category(org.junit.experimental.categories.Category)

Example 15 with Assert.assertEquals

use of org.junit.Assert.assertEquals in project solr-document-store by DBCDK.

the class BiliographicRecordAPIBeanIT method testSupersedeIdIncluded.

@Test
public void testSupersedeIdIncluded() throws JsonProcessingException {
    String bibliographicRecordId = "page-order";
    Response json = bean.getBibliographicKeysWithSupersedeId(bibliographicRecordId, 1, 10, "agencyId", false);
    FrontendReturnListType<BibliographicFrontendEntity> frontendReturnListType = (FrontendReturnListType<BibliographicFrontendEntity>) json.getEntity();
    List<String> supersedeIds = frontendReturnListType.result.stream().map(b -> b.getSupersedeId()).collect(Collectors.toList());
    Assert.assertEquals(supersedeIds, Arrays.asList("0639423", "0639423", "0639423", "0639423", "0639423", "0639423", "0639423", "0639423"));
    String repositoryId = "p-o";
    Response jsonRepo = bean.getBibliographicKeysByRepositoryIdWithSupersedeId(repositoryId, 1, 10, "agencyId", false);
    FrontendReturnListType<BibliographicFrontendEntity> frontendReturnListTypeRepo = (FrontendReturnListType<BibliographicFrontendEntity>) jsonRepo.getEntity();
    List<String> supersedeIdsRepo = frontendReturnListTypeRepo.result.stream().map(b -> b.getSupersedeId()).collect(Collectors.toList());
    Assert.assertEquals(supersedeIdsRepo, Arrays.asList("0639423", "0639423", "0639423", "0639423", "0639423", "0639423", "0639423", "0639423"));
}
Also used : Response(javax.ws.rs.core.Response) java.util(java.util) BeanFactoryUtil(dk.dbc.search.solrdocstore.BeanFactoryUtil) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) Test(org.junit.Test) EntityManager(javax.persistence.EntityManager) NotNull(javax.validation.constraints.NotNull) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) JSONBContext(dk.dbc.commons.jsonb.JSONBContext) Response(javax.ws.rs.core.Response) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) Before(org.junit.Before) Test(org.junit.Test)

Aggregations

Assert.assertEquals (org.junit.Assert.assertEquals)68 Assert (org.junit.Assert)67 Test (org.junit.Test)62 List (java.util.List)56 Before (org.junit.Before)42 Assert.assertTrue (org.junit.Assert.assertTrue)41 ArrayList (java.util.ArrayList)39 Assert.assertFalse (org.junit.Assert.assertFalse)39 Arrays (java.util.Arrays)29 Assert.assertNotNull (org.junit.Assert.assertNotNull)29 Collections (java.util.Collections)28 Map (java.util.Map)25 After (org.junit.After)25 HashMap (java.util.HashMap)24 Collectors (java.util.stream.Collectors)24 Assert.assertNull (org.junit.Assert.assertNull)23 Set (java.util.Set)17 SystemEntityType (eu.bcvsolutions.idm.acc.domain.SystemEntityType)15 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)15 SysSystemService (eu.bcvsolutions.idm.acc.service.api.SysSystemService)15