Skip to content

Commit 53b3423

Browse files
Added plenty more tests for queries
1 parent 7370106 commit 53b3423

4 files changed

Lines changed: 678 additions & 3 deletions

File tree

spring-data-eclipse-store/src/main/java/software/xdev/spring/data/eclipse/store/repository/query/criteria/AbstractCriteriaNode.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ public AbstractCriteriaNode<T> like(final String like)
152152
final String completeRegex = sqlLikeStringToRegex(like);
153153
this.predicates.add(entity -> {
154154
final String fieldValue = (String)Objects.requireNonNull(this.field).readValue(entity);
155-
return fieldValue != null && fieldValue.toUpperCase().matches(completeRegex);
155+
return fieldValue != null && fieldValue.matches(completeRegex);
156156
});
157157
return this;
158158
}
159159

160160
private static String sqlLikeStringToRegex(final String like)
161161
{
162-
String regex = like.toUpperCase();
162+
String regex = like;
163163
regex = regex.replace(".", "\\.");
164164
regex = regex.replace("_", ".");
165165
return regex.replace("%", ".*");
@@ -185,7 +185,7 @@ public AbstractCriteriaNode<T> notLike(final String notLikeString)
185185
final String completeRegex = sqlLikeStringToRegex(notLikeString);
186186
this.predicates.add(entity -> {
187187
final String fieldValue = (String)Objects.requireNonNull(this.field).readValue(entity);
188-
return fieldValue != null && !fieldValue.toUpperCase().matches(completeRegex);
188+
return fieldValue != null && !fieldValue.matches(completeRegex);
189189
});
190190
return this;
191191
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,135 @@
1+
/*
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.query.by.string;
17+
18+
import java.time.LocalDate;
19+
20+
import jakarta.persistence.GeneratedValue;
21+
import jakarta.persistence.GenerationType;
22+
import jakarta.persistence.Id;
23+
24+
25+
public class User
26+
{
27+
@Id
28+
@GeneratedValue(strategy = GenerationType.AUTO)
29+
private Long id;
30+
31+
private String firstName;
32+
private String lastName;
33+
private Integer age;
34+
private String email;
35+
private String city;
36+
private LocalDate dateOfBirth;
37+
private Boolean isActive;
38+
39+
// Constructors, Getters, and Setters
40+
41+
public User()
42+
{
43+
}
44+
45+
public User(final String firstName, final String lastName, final Integer age, final String email, final String city, final LocalDate dateOfBirth, final Boolean isActive)
46+
{
47+
this.firstName = firstName;
48+
this.lastName = lastName;
49+
this.age = age;
50+
this.email = email;
51+
this.city = city;
52+
this.dateOfBirth = dateOfBirth;
53+
this.isActive = isActive;
54+
}
55+
56+
public Long getId()
57+
{
58+
return this.id;
59+
}
60+
61+
public void setId(final Long id)
62+
{
63+
this.id = id;
64+
}
65+
66+
public String getFirstName()
67+
{
68+
return this.firstName;
69+
}
70+
71+
public void setFirstName(final String firstName)
72+
{
73+
this.firstName = firstName;
74+
}
75+
76+
public String getLastName()
77+
{
78+
return this.lastName;
79+
}
80+
81+
public void setLastName(final String lastName)
82+
{
83+
this.lastName = lastName;
84+
}
85+
86+
public Integer getAge()
87+
{
88+
return this.age;
89+
}
90+
91+
public void setAge(final Integer age)
92+
{
93+
this.age = age;
94+
}
95+
96+
public String getEmail()
97+
{
98+
return this.email;
99+
}
100+
101+
public void setEmail(final String email)
102+
{
103+
this.email = email;
104+
}
105+
106+
public String getCity()
107+
{
108+
return this.city;
109+
}
110+
111+
public void setCity(final String city)
112+
{
113+
this.city = city;
114+
}
115+
116+
public LocalDate getDateOfBirth()
117+
{
118+
return this.dateOfBirth;
119+
}
120+
121+
public void setDateOfBirth(final LocalDate dateOfBirth)
122+
{
123+
this.dateOfBirth = dateOfBirth;
124+
}
125+
126+
public Boolean getActive()
127+
{
128+
return this.isActive;
129+
}
130+
131+
public void setActive(final Boolean active)
132+
{
133+
this.isActive = active;
134+
}
135+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
/*
2+
* Copyright © 2024 XDEV Software (https://xdev.software)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package software.xdev.spring.data.eclipse.store.integration.isolated.tests.query.by.string;
17+
18+
import java.time.LocalDate;
19+
import java.util.List;
20+
21+
import org.springframework.stereotype.Repository;
22+
23+
import software.xdev.spring.data.eclipse.store.repository.interfaces.EclipseStoreRepository;
24+
25+
26+
@Repository
27+
public interface UserRepository extends EclipseStoreRepository<User, Long>
28+
{
29+
30+
// Test keyword: And
31+
List<User> findByFirstNameAndLastName(String firstName, String lastName);
32+
33+
// Test keyword: Or
34+
List<User> findByFirstNameOrLastName(String firstName, String lastName);
35+
36+
// Test keyword: Between
37+
List<User> findByAgeBetween(Integer startAge, Integer endAge);
38+
39+
// Test keyword: LessThan
40+
List<User> findByAgeLessThan(Integer age);
41+
42+
// Test keyword: LessThanEqual
43+
List<User> findByAgeLessThanEqual(Integer age);
44+
45+
// Test keyword: GreaterThan
46+
List<User> findByAgeGreaterThan(Integer age);
47+
48+
// Test keyword: GreaterThanEqual
49+
List<User> findByAgeGreaterThanEqual(Integer age);
50+
51+
// Test keyword: After
52+
List<User> findByDateOfBirthAfter(LocalDate date);
53+
54+
// Test keyword: Before
55+
List<User> findByDateOfBirthBefore(LocalDate date);
56+
57+
// Test keyword: IsNull
58+
List<User> findByEmailIsNull();
59+
60+
// Test keyword: IsNotNull
61+
List<User> findByEmailIsNotNull();
62+
63+
// Test keyword: Like
64+
List<User> findByFirstNameLike(String pattern);
65+
66+
// Test keyword: NotLike
67+
List<User> findByFirstNameNotLike(String pattern);
68+
69+
// Test keyword: StartingWith
70+
List<User> findByFirstNameStartingWith(String prefix);
71+
72+
// Test keyword: EndingWith
73+
List<User> findByFirstNameEndingWith(String suffix);
74+
75+
// Test keyword: Containing
76+
List<User> findByFirstNameContaining(String infix);
77+
78+
// Test keyword: OrderBy
79+
List<User> findByCityOrderByFirstNameAsc(String city);
80+
81+
// Test keyword: Not
82+
List<User> findByFirstNameNot(String firstName);
83+
84+
// Test keyword: In
85+
List<User> findByAgeIn(List<Integer> ages);
86+
87+
// Test keyword: NotIn
88+
List<User> findByAgeNotIn(List<Integer> ages);
89+
90+
// Test keyword: True
91+
List<User> findByIsActiveTrue();
92+
93+
// Test keyword: False
94+
List<User> findByIsActiveFalse();
95+
96+
// Additional fields to handle boolean flag for active status
97+
List<User> findByIsActive(Boolean isActive);
98+
}

0 commit comments

Comments
 (0)