Skip to content

Commit 154e131

Browse files
author
talhadilber
committed
JDQ Presentation Test Method Copied and asserts added
1 parent 512ede9 commit 154e131

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+2179
-55
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ more multi value operators with java code touches.
159159

160160
#### Comparable Operators
161161

162-
This operator is used to compare numbers and dates. Available Java Types are **Date, Double, Long, LocalDate,
162+
This operator is used to compare numbers and dates. Available Java Types are **Timestamp, Date, Double, Long, LocalDate,
163163
ZonedDateTime, Instant, Integer**.
164164

165165
The following operators are available:

pom.xml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@
7171
<artifactId>spring-data-jpa</artifactId>
7272
</dependency>
7373
<dependency>
74-
<groupId>jakarta.persistence</groupId>
75-
<artifactId>jakarta.persistence-api</artifactId>
74+
<groupId>javax.persistence</groupId>
75+
<artifactId>javax.persistence-api</artifactId>
7676
</dependency>
7777
<dependency>
7878
<groupId>org.hibernate</groupId>
7979
<artifactId>hibernate-core</artifactId>
80+
<version>${hibernate.version}</version>
8081
</dependency>
8182
<dependency>
8283
<groupId>org.projectlombok</groupId>
@@ -117,7 +118,6 @@
117118
<dependency>
118119
<groupId>com.google.code.gson</groupId>
119120
<artifactId>gson</artifactId>
120-
<version>2.10.1</version>
121121
<scope>test</scope>
122122
</dependency>
123123
</dependencies>
@@ -138,7 +138,7 @@
138138
<plugin>
139139
<groupId>org.apache.maven.plugins</groupId>
140140
<artifactId>maven-source-plugin</artifactId>
141-
<version>3.2.1</version>
141+
<version>${maven-source-plugin.version}</version>
142142
<executions>
143143
<execution>
144144
<id>attach-sources</id>
@@ -151,7 +151,7 @@
151151
<plugin>
152152
<groupId>org.apache.maven.plugins</groupId>
153153
<artifactId>maven-javadoc-plugin</artifactId>
154-
<version>2.9.1</version>
154+
<version>${maven-javadoc-plugin.version}</version>
155155
<executions>
156156
<execution>
157157
<id>attach-javadocs</id>

src/test/java/com/beyt/jdq/BaseTestInstance.java

Lines changed: 157 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,20 @@
22

33
import com.beyt.jdq.testenv.entity.Customer;
44
import com.beyt.jdq.testenv.entity.User;
5-
import com.beyt.jdq.testenv.repository.CustomerRepository;
6-
import com.beyt.jdq.testenv.repository.UserRepository;
5+
import com.beyt.jdq.testenv.entity.authorization.*;
6+
import com.beyt.jdq.testenv.entity.school.Address;
7+
import com.beyt.jdq.testenv.entity.school.Course;
8+
import com.beyt.jdq.testenv.entity.school.Department;
9+
import com.beyt.jdq.testenv.entity.school.Student;
10+
import com.beyt.jdq.testenv.repository.*;
11+
import org.junit.jupiter.api.BeforeAll;
712
import org.springframework.beans.factory.annotation.Autowired;
813

914
import javax.persistence.EntityManager;
1015
import java.util.Calendar;
16+
import java.sql.Timestamp;
17+
import java.util.List;
18+
import java.util.Set;
1119

1220
public abstract class BaseTestInstance {
1321

@@ -17,6 +25,31 @@ public abstract class BaseTestInstance {
1725
@Autowired
1826
protected UserRepository userRepository;
1927

28+
@Autowired
29+
protected AddressRepository addressRepository;
30+
31+
@Autowired
32+
protected RoleRepository roleRepository;
33+
34+
@Autowired
35+
protected DepartmentRepository departmentRepository;
36+
37+
@Autowired
38+
protected CourseRepository courseRepository;
39+
40+
@Autowired
41+
protected StudentRepository studentRepository;
42+
43+
@Autowired
44+
protected AuthorizationRepository authorizationRepository;
45+
46+
@Autowired
47+
protected RoleAuthorizationRepository roleAuthorizationRepository;
48+
49+
@Autowired
50+
protected AdminUserRepository adminUserRepository;
51+
52+
2053
@Autowired
2154
protected EntityManager entityManager;
2255

@@ -39,6 +72,77 @@ public abstract class BaseTestInstance {
3972
public final Customer customer8;
4073
public static final Calendar INSTANCE = Calendar.getInstance();
4174

75+
protected Address address1 = new Address(1L, "123 Main St", "New York", "NY", "10001");
76+
protected Address address2 = new Address(2L, "456 Park Ave", "Chicago", "IL", "60605");
77+
protected Address address3 = new Address(3L, "789 Broadway", "Los Angeles", "CA", "90001");
78+
protected Address address4 = new Address(4L, "321 Market St", "San Francisco", "CA", "94105");
79+
protected Address address5 = new Address(5L, "654 Elm St", "Dallas", "TX", "75001");
80+
protected Address address6 = new Address(6L, "987 Oak St", "Houston", "TX", "77002");
81+
protected Address address7 = new Address(7L, "345 Pine St", "Philadelphia", "PA", "19019");
82+
protected Address address8 = new Address(8L, "678 Maple St", "Phoenix", "AZ", "85001");
83+
protected Address address9 = new Address(9L, "102 Beach St", "Miami", "FL", "33101");
84+
protected Address address10 = new Address(10L, "567 Hill St", "Atlanta", "GA", "30301");
85+
86+
87+
protected Department department1 = new Department(1L, "Computer Science");
88+
protected Department department2 = new Department(2L, "Mathematics");
89+
protected Department department3 = new Department(3L, "Physics");
90+
protected Department department4 = new Department(4L, "Chemistry");
91+
protected Department department5 = new Department(5L, "Biology");
92+
protected Department department6 = new Department(6L, "English Literature");
93+
protected Department department7 = new Department(7L, "History");
94+
protected Department department8 = new Department(8L, "Geography");
95+
protected Department department9 = new Department(9L, "Political Science");
96+
protected Department department10 = new Department(10L, "Economics");
97+
98+
protected Course course1 = new Course(1L, "Introduction to Computer Science", Timestamp.valueOf("2016-06-18 00:00:00"), 50, true, "Introduction to fundamental concepts of computer science.");
99+
protected Course course2 = new Course(2L, "Calculus I", Timestamp.valueOf("2017-06-18 00:00:00"), 60, true, "Introduction to fundamental concepts of calculus.");
100+
protected Course course3 = new Course(3L, "Calculus II", Timestamp.valueOf("2018-06-18 00:00:00"), 250, null, "Advanced topics in calculus including integrals and series.");
101+
protected Course course4 = new Course(4L, "Physics I", Timestamp.valueOf("2019-06-18 00:00:00"), 250, null, "Introduction to classical mechanics and Newtonian physics.");
102+
protected Course course5 = new Course(5L, "Physics II", Timestamp.valueOf("2020-06-18 00:00:00"), 250, null, "Advanced topics in physics including electromagnetism and thermodynamics.");
103+
protected Course course6 = new Course(6L, "Chemistry I", Timestamp.valueOf("2021-06-18 00:00:00"), 40, null, "Basic principles of chemistry including atomic structure and chemical bonding.");
104+
protected Course course7 = new Course(7L, "Chemistry II", Timestamp.valueOf("2022-06-18 00:00:00"), 30, null, "Continuation of chemistry studies covering topics like kinetics and equilibrium.");
105+
protected Course course8 = new Course(8L, "Biology I", Timestamp.valueOf("2015-06-18 00:00:00"), 20, true, "Introduction to cellular biology and genetics.");
106+
protected Course course9 = new Course(9L, "Biology II", Timestamp.valueOf("2013-06-18 00:00:00"), 54, true, "Advanced topics in biology including evolution and ecology.");
107+
protected Course course10 = new Course(10L, "English Literature I", Timestamp.valueOf("2025-06-18 00:00:00"), 10, false, "Exploration of classic works of English literature and literary analysis.");
108+
109+
protected Student student1 = new Student(1L, "John Doe", address1, department1, List.of(course1, course2));
110+
protected Student student2 = new Student(2L, "Jane Smith", address2, department2, List.of(course2, course4));
111+
protected Student student3 = new Student(3L, "Robert Johnson", address3, department3, List.of(course3));
112+
protected Student student4 = new Student(4L, "Emily Davis", address4, department4, List.of(course4));
113+
protected Student student5 = new Student(5L, "Michael Miller", address5, department5, List.of(course5));
114+
protected Student student6 = new Student(6L, "Sarah Wilson", address6, department6, List.of(course6));
115+
protected Student student7 = new Student(7L, "David Moore", address7, department7, List.of(course7));
116+
protected Student student8 = new Student(8L, "Jessica Taylor", address8, department8, List.of(course8));
117+
protected Student student9 = new Student(9L, "Daniel Anderson", address9, department9, List.of(course9));
118+
protected Student student10 = new Student(10L, "Jennifer Thomas", address10, department10, List.of(course10));
119+
protected Student student11 = new Student(11L, "Talha Dilber", null, null, List.of());
120+
121+
protected Authorization authorization1 = new Authorization(1L, "auth1", "/url1", "icon1");
122+
protected Authorization authorization2 = new Authorization(2L, "auth2", "/url2", "icon2");
123+
protected Authorization authorization3 = new Authorization(3L, "auth3", "/url3", "icon3");
124+
protected Authorization authorization4 = new Authorization(4L, "auth4", "/url4", "icon4");
125+
protected Authorization authorization5 = new Authorization(5L, "auth5", "/url5", "icon5");
126+
127+
protected Role role1 = new Role(1L, "role1", "description1");
128+
protected Role role2 = new Role(2L, "role2", "description2");
129+
protected Role role3 = new Role(3L, "role3", "description3");
130+
protected Role role4 = new Role(4L, "role4", "description4");
131+
protected Role role5 = new Role(5L, "role5", "description5");
132+
133+
protected RoleAuthorization roleAuthorization1 = new RoleAuthorization(1L, role1, authorization1);
134+
protected RoleAuthorization roleAuthorization2 = new RoleAuthorization(2L, role2, authorization2);
135+
protected RoleAuthorization roleAuthorization3 = new RoleAuthorization(3L, role3, authorization3);
136+
protected RoleAuthorization roleAuthorization4 = new RoleAuthorization(4L, role4, authorization4);
137+
protected RoleAuthorization roleAuthorization5 = new RoleAuthorization(5L, role5, authorization5);
138+
139+
140+
protected AdminUser adminUser1 = new AdminUser(1L, "admin1", "password1", List.of(role1));
141+
protected AdminUser adminUser2 = new AdminUser(2L, "admin2", "password2", List.of(role2));
142+
protected AdminUser adminUser3 = new AdminUser(3L, "admin3", "password3", List.of(role3));
143+
protected AdminUser adminUser4 = new AdminUser(4L, "admin4", "password4", List.of(role4));
144+
protected AdminUser adminUser5 = new AdminUser(5L, "admin5", "password5", List.of(role5));
145+
42146
public BaseTestInstance() {
43147
user1 = new User(null, "Name 1", "Surname 1", 35, INSTANCE.toInstant(), User.Status.PASSIVE, User.Type.USER);
44148
customer1 = new Customer(null, "Customer 1", 20, INSTANCE.toInstant(), user1);
@@ -65,4 +169,55 @@ public BaseTestInstance() {
65169
customer8 = new Customer(null, null, 27, INSTANCE.toInstant(), user8);
66170

67171
}
172+
173+
174+
@BeforeAll
175+
public void init() {
176+
if (userRepository.count() != 0) {
177+
return;
178+
}
179+
userRepository.save(user1);
180+
userRepository.save(user2);
181+
userRepository.save(user3);
182+
userRepository.save(user4);
183+
userRepository.save(user5);
184+
userRepository.save(user6);
185+
userRepository.save(user7);
186+
userRepository.save(user8);
187+
188+
if (customerRepository.count() != 0) {
189+
return;
190+
}
191+
customerRepository.save(customer1);
192+
customerRepository.save(customer2);
193+
customerRepository.save(customer3);
194+
customerRepository.save(customer4);
195+
customerRepository.save(customer5);
196+
customerRepository.save(customer6);
197+
customerRepository.save(customer7);
198+
customerRepository.save(customer8);
199+
200+
if (addressRepository.count() != 0) {
201+
return;
202+
}
203+
addressRepository.saveAllAndFlush(List.of(address1, address2, address3, address4, address5, address6, address7, address8, address9, address10));
204+
205+
departmentRepository.saveAllAndFlush(List.of(department1, department2, department3, department4, department5, department6, department7, department8, department9, department10));
206+
207+
courseRepository.saveAllAndFlush(List.of(course1, course2, course3, course4, course5, course6, course7, course8, course9, course10));
208+
209+
studentRepository.saveAllAndFlush(List.of(student1, student2, student3, student4, student5, student6, student7, student8, student9, student10, student11));
210+
211+
if (authorizationRepository.count() != 0) {
212+
return;
213+
}
214+
authorizationRepository.saveAllAndFlush(List.of(authorization1, authorization2, authorization3, authorization4, authorization5));
215+
216+
roleRepository.saveAllAndFlush(List.of(role1, role2, role3, role4, role5));
217+
218+
roleAuthorizationRepository.saveAllAndFlush(List.of(roleAuthorization1, roleAuthorization2, roleAuthorization3, roleAuthorization4, roleAuthorization5));
219+
220+
adminUserRepository.saveAllAndFlush(List.of(adminUser1, adminUser2, adminUser3, adminUser4, adminUser5));
221+
}
222+
68223
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.beyt.jdq.context;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
import org.springframework.stereotype.Component;
6+
import org.springframework.web.context.annotation.RequestScope;
7+
8+
import java.io.Serializable;
9+
10+
11+
@Component
12+
@RequestScope
13+
public class DBSelectionContext implements Serializable {
14+
public enum Database {
15+
READ, WRITE
16+
}
17+
18+
@Getter
19+
@Setter
20+
private Database database = Database.WRITE;
21+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package com.beyt.jdq.controller;
2+
3+
import com.beyt.jdq.dto.CriteriaList;
4+
import com.beyt.jdq.dto.DynamicQuery;
5+
import com.beyt.jdq.presetation.S9_Query_Builder;
6+
import com.beyt.jdq.testenv.entity.school.Course;
7+
import com.beyt.jdq.testenv.repository.AdminUserRepository;
8+
import com.beyt.jdq.testenv.repository.CourseRepository;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.data.domain.Page;
11+
import org.springframework.http.ResponseEntity;
12+
import org.springframework.web.bind.annotation.GetMapping;
13+
import org.springframework.web.bind.annotation.RequestMapping;
14+
import org.springframework.web.bind.annotation.RestController;
15+
16+
import java.util.List;
17+
18+
@RestController
19+
@RequestMapping("/test-api")
20+
public class PresentationTestController {
21+
@Autowired
22+
private CourseRepository courseRepository;
23+
@Autowired
24+
private AdminUserRepository adminUserRepository;
25+
26+
27+
@GetMapping("/course")
28+
public ResponseEntity<List<Course>> getCourseWithCriteria(CriteriaList criteriaList) {
29+
List<Course> customerList = courseRepository.findAll(criteriaList);
30+
return ResponseEntity.ok().body(customerList);
31+
}
32+
33+
@GetMapping("/course/as-page")
34+
public ResponseEntity<Page<Course>> getCourseWithSearchFilterAsPage(DynamicQuery dynamicQuery) {
35+
Page<Course> customerList = courseRepository.findAllAsPage(dynamicQuery);
36+
return ResponseEntity.ok().body(customerList);
37+
}
38+
39+
@GetMapping("/course/as-list")
40+
public ResponseEntity<List<S9_Query_Builder.AuthorizationSummary>> getCourseWithSearchFilterAsList(DynamicQuery dynamicQuery) {
41+
List<S9_Query_Builder.AuthorizationSummary> customerList = adminUserRepository.findAll(dynamicQuery, S9_Query_Builder.AuthorizationSummary.class);
42+
return ResponseEntity.ok().body(customerList);
43+
}
44+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.beyt.jdq.deserializer;
2+
3+
import org.springframework.stereotype.Component;
4+
5+
import java.sql.Timestamp;
6+
import java.text.SimpleDateFormat;
7+
import java.sql.Timestamp;
8+
import java.util.Date;
9+
10+
@Component
11+
public class DateTimeDeserializer extends BasicDeserializer {
12+
13+
@Override
14+
public <T> T deserialize(Object value, Class<T> clazz) throws Exception {
15+
if (clazz.isAssignableFrom(Date.class)) {
16+
if (value instanceof Date date) {
17+
return (T) date;
18+
}
19+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
20+
simpleDateFormat.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));
21+
Date parsedDate = simpleDateFormat.parse(value.toString());
22+
return (T) parsedDate;
23+
}
24+
25+
if (clazz.isAssignableFrom(Timestamp.class)) {
26+
if (value instanceof Timestamp date) {
27+
return (T) date;
28+
}
29+
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
30+
simpleDateFormat.setTimeZone(java.util.TimeZone.getTimeZone("UTC"));
31+
Date parsedDate = simpleDateFormat.parse(value.toString());
32+
return (T) new Timestamp(parsedDate.getTime());
33+
}
34+
35+
36+
37+
return super.deserialize(value, clazz);
38+
}
39+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package com.beyt.jdq.interceptor;
2+
3+
import com.beyt.jdq.context.DBSelectionContext;
4+
import lombok.extern.slf4j.Slf4j;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.method.HandlerMethod;
8+
import org.springframework.web.servlet.HandlerInterceptor;
9+
10+
import javax.servlet.http.HttpServletRequest;
11+
import javax.servlet.http.HttpServletResponse;
12+
import java.lang.reflect.Method;
13+
14+
@Slf4j
15+
public class DatabaseSelectionInterceptor implements HandlerInterceptor {
16+
17+
@Autowired
18+
private DBSelectionContext dbSelectionContext;
19+
20+
@Override
21+
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) {
22+
if (!(handler instanceof HandlerMethod)) {
23+
return true;
24+
}
25+
26+
HandlerMethod handlerMethod = (HandlerMethod) handler;
27+
Method method = handlerMethod.getMethod();
28+
GetMapping getMapping = method.getAnnotation(GetMapping.class);
29+
if (getMapping != null) {
30+
dbSelectionContext.setDatabase(DBSelectionContext.Database.READ);
31+
}
32+
33+
return true;
34+
}
35+
}

0 commit comments

Comments
 (0)