All Questions
71 questions
0
votes
1
answer
654
views
JUnit doesn't scan Jakarta entities
I have a java(8) application running with Tomcat 10, Spring 5.3.22, hibernate 5.6.10.Final and jakarta.persistence 3.0.0
I'm using jakarta entities due to my tomcat 10.
entity for example:
import ...
0
votes
0
answers
118
views
Unit testing a DAO class extending a generic DAO class
My generic DAO class looks like:
public abstract class DAO<A,B> {
public Class<B> entity;
protected final Provider<EntityManager> entityManagerFactory;
@Inject
...
0
votes
1
answer
1k
views
Why JUnit Test Failed when creating mock for javax.persistence.criteria.Root
I have created a mock junit test case for below method
Method:
@Override
public List retrieveListByUserId(Users users) {
Session session = this.sessionFactory.getCurrentSession();
CriteriaBuilder ...
1
vote
1
answer
583
views
How to test this code in junit 4 and java 8?
I'm trying to testing this code in junit 4 and java 8 (I can't improve the version).
The thing is, I can't use in this version @MockBean or @Autowired for test coding, so, ¿what's the better option if ...
1
vote
0
answers
2k
views
Error creating bean with name 'resourceHandlerMapping'[org/springframework/web/servlet/config/annotation/DelegatingWebMvcConfiguration.class]
I'm trying to run JUnit test but I got this error. I tried alot but didn't find the solution.I got this exceptions. I also tried to componentScan at test class :-@ComponentScan(basePackages= {"...
1
vote
0
answers
250
views
Could not create JDBC connection for a test method, when i add entity
Good morning, i have some problems with my Junit test.
i have this error when i run my Junit test:
java.lang.RuntimeException: Could not create dataset for test
'testRecupereEvenementsATraiter'....
3
votes
1
answer
7k
views
Hibernate configuration for Mysql 8.0
I'm new in Java! When I run the Junit test the console show me exception and I don't know how to resolve this. What is wrong with my Hibernate configuration? This code perfect works with H2 database, ...
0
votes
1
answer
1k
views
how To configure test in spring mvc
How to rigth configure Tests in spring mvc?
Java based configuration.
This is my UserTest class
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(classes = {
...
3
votes
1
answer
1k
views
Junit 4.x + Hibernate 5.x with H2 database
I am not using any framework just using maven war module and want to test the DAO layer using Juit 4 + Powermockito (first time).
My idea is when I call CustomerDao to test createCustomer. First ...
0
votes
1
answer
87
views
Spring MVC testing with JUnit
I'm trying to do some test for my repository, but I'm getting a NullPointerException.
Interface:
public interface PersonneRepository {
void setSessionFactory(SessionFactory sessionFactory);
...
1
vote
1
answer
9k
views
This exception may occur if matchers are combined with raw values
My Mock call is like below :
BDDMockito.given(restTemplate.exchange(url,
HttpMethod.POST,
BDDMockito.any(),
Response.class)
).willReturn(responseEntity);
but i am getting below errors ...
1
vote
0
answers
103
views
Spring MVC With Junit Test does not work when testing Dao: NULL pointer
This is my applicationContext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
...
0
votes
1
answer
238
views
Junit test for Service class fall
For my test I am using h2 embedded DB, hibernate, Junit and spring-boot. My DAO Tests works fine but my service tests falls.
@RunWith(SpringRunner.class)
@DataJpaTest
public class ...
1
vote
1
answer
136
views
What is the right combination of expected exceptions in my test case?
While doing some data sources testing I wrote this small EJB.
@Stateless
@Remote(IEmpService.class)
@LocalBean
public class EmpService implements IEmpService {
@PersistenceContext
private ...
2
votes
1
answer
2k
views
@Rollback is not working in Spring+Hibernate+Junit testing
while testing a DAO function in spring+hibernate application, data rollback is not happening. I am trying to do the rollback a junit test case by @Rollback annotation
transactionManager config:
<...
-1
votes
1
answer
2k
views
junit test "java.lang.IllegalStateException : Failed to load ApplicationContext"
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:99)
at ...
-1
votes
1
answer
9k
views
java.lang.AssertionError throwing null
We have created test for the functionality via springframework.test.context.junit4.
Below is one of the test case :
Test Class
@Test
public void testAuthorizedPut() throws Exception {
...
1
vote
2
answers
10k
views
1 of 2 branches missed in Eclemma
I have an application (Spring 4 MVC+Hibernate+jpa4+MySQL+Maven integration example using annotations) , integrating Spring with Hibernate using annotation based configuration.
and this unit test
@...
0
votes
1
answer
53
views
Hibernate ConstraintValidation while running Junit
I am working on an enhancement to create a new Table A and reference the id of that as a new column in an existing Table B
I have omitted the entire entity class for brevity.
import javax.validation....
2
votes
0
answers
924
views
Why doesn't Junit test throw javax.persistence.PersistenceException?
I run my JUnit4 test to test my JPA repository. But when I try to run this test, which have to throw javax.persistence.PersistenceException my test fails - it doesn't get needed exception. I've tried ...
-2
votes
2
answers
622
views
Junit test that persist in mysql
Is it possible to write junit test that persist in mysql using hibernate / jpa?
If so any example available?
I'm using spring/hibernate for my application
0
votes
0
answers
560
views
How to rename HSQLDB catalog in JUNIT
When using embedded HSQLDB to unit test, it seems the schema and/or the catalog defined in the hibernate entity mapping file can't be handled correctly. The hibernate mapping looks like
<class ...
-1
votes
1
answer
447
views
hibernate rollback not working in service layer
i have issue in rollback insert/update data in postgresql database, in service layer, where as in DAO layer it is working fine.
My DAO junit test Code
@ContextConfiguration("classpath:datasource-...
0
votes
1
answer
806
views
testing Hibernate with Spring's EmbeddedDatabaseBuilder issues with SpringSessionContext
I am unit-testing with Spring Framework's EmbeddedDatabaseBuilder as a datasource and passing this into the Hibernate config for my SessionFactory, using Spring 4 and Hibernate 4. I am not using the ...
0
votes
0
answers
315
views
Test fails. Throwing exceptions, Injection of autowired dependencies failed. NoSuchBeanDefinitionException
My test methods throwing exceptions.
This is my beans.xml file.
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="...
0
votes
0
answers
287
views
Oracle stored procedure returns incorrect value during Hibernate test Transaction
I have a test class that extends AbstractTransactionalJUnit4SpringContextTests and uses Transactions for Integration Tests. One of the tested methods calls a Stored Procedure from an Oracle Database ...
0
votes
1
answer
103
views
Integration Test issue in Spring/Hibernate (JUnit4)
I've recently started developing a simple Spring/Hibernate service but i'm still quite the noob at it, I'm having a persistent issue with this particular test. Everything else seems to be working fine,...
0
votes
2
answers
1k
views
How to test org.hibernate.Session?
Hi I have tested this code with junit 4:
public class UserDaoTest {
/**
* Runs before all test methods
*/
@BeforeClass
public static void createDB() {
sessionFactory = ...
2
votes
2
answers
151
views
Java generics ? extends Clazz
I'm using spring, hibernate and junit to setup a test class for some of my models.
All of my models extend BaseModel
I have the following function in my testing class:
void printValidation(Set<...
1
vote
0
answers
243
views
Unit test class annotated by @Transactional and implications to detach/evict in hibernate
I'm struggling with a problem I and can not find out proper solution or even a cause neither in hibernate docs, sources nor S/O.
I have spring/hibernate application with DAO-Service-RPC layers, where ...
0
votes
1
answer
598
views
Hibernate 4 and Spring Data JPA not populates collection
I am using Hibernate 4 and Spring Data JPA, I have a ManyToOne relationship with FetchType.EAGER, Contact has many Addresses, my problem is when I run the test I cannot get the populated collection in ...
0
votes
4
answers
2k
views
Entities not persisting in integration tests (Hibernate + Spring Roo ActiveRecord )
After much hassle I'm here for help. I am not able to persist data to development database (and also Embedded database) from a test case. When I run the test case without asserting it passes without ...
6
votes
3
answers
15k
views
Reset JPA generated value between tests
I'm running spring + hibernate + JUnit with springJunit4runner and transactional set to default rollback I'm using in-memory derbydb as Database. Hibernate is used as a JPA Provider and I am ...
0
votes
2
answers
2k
views
Sequence Number in testing Spring application with JUnit (Hibernating, Spring MVC)
I am testing DAO in Spring Application.
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = "classpath:/applicationContext.xml")
@TransactionConfiguration(transactionManager = "...
0
votes
1
answer
1k
views
Spring + Hibernatate 4 + Junit 4 Impossible to get an autoWired session open
I'm having really trouble with my configuration i think. Here's the problem. Ican open the the session like that :
@Test
public void testSessionFactory()
{
try {
...
1
vote
0
answers
429
views
spring hibernate transaction junit new thread
I am using spring managed hibernate transactions
<tx:annotation-driven transaction-manager="transactionManager" />
<bean id="transactionManager"
class="org.springframework.orm....
9
votes
2
answers
17k
views
Hibernate :java.lang.NoSuchMethodError:javax/validation/spi/ConfigurationState.getParameterNameProvider()Ljavax/validation/ParameterNameProvider
We are executing Junit suite for Spring-Hibernate based application( using spring text conext Unit testing framework).and using ANT for building and below Hibernate Jars are there in build path .
...
5
votes
5
answers
8k
views
Exception: expected<org.hibernate.exception.ConstraintViolationException> but was<java.lang.NoClassDefFoundError>
Im getting this error:
java.lang.Exception: Unexpected exception, expected<org.hibernate.exception.ConstraintViolationException> but was<java.lang.NoClassDefFoundError>
at org.junit....
1
vote
1
answer
657
views
How to write unit tests for hibernate domain objects
I have domain objects with one to many, many to many, many to one relations in hibernate. I wrote the unit tests for the validation rules imposed on the domain objects.
To improve the test coverage ...
0
votes
1
answer
2k
views
validate uniqueness with JUnit 4
How can I validate with Junit that a field is unique?
I have this constraint in my DB:
CREATE TABLE IF NOT EXISTS `user` (
`_id` varchar(17) COLLATE utf8_unicode_ci NOT NULL,
`login` varchar(128)...
1
vote
3
answers
4k
views
Spring Autowired DAO with hibernate.cfg.xml
I have a Spring Maven DAO Project which is packaged into a jar. It was originally a Spring DAO Ivy project, but I converted it to maven. This was a legacy project which used Spring 3.2.0 and ...
0
votes
0
answers
116
views
Hibernate JUnit method add always return 0 instead last added id
I wanna to test that I can insert correct data to db. For that I use mock for my service layer. I know that method for which I write test work correct. For all methods which select data I get rignt ...
5
votes
1
answer
5k
views
Hibernate - java.lang.NoClassDefFoundError
Implementing a web service using Hiberate for persistence layer. Works great, with no errors. However, when I write a unit test to access the Dao an encounter this error when getting an instance of ...
1
vote
2
answers
3k
views
org.hibernate.exception.GenericJDBCException: could not execute query (HSQLDB, Hibernate, Spring, Maven)
I'm using Hibernate 3.5.6-Final, Spring 3.0.5 and HSQLDB 2.2.9.
Our company using Microsoft SQL 2008 on real database. I want to separate from the real database and create a virtual HSQLDB database by ...
1
vote
2
answers
2k
views
JUnit: What to Assert on Hibernate Save
I am new to JUnit and trying to implement it in my legacy codebase.
What should I assert when I test hibernateEntity.save()?
0
votes
1
answer
3k
views
junit and hibernate - proper setup and teardown and couple of test in between
I'm trying to properly set up junit test for a persistance class and even though I'm getting 'green bar', I'm worried about couple of things.
When i run the test file in debugger, I can see for the ...
4
votes
6
answers
8k
views
transactions not working with Spring 3.1 – H2 – junit 4– hibernate 3.2
I have the following test..
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/schedule-agents-config-context.xml"})
@TransactionConfiguration(transactionManager = "...
1
vote
0
answers
799
views
Junit test cases for hibernate
I have developed a web project(struts2+hibernate) for which i need to do code coverage.I dont know how to write junit test cases for this Hibernate part.Can anyone suggest me idea.i want my test case ...
3
votes
1
answer
2k
views
How to test DAOs using hibernate in JUnit4
This seems to be a similar question (Test DAO in java using Junit4 and Hibernate), but he's getting the session created successfully. I'm unable to create the session.
Please note that I'm not using ...
0
votes
1
answer
189
views
Spring 3.2 JUnit4 Test Case passes when rolling back, but fails when not rolling back?
I have a Spring 3.2 application, using Hibernate, and some JUnit 4 test cases. I am using MySQL 5 as the database.
When writing test cases for a DAO class that rolls back, the test case passes. ...