Package io.conducive.server.db.impl

Source Code of io.conducive.server.db.impl.UserDaoTest

package io.conducive.server.db.impl;

import io.conducive.shared.model.User;
import org.junit.Before;
import org.junit.Test;
import org.mapdb.DBMaker;

import java.io.File;

import static org.junit.Assert.*;

/**
* @author Reuben Firmin
*/
public class UserDaoTest {

    UserDAOImpl dao;

    @Before
    public void makeDb() throws Exception {
        File file = File.createTempFile("temp", "db");
        dao = new UserDAOImpl(file, DBMaker.newFileDB(file).make());
    }

    @Test
    public void createUser() throws Exception {

        for (String username : new String[]{"john", "peter", "fred", "margaret", "paul"}) {
            final String password = username.substring(0, 2) + username.substring(0, 2);
            final String salt = "this is a salt";

            User user1 = new User();
            user1.setUsername(username);
            user1.setHash(password);
            user1.setSalt(salt);
            dao.createUser(user1);
            final User user2 = dao.getUser(username, password, salt);
            assertNull(dao.getUser(username, "foobah", salt));

            assertEquals(user2.getUsername(), username);
            assertNotSame(user2.getHash(), password);
        }
    }
}
TOP

Related Classes of io.conducive.server.db.impl.UserDaoTest

TOP
Copyright © 2018 www.massapi.com. 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.