Skip to content

Instantly share code, notes, and snippets.

@espendennis
espendennis / OfferApiTests.java
Created October 18, 2016 13:06
Generating the JSON-String
@Test
public void testPutOffer() throws Exception {
ArrayList<Offer> offers = (ArrayList<Offer>) offersService.findAll();
Offer offerToChange = offers.get(4);
offerToChange.setStartingPoint("München");
offerToChange.setDestination("Frankfurt");
offerToChange.setPrice(100);
offerToChange.setUsername("admin");
offerToChange.setDate("2017-11-11T09:25");
String json = mapper.writeValueAsString(offerToChange);
@espendennis
espendennis / OfferApiTests.java
Created October 18, 2016 13:02
Empty test-body
@Test
public void testGetOffers() throws Exception {
}
@espendennis
espendennis / OfferApiTests.java
Created October 18, 2016 13:01
Empty Test-Body
@Test
public void testGetOffers() throws Exception {
}
@espendennis
espendennis / OfferApiTests.java
Created October 18, 2016 12:12
Complete first test
@Test
public void testGetOffers() throws Exception {
MvcResult result = mockMvc.perform(get("/api/offers")).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)).andExpect(jsonPath("$", hasSize(5)))
.andReturn();
Offer[] offers = mapper.readValue(result.getResponse().getContentAsString(), Offer[].class);
assertEquals(offers[0], offer1);
assertEquals(offers[1], offer2);
assertEquals(offers[2], offer3);
assertEquals(offers[3], offer4);
@espendennis
espendennis / OfferApiTest.java
Created October 18, 2016 11:54
checking the response
Offer[] offers = mapper.readValue(result.getResponse().getContentAsString(), Offer[].class);
assertEquals(offers[0], offer1);
assertEquals(offers[1], offer2);
assertEquals(offers[2], offer3);
assertEquals(offers[3], offer4);
assertEquals(offers[4], offer5);
@espendennis
espendennis / OfferApiTests.java
Created October 18, 2016 11:52
final request
MvcResult result = mockMvc.perform(get("/api/offers")).andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", hasSize(5)))
.andReturn();
@espendennis
espendennis / OfferApiTests.java
Created October 18, 2016 11:48
checking the response
mockMvc.perform(get("/api/offers"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", hasSize(5)));
@espendennis
espendennis / OfferApiTests.java
Created October 18, 2016 11:47
Checking the response
mockMvc.perform(get("/api/offers"))
.andExpect(status().isOk())
andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", hasSize(5)));
@espendennis
espendennis / OfferApiTests.java
Created October 18, 2016 11:47
checking the response
mockMvc.perform(get("/api/offers"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", hasSize(5)));
mockMvc.perform(get("/api/offers"))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8))
.andExpect(jsonPath("$", hasSize(5))).