Fix version and format

This commit is contained in:
Yuriy Dvorzhetskiy
2021-05-15 17:44:56 +03:00
parent 209f821477
commit 9cbcf9ae5f
10 changed files with 48 additions and 77 deletions
+1 -1
View File
@@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<version>2.4.5</version>
<relativePath/>
</parent>
@@ -22,35 +22,35 @@ import static org.springframework.web.reactive.function.server.ServerResponse.ok
@SpringBootApplication
public class Main {
public static void main( String[] args ) {
ApplicationContext context = SpringApplication.run( Main.class );
PersonRepository repository = context.getBean( PersonRepository.class );
public static void main(String[] args) {
ApplicationContext context = SpringApplication.run(Main.class);
PersonRepository repository = context.getBean(PersonRepository.class);
repository.saveAll( Arrays.asList(
new Person( "Pushkin", 22 ),
new Person( "Lermontov", 22 ),
new Person( "Tolstoy", 60 )
) ).subscribe( p -> System.out.println( p.getLastName() ) );
repository.saveAll(Arrays.asList(
new Person("Pushkin", 22),
new Person("Lermontov", 22),
new Person("Tolstoy", 60)
)).subscribe(p -> System.out.println(p.getLastName()));
}
@Bean
public RouterFunction<ServerResponse> composedRoutes( PersonRepository repository ) {
public RouterFunction<ServerResponse> composedRoutes(PersonRepository repository) {
PersonHandler handler = new PersonHandler( repository );
PersonHandler handler = new PersonHandler(repository);
RouterFunction<ServerResponse> route = route()
.GET( "/func/person", accept( APPLICATION_JSON ), handler::list )
.GET( "/func/person/{id}", accept( APPLICATION_JSON ),
request -> repository.findById( request.pathVariable( "id" ) )
.flatMap( person -> ok().contentType( APPLICATION_JSON ).body( fromObject( person ) ) )
.GET("/func/person", accept(APPLICATION_JSON), handler::list)
.GET("/func/person/{id}", accept(APPLICATION_JSON),
request -> repository.findById(request.pathVariable("id"))
.flatMap(person -> ok().contentType(APPLICATION_JSON).body(fromObject(person)))
)
.GET( "/func/person/age/{age}", accept( APPLICATION_JSON ),
serverRequest -> ok().contentType( APPLICATION_JSON )
.body( repository.findAllByAge( Integer.valueOf( serverRequest.pathVariable( "age" ) ) ), Person.class ) )
.GET( "/func/person/find", accept( APPLICATION_JSON ),
serverRequest -> ok().contentType( APPLICATION_JSON )
.body( repository.findAllByAge( Integer.valueOf( serverRequest.queryParam( "age" ).get() ) ), Person.class ) )
.GET("/func/person/age/{age}", accept(APPLICATION_JSON),
serverRequest -> ok().contentType(APPLICATION_JSON)
.body(repository.findAllByAge(Integer.valueOf(serverRequest.pathVariable("age"))), Person.class))
.GET("/func/person/find", accept(APPLICATION_JSON),
serverRequest -> ok().contentType(APPLICATION_JSON)
.body(repository.findAllByAge(Integer.valueOf(serverRequest.queryParam("age").get())), Person.class))
.build();
return route;
@@ -61,18 +61,18 @@ public class Main {
private PersonRepository repository;
PersonHandler( PersonRepository repository ) {
PersonHandler(PersonRepository repository) {
this.repository = repository;
}
Mono<ServerResponse> list( ServerRequest request ) {
return ok().contentType( APPLICATION_JSON ).body( repository.findAll(), Person.class );
Mono<ServerResponse> list(ServerRequest request) {
return ok().contentType(APPLICATION_JSON).body(repository.findAll(), Person.class);
}
Mono<ServerResponse> listAge( ServerRequest request ) {
System.out.println( "I'm here" );
return ok().contentType( APPLICATION_JSON )
.body( repository.findAllByAge( Integer.valueOf( request.queryParam( "age" ).get() ) ), Person.class );
Mono<ServerResponse> listAge(ServerRequest request) {
System.out.println("I'm here");
return ok().contentType(APPLICATION_JSON)
.body(repository.findAllByAge(Integer.valueOf(request.queryParam("age").get())), Person.class);
}
}
}
@@ -13,21 +13,21 @@ public class AnnotatedController {
@GetMapping("/flux/one")
public Mono<String> one() {
return Mono.just( "one" );
return Mono.just("one");
}
@GetMapping("/flux/ten")
public Flux<Integer> list() {
return Flux.range( 1, 10 ).delayElements( Duration.ofSeconds( 1 ) );
return Flux.range(1, 10).delayElements(Duration.ofSeconds(1));
}
@GetMapping(path = "/stream", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> stream() {
return Flux.generate( () -> 0, ( state, emitter ) -> {
emitter.next( state );
return Flux.generate(() -> 0, (state, emitter) -> {
emitter.next(state);
return state + 1;
} )
.delayElements( Duration.ofSeconds( 1L ) )
.map( i -> "" + i );
})
.delayElements(Duration.ofSeconds(1L))
.map(i -> "" + i);
}
}
@@ -31,7 +31,7 @@ public class PersonController {
}
@GetMapping("/person/find")
public Flux<Person> byName(@RequestParam("name") String name){
return repository.findAllByLastName( name );
public Flux<Person> byName(@RequestParam("name") String name) {
return repository.findAllByLastName(name);
}
}
@@ -1,17 +1,14 @@
package ru.otus.spring.repository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
import org.springframework.test.context.junit4.SpringRunner;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import ru.otus.spring.domain.Person;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@RunWith(SpringRunner.class)
@DataMongoTest
public class PersonRepositoryTest {
@@ -1,19 +1,17 @@
package ru.otus.spring.rest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonControllerTest {
@Autowired
private RouterFunction route;
private RouterFunction<ServerResponse> route;
@Test
public void testRoute() {
@@ -27,6 +25,4 @@ public class PersonControllerTest {
.expectStatus()
.isOk();
}
}
+1 -1
View File
@@ -11,7 +11,7 @@
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.2.4.RELEASE</version>
<version>2.4.5</version>
<relativePath/>
</parent>
@@ -6,9 +6,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerRequest;
import org.springframework.web.reactive.function.server.ServerResponse;
import reactor.core.publisher.Mono;
import ru.otus.spring.domain.Person;
import ru.otus.spring.repository.PersonRepository;
@@ -1,17 +1,14 @@
package ru.otus.spring.repository;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.mongo.DataMongoTest;
import org.springframework.test.context.junit4.SpringRunner;
import reactor.core.publisher.Mono;
import reactor.test.StepVerifier;
import ru.otus.spring.domain.Person;
import static org.junit.Assert.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNotNull;
@RunWith(SpringRunner.class)
@DataMongoTest
public class PersonRepositoryTest {
@@ -28,17 +25,4 @@ public class PersonRepositoryTest {
.expectComplete()
.verify();
}
@Test
public void shouldFindByAge() {
repository.save(new Person("Pushkin", 18)).block();
StepVerifier.create(
repository.findAllByAge(18)
)
.expectFusion()
.expectNextCount(1)
.expectComplete()
.verify();
}
}
@@ -1,19 +1,17 @@
package ru.otus.spring.rest;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.web.reactive.function.server.RouterFunction;
import org.springframework.web.reactive.function.server.ServerResponse;
@RunWith(SpringRunner.class)
@SpringBootTest
public class PersonControllerTest {
@Autowired
private RouterFunction route;
private RouterFunction<ServerResponse> route;
@Test
public void testRoute() {
@@ -27,6 +25,4 @@ public class PersonControllerTest {
.expectStatus()
.isOk();
}
}