new tests to show errors in pac module

This commit is contained in:
Peter Hormanns 2013-05-06 19:59:23 +02:00
parent 70752cf64b
commit 5028419aa3
6 changed files with 88 additions and 12 deletions

View File

@ -14,7 +14,7 @@ INSERT INTO basepacket (basepacket_code, description, sorting, valid, article_nu
-- Table: basecomponent
--
INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
VALUES ('MULTI', 'Monatliches Datenvolumen in GB', 100, true);
VALUES ('MULTI', 'Accounts', 100, true);
INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
VALUES ('TRAFFIC', 'Monatliches Datenvolumen in GB', 200, true);
INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
@ -34,11 +34,11 @@ INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
-- Table: component
--
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 1, 1, 1, 1, 1, false, 100 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='MULTI';
SELECT basepacket_id, basecomponent_id, 1, 10, 1, 1, 1, false, 100 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='MULTI';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 1, 1, 1, 1, 1, false, 200 FROM basepacket, basecomponent WHERE basepacket_code='PAC/SW' AND basecomponent_code='MULTI';
SELECT basepacket_id, basecomponent_id, 1, 10, 1, 1, 1, false, 200 FROM basepacket, basecomponent WHERE basepacket_code='PAC/SW' AND basecomponent_code='MULTI';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 1, 1, 1, 1, 1, false, 300 FROM basepacket, basecomponent WHERE basepacket_code='PAC/WEB' AND basecomponent_code='MULTI';
SELECT basepacket_id, basecomponent_id, 1, 10, 1, 1, 1, false, 300 FROM basepacket, basecomponent WHERE basepacket_code='PAC/WEB' AND basecomponent_code='MULTI';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
SELECT basepacket_id, basecomponent_id, 128, 40960, 128, 128, 128, false, 101 FROM basepacket, basecomponent WHERE basepacket_code='PAC/DW' AND basecomponent_code='QUOTA';
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)

View File

@ -36,13 +36,15 @@ import de.hsadmin.mods.user.UnixUser;
@AnnModuleImpl(de.hsadmin.mods.pac.PacModuleImpl.class)
public class Pac extends AbstractEntity implements Serializable {
private static final long serialVersionUID = 1L;
public static final int UNDEFINED_QUANTITY = -1;
public static final String PAC_DW = "PAC/DW";
public static final String PAC_SW = "PAC/SW";
public static final String PAC_WEB = "PAC/WEB";
public static final String PAC_SRV = "SRV/MGD";
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = SEQUENCE, generator = "PacsSeqGen")
@Column(name = "packet_id", columnDefinition = "integer")
@ -87,7 +89,7 @@ public class Pac extends AbstractEntity implements Serializable {
@Transient
private BasePac basepac;
public void initPacComponents(EntityManager em, BasePac aBasepac) {
public void initPacComponents(EntityManager em, BasePac aBasepac, boolean setDefaults) {
Query qAttachedBasepac = em.createQuery("SELECT b FROM BasePacs b WHERE b.valid = :valid AND b.name = :name");
qAttachedBasepac.setParameter("valid", Boolean.TRUE);
qAttachedBasepac.setParameter("name", aBasepac.getName());
@ -100,7 +102,11 @@ public class Pac extends AbstractEntity implements Serializable {
pacComp.setCreated(today);
pacComp.setComponent(comp);
pacComp.setPac(this);
if (setDefaults) {
pacComp.setQuantity(comp.getDefaultQuantity());
} else {
pacComp.setQuantity(UNDEFINED_QUANTITY);
}
pacComponents.add(pacComp);
}
}

View File

@ -93,4 +93,9 @@ public class PacComponent implements Serializable {
this.component = component;
}
@Override
public String toString() {
return "pac=" + pac.getName() + ";comp=" + component.getBaseComponent().getFeature() + ";quantity=" + getQuantity();
}
}

View File

@ -84,7 +84,11 @@ public class PacModuleImpl extends AbstractModuleImpl {
pacComponent.setPac(pac);
String feature = baseComponent.getFeature();
int requestedQuantity = pac.getPacComponent(feature).getQuantity();
if (requestedQuantity == Pac.UNDEFINED_QUANTITY) {
pacComponent.setQuantity(comp.getDefaultQuantity());
} else {
pacComponent.setQuantity(requestedQuantity);
}
pacComponents.add(pacComponent);
}
pac.setPacComponents(pacComponents);
@ -145,7 +149,7 @@ public class PacModuleImpl extends AbstractModuleImpl {
newState.getPacComponents().clear();
em.flush();
newState.setBasepac(newBasepac);
newState.initPacComponents(em, newBasepac);
newState.initPacComponents(em, newBasepac, false);
Set<PacComponent> newPacComponents = newState.getPacComponents();
for (PacComponent pc : newPacComponents) {
BaseComponent bc = pc.getBaseComponent();

View File

@ -94,7 +94,7 @@ public class PacRemote extends AbstractRemote {
hive.setName(hiveName);
pac.setHive(hive);
}
pac.initPacComponents(tx.getEntityManager(), basePac);
pac.initPacComponents(tx.getEntityManager(), basePac, false);
Object componentsObj = setParams.get("components");
if (componentsObj != null && componentsObj instanceof Map) {
Map<?, ?> componentsMap = (Map<?, ?>) componentsObj;

View File

@ -64,7 +64,7 @@ public class PacTest {
}
@Test
public void testUpdate() {
public void testUpdateByPacadminFails() {
String user = "aaa00";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> setParams = new HashMap<String, String>();
@ -83,6 +83,67 @@ public class PacTest {
}
}
@Test
public void testUpdateInvalidValueFails() {
String user = "ad";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> componentsMap = new HashMap<String,String>();
componentsMap.put("QUOTA", "524");
Map<String, Object> setParams = new HashMap<String,Object>();
Map<String, Object> whereParams = new HashMap<String,Object>();
setParams.put("components", componentsMap);
whereParams.put("name", "aaa00");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams, whereParams };
try {
Object execute = client.execute(MODULE + ".update", params);
assertNotNull(execute);
fail("exception expected");
} catch (XmlRpcException e) {
}
}
@Test
public void testUpdateValidValue() {
String user = "ad";
String grantingTicketURL = cas.getGrantingTicketURL(user);
Map<String, String> componentsMap = new HashMap<String,String>();
componentsMap.put("QUOTA", "640");
Map<String, Object> setParams = new HashMap<String,Object>();
Map<String, Object> whereParams = new HashMap<String,Object>();
setParams.put("components", componentsMap);
whereParams.put("name", "aaa00");
Object[] params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
setParams, whereParams };
try {
Object execute = client.execute(MODULE + ".update", params);
assertNotNull(execute);
params = new Object[] { user,
cas.getServiceTicket(grantingTicketURL, RemoteTestHelper.getBackendURL()),
whereParams };
execute = client.execute(MODULE + ".search", params);
assertNotNull(execute);
assertTrue(execute instanceof Object[]);
Object[] untypedResultArray = (Object[]) execute;
assertEquals(1, untypedResultArray.length);
assertTrue(untypedResultArray[0] instanceof Map<?,?>);
@SuppressWarnings("unchecked")
Map<String, ?> pacResultMap = (Map<String, ?>) untypedResultArray[0];
assertEquals(Pac.PAC_WEB, pacResultMap.get("basepac"));
Object compMapObj = pacResultMap.get("components");
assertTrue(compMapObj instanceof Map<?,?>);
@SuppressWarnings("unchecked")
Map<String,String> compMap = (Map<String, String>) compMapObj;
assertEquals("640", compMap.get("QUOTA"));
assertEquals("2", compMap.get("TRAFFIC"));
assertEquals("1", compMap.get("MULTI"));
} catch (XmlRpcException e) {
fail(e.getMessage());
}
}
@Test
public void testCreateWeb() {
int count = getPacsCount();