-
Notifications
You must be signed in to change notification settings - Fork 9
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
Polish #1598
Merged
Merged
Polish #1598
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2137e67
polish
rajadilipkolli c996d81
feat : adds new testcases
rajadilipkolli 90c8676
fix input type
rajadilipkolli 8beedfa
fix wildcard import
rajadilipkolli d808beb
polish db operations
rajadilipkolli 41615f6
Merge branch 'main' into polish
rajadilipkolli 67f8292
fix : spotless
rajadilipkolli 5705ca8
concise code, consider leveraging streams directly
rajadilipkolli File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 17 additions & 1 deletion
18
...read-replica-postgresql/src/main/java/com/example/demo/readreplica/domain/ArticleDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
package com.example.demo.readreplica.domain; | ||
|
||
import static com.example.demo.readreplica.domain.CommentDTO.convertToComment; | ||
|
||
import com.example.demo.readreplica.entities.Article; | ||
import com.example.demo.readreplica.entities.Comment; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
public record ArticleDTO( | ||
String title, | ||
LocalDateTime authored, | ||
LocalDateTime published, | ||
List<CommentDTO> commentDTOs) {} | ||
List<CommentDTO> commentDTOs) { | ||
|
||
public Article convertToArticle() { | ||
Article article = | ||
new Article().setAuthored(authored).setTitle(title).setPublished(published); | ||
commentDTOs.forEach( | ||
commentDTO -> { | ||
Comment comment = convertToComment(commentDTO); | ||
article.addComment(comment); | ||
}); | ||
return article; | ||
} | ||
} |
9 changes: 8 additions & 1 deletion
9
...read-replica-postgresql/src/main/java/com/example/demo/readreplica/domain/CommentDTO.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,10 @@ | ||
package com.example.demo.readreplica.domain; | ||
|
||
public record CommentDTO(String comment) {} | ||
import com.example.demo.readreplica.entities.Comment; | ||
|
||
public record CommentDTO(String comment) { | ||
|
||
static Comment convertToComment(CommentDTO commentDTO) { | ||
return new Comment().setComment(commentDTO.comment()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
119 changes: 119 additions & 0 deletions
119
...resql/src/test/java/com/example/demo/readreplica/controller/ArticleControllerIntTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
package com.example.demo.readreplica.controller; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.example.demo.readreplica.domain.ArticleDTO; | ||
import com.example.demo.readreplica.domain.CommentDTO; | ||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.time.LocalDate; | ||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
import java.util.concurrent.atomic.AtomicReference; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.web.servlet.assertj.MockMvcTester; | ||
|
||
@SpringBootTest | ||
@AutoConfigureMockMvc | ||
class ArticleControllerIntTest { | ||
|
||
@Autowired private MockMvcTester mvcTester; | ||
|
||
@Autowired private ObjectMapper objectMapper; | ||
|
||
@Test | ||
void findArticleById() { | ||
|
||
mvcTester | ||
.get() | ||
.uri("/articles/1") | ||
.assertThat() | ||
.hasStatusOk() | ||
.hasContentType(MediaType.APPLICATION_JSON) | ||
.bodyJson() | ||
.convertTo(ArticleDTO.class) | ||
.satisfies( | ||
articleDTO -> { | ||
assertThat(articleDTO.title()) | ||
.isNotNull() | ||
.isEqualTo("Waiter! There is a bug in my JSoup!"); | ||
assertThat(articleDTO.authored()) | ||
.isNotNull() | ||
.isInstanceOf(LocalDateTime.class); | ||
assertThat(articleDTO.published()) | ||
.isNotNull() | ||
.isInstanceOf(LocalDateTime.class); | ||
assertThat(articleDTO.commentDTOs()) | ||
.isNotNull() | ||
.hasSize(2) | ||
.hasOnlyElementsOfType(CommentDTO.class); | ||
}); | ||
} | ||
|
||
@Test | ||
void shouldReturn404WhenFetchingNonExistingArticle() { | ||
mvcTester.get().uri("/articles/99999").assertThat().hasStatus(HttpStatus.NOT_FOUND); | ||
} | ||
|
||
@Test | ||
void saveRetrieveAndDeleteArticle() throws JsonProcessingException { | ||
ArticleDTO articleDTO = | ||
new ArticleDTO( | ||
"junitTitle", | ||
LocalDateTime.now().minusDays(1), | ||
LocalDateTime.now(), | ||
List.of(new CommentDTO("junitComment"))); | ||
AtomicReference<String> location = new AtomicReference<>(); | ||
mvcTester | ||
.post() | ||
.uri("/articles/") | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(articleDTO)) | ||
.assertThat() | ||
.hasStatus(HttpStatus.CREATED) | ||
.matches( | ||
result -> { | ||
location.set(result.getResponse().getHeader("Location")); | ||
assertThat(location.get()).isNotBlank().contains("/articles/"); | ||
}); | ||
|
||
mvcTester | ||
.get() | ||
.uri(location.get()) | ||
.assertThat() | ||
.hasStatusOk() | ||
.hasContentType(MediaType.APPLICATION_JSON) | ||
.bodyJson() | ||
.convertTo(ArticleDTO.class) | ||
.satisfies( | ||
response -> { | ||
assertThat(response.title()).isNotNull().isEqualTo("junitTitle"); | ||
assertThat(response.authored()) | ||
.isNotNull() | ||
.isInstanceOf(LocalDateTime.class); | ||
assertThat(response.authored().toLocalDate()) | ||
.isEqualTo(LocalDate.now().minusDays(1)); | ||
assertThat(response.published()) | ||
.isNotNull() | ||
.isInstanceOf(LocalDateTime.class); | ||
assertThat(response.published().toLocalDate()) | ||
.isEqualTo(LocalDate.now()); | ||
assertThat(response.commentDTOs()) | ||
.isNotNull() | ||
.hasSize(1) | ||
.hasOnlyElementsOfType(CommentDTO.class); | ||
}); | ||
|
||
mvcTester.delete().uri(location.get()).assertThat().hasStatus(HttpStatus.ACCEPTED); | ||
} | ||
|
||
@Test | ||
void cantDeleteArticleWhenArticleNotFound() { | ||
mvcTester.delete().uri("/articles/99999").assertThat().hasStatus(HttpStatus.NOT_FOUND); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Codebase verification
Problem Details enabled but error handling implementation is incomplete
The problem details configuration is enabled in application.yml, but the Article-related components lack proper error handling implementation:
To properly integrate with Problem Details:
🔗 Analysis chain
Verify error handling integration with Article operations.
Let's verify that the problem details configuration is properly integrated with the Article-related error scenarios.
Let me gather more specific information about the error handling in this project.
Let me check for specific error handling implementations in the Article-related components.
Let me check one more aspect to verify the error handling integration.
🏁 Scripts executed
The following scripts were executed for the analysis:
Script:
Length of output: 3555
Script:
Length of output: 35315
Script:
Length of output: 4263
Script:
Length of output: 2479