package org.odroid.server.controllers;
import static org.odroid.server.controllers.ApplicationControllerTest.INVALID_HASH;
import static org.springframework.http.MediaType.APPLICATION_JSON;
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;
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.odroid.server.entities.Application;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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;
@RunWith(SpringJUnit4ClassRunner.class)
@WebAppConfiguration
@ContextConfiguration(locations = { "/root-context-test.xml", "/servlet-context-test.xml" })
public class HTTPApplicationControllerTest {
private Logger l = LoggerFactory.getLogger(getClass());
@Autowired
private ApplicationController ac;
@Test
public void testGetApplicationForHashResponse() throws Exception {
Application a = new Application();
a.setName("Application#1");
a = ac.create(a);
standaloneSetup(ac).build().perform(get("/app/" + a.getHash()).accept(APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(content().string("{\"name\":\"Application#1\",\"hash\":\"" + a.getHash() + "\",\"active\":false,\"id\":1}"));
}
@Test
public void testGetApplicationForInvalidHashResponse() throws Exception {
standaloneSetup(ac).build().perform(get("/app/" + INVALID_HASH).accept(APPLICATION_JSON)).andExpect(status().isOk())
.andExpect(content().string("{\"name\":\"Application#1\",\"hash\":\",\"active\":false,\"id\":1}"));
}
}