new tests to show errors in pac module
This commit is contained in:
parent
70752cf64b
commit
5028419aa3
@ -14,7 +14,7 @@ INSERT INTO basepacket (basepacket_code, description, sorting, valid, article_nu
|
|||||||
-- Table: basecomponent
|
-- Table: basecomponent
|
||||||
--
|
--
|
||||||
INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
|
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)
|
INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
|
||||||
VALUES ('TRAFFIC', 'Monatliches Datenvolumen in GB', 200, true);
|
VALUES ('TRAFFIC', 'Monatliches Datenvolumen in GB', 200, true);
|
||||||
INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
|
INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
|
||||||
@ -34,11 +34,11 @@ INSERT INTO basecomponent (basecomponent_code, description, sorting, valid)
|
|||||||
-- Table: component
|
-- Table: component
|
||||||
--
|
--
|
||||||
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
|
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)
|
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)
|
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)
|
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';
|
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)
|
INSERT INTO component (basepacket_id, basecomponent_id, min_quantity, max_quantity, default_quantity, increment_quantity, include_quantity, admin_only, article_number)
|
||||||
|
@ -36,13 +36,15 @@ import de.hsadmin.mods.user.UnixUser;
|
|||||||
@AnnModuleImpl(de.hsadmin.mods.pac.PacModuleImpl.class)
|
@AnnModuleImpl(de.hsadmin.mods.pac.PacModuleImpl.class)
|
||||||
public class Pac extends AbstractEntity implements Serializable {
|
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_DW = "PAC/DW";
|
||||||
public static final String PAC_SW = "PAC/SW";
|
public static final String PAC_SW = "PAC/SW";
|
||||||
public static final String PAC_WEB = "PAC/WEB";
|
public static final String PAC_WEB = "PAC/WEB";
|
||||||
public static final String PAC_SRV = "SRV/MGD";
|
public static final String PAC_SRV = "SRV/MGD";
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
@Id
|
@Id
|
||||||
@GeneratedValue(strategy = SEQUENCE, generator = "PacsSeqGen")
|
@GeneratedValue(strategy = SEQUENCE, generator = "PacsSeqGen")
|
||||||
@Column(name = "packet_id", columnDefinition = "integer")
|
@Column(name = "packet_id", columnDefinition = "integer")
|
||||||
@ -87,7 +89,7 @@ public class Pac extends AbstractEntity implements Serializable {
|
|||||||
@Transient
|
@Transient
|
||||||
private BasePac basepac;
|
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");
|
Query qAttachedBasepac = em.createQuery("SELECT b FROM BasePacs b WHERE b.valid = :valid AND b.name = :name");
|
||||||
qAttachedBasepac.setParameter("valid", Boolean.TRUE);
|
qAttachedBasepac.setParameter("valid", Boolean.TRUE);
|
||||||
qAttachedBasepac.setParameter("name", aBasepac.getName());
|
qAttachedBasepac.setParameter("name", aBasepac.getName());
|
||||||
@ -100,7 +102,11 @@ public class Pac extends AbstractEntity implements Serializable {
|
|||||||
pacComp.setCreated(today);
|
pacComp.setCreated(today);
|
||||||
pacComp.setComponent(comp);
|
pacComp.setComponent(comp);
|
||||||
pacComp.setPac(this);
|
pacComp.setPac(this);
|
||||||
pacComp.setQuantity(comp.getDefaultQuantity());
|
if (setDefaults) {
|
||||||
|
pacComp.setQuantity(comp.getDefaultQuantity());
|
||||||
|
} else {
|
||||||
|
pacComp.setQuantity(UNDEFINED_QUANTITY);
|
||||||
|
}
|
||||||
pacComponents.add(pacComp);
|
pacComponents.add(pacComp);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -93,4 +93,9 @@ public class PacComponent implements Serializable {
|
|||||||
this.component = component;
|
this.component = component;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "pac=" + pac.getName() + ";comp=" + component.getBaseComponent().getFeature() + ";quantity=" + getQuantity();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -84,7 +84,11 @@ public class PacModuleImpl extends AbstractModuleImpl {
|
|||||||
pacComponent.setPac(pac);
|
pacComponent.setPac(pac);
|
||||||
String feature = baseComponent.getFeature();
|
String feature = baseComponent.getFeature();
|
||||||
int requestedQuantity = pac.getPacComponent(feature).getQuantity();
|
int requestedQuantity = pac.getPacComponent(feature).getQuantity();
|
||||||
pacComponent.setQuantity(requestedQuantity);
|
if (requestedQuantity == Pac.UNDEFINED_QUANTITY) {
|
||||||
|
pacComponent.setQuantity(comp.getDefaultQuantity());
|
||||||
|
} else {
|
||||||
|
pacComponent.setQuantity(requestedQuantity);
|
||||||
|
}
|
||||||
pacComponents.add(pacComponent);
|
pacComponents.add(pacComponent);
|
||||||
}
|
}
|
||||||
pac.setPacComponents(pacComponents);
|
pac.setPacComponents(pacComponents);
|
||||||
@ -145,7 +149,7 @@ public class PacModuleImpl extends AbstractModuleImpl {
|
|||||||
newState.getPacComponents().clear();
|
newState.getPacComponents().clear();
|
||||||
em.flush();
|
em.flush();
|
||||||
newState.setBasepac(newBasepac);
|
newState.setBasepac(newBasepac);
|
||||||
newState.initPacComponents(em, newBasepac);
|
newState.initPacComponents(em, newBasepac, false);
|
||||||
Set<PacComponent> newPacComponents = newState.getPacComponents();
|
Set<PacComponent> newPacComponents = newState.getPacComponents();
|
||||||
for (PacComponent pc : newPacComponents) {
|
for (PacComponent pc : newPacComponents) {
|
||||||
BaseComponent bc = pc.getBaseComponent();
|
BaseComponent bc = pc.getBaseComponent();
|
||||||
|
@ -94,7 +94,7 @@ public class PacRemote extends AbstractRemote {
|
|||||||
hive.setName(hiveName);
|
hive.setName(hiveName);
|
||||||
pac.setHive(hive);
|
pac.setHive(hive);
|
||||||
}
|
}
|
||||||
pac.initPacComponents(tx.getEntityManager(), basePac);
|
pac.initPacComponents(tx.getEntityManager(), basePac, false);
|
||||||
Object componentsObj = setParams.get("components");
|
Object componentsObj = setParams.get("components");
|
||||||
if (componentsObj != null && componentsObj instanceof Map) {
|
if (componentsObj != null && componentsObj instanceof Map) {
|
||||||
Map<?, ?> componentsMap = (Map<?, ?>) componentsObj;
|
Map<?, ?> componentsMap = (Map<?, ?>) componentsObj;
|
||||||
|
@ -64,7 +64,7 @@ public class PacTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testUpdate() {
|
public void testUpdateByPacadminFails() {
|
||||||
String user = "aaa00";
|
String user = "aaa00";
|
||||||
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
String grantingTicketURL = cas.getGrantingTicketURL(user);
|
||||||
Map<String, String> setParams = new HashMap<String, String>();
|
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
|
@Test
|
||||||
public void testCreateWeb() {
|
public void testCreateWeb() {
|
||||||
int count = getPacsCount();
|
int count = getPacsCount();
|
||||||
|
Loading…
Reference in New Issue
Block a user