Package org.springmodules.prevayler.test.domain

Examples of org.springmodules.prevayler.test.domain.EmployeeImpl


        emp1 = (EmployeeImpl) this.template.get(Employee.class, emp1.getId());
        assertEquals("Sergio", emp1.getFirstname());
    }
   
    public void testDeleteByEntity() {
        EmployeeImpl emp = new EmployeeImpl("a1");
       
        // Add an employee:
        this.template.save(emp);
       
        // Delete it:
        this.template.delete(emp);
        // Try to get it by id and verify null is returned:
        emp = (EmployeeImpl) this.template.get(emp.getClass(), emp.getId());
        assertNull(emp);
    }
View Full Code Here


        emp = (EmployeeImpl) this.template.get(emp.getClass(), emp.getId());
        assertNull(emp);
    }
   
    public void testDeleteByEntityClass() {
        EmployeeImpl emp = new EmployeeImpl("a1");
       
        // Add an employee:
        this.template.save(emp);
        // Verify:
        List result = this.template.get(emp.getClass());
        assertFalse(result.isEmpty());
       
        // Delete all:
        this.template.delete(emp.getClass());
        // Try to get all employees and verify that an empty list is returned:
        result = this.template.get(emp.getClass());
        assertTrue(result.isEmpty());
    }
View Full Code Here

    protected void setUp() throws Exception {
        this.resolver = new DefaultIdResolver();
    }

    public void testResolveId() {
        Employee emp = new EmployeeImpl("a1");
        assertNotNull(this.resolver.resolveId(emp));
       
        Manager man = new ManagerImpl("a1");
        assertNotNull(this.resolver.resolveId(man));
    }
View Full Code Here

        result = this.template.get(emp.getClass());
        assertTrue(result.isEmpty());
    }
   
    public void testExecuteCallback() {
        EmployeeImpl emp1 = new EmployeeImpl("a1");
        EmployeeImpl emp2 = new EmployeeImpl("a2");
       
        this.template.save(emp1);
        this.template.save(emp2);
       
        assertNull(emp1.getFirstname());
        assertNull(emp1.getSurname());
       
        // Execute a callback which looks for a1 and update it:
        PrevaylerCallback callback = new SimpleSearchAndUpdatePrevaylerCallback();
        // The callback execution returns a list of one employee:
        List result = (List) this.template.execute(callback);
        assertEquals(1, result.size());
        // Get it:
        emp1 = (EmployeeImpl) result.get(0);
        // Verify the update:
        assertTrue(emp1.getFirstname().equals("Sergio"));
        assertTrue(emp1.getSurname().equals("Bossa"));
       
        // Verify it is the same as the one directly retrieved from the prevalent system:
        EmployeeImpl emp1_1 = (EmployeeImpl) this.template.get(Employee.class, emp1.getId());
        assertSame(emp1, emp1_1);
    }
View Full Code Here

        EmployeeImpl emp1_1 = (EmployeeImpl) this.template.get(Employee.class, emp1.getId());
        assertSame(emp1, emp1_1);
    }
   
    public void testConcurrentUpdates() throws Exception {
        EmployeeImpl emp = new EmployeeImpl("a1");
        this.template.save(emp);
        final Object id = emp.getId();
       
        Runnable r1 = new Runnable() {
            public void run() {
                PrevaylerTemplateTest.this.template.execute(new SleepingPrevaylerCallback(id));
            }
View Full Code Here

    }

    public void testMergeObjects() throws Exception {
        OfficeImpl o1 = new OfficeImpl("o1", "Office 1");
        ManagerImpl m1 = new ManagerImpl("m1");
        EmployeeImpl e1 = new EmployeeImpl("e1");
        o1.setId(new Long(1));
        e1.setId(new Long(2));
        e1.setOffice(o1);
        m1.setId(new Long(1));
        m1.addManagedEmployee(e1);
        m1.setOffice(o1);
       
        OfficeImpl o2 = new OfficeImpl("o1", "Office 1");
        ManagerImpl m2 = new ManagerImpl("m1");
        EmployeeImpl e2 = new EmployeeImpl("e1");
        e2.setOffice(o2);
        m2.addManagedEmployee(e2);
        m2.setOffice(o2);
       
        assertNull(o2.getId());
        assertNull(m2.getId());
        assertNull(e2.getId());
       
        this.merger.merge(m1, m2);
       
        assertNotNull(o2.getId());
        assertEquals(o1.getId(), o2.getId());
        assertNotNull(m2.getId());
        assertEquals(m1.getId(), m2.getId());
        assertNotNull(e2.getId());
        assertEquals(e1.getId(), e2.getId());
    }
View Full Code Here

    public SleepingPrevaylerCallback(Object entityId) {
        this.entityId = entityId;
    }
   
    public Object doInTransaction(PrevalentSystem system) {
        EmployeeImpl emp = (EmployeeImpl) system.get(Employee.class, this.entityId);
        try {
            Thread.sleep(1000);
        }
        catch (InterruptedException ex) {
            ex.printStackTrace();
        }
        System.out.println("Setting name to Paul!");
        System.out.println("Current name: " + emp.getFirstname());
        emp.setFirstname("Paul");
        emp = (EmployeeImpl) system.update(emp);
        System.out.println("Name set to Paul!");
        return emp;
    }
View Full Code Here

    }
   
    public void testMergeArrays() throws Exception {
        OfficeImpl o1 = new OfficeImpl("o1", "Office 1");
        ManagerImpl m1 = new ManagerImpl("m1");
        EmployeeImpl e1 = new EmployeeImpl("e1");
        o1.setId(new Long(1));
        e1.setId(new Long(2));
        e1.setOffice(o1);
        m1.setId(new Long(1));
        m1.addManagedEmployee(e1);
        m1.setOffice(o1);
       
        OfficeImpl o2 = new OfficeImpl("o1", "Office 1");
        ManagerImpl m2 = new ManagerImpl("m1");
        EmployeeImpl e2 = new EmployeeImpl("e1");
        e2.setOffice(o2);
        m2.addManagedEmployee(e2);
        m2.setOffice(o2);
       
        assertNull(o2.getId());
        assertNull(m2.getId());
        assertNull(e2.getId());
       
        Employee[] emps1 = {e1, m1};
        Employee[] emps2 = {e2, m2};
       
        this.merger.merge(emps1, emps2);
       
        assertNotNull(o2.getId());
        assertEquals(o1.getId(), o2.getId());
        assertNotNull(m2.getId());
        assertEquals(m1.getId(), m2.getId());
        assertNotNull(e2.getId());
        assertEquals(e1.getId(), e2.getId());
    }
View Full Code Here

    }
   
    public void testMergeCollections() throws Exception {
        OfficeImpl o1 = new OfficeImpl("o1", "Office 1");
        ManagerImpl m1 = new ManagerImpl("m1");
        EmployeeImpl e1 = new EmployeeImpl("e1");
        o1.setId(new Long(1));
        e1.setId(new Long(2));
        e1.setOffice(o1);
        m1.setId(new Long(1));
        m1.addManagedEmployee(e1);
        m1.setOffice(o1);
       
        OfficeImpl o2 = new OfficeImpl("o1", "Office 1");
        ManagerImpl m2 = new ManagerImpl("m1");
        EmployeeImpl e2 = new EmployeeImpl("e1");
        e2.setOffice(o2);
        m2.addManagedEmployee(e2);
        m2.setOffice(o2);
       
        assertNull(o2.getId());
        assertNull(m2.getId());
        assertNull(e2.getId());
       
        Set emps1 = new HashSet(Arrays.asList(new Employee[]{e1, m1}));
        Set emps2 = new HashSet(Arrays.asList(new Employee[]{e2, m2}));
       
        this.merger.merge(emps1, emps2);
       
        assertNotNull(o2.getId());
        assertEquals(o1.getId(), o2.getId());
        assertNotNull(m2.getId());
        assertEquals(m1.getId(), m2.getId());
        assertNotNull(e2.getId());
        assertEquals(e1.getId(), e2.getId());
    }
View Full Code Here

    }
   
    public void testMergeMaps() throws Exception {
        OfficeImpl o1 = new OfficeImpl("o1", "Office 1");
        ManagerImpl m1 = new ManagerImpl("m1");
        EmployeeImpl e1 = new EmployeeImpl("e1");
        o1.setId(new Long(1));
        e1.setId(new Long(2));
        e1.setOffice(o1);
        m1.setId(new Long(1));
        m1.addManagedEmployee(e1);
        m1.setOffice(o1);
       
        OfficeImpl o2 = new OfficeImpl("o1", "Office 1");
        ManagerImpl m2 = new ManagerImpl("m1");
        EmployeeImpl e2 = new EmployeeImpl("e1");
        e2.setOffice(o2);
        m2.addManagedEmployee(e2);
        m2.setOffice(o2);
       
        assertNull(o2.getId());
        assertNull(m2.getId());
        assertNull(e2.getId());
       
        Map emps1 = new HashMap();
        Map emps2 = new HashMap();
        emps1.put(e1.getMatriculationCode(), e1);
        emps1.put(m1.getMatriculationCode(), m1);
        emps2.put(e2.getMatriculationCode(), e2);
        emps2.put(m2.getMatriculationCode(), m2);
       
        this.merger.merge(emps1, emps2);
       
        assertNotNull(o2.getId());
        assertNotNull(m2.getId());
        assertNotNull(e2.getId());
    }
View Full Code Here

TOP

Related Classes of org.springmodules.prevayler.test.domain.EmployeeImpl

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.