Skip to content

Commit

Permalink
110 now it's actually done
Browse files Browse the repository at this point in the history
  • Loading branch information
iuliana committed Aug 6, 2017
1 parent e3efb7e commit 62e18e4
Show file tree
Hide file tree
Showing 35 changed files with 327 additions and 118 deletions.
14 changes: 7 additions & 7 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ext {
//spring libs
springVersion = '5.0.0.M4'
springVersion = '5.0.0.RC3'
bootVersion = '2.0.0.M3'
springDataVersion = '2.0.0.M3'
springAmqpVersion = '2.0.0.M4'
Expand Down Expand Up @@ -30,7 +30,7 @@ ext {
artemisVersion = '2.1.0'
hornetqVersion = '2.4.0.Final'
castorVersion = '1.4.1'
jacksonVersion = '2.9.0.pr3'
jacksonVersion = '2.9.0'
httpclientVersion = '4.5.3'
poiVersion = '3.16'
tilesVersion = '3.0.7'
Expand Down Expand Up @@ -106,14 +106,14 @@ ext {
starterThyme : "org.springframework.boot:spring-boot-starter-thymeleaf:$bootVersion",
starterSecurity : "org.springframework.boot:spring-boot-starter-security:$bootVersion",
starterBatch : "org.springframework.boot:spring-boot-starter-batch:$bootVersion",
starterWebflux : "org.springframework.boot:spring-boot-starter-webflux:$bootVersion"
starterWebflux : "org.springframework.boot:spring-boot-starter-webflux:$bootVersion"

]

testing = [
junit : "junit:junit:$junitVersion",
junit5 : "org.junit.jupiter:junit-jupiter-engine:$junit5Version",
junitJupiter: "org.junit.jupiter:junit-jupiter-api:$junit5Version",
junit5Engine: "org.junit.jupiter:junit-jupiter-engine:$junit5Version",
junit5Runner: "org.junit.platform:junit-platform-runner:1.0.0-M4",
mockito : "org.mockito:mockito-all:$mockitoVersion",
easymock : "org.easymock:easymock:3.4",
jmock : "org.jmock:jmock:2.8.2",
Expand Down Expand Up @@ -162,8 +162,8 @@ ext {
]

react = [
projReactorIpc : "io.projectreactor.ipc:reactor-netty:0.7.0.M1",
tomcatEmbedded : "org.apache.tomcat.embed:tomcat-embed-core:9.0.0.M25"
projReactorIpc: "io.projectreactor.ipc:reactor-netty:0.7.0.M1",
tomcatEmbedded: "org.apache.tomcat.embed:tomcat-embed-core:9.0.0.M25",
]

db = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.springframework.oxm.castor.CastorMarshaller;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand All @@ -28,7 +28,7 @@
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.apress.prospring5.ch12"})
public class WebConfig extends WebMvcConfigurerAdapter {
public class WebConfig implements WebMvcConfigurer {

@Autowired ApplicationContext ctx;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
import org.springframework.oxm.castor.CastorMarshaller;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand All @@ -28,7 +28,7 @@
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.apress.prospring5.ch12"})
public class WebConfig extends WebMvcConfigurerAdapter {
public class WebConfig implements WebMvcConfigurer {

@Autowired ApplicationContext ctx;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
* Created by iuliana.cosmina on 6/5/17.
*/
@Configuration
@EnableWebMvc
public class WebConfig extends WebMvcConfigurerAdapter {
public class WebConfig implements WebMvcConfigurer {

}
2 changes: 1 addition & 1 deletion chapter13/junit5-test/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
dependencies {
compile project(':chapter13:base-test')
testCompile testing.junit5, testing. junitJupiter, testing.mockito, spring.test
testCompile testing.junit5Engine, testing.mockito, spring.test
}

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import org.springframework.oxm.castor.CastorMarshaller;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.persistence.EntityManagerFactory;
import java.text.DateFormat;
Expand All @@ -36,12 +36,13 @@
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.apress.prospring5.ch15"})
public class WebConfig extends WebMvcConfigurerAdapter {
public class WebConfig implements WebMvcConfigurer {

@Autowired ApplicationContext ctx;

/**
* Setting the MappingJackson2HttpMessageConverter and configuring it
*
* @return
*/
@Bean
Expand Down Expand Up @@ -85,24 +86,23 @@ public void configureMessageConverters(List<HttpMessageConverter<?>> converters)

@Bean CastorMarshaller castorMarshaller() {
CastorMarshaller castorMarshaller = new CastorMarshaller();
castorMarshaller.setMappingLocation(ctx.getResource( "classpath:spring/oxm-mapping.xml"));
castorMarshaller.setMappingLocation(ctx.getResource("classpath:spring/oxm-mapping.xml"));
return castorMarshaller;
}

// JMX beans

@Bean AppStatistics appStatisticsBean() {
return new AppStatisticsImpl();
}

@Bean CustomStatistics statisticsBean(){
@Bean CustomStatistics statisticsBean() {
return new CustomStatistics();
}

@Autowired
private EntityManagerFactory entityManagerFactory;

@Bean SessionFactory sessionFactory(){
@Bean SessionFactory sessionFactory() {
return entityManagerFactory.unwrap(SessionFactory.class);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.apress.prospring5.ch16"})
public class WebConfig extends WebMvcConfigurerAdapter {
public class WebConfig implements WebMvcConfigurer {

//Declare our static resources. I added cache to the java config but it?s not required.
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
* Created by iuliana.cosmina on 7/29/17.
Expand All @@ -12,7 +15,7 @@
@EnableWebMvc
@EnableAsync
@ComponentScan(basePackages = {"com.apress.prospring5.ch17"})
public class WebConfig extends WebMvcConfigurerAdapter {
public class WebConfig implements WebMvcConfigurer {

// <=> <mvc:default-servlet-handler/>
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
* Created by iuliana.cosmina on 7/29/17.
Expand All @@ -15,7 +18,7 @@
@EnableWebMvc
@EnableAsync
@ComponentScan(basePackages = {"com.apress.prospring5.ch17"})
public class WebConfig extends WebMvcConfigurerAdapter {
public class WebConfig implements WebMvcConfigurer {

// <=> <mvc:default-servlet-handler/>
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@

import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;
import org.springframework.web.servlet.config.annotation.DefaultServletHandlerConfigurer;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
* Created by iuliana.cosmina on 7/29/17.
*/
@Configuration
@EnableWebMvc
@ComponentScan(basePackages = {"com.apress.prospring5.ch17"})
public class WebConfig extends WebMvcConfigurerAdapter {
public class WebConfig implements WebMvcConfigurer {

// <=> <mvc:default-servlet-handler/>
@Override
Expand Down
30 changes: 30 additions & 0 deletions chapter18/boot-tests/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
buildscript {
repositories {
mavenLocal()
mavenCentral()
maven { url "http://repo.spring.io/release" }
maven { url "http://repo.spring.io/snapshot" }
maven { url "https://repo.spring.io/libs-snapshot" }
maven { url "http://repo.spring.io/milestone" }
maven { url "https://repo.spring.io/libs-milestone" }
}

dependencies {
classpath boot.springBootPlugin
}
}

apply plugin: 'org.springframework.boot'

dependencies {
compile boot.starterWebflux, boot.starterWeb
testCompile boot.starterTest, testing.junit5Engine, testing.junit5Runner
}

jar {
manifest {
attributes("Created-By": "Iuliana Cosmina",
"Specification-Title": "Pro Spring 5",
"Class-Path": configurations.compile.collect { it.getName() }.join(' '))
}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,28 @@
package com.apress.prospring5.ch18;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;


/**
* Created by iuliana.cosmina on 8/6/17.
*/
@SpringBootApplication
public class Application {

private static final Logger logger = LoggerFactory.getLogger(Application.class);

public static void main(String[] args) throws Exception {
ConfigurableApplicationContext ctx = new SpringApplicationBuilder(Application.class)
.run(args);
assert (ctx != null);
logger.info("Application started...");

System.in.read();
ctx.close();
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
package com.apress.prospring5.ch18;

import org.springframework.stereotype.Component;
import reactor.core.publisher.Flux;

/**
* Created by iuliana.cosmina on 8/6/17.
*/
@Component
public class FluxGenerator {

public Flux<String> generate(String... args){
return Flux.just(args);
}

}
Original file line number Diff line number Diff line change
@@ -1,37 +1,42 @@
package com.apress.prospring5.ch18.test;

import com.apress.prospring5.ch18.entities.Singer;
import com.apress.prospring5.ch18.FluxGenerator;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import reactor.core.publisher.Flux;
import reactor.util.function.Tuple2;

import java.time.Duration;

/**
* Created by iuliana.cosmina on 8/6/17.
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class IntegrationOneTest {

private final Logger logger = LoggerFactory.getLogger(IntegrationOneTest.class);
@Autowired FluxGenerator fluxGenerator;

@Test
public void test1One() {
Flux<String> numbers = Flux.just("1", "2", "3");
Flux<Long> periodFlux = Flux.interval(Duration.ofSeconds(2));
Flux.zip(numbers, periodFlux).map(Tuple2::getT1).doOnNext(logger::info);
fluxGenerator.generate("1", "2", "3").collectList().block().forEach(s ->
executeSlow(2000, s)
);
}

@Test
public void test2One() {
Flux<String> numbers = Flux.just("11", "22", "33");
Flux<Long> periodFlux = Flux.interval(Duration.ofSeconds(2));
Flux.zip(numbers, periodFlux).map(Tuple2::getT1).doOnNext(logger::info);
fluxGenerator.generate("11", "22", "33").collectList().block().forEach(s -> executeSlow(1000, s));
}

private void executeSlow(int duration, String s) {
try {
Thread.sleep(duration);
logger.info(s);
} catch (InterruptedException e) {
}
}
}

Loading

0 comments on commit 62e18e4

Please sign in to comment.