Skip to content

Commit

Permalink
chore: clean boot-data-couchbase
Browse files Browse the repository at this point in the history
  • Loading branch information
hantsy committed May 27, 2022
1 parent d60b5eb commit 3cd1aea
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 17 deletions.
2 changes: 1 addition & 1 deletion boot-data-couchbase/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<properties>
<java.version>17</java.version>
<testcontainers.version>1.17.1</testcontainers.version>
<testcontainers.version>1.17.2</testcontainers.version>
<maven-surefire-plugin.version>3.0.0-M6</maven-surefire-plugin.version>
</properties>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,20 @@ public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}

}

@Configuration
class WebConfig {
@Bean
public RouterFunction<ServerResponse> routes(PostHandler postController) {
return route(GET("/posts"), postController::all)
.andRoute(POST("/posts"), postController::create)
.andRoute(GET("/posts/{id}"), postController::get)
.andRoute(PUT("/posts/{id}"), postController::update)
.andRoute(DELETE("/posts/{id}"), postController::delete);
public RouterFunction<ServerResponse> routes(PostHandler handler) {
return route(GET("/posts"), handler::all)
.andRoute(POST("/posts"), handler::create)
.andRoute(GET("/posts/{id}"), handler::get)
.andRoute(PUT("/posts/{id}"), handler::update)
.andRoute(DELETE("/posts/{id}"), handler::delete);
}

}


@Configuration(proxyBeanMethods = false)
// see: https://jira.spring.io/browse/DATACOUCH-644
@EnableReactiveCouchbaseAuditing
Expand Down Expand Up @@ -94,14 +96,10 @@ public void run(String[] args) {
}

@Component
@RequiredArgsConstructor
class PostHandler {

private final PostRepository posts;

public PostHandler(PostRepository posts) {
this.posts = posts;
}

public Mono<ServerResponse> all(ServerRequest req) {
return ServerResponse.ok().body(this.posts.findAll(), Post.class);
}
Expand Down Expand Up @@ -153,7 +151,6 @@ interface PostRepository extends ReactiveCouchbaseRepository<Post, String> {
@Builder
@NoArgsConstructor
@AllArgsConstructor

class Post {

@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.example.demo;

import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.autoconfigure.data.couchbase.DataCouchbaseTest;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Import;
import org.springframework.data.domain.Sort;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.DynamicPropertyRegistry;
Expand All @@ -18,14 +21,22 @@

import java.time.Duration;
import java.util.List;
import java.util.concurrent.CountDownLatch;

import static org.assertj.core.api.Assertions.assertThat;

@SpringBootTest
@DataCouchbaseTest
@Testcontainers
@ActiveProfiles("test")
@Slf4j
class PostRepositoryWithDynamicPropertiesTest {


@TestConfiguration
@Import(DataConfig.class)
static class TestConfig {
}

private static final String COUCHBASE_IMAGE_NAME = "couchbase";
private static final String DEFAULT_IMAGE_NAME = "couchbase/server";
private static final DockerImageName DEFAULT_IMAGE = DockerImageName.parse(COUCHBASE_IMAGE_NAME)
Expand All @@ -49,16 +60,21 @@ static void bindCouchbaseProperties(DynamicPropertyRegistry registry) {
@Autowired
private PostRepository posts;

@SneakyThrows
@BeforeEach
public void setup() {
var countDownLatch = new CountDownLatch(1);
this.posts
.saveAll(
List.of(
Post.builder().title("Post one").content("content of post one").build(),
Post.builder().title("Post two").content("content of post two").build()
)
)
.doOnTerminate(countDownLatch::countDown)
.subscribe(data -> log.debug("saved data: {}", data));

countDownLatch.await(1000, java.util.concurrent.TimeUnit.MILLISECONDS);
}

@Test
Expand Down

0 comments on commit 3cd1aea

Please sign in to comment.