I've got the following test I'm trying to run. In this case just a blank test to try it out but for some reason it's not working.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = TestConfig.class)
@Transactional
public class UserHibernateDaoTest {
private static final long USERID = 1;
private static final long NONEXISTENTUSERID = -1;
private static final String FIRSTNAME = "TestFirstName";
private static final String LASTNAME = "TestLastName";
private static final String EMAIL = "[email protected]";
private static final String PASSWORD = "TestPassword";
private static final String PHONENUMBER = "0000000";
private static final String ROLE = "USER";
@PersistenceContext
private EntityManager em;
private UserHibernateDao userHibernateDao;
private JdbcTemplate jdbcTemplate;
@Before
@Transactional
public void setUp() {
this.userHibernateDao = new UserHibernateDao();
User u;
u = new User();
u.setUserid(123);
u.setFirstName(FIRSTNAME);
u.setLastName(LASTNAME);
u.setEmail(EMAIL);
u.setPassword(PASSWORD);
u.setPhoneNumber(PHONENUMBER);
u.setRole(ROLE);
em.persist(u);
}
@Rollback
@Test
public void testCreate() {
// Trying to run this empty test
}
}
I get the following when I run it:
INFO: Began transaction (1) for test context [DefaultTestContext@16fb356 testClass = UserHibernateDaoTest, testInstance = ar.edu.itba.paw.persistence.UserHibernateDaoTest@6bc248ed, testMethod = testCreate@UserHibernateDaoTest, testException = [null], mergedContextConfiguration = [MergedContextConfiguration@224b4d61 testClass = UserHibernateDaoTest, locations = '{}', classes = '{class ar.edu.itba.paw.persistence.TestConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]]; transaction manager [org.springframework.orm.jpa.JpaTransactionManager@23a9ba52]; rollback [true]
Jan 15, 2020 1:17:10 PM org.springframework.test.context.transaction.TransactionContext endTransaction
INFO: Rolled back transaction for test context [DefaultTestContext@16fb356 testClass = UserHibernateDaoTest, testInstance = ar.edu.itba.paw.persistence.UserHibernateDaoTest@6bc248ed, testMethod = testCreate@UserHibernateDaoTest, testException = java.lang.IllegalArgumentException: Unknown entity: ar.edu.itba.paw.models.User, mergedContextConfiguration = [MergedContextConfiguration@224b4d61 testClass = UserHibernateDaoTest, locations = '{}', classes = '{class ar.edu.itba.paw.persistence.TestConfig}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{}', contextLoader = 'org.springframework.test.context.support.DelegatingSmartContextLoader', parent = [null]]].
If change Rollback() to Rollback(false) I get:
RollbackException: Transaction marked as rollbackOnly
Any ideas how to fix this?
In case you find it neccesary I published my TestConfig in this question.