Skip to content

Commit

Permalink
make sure to disable validation while tests are running
Browse files Browse the repository at this point in the history
  • Loading branch information
christophstrobl committed Jan 7, 2025
1 parent 7d35720 commit b80794f
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 24 deletions.
6 changes: 6 additions & 0 deletions spring-data-jpa/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@
<artifactId>junit-platform-launcher</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit-pioneer</groupId>
<artifactId>junit-pioneer</artifactId>
<version>2.3.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.hsqldb</groupId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import jakarta.persistence.EntityManager;
import jakarta.persistence.Query;

import org.springframework.core.SpringProperties;
import org.springframework.data.jpa.repository.QueryRewriter;
import org.springframework.data.repository.query.RepositoryQuery;
import org.springframework.data.repository.query.ValueExpressionDelegate;
Expand Down Expand Up @@ -84,6 +85,10 @@ private void validateQuery(String query, String errorMessage, Object... argument
return;
}

if(SpringProperties.getFlag("spring.jpa.query.validation.disbaled")) {
return;
}

EntityManager validatingEm = null;

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,15 @@

import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.test.context.ContextConfiguration;

/**
* @author Oliver Gierke
* @author Christoph Strobl
*/
@ContextConfiguration("classpath:eclipselink.xml")
@SetSystemProperty(key = "spring.jpa.query.validation.disbaled", value = "true")
class EclipseLinkEntityGraphRepositoryMethodsIntegrationTests
extends EntityGraphRepositoryMethodsIntegrationTests {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/
package org.springframework.data.jpa.repository;

import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.test.context.ContextConfiguration;

@ContextConfiguration("classpath:eclipselink.xml")
@SetSystemProperty(key = "spring.jpa.query.validation.disbaled", value = "true")
class EclipseLinkParentRepositoryIntegrationTests extends ParentRepositoryIntegrationTests {

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
*/
package org.springframework.data.jpa.repository;

import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.context.annotation.ImportResource;
import org.springframework.test.context.ContextConfiguration;

Expand All @@ -24,6 +25,7 @@
* @author Mark Paluch
*/
@ContextConfiguration
@SetSystemProperty(key = "spring.jpa.query.validation.disbaled", value = "true")
class EclipseLinkRepositoryWithCompositeKeyIntegrationTests extends RepositoryWithIdClassKeyTests {

@ImportResource({ "classpath:infrastructure.xml", "classpath:eclipselink.xml" })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package org.springframework.data.jpa.repository;

import org.junit.jupiter.api.Disabled;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.test.context.ContextConfiguration;

/**
Expand All @@ -26,6 +27,7 @@
* @author Greg Turnquist
*/
@ContextConfiguration("classpath:eclipselink-h2.xml")
@SetSystemProperty(key = "spring.jpa.query.validation.disbaled", value = "true")
class EclipseLinkUserRepositoryFinderTests extends UserRepositoryFinderTests {

@Disabled
Expand All @@ -40,4 +42,9 @@ void executesInKeywordForPageCorrectly() {}
@Override
void rawMapProjectionWithEntityAndAggregatedValue() {}

@Disabled
@Override
void testQueryWithCTE() {
super.testQueryWithCTE();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -435,11 +435,10 @@ void dtoMultiselectProjectionShouldApplyConstructorExpressionRewriting() {
}

@Test // GH-3726
void xxx() {

Page<UserExcerptDto> dtos = userRepository.findWithCTE(PageRequest.of(0, 1));
System.out.println("dtos: " + dtos);
void testQueryWithCTE() {

Page<UserExcerptDto> result = userRepository.findWithCTE(PageRequest.of(0, 1));
assertThat(result.getTotalElements()).isEqualTo(3);
}

@Test // GH-3076
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@
*/
package org.springframework.data.jpa.repository.query;

import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.test.context.ContextConfiguration;

/**
* @author Christoph Strobl
*/
@ContextConfiguration("classpath:eclipselink.xml")
@SetSystemProperty(key = "spring.jpa.query.validation.disbaled", value = "true")
class EclipseLinkJpa21UtilsTests extends Jpa21UtilsTests {}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junitpioneer.jupiter.SetSystemProperty;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
Expand Down Expand Up @@ -69,6 +70,7 @@
@ExtendWith(SpringExtension.class)
@ContextConfiguration
@Transactional
@SetSystemProperty(key = "spring.jpa.query.validation.disbaled", value = "true")
class EclipseLinkMetaAnnotatedQueryMethodIntegrationTests {

@Autowired RoleRepositoryWithMeta repository;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
Expand All @@ -16,32 +16,33 @@
package org.springframework.data.jpa.repository.sample;

/**
* Hibernate is still a bit picky on records so let's use a class, just in case.
*
* @author Christoph Strobl
* @since 2025/01
*/
public class UserExcerptDto {

String firstname;
String lastname;
private String firstname;
private String lastname;

public UserExcerptDto(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;
}
public UserExcerptDto(String firstname, String lastname) {
this.firstname = firstname;
this.lastname = lastname;
}

public String getFirstname() {
return firstname;
}
public String getFirstname() {
return firstname;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}
public void setFirstname(String firstname) {
this.firstname = firstname;
}

public String getLastname() {
return lastname;
}
public String getLastname() {
return lastname;
}

public void setLastname(String lastname) {
this.lastname = lastname;
}
public void setLastname(String lastname) {
this.lastname = lastname;
}
}

0 comments on commit b80794f

Please sign in to comment.