use of de.spring.webservices.domain.Car in project JavaForFun by gumartinm.
the class CarControllerIntegrationTest method testWhenCreateNewCarThenRetrieveJsonValue.
@Test
public void testWhenCreateNewCarThenRetrieveJsonValue() throws Exception {
Car car = new Car(null, "nothing");
given(awesomeBusinessLogic.create(car)).willReturn(new Car(1L, String.format(TEMPLATE, 1)));
mockMvc.perform(post("/api/cars/").contentType(MediaType.APPLICATION_JSON_UTF8).content(asJsonString(car)).accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isCreated()).andExpect(jsonPath("id", any(Integer.class))).andExpect(jsonPath("content", is("Car: 1"))).andExpect(header().string(HttpHeaders.LOCATION, "/api/cars/1")).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));
}
use of de.spring.webservices.domain.Car in project JavaForFun by gumartinm.
the class CarControllerIntegrationTest method testWhenGetAllCarsThenRetrieveJsonValues.
@Test
public void testWhenGetAllCarsThenRetrieveJsonValues() throws Exception {
final List<Car> cars = new ArrayList<>();
cars.add(new Car(1L, String.format(TEMPLATE, 1)));
given(awesomeBusinessLogic.findAll(new PageRequest(PAGE, PAGE_SIZE))).willReturn(new PageImpl<>(cars));
mockMvc.perform(get("/api/cars/").accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(status().isOk()).andExpect(jsonPath("$.content[0].id", any(Integer.class))).andExpect(jsonPath("$.content[0].content", is("Car: 1"))).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));
}
use of de.spring.webservices.domain.Car in project JavaForFun by gumartinm.
the class CompletableFutureCarControllerIntegrationTest method testWhenGetAllCarsThenRetrieveJsonValues.
@Test
public void testWhenGetAllCarsThenRetrieveJsonValues() throws Exception {
final List<Car> cars = new ArrayList<>();
cars.add(new Car(1L, String.format(TEMPLATE, 1)));
CompletableFuture<Page<Car>> future = CompletableFuture.supplyAsync(() -> new PageImpl<>(cars));
given(completableFutureBusinessLogic.findAll(new PageRequest(PAGE, PAGE_SIZE))).willReturn(future);
MvcResult result = mockMvc.perform(get("/api/completablefuture/cars/").accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(request().asyncStarted()).andExpect(request().asyncResult(instanceOf(Page.class))).andReturn();
mockMvc.perform(asyncDispatch(result)).andExpect(status().isOk()).andExpect(jsonPath("$.content[0].id", any(Integer.class))).andExpect(jsonPath("$.content[0].id", any(Integer.class))).andExpect(jsonPath("$.content[0].content", is("Car: 1"))).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));
}
use of de.spring.webservices.domain.Car in project JavaForFun by gumartinm.
the class CompletableFutureCarControllerIntegrationTest method testWhenGetOneCarThenRetrieveJsonValue.
@Test
public void testWhenGetOneCarThenRetrieveJsonValue() throws Exception {
CompletableFuture<Car> expected = CompletableFuture.supplyAsync(() -> new Car(1L, String.format(TEMPLATE, 1)));
given(completableFutureBusinessLogic.findById(1L)).willReturn(expected);
MvcResult result = mockMvc.perform(get("/api/completablefuture/cars/{id}", 1L).accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(request().asyncStarted()).andExpect(request().asyncResult(instanceOf(Car.class))).andReturn();
mockMvc.perform(asyncDispatch(result)).andExpect(status().isOk()).andExpect(jsonPath("id", any(Integer.class))).andExpect(jsonPath("content", is("Car: 1"))).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));
}
use of de.spring.webservices.domain.Car in project JavaForFun by gumartinm.
the class RxJavaCarControllerIntegrationTest method testWhenCreateNewCarThenRetrieveJsonValue.
// THIS GUY IS USING MY de.spring.webservices.rest.controller.adapters.RxJavaAdapter AND IT DOES NOT NEED to call onCompleted()
// I DO NOT THINK MY de.spring.webservices.rest.controller.adapters.RxJavaAdapter SHOULD BE USED. YOU'D BETTER USE THE spring netflix IMPLEMENTATION :/
@Test
public void testWhenCreateNewCarThenRetrieveJsonValue() throws Exception {
Car car = new Car(null, "nothing");
Observable<Car> observable = Observable.create(observer -> observer.onNext(new Car(1L, String.format(TEMPLATE, 1))));
given(rxJavaBusinessLogic.createThrowable(car)).willReturn(observable);
MvcResult result = mockMvc.perform(post("/api/rxjava/cars/").contentType(MediaType.APPLICATION_JSON_UTF8).content(asJsonString(car)).accept(MediaType.APPLICATION_JSON_UTF8)).andExpect(request().asyncStarted()).andExpect(request().asyncResult(instanceOf(ResponseEntity.class))).andReturn();
mockMvc.perform(asyncDispatch(result)).andExpect(status().isCreated()).andExpect(jsonPath("id", any(Integer.class))).andExpect(jsonPath("content", is("Car: 1"))).andExpect(header().string(HttpHeaders.LOCATION, "/api/rxjava/cars/1")).andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8));
}
Aggregations