### Question:
VirtualDatacenterService extends DefaultApiService { public Collection<VirtualDatacenter> getVirtualDatacenters(final Enterprise enterprise, final Datacenter datacenter, final FilterOptions filterOptions) { User user = userService.getCurrentUser(); return getVirtualDatacenters(enterprise, datacenter, user, filterOptions); } VirtualDatacenterService();  VirtualDatacenterService(final EntityManager em); Collection<VirtualDatacenter> getVirtualDatacenters(final Enterprise enterprise,
        final Datacenter datacenter, final FilterOptions filterOptions); Collection<VirtualDatacenter> getVirtualDatacenters(Enterprise enterprise,
        final Datacenter datacenter, final User user, final FilterOptions filterOptions); Collection<VirtualDatacenter> getVirtualDatacentersByDatacenter(
        final Datacenter datacenter, final Integer startwith, final Integer limit,
        final String filter, final OrderByEnum orderByEnum, final Boolean asc); @Transactional(readOnly = true, propagation = Propagation.REQUIRED) VirtualDatacenter getVirtualDatacenter(final Integer id); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) VirtualDatacenter createVirtualDatacenter(final VirtualDatacenterDto dto,
        final Datacenter datacenter, final Enterprise enterprise); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) VirtualDatacenter updateVirtualDatacenter(final Integer id,
        final VirtualDatacenterDto dto); @Transactional(readOnly = false, propagation = Propagation.REQUIRED) void deleteVirtualDatacenter(final Integer id); Collection<NodeVirtualImage> getNodeVirtualImageByEnterprise(final Enterprise enterprise); void detach(final VirtualDatacenter virtualDatacenter); static final String FENCE_MODE; }### Answer:
@Test public void findVirtualDatacenterAssignedToUser() { Enterprise enterprise = enterpriseGenerator.createUniqueInstance(); Datacenter datacenter = datacenterGenerator.createUniqueInstance(); Role role = roleGenerator.createInstance(); User user = userGenerator.createInstance(enterprise, role); VirtualDatacenter vdc1 = vdcGenerator.createInstance(datacenter, enterprise); VirtualDatacenter vdc2 = vdcGenerator.createInstance(datacenter, enterprise); VirtualDatacenter vdc3 = vdcGenerator.createInstance(datacenter, enterprise); setup(enterprise, datacenter, vdc1, vdc2, vdc3); String ids = vdc1.getId() + "," + vdc2.getId(); user.setAvailableVirtualDatacenters(ids); setup(user.getRole(), user); VirtualDatacenterService service = new VirtualDatacenterService(getEntityManagerWithAnActiveTransaction()); Collection<VirtualDatacenter> vdcs = service.getVirtualDatacenters(enterprise, null, null, null); Assert.assertSize(vdcs, 3); vdcs = service.getVirtualDatacenters(enterprise, null, user, null); Assert.assertSize(vdcs, 2); }
@Test public void findVirtualDatacenterAssignedToEnterpriseAdmin() { Enterprise enterprise = enterpriseGenerator.createUniqueInstance(); Enterprise enterprise2 = enterpriseGenerator.createUniqueInstance(); Datacenter datacenter = datacenterGenerator.createUniqueInstance(); Role role = roleGenerator.createInstance(); User user = userGenerator.createInstance(enterprise, role); VirtualDatacenter vdc1 = vdcGenerator.createInstance(datacenter, enterprise); VirtualDatacenter vdc2 = vdcGenerator.createInstance(datacenter, enterprise); VirtualDatacenter vdc3 = vdcGenerator.createInstance(datacenter, enterprise2); setup(enterprise, enterprise2, datacenter, vdc1, vdc2, vdc3, user.getRole(), user); VirtualDatacenterService service = new VirtualDatacenterService(getEntityManagerWithAnActiveTransaction()); Collection<VirtualDatacenter> vdcs = service.getVirtualDatacenters(null, null, null, null); Assert.assertSize(vdcs, 3); vdcs = service.getVirtualDatacenters(null, null, user, null); Assert.assertSize(vdcs, 2); }