/** * Default constructor of Quota, which initialize empty lists for specific limitations, and no user assigned. */ public Quota() { setQuotaStorages(new ArrayList<QuotaStorage>()); setQuotaClusters(new ArrayList<QuotaCluster>()); id = Guid.Empty; description = ""; }
/** * Get full {@code Quota} entity. */ @Override public Quota getById(Guid quotaId) { MapSqlParameterSource parameterSource = createQuotaIdParameterMapper(quotaId); Quota quotaEntity = getCallsHandler().executeRead("GetQuotaByQuotaGuid", getQuotaFromResultSet(), parameterSource); if (quotaEntity != null) { quotaEntity.setQuotaClusters(getQuotaClusterByQuotaGuid(quotaId)); quotaEntity.setQuotaStorages(getQuotaStorageByQuotaGuid(quotaId)); } return quotaEntity; }
} else { if (quota.getQuotaClusters() == null) { quota.setQuotaClusters(new ArrayList<>());
@Test public void testListNonGlobalLimit() { Quota quota = getQuota(); List<QuotaCluster> clusterLimits = new LinkedList<>(); QuotaCluster clusterLimit1 = new QuotaCluster(); clusterLimit1.setVirtualCpu(CPU_NUMBER); clusterLimit1.setClusterId(CLUSTER_ID_1); QuotaCluster clusterLimit2 = new QuotaCluster(); clusterLimit2.setVirtualCpuUsage(VIRTUAL_CPU_USAGE); clusterLimit2.setClusterId(CLUSTER_ID_2); clusterLimits.add(clusterLimit1); clusterLimits.add(clusterLimit2); quota.setQuotaClusters(clusterLimits); setUpGetEntityExpectations(quota); QuotaClusterLimits list = collection.list(); assertClusterLimitsFound(list, 2); for (QuotaClusterLimit clusterLimit: list.getQuotaClusterLimits()) { if (clusterLimit.getCluster().getId().equals(CLUSTER_ID_1.toString())) { assertEquals(CPU_NUMBER, clusterLimit.getVcpuLimit().longValue()); } if (clusterLimit.getCluster().getId().equals(CLUSTER_ID_2.toString())) { assertEquals(VIRTUAL_CPU_USAGE, (int) clusterLimit.getVcpuUsage()); } } }
/** * Make Quota specific to be the same as Quota general and specific. */ @Test public void testUpdateQuota() { Quota quotaGeneralToSpecific = dao.getById(FixturesTool.QUOTA_GENERAL); // Save quotaName and cluster list for future check. String quotaName = "New Temporary name"; List<QuotaCluster> quotaClusterList = getQuotaCluster(getSpecificQuotaCluster(quotaGeneralToSpecific.getId())); Long newStorageLimit = 2345L; // Check before the update, that the fields are not equal. assertNotEquals(quotaName, quotaGeneralToSpecific.getQuotaName()); assertNotEquals(quotaClusterList.size(), quotaGeneralToSpecific.getQuotaClusters().size()); assertNotEquals(newStorageLimit, quotaGeneralToSpecific.getGlobalQuotaStorage().getStorageSizeGB()); // Update quotaGeneralToSpecific.setQuotaName(quotaName); quotaGeneralToSpecific.getGlobalQuotaStorage().setStorageSizeGB(newStorageLimit); quotaGeneralToSpecific.setQuotaClusters(quotaClusterList); dao.update(quotaGeneralToSpecific); quotaGeneralToSpecific = dao.getById(FixturesTool.QUOTA_GENERAL); // Check after the update, that the fields are equal now. assertEquals(quotaName, quotaGeneralToSpecific.getQuotaName()); assertEquals(quotaClusterList.size(), quotaGeneralToSpecific.getQuotaClusters().size()); assertEquals(newStorageLimit, quotaGeneralToSpecific.getGlobalQuotaStorage().getStorageSizeGB()); }
@Test public void testSpecificAndGeneralQuotaLimitations() { // Set new Quota definition. Quota quota = createGeneralQuota(); quota.setQuotaClusters(getQuotaCluster(getSpecificQuotaCluster(quota.getId()))); quota.setQuotaStorages(getQuotaStorage(null)); quota.setGlobalQuotaStorage(new QuotaStorage(null, null, null, 10000L, 0d)); dao.save(quota); Quota quotaEntity = dao.getById(quota.getId()); assertNotNull(quotaEntity); assertEquals(quota, quotaEntity); }
@Test public void testSpecificQuotaLimitations() { // Set new Quota definition. Quota quota = createGeneralQuota(); quota.setQuotaClusters(getQuotaCluster(getSpecificQuotaCluster(quota.getId()))); quota.setQuotaStorages(getQuotaStorage(getSpecificQuotaStorage(quota.getId()))); dao.save(quota); Quota quotaEntity = dao.getById(quota.getId()); assertNotNull(quotaEntity); assertEquals(quota, quotaEntity); }
quota.setQuotaClusters(quotaClusterList);
@Test public void testGeneralQuotaLimitations() { // Set new Quota definition. Quota quota = createGeneralQuota(); setQuotaGlobalLimitations(quota); quota.setQuotaClusters(getQuotaCluster(null)); quota.setQuotaStorages(getQuotaStorage(null)); dao.save(quota); Quota quotaEntity = dao.getById(quota.getId()); assertNotNull(quotaEntity); assertEquals(quota, quotaEntity); assertEquals("rhel6.NFS", quotaEntity.getStoragePoolName()); assertEquals(QuotaEnforcementTypeEnum.DISABLED, quotaEntity.getQuotaEnforcementType()); }