Package cz.muni.fi.pa165.stis.entity

Examples of cz.muni.fi.pa165.stis.entity.User


            throw new IllegalArgumentException("user is null");
        }
        if (user.getId() == null) {
            throw new IllegalArgumentException("user.id is null");
        }
        User user2 = mapper.map(user, User.class);
        dao.makeAdmin(user2);
    }
View Full Code Here


        assertNotNull("ID is null", user.getId());
    }

    @Test
    public void testGet() {
        User u = newUser(null, null, true);
        userDAO.create(u);
        Long id = null;
        try {
            userDAO.get(id);
            fail("Id null and didn't throw exception");
        } catch (DataAccessException ex) {
            //ok
        } catch (Exception ex) {
            fail("Id null and didn't throw appropriate exception");
        }
        User u2 = userDAO.get(u.getId());
        assertNotNull("User is null", u2);
        assertEquals("Users are not the same", u2, u);
        assertDeepEquals(u, u2);
        User u3 = userDAO.get(u.getId() + 1); // shouldn't exist
        assertNull("User is not null", u3);
        removeAll();
    }
View Full Code Here

        removeAll();
    }

    @Test
    public void testUpdate() {
        User u = newUser(null, null, false);
        userDAO.create(u);
        Long uId = u.getId();
        u.setId(null);
        //
        try {
            userDAO.update(null);
            fail("User is null and didn't throw exception");
        } catch (DataAccessException ex) {
            //ok
        } catch (Exception ex) {
            fail("User is null and didn't throw appropriate exception");
        }
        try {
            userDAO.update(u);
            fail("User is ID null and didn't throw exception");
        } catch (DataAccessException ex) {
            //ok
        } catch (Exception ex) {
            fail("User is ID null and didn't throw appropriate exception");
        }
        //
        u.setId(uId);
        userDAO.update(u);
        //
        User u2 = userDAO.get(u.getId());
        assertEquals("Customer are not the same", u2, u);
        assertDeepEquals(u2, u);
    }
View Full Code Here

        assertDeepEquals(u2, u);
    }

    @Test
    public void testRemove() {
        User u = newUser(null, null, false);
        userDAO.create(u);
        //
        try {
            userDAO.remove(null);
            fail("User is null and didn't throw exception");
        } catch (DataAccessException ex) {
            //ok
        } catch (Exception ex) {
            fail("User is null and didn't throw appropriate exception");
        }
        try {
            userDAO.remove(new User());
            fail("User ID is null and didn't throw exception");
        } catch (DataAccessException ex) {
            // ok
        } catch (Exception ex) {
            fail("User ID is null and didn't throw appropriate exception");
        }
        try {
            User u2 = new User();
            u2.setId(-1L);
            userDAO.remove(u2);
            fail("Shouldn't remove non-existent entity");
        } catch (DataAccessException ex) {
            //ok
        } catch (Exception ex) {
            fail("Non existent user - should throw appropriate exception");
        }
        //
        userDAO.remove(u);
        User u3 = userDAO.get(u.getId());
        assertNull("Found user that shouldn't be there", u3);
        removeAll();
    }
View Full Code Here

        }
    }

    @Test
    public void testGetByUsername() {
        User user1 = newUser("Jan", "Hrach", false);
        User user2 = newUser("Bruce", "Willis", false);
        User user3 = newUser("Peter", "Mravec", true);
        List<User> users = new ArrayList<>();
        users.add(user1);
        users.add(user2);
        users.add(user3);                   
               
        for (User u : users) {
            userDAO.create(u);
        }
       
        User user4 = userDAO.getByUsername("Peter");
        assertEquals(user4, user3);
        try {
            userDAO.getByUsername("Lukas");
        } catch (DataAccessException e) {
            //ok
View Full Code Here

                    newUser("Peter", "Mravec", true)
                });
        for (User u : users) {
            userDAO.create(u);
        }
        User u1 = newUser("Bruce", "pass", false);
        User u2 = newUser("Bruce1", "pass", false);
        assertFalse("Username exist", userDAO.availableUsername(u1.getUsername()));
        assertTrue("Username is free", userDAO.availableUsername(u2.getUsername()));
    }
View Full Code Here

        assertTrue("Username is admin", userDAO.isAdmin(users.get(1)));
    }

    @Test
    public void testMakeAdmin() {
        User u1 = newUser("Bruce", "pass", false);
        userDAO.create(u1);
        assertFalse("Username is not admin", userDAO.isAdmin(u1));
        userDAO.makeAdmin(u1);
        assertTrue("Username is admin", userDAO.isAdmin(u1));
    }
View Full Code Here

            userDAO.remove(t);
        }
    }

    private static User newUser(String userName, String password, boolean isAdmin) {
        User user = new User();
        user.setUsername(userName);
        user.setPassword(password);
        user.setRoleAdmin(isAdmin);

        return user;
    }
View Full Code Here

        customer = createCustomer(null, "Adam", "Petrik", "Burzoazna 12", "112567");
        customerTO = mapper.map(customer, CustomerTO.class);       
        CustomerUserTO customerUserTO = new CustomerUserTO(customerTO, userTO);
        customerTO.setUser(userTO)
               
        User user2 = createUser("ferko22", "bak!s$#", false);
        UserTO userTO2 = mapper.map(user2, UserTO.class);       
        Customer customer2 = createCustomer(null, "Petko", "Mravcek", "Teplicka nad Vahom 142", "772222222");
        CustomerTO customerTO2 = mapper.map(customer2, CustomerTO.class);       
        CustomerUserTO customerUserTO2 = new CustomerUserTO(customerTO2, userTO2);
        customerTO2.setUser(userTO2)
View Full Code Here

        c.setPhone(phone);
        return c;
    }

    private static User createUser(String username, String password, boolean roleAdmin) {
        User user = new User();
        user.setUsername(username);
        user.setPassword(password);
        user.setRoleAdmin(roleAdmin);
        return user;
    }
View Full Code Here

TOP

Related Classes of cz.muni.fi.pa165.stis.entity.User

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.