Skip to content

Commit

Permalink
clean data-mongo, vanilla sample, and update to Spring Boot 2.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
hantsy committed Mar 4, 2020
1 parent 06aa9ac commit d8fec92
Show file tree
Hide file tree
Showing 44 changed files with 533 additions and 548 deletions.
20 changes: 10 additions & 10 deletions data-mongo-pageable/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>11</java.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -79,10 +79,15 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>


<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -105,11 +110,6 @@
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,25 +28,25 @@ public DataInitializer(PostRepository posts) {
public void init() {
log.info("start data initialization ...");
this.posts
.deleteAll()
.thenMany(
Flux
.range(0, 100)
.flatMap(
n -> this.posts.save(
Post.builder()
.title("post title #" + n)
.content("content of post " + n)
.build()
)
)
)
.log()
.subscribe(
null,
null,
() -> log.info("done initialization...")
);
.deleteAll()
.thenMany(
Flux
.range(0, 100)
.flatMap(
n -> this.posts.save(
Post.builder()
.title("post title #" + n)
.content("content of post " + n)
.build()
)
)
)
.log()
.subscribe(
data -> log.info("data: {}", data),
error -> log.info("error: {}", error),
() -> log.info("done initialization...")
);

}

Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
mongo.uri=mongodb://localhost:27017/
mongo.uri=mongodb://localhost:27017/blogdb
Original file line number Diff line number Diff line change
Expand Up @@ -5,73 +5,67 @@
*/
package com.example.demo;

import static org.junit.Assert.assertTrue;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;

import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.web.reactive.server.WebTestClient;

/**
*
* @author hantsy
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = Application.class)
@SpringJUnitConfig(classes = Application.class)
@ActiveProfiles("test")
public class ApplicationTests {

@Autowired
ApplicationContext context;

WebTestClient rest;
WebTestClient client;

@Before
@BeforeAll
public void setup() {
this.rest = WebTestClient
.bindToApplicationContext(this.context)
.configureClient()
.build();
this.client = WebTestClient
.bindToApplicationContext(this.context)
.configureClient()
.build();
}

@Test
public void searchPostsByKeyword_shouldBeOK() throws Exception {
this.rest
.get()
.uri("/posts/search?q=post")
.exchange()
.expectStatus().isOk()
.expectBodyList(Post.class).hasSize(10);
this.client
.get()
.uri("/posts/search?q=post")
.exchange()
.expectStatus().isOk()
.expectBodyList(Post.class).hasSize(10);
}

@Test
@Ignore
public void countPostsByKeyword_shouldBeOK() throws Exception {
this.rest
.get()
.uri("/posts/count?q=0")
.exchange()
.expectStatus().isOk()
.expectBody().jsonPath("$.count").isEqualTo(10);
this.client
.get()
.uri("/posts/count?q=0")
.exchange()
.expectStatus().isOk()
.expectBody().jsonPath("$.count").isEqualTo(10);

this.rest
.get()
.uri("/posts/count?q=5")
.exchange()
.expectStatus().isOk()
.expectBody().jsonPath("$.count").isEqualTo(19);
this.client
.get()
.uri("/posts/count?q=5")
.exchange()
.expectStatus().isOk()
.expectBody().jsonPath("$.count").isEqualTo(19);

this.rest
.get()
.uri("/posts/count?q=post")
.exchange()
.expectStatus().isOk()
.expectBody().jsonPath("$.count").isEqualTo(100);
this.client
.get()
.uri("/posts/count?q=post")
.exchange()
.expectStatus().isOk()
.expectBody().jsonPath("$.count").isEqualTo(100);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,77 +1,80 @@
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package com.example.demo;

import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
import org.springframework.test.web.reactive.server.WebTestClient;
import reactor.netty.DisposableServer;
import reactor.netty.http.server.HttpServer;

import java.time.Duration;

/**
*
* @author hantsy
*/
@RunWith(SpringRunner.class)
@ContextConfiguration(classes = Application.class)
@SpringJUnitConfig(classes = Application.class)
public class IntegrationTests {

@Value("#{@nettyContext.address().getPort()}")
@Value("${server.port:8080}")
int port;

WebTestClient rest;
WebTestClient client;

@Autowired
HttpServer httpServer;

private DisposableServer disposableServer;

@Before
@BeforeAll
public void setup() {
this.rest =WebTestClient
.bindToServer()
.responseTimeout(Duration.ofDays(1))
.baseUrl("http://localhost:" + this.port)
.build();
this.disposableServer = this.httpServer.bindNow();
this.client = WebTestClient
.bindToServer()
.responseTimeout(Duration.ofDays(1))
.baseUrl("http://localhost:" + this.port)
.build();
}

@AfterAll
public void teardown() {
this.disposableServer.dispose();
}

@Test
public void searchPostsByKeyword_shouldBeOK() throws Exception {
this.rest
.get()
.uri("/posts/search?q=post")
.exchange()
.expectStatus().isOk()
.expectBodyList(Post.class).hasSize(10);
this.client
.get()
.uri("/posts/search?q=post")
.exchange()
.expectStatus().isOk()
.expectBodyList(Post.class).hasSize(10);
}

@Test
public void countPostsByKeyword_shouldBeOK() throws Exception {
this.rest
.get()
.uri("/posts/count?q=0")
.exchange()
.expectStatus().isOk()
.expectBody().jsonPath("$.count").isEqualTo(10);
this.client
.get()
.uri("/posts/count?q=0")
.exchange()
.expectStatus().isOk()
.expectBody().jsonPath("$.count").isEqualTo(10);

this.rest
.get()
.uri("/posts/count?q=5")
.exchange()
.expectStatus().isOk()
.expectBody().jsonPath("$.count").isEqualTo(19);
this.client
.get()
.uri("/posts/count?q=5")
.exchange()
.expectStatus().isOk()
.expectBody().jsonPath("$.count").isEqualTo(19);

this.rest
.get()
.uri("/posts/count?q=post")
.exchange()
.expectStatus().isOk()
.expectBody().jsonPath("$.count").isEqualTo(100);
this.client
.get()
.uri("/posts/count?q=post")
.exchange()
.expectStatus().isOk()
.expectBody().jsonPath("$.count").isEqualTo(100);
}


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
junit.jupiter.testinstance.lifecycle.default = per_class
28 changes: 12 additions & 16 deletions data-mongo/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<version>2.2.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<java.version>11</java.version>
</properties>

<dependencies>
Expand Down Expand Up @@ -79,30 +77,28 @@
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</dependency>

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.skyscreamer</groupId>
<artifactId>jsonassert</artifactId>
<scope>test</scope>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path-assert</artifactId>
</dependency>
<dependency>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-test</artifactId>
<groupId>io.projectreactor</groupId>
<artifactId>reactor-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
Expand Down
Loading

0 comments on commit d8fec92

Please sign in to comment.