Created
November 17, 2016 02:56
-
-
Save hanrw/431f3ab670fa7efd0137456430426a09 to your computer and use it in GitHub Desktop.
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
import org.junit.Before | |
import org.junit.Test | |
import org.junit.runner.RunWith | |
import org.springframework.http.MediaType | |
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.request.MockMvcRequestBuilders | |
import org.springframework.test.web.servlet.setup.MockMvcBuilders | |
import javax.xml.bind.JAXBContext | |
import javax.xml.bind.Marshaller | |
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 | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@WebAppConfiguration | |
@ContextConfiguration(classes = WebConfig.class) | |
class PlayerControllerTest { | |
private MockMvc mockMvc | |
@Before | |
public void setup() throws Exception { | |
this.mockMvc = MockMvcBuilders.standaloneSetup(new PlayerController()).defaultRequest(get("/")).build() | |
} | |
@Test | |
public void should_return_player_authentication_response() throws Exception { | |
def postData = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns3:playerAuthentication xmlns:ns2="http://williamsinteractive.com/integration/vanilla/api/common" xmlns:ns3="http://williamsinteractive.com/integration/vanilla/api/player"><accountRef>some-accountRef</accountRef><context>some-context</context><gameCode>some-code</gameCode><ticket>some-ticket</ticket></ns3:playerAuthentication>' | |
def exceptedResult = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:playerAuthenticationResponse xmlns:ns2="http://williamsinteractive.com/integration/vanilla/api/player"><balance>0</balance></ns2:playerAuthenticationResponse>' | |
def post = MockMvcRequestBuilders.post("/authenticate") | |
.contentType(MediaType.APPLICATION_XML) | |
.content(postData) | |
mockMvc.perform(post) | |
.andExpect(status().isOk()).andExpect(content().string(exceptedResult)) | |
} | |
@Test | |
public void should_return_balance_response() throws Exception { | |
def postData = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:balance xmlns:ns2="http://williamsinteractive.com/integration/vanilla/api/player"><accountRef>some-accountRef</accountRef><context>some-context</context><currency>some-currency</currency><gameCode>some-code</gameCode><ticket>some-ticket</ticket></ns2:balance>' | |
def exceptedResult = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?><ns2:balanceResponse xmlns:ns2="http://williamsinteractive.com/integration/vanilla/api/player"><balance>0</balance></ns2:balanceResponse>' | |
def post = MockMvcRequestBuilders.post("/getBalance") | |
.contentType(MediaType.APPLICATION_XML) | |
.content(postData) | |
mockMvc.perform(post) | |
.andExpect(status().isOk()).andExpect(content().string(exceptedResult)) | |
} | |
def printXmlForPreparePostData() { | |
JAXBContext jc = JAXBContext.newInstance(Balance.class) | |
Marshaller m = jc.createMarshaller() | |
def balance = new Balance() | |
balance.accountRef = 'some-accountRef' | |
balance.currency = new Currency('some-currency', 0, 0) | |
balance.ticket = 'some-ticket' | |
balance.gameCode = 'some-code' | |
balance.context = 'some-context' | |
m.marshal(balance, System.out) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment