Package se.gu.fire

Source Code of se.gu.fire.GraderTest

package se.gu.fire;

import javax.persistence.EntityManager;
import javax.persistence.Persistence;
import org.junit.After;
import org.junit.AfterClass;
import static org.junit.Assert.*;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import se.gu.fire.core.FireUser;
import se.gu.fire.data.UserManager;
import se.gu.fire.util.test.TestUtil;
import se.gu.fire.core.UserRole;
import se.gu.fire.util.test.TestBean;

public class GraderTest {

    private static EntityManager em;
    private static TestBean testBean;

    @BeforeClass
    public static void setUpClass() throws Exception {
        em = Persistence.createEntityManagerFactory(TestUtil.TEST_PU_NAME).createEntityManager();
        testBean = new TestBean(em);
    }
   
    public GraderTest() {
    }

    @AfterClass
    public static void tearDownClass() {
    }

    @Before
    public void setUp() {
        testBean.clearDb();
    }

    @After
    public void tearDown() {
        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));
    }
}
TOP

Related Classes of se.gu.fire.GraderTest

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.