Giter Site home page Giter Site logo

flight-root-tdd's Introduction

[1] ####1. Configurations

inventory-service.yml
server:
  port: 8081
spring:
  application:
    name: flight-inventory
  datasource:
    url: "jdbc:h2:mem:test;MODE=MySQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE;INIT=CREATE SCHEMA IF NOT EXISTS flight"
    username: "sa"
    password:
    driver-class-name: org.h2.Driver
  jpa:
    database-platform: org.hibernate.dialect.H2Dialect
    hibernate:
      ddl-auto: create-drop
    show-sql: true

The other services would follow similar properties.

Curls - Not recommended - only for quick testing

//CURL

  http://localhost:8081/inventory \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
    "id": 1,
    "fromCity": "CGK",
    "toCity": "NYC",
    "availability": true,
    "flightCarrier": "Garuda Airlines"
}'


curl -X GET \
  'http://localhost:8081/inventory?id=1' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache'


curl -X POST \
  http://localhost:8082/booking \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
    "id": 1,
    "userId": 2,
    "bookingDetail" : {
      "code" : 2,
      "fromCity" : "CGK",
      "toCity" : "NYC"
    },
    "quantity": 5
}'  

curl -X GET \
  'http://localhost:8082/booking?id=1' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache'


//Curl Through Edge service
curl -X POST \
  http://localhost:8000/flight-inventory/inventory \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
    "id": 1,
    "fromCity": "CGK",
    "toCity": "NYC",
    "availability": true,
    "flightCarrier": "Garuda Airlines"
}'


curl -X GET \
  'http://localhost:8000/flight-inventory/inventory?id=1' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache'


curl -X POST \
  http://localhost:8000/booking-service/booking \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
    "id": 1,
    "userId": 2,
    "bookingDetail" : {
      "code" : 2,
      "fromCity" : "CGK",
      "toCity" : "NYC"
    },
    "quantity": 5
}'  

curl -X GET \
  'http://localhost:8000/booking-service/booking?id=1' \
  -H 'Accept: application/json' \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' 
Imports Mock MVC
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

mockMvc.perform(
                post("/inventory")
                        .accept(MediaType.APPLICATION_JSON)
                        .contentType(MediaType.APPLICATION_JSON)
                        .content(valueAsString)
        ).andDo(print())
                .andExpect(status().isCreated());

Imports Mock Server
import static org.springframework.test.web.client.match.MockRestRequestMatchers.method;
import static org.springframework.test.web.client.match.MockRestRequestMatchers.requestTo;
import static org.springframework.test.web.client.response.MockRestResponseCreators.withSuccess;

MockRestServiceServer mockRestServiceServer = MockRestServiceServer.createServer(restTemplate);

@Test
public void shouldSaveOrder(){
    mockRestServiceServer.expect(requestTo("http://localhost:8081/inventory"))
            .andExpect(method(HttpMethod.GET))
            .andRespond(withSuccess("true", MediaType.APPLICATION_JSON));

    flightBookingService.createFlightBooking(null);

    mockRestServiceServer.verify();

}

Eureka Properties
  eureka:
  client:
    fetch-registry: false
    register-with-eureka: false

Java 10 Missing JaxB Imports
//in discovery service
 compileOnly('javax.xml.bind:jaxb-api:2.3.0')
 compileOnly('javax.activation:activation:1.1')
 compileOnly('org.glassfish.jaxb:jaxb-runtime:2.3.0')   

flight-root-tdd's People

Contributors

sanjeevblr avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.