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

clean code #1601

Merged
merged 4 commits into from
Dec 26, 2024
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
54 changes: 27 additions & 27 deletions README.md

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion boot-grafana-lgtm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<!-- Remove version when spring boot supports-->
<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>grafana</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion boot-rabbitmq-thymeleaf/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@
<configuration>
<java>
<googleJavaFormat>
<version>1.22.0</version>
<version>1.25.2</version>
<style>AOSP</style>
</googleJavaFormat>
</java>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import static org.testcontainers.shaded.org.awaitility.Awaitility.await;

import com.poc.boot.rabbitmq.common.ContainerConfiguration;
import com.poc.boot.rabbitmq.model.Order;
import com.poc.boot.rabbitmq.repository.TrackingStateRepository;
import java.util.concurrent.TimeUnit;
Expand All @@ -20,7 +21,7 @@

@SpringBootTest(
webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT,
classes = TestRabbitMQApplication.class)
classes = ContainerConfiguration.class)
@AutoConfigureMockMvc
class RabbitMQIntegrationTest {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,11 @@
package com.poc.boot.rabbitmq;

import com.poc.boot.rabbitmq.common.ContainerConfiguration;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.devtools.restart.RestartScope;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.RabbitMQContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class TestRabbitMQApplication {

@Bean
@ServiceConnection
@RestartScope
RabbitMQContainer rabbitMQContainer() {
return new RabbitMQContainer(DockerImageName.parse("rabbitmq").withTag("4.0.4-management"));
}

public static void main(String[] args) {
SpringApplication.from(RabbitMQApplication::main).with(TestRabbitMQApplication.class).run();
SpringApplication.from(RabbitMQApplication::main).with(ContainerConfiguration.class).run();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.poc.boot.rabbitmq.common;

import org.springframework.boot.devtools.restart.RestartScope;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
import org.springframework.context.annotation.Bean;
import org.testcontainers.containers.RabbitMQContainer;
import org.testcontainers.utility.DockerImageName;

@TestConfiguration(proxyBeanMethods = false)
public class ContainerConfiguration {

@Bean
@ServiceConnection
@RestartScope
RabbitMQContainer rabbitMQContainer() {
return new RabbitMQContainer(DockerImageName.parse("rabbitmq").withTag("4.0.5-management"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;

@WebMvcTest(MessageController.class)
Expand All @@ -29,7 +29,7 @@ class MessageControllerTest {

@Autowired private MockMvc mockMvc;

@MockBean private OrderMessageSender orderMessageSender;
@MockitoBean private OrderMessageSender orderMessageSender;

@Test
void handleMessage() throws Exception {
Expand Down
4 changes: 4 additions & 0 deletions graphql/boot-graphql-webmvc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,10 @@

<build>
<plugins>
<plugin>
<groupId>org.graalvm.buildtools</groupId>
<artifactId>native-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ public class ContainersConfig {
@Bean
@ServiceConnection
PostgreSQLContainer<?> postgreSQLContainer() {
return new PostgreSQLContainer<>(DockerImageName.parse("postgres:17.2-alpine"));
return new PostgreSQLContainer<>(DockerImageName.parse("postgres").withTag("17.2-alpine"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
import org.springframework.context.annotation.Import;

@DataJpaTest(properties = {"spring.jpa.hibernate.ddl-auto=validate", "spring.test.database.replace=none"})
@DataJpaTest(properties = {"spring.jpa.hibernate.ddl-auto=validate"})
@Import(ContainersConfig.class)
class SchemaValidationTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.bean.override.mockito.MockitoBean;
import org.springframework.test.web.servlet.MockMvc;

@WebMvcTest(controllers = CustomerController.class)
Expand All @@ -48,7 +48,7 @@ class CustomerControllerTest {
@Autowired
private MockMvc mockMvc;

@MockBean
@MockitoBean
private CustomerService customerService;

@Autowired
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
suppressTimestampInGenerated = true)
public interface CustomerMapper {

@Mapping(target = "id", ignore = true)
Customer toEntity(CustomerRequest customerRequest);

@IterableMapping(elementTargetType = CustomerResponse.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
suppressTimestampInGenerated = true)
public interface OrderMapper {

@Mapping(target = "removeOrderItem", ignore = true)
@Mapping(target = "orderItems", ignore = true)
@Mapping(target = "id", ignore = true)
@Mapping(target = "customer.id", source = "customerId")
Expand All @@ -32,6 +33,7 @@ public interface OrderMapper {
@IterableMapping(elementTargetType = OrderResponse.class)
List<OrderResponse> mapToOrderResponseList(List<Order> orderList);

@Mapping(target = "removeOrderItem", ignore = true)
@Mapping(target = "orderItems", ignore = true)
@Mapping(target = "id", ignore = true)
@Mapping(target = "customer", ignore = true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
public interface CustomerRepository
extends BaseJpaRepository<Customer, Long>, PagingAndSortingRepository<Customer, Long> {

@Transactional(readOnly = true)
@QueryHints(@QueryHint(name = HINT_CACHEABLE, value = "true"))
@EntityGraph(attributePaths = {"orders"})
Optional<Customer> findByFirstName(String firstName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
import reactor.core.publisher.Mono;

@Service
@Transactional
@Transactional(readOnly = true)
@RequiredArgsConstructor
public class ReactiveCommentsService {

Expand All @@ -34,20 +34,23 @@ public Mono<ReactiveComments> findReactiveCommentById(UUID id) {
return reactiveCommentsRepository.findById(id);
}

@Transactional
public Mono<ReactiveComments> saveReactiveCommentByPostId(
ReactiveCommentRequest reactiveCommentRequest) {
ReactiveComments reactiveComments =
reactivePostCommentMapper.mapToReactivePostComments(reactiveCommentRequest);
return reactiveCommentsRepository.save(reactiveComments);
}

@Transactional
public Mono<ReactiveComments> updateReactivePostComment(
ReactiveCommentRequest reactiveCommentRequest, ReactiveComments reactiveComments) {
reactivePostCommentMapper.updateReactiveCommentRequestFromReactiveComments(
reactiveCommentRequest, reactiveComments);
return reactiveCommentsRepository.save(reactiveComments);
}

@Transactional
public Mono<Void> deleteReactiveCommentById(UUID id) {
return reactiveCommentsRepository.deleteById(id);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,9 @@ void deleteReactivePostById() {
// given
given(reactivePostRepository.deleteById(1L)).willReturn(Mono.empty());
// when
reactivePostService.deleteReactivePostById(1L);
Mono<Void> voidMono = reactivePostService.deleteReactivePostById(1L);
// then
StepVerifier.create(voidMono).expectComplete().verify();
verify(reactivePostRepository, times(1)).deleteById(1L);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ spring.quartz.properties.org.quartz.scheduler.instanceId=AUTO
spring.quartz.properties.org.quartz.jobStore.driverDelegateClass=org.quartz.impl.jdbcjobstore.PostgreSQLDelegate
## Default is RamJobStore, if you want to use JDBC Job Store, you need to set the following properties
spring.quartz.properties.org.quartz.jobStore.class=org.quartz.impl.jdbcjobstore.JobStoreTX
spring.quartz.properties.org.quartz.jobStore.dataSource=quartzDataSource
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.provider=hikaricp
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.driver=${spring.datasource.driver-class-name}
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.URL=${spring.datasource.url}
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.user=${spring.datasource.username}
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.password=${spring.datasource.password}
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.maxConnections=10
spring.quartz.properties.org.quartz.dataSource.quartzDataSource.validationQuery=select 1
spring.quartz.properties.org.quartz.jobStore.dataSource=quartzDS
spring.quartz.properties.org.quartz.dataSource.quartzDS.provider=hikaricp
spring.quartz.properties.org.quartz.dataSource.quartzDS.driver=${spring.datasource.driver-class-name}
spring.quartz.properties.org.quartz.dataSource.quartzDS.URL=${spring.datasource.url}
spring.quartz.properties.org.quartz.dataSource.quartzDS.user=${spring.datasource.username}
spring.quartz.properties.org.quartz.dataSource.quartzDS.password=${spring.datasource.password}
spring.quartz.properties.org.quartz.dataSource.quartzDS.maxConnections=10
spring.quartz.properties.org.quartz.dataSource.quartzDS.validationQuery=select 1

Loading