Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : adds pagination #1636

Merged
merged 5 commits into from
Jan 12, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
230 changes: 150 additions & 80 deletions r2dbc/boot-r2dbc-json-column/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,18 @@

<properties>
<java.version>21</java.version>
<!-- test properties -->
<skip.unit.tests>true</skip.unit.tests>
<skip.integration.tests>false</skip.integration.tests>
<spotless.version>2.44.1</spotless.version>
<!-- test properties -->
<jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>
<jacoco.minimum.coverage>0.80</jacoco.minimum.coverage>
<project.testresult.directory>${project.build.directory}/test-results</project.testresult.directory>
<jacoco.utReportFolder>${project.build.directory}/jacoco/test</jacoco.utReportFolder>
<jacoco.utReportFile>${jacoco.utReportFolder}/test.exec</jacoco.utReportFile>
<jacoco.itReportFolder>${project.build.directory}/jacoco/integrationTest</jacoco.itReportFolder>
<jacoco.itReportFile>${jacoco.itReportFolder}/integrationTest.exec</jacoco.itReportFile>
<junit.utReportFolder>${project.testresult.directory}/test</junit.utReportFolder>
<junit.itReportFolder>${project.testresult.directory}/integrationTest</junit.itReportFolder>

</properties>

<dependencies>
Expand Down Expand Up @@ -118,51 +126,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<skipTests>${skip.unit.tests}</skipTests>
</configuration>
<executions>
<execution>
<phase>test</phase>
<id>unit-test</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<excludes>
<exclude>**/*IT.java</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<configuration>
<skipITs>${skip.integration.tests}</skipITs>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<includes>
<include>**/*IT.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down Expand Up @@ -211,41 +174,148 @@
</execution>
</executions>
</plugin>
<plugin>
<groupId>io.github.git-commit-id</groupId>
<artifactId>git-commit-id-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>revision</goal>
</goals>
</execution>
</executions>
<configuration>
<failOnNoGitDirectory>false</failOnNoGitDirectory>
<failOnUnableToExtractRepoInfo>false</failOnUnableToExtractRepoInfo>
<generateGitPropertiesFile>true</generateGitPropertiesFile>
<includeOnlyProperties>
<includeOnlyProperty>^git.branch$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.id.abbrev$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.user.name$</includeOnlyProperty>
<includeOnlyProperty>^git.commit.message.full$</includeOnlyProperty>
</includeOnlyProperties>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin.version}</version>
<configuration>
<runOrder>alphabetical</runOrder>
<reportsDirectory>${junit.utReportFolder}</reportsDirectory>
<excludes>
<exclude>**/*IT*</exclude>
<exclude>**/*IntTest*</exclude>
<exclude>**/*IntegrationTest*</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>${maven-failsafe-plugin.version}</version>
<configuration>
<classesDirectory>${project.build.outputDirectory}</classesDirectory>
<runOrder>alphabetical</runOrder>
<reportsDirectory>${junit.itReportFolder}</reportsDirectory>
<includes>
<include>**/*IT*</include>
<include>**/*IntTest*</include>
<include>**/*IntegrationTest*</include>
</includes>
</configuration>
<executions>
<execution>
<id>integration-test</id>
<goals>
<goal>integration-test</goal>
</goals>
</execution>
<execution>
<id>verify</id>
<goals>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>${jacoco-maven-plugin.version}</version>
<configuration>
<dataFile>${project.build.directory}/jacoco/test/jacoco.exec</dataFile>
<rules>
<rule>
<element>BUNDLE</element>
<limits>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>${jacoco.minimum.coverage}</minimum>
</limit>
</limits>
</rule>
</rules>
<excludes>
<exclude>**/*Application.*</exclude>
<exclude>**/config/**</exclude>
<exclude>**/models/*</exclude>
<exclude>**/dtos/*</exclude>
<exclude>**/exceptions/*</exclude>
<exclude>**/*Constants*</exclude>
</excludes>
</configuration>
<executions>
<execution>
<id>pre-unit-tests</id>
<goals>
<goal>prepare-agent</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${jacoco.utReportFile}</destFile>
</configuration>
</execution>
<!-- Ensures that the code coverage report for unit tests is created after unit tests have been run -->
<execution>
<id>post-unit-test</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
<configuration>
<dataFile>${jacoco.utReportFile}</dataFile>
<outputDirectory>${jacoco.utReportFolder}</outputDirectory>
</configuration>
</execution>
<execution>
<id>pre-integration-tests</id>
<goals>
<goal>prepare-agent-integration</goal>
</goals>
<configuration>
<!-- Sets the path to the file which contains the execution data. -->
<destFile>${jacoco.itReportFile}</destFile>
</configuration>
</execution>
<!-- Ensures that the code coverage report for integration tests is created after integration tests have been run -->
<execution>
<id>post-integration-tests</id>
<phase>post-integration-test</phase>
<goals>
<goal>report-integration</goal>
</goals>
<configuration>
<dataFile>${jacoco.itReportFile}</dataFile>
<outputDirectory>${jacoco.itReportFolder}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
Comment on lines +242 to +315
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codebase verification

Maintain test coverage for business-critical components

The current broad exclusion patterns should be refined as the excluded components contain important business logic:

  • DTOs contain core business objects and validations (e.g., CustomerDTO, Orders)
  • Configuration classes implement critical security rules and bean configurations
  • Exception handlers contain custom business error handling logic

Recommended approach:

  • Only exclude application bootstrap classes
  • Keep coverage for DTOs, models, and exceptions containing business logic
  • Maintain tests for configuration classes implementing business rules
🔗 Analysis chain

Review coverage exclusion patterns.

The current exclusion patterns might be too broad:

<excludes>
    <exclude>**/*Application.*</exclude>
    <exclude>**/config/**</exclude>
    <exclude>**/models/*</exclude>
    <exclude>**/dtos/*</exclude>
    <exclude>**/exceptions/*</exclude>
    <exclude>**/*Constants*</exclude>
</excludes>

While it's common to exclude application bootstrap classes, consider:

  • Models and DTOs might benefit from coverage to ensure proper initialization and validation
  • Exception classes might contain business logic that should be tested
  • Configuration classes might contain crucial business rules

Would you like me to help create a more granular exclusion pattern that better balances coverage with maintainability?

🏁 Scripts executed

The following scripts were executed for the analysis:

Error: No shell scripts found


Script:

#!/bin/bash
# Check for business logic in models, DTOs, and exceptions
echo "=== Checking models for methods ==="
ast-grep --pattern 'class $_ {
  $$$
  $METHODNAME($$$) {
    $$$
  }
  $$$
}'  | rg "models/"

echo -e "\n=== Checking DTOs for methods ==="
ast-grep --pattern 'class $_ {
  $$$
  $METHODNAME($$$) {
    $$$
  }
  $$$
}'  | rg "dtos/"

echo -e "\n=== Checking exceptions for custom logic ==="
ast-grep --pattern 'class $_ extends $_ {
  $$$
  $METHODNAME($$$) {
    $$$
  }
  $$$
}'  | rg "exceptions/"

echo -e "\n=== Checking config classes for business rules ==="
ast-grep --pattern 'class $_ {
  $$$
  @Bean
  $METHODNAME($$$) {
    $$$
  }
  $$$
}'  | rg "config/"

echo -e "\n=== Looking for existing tests ==="
fd -e java -e kt --full-path "(Test|IT|Spec)\\.java$|Test\\.kt$" | rg "(models|dtos|exceptions|config)"

Length of output: 971


Script:

#!/bin/bash
# First check if these directories exist and contain any code
echo "=== Checking directory structure ==="
fd -t d "(models|dtos|config|exceptions)"

echo -e "\n=== Looking for Java/Kotlin files in these directories ==="
fd -e java -e kt | rg "(models|dtos|config|exceptions)"

echo -e "\n=== Examining content of any found files ==="
fd -e java -e kt | rg "(models|dtos|config|exceptions)" | xargs -I {} sh -c 'echo "=== {} ==="; cat "{}" 2>/dev/null || true'

Length of output: 73543

</plugins>
</build>

<profiles>
<profile>
<id>it</id>
<properties>
<skip.unit.tests>true</skip.unit.tests>
<skip.integration.tests>false</skip.integration.tests>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

<repositories>
<repository>
<id>spring-milestones</id>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ static class Deserializer extends JsonDeserializer<Json> {
@Override
public Json deserialize(JsonParser p, DeserializationContext ctxt) throws IOException {
var value = ctxt.readTree(p);
log.info("read json value :{}", value);
log.debug("read json value :{}", value);
return Json.of(value.toString());
}
}
Expand All @@ -31,11 +31,12 @@ static class Serializer extends JsonSerializer<Json> {
@Override
public void serialize(Json value, JsonGenerator gen, SerializerProvider serializers) throws IOException {
var text = value.asString();
log.info("The raw json value from PostgresSQL JSON type:{}", text);
log.debug("The raw json value from PostgresSQL JSON type:{}", text);
JsonFactory factory = new JsonFactory();
JsonParser parser = factory.createParser(text);
var node = gen.getCodec().readTree(parser);
serializers.defaultSerializeValue(node, gen);
try (JsonParser parser = factory.createParser(text)) {
var node = gen.getCodec().readTree(parser);
serializers.defaultSerializeValue(node, gen);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.example.learning.config;

import static org.springframework.http.MediaType.APPLICATION_JSON;
import static org.springframework.web.reactive.function.server.RequestPredicates.accept;
import static org.springframework.web.reactive.function.server.RequestPredicates.contentType;
import static org.springframework.web.reactive.function.server.RequestPredicates.path;
import static org.springframework.web.reactive.function.server.RouterFunctions.route;

Expand All @@ -10,19 +13,30 @@
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;

@Configuration
@Configuration(proxyBeanMethods = false)
public class WebRouterConfig {

@Bean
public RouterFunction<ServerResponse> routes(PostHandler postController, CommentHandler commentHandler) {
return route().path("/posts", () -> route().nest(path(""), () -> route().GET("", postController::all)
.POST("", postController::create)
.build())
.nest(path("{id}"), () -> route().GET("", postController::get)
.PUT("", postController::update)
RouterFunction<ServerResponse> routes(PostHandler postController, CommentHandler commentHandler) {
return route().path("/posts", () -> route().nest(
path(""), () -> route().GET("", accept(APPLICATION_JSON), postController::all)
.POST(
"",
contentType(APPLICATION_JSON).and(accept(APPLICATION_JSON)),
postController::create)
.build())
.nest(path("{id}"), () -> route().GET("", accept(APPLICATION_JSON), postController::get)
.PUT(
"",
contentType(APPLICATION_JSON).and(accept(APPLICATION_JSON)),
postController::update)
.DELETE("", postController::delete)
.nest(path("comments"), () -> route().GET("", commentHandler::getByPostId)
.POST("", commentHandler::create)
.nest(path("comments"), () -> route().GET(
"", accept(APPLICATION_JSON), commentHandler::getByPostId)
.POST(
"",
contentType(APPLICATION_JSON).and(accept(APPLICATION_JSON)),
commentHandler::create)
.build())
.build())
.build())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@
import java.util.List;
import java.util.UUID;
import lombok.*;
import org.springframework.data.annotation.*;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.LastModifiedDate;
import org.springframework.data.annotation.Transient;
import org.springframework.data.annotation.Version;
import org.springframework.data.relational.core.mapping.Column;
import org.springframework.data.relational.core.mapping.Table;

Expand Down Expand Up @@ -47,6 +51,7 @@ public class Post {
private Long version;

@Transient
@Builder.Default
private List<Comment> comments = new ArrayList<>(); // This field is transient and will be populated manually

public enum Status {
Expand Down
Loading
Loading