This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--> | |
<meta name="viewport" content="width=device-width, initial-scale=1.0"> | |
<meta name="generator" content="Asciidoctor 1.5.3"> | |
<meta name="author" content="Dennis Espen"> | |
<title>/api/offers Getting Started Guide</title> | |
<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:300,300italic,400,400italic,600,600italic%7CNoto+Serif:400,400italic,700,700italic%7CDroid+Sans+Mono:400,700"> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.espen.tests; | |
import org.junit.Before; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.test.context.SpringBootTest; | |
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | |
import org.springframework.test.context.TestPropertySource; | |
import org.springframework.test.context.junit4.SpringRunner; | |
import org.springframework.test.web.servlet.MockMvc; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testNewOffer() throws Exception { | |
Offer testoffer = new Offer("München", "Bozen", "user1", "2016-10-11T08:50", 100); | |
mockMvc.perform(post("/newoffer").with(user("admin").password("123456seven")) | |
.param("startingPoint", testoffer.getStartingPoint()) | |
.param("destination", testoffer.getDestination()) | |
.param("username", testoffer.getUsername()) | |
.param("date", testoffer.getDate()) | |
.param("price", new Double(testoffer.getPrice()).toString()) | |
.contentType(MediaType.APPLICATION_FORM_URLENCODED)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testLoggingIn() throws Exception { | |
mockMvc.perform(formLogin().user("admin").password("123456seven")).andExpect(authenticated()); | |
} | |
@Test | |
public void testLogginFail() throws Exception { | |
mockMvc.perform(formLogin().user("notExistent").password("asdasdad")).andExpect(unauthenticated()); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testShowOffer() throws Exception { | |
mockMvc.perform(get("/offer/{id}", offer1.getId())).andExpect(status().isOk()).andExpect(view().name("offer")) | |
.andExpect(forwardedUrl("/WEB-INF/tiles/templates/baselayout.jsp")) | |
.andExpect(model().attribute("offer", hasProperty("id", is(offer1.getId())))) | |
.andExpect(model().attribute("offer", hasProperty("startingPoint", is(offer1.getStartingPoint())))) | |
.andExpect(model().attribute("offer", hasProperty("destination", is(offer1.getDestination())))) | |
.andExpect(model().attribute("offer", hasProperty("username", is(offer1.getUsername())))) | |
.andExpect(model().attribute("offer", hasProperty("date", is(offer1.getDate())))); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testOfferCreated() throws Exception { | |
mockMvc.perform(get("/offercreated").with(user("admin").password("123456seven"))).andExpect(status().isOk()) | |
.andExpect(view().name("offercreated")) | |
.andExpect(forwardedUrl("/WEB-INF/tiles/templates/baselayout.jsp")); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
public void testHome() throws Exception { | |
mockMvc.perform(get("/")).andExpect(status().isOk()).andExpect(view().name("home")) | |
.andExpect(forwardedUrl("/WEB-INF/tiles/templates/baselayout.jsp")).andExpect(model().size(1)); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.espen.tests; | |
import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; | |
import org.junit.Before; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.test.context.SpringBootTest; | |
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; | |
import org.springframework.test.context.TestPropertySource; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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); |
NewerOlder