Package se.gu.fire.data

Examples of se.gu.fire.data.UserManager


        testBean.clearDb();
    }

    @Test
    public void assignmentAndGrading() {
        UserManager um = new UserManager();
        um.setEntityManager(em);

        // Skapa ny grader
        FireUser u = TestUtil.createRandomUser();
        u.setRole(UserRole.GRADER);
       
        em.getTransaction().begin();
        um.create(u);
        em.getTransaction().commit();
       
        assertTrue(um.isGrader(u.getId()));
        assertTrue(um.isGrader(u));

        // Skapa en ny admin
        u = TestUtil.createRandomUser();
        u.setRole(UserRole.ADMIN);
       
        em.getTransaction().begin();
        um.create(u);
        em.getTransaction().commit();
       
        assertTrue(um.isAdmin(u.getId()));
        assertTrue(um.isAdmin(u));
    }
View Full Code Here


    }

    @Test
    public void someStudentGroupTests() {

        UserManager userMan = new UserManager();
        userMan.setEntityManager(em);
       
        GroupManager groupMan = new GroupManager();
        groupMan.setEntityManager(em);
       
        FireUser user1 = TestUtil.createRandomUser();

        StudentGroup sg = new StudentGroup();

        sg.addGroupMember(user1);

        em.getTransaction().begin();
        userMan.create(user1);
        groupMan.create(sg);
        em.getTransaction().commit();

        FireUser user2 = userMan.read(user1.getId());
        assertNotNull(user2);

        StudentGroup group = groupMan.read(sg.getId());
        assertNotNull(group);

        assertEquals(user2, user1);
       
        // Test getGroupForUser
        List<FireUser> users = groupMan.getGroupMembers(group);
        assertTrue(users.size() > 0);

        TestData data = new TestData();

        StudentGroup group2 = new StudentGroup();
        group2.addAllGroupMembers(data.users);

        em.getTransaction().begin();
        for (FireUser user : data.users) userMan.create(user);
        groupMan.create(group2);
        em.getTransaction().commit();

        StudentGroup group3 = groupMan.getGroupForUser(data.user2);
View Full Code Here

    @Test
    public void insertAndGetPassword() {
        PasswordManager pm = new PasswordManager();
        pm.setEntityManager(em);
       
        UserManager um = new UserManager();
        um.setEntityManager(em);
       
        em.getTransaction().begin();
        Password password = new Password(10L, "tio");
        pm.create(password);
        em.getTransaction().commit();
View Full Code Here

    @Test
    public void associatePasswordWithUser() {
        PasswordManager pm = new PasswordManager();
        pm.setEntityManager(em);
       
        UserManager um = new UserManager();
        um.setEntityManager(em);
       
        FireUser oscar = TestUtil.createRandomUser();

        em.getTransaction().begin();
        um.create(oscar);
        em.getTransaction().commit();
       
        FireUser u5 = um.read(oscar.getId());
        assertNotNull(u5);

        String smart = "haxx";
        Password oscarsPassword = new Password(oscar.getId(), smart);
        em.getTransaction().begin();
View Full Code Here

   
    @Test (expected=RollbackException.class)
    public void ensureUnique() {

       
        UserManager um = new UserManager();
        um.setEntityManager(em);
       
        String email = "notUnique@hotmail.com";
       
          // Test getting same item back!
        FireUser user = TestUtil.createRandomUser();
        user.setEmail(email);

        em.getTransaction().begin();
        um.create(user);
        em.getTransaction().commit();
       
        user = TestUtil.createRandomUser();
        user.setEmail(email);
       
        em.getTransaction().begin();
        um.create(user);
        em.getTransaction().commit();
       
    }
View Full Code Here

    }

    @Test
    public void insertAndFetchUser() {
       
        UserManager userMan = new UserManager();
        userMan.setEntityManager(em);
       
          // Test getting same item back using email!
        String johnEmail = "aa@a.com";
       
        FireUser user1 =  TestUtil.createRandomUser();
        user1.setEmail(johnEmail);
       
        List<FireUser> us = userMan.getAll();
        for (FireUser u : us) System.out.println("User: " + u.getEmail());
       
        em.getTransaction().begin();
        userMan.create(user1);
        em.getTransaction().commit();

        // Lets find per email
        FireUser user = userMan.findUser(johnEmail);
        assertNotNull(user);
       
        List<FireUser> users = userMan.findUsersByFirstName(user1.getFname());
        assertTrue(users.contains(user1));
       
        users = userMan.findUsersByLastName(user1.getLname());
        assertTrue(users.contains(user1));
       
        FireUser user2 = userMan.read(user1.getId());

        assertNotNull(user2);
        assertTrue(user1.equals(user2));

        // Add 10 users to ensure we have enought
        // users for following tests
        em.getTransaction().begin();
        for(int i = 0; i < 10; i++) {
            userMan.create(new FireUser());
        }
        em.getTransaction().commit();
       
        // Get all
        List<FireUser> all = userMan.getAll();
        assertTrue(all.size() >= 10);

        // Get range tests
        all = userMan.getRange(0, 5);
        assertTrue(all.size() == 5);

        all = userMan.getRange(5, 5);
        assertTrue(all.size() == 5);

        // Test update
        String name = user1.getFname();
        user2.setFname("Another");
        em.getTransaction().begin();
        userMan.update(user2);
        em.getTransaction().commit();
       
        user2 = userMan.read(user1.getId());
        assertFalse(name.equals(user2.getFname()));

        // Test remove
        em.getTransaction().begin();
        userMan.delete(user2);
        em.getTransaction().commit();
        user2 = userMan.read(user1.getId());
        assertNull(user2);
             
    }
View Full Code Here

    public TestBean(EntityManager entMan) {
        this.entMan = entMan;

        assignMan = new AssignmentManager();
        subMan = new SubmissionManager();
        userMan = new UserManager();
        groupMan = new GroupManager();
        comMan = new CommentManager();
        passMan = new PasswordManager();
        fileMan = new StoredFileManager();
        mans = collectMans();
View Full Code Here

        am.setEntityManager(em);

        SubmissionManager sm = new SubmissionManager();
        sm.setEntityManager(em);

        UserManager um = new UserManager();
        um.setEntityManager(em);

        GroupManager gm = new GroupManager();
        gm.setEntityManager(em);

        CommentManager cm = new CommentManager();
        cm.setEntityManager(em);

        // Fix assignment
        Assignment assign = new Assignment.Builder()
                .title("Ratnum labb")
                .information("Programmera RatNum labben ordentligt annars kommer Christopher.")
                .finalDeadline(new Date(Calendar.getInstance().getTime().getTime()+15000))
                .firstDeadline(new Date(Calendar.getInstance().getTime().getTime()+10000))
                .build();
           
        em.getTransaction().begin();
        am.create(assign);
        em.getTransaction().commit();


        // Fix users
        FireUser u = TestUtil.createRandomUser();
       
        em.getTransaction().begin();
        um.create(u);
        em.getTransaction().commit();


        FireUser u2 = TestUtil.createRandomUser();
       
        em.getTransaction().begin();
        um.create(u2);
        em.getTransaction().commit();

        // Student group
        StudentGroup group = new StudentGroup();
        em.getTransaction().begin();
View Full Code Here

TOP

Related Classes of se.gu.fire.data.UserManager

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.