### Question:
DatacenterDAO extends DefaultDAOBase<Integer, Datacenter> { public DefaultEntityCurrentUsed getCurrentResourcesAllocated(final int datacenterId, final int enterpriseId) { Object[] vmResources = (Object[]) getSession().createSQLQuery(SUM_VM_RESOURCES).setParameter("datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId).uniqueResult(); Long cpu = vmResources[0] == null ? 0 : ((BigDecimal) vmResources[0]).longValue(); Long ram = vmResources[1] == null ? 0 : ((BigDecimal) vmResources[1]).longValue(); Long hd = vmResources[2] == null ? 0 : ((BigDecimal) vmResources[2]).longValue(); BigDecimal extraHd = (BigDecimal) getSession().createSQLQuery(SUM_EXTRA_HD_RESOURCES).setParameter( "datacenterId", datacenterId).uniqueResult(); Long hdTot = extraHd == null ? hd : hd + extraHd.longValue() * 1024 * 1024; BigDecimal storage = (BigDecimal) getSession().createSQLQuery(SUM_STORAGE_RESOURCES).setParameter( "datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId) .uniqueResult(); BigInteger publicIps = (BigInteger) getSession().createSQLQuery(COUNT_IP_RESOURCES).setParameter( "datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId) .uniqueResult(); BigInteger vlan = (BigInteger) getSession().createSQLQuery(COUNT_VLAN_RESOURCES).setParameter( "datacenterId", datacenterId).setParameter("enterpriseId", enterpriseId) .uniqueResult(); DefaultEntityCurrentUsed used = new DefaultEntityCurrentUsed(cpu.intValue(), ram, hdTot); used.setStorage(storage == null ? 0 : storage.longValue() * 1024 * 1024); used.setPublicIp(publicIps == null ? 0 : publicIps.longValue()); used.setVlanCount(vlan == null ? 0 : vlan.longValue()); return used; } DatacenterDAO();  DatacenterDAO(final EntityManager entityManager); boolean existsAnyWithName(final String name); boolean existsAnyOtherWithName(final Datacenter datacenter, final String name); DefaultEntityCurrentUsed getCurrentResourcesAllocated(final int datacenterId,
        final int enterpriseId); List<Enterprise> findEnterprisesByDatacenters(final Datacenter datacenter,
        final Integer firstElem, final Integer numElem, final Boolean network); static final String BY_ENT_WITH_NETWORK; static final String BY_ENT; }### Answer:
@Test(enabled = false) public void test_getUsedResources() { Enterprise enterprise = this.enterpriseGenerator.createInstance("Enterprise Name"); Datacenter datacenter = createUniqueEntity(); datacenter.setName("Datacenter name"); ds().persistAll(datacenter, enterprise); DatacenterDAO dao = createDaoWithNoTransaction(); DefaultEntityCurrentUsed expectedUsed = new DefaultEntityCurrentUsed(0, 0, 0); DefaultEntityCurrentUsed currentUsed = dao.getCurrentResourcesAllocated(datacenter.getId(), enterprise.getId()); Assert.assertEquals(currentUsed.getCpu(), expectedUsed.getCpu()); Assert.assertEquals(currentUsed.getRamInMb(), expectedUsed.getRamInMb()); Assert.assertEquals(currentUsed.getHdInMb(), expectedUsed.getHdInMb()); Assert.assertEquals(currentUsed.getPublicIp(), expectedUsed.getPublicIp()); Assert.assertEquals(currentUsed.getVlanCount(), expectedUsed.getVlanCount()); }