Java tutorial
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com.tamnd.app.jpa; import com.tamnd.app.config.WebMvcConfig; import com.tamnd.app.core.entities.Account; import com.tamnd.app.core.entities.AccountRole; import com.tamnd.app.core.repositories.AccountRepo; import java.util.HashSet; import java.util.Set; import javax.transaction.Transactional; import junit.framework.Assert; import org.junit.After; import org.junit.AfterClass; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.test.context.web.WebAppConfiguration; /** * * @author tamnd */ @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration(classes = { WebMvcConfig.class }) @WebAppConfiguration public class AccountJPATest { @Autowired private AccountRepo repo; private Account account; public AccountJPATest() { } @BeforeClass public static void setUpClass() { } @AfterClass public static void tearDownClass() { } @Before public void setUp() { account = new Account(); account.setUserName("tamnd2"); account.setPassword("123456"); account.setEnable(Boolean.TRUE); Set<AccountRole> roles = new HashSet(0); roles.add(new AccountRole(account, "USER")); account.setUserRole(roles); repo.createAccount(account); } @After public void tearDown() { } @Test @Transactional public void testFind() { Assert.assertNotNull(repo.findAccount(account.getUserId())); Assert.assertTrue(repo.findAccount(account.getUserId()).getUserRole().size() > 0); } }