├── Chapter04 ├── account-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── accountservice │ │ │ │ ├── AccountServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── AccountController.java │ │ │ │ ├── domain │ │ │ │ └── Account.java │ │ │ │ └── repository │ │ │ │ └── AccountRepository.java │ │ └── resources │ │ │ ├── application.properties │ │ │ ├── application.yml │ │ │ ├── data.sql │ │ │ └── schema.sql │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── accountservice │ │ ├── AccountControllerIntegrationTest.java │ │ ├── AccountControllerTest.java │ │ ├── AccountRepositoryIntegrationTest.java │ │ └── AccountServiceApplicationTests.java ├── book-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── bookservice │ │ │ │ ├── BookServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── BookController.java │ │ │ │ ├── domain │ │ │ │ └── Book.java │ │ │ │ └── repository │ │ │ │ └── BookRepository.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── bookservice │ │ └── BookServiceApplicationTests.java ├── eureka-server │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── eurekaserver │ │ │ │ └── EurekaServerApplication.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── eurekaserver │ │ └── EurekaServerApplicationTests.java ├── order-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── orderservice │ │ │ │ ├── OrderServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── OrderController.java │ │ │ │ ├── domain │ │ │ │ └── Order.java │ │ │ │ ├── repository │ │ │ │ └── OrderRepository.java │ │ │ │ └── service │ │ │ │ ├── AccountService.java │ │ │ │ └── BookService.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── orderservice │ │ └── OrderServiceApplicationTests.java ├── shipping-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── shippingservice │ │ │ │ ├── ShippingServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── ShippingController.java │ │ │ │ ├── domain │ │ │ │ └── Shipping.java │ │ │ │ ├── repository │ │ │ │ └── ShippingRepository.java │ │ │ │ └── service │ │ │ │ └── OrderService.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── shippingservice │ │ └── ShippingServiceApplicationTests.java └── shopfront-ui │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── dineshonjava │ │ │ └── bookshop │ │ │ └── shopfrontui │ │ │ ├── ShopfrontUiApplication.java │ │ │ ├── controller │ │ │ └── BookShopController.java │ │ │ ├── dto │ │ │ ├── Account.java │ │ │ ├── Book.java │ │ │ ├── Order.java │ │ │ └── Shipping.java │ │ │ └── service │ │ │ ├── AccountService.java │ │ │ ├── BookService.java │ │ │ └── OrderService.java │ └── resources │ │ ├── application.properties │ │ ├── application.yml │ │ └── templates │ │ └── home.html │ └── test │ └── java │ └── com │ └── dineshonjava │ └── bookshop │ └── shopfrontui │ └── ShopfrontUiApplicationTests.java ├── Chapter05 ├── account-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── accountservice │ │ │ │ ├── AccountServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── AccountController.java │ │ │ │ ├── domain │ │ │ │ └── Account.java │ │ │ │ └── repository │ │ │ │ └── AccountRepository.java │ │ └── resources │ │ │ ├── application.properties │ │ │ ├── application.yml │ │ │ ├── data.sql │ │ │ └── schema.sql │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── accountservice │ │ ├── AccountControllerIntegrationTest.java │ │ ├── AccountControllerTest.java │ │ ├── AccountRepositoryIntegrationTest.java │ │ └── AccountServiceApplicationTests.java ├── book-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── bookservice │ │ │ │ ├── BookServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── BookController.java │ │ │ │ ├── domain │ │ │ │ └── Book.java │ │ │ │ └── repository │ │ │ │ └── BookRepository.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── bookservice │ │ └── BookServiceApplicationTests.java ├── eureka-server │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── eurekaserver │ │ │ │ └── EurekaServerApplication.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── eurekaserver │ │ └── EurekaServerApplicationTests.java ├── order-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── orderservice │ │ │ │ ├── OrderServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── OrderController.java │ │ │ │ ├── domain │ │ │ │ └── Order.java │ │ │ │ ├── repository │ │ │ │ └── OrderRepository.java │ │ │ │ └── service │ │ │ │ ├── AccountService.java │ │ │ │ └── BookService.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── orderservice │ │ └── OrderServiceApplicationTests.java ├── shipping-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── shippingservice │ │ │ │ ├── ShippingServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── ShippingController.java │ │ │ │ ├── domain │ │ │ │ └── Shipping.java │ │ │ │ ├── repository │ │ │ │ └── ShippingRepository.java │ │ │ │ └── service │ │ │ │ └── OrderService.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── shippingservice │ │ └── ShippingServiceApplicationTests.java └── shopfront-ui │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── dineshonjava │ │ │ └── bookshop │ │ │ └── shopfrontui │ │ │ ├── ShopfrontUiApplication.java │ │ │ ├── controller │ │ │ └── BookShopController.java │ │ │ ├── dto │ │ │ ├── Account.java │ │ │ ├── Book.java │ │ │ ├── Order.java │ │ │ └── Shipping.java │ │ │ └── service │ │ │ ├── AccountService.java │ │ │ ├── BookService.java │ │ │ └── OrderService.java │ └── resources │ │ ├── application.properties │ │ ├── application.yml │ │ └── templates │ │ └── home.html │ └── test │ └── java │ └── com │ └── dineshonjava │ └── bookshop │ └── shopfrontui │ └── ShopfrontUiApplicationTests.java ├── Chapter06 ├── account-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── accountservice │ │ │ │ ├── AccountServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── AccountController.java │ │ │ │ ├── domain │ │ │ │ └── Account.java │ │ │ │ └── repository │ │ │ │ └── AccountRepository.java │ │ └── resources │ │ │ ├── application.properties │ │ │ ├── application.yml │ │ │ ├── data.sql │ │ │ └── schema.sql │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── accountservice │ │ ├── AccountControllerIntegrationTest.java │ │ ├── AccountControllerTest.java │ │ ├── AccountRepositoryIntegrationTest.java │ │ └── AccountServiceApplicationTests.java ├── api-zuul-proxy │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── apizuulproxy │ │ │ │ └── ApiZuulProxyApplication.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── apizuulproxy │ │ └── ApiZuulProxyApplicationTests.java ├── book-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── bookservice │ │ │ │ ├── BookServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── BookController.java │ │ │ │ ├── domain │ │ │ │ └── Book.java │ │ │ │ └── repository │ │ │ │ └── BookRepository.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── bookservice │ │ └── BookServiceApplicationTests.java ├── eureka-server │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── eurekaserver │ │ │ │ └── EurekaServerApplication.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── eurekaserver │ │ └── EurekaServerApplicationTests.java ├── order-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── orderservice │ │ │ │ ├── OrderServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── OrderController.java │ │ │ │ ├── domain │ │ │ │ └── Order.java │ │ │ │ ├── repository │ │ │ │ └── OrderRepository.java │ │ │ │ └── service │ │ │ │ ├── AccountService.java │ │ │ │ └── BookService.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── orderservice │ │ └── OrderServiceApplicationTests.java ├── shipping-service │ ├── .gitignore │ ├── .mvn │ │ └── wrapper │ │ │ ├── maven-wrapper.jar │ │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── dineshonjava │ │ │ │ └── bookshop │ │ │ │ └── shippingservice │ │ │ │ ├── ShippingServiceApplication.java │ │ │ │ ├── controller │ │ │ │ └── ShippingController.java │ │ │ │ ├── domain │ │ │ │ └── Shipping.java │ │ │ │ ├── repository │ │ │ │ └── ShippingRepository.java │ │ │ │ └── service │ │ │ │ └── OrderService.java │ │ └── resources │ │ │ ├── application.properties │ │ │ └── application.yml │ │ └── test │ │ └── java │ │ └── com │ │ └── dineshonjava │ │ └── bookshop │ │ └── shippingservice │ │ └── ShippingServiceApplicationTests.java └── shopfront-ui │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── dineshonjava │ │ │ └── bookshop │ │ │ └── shopfrontui │ │ │ ├── ShopfrontUiApplication.java │ │ │ ├── controller │ │ │ └── BookShopController.java │ │ │ ├── dto │ │ │ ├── Account.java │ │ │ ├── Book.java │ │ │ ├── Order.java │ │ │ └── Shipping.java │ │ │ └── service │ │ │ ├── AccountService.java │ │ │ ├── BookService.java │ │ │ └── OrderService.java │ └── resources │ │ ├── application.properties │ │ ├── application.yml │ │ └── templates │ │ └── home.html │ └── test │ └── java │ └── com │ └── dineshonjava │ └── bookshop │ └── shopfrontui │ └── ShopfrontUiApplicationTests.java ├── Chapter07 └── account-service │ ├── .gitignore │ ├── .mvn │ └── wrapper │ │ ├── maven-wrapper.jar │ │ └── maven-wrapper.properties │ ├── mvnw │ ├── mvnw.cmd │ ├── pom.xml │ └── src │ ├── main │ ├── java │ │ └── com │ │ │ └── dineshonjava │ │ │ └── bookshop │ │ │ └── accountservice │ │ │ ├── AccountServiceApplication.java │ │ │ ├── controller │ │ │ └── AccountController.java │ │ │ ├── domain │ │ │ └── Account.java │ │ │ └── repository │ │ │ └── AccountRepository.java │ └── resources │ │ ├── application.properties │ │ ├── application.yml │ │ ├── data.sql │ │ └── schema.sql │ └── test │ └── java │ └── com │ └── dineshonjava │ └── bookshop │ └── accountservice │ ├── AccountControllerIntegrationTest.java │ ├── AccountControllerTest.java │ ├── AccountRepositoryIntegrationTest.java │ └── AccountServiceApplicationTests.java ├── Chapter08 └── GatlingTest │ ├── .classpath │ ├── .project │ ├── .settings │ ├── org.eclipse.jdt.core.prefs │ └── org.eclipse.m2e.core.prefs │ ├── pom.xml │ ├── src │ └── com │ │ └── doj │ │ └── test │ │ └── AccountGatlingSimulation.scala │ └── target │ └── classes │ └── META-INF │ ├── MANIFEST.MF │ └── maven │ └── GatlingTest │ └── GatlingTest │ ├── pom.properties │ └── pom.xml ├── LICENSE └── README.md /Chapter04/account-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter04/account-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter04/account-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter04/account-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter04/account-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | account-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | account-service 12 | account-service project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-data-jpa 40 | 41 | 42 | com.h2database 43 | h2 44 | runtime 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.cloud 57 | spring-cloud-dependencies 58 | ${spring-cloud.version} 59 | pom 60 | import 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /Chapter04/account-service/src/main/java/com/dineshonjava/bookshop/accountservice/AccountServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.accountservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @EnableEurekaClient 8 | @SpringBootApplication 9 | public class AccountServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AccountServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter04/account-service/src/main/java/com/dineshonjava/bookshop/accountservice/controller/AccountController.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.accountservice.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.DeleteMapping; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.PutMapping; 9 | import org.springframework.web.bind.annotation.RequestBody; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import com.dineshonjava.bookshop.accountservice.domain.Account; 13 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 14 | 15 | /** 16 | * @author Dinesh.Rajput 17 | * 18 | */ 19 | @RestController 20 | public class AccountController { 21 | 22 | @Autowired 23 | AccountRepository accountRepository; 24 | 25 | public AccountController(AccountRepository accountRepository) { 26 | super(); 27 | this.accountRepository = accountRepository; 28 | } 29 | 30 | @PostMapping(value = "/account") 31 | public Account save (@RequestBody Account account){ 32 | return accountRepository.save(account); 33 | } 34 | 35 | @GetMapping(value = "/account") 36 | public Iterable all (){ 37 | return accountRepository.findAll(); 38 | } 39 | 40 | @GetMapping(value = "/account/{accountId}") 41 | public Account findByAccountId (@PathVariable Integer accountId){ 42 | return accountRepository.findAccountByAccountId(accountId); 43 | } 44 | 45 | @PutMapping(value = "/account") 46 | public Account update (@RequestBody Account account){ 47 | return accountRepository.save(account); 48 | } 49 | 50 | @DeleteMapping(value = "/account") 51 | public void delete (@RequestBody Account account){ 52 | accountRepository.delete(account); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Chapter04/account-service/src/main/java/com/dineshonjava/bookshop/accountservice/repository/AccountRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice.repository; 5 | 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | import com.dineshonjava.bookshop.accountservice.domain.Account; 9 | 10 | /** 11 | * @author Dinesh.Rajput 12 | * 13 | */ 14 | public interface AccountRepository extends CrudRepository{ 15 | 16 | Account findAccountByAccountId(Integer accountId); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter04/account-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter04/account-service/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter04/account-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: account-service 4 | 5 | server: 6 | port: 1111 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter04/account-service/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1000, 'Dinesh Rajput', 'K-12, Sector 13, Noida', 'dineshxxx@gmail.com', '99312XXX12'); 2 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1001, 'Anamika Rajput', 'M-15, Sector 15, Noida', 'anamikaxxx@gmail.com', '67312XXX12'); 3 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1002, 'Arnav Rajput', 'N-19, Sector 17, Mumbai', 'arnavxxx@gmail.com', '54312XXX12'); 4 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1003, 'Rushika Rajput', 'O-10, Sector 11, New Delhi', 'rushikaxxx@gmail.com', '99232XXX12'); 5 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1004, 'Adesh Rajput', 'P-14, Sector 10, Greater Noida', 'adeshxxx@gmail.com', '99312XXX12'); 6 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1005, 'Vinesh Rajput', 'C-32, Sector 43, Gurugram', 'vineshxxx@gmail.com', '92332XXX12'); 7 | -------------------------------------------------------------------------------- /Chapter04/account-service/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE ACCOUNT (accountId INTEGER, NAME VARCHAR(20), ADDRESS VARCHAR(128), EMAIL VARCHAR(20), MOBILE VARCHAR(10)); -------------------------------------------------------------------------------- /Chapter04/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountControllerIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice; 5 | 6 | import static org.mockito.BDDMockito.given; 7 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 8 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 9 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 10 | 11 | import org.junit.Test; 12 | import org.junit.runner.RunWith; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; 15 | import org.springframework.boot.test.mock.mockito.MockBean; 16 | import org.springframework.test.context.junit4.SpringRunner; 17 | import org.springframework.test.web.servlet.MockMvc; 18 | 19 | import com.dineshonjava.bookshop.accountservice.controller.AccountController; 20 | import com.dineshonjava.bookshop.accountservice.domain.Account; 21 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 22 | 23 | /** 24 | * @author Dinesh.Rajput 25 | * 26 | */ 27 | @RunWith(SpringRunner.class) 28 | @WebMvcTest(controllers = AccountController.class) 29 | public class AccountControllerIntegrationTest { 30 | 31 | @Autowired 32 | private MockMvc mockMvc; 33 | 34 | @MockBean 35 | private AccountRepository accountRepository; 36 | 37 | @Test 38 | public void shouldReturnFullName() throws Exception { 39 | Account rushika = new Account(1003, "Rushika Rajput", "Noida", "9832XXX23", "rushika.raj@mail.com"); 40 | given(accountRepository.findAccountByAccountId(10003)).willReturn(rushika); 41 | mockMvc.perform(get("/account/10003")) 42 | .andExpect(content().json("{\"accountId\":1003,\"name\":\"Rushika Rajput\",\"address\":\"Noida\",\"mobile\":\"9832XXX23\",\"email\":\"rushika.raj@mail.com\"}")) 43 | .andExpect(status().is2xxSuccessful()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Chapter04/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountControllerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice; 5 | 6 | import static org.hamcrest.core.Is.is; 7 | import static org.junit.Assert.assertThat; 8 | import static org.mockito.BDDMockito.given; 9 | import static org.mockito.MockitoAnnotations.initMocks; 10 | 11 | import org.junit.Before; 12 | import org.junit.Test; 13 | import org.mockito.Mock; 14 | 15 | import com.dineshonjava.bookshop.accountservice.controller.AccountController; 16 | import com.dineshonjava.bookshop.accountservice.domain.Account; 17 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 18 | 19 | /** 20 | * @author Dinesh.Rajput 21 | * 22 | */ 23 | public class AccountControllerTest { 24 | 25 | AccountController accountController; 26 | 27 | @Mock 28 | AccountRepository accountRepository; 29 | 30 | @Before 31 | public void setUp() throws Exception { 32 | initMocks(this); 33 | accountController = new AccountController(accountRepository); 34 | } 35 | 36 | @Test 37 | public void findByAccountId (){ 38 | Account account = new Account(1003, "Arnav Rajput", "Noida", "9832XXX23", "arnav.raj@mail.com"); 39 | given(accountRepository.findAccountByAccountId(10003)).willReturn(account); 40 | Account acct = accountController.findByAccountId(10003); 41 | assertThat(acct.getName(), is("Arnav Rajput")); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Chapter04/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountRepositoryIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice; 5 | 6 | import static org.hamcrest.core.Is.is; 7 | import static org.junit.Assert.assertThat; 8 | 9 | import org.junit.After; 10 | import org.junit.Test; 11 | import org.junit.runner.RunWith; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; 14 | import org.springframework.test.context.junit4.SpringRunner; 15 | 16 | import com.dineshonjava.bookshop.accountservice.domain.Account; 17 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 18 | 19 | /** 20 | * @author Dinesh.Rajput 21 | * 22 | */ 23 | 24 | @RunWith(SpringRunner.class) 25 | @DataJpaTest 26 | public class AccountRepositoryIntegrationTest { 27 | 28 | @Autowired 29 | private AccountRepository accountRepository; 30 | 31 | @After 32 | public void tearDown() throws Exception { 33 | accountRepository.deleteAll(); 34 | } 35 | 36 | @Test 37 | public void shouldSaveAndFetchAccount() throws Exception { 38 | Account accountA = new Account(1002, "Arnav Rajput", "Noida", "9431XXX133", "arnav.mail@my.com"); 39 | accountRepository.save(accountA); 40 | Account accountB = accountRepository.findAccountByAccountId(1002); 41 | assertThat(accountB, is(accountA)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Chapter04/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.accountservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class AccountServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter04/book-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter04/book-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter04/book-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter04/book-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter04/book-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | book-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | book-service 12 | book-service project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-data-jpa 40 | 41 | 42 | com.h2database 43 | h2 44 | runtime 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.cloud 57 | spring-cloud-dependencies 58 | ${spring-cloud.version} 59 | pom 60 | import 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /Chapter04/book-service/src/main/java/com/dineshonjava/bookshop/bookservice/BookServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.bookservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class BookServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(BookServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter04/book-service/src/main/java/com/dineshonjava/bookshop/bookservice/controller/BookController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.bookservice.controller; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import com.dineshonjava.bookshop.bookservice.domain.Book; 11 | import com.dineshonjava.bookshop.bookservice.repository.BookRepository; 12 | 13 | /** 14 | * @author Dinesh.Rajput 15 | * 16 | */ 17 | @RestController 18 | public class BookController { 19 | 20 | @Autowired 21 | BookRepository bookRepository; 22 | 23 | @GetMapping(value = "/account") 24 | public Iterable all (){ 25 | return bookRepository.findAll(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Chapter04/book-service/src/main/java/com/dineshonjava/bookshop/bookservice/domain/Book.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.bookservice.domain; 5 | 6 | import java.io.Serializable; 7 | 8 | import javax.persistence.Column; 9 | import javax.persistence.Entity; 10 | import javax.persistence.Id; 11 | import javax.persistence.Table; 12 | 13 | /** 14 | * @author Dinesh.Rajput 15 | * 16 | */ 17 | @Entity 18 | @Table(name="BOOK") 19 | public class Book implements Serializable{ 20 | 21 | /** 22 | * 23 | */ 24 | private static final long serialVersionUID = 1L; 25 | @Column 26 | @Id 27 | String isbn; 28 | @Column 29 | String title; 30 | @Column 31 | String publication; 32 | @Column 33 | String category; 34 | @Column 35 | Double price; 36 | @Column 37 | String author; 38 | public Book() { 39 | super(); 40 | } 41 | public String getIsbn() { 42 | return isbn; 43 | } 44 | public void setIsbn(String isbn) { 45 | this.isbn = isbn; 46 | } 47 | public String getTitle() { 48 | return title; 49 | } 50 | public void setTitle(String title) { 51 | this.title = title; 52 | } 53 | public String getPublication() { 54 | return publication; 55 | } 56 | public void setPublication(String publication) { 57 | this.publication = publication; 58 | } 59 | public String getCategory() { 60 | return category; 61 | } 62 | public void setCategory(String category) { 63 | this.category = category; 64 | } 65 | public Double getPrice() { 66 | return price; 67 | } 68 | public void setPrice(Double price) { 69 | this.price = price; 70 | } 71 | public String getAuthor() { 72 | return author; 73 | } 74 | public void setAuthor(String author) { 75 | this.author = author; 76 | } 77 | @Override 78 | public String toString() { 79 | return "Book [isbn=" + isbn + ", title=" + title + ", publication=" + publication + ", category=" + category 80 | + ", price=" + price + ", author=" + author + "]"; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /Chapter04/book-service/src/main/java/com/dineshonjava/bookshop/bookservice/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.bookservice.repository; 5 | 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | import com.dineshonjava.bookshop.bookservice.domain.Book; 9 | 10 | /** 11 | * @author Dinesh.Rajput 12 | * 13 | */ 14 | public interface BookRepository extends CrudRepository { 15 | 16 | //List findAllbyAuthor(String author); 17 | 18 | //List findAllbycategory(String category); 19 | } 20 | -------------------------------------------------------------------------------- /Chapter04/book-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter04/book-service/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter04/book-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: book-service 4 | 5 | server: 6 | port: 0 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter04/book-service/src/test/java/com/dineshonjava/bookshop/bookservice/BookServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.bookservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BookServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter04/eureka-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter04/eureka-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter04/eureka-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter04/eureka-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter04/eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | eureka-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | eureka-server 12 | eureka-server project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-server 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-dependencies 50 | ${spring-cloud.version} 51 | pom 52 | import 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /Chapter04/eureka-server/src/main/java/com/dineshonjava/bookshop/eurekaserver/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.eurekaserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @EnableEurekaServer 8 | @SpringBootApplication 9 | public class EurekaServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(EurekaServerApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter04/eureka-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter04/eureka-server/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter04/eureka-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | 4 | eureka: 5 | instance: 6 | hostname: localhost 7 | client: 8 | registerWithEureka: false 9 | fetchRegistry: false 10 | serviceUrl: 11 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ -------------------------------------------------------------------------------- /Chapter04/eureka-server/src/test/java/com/dineshonjava/bookshop/eurekaserver/EurekaServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.eurekaserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class EurekaServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter04/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter04/order-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter04/order-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter04/order-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter04/order-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | order-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | order-service 12 | order-service project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-data-jpa 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-openfeign 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-actuator 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-netflix-hystrix 52 | 53 | 54 | org.springframework.cloud 55 | spring-cloud-starter-netflix-hystrix-dashboard 56 | 57 | 58 | com.h2database 59 | h2 60 | runtime 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-starter-test 65 | test 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.springframework.cloud 73 | spring-cloud-dependencies 74 | ${spring-cloud.version} 75 | pom 76 | import 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | org.springframework.boot 85 | spring-boot-maven-plugin 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Chapter04/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.orderservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.openfeign.EnableFeignClients; 7 | 8 | @EnableEurekaClient 9 | @SpringBootApplication 10 | public class OrderServiceApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(OrderServiceApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter04/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.controller; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @RestController 13 | public class OrderController { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter04/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/domain/Order.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.domain; 5 | 6 | import java.io.Serializable; 7 | 8 | import javax.persistence.Column; 9 | import javax.persistence.Entity; 10 | import javax.persistence.Id; 11 | import javax.persistence.Table; 12 | 13 | /** 14 | * @author Dinesh.Rajput 15 | * 16 | */ 17 | @Entity 18 | @Table(name="ORDER") 19 | public class Order implements Serializable{ 20 | 21 | /** 22 | * 23 | */ 24 | private static final long serialVersionUID = 1L; 25 | @Id 26 | @Column 27 | Long orderNumber; 28 | @Column 29 | String orderName; 30 | @Column 31 | Long orderedItem; 32 | @Column 33 | Integer accountId; 34 | 35 | public Order() { 36 | super(); 37 | } 38 | 39 | public Long getOrderNumber() { 40 | return orderNumber; 41 | } 42 | 43 | public void setOrderNumber(Long orderNumber) { 44 | this.orderNumber = orderNumber; 45 | } 46 | 47 | public String getOrderName() { 48 | return orderName; 49 | } 50 | 51 | public void setOrderName(String orderName) { 52 | this.orderName = orderName; 53 | } 54 | 55 | public Long getOrderedItem() { 56 | return orderedItem; 57 | } 58 | 59 | public void setOrderedItem(Long orderedItem) { 60 | this.orderedItem = orderedItem; 61 | } 62 | 63 | public Integer getAccountId() { 64 | return accountId; 65 | } 66 | 67 | public void setAccountId(Integer accountId) { 68 | this.accountId = accountId; 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return "Order [orderNumber=" + orderNumber + ", orderName=" + orderName + ", orderedItem=" + orderedItem 74 | + ", accountId=" + accountId + "]"; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /Chapter04/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.repository; 5 | 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | import com.dineshonjava.bookshop.orderservice.domain.Order; 9 | 10 | /** 11 | * @author Dinesh.Rajput 12 | * 13 | */ 14 | public interface OrderRepository extends CrudRepository { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter04/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/service/AccountService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.service; 5 | 6 | /** 7 | * @author Dinesh.Rajput 8 | * 9 | */ 10 | //@FeignClient("account-service") 11 | public interface AccountService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter04/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/service/BookService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.service; 5 | 6 | /** 7 | * @author Dinesh.Rajput 8 | * 9 | */ 10 | //@FeignClient("book-service") 11 | public interface BookService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter04/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter04/order-service/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter04/order-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: order-service 4 | 5 | server: 6 | port: 0 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter04/order-service/src/test/java/com/dineshonjava/bookshop/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class OrderServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter04/shipping-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter04/shipping-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter04/shipping-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter04/shipping-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter04/shipping-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | shipping-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | shipping-service 12 | shipping-service project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-data-jpa 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-openfeign 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-actuator 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-netflix-hystrix 52 | 53 | 54 | org.springframework.cloud 55 | spring-cloud-starter-netflix-hystrix-dashboard 56 | 57 | 58 | com.h2database 59 | h2 60 | runtime 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-starter-test 65 | test 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.springframework.cloud 73 | spring-cloud-dependencies 74 | ${spring-cloud.version} 75 | pom 76 | import 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | org.springframework.boot 85 | spring-boot-maven-plugin 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Chapter04/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/ShippingServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shippingservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @EnableEurekaClient 8 | @SpringBootApplication 9 | public class ShippingServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ShippingServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter04/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/controller/ShippingController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shippingservice.controller; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @RestController 13 | public class ShippingController { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter04/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/domain/Shipping.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shippingservice.domain; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.Id; 12 | import javax.persistence.Table; 13 | 14 | /** 15 | * @author Dinesh.Rajput 16 | * 17 | */ 18 | @Entity 19 | @Table(name="SHIPPING") 20 | public class Shipping implements Serializable{ 21 | 22 | /** 23 | * 24 | */ 25 | private static final long serialVersionUID = 1L; 26 | @Id 27 | @Column 28 | Long shippingId; 29 | @Column 30 | Date shippingDate; 31 | @Column 32 | Long orderId; 33 | @Column 34 | String courrior; 35 | public Shipping() { 36 | super(); 37 | } 38 | public Long getShippingId() { 39 | return shippingId; 40 | } 41 | public void setShippingId(Long shippingId) { 42 | this.shippingId = shippingId; 43 | } 44 | public Date getShippingDate() { 45 | return shippingDate; 46 | } 47 | public void setShippingDate(Date shippingDate) { 48 | this.shippingDate = shippingDate; 49 | } 50 | public Long getOrderId() { 51 | return orderId; 52 | } 53 | public void setOrderId(Long orderId) { 54 | this.orderId = orderId; 55 | } 56 | public String getCourrior() { 57 | return courrior; 58 | } 59 | public void setCourrior(String courrior) { 60 | this.courrior = courrior; 61 | } 62 | @Override 63 | public String toString() { 64 | return "Shipping [shippingId=" + shippingId + ", shippingDate=" + shippingDate + ", orderId=" + orderId 65 | + ", courrior=" + courrior + "]"; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /Chapter04/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/repository/ShippingRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shippingservice.repository; 5 | 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | import com.dineshonjava.bookshop.shippingservice.domain.Shipping; 9 | 10 | /** 11 | * @author Dinesh.Rajput 12 | * 13 | */ 14 | public interface ShippingRepository extends CrudRepository { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter04/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/service/OrderService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shippingservice.service; 5 | 6 | /** 7 | * @author Dinesh.Rajput 8 | * 9 | */ 10 | //@FeignClient("order-service") 11 | public interface OrderService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter04/shipping-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter04/shipping-service/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter04/shipping-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: shipping-service 4 | 5 | server: 6 | port: 0 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter04/shipping-service/src/test/java/com/dineshonjava/bookshop/shippingservice/ShippingServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shippingservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShippingServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter04/shopfront-ui/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | shopfront-ui 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | shopfront-ui 12 | shopfront-ui project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-thymeleaf 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-netflix-eureka-client 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-openfeign 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-actuator 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-netflix-hystrix 52 | 53 | 54 | org.springframework.cloud 55 | spring-cloud-starter-netflix-hystrix-dashboard 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-starter-test 60 | test 61 | 62 | 63 | 64 | 65 | 66 | 67 | org.springframework.cloud 68 | spring-cloud-dependencies 69 | ${spring-cloud.version} 70 | pom 71 | import 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | org.springframework.boot 80 | spring-boot-maven-plugin 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/ShopfrontUiApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shopfrontui; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @EnableEurekaClient 8 | @SpringBootApplication 9 | public class ShopfrontUiApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ShopfrontUiApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/controller/BookShopController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.controller; 5 | 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | 9 | /** 10 | * @author Dinesh.Rajput 11 | * 12 | */ 13 | @Controller 14 | public class BookShopController { 15 | 16 | @GetMapping("/") 17 | public String home() { 18 | return "home"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/dto/Account.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shopfrontui.dto; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author Dinesh.Rajput 7 | * 8 | */ 9 | public class Account implements Serializable{ 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = 1L; 14 | Integer accountId; 15 | String name; 16 | String address; 17 | String mobile; 18 | String email; 19 | 20 | public Account() { 21 | super(); 22 | } 23 | 24 | public Integer getAccountId() { 25 | return accountId; 26 | } 27 | 28 | public void setAccountId(Integer accountId) { 29 | this.accountId = accountId; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public String getAddress() { 41 | return address; 42 | } 43 | 44 | public void setAddress(String address) { 45 | this.address = address; 46 | } 47 | 48 | public String getMobile() { 49 | return mobile; 50 | } 51 | 52 | public void setMobile(String mobile) { 53 | this.mobile = mobile; 54 | } 55 | 56 | public String getEmail() { 57 | return email; 58 | } 59 | 60 | public void setEmail(String email) { 61 | this.email = email; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "Account [accountId=" + accountId + ", name=" + name + ", address=" + address + ", mobile=" + mobile 67 | + ", email=" + email + "]"; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/dto/Book.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.dto; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | public class Book implements Serializable{ 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = 1L; 18 | String isbn; 19 | String title; 20 | String publication; 21 | String category; 22 | Double price; 23 | String author; 24 | public Book() { 25 | super(); 26 | } 27 | public String getIsbn() { 28 | return isbn; 29 | } 30 | public void setIsbn(String isbn) { 31 | this.isbn = isbn; 32 | } 33 | public String getTitle() { 34 | return title; 35 | } 36 | public void setTitle(String title) { 37 | this.title = title; 38 | } 39 | public String getPublication() { 40 | return publication; 41 | } 42 | public void setPublication(String publication) { 43 | this.publication = publication; 44 | } 45 | public String getCategory() { 46 | return category; 47 | } 48 | public void setCategory(String category) { 49 | this.category = category; 50 | } 51 | public Double getPrice() { 52 | return price; 53 | } 54 | public void setPrice(Double price) { 55 | this.price = price; 56 | } 57 | public String getAuthor() { 58 | return author; 59 | } 60 | public void setAuthor(String author) { 61 | this.author = author; 62 | } 63 | @Override 64 | public String toString() { 65 | return "Book [isbn=" + isbn + ", title=" + title + ", publication=" + publication + ", category=" + category 66 | + ", price=" + price + ", author=" + author + "]"; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/dto/Order.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.dto; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | public class Order implements Serializable{ 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = 1L; 18 | Long orderNumber; 19 | String orderName; 20 | Long orderedItem; 21 | Integer accountId; 22 | 23 | public Order() { 24 | super(); 25 | } 26 | 27 | public Long getOrderNumber() { 28 | return orderNumber; 29 | } 30 | 31 | public void setOrderNumber(Long orderNumber) { 32 | this.orderNumber = orderNumber; 33 | } 34 | 35 | public String getOrderName() { 36 | return orderName; 37 | } 38 | 39 | public void setOrderName(String orderName) { 40 | this.orderName = orderName; 41 | } 42 | 43 | public Long getOrderedItem() { 44 | return orderedItem; 45 | } 46 | 47 | public void setOrderedItem(Long orderedItem) { 48 | this.orderedItem = orderedItem; 49 | } 50 | 51 | public Integer getAccountId() { 52 | return accountId; 53 | } 54 | 55 | public void setAccountId(Integer accountId) { 56 | this.accountId = accountId; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "Order [orderNumber=" + orderNumber + ", orderName=" + orderName + ", orderedItem=" + orderedItem 62 | + ", accountId=" + accountId + "]"; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/dto/Shipping.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.dto; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | /** 10 | * @author Dinesh.Rajput 11 | * 12 | */ 13 | public class Shipping implements Serializable{ 14 | 15 | /** 16 | * 17 | */ 18 | private static final long serialVersionUID = 1L; 19 | Long shippingId; 20 | Date shippingDate; 21 | Long orderId; 22 | String courrior; 23 | public Shipping() { 24 | super(); 25 | } 26 | public Long getShippingId() { 27 | return shippingId; 28 | } 29 | public void setShippingId(Long shippingId) { 30 | this.shippingId = shippingId; 31 | } 32 | public Date getShippingDate() { 33 | return shippingDate; 34 | } 35 | public void setShippingDate(Date shippingDate) { 36 | this.shippingDate = shippingDate; 37 | } 38 | public Long getOrderId() { 39 | return orderId; 40 | } 41 | public void setOrderId(Long orderId) { 42 | this.orderId = orderId; 43 | } 44 | public String getCourrior() { 45 | return courrior; 46 | } 47 | public void setCourrior(String courrior) { 48 | this.courrior = courrior; 49 | } 50 | @Override 51 | public String toString() { 52 | return "Shipping [shippingId=" + shippingId + ", shippingDate=" + shippingDate + ", orderId=" + orderId 53 | + ", courrior=" + courrior + "]"; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/service/AccountService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.service; 5 | 6 | import org.springframework.cloud.openfeign.FeignClient; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @FeignClient("account-service") 13 | public interface AccountService { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/service/BookService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.service; 5 | 6 | import org.springframework.cloud.openfeign.FeignClient; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @FeignClient("book-service") 13 | public interface BookService { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/service/OrderService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.service; 5 | 6 | import org.springframework.cloud.openfeign.FeignClient; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @FeignClient("order-service") 13 | public interface OrderService { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | management.endpoint.health.enabled=true 2 | management.endpoints.jmx.exposure.include=* 3 | management.endpoints.web.exposure.include=* 4 | management.endpoints.web.base-path=/ 5 | management.endpoints.web.cors.allowed-origins=true 6 | management.endpoint.health.show-details=always -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: shopfront-ui 4 | 5 | server: 6 | port: 8181 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Account Management Page | Dineshonjava.com 5 | 6 | 7 |

All Accounts

8 |

Open Account

9 | 10 | -------------------------------------------------------------------------------- /Chapter04/shopfront-ui/src/test/java/com/dineshonjava/bookshop/shopfrontui/ShopfrontUiApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shopfrontui; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShopfrontUiApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter05/account-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter05/account-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter05/account-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter05/account-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter05/account-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | account-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | account-service 12 | account-service project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-data-jpa 40 | 41 | 42 | com.h2database 43 | h2 44 | runtime 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.cloud 57 | spring-cloud-dependencies 58 | ${spring-cloud.version} 59 | pom 60 | import 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /Chapter05/account-service/src/main/java/com/dineshonjava/bookshop/accountservice/AccountServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.accountservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @EnableEurekaClient 8 | @SpringBootApplication 9 | public class AccountServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AccountServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter05/account-service/src/main/java/com/dineshonjava/bookshop/accountservice/controller/AccountController.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.accountservice.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.DeleteMapping; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.PutMapping; 9 | import org.springframework.web.bind.annotation.RequestBody; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import com.dineshonjava.bookshop.accountservice.domain.Account; 13 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 14 | 15 | /** 16 | * @author Dinesh.Rajput 17 | * 18 | */ 19 | @RestController 20 | public class AccountController { 21 | 22 | @Autowired 23 | AccountRepository accountRepository; 24 | 25 | public AccountController(AccountRepository accountRepository) { 26 | super(); 27 | this.accountRepository = accountRepository; 28 | } 29 | 30 | @PostMapping(value = "/account") 31 | public Account save (@RequestBody Account account){ 32 | return accountRepository.save(account); 33 | } 34 | 35 | @GetMapping(value = "/account") 36 | public Iterable all (){ 37 | return accountRepository.findAll(); 38 | } 39 | 40 | @GetMapping(value = "/account/{accountId}") 41 | public Account findByAccountId (@PathVariable Integer accountId){ 42 | return accountRepository.findAccountByAccountId(accountId); 43 | } 44 | 45 | @PutMapping(value = "/account") 46 | public Account update (@RequestBody Account account){ 47 | return accountRepository.save(account); 48 | } 49 | 50 | @DeleteMapping(value = "/account") 51 | public void delete (@RequestBody Account account){ 52 | accountRepository.delete(account); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Chapter05/account-service/src/main/java/com/dineshonjava/bookshop/accountservice/repository/AccountRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice.repository; 5 | 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | import com.dineshonjava.bookshop.accountservice.domain.Account; 9 | 10 | /** 11 | * @author Dinesh.Rajput 12 | * 13 | */ 14 | public interface AccountRepository extends CrudRepository{ 15 | 16 | Account findAccountByAccountId(Integer accountId); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter05/account-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter05/account-service/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter05/account-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: account-service 4 | 5 | server: 6 | port: 1111 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter05/account-service/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1000, 'Dinesh Rajput', 'K-12, Sector 13, Noida', 'dineshxxx@gmail.com', '99312XXX12'); 2 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1001, 'Anamika Rajput', 'M-15, Sector 15, Noida', 'anamikaxxx@gmail.com', '67312XXX12'); 3 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1002, 'Arnav Rajput', 'N-19, Sector 17, Mumbai', 'arnavxxx@gmail.com', '54312XXX12'); 4 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1003, 'Rushika Rajput', 'O-10, Sector 11, New Delhi', 'rushikaxxx@gmail.com', '99232XXX12'); 5 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1004, 'Adesh Rajput', 'P-14, Sector 10, Greater Noida', 'adeshxxx@gmail.com', '99312XXX12'); 6 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1005, 'Vinesh Rajput', 'C-32, Sector 43, Gurugram', 'vineshxxx@gmail.com', '92332XXX12'); 7 | -------------------------------------------------------------------------------- /Chapter05/account-service/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE ACCOUNT (accountId INTEGER, NAME VARCHAR(20), ADDRESS VARCHAR(128), EMAIL VARCHAR(20), MOBILE VARCHAR(10)); -------------------------------------------------------------------------------- /Chapter05/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountControllerIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice; 5 | 6 | import static org.mockito.BDDMockito.given; 7 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 8 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 9 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 10 | 11 | import org.junit.Test; 12 | import org.junit.runner.RunWith; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; 15 | import org.springframework.boot.test.mock.mockito.MockBean; 16 | import org.springframework.test.context.junit4.SpringRunner; 17 | import org.springframework.test.web.servlet.MockMvc; 18 | 19 | import com.dineshonjava.bookshop.accountservice.controller.AccountController; 20 | import com.dineshonjava.bookshop.accountservice.domain.Account; 21 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 22 | 23 | /** 24 | * @author Dinesh.Rajput 25 | * 26 | */ 27 | @RunWith(SpringRunner.class) 28 | @WebMvcTest(controllers = AccountController.class) 29 | public class AccountControllerIntegrationTest { 30 | 31 | @Autowired 32 | private MockMvc mockMvc; 33 | 34 | @MockBean 35 | private AccountRepository accountRepository; 36 | 37 | @Test 38 | public void shouldReturnFullName() throws Exception { 39 | Account rushika = new Account(1003, "Rushika Rajput", "Noida", "9832XXX23", "rushika.raj@mail.com"); 40 | given(accountRepository.findAccountByAccountId(10003)).willReturn(rushika); 41 | mockMvc.perform(get("/account/10003")) 42 | .andExpect(content().json("{\"accountId\":1003,\"name\":\"Rushika Rajput\",\"address\":\"Noida\",\"mobile\":\"9832XXX23\",\"email\":\"rushika.raj@mail.com\"}")) 43 | .andExpect(status().is2xxSuccessful()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Chapter05/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountControllerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice; 5 | 6 | import static org.hamcrest.core.Is.is; 7 | import static org.junit.Assert.assertThat; 8 | import static org.mockito.BDDMockito.given; 9 | import static org.mockito.MockitoAnnotations.initMocks; 10 | 11 | import org.junit.Before; 12 | import org.junit.Test; 13 | import org.mockito.Mock; 14 | 15 | import com.dineshonjava.bookshop.accountservice.controller.AccountController; 16 | import com.dineshonjava.bookshop.accountservice.domain.Account; 17 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 18 | 19 | /** 20 | * @author Dinesh.Rajput 21 | * 22 | */ 23 | public class AccountControllerTest { 24 | 25 | AccountController accountController; 26 | 27 | @Mock 28 | AccountRepository accountRepository; 29 | 30 | @Before 31 | public void setUp() throws Exception { 32 | initMocks(this); 33 | accountController = new AccountController(accountRepository); 34 | } 35 | 36 | @Test 37 | public void findByAccountId (){ 38 | Account account = new Account(1003, "Arnav Rajput", "Noida", "9832XXX23", "arnav.raj@mail.com"); 39 | given(accountRepository.findAccountByAccountId(10003)).willReturn(account); 40 | Account acct = accountController.findByAccountId(10003); 41 | assertThat(acct.getName(), is("Arnav Rajput")); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Chapter05/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountRepositoryIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice; 5 | 6 | import static org.hamcrest.core.Is.is; 7 | import static org.junit.Assert.assertThat; 8 | 9 | import org.junit.After; 10 | import org.junit.Test; 11 | import org.junit.runner.RunWith; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; 14 | import org.springframework.test.context.junit4.SpringRunner; 15 | 16 | import com.dineshonjava.bookshop.accountservice.domain.Account; 17 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 18 | 19 | /** 20 | * @author Dinesh.Rajput 21 | * 22 | */ 23 | 24 | @RunWith(SpringRunner.class) 25 | @DataJpaTest 26 | public class AccountRepositoryIntegrationTest { 27 | 28 | @Autowired 29 | private AccountRepository accountRepository; 30 | 31 | @After 32 | public void tearDown() throws Exception { 33 | accountRepository.deleteAll(); 34 | } 35 | 36 | @Test 37 | public void shouldSaveAndFetchAccount() throws Exception { 38 | Account accountA = new Account(1002, "Arnav Rajput", "Noida", "9431XXX133", "arnav.mail@my.com"); 39 | accountRepository.save(accountA); 40 | Account accountB = accountRepository.findAccountByAccountId(1002); 41 | assertThat(accountB, is(accountA)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Chapter05/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.accountservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class AccountServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter05/book-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter05/book-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter05/book-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter05/book-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter05/book-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | book-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | book-service 12 | book-service project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-data-jpa 40 | 41 | 42 | com.h2database 43 | h2 44 | runtime 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.cloud 57 | spring-cloud-dependencies 58 | ${spring-cloud.version} 59 | pom 60 | import 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /Chapter05/book-service/src/main/java/com/dineshonjava/bookshop/bookservice/BookServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.bookservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class BookServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(BookServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter05/book-service/src/main/java/com/dineshonjava/bookshop/bookservice/controller/BookController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.bookservice.controller; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import com.dineshonjava.bookshop.bookservice.domain.Book; 11 | import com.dineshonjava.bookshop.bookservice.repository.BookRepository; 12 | 13 | /** 14 | * @author Dinesh.Rajput 15 | * 16 | */ 17 | @RestController 18 | public class BookController { 19 | 20 | @Autowired 21 | BookRepository bookRepository; 22 | 23 | @GetMapping(value = "/account") 24 | public Iterable all (){ 25 | return bookRepository.findAll(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Chapter05/book-service/src/main/java/com/dineshonjava/bookshop/bookservice/domain/Book.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.bookservice.domain; 5 | 6 | import java.io.Serializable; 7 | 8 | import javax.persistence.Column; 9 | import javax.persistence.Entity; 10 | import javax.persistence.Id; 11 | import javax.persistence.Table; 12 | 13 | /** 14 | * @author Dinesh.Rajput 15 | * 16 | */ 17 | @Entity 18 | @Table(name="BOOK") 19 | public class Book implements Serializable{ 20 | 21 | /** 22 | * 23 | */ 24 | private static final long serialVersionUID = 1L; 25 | @Column 26 | @Id 27 | String isbn; 28 | @Column 29 | String title; 30 | @Column 31 | String publication; 32 | @Column 33 | String category; 34 | @Column 35 | Double price; 36 | @Column 37 | String author; 38 | public Book() { 39 | super(); 40 | } 41 | public String getIsbn() { 42 | return isbn; 43 | } 44 | public void setIsbn(String isbn) { 45 | this.isbn = isbn; 46 | } 47 | public String getTitle() { 48 | return title; 49 | } 50 | public void setTitle(String title) { 51 | this.title = title; 52 | } 53 | public String getPublication() { 54 | return publication; 55 | } 56 | public void setPublication(String publication) { 57 | this.publication = publication; 58 | } 59 | public String getCategory() { 60 | return category; 61 | } 62 | public void setCategory(String category) { 63 | this.category = category; 64 | } 65 | public Double getPrice() { 66 | return price; 67 | } 68 | public void setPrice(Double price) { 69 | this.price = price; 70 | } 71 | public String getAuthor() { 72 | return author; 73 | } 74 | public void setAuthor(String author) { 75 | this.author = author; 76 | } 77 | @Override 78 | public String toString() { 79 | return "Book [isbn=" + isbn + ", title=" + title + ", publication=" + publication + ", category=" + category 80 | + ", price=" + price + ", author=" + author + "]"; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /Chapter05/book-service/src/main/java/com/dineshonjava/bookshop/bookservice/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.bookservice.repository; 5 | 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | import com.dineshonjava.bookshop.bookservice.domain.Book; 9 | 10 | /** 11 | * @author Dinesh.Rajput 12 | * 13 | */ 14 | public interface BookRepository extends CrudRepository { 15 | 16 | //List findAllbyAuthor(String author); 17 | 18 | //List findAllbycategory(String category); 19 | } 20 | -------------------------------------------------------------------------------- /Chapter05/book-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter05/book-service/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter05/book-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: book-service 4 | 5 | server: 6 | port: 0 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter05/book-service/src/test/java/com/dineshonjava/bookshop/bookservice/BookServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.bookservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BookServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter05/eureka-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter05/eureka-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter05/eureka-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter05/eureka-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter05/eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | eureka-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | eureka-server 12 | eureka-server project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-server 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-dependencies 50 | ${spring-cloud.version} 51 | pom 52 | import 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /Chapter05/eureka-server/src/main/java/com/dineshonjava/bookshop/eurekaserver/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.eurekaserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @EnableEurekaServer 8 | @SpringBootApplication 9 | public class EurekaServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(EurekaServerApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter05/eureka-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter05/eureka-server/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter05/eureka-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | 4 | eureka: 5 | instance: 6 | hostname: localhost 7 | client: 8 | registerWithEureka: false 9 | fetchRegistry: false 10 | serviceUrl: 11 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ -------------------------------------------------------------------------------- /Chapter05/eureka-server/src/test/java/com/dineshonjava/bookshop/eurekaserver/EurekaServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.eurekaserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class EurekaServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter05/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter05/order-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter05/order-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter05/order-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter05/order-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | order-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | order-service 12 | order-service project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-data-jpa 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-openfeign 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-actuator 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-netflix-hystrix 52 | 53 | 54 | org.springframework.cloud 55 | spring-cloud-starter-netflix-hystrix-dashboard 56 | 57 | 58 | com.h2database 59 | h2 60 | runtime 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-starter-test 65 | test 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.springframework.cloud 73 | spring-cloud-dependencies 74 | ${spring-cloud.version} 75 | pom 76 | import 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | org.springframework.boot 85 | spring-boot-maven-plugin 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Chapter05/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.orderservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.openfeign.EnableFeignClients; 7 | 8 | @EnableEurekaClient 9 | @SpringBootApplication 10 | public class OrderServiceApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(OrderServiceApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter05/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.controller; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @RestController 13 | public class OrderController { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter05/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/domain/Order.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.domain; 5 | 6 | import java.io.Serializable; 7 | 8 | import javax.persistence.Column; 9 | import javax.persistence.Entity; 10 | import javax.persistence.Id; 11 | import javax.persistence.Table; 12 | 13 | /** 14 | * @author Dinesh.Rajput 15 | * 16 | */ 17 | @Entity 18 | @Table(name="ORDER") 19 | public class Order implements Serializable{ 20 | 21 | /** 22 | * 23 | */ 24 | private static final long serialVersionUID = 1L; 25 | @Id 26 | @Column 27 | Long orderNumber; 28 | @Column 29 | String orderName; 30 | @Column 31 | Long orderedItem; 32 | @Column 33 | Integer accountId; 34 | 35 | public Order() { 36 | super(); 37 | } 38 | 39 | public Long getOrderNumber() { 40 | return orderNumber; 41 | } 42 | 43 | public void setOrderNumber(Long orderNumber) { 44 | this.orderNumber = orderNumber; 45 | } 46 | 47 | public String getOrderName() { 48 | return orderName; 49 | } 50 | 51 | public void setOrderName(String orderName) { 52 | this.orderName = orderName; 53 | } 54 | 55 | public Long getOrderedItem() { 56 | return orderedItem; 57 | } 58 | 59 | public void setOrderedItem(Long orderedItem) { 60 | this.orderedItem = orderedItem; 61 | } 62 | 63 | public Integer getAccountId() { 64 | return accountId; 65 | } 66 | 67 | public void setAccountId(Integer accountId) { 68 | this.accountId = accountId; 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return "Order [orderNumber=" + orderNumber + ", orderName=" + orderName + ", orderedItem=" + orderedItem 74 | + ", accountId=" + accountId + "]"; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /Chapter05/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.repository; 5 | 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | import com.dineshonjava.bookshop.orderservice.domain.Order; 9 | 10 | /** 11 | * @author Dinesh.Rajput 12 | * 13 | */ 14 | public interface OrderRepository extends CrudRepository { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter05/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/service/AccountService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.service; 5 | 6 | /** 7 | * @author Dinesh.Rajput 8 | * 9 | */ 10 | //@FeignClient("account-service") 11 | public interface AccountService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter05/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/service/BookService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.service; 5 | 6 | /** 7 | * @author Dinesh.Rajput 8 | * 9 | */ 10 | //@FeignClient("book-service") 11 | public interface BookService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter05/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter05/order-service/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter05/order-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: order-service 4 | 5 | server: 6 | port: 0 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter05/order-service/src/test/java/com/dineshonjava/bookshop/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class OrderServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter05/shipping-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter05/shipping-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter05/shipping-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter05/shipping-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter05/shipping-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | shipping-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | shipping-service 12 | shipping-service project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-data-jpa 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-openfeign 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-actuator 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-netflix-hystrix 52 | 53 | 54 | org.springframework.cloud 55 | spring-cloud-starter-netflix-hystrix-dashboard 56 | 57 | 58 | com.h2database 59 | h2 60 | runtime 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-starter-test 65 | test 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.springframework.cloud 73 | spring-cloud-dependencies 74 | ${spring-cloud.version} 75 | pom 76 | import 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | org.springframework.boot 85 | spring-boot-maven-plugin 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Chapter05/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/ShippingServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shippingservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @EnableEurekaClient 8 | @SpringBootApplication 9 | public class ShippingServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ShippingServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter05/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/controller/ShippingController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shippingservice.controller; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @RestController 13 | public class ShippingController { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter05/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/domain/Shipping.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shippingservice.domain; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.Id; 12 | import javax.persistence.Table; 13 | 14 | /** 15 | * @author Dinesh.Rajput 16 | * 17 | */ 18 | @Entity 19 | @Table(name="SHIPPING") 20 | public class Shipping implements Serializable{ 21 | 22 | /** 23 | * 24 | */ 25 | private static final long serialVersionUID = 1L; 26 | @Id 27 | @Column 28 | Long shippingId; 29 | @Column 30 | Date shippingDate; 31 | @Column 32 | Long orderId; 33 | @Column 34 | String courrior; 35 | public Shipping() { 36 | super(); 37 | } 38 | public Long getShippingId() { 39 | return shippingId; 40 | } 41 | public void setShippingId(Long shippingId) { 42 | this.shippingId = shippingId; 43 | } 44 | public Date getShippingDate() { 45 | return shippingDate; 46 | } 47 | public void setShippingDate(Date shippingDate) { 48 | this.shippingDate = shippingDate; 49 | } 50 | public Long getOrderId() { 51 | return orderId; 52 | } 53 | public void setOrderId(Long orderId) { 54 | this.orderId = orderId; 55 | } 56 | public String getCourrior() { 57 | return courrior; 58 | } 59 | public void setCourrior(String courrior) { 60 | this.courrior = courrior; 61 | } 62 | @Override 63 | public String toString() { 64 | return "Shipping [shippingId=" + shippingId + ", shippingDate=" + shippingDate + ", orderId=" + orderId 65 | + ", courrior=" + courrior + "]"; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /Chapter05/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/repository/ShippingRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shippingservice.repository; 5 | 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | import com.dineshonjava.bookshop.shippingservice.domain.Shipping; 9 | 10 | /** 11 | * @author Dinesh.Rajput 12 | * 13 | */ 14 | public interface ShippingRepository extends CrudRepository { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter05/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/service/OrderService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shippingservice.service; 5 | 6 | /** 7 | * @author Dinesh.Rajput 8 | * 9 | */ 10 | //@FeignClient("order-service") 11 | public interface OrderService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter05/shipping-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter05/shipping-service/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter05/shipping-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: shipping-service 4 | 5 | server: 6 | port: 0 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter05/shipping-service/src/test/java/com/dineshonjava/bookshop/shippingservice/ShippingServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shippingservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShippingServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter05/shopfront-ui/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | shopfront-ui 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | shopfront-ui 12 | shopfront-ui project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-thymeleaf 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-netflix-eureka-client 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-openfeign 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-actuator 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-netflix-hystrix 52 | 53 | 54 | org.springframework.cloud 55 | spring-cloud-starter-netflix-hystrix-dashboard 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-starter-test 60 | test 61 | 62 | 63 | 64 | 65 | 66 | 67 | org.springframework.cloud 68 | spring-cloud-dependencies 69 | ${spring-cloud.version} 70 | pom 71 | import 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | org.springframework.boot 80 | spring-boot-maven-plugin 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/ShopfrontUiApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shopfrontui; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @EnableEurekaClient 8 | @SpringBootApplication 9 | public class ShopfrontUiApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ShopfrontUiApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/controller/BookShopController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.controller; 5 | 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | 9 | /** 10 | * @author Dinesh.Rajput 11 | * 12 | */ 13 | @Controller 14 | public class BookShopController { 15 | 16 | @GetMapping("/") 17 | public String home() { 18 | return "home"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/dto/Account.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shopfrontui.dto; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author Dinesh.Rajput 7 | * 8 | */ 9 | public class Account implements Serializable{ 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = 1L; 14 | Integer accountId; 15 | String name; 16 | String address; 17 | String mobile; 18 | String email; 19 | 20 | public Account() { 21 | super(); 22 | } 23 | 24 | public Integer getAccountId() { 25 | return accountId; 26 | } 27 | 28 | public void setAccountId(Integer accountId) { 29 | this.accountId = accountId; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public String getAddress() { 41 | return address; 42 | } 43 | 44 | public void setAddress(String address) { 45 | this.address = address; 46 | } 47 | 48 | public String getMobile() { 49 | return mobile; 50 | } 51 | 52 | public void setMobile(String mobile) { 53 | this.mobile = mobile; 54 | } 55 | 56 | public String getEmail() { 57 | return email; 58 | } 59 | 60 | public void setEmail(String email) { 61 | this.email = email; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "Account [accountId=" + accountId + ", name=" + name + ", address=" + address + ", mobile=" + mobile 67 | + ", email=" + email + "]"; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/dto/Book.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.dto; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | public class Book implements Serializable{ 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = 1L; 18 | String isbn; 19 | String title; 20 | String publication; 21 | String category; 22 | Double price; 23 | String author; 24 | public Book() { 25 | super(); 26 | } 27 | public String getIsbn() { 28 | return isbn; 29 | } 30 | public void setIsbn(String isbn) { 31 | this.isbn = isbn; 32 | } 33 | public String getTitle() { 34 | return title; 35 | } 36 | public void setTitle(String title) { 37 | this.title = title; 38 | } 39 | public String getPublication() { 40 | return publication; 41 | } 42 | public void setPublication(String publication) { 43 | this.publication = publication; 44 | } 45 | public String getCategory() { 46 | return category; 47 | } 48 | public void setCategory(String category) { 49 | this.category = category; 50 | } 51 | public Double getPrice() { 52 | return price; 53 | } 54 | public void setPrice(Double price) { 55 | this.price = price; 56 | } 57 | public String getAuthor() { 58 | return author; 59 | } 60 | public void setAuthor(String author) { 61 | this.author = author; 62 | } 63 | @Override 64 | public String toString() { 65 | return "Book [isbn=" + isbn + ", title=" + title + ", publication=" + publication + ", category=" + category 66 | + ", price=" + price + ", author=" + author + "]"; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/dto/Order.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.dto; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | public class Order implements Serializable{ 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = 1L; 18 | Long orderNumber; 19 | String orderName; 20 | Long orderedItem; 21 | Integer accountId; 22 | 23 | public Order() { 24 | super(); 25 | } 26 | 27 | public Long getOrderNumber() { 28 | return orderNumber; 29 | } 30 | 31 | public void setOrderNumber(Long orderNumber) { 32 | this.orderNumber = orderNumber; 33 | } 34 | 35 | public String getOrderName() { 36 | return orderName; 37 | } 38 | 39 | public void setOrderName(String orderName) { 40 | this.orderName = orderName; 41 | } 42 | 43 | public Long getOrderedItem() { 44 | return orderedItem; 45 | } 46 | 47 | public void setOrderedItem(Long orderedItem) { 48 | this.orderedItem = orderedItem; 49 | } 50 | 51 | public Integer getAccountId() { 52 | return accountId; 53 | } 54 | 55 | public void setAccountId(Integer accountId) { 56 | this.accountId = accountId; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "Order [orderNumber=" + orderNumber + ", orderName=" + orderName + ", orderedItem=" + orderedItem 62 | + ", accountId=" + accountId + "]"; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/dto/Shipping.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.dto; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | /** 10 | * @author Dinesh.Rajput 11 | * 12 | */ 13 | public class Shipping implements Serializable{ 14 | 15 | /** 16 | * 17 | */ 18 | private static final long serialVersionUID = 1L; 19 | Long shippingId; 20 | Date shippingDate; 21 | Long orderId; 22 | String courrior; 23 | public Shipping() { 24 | super(); 25 | } 26 | public Long getShippingId() { 27 | return shippingId; 28 | } 29 | public void setShippingId(Long shippingId) { 30 | this.shippingId = shippingId; 31 | } 32 | public Date getShippingDate() { 33 | return shippingDate; 34 | } 35 | public void setShippingDate(Date shippingDate) { 36 | this.shippingDate = shippingDate; 37 | } 38 | public Long getOrderId() { 39 | return orderId; 40 | } 41 | public void setOrderId(Long orderId) { 42 | this.orderId = orderId; 43 | } 44 | public String getCourrior() { 45 | return courrior; 46 | } 47 | public void setCourrior(String courrior) { 48 | this.courrior = courrior; 49 | } 50 | @Override 51 | public String toString() { 52 | return "Shipping [shippingId=" + shippingId + ", shippingDate=" + shippingDate + ", orderId=" + orderId 53 | + ", courrior=" + courrior + "]"; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/service/AccountService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.service; 5 | 6 | import org.springframework.cloud.openfeign.FeignClient; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @FeignClient("account-service") 13 | public interface AccountService { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/service/BookService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.service; 5 | 6 | import org.springframework.cloud.openfeign.FeignClient; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @FeignClient("book-service") 13 | public interface BookService { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/service/OrderService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.service; 5 | 6 | import org.springframework.cloud.openfeign.FeignClient; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @FeignClient("order-service") 13 | public interface OrderService { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | management.endpoint.health.enabled=true 2 | management.endpoints.jmx.exposure.include=* 3 | management.endpoints.web.exposure.include=* 4 | management.endpoints.web.base-path=/ 5 | management.endpoints.web.cors.allowed-origins=true 6 | management.endpoint.health.show-details=always -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: shopfront-ui 4 | 5 | server: 6 | port: 8181 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Account Management Page | Dineshonjava.com 5 | 6 | 7 |

All Accounts

8 |

Open Account

9 | 10 | -------------------------------------------------------------------------------- /Chapter05/shopfront-ui/src/test/java/com/dineshonjava/bookshop/shopfrontui/ShopfrontUiApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shopfrontui; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShopfrontUiApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter06/account-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter06/account-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter06/account-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter06/account-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter06/account-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | account-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | account-service 12 | account-service project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-data-jpa 40 | 41 | 42 | com.h2database 43 | h2 44 | runtime 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.cloud 57 | spring-cloud-dependencies 58 | ${spring-cloud.version} 59 | pom 60 | import 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /Chapter06/account-service/src/main/java/com/dineshonjava/bookshop/accountservice/AccountServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.accountservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @EnableEurekaClient 8 | @SpringBootApplication 9 | public class AccountServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AccountServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter06/account-service/src/main/java/com/dineshonjava/bookshop/accountservice/controller/AccountController.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.accountservice.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.DeleteMapping; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.PutMapping; 9 | import org.springframework.web.bind.annotation.RequestBody; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import com.dineshonjava.bookshop.accountservice.domain.Account; 13 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 14 | 15 | /** 16 | * @author Dinesh.Rajput 17 | * 18 | */ 19 | @RestController 20 | public class AccountController { 21 | 22 | @Autowired 23 | AccountRepository accountRepository; 24 | 25 | public AccountController(AccountRepository accountRepository) { 26 | super(); 27 | this.accountRepository = accountRepository; 28 | } 29 | 30 | @PostMapping(value = "/account") 31 | public Account save (@RequestBody Account account){ 32 | return accountRepository.save(account); 33 | } 34 | 35 | @GetMapping(value = "/account") 36 | public Iterable all (){ 37 | return accountRepository.findAll(); 38 | } 39 | 40 | @GetMapping(value = "/account/{accountId}") 41 | public Account findByAccountId (@PathVariable Integer accountId){ 42 | return accountRepository.findAccountByAccountId(accountId); 43 | } 44 | 45 | @PutMapping(value = "/account") 46 | public Account update (@RequestBody Account account){ 47 | return accountRepository.save(account); 48 | } 49 | 50 | @DeleteMapping(value = "/account") 51 | public void delete (@RequestBody Account account){ 52 | accountRepository.delete(account); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Chapter06/account-service/src/main/java/com/dineshonjava/bookshop/accountservice/repository/AccountRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice.repository; 5 | 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | import com.dineshonjava.bookshop.accountservice.domain.Account; 9 | 10 | /** 11 | * @author Dinesh.Rajput 12 | * 13 | */ 14 | public interface AccountRepository extends CrudRepository{ 15 | 16 | Account findAccountByAccountId(Integer accountId); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter06/account-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter06/account-service/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter06/account-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: account-service 4 | 5 | server: 6 | port: 1111 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter06/account-service/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1000, 'Dinesh Rajput', 'K-12, Sector 13, Noida', 'dineshxxx@gmail.com', '99312XXX12'); 2 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1001, 'Anamika Rajput', 'M-15, Sector 15, Noida', 'anamikaxxx@gmail.com', '67312XXX12'); 3 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1002, 'Arnav Rajput', 'N-19, Sector 17, Mumbai', 'arnavxxx@gmail.com', '54312XXX12'); 4 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1003, 'Rushika Rajput', 'O-10, Sector 11, New Delhi', 'rushikaxxx@gmail.com', '99232XXX12'); 5 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1004, 'Adesh Rajput', 'P-14, Sector 10, Greater Noida', 'adeshxxx@gmail.com', '99312XXX12'); 6 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1005, 'Vinesh Rajput', 'C-32, Sector 43, Gurugram', 'vineshxxx@gmail.com', '92332XXX12'); 7 | -------------------------------------------------------------------------------- /Chapter06/account-service/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE ACCOUNT (accountId INTEGER, NAME VARCHAR(20), ADDRESS VARCHAR(128), EMAIL VARCHAR(20), MOBILE VARCHAR(10)); -------------------------------------------------------------------------------- /Chapter06/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountControllerIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice; 5 | 6 | import static org.mockito.BDDMockito.given; 7 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 8 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 9 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 10 | 11 | import org.junit.Test; 12 | import org.junit.runner.RunWith; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; 15 | import org.springframework.boot.test.mock.mockito.MockBean; 16 | import org.springframework.test.context.junit4.SpringRunner; 17 | import org.springframework.test.web.servlet.MockMvc; 18 | 19 | import com.dineshonjava.bookshop.accountservice.controller.AccountController; 20 | import com.dineshonjava.bookshop.accountservice.domain.Account; 21 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 22 | 23 | /** 24 | * @author Dinesh.Rajput 25 | * 26 | */ 27 | @RunWith(SpringRunner.class) 28 | @WebMvcTest(controllers = AccountController.class) 29 | public class AccountControllerIntegrationTest { 30 | 31 | @Autowired 32 | private MockMvc mockMvc; 33 | 34 | @MockBean 35 | private AccountRepository accountRepository; 36 | 37 | @Test 38 | public void shouldReturnFullName() throws Exception { 39 | Account rushika = new Account(1003, "Rushika Rajput", "Noida", "9832XXX23", "rushika.raj@mail.com"); 40 | given(accountRepository.findAccountByAccountId(10003)).willReturn(rushika); 41 | mockMvc.perform(get("/account/10003")) 42 | .andExpect(content().json("{\"accountId\":1003,\"name\":\"Rushika Rajput\",\"address\":\"Noida\",\"mobile\":\"9832XXX23\",\"email\":\"rushika.raj@mail.com\"}")) 43 | .andExpect(status().is2xxSuccessful()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Chapter06/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountControllerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice; 5 | 6 | import static org.hamcrest.core.Is.is; 7 | import static org.junit.Assert.assertThat; 8 | import static org.mockito.BDDMockito.given; 9 | import static org.mockito.MockitoAnnotations.initMocks; 10 | 11 | import org.junit.Before; 12 | import org.junit.Test; 13 | import org.mockito.Mock; 14 | 15 | import com.dineshonjava.bookshop.accountservice.controller.AccountController; 16 | import com.dineshonjava.bookshop.accountservice.domain.Account; 17 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 18 | 19 | /** 20 | * @author Dinesh.Rajput 21 | * 22 | */ 23 | public class AccountControllerTest { 24 | 25 | AccountController accountController; 26 | 27 | @Mock 28 | AccountRepository accountRepository; 29 | 30 | @Before 31 | public void setUp() throws Exception { 32 | initMocks(this); 33 | accountController = new AccountController(accountRepository); 34 | } 35 | 36 | @Test 37 | public void findByAccountId (){ 38 | Account account = new Account(1003, "Arnav Rajput", "Noida", "9832XXX23", "arnav.raj@mail.com"); 39 | given(accountRepository.findAccountByAccountId(10003)).willReturn(account); 40 | Account acct = accountController.findByAccountId(10003); 41 | assertThat(acct.getName(), is("Arnav Rajput")); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Chapter06/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountRepositoryIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice; 5 | 6 | import static org.hamcrest.core.Is.is; 7 | import static org.junit.Assert.assertThat; 8 | 9 | import org.junit.After; 10 | import org.junit.Test; 11 | import org.junit.runner.RunWith; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; 14 | import org.springframework.test.context.junit4.SpringRunner; 15 | 16 | import com.dineshonjava.bookshop.accountservice.domain.Account; 17 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 18 | 19 | /** 20 | * @author Dinesh.Rajput 21 | * 22 | */ 23 | 24 | @RunWith(SpringRunner.class) 25 | @DataJpaTest 26 | public class AccountRepositoryIntegrationTest { 27 | 28 | @Autowired 29 | private AccountRepository accountRepository; 30 | 31 | @After 32 | public void tearDown() throws Exception { 33 | accountRepository.deleteAll(); 34 | } 35 | 36 | @Test 37 | public void shouldSaveAndFetchAccount() throws Exception { 38 | Account accountA = new Account(1002, "Arnav Rajput", "Noida", "9431XXX133", "arnav.mail@my.com"); 39 | accountRepository.save(accountA); 40 | Account accountB = accountRepository.findAccountByAccountId(1002); 41 | assertThat(accountB, is(accountA)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Chapter06/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.accountservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class AccountServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter06/api-zuul-proxy/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter06/api-zuul-proxy/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter06/api-zuul-proxy/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter06/api-zuul-proxy/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter06/api-zuul-proxy/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.example 7 | demo 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | demo 12 | Demo project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.cloud 31 | spring-cloud-starter-netflix-eureka-client 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-zuul 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-dependencies 50 | ${spring-cloud.version} 51 | pom 52 | import 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /Chapter06/api-zuul-proxy/src/main/java/com/dineshonjava/bookshop/apizuulproxy/ApiZuulProxyApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.apizuulproxy; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.client.discovery.EnableDiscoveryClient; 6 | import org.springframework.cloud.netflix.zuul.EnableZuulProxy; 7 | 8 | @EnableZuulProxy 9 | @EnableDiscoveryClient 10 | @SpringBootApplication 11 | public class ApiZuulProxyApplication { 12 | 13 | public static void main(String[] args) { 14 | SpringApplication.run(ApiZuulProxyApplication.class, args); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /Chapter06/api-zuul-proxy/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter06/api-zuul-proxy/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter06/api-zuul-proxy/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: API-GATEWAY 4 | 5 | server: 6 | port: 8080 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | 15 | zuul: 16 | ignoredServices: '*' 17 | prefix: /api 18 | routes: 19 | account-service: 20 | path: /account/** 21 | serviceId: ACCOUNT-SERVICE 22 | book-service: 23 | path: /book/** 24 | serviceId: BOOK-SERVICE 25 | order-service: 26 | path: /order/** 27 | serviceId: ORDER-SERVICE 28 | shipping-service: 29 | path: /shipping/** 30 | serviceId: SHIPPING-SERVICE 31 | host: 32 | socket-timeout-millis: 30000 -------------------------------------------------------------------------------- /Chapter06/api-zuul-proxy/src/test/java/com/dineshonjava/bookshop/apizuulproxy/ApiZuulProxyApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.apizuulproxy; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ApiZuulProxyApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter06/book-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter06/book-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter06/book-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter06/book-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter06/book-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | book-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | book-service 12 | book-service project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-data-jpa 40 | 41 | 42 | com.h2database 43 | h2 44 | runtime 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.cloud 57 | spring-cloud-dependencies 58 | ${spring-cloud.version} 59 | pom 60 | import 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /Chapter06/book-service/src/main/java/com/dineshonjava/bookshop/bookservice/BookServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.bookservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @SpringBootApplication 8 | @EnableEurekaClient 9 | public class BookServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(BookServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter06/book-service/src/main/java/com/dineshonjava/bookshop/bookservice/controller/BookController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.bookservice.controller; 5 | 6 | import org.springframework.beans.factory.annotation.Autowired; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | import org.springframework.web.bind.annotation.RestController; 9 | 10 | import com.dineshonjava.bookshop.bookservice.domain.Book; 11 | import com.dineshonjava.bookshop.bookservice.repository.BookRepository; 12 | 13 | /** 14 | * @author Dinesh.Rajput 15 | * 16 | */ 17 | @RestController 18 | public class BookController { 19 | 20 | @Autowired 21 | BookRepository bookRepository; 22 | 23 | @GetMapping(value = "/account") 24 | public Iterable all (){ 25 | return bookRepository.findAll(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Chapter06/book-service/src/main/java/com/dineshonjava/bookshop/bookservice/domain/Book.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.bookservice.domain; 5 | 6 | import java.io.Serializable; 7 | 8 | import javax.persistence.Column; 9 | import javax.persistence.Entity; 10 | import javax.persistence.Id; 11 | import javax.persistence.Table; 12 | 13 | /** 14 | * @author Dinesh.Rajput 15 | * 16 | */ 17 | @Entity 18 | @Table(name="BOOK") 19 | public class Book implements Serializable{ 20 | 21 | /** 22 | * 23 | */ 24 | private static final long serialVersionUID = 1L; 25 | @Column 26 | @Id 27 | String isbn; 28 | @Column 29 | String title; 30 | @Column 31 | String publication; 32 | @Column 33 | String category; 34 | @Column 35 | Double price; 36 | @Column 37 | String author; 38 | public Book() { 39 | super(); 40 | } 41 | public String getIsbn() { 42 | return isbn; 43 | } 44 | public void setIsbn(String isbn) { 45 | this.isbn = isbn; 46 | } 47 | public String getTitle() { 48 | return title; 49 | } 50 | public void setTitle(String title) { 51 | this.title = title; 52 | } 53 | public String getPublication() { 54 | return publication; 55 | } 56 | public void setPublication(String publication) { 57 | this.publication = publication; 58 | } 59 | public String getCategory() { 60 | return category; 61 | } 62 | public void setCategory(String category) { 63 | this.category = category; 64 | } 65 | public Double getPrice() { 66 | return price; 67 | } 68 | public void setPrice(Double price) { 69 | this.price = price; 70 | } 71 | public String getAuthor() { 72 | return author; 73 | } 74 | public void setAuthor(String author) { 75 | this.author = author; 76 | } 77 | @Override 78 | public String toString() { 79 | return "Book [isbn=" + isbn + ", title=" + title + ", publication=" + publication + ", category=" + category 80 | + ", price=" + price + ", author=" + author + "]"; 81 | } 82 | 83 | } 84 | -------------------------------------------------------------------------------- /Chapter06/book-service/src/main/java/com/dineshonjava/bookshop/bookservice/repository/BookRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.bookservice.repository; 5 | 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | import com.dineshonjava.bookshop.bookservice.domain.Book; 9 | 10 | /** 11 | * @author Dinesh.Rajput 12 | * 13 | */ 14 | public interface BookRepository extends CrudRepository { 15 | 16 | //List findAllbyAuthor(String author); 17 | 18 | //List findAllbycategory(String category); 19 | } 20 | -------------------------------------------------------------------------------- /Chapter06/book-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter06/book-service/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter06/book-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: book-service 4 | 5 | server: 6 | port: 0 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter06/book-service/src/test/java/com/dineshonjava/bookshop/bookservice/BookServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.bookservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class BookServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter06/eureka-server/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter06/eureka-server/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter06/eureka-server/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter06/eureka-server/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter06/eureka-server/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | eureka-server 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | eureka-server 12 | eureka-server project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-server 36 | 37 | 38 | 39 | org.springframework.boot 40 | spring-boot-starter-test 41 | test 42 | 43 | 44 | 45 | 46 | 47 | 48 | org.springframework.cloud 49 | spring-cloud-dependencies 50 | ${spring-cloud.version} 51 | pom 52 | import 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | org.springframework.boot 61 | spring-boot-maven-plugin 62 | 63 | 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /Chapter06/eureka-server/src/main/java/com/dineshonjava/bookshop/eurekaserver/EurekaServerApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.eurekaserver; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer; 6 | 7 | @EnableEurekaServer 8 | @SpringBootApplication 9 | public class EurekaServerApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(EurekaServerApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter06/eureka-server/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter06/eureka-server/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter06/eureka-server/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | server: 2 | port: 8761 3 | 4 | eureka: 5 | instance: 6 | hostname: localhost 7 | client: 8 | registerWithEureka: false 9 | fetchRegistry: false 10 | serviceUrl: 11 | defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/ -------------------------------------------------------------------------------- /Chapter06/eureka-server/src/test/java/com/dineshonjava/bookshop/eurekaserver/EurekaServerApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.eurekaserver; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class EurekaServerApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter06/order-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter06/order-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter06/order-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter06/order-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter06/order-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | order-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | order-service 12 | order-service project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.5.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.SR1 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-data-jpa 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-openfeign 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-actuator 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-netflix-hystrix 52 | 53 | 54 | org.springframework.cloud 55 | spring-cloud-starter-netflix-hystrix-dashboard 56 | 57 | 58 | com.h2database 59 | h2 60 | runtime 61 | 62 | 63 | org.springframework.boot 64 | spring-boot-starter-test 65 | test 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.springframework.cloud 73 | spring-cloud-dependencies 74 | ${spring-cloud.version} 75 | pom 76 | import 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | org.springframework.boot 85 | spring-boot-maven-plugin 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /Chapter06/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/OrderServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.orderservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | import org.springframework.cloud.openfeign.EnableFeignClients; 7 | 8 | @EnableEurekaClient 9 | @SpringBootApplication 10 | public class OrderServiceApplication { 11 | 12 | public static void main(String[] args) { 13 | SpringApplication.run(OrderServiceApplication.class, args); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /Chapter06/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/controller/OrderController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.controller; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @RestController 13 | public class OrderController { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter06/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/domain/Order.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.domain; 5 | 6 | import java.io.Serializable; 7 | 8 | import javax.persistence.Column; 9 | import javax.persistence.Entity; 10 | import javax.persistence.Id; 11 | import javax.persistence.Table; 12 | 13 | /** 14 | * @author Dinesh.Rajput 15 | * 16 | */ 17 | @Entity 18 | @Table(name="ORDER") 19 | public class Order implements Serializable{ 20 | 21 | /** 22 | * 23 | */ 24 | private static final long serialVersionUID = 1L; 25 | @Id 26 | @Column 27 | Long orderNumber; 28 | @Column 29 | String orderName; 30 | @Column 31 | Long orderedItem; 32 | @Column 33 | Integer accountId; 34 | 35 | public Order() { 36 | super(); 37 | } 38 | 39 | public Long getOrderNumber() { 40 | return orderNumber; 41 | } 42 | 43 | public void setOrderNumber(Long orderNumber) { 44 | this.orderNumber = orderNumber; 45 | } 46 | 47 | public String getOrderName() { 48 | return orderName; 49 | } 50 | 51 | public void setOrderName(String orderName) { 52 | this.orderName = orderName; 53 | } 54 | 55 | public Long getOrderedItem() { 56 | return orderedItem; 57 | } 58 | 59 | public void setOrderedItem(Long orderedItem) { 60 | this.orderedItem = orderedItem; 61 | } 62 | 63 | public Integer getAccountId() { 64 | return accountId; 65 | } 66 | 67 | public void setAccountId(Integer accountId) { 68 | this.accountId = accountId; 69 | } 70 | 71 | @Override 72 | public String toString() { 73 | return "Order [orderNumber=" + orderNumber + ", orderName=" + orderName + ", orderedItem=" + orderedItem 74 | + ", accountId=" + accountId + "]"; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /Chapter06/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/repository/OrderRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.repository; 5 | 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | import com.dineshonjava.bookshop.orderservice.domain.Order; 9 | 10 | /** 11 | * @author Dinesh.Rajput 12 | * 13 | */ 14 | public interface OrderRepository extends CrudRepository { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter06/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/service/AccountService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.service; 5 | 6 | /** 7 | * @author Dinesh.Rajput 8 | * 9 | */ 10 | //@FeignClient("account-service") 11 | public interface AccountService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter06/order-service/src/main/java/com/dineshonjava/bookshop/orderservice/service/BookService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.orderservice.service; 5 | 6 | /** 7 | * @author Dinesh.Rajput 8 | * 9 | */ 10 | //@FeignClient("book-service") 11 | public interface BookService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter06/order-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter06/order-service/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter06/order-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: order-service 4 | 5 | server: 6 | port: 0 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter06/order-service/src/test/java/com/dineshonjava/bookshop/orderservice/OrderServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.orderservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class OrderServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter06/shipping-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter06/shipping-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter06/shipping-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter06/shipping-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter06/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/ShippingServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shippingservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @EnableEurekaClient 8 | @SpringBootApplication 9 | public class ShippingServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ShippingServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter06/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/controller/ShippingController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shippingservice.controller; 5 | 6 | import org.springframework.web.bind.annotation.RestController; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @RestController 13 | public class ShippingController { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter06/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/domain/Shipping.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shippingservice.domain; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | import javax.persistence.Column; 10 | import javax.persistence.Entity; 11 | import javax.persistence.Id; 12 | import javax.persistence.Table; 13 | 14 | /** 15 | * @author Dinesh.Rajput 16 | * 17 | */ 18 | @Entity 19 | @Table(name="SHIPPING") 20 | public class Shipping implements Serializable{ 21 | 22 | /** 23 | * 24 | */ 25 | private static final long serialVersionUID = 1L; 26 | @Id 27 | @Column 28 | Long shippingId; 29 | @Column 30 | Date shippingDate; 31 | @Column 32 | Long orderId; 33 | @Column 34 | String courrior; 35 | public Shipping() { 36 | super(); 37 | } 38 | public Long getShippingId() { 39 | return shippingId; 40 | } 41 | public void setShippingId(Long shippingId) { 42 | this.shippingId = shippingId; 43 | } 44 | public Date getShippingDate() { 45 | return shippingDate; 46 | } 47 | public void setShippingDate(Date shippingDate) { 48 | this.shippingDate = shippingDate; 49 | } 50 | public Long getOrderId() { 51 | return orderId; 52 | } 53 | public void setOrderId(Long orderId) { 54 | this.orderId = orderId; 55 | } 56 | public String getCourrior() { 57 | return courrior; 58 | } 59 | public void setCourrior(String courrior) { 60 | this.courrior = courrior; 61 | } 62 | @Override 63 | public String toString() { 64 | return "Shipping [shippingId=" + shippingId + ", shippingDate=" + shippingDate + ", orderId=" + orderId 65 | + ", courrior=" + courrior + "]"; 66 | } 67 | 68 | } 69 | -------------------------------------------------------------------------------- /Chapter06/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/repository/ShippingRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shippingservice.repository; 5 | 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | import com.dineshonjava.bookshop.shippingservice.domain.Shipping; 9 | 10 | /** 11 | * @author Dinesh.Rajput 12 | * 13 | */ 14 | public interface ShippingRepository extends CrudRepository { 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter06/shipping-service/src/main/java/com/dineshonjava/bookshop/shippingservice/service/OrderService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shippingservice.service; 5 | 6 | /** 7 | * @author Dinesh.Rajput 8 | * 9 | */ 10 | //@FeignClient("order-service") 11 | public interface OrderService { 12 | 13 | } 14 | -------------------------------------------------------------------------------- /Chapter06/shipping-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter06/shipping-service/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter06/shipping-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: shipping-service 4 | 5 | server: 6 | port: 0 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter06/shipping-service/src/test/java/com/dineshonjava/bookshop/shippingservice/ShippingServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shippingservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShippingServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter06/shopfront-ui/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | shopfront-ui 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | shopfront-ui 12 | shopfront-ui project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-thymeleaf 32 | 33 | 34 | org.springframework.boot 35 | spring-boot-starter-web 36 | 37 | 38 | org.springframework.cloud 39 | spring-cloud-starter-netflix-eureka-client 40 | 41 | 42 | org.springframework.cloud 43 | spring-cloud-starter-openfeign 44 | 45 | 46 | org.springframework.boot 47 | spring-boot-starter-actuator 48 | 49 | 50 | org.springframework.cloud 51 | spring-cloud-starter-netflix-hystrix 52 | 53 | 54 | org.springframework.cloud 55 | spring-cloud-starter-netflix-hystrix-dashboard 56 | 57 | 58 | org.springframework.boot 59 | spring-boot-starter-test 60 | test 61 | 62 | 63 | 64 | 65 | 66 | 67 | org.springframework.cloud 68 | spring-cloud-dependencies 69 | ${spring-cloud.version} 70 | pom 71 | import 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | org.springframework.boot 80 | spring-boot-maven-plugin 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/ShopfrontUiApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shopfrontui; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @EnableEurekaClient 8 | @SpringBootApplication 9 | public class ShopfrontUiApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(ShopfrontUiApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/controller/BookShopController.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.controller; 5 | 6 | import org.springframework.stereotype.Controller; 7 | import org.springframework.web.bind.annotation.GetMapping; 8 | 9 | /** 10 | * @author Dinesh.Rajput 11 | * 12 | */ 13 | @Controller 14 | public class BookShopController { 15 | 16 | @GetMapping("/") 17 | public String home() { 18 | return "home"; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/dto/Account.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shopfrontui.dto; 2 | 3 | import java.io.Serializable; 4 | 5 | /** 6 | * @author Dinesh.Rajput 7 | * 8 | */ 9 | public class Account implements Serializable{ 10 | /** 11 | * 12 | */ 13 | private static final long serialVersionUID = 1L; 14 | Integer accountId; 15 | String name; 16 | String address; 17 | String mobile; 18 | String email; 19 | 20 | public Account() { 21 | super(); 22 | } 23 | 24 | public Integer getAccountId() { 25 | return accountId; 26 | } 27 | 28 | public void setAccountId(Integer accountId) { 29 | this.accountId = accountId; 30 | } 31 | 32 | public String getName() { 33 | return name; 34 | } 35 | 36 | public void setName(String name) { 37 | this.name = name; 38 | } 39 | 40 | public String getAddress() { 41 | return address; 42 | } 43 | 44 | public void setAddress(String address) { 45 | this.address = address; 46 | } 47 | 48 | public String getMobile() { 49 | return mobile; 50 | } 51 | 52 | public void setMobile(String mobile) { 53 | this.mobile = mobile; 54 | } 55 | 56 | public String getEmail() { 57 | return email; 58 | } 59 | 60 | public void setEmail(String email) { 61 | this.email = email; 62 | } 63 | 64 | @Override 65 | public String toString() { 66 | return "Account [accountId=" + accountId + ", name=" + name + ", address=" + address + ", mobile=" + mobile 67 | + ", email=" + email + "]"; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/dto/Book.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.dto; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | public class Book implements Serializable{ 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = 1L; 18 | String isbn; 19 | String title; 20 | String publication; 21 | String category; 22 | Double price; 23 | String author; 24 | public Book() { 25 | super(); 26 | } 27 | public String getIsbn() { 28 | return isbn; 29 | } 30 | public void setIsbn(String isbn) { 31 | this.isbn = isbn; 32 | } 33 | public String getTitle() { 34 | return title; 35 | } 36 | public void setTitle(String title) { 37 | this.title = title; 38 | } 39 | public String getPublication() { 40 | return publication; 41 | } 42 | public void setPublication(String publication) { 43 | this.publication = publication; 44 | } 45 | public String getCategory() { 46 | return category; 47 | } 48 | public void setCategory(String category) { 49 | this.category = category; 50 | } 51 | public Double getPrice() { 52 | return price; 53 | } 54 | public void setPrice(Double price) { 55 | this.price = price; 56 | } 57 | public String getAuthor() { 58 | return author; 59 | } 60 | public void setAuthor(String author) { 61 | this.author = author; 62 | } 63 | @Override 64 | public String toString() { 65 | return "Book [isbn=" + isbn + ", title=" + title + ", publication=" + publication + ", category=" + category 66 | + ", price=" + price + ", author=" + author + "]"; 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/dto/Order.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.dto; 5 | 6 | import java.io.Serializable; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | public class Order implements Serializable{ 13 | 14 | /** 15 | * 16 | */ 17 | private static final long serialVersionUID = 1L; 18 | Long orderNumber; 19 | String orderName; 20 | Long orderedItem; 21 | Integer accountId; 22 | 23 | public Order() { 24 | super(); 25 | } 26 | 27 | public Long getOrderNumber() { 28 | return orderNumber; 29 | } 30 | 31 | public void setOrderNumber(Long orderNumber) { 32 | this.orderNumber = orderNumber; 33 | } 34 | 35 | public String getOrderName() { 36 | return orderName; 37 | } 38 | 39 | public void setOrderName(String orderName) { 40 | this.orderName = orderName; 41 | } 42 | 43 | public Long getOrderedItem() { 44 | return orderedItem; 45 | } 46 | 47 | public void setOrderedItem(Long orderedItem) { 48 | this.orderedItem = orderedItem; 49 | } 50 | 51 | public Integer getAccountId() { 52 | return accountId; 53 | } 54 | 55 | public void setAccountId(Integer accountId) { 56 | this.accountId = accountId; 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return "Order [orderNumber=" + orderNumber + ", orderName=" + orderName + ", orderedItem=" + orderedItem 62 | + ", accountId=" + accountId + "]"; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/dto/Shipping.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.dto; 5 | 6 | import java.io.Serializable; 7 | import java.util.Date; 8 | 9 | /** 10 | * @author Dinesh.Rajput 11 | * 12 | */ 13 | public class Shipping implements Serializable{ 14 | 15 | /** 16 | * 17 | */ 18 | private static final long serialVersionUID = 1L; 19 | Long shippingId; 20 | Date shippingDate; 21 | Long orderId; 22 | String courrior; 23 | public Shipping() { 24 | super(); 25 | } 26 | public Long getShippingId() { 27 | return shippingId; 28 | } 29 | public void setShippingId(Long shippingId) { 30 | this.shippingId = shippingId; 31 | } 32 | public Date getShippingDate() { 33 | return shippingDate; 34 | } 35 | public void setShippingDate(Date shippingDate) { 36 | this.shippingDate = shippingDate; 37 | } 38 | public Long getOrderId() { 39 | return orderId; 40 | } 41 | public void setOrderId(Long orderId) { 42 | this.orderId = orderId; 43 | } 44 | public String getCourrior() { 45 | return courrior; 46 | } 47 | public void setCourrior(String courrior) { 48 | this.courrior = courrior; 49 | } 50 | @Override 51 | public String toString() { 52 | return "Shipping [shippingId=" + shippingId + ", shippingDate=" + shippingDate + ", orderId=" + orderId 53 | + ", courrior=" + courrior + "]"; 54 | } 55 | 56 | } 57 | -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/service/AccountService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.service; 5 | 6 | import org.springframework.cloud.openfeign.FeignClient; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @FeignClient("account-service") 13 | public interface AccountService { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/service/BookService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.service; 5 | 6 | import org.springframework.cloud.openfeign.FeignClient; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @FeignClient("book-service") 13 | public interface BookService { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/src/main/java/com/dineshonjava/bookshop/shopfrontui/service/OrderService.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.shopfrontui.service; 5 | 6 | import org.springframework.cloud.openfeign.FeignClient; 7 | 8 | /** 9 | * @author Dinesh.Rajput 10 | * 11 | */ 12 | @FeignClient("order-service") 13 | public interface OrderService { 14 | 15 | } 16 | -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | management.endpoint.health.enabled=true 2 | management.endpoints.jmx.exposure.include=* 3 | management.endpoints.web.exposure.include=* 4 | management.endpoints.web.base-path=/ 5 | management.endpoints.web.cors.allowed-origins=true 6 | management.endpoint.health.show-details=always -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: shopfront-ui 4 | 5 | server: 6 | port: 8181 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/src/main/resources/templates/home.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Account Management Page | Dineshonjava.com 5 | 6 | 7 |

All Accounts

8 |

Open Account

9 | 10 | -------------------------------------------------------------------------------- /Chapter06/shopfront-ui/src/test/java/com/dineshonjava/bookshop/shopfrontui/ShopfrontUiApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.shopfrontui; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class ShopfrontUiApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter07/account-service/.gitignore: -------------------------------------------------------------------------------- 1 | /target/ 2 | !.mvn/wrapper/maven-wrapper.jar 3 | 4 | ### STS ### 5 | .apt_generated 6 | .classpath 7 | .factorypath 8 | .project 9 | .settings 10 | .springBeans 11 | .sts4-cache 12 | 13 | ### IntelliJ IDEA ### 14 | .idea 15 | *.iws 16 | *.iml 17 | *.ipr 18 | 19 | ### NetBeans ### 20 | /nbproject/private/ 21 | /build/ 22 | /nbbuild/ 23 | /dist/ 24 | /nbdist/ 25 | /.nb-gradle/ -------------------------------------------------------------------------------- /Chapter07/account-service/.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter07/account-service/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /Chapter07/account-service/.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo1.maven.org/maven2/org/apache/maven/apache-maven/3.5.3/apache-maven-3.5.3-bin.zip 2 | -------------------------------------------------------------------------------- /Chapter07/account-service/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 4.0.0 5 | 6 | com.doj.bookshop 7 | account-service 8 | 0.0.1-SNAPSHOT 9 | jar 10 | 11 | account-service 12 | account-service project for Spring Boot 13 | 14 | 15 | org.springframework.boot 16 | spring-boot-starter-parent 17 | 2.0.3.RELEASE 18 | 19 | 20 | 21 | 22 | UTF-8 23 | UTF-8 24 | 1.8 25 | Finchley.RELEASE 26 | 27 | 28 | 29 | 30 | org.springframework.boot 31 | spring-boot-starter-web 32 | 33 | 34 | org.springframework.cloud 35 | spring-cloud-starter-netflix-eureka-client 36 | 37 | 38 | org.springframework.boot 39 | spring-boot-starter-data-jpa 40 | 41 | 42 | com.h2database 43 | h2 44 | runtime 45 | 46 | 47 | org.springframework.boot 48 | spring-boot-starter-test 49 | test 50 | 51 | 52 | 53 | 54 | 55 | 56 | org.springframework.cloud 57 | spring-cloud-dependencies 58 | ${spring-cloud.version} 59 | pom 60 | import 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | org.springframework.boot 69 | spring-boot-maven-plugin 70 | 71 | 72 | 73 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /Chapter07/account-service/src/main/java/com/dineshonjava/bookshop/accountservice/AccountServiceApplication.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.accountservice; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; 6 | 7 | @EnableEurekaClient 8 | @SpringBootApplication 9 | public class AccountServiceApplication { 10 | 11 | public static void main(String[] args) { 12 | SpringApplication.run(AccountServiceApplication.class, args); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /Chapter07/account-service/src/main/java/com/dineshonjava/bookshop/accountservice/controller/AccountController.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.accountservice.controller; 2 | 3 | import org.springframework.beans.factory.annotation.Autowired; 4 | import org.springframework.web.bind.annotation.DeleteMapping; 5 | import org.springframework.web.bind.annotation.GetMapping; 6 | import org.springframework.web.bind.annotation.PathVariable; 7 | import org.springframework.web.bind.annotation.PostMapping; 8 | import org.springframework.web.bind.annotation.PutMapping; 9 | import org.springframework.web.bind.annotation.RequestBody; 10 | import org.springframework.web.bind.annotation.RestController; 11 | 12 | import com.dineshonjava.bookshop.accountservice.domain.Account; 13 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 14 | 15 | /** 16 | * @author Dinesh.Rajput 17 | * 18 | */ 19 | @RestController 20 | public class AccountController { 21 | 22 | @Autowired 23 | AccountRepository accountRepository; 24 | 25 | public AccountController(AccountRepository accountRepository) { 26 | super(); 27 | this.accountRepository = accountRepository; 28 | } 29 | 30 | @PostMapping(value = "/account") 31 | public Account save (@RequestBody Account account){ 32 | return accountRepository.save(account); 33 | } 34 | 35 | @GetMapping(value = "/account") 36 | public Iterable all (){ 37 | return accountRepository.findAll(); 38 | } 39 | 40 | @GetMapping(value = "/account/{accountId}") 41 | public Account findByAccountId (@PathVariable Integer accountId){ 42 | return accountRepository.findAccountByAccountId(accountId); 43 | } 44 | 45 | @PutMapping(value = "/account") 46 | public Account update (@RequestBody Account account){ 47 | return accountRepository.save(account); 48 | } 49 | 50 | @DeleteMapping(value = "/account") 51 | public void delete (@RequestBody Account account){ 52 | accountRepository.delete(account); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /Chapter07/account-service/src/main/java/com/dineshonjava/bookshop/accountservice/repository/AccountRepository.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice.repository; 5 | 6 | import org.springframework.data.repository.CrudRepository; 7 | 8 | import com.dineshonjava.bookshop.accountservice.domain.Account; 9 | 10 | /** 11 | * @author Dinesh.Rajput 12 | * 13 | */ 14 | public interface AccountRepository extends CrudRepository{ 15 | 16 | Account findAccountByAccountId(Integer accountId); 17 | } 18 | -------------------------------------------------------------------------------- /Chapter07/account-service/src/main/resources/application.properties: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PacktPublishing/Hands-On-Microservices-Monitoring-and-Testing/45fd8ed56a14caa1a4c2c33d1c236649de681e5f/Chapter07/account-service/src/main/resources/application.properties -------------------------------------------------------------------------------- /Chapter07/account-service/src/main/resources/application.yml: -------------------------------------------------------------------------------- 1 | spring: 2 | application: 3 | name: account-service 4 | 5 | server: 6 | port: 1111 7 | 8 | eureka: 9 | client: 10 | service-url: 11 | default-zone: ${EUREKA_URI:http://localhost:8761/eureka} 12 | instance: 13 | prefer-ip-address: true 14 | -------------------------------------------------------------------------------- /Chapter07/account-service/src/main/resources/data.sql: -------------------------------------------------------------------------------- 1 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1000, 'Dinesh Rajput', 'K-12, Sector 13, Noida', 'dineshxxx@gmail.com', '99312XXX12'); 2 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1001, 'Anamika Rajput', 'M-15, Sector 15, Noida', 'anamikaxxx@gmail.com', '67312XXX12'); 3 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1002, 'Arnav Rajput', 'N-19, Sector 17, Mumbai', 'arnavxxx@gmail.com', '54312XXX12'); 4 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1003, 'Rushika Rajput', 'O-10, Sector 11, New Delhi', 'rushikaxxx@gmail.com', '99232XXX12'); 5 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1004, 'Adesh Rajput', 'P-14, Sector 10, Greater Noida', 'adeshxxx@gmail.com', '99312XXX12'); 6 | INSERT INTO ACCOUNT (accountId, NAME, ADDRESS, EMAIL, MOBILE) values (1005, 'Vinesh Rajput', 'C-32, Sector 43, Gurugram', 'vineshxxx@gmail.com', '92332XXX12'); 7 | -------------------------------------------------------------------------------- /Chapter07/account-service/src/main/resources/schema.sql: -------------------------------------------------------------------------------- 1 | CREATE TABLE ACCOUNT (accountId INTEGER, NAME VARCHAR(20), ADDRESS VARCHAR(128), EMAIL VARCHAR(20), MOBILE VARCHAR(10)); -------------------------------------------------------------------------------- /Chapter07/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountControllerIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice; 5 | 6 | import static org.mockito.BDDMockito.given; 7 | import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; 8 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; 9 | import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; 10 | 11 | import org.junit.Test; 12 | import org.junit.runner.RunWith; 13 | import org.springframework.beans.factory.annotation.Autowired; 14 | import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; 15 | import org.springframework.boot.test.mock.mockito.MockBean; 16 | import org.springframework.test.context.junit4.SpringRunner; 17 | import org.springframework.test.web.servlet.MockMvc; 18 | 19 | import com.dineshonjava.bookshop.accountservice.controller.AccountController; 20 | import com.dineshonjava.bookshop.accountservice.domain.Account; 21 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 22 | 23 | /** 24 | * @author Dinesh.Rajput 25 | * 26 | */ 27 | @RunWith(SpringRunner.class) 28 | @WebMvcTest(controllers = AccountController.class) 29 | public class AccountControllerIntegrationTest { 30 | 31 | @Autowired 32 | private MockMvc mockMvc; 33 | 34 | @MockBean 35 | private AccountRepository accountRepository; 36 | 37 | @Test 38 | public void shouldReturnFullName() throws Exception { 39 | Account rushika = new Account(1003, "Rushika Rajput", "Noida", "9832XXX23", "rushika.raj@mail.com"); 40 | given(accountRepository.findAccountByAccountId(10003)).willReturn(rushika); 41 | mockMvc.perform(get("/account/10003")) 42 | .andExpect(content().json("{\"accountId\":1003,\"name\":\"Rushika Rajput\",\"address\":\"Noida\",\"mobile\":\"9832XXX23\",\"email\":\"rushika.raj@mail.com\"}")) 43 | .andExpect(status().is2xxSuccessful()); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /Chapter07/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountControllerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice; 5 | 6 | import static org.hamcrest.core.Is.is; 7 | import static org.junit.Assert.assertThat; 8 | import static org.mockito.BDDMockito.given; 9 | import static org.mockito.MockitoAnnotations.initMocks; 10 | 11 | import org.junit.Before; 12 | import org.junit.Test; 13 | import org.mockito.Mock; 14 | 15 | import com.dineshonjava.bookshop.accountservice.controller.AccountController; 16 | import com.dineshonjava.bookshop.accountservice.domain.Account; 17 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 18 | 19 | /** 20 | * @author Dinesh.Rajput 21 | * 22 | */ 23 | public class AccountControllerTest { 24 | 25 | AccountController accountController; 26 | 27 | @Mock 28 | AccountRepository accountRepository; 29 | 30 | @Before 31 | public void setUp() throws Exception { 32 | initMocks(this); 33 | accountController = new AccountController(accountRepository); 34 | } 35 | 36 | @Test 37 | public void findByAccountId (){ 38 | Account account = new Account(1003, "Arnav Rajput", "Noida", "9832XXX23", "arnav.raj@mail.com"); 39 | given(accountRepository.findAccountByAccountId(10003)).willReturn(account); 40 | Account acct = accountController.findByAccountId(10003); 41 | assertThat(acct.getName(), is("Arnav Rajput")); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Chapter07/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountRepositoryIntegrationTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.dineshonjava.bookshop.accountservice; 5 | 6 | import static org.hamcrest.core.Is.is; 7 | import static org.junit.Assert.assertThat; 8 | 9 | import org.junit.After; 10 | import org.junit.Test; 11 | import org.junit.runner.RunWith; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; 14 | import org.springframework.test.context.junit4.SpringRunner; 15 | 16 | import com.dineshonjava.bookshop.accountservice.domain.Account; 17 | import com.dineshonjava.bookshop.accountservice.repository.AccountRepository; 18 | 19 | /** 20 | * @author Dinesh.Rajput 21 | * 22 | */ 23 | 24 | @RunWith(SpringRunner.class) 25 | @DataJpaTest 26 | public class AccountRepositoryIntegrationTest { 27 | 28 | @Autowired 29 | private AccountRepository accountRepository; 30 | 31 | @After 32 | public void tearDown() throws Exception { 33 | accountRepository.deleteAll(); 34 | } 35 | 36 | @Test 37 | public void shouldSaveAndFetchAccount() throws Exception { 38 | Account accountA = new Account(1002, "Arnav Rajput", "Noida", "9431XXX133", "arnav.mail@my.com"); 39 | accountRepository.save(accountA); 40 | Account accountB = accountRepository.findAccountByAccountId(1002); 41 | assertThat(accountB, is(accountA)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Chapter07/account-service/src/test/java/com/dineshonjava/bookshop/accountservice/AccountServiceApplicationTests.java: -------------------------------------------------------------------------------- 1 | package com.dineshonjava.bookshop.accountservice; 2 | 3 | import org.junit.Test; 4 | import org.junit.runner.RunWith; 5 | import org.springframework.boot.test.context.SpringBootTest; 6 | import org.springframework.test.context.junit4.SpringRunner; 7 | 8 | @RunWith(SpringRunner.class) 9 | @SpringBootTest 10 | public class AccountServiceApplicationTests { 11 | 12 | @Test 13 | public void contextLoads() { 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /Chapter08/GatlingTest/.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /Chapter08/GatlingTest/.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | GatlingTest 4 | 5 | 6 | 7 | 8 | 9 | org.scala-ide.sdt.core.scalabuilder 10 | 11 | 12 | 13 | 14 | 15 | org.scala-ide.sdt.core.scalanature 16 | org.eclipse.jdt.core.javanature 17 | 18 | 19 | -------------------------------------------------------------------------------- /Chapter08/GatlingTest/.settings/org.eclipse.jdt.core.prefs: -------------------------------------------------------------------------------- 1 | eclipse.preferences.version=1 2 | org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled 3 | org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5 4 | org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve 5 | org.eclipse.jdt.core.compiler.compliance=1.5 6 | org.eclipse.jdt.core.compiler.debug.lineNumber=generate 7 | org.eclipse.jdt.core.compiler.debug.localVariable=generate 8 | org.eclipse.jdt.core.compiler.debug.sourceFile=generate 9 | org.eclipse.jdt.core.compiler.problem.assertIdentifier=error 10 | org.eclipse.jdt.core.compiler.problem.enumIdentifier=error 11 | org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning 12 | org.eclipse.jdt.core.compiler.source=1.5 13 | -------------------------------------------------------------------------------- /Chapter08/GatlingTest/.settings/org.eclipse.m2e.core.prefs: -------------------------------------------------------------------------------- 1 | activeProfiles= 2 | eclipse.preferences.version=1 3 | resolveWorkspaceProjects=true 4 | version=1 5 | -------------------------------------------------------------------------------- /Chapter08/GatlingTest/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | GatlingTest 4 | GatlingTest 5 | 0.0.1-SNAPSHOT 6 | 7 | 8 | 9 | io.gatling.highcharts 10 | gatling-charts-highcharts 11 | 2.3.1 12 | 13 | 14 | -------------------------------------------------------------------------------- /Chapter08/GatlingTest/src/com/doj/test/AccountGatlingSimulation.scala: -------------------------------------------------------------------------------- 1 | /** 2 | * 3 | */ 4 | package com.doj.test 5 | 6 | /** 7 | * @author Dinesh.Rajput 8 | * 9 | */ 10 | class AccountGatlingSimulation extends Simulation{ 11 | val scn = scenario("AddAndFindAccount").repeat(500, "n") { 12 | exec( 13 | http("AddAccount-API") 14 | .post("http://localhost:1111/account") 15 | .header("Content-Type", "application/json") 16 | .body(StringBody("""{"accountId":${n}, "name":"Arnav${n}","email":"arnav${n}@mail.com","mobile":"9334343${n}", 17 | "address": "Noida:${n}"}""")) 18 | .check(status.is(200)) 19 | ).pause(2) 20 | }.repeat(500, "n") { 21 | exec( 22 | http("GetAccount-API") 23 | .get("http://localhost:8090/account/${n}") 24 | .check(status.is(200)) 25 | ) 26 | } 27 | setUp(scn.inject(atOnceUsers(30))).maxDuration(FiniteDuration.apply(5, "minutes")) 28 | } -------------------------------------------------------------------------------- /Chapter08/GatlingTest/target/classes/META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Built-By: Dinesh.Rajput 3 | Build-Jdk: 1.8.0_161 4 | Created-By: Maven Integration for Eclipse 5 | 6 | -------------------------------------------------------------------------------- /Chapter08/GatlingTest/target/classes/META-INF/maven/GatlingTest/GatlingTest/pom.properties: -------------------------------------------------------------------------------- 1 | #Generated by Maven Integration for Eclipse 2 | #Sat Aug 25 06:48:42 IST 2018 3 | version=0.0.1-SNAPSHOT 4 | groupId=GatlingTest 5 | m2e.projectName=GatlingTest 6 | m2e.projectLocation=D\:\\packt-HoM-workspace\\GatlingTest 7 | artifactId=GatlingTest 8 | -------------------------------------------------------------------------------- /Chapter08/GatlingTest/target/classes/META-INF/maven/GatlingTest/GatlingTest/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 4.0.0 3 | GatlingTest 4 | GatlingTest 5 | 0.0.1-SNAPSHOT 6 | 7 | 8 | 9 | io.gatling.highcharts 10 | gatling-charts-highcharts 11 | 2.3.1 12 | 13 | 14 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Packt 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | --------------------------------------------------------------------------------