new tests to show errors in pac module
| | |
| | | -- 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) |
| | |
| | | -- 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) |
| | |
| | | @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") |
| | |
| | | @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()); |
| | |
| | | pacComp.setCreated(today); |
| | | pacComp.setComponent(comp); |
| | | pacComp.setPac(this); |
| | | pacComp.setQuantity(comp.getDefaultQuantity()); |
| | | if (setDefaults) { |
| | | pacComp.setQuantity(comp.getDefaultQuantity()); |
| | | } else { |
| | | pacComp.setQuantity(UNDEFINED_QUANTITY); |
| | | } |
| | | pacComponents.add(pacComp); |
| | | } |
| | | } |
| | |
| | | this.component = component; |
| | | } |
| | | |
| | | @Override |
| | | public String toString() { |
| | | return "pac=" + pac.getName() + ";comp=" + component.getBaseComponent().getFeature() + ";quantity=" + getQuantity(); |
| | | } |
| | | |
| | | } |
| | |
| | | pacComponent.setPac(pac); |
| | | String feature = baseComponent.getFeature(); |
| | | 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); |
| | | } |
| | | pac.setPacComponents(pacComponents); |
| | |
| | | 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(); |
| | |
| | | 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; |
| | |
| | | } |
| | | |
| | | @Test |
| | | public void testUpdate() { |
| | | public void testUpdateByPacadminFails() { |
| | | String user = "aaa00"; |
| | | String grantingTicketURL = cas.getGrantingTicketURL(user); |
| | | Map<String, String> setParams = new HashMap<String, String>(); |
| | |
| | | } |
| | | |
| | | @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(); |
| | | String user = "ad"; |