java/code/src/com/redhat/rhn/domain/channel/test/ChannelFactoryTest.java
| 27 -
java/code/src/com/redhat/rhn/domain/channel/test/ChannelFamilyFactoryTest.java
| 17
java/code/src/com/redhat/rhn/domain/server/ServerGroupType.java
| 10
java/code/src/com/redhat/rhn/domain/server/test/HostBuilder.java
| 11
java/code/src/com/redhat/rhn/domain/server/test/ServerFactoryTest.java
| 45 +-
java/code/src/com/redhat/rhn/manager/system/VirtualizationEntitlementsManager.java
| 25 -
java/code/src/com/redhat/rhn/manager/system/test/VirtualizationEntitlementsManagerTest.java
| 220 ++++++++++
java/code/src/com/redhat/rhn/testing/UserTestUtils.java
| 14
8 files changed, 311 insertions(+), 58 deletions(-)
New commits:
commit 5445dc72d6f86f44bbac5d4c14c7d6000cdd76f8
Author: Partha Aji <paji(a)redhat.com>
Date: Fri Jun 25 14:51:29 2010 -0400
Added unit tests for VirtEntitlementsManager
diff --git a/java/code/src/com/redhat/rhn/domain/channel/test/ChannelFactoryTest.java
b/java/code/src/com/redhat/rhn/domain/channel/test/ChannelFactoryTest.java
index d7d48e3..d33e07c 100644
--- a/java/code/src/com/redhat/rhn/domain/channel/test/ChannelFactoryTest.java
+++ b/java/code/src/com/redhat/rhn/domain/channel/test/ChannelFactoryTest.java
@@ -89,11 +89,29 @@ public class ChannelFactoryTest extends RhnBaseTestCase {
ChannelFactory.save(c);
return c;
}
+
+ public static Channel createBaseChannel(User user,
+ ChannelFamily fam) throws Exception {
+ Channel c = createTestChannel(null, fam);
+ ProductName pn = lookupOrCreateProductName(ChannelManager.RHEL_PRODUCT_NAME);
+ c.setProductName(pn);
+ ChannelFactory.save(c);
+ return (Channel)TestUtils.saveAndReload(c);
+ }
+
public static Channel createTestChannel(User user) throws Exception {
Org org = user.getOrg();
ChannelFamily cfam = user.getOrg().getPrivateChannelFamily();
+ Channel c = createTestChannel(org, cfam);
+ // assume we want the user to have access to this channel once created
+ UserManager.addChannelPerm(user, c.getId(), "subscribe");
+ UserManager.addChannelPerm(user, c.getId(), "manage");
+ ChannelFactory.save(c);
+ return c;
+ }
+ public static Channel createTestChannel(Org org, ChannelFamily cfam) throws Exception
{
String label = "ChannelLabel" + TestUtils.randomString();
String basedir = "TestChannel basedir";
String name = "ChannelName" + TestUtils.randomString();
@@ -108,11 +126,10 @@ public class ChannelFactoryTest extends RhnBaseTestCase {
Calendar cal = Calendar.getInstance();
cal.roll(Calendar.DATE, true);
Date endoflife = new Date(System.currentTimeMillis() + Integer.MAX_VALUE);
-
+
Long testid = new Long(500);
String query = "ChannelArch.findById";
ChannelArch arch = (ChannelArch) TestUtils.lookupFromCacheById(testid, query);
-
Channel c = new Channel();
c.setOrg(org);
c.setLabel(label);
@@ -129,12 +146,6 @@ public class ChannelFactoryTest extends RhnBaseTestCase {
c.setEndOfLife(endoflife);
c.setChannelArch(arch);
c.setChannelFamily(cfam);
-
- ChannelFactory.save(c);
-
- // assume we want the user to have access to this channel once created
- UserManager.addChannelPerm(user, c.getId(), "subscribe");
- UserManager.addChannelPerm(user, c.getId(), "manage");
ChannelFactory.save(c);
return c;
}
diff --git
a/java/code/src/com/redhat/rhn/domain/channel/test/ChannelFamilyFactoryTest.java
b/java/code/src/com/redhat/rhn/domain/channel/test/ChannelFamilyFactoryTest.java
index 66bf9b1..6389262 100644
--- a/java/code/src/com/redhat/rhn/domain/channel/test/ChannelFamilyFactoryTest.java
+++ b/java/code/src/com/redhat/rhn/domain/channel/test/ChannelFamilyFactoryTest.java
@@ -14,6 +14,7 @@
*/
package com.redhat.rhn.domain.channel.test;
+import com.redhat.rhn.common.hibernate.HibernateFactory;
import com.redhat.rhn.domain.channel.ChannelFamily;
import com.redhat.rhn.domain.channel.ChannelFamilyFactory;
import com.redhat.rhn.domain.channel.PrivateChannelFamily;
@@ -31,7 +32,8 @@ import java.util.List;
*/
public class ChannelFamilyFactoryTest extends RhnBaseTestCase {
- public static final Long ENTITLEMENT_ALLOCATION = new Long(10000);
+ public static final long ENTITLEMENT_ALLOCATION = 10000;
+ public static final long FLEX_ALLOCATION = ENTITLEMENT_ALLOCATION;
public void testChannelFamilyFactory() throws Exception {
ChannelFamily cfam = createTestChannelFamily();
@@ -105,6 +107,11 @@ public class ChannelFamilyFactoryTest extends RhnBaseTestCase {
}
public static ChannelFamily createTestChannelFamily(User user) throws Exception {
+ return createTestChannelFamily(user, ENTITLEMENT_ALLOCATION, FLEX_ALLOCATION);
+ }
+
+ public static ChannelFamily createTestChannelFamily(User user,
+ Long ents, Long flexEnts) throws Exception {
Org org = user.getOrg();
String label = "ChannelFamilyLabel" + TestUtils.randomString();
String name = "ChannelFamilyName" + TestUtils.randomString();
@@ -123,8 +130,12 @@ public class ChannelFamilyFactoryTest extends RhnBaseTestCase {
pcf.setOrg(user.getOrg());
pcf.setChannelFamily(cfam);
pcf.setCurrentMembers(new Long(0));
- pcf.setMaxMembers(ENTITLEMENT_ALLOCATION);
- pcf = (PrivateChannelFamily) TestUtils.saveAndReload(pcf);
+ pcf.setMaxMembers(ents);
+ pcf.setCurrentFlex(0L);
+ pcf.setMaxFlex(flexEnts);
+ HibernateFactory.getSession().save(pcf);
+
+
cfam.addPrivateChannelFamily(pcf);
cfam = (ChannelFamily) TestUtils.reload(cfam);
return cfam;
diff --git a/java/code/src/com/redhat/rhn/domain/server/ServerGroupType.java
b/java/code/src/com/redhat/rhn/domain/server/ServerGroupType.java
index ede23eb..7a458f9 100644
--- a/java/code/src/com/redhat/rhn/domain/server/ServerGroupType.java
+++ b/java/code/src/com/redhat/rhn/domain/server/ServerGroupType.java
@@ -15,6 +15,8 @@
package com.redhat.rhn.domain.server;
import com.redhat.rhn.domain.AbstractLabelNameHelper;
+import com.redhat.rhn.domain.entitlement.Entitlement;
+import com.redhat.rhn.manager.entitlement.EntitlementManager;
import java.util.HashSet;
import java.util.Set;
@@ -74,4 +76,12 @@ public class ServerGroupType extends AbstractLabelNameHelper {
public void setFeatures(Set<Feature> featuresIn) {
features = featuresIn;
}
+
+ /**
+ * Get the associated Entitlement
+ * @return the Entitlement
+ */
+ public Entitlement getAssociatedEntitlement() {
+ return EntitlementManager.getByName(this.getLabel());
+ }
}
diff --git a/java/code/src/com/redhat/rhn/domain/server/test/HostBuilder.java
b/java/code/src/com/redhat/rhn/domain/server/test/HostBuilder.java
index 299067f..61fa278 100644
--- a/java/code/src/com/redhat/rhn/domain/server/test/HostBuilder.java
+++ b/java/code/src/com/redhat/rhn/domain/server/test/HostBuilder.java
@@ -20,10 +20,13 @@ import com.redhat.rhn.domain.server.ServerConstants;
import com.redhat.rhn.domain.server.ServerGroupType;
import com.redhat.rhn.domain.server.VirtualInstance;
import com.redhat.rhn.domain.user.User;
+import com.redhat.rhn.manager.entitlement.EntitlementManager;
+import com.redhat.rhn.manager.system.SystemManager;
import com.redhat.rhn.testing.TestUtils;
import org.hibernate.Session;
+import java.util.Date;
import java.util.Iterator;
@@ -80,6 +83,9 @@ public class HostBuilder {
private HostBuilder createHost(ServerGroupType type) throws Exception {
host = ServerFactoryTest.createTestServer(owner, true, type);
+ if (host.getBaseEntitlement() == null) {
+ SystemManager.entitleServer(host, EntitlementManager.MANAGEMENT);
+ }
return this;
}
@@ -162,11 +168,14 @@ public class HostBuilder {
virtualInstance.setUuid(TestUtils.randomString());
if (register) {
- guest = ServerFactoryTest.createTestServer(owner);
+ guest = ServerFactoryTest.createUnentitledTestServer(owner, true,
+ ServerFactoryTest.TYPE_SERVER_NORMAL , new Date());
virtualInstance.setGuestSystem(guest);
}
host.addGuest(virtualInstance);
+ TestUtils.saveAndFlush(host);
+ TestUtils.saveAndFlush(guest);
}
}
diff --git a/java/code/src/com/redhat/rhn/domain/server/test/ServerFactoryTest.java
b/java/code/src/com/redhat/rhn/domain/server/test/ServerFactoryTest.java
index 68f3016..42ef538 100644
--- a/java/code/src/com/redhat/rhn/domain/server/test/ServerFactoryTest.java
+++ b/java/code/src/com/redhat/rhn/domain/server/test/ServerFactoryTest.java
@@ -535,36 +535,42 @@ public class ServerFactoryTest extends RhnBaseTestCase {
new Date());
}
- public static Server createTestServer(User owner, boolean ensureOwnerAccess,
- ServerGroupType type, Date dateCreated) throws Exception {
- return createTestServer(owner, ensureOwnerAccess, type, TYPE_SERVER_NORMAL,
- dateCreated);
- }
public static Server createTestServer(User owner, boolean ensureOwnerAccess,
ServerGroupType type, int stype) throws Exception {
return createTestServer(owner, ensureOwnerAccess, type, stype, new Date());
}
+
+ private static Server createTestServer(User owner, boolean ensureOwnerAccess,
+ ServerGroupType type, int stype, Date dateCreated)
+ throws Exception {
+
+ Server newS = createUnentitledTestServer(owner, ensureOwnerAccess, stype,
+ dateCreated);
+
+ if (!type.getAssociatedEntitlement().isBase()) {
+ SystemManager.entitleServer(newS, EntitlementManager.MANAGEMENT);
+ }
+
+
+ EntitlementServerGroup sg = ServerGroupTestUtils.createEntitled(owner.getOrg(),
+ type);
+ SystemManager.entitleServer(newS, sg.getGroupType().getAssociatedEntitlement());
+ return (Server) TestUtils.saveAndReload(newS);
+ }
+
/**
* Create a test Server and commit it to the DB.
* @param owner the owner of this Server
* @param ensureOwnerAccess this flag will make sure the owner passed in has
* access to the new server.
* @return Server that was created
+ * @throws Exception if there are server creation errors
*/
- private static Server createTestServer(User owner, boolean ensureOwnerAccess,
- ServerGroupType type, int stype, Date dateCreated)
- throws Exception {
-
- //Create a server and a server group
- EntitlementServerGroup sg = ServerGroupTestUtils.createEntitled(owner.getOrg(),
- type);
- if (sg.getMaxMembers() != null) {
- sg.setMaxMembers(new Long(sg.getMaxMembers().longValue() + 10L));
- }
+ public static Server createUnentitledTestServer(User owner, boolean
ensureOwnerAccess,
+ int stype, Date dateCreated) throws Exception {
Server newS = createServer(stype);
-
// We have to commit this change manually since
// ServerGroups aren't actually mapped from within
// the Server class.
@@ -587,9 +593,11 @@ public class ServerFactoryTest extends RhnBaseTestCase {
newS.addNetworkInterface(netint);
+
ServerFactory.save(newS);
- ServerFactory.addServerToGroup(newS, sg);
+ TestUtils.saveAndReload(newS);
+
/* Since we added a server to the Org we need
* to update the User's permissions as associated with
@@ -705,7 +713,7 @@ public class ServerFactoryTest extends RhnBaseTestCase {
throws Exception {
return createTestServer(owner, ensureOwnerAccess,
- ServerConstants.getServerGroupTypeUpdateEntitled());
+ ServerConstants.getServerGroupTypeEnterpriseEntitled());
}
private static Server createServer(int type) {
@@ -988,4 +996,3 @@ public class ServerFactoryTest extends RhnBaseTestCase {
}
}
-
diff --git
a/java/code/src/com/redhat/rhn/manager/system/VirtualizationEntitlementsManager.java
b/java/code/src/com/redhat/rhn/manager/system/VirtualizationEntitlementsManager.java
index 4f10446..2c9d9d5 100644
--- a/java/code/src/com/redhat/rhn/manager/system/VirtualizationEntitlementsManager.java
+++ b/java/code/src/com/redhat/rhn/manager/system/VirtualizationEntitlementsManager.java
@@ -22,9 +22,6 @@ import com.redhat.rhn.domain.server.VirtualInstanceFactory;
import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.frontend.dto.ChannelFamilySystemGroup;
-import org.apache.commons.lang.BooleanUtils;
-
-import java.sql.Types;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
@@ -137,26 +134,4 @@ public class VirtualizationEntitlementsManager {
"Channel_queries", "convert_to_flex");
m.execute(in, new HashMap());
}
-
-
- /**
- * True if the passed in server can be converted to flex
- * @param sid the server id
- * @param cfid the channel family id
- * @return true if the server can be converted to flex
- */
- public boolean canConvertToFlex(Long sid, Long cfid) {
- Map in = new HashMap();
- in.put("sid", sid);
- in.put("cfid", cfid);
- Map outParams = new HashMap();
- outParams.put("result", new Integer(Types.NUMERIC));
-
- CallableMode m = ModeFactory.getCallableMode(
- "Channel_queries", "can_convert_to_flex");
-
- Map result = m.execute(in, outParams);
- return BooleanUtils.toBoolean(
- ((Long)result.get("result")).intValue());
- }
}
diff --git
a/java/code/src/com/redhat/rhn/manager/system/test/VirtualizationEntitlementsManagerTest.java
b/java/code/src/com/redhat/rhn/manager/system/test/VirtualizationEntitlementsManagerTest.java
new file mode 100644
index 0000000..9e5dca4
--- /dev/null
+++
b/java/code/src/com/redhat/rhn/manager/system/test/VirtualizationEntitlementsManagerTest.java
@@ -0,0 +1,220 @@
+/**
+ * Copyright (c) 2010 Red Hat, Inc.
+ *
+ * This software is licensed to you under the GNU General Public License,
+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or
+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+ * along with this software; if not, see
+ *
http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ * Red Hat trademarks are not licensed under GPLv2. No permission is
+ * granted to use or replicate Red Hat trademarks that are incorporated
+ * in this software or its documentation.
+ */
+package com.redhat.rhn.manager.system.test;
+
+import com.redhat.rhn.common.hibernate.HibernateFactory;
+import com.redhat.rhn.domain.channel.Channel;
+import com.redhat.rhn.domain.channel.ChannelFactory;
+import com.redhat.rhn.domain.channel.ChannelFamily;
+import com.redhat.rhn.domain.channel.ChannelFamilyFactory;
+import com.redhat.rhn.domain.channel.test.ChannelFactoryTest;
+import com.redhat.rhn.domain.channel.test.ChannelFamilyFactoryTest;
+import
com.redhat.rhn.domain.org.Org;
+import com.redhat.rhn.domain.org.OrgFactory;
+import com.redhat.rhn.domain.role.RoleFactory;
+import com.redhat.rhn.domain.server.EntitlementServerGroup;
+import com.redhat.rhn.domain.server.Server;
+import com.redhat.rhn.domain.server.ServerFactory;
+import com.redhat.rhn.domain.server.VirtualInstance;
+import com.redhat.rhn.domain.server.test.HostBuilder;
+import com.redhat.rhn.domain.user.User;
+import com.redhat.rhn.domain.user.UserFactory;
+import com.redhat.rhn.frontend.dto.ChannelFamilySystemGroup;
+import com.redhat.rhn.manager.entitlement.EntitlementManager;
+import com.redhat.rhn.manager.org.UpdateOrgSoftwareEntitlementsCommand;
+import com.redhat.rhn.manager.org.UpdateOrgSystemEntitlementsCommand;
+import com.redhat.rhn.manager.system.ServerGroupManager;
+import com.redhat.rhn.manager.system.SystemManager;
+import com.redhat.rhn.manager.system.VirtualizationEntitlementsManager;
+import com.redhat.rhn.testing.RhnBaseTestCase;
+import com.redhat.rhn.testing.UserTestUtils;
+
+import org.apache.commons.lang.RandomStringUtils;
+
+import java.util.List;
+
+
+/**
+ * VirtualizationEntitlementsManagerTest
+ * @version $Rev$
+ */
+public class VirtualizationEntitlementsManagerTest extends RhnBaseTestCase {
+
+ public void testListFlexGuests() throws Exception {
+ Org org =
UserTestUtils.createNewOrgFull(RandomStringUtils.randomAlphabetic(10));
+ User user = UserTestUtils.createUser(RandomStringUtils.randomAlphabetic(10),
+ org.getId());
+ user.addRole(RoleFactory.ORG_ADMIN);
+ UserFactory.save(user);
+ long ents = 3;
+ int guestsToCreate = 6;
+ long flexEnts = guestsToCreate;
+ long sysEnts = guestsToCreate + 1; // 1 for host
+ //Give it some system entitlements
+ UpdateOrgSystemEntitlementsCommand cmd1 = new
UpdateOrgSystemEntitlementsCommand(
+ EntitlementManager.MANAGEMENT, org, sysEnts);
+ assertNull(cmd1.store());
+
+ ChannelFamily rhelFamily = ChannelFamilyFactoryTest.createTestChannelFamily(
+ UserFactory.findRandomOrgAdmin(OrgFactory.getSatelliteOrg()),
+ ents, flexEnts);
+ assertEquals(Long.valueOf(flexEnts),
+ rhelFamily.getMaxFlex(OrgFactory.getSatelliteOrg()));
+ UpdateOrgSoftwareEntitlementsCommand cmd2 = new
+ UpdateOrgSoftwareEntitlementsCommand(rhelFamily.getLabel(),
+ org, ents, flexEnts);
+ assertNull(cmd2.store());
+ Channel rhelChannel = ChannelFactoryTest.createBaseChannel(user, rhelFamily);
+
+
+ HibernateFactory.getSession().clear();
+ rhelChannel = ChannelFactory.lookupById(rhelChannel.getId());
+ assertNotNull(rhelChannel.getId());
+ assertNotNull(rhelChannel);
+
+ rhelFamily = ChannelFamilyFactory.lookupById(rhelFamily.getId());
+ assertNotNull(rhelFamily);
+ assertNotNull(rhelFamily.getMaxFlex(org));
+ assertEquals(Long.valueOf(flexEnts), rhelFamily.getMaxFlex(org));
+
+ HostBuilder builder = new HostBuilder(org.getActiveOrgAdmins().get(0));
+ builder.createNonVirtHost().withGuests(guestsToCreate);
+ Server host = builder.build();
+ ServerFactory.save(host);
+
+ SystemManager.subscribeServerToChannel(user, host, rhelChannel);
+
+ ServerFactory.save(host);
+
+ for (VirtualInstance inst : host.getGuests()) {
+ SystemManager.subscribeServerToChannel(user,
+ inst.getGuestSystem(), rhelChannel);
+ SystemManager.entitleServer(inst.getGuestSystem(),
+ EntitlementManager.MANAGEMENT);
+ ServerFactory.save(inst.getGuestSystem());
+ }
+
+ HibernateFactory.getSession().clear();
+
+
+ //Verify everything is as it should be
+ EntitlementServerGroup mgmnt =
+ ServerGroupManager.getInstance().lookupEntitled(
+ EntitlementManager.MANAGEMENT, user);
+ assertEquals(Long.valueOf(sysEnts), mgmnt.getCurrentMembers());
+
+ rhelFamily = ChannelFamilyFactory.lookupById(rhelFamily.getId());
+ assertEquals(Long.valueOf(1), rhelFamily.getCurrentMembers(org));
+ assertEquals(Long.valueOf(guestsToCreate), rhelFamily.getCurrentFlex(org));
+
+ List<ChannelFamilySystemGroup> l =
VirtualizationEntitlementsManager.getInstance().
+ listFlexGuests(user);
+ assertTrue(!l.isEmpty());
+ assertEquals(1, l.size());
+ assertEquals(guestsToCreate, l.get(0).expand().size());
+ }
+
+ public void testListEligibleFlexGuests() throws Exception {
+ Org org =
UserTestUtils.createNewOrgFull(RandomStringUtils.randomAlphabetic(10));
+ User user = UserTestUtils.createUser(RandomStringUtils.randomAlphabetic(10),
+ org.getId());
+ user.addRole(RoleFactory.ORG_ADMIN);
+ UserFactory.save(user);
+ int guestsToCreate = 6;
+ long flexEnts = guestsToCreate;
+ long ents = guestsToCreate + 1; //+ 1 for host
+ long sysEnts = guestsToCreate + 1; //+ 1 for host
+ //Give it some system entitlements
+ UpdateOrgSystemEntitlementsCommand cmd1 = new
UpdateOrgSystemEntitlementsCommand(
+ EntitlementManager.MANAGEMENT, org, sysEnts);
+ assertNull(cmd1.store());
+
+ ChannelFamily rhelFamily = ChannelFamilyFactoryTest.createTestChannelFamily(
+ UserFactory.findRandomOrgAdmin(OrgFactory.getSatelliteOrg()),
+ ents, flexEnts);
+ assertEquals(Long.valueOf(flexEnts),
+ rhelFamily.getMaxFlex(OrgFactory.getSatelliteOrg()));
+
+ //No flex initially
+ UpdateOrgSoftwareEntitlementsCommand cmd2 = new
+ UpdateOrgSoftwareEntitlementsCommand(rhelFamily.getLabel(),
+ org, ents, 0L);
+ assertNull(cmd2.store());
+ Channel rhelChannel = ChannelFactoryTest.createBaseChannel(user, rhelFamily);
+
+
+ HibernateFactory.getSession().clear();
+ rhelChannel = ChannelFactory.lookupById(rhelChannel.getId());
+ assertNotNull(rhelChannel.getId());
+ assertNotNull(rhelChannel);
+
+ rhelFamily = ChannelFamilyFactory.lookupById(rhelFamily.getId());
+ assertNotNull(rhelFamily);
+ assertNotNull(rhelFamily.getMaxFlex(org));
+ assertEquals(Long.valueOf(0), rhelFamily.getMaxFlex(org));
+
+ HostBuilder builder = new HostBuilder(org.getActiveOrgAdmins().get(0));
+ builder.createNonVirtHost().withGuests(guestsToCreate);
+ Server host = builder.build();
+ ServerFactory.save(host);
+
+ SystemManager.subscribeServerToChannel(user, host, rhelChannel);
+
+ ServerFactory.save(host);
+ for (VirtualInstance inst : host.getGuests()) {
+ SystemManager.subscribeServerToChannel(user,
+ inst.getGuestSystem(), rhelChannel);
+ SystemManager.entitleServer(inst.getGuestSystem(),
+ EntitlementManager.MANAGEMENT);
+ ServerFactory.save(inst.getGuestSystem());
+ }
+
+ HibernateFactory.getSession().clear();
+
+
+ //Verify everything is as it should be
+ EntitlementServerGroup mgmnt =
+ ServerGroupManager.getInstance().lookupEntitled(
+ EntitlementManager.MANAGEMENT, user);
+ assertEquals(Long.valueOf(sysEnts), mgmnt.getCurrentMembers());
+
+ rhelFamily = ChannelFamilyFactory.lookupById(rhelFamily.getId());
+ assertEquals(Long.valueOf(ents), rhelFamily.getCurrentMembers(org));
+ assertEquals(Long.valueOf(0), rhelFamily.getCurrentFlex(org));
+
+ assertTrue(VirtualizationEntitlementsManager.getInstance().
+ listFlexGuests(user).isEmpty());
+
+ //Now Uodate the rhenChannelFamily's flex entitlements
+
+ cmd2 = new UpdateOrgSoftwareEntitlementsCommand(rhelFamily.getLabel(),
+ org, ents, flexEnts);
+ assertNull(cmd2.store());
+ HibernateFactory.getSession().clear();
+
+ rhelFamily = ChannelFamilyFactory.lookupById(rhelFamily.getId());
+ assertEquals(Long.valueOf(flexEnts), rhelFamily.getMaxFlex(org));
+
+ List<ChannelFamilySystemGroup> l = VirtualizationEntitlementsManager.
+ getInstance().listEligibleFlexGuests(user);
+
+
+ assertTrue(!l.isEmpty());
+ assertEquals(1, l.size());
+ assertEquals(guestsToCreate, l.get(0).expand().size());
+ }
+
+
+}
diff --git a/java/code/src/com/redhat/rhn/testing/UserTestUtils.java
b/java/code/src/com/redhat/rhn/testing/UserTestUtils.java
index 308e2d1..04f61d9 100644
--- a/java/code/src/com/redhat/rhn/testing/UserTestUtils.java
+++ b/java/code/src/com/redhat/rhn/testing/UserTestUtils.java
@@ -53,15 +53,25 @@ public class UserTestUtils extends Assert {
* @return long The Org id.
*/
public static Long createOrg(String orgName) {
+ return createNewOrgFull(orgName).getId();
+ }
+
+ /**
+ * Creates a new Org with the given orgName.
+ * The current time is appended to the given orgName.
+ * @param orgName Name of org.
+ * @return long The Org
+ */
+ public static Org createNewOrgFull(String orgName) {
Org org1 = OrgFactory.createOrg();
org1.setName(orgName + TestUtils.randomString());
org1.setCustomerType("B");
org1 = OrgFactory.save(org1);
assertTrue(org1.getId().longValue() > 0);
-
- return org1.getId();
+ return org1;
}
+
/**
* Creates a new User and Org with the given userName and orgName.
* The current time is appended to the given username and orgName.