-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#182: add default json format
- Loading branch information
Showing
4 changed files
with
66 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
56 changes: 56 additions & 0 deletions
56
restservice/src/test/java/org/itevents/integration/ControllerTest.java
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package org.itevents.integration; | ||
|
||
import org.codehaus.jackson.map.ObjectMapper; | ||
import org.itevents.dao.model.Event; | ||
import org.itevents.service.EventService; | ||
import org.itevents.test_utils.BuilderUtil; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | ||
import org.springframework.test.context.web.WebAppConfiguration; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.setup.MockMvcBuilders; | ||
import org.springframework.web.context.WebApplicationContext; | ||
|
||
import javax.inject.Inject; | ||
|
||
import static org.mockito.Mockito.when; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
/** | ||
* Created by ramax on 3/10/16. | ||
*/ | ||
@RunWith(SpringJUnit4ClassRunner.class) | ||
@ContextConfiguration({ "classpath:applicationContext.xml", | ||
"classpath:applicationContextTestAddon.xml", | ||
"classpath:mvc-dispatcher-servlet.xml", | ||
"classpath:spring-security.xml"}) | ||
@WebAppConfiguration | ||
public class ControllerTest { | ||
@Inject | ||
private WebApplicationContext context; | ||
private MockMvc mvc; | ||
@Inject | ||
private EventService eventService; | ||
|
||
@Before | ||
public void setup() { | ||
mvc = MockMvcBuilders.webAppContextSetup(context).build(); | ||
} | ||
|
||
@Test | ||
public void shouldGetJsonFormatEvent() throws Exception { | ||
Event event = BuilderUtil.buildEventJava(); | ||
String expectedEventInJson = new ObjectMapper().writeValueAsString(event); | ||
|
||
when(eventService.getEvent(event.getId())).thenReturn(event); | ||
|
||
mvc.perform(get("/events/" + event.getId())) | ||
.andExpect(content().json(expectedEventInJson)) | ||
.andExpect(status().isOk()); | ||
} | ||
} |