HSAdmin Backend Domains, E-Mail, Datenbanken
Peter Hormanns
2013-05-06 5028419aa3c51b06418b7c80b9859e811959afc4
new tests to show errors in pac module
6 files modified
100 ■■■■ changed files
hsarback/database/data.sql 8 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/Pac.java 14 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/PacComponent.java 5 ●●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java 8 ●●●● patch | view | raw | blame | history
hsarback/src/de/hsadmin/remote/PacRemote.java 2 ●●● patch | view | raw | blame | history
hsarback/test/de/hsadmin/remote/PacTest.java 63 ●●●●● patch | view | raw | blame | history
hsarback/database/data.sql
@@ -14,7 +14,7 @@
-- 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 @@
-- 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)
hsarback/src/de/hsadmin/mods/pac/Pac.java
@@ -36,13 +36,15 @@
@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 @@
    @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 @@
            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);
        }
    }
hsarback/src/de/hsadmin/mods/pac/PacComponent.java
@@ -93,4 +93,9 @@
        this.component = component;
    }
    @Override
    public String toString() {
        return "pac=" + pac.getName() + ";comp=" + component.getBaseComponent().getFeature() + ";quantity=" + getQuantity();
    }
}
hsarback/src/de/hsadmin/mods/pac/PacModuleImpl.java
@@ -84,7 +84,11 @@
            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);
@@ -145,7 +149,7 @@
            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();
hsarback/src/de/hsadmin/remote/PacRemote.java
@@ -94,7 +94,7 @@
            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;
hsarback/test/de/hsadmin/remote/PacTest.java
@@ -64,7 +64,7 @@
    }
    @Test
    public void testUpdate() {
    public void testUpdateByPacadminFails() {
        String user = "aaa00";
        String grantingTicketURL = cas.getGrantingTicketURL(user);
        Map<String, String> setParams = new HashMap<String, String>();
@@ -84,6 +84,67 @@
    }
    @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";