Search in sources :

Example 1 with JsonTester

use of com.thoughtworks.go.util.JsonTester in project gocd by gocd.

the class JobStatusJsonPresentationModelTest method shouldShowBuildStatus.

@Test
public void shouldShowBuildStatus() throws Exception {
    JobInstance instance = JobInstanceMother.assigned("test");
    instance.setId(12);
    instance.setAgentUuid("1234");
    final Agents agents = new Agents(new AgentConfig("1234", "localhost", "1234"));
    JobStatusJsonPresentationModel presenter = new JobStatusJsonPresentationModel(instance, agents.getAgentByUuid(instance.getAgentUuid()));
    Map json = presenter.toJsonHash();
    new JsonTester(json).shouldContain("{ 'name' : 'test'," + " 'id' : '12', " + " 'agent' : 'localhost', " + " 'current_status' : 'assigned' " + "}");
}
Also used : AgentConfig(com.thoughtworks.go.config.AgentConfig) JsonTester(com.thoughtworks.go.util.JsonTester) JobInstance(com.thoughtworks.go.domain.JobInstance) Agents(com.thoughtworks.go.config.Agents) Map(java.util.Map) Test(org.junit.Test)

Example 2 with JsonTester

use of com.thoughtworks.go.util.JsonTester in project gocd by gocd.

the class JsonViewTest method testShouldRenderNestedMaps.

@Test
public void testShouldRenderNestedMaps() throws Exception {
    Map<String, Object> map = new LinkedHashMap<>();
    Map<String, Object> nestedMap = new LinkedHashMap<>();
    nestedMap.put("keyA", "valueA");
    map.put("key1", nestedMap);
    JsonView view = new JsonView();
    String json = view.renderJson(map);
    new JsonTester(json).is("{ 'key1' : {" + "    'keyA' : 'valueA'" + "  }" + "}");
}
Also used : JsonTester(com.thoughtworks.go.util.JsonTester) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 3 with JsonTester

use of com.thoughtworks.go.util.JsonTester in project gocd by gocd.

the class JsonViewTest method testShouldReturnOutputWithoutWhitespaceThatIsNotAllowedInHeaders.

@Test
public void testShouldReturnOutputWithoutWhitespaceThatIsNotAllowedInHeaders() throws Exception {
    JsonView view = new JsonView(requestContext);
    MockHttpServletResponse response = new MockHttpServletResponse();
    Map<String, Object> map = new LinkedHashMap<>();
    map.put("key", "\r\t\n");
    view.renderMergedOutputModel(asMap(map), new MockHttpServletRequest(), response);
    String json = response.getContentAsString();
    new JsonTester(json).is("{ 'key' : '\\r\\t\\n' }");
}
Also used : JsonTester(com.thoughtworks.go.util.JsonTester) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 4 with JsonTester

use of com.thoughtworks.go.util.JsonTester in project gocd by gocd.

the class JsonViewTest method testShouldRenderI18n.

@Test
public void testShouldRenderI18n() {
    Map<String, Object> map = new LinkedHashMap<>();
    final String i18nMessage = "waiting(zh_CN)";
    final ResolvableViewableStatus resolvableViewableStatus = new ResolvableViewableStatus(WAITING);
    map.put("key1", resolvableViewableStatus);
    JsonView view = new JsonView(requestContext);
    mockContext.checking(new Expectations() {

        {
            one(requestContext).getMessage(with(equal(resolvableViewableStatus)));
            will(returnValue(i18nMessage));
        }
    });
    String json = view.renderJson(map);
    mockContext.assertIsSatisfied();
    new JsonTester(json).is("{ 'key1' : '" + i18nMessage + "' }");
}
Also used : Expectations(org.jmock.Expectations) JsonTester(com.thoughtworks.go.util.JsonTester) ResolvableViewableStatus(com.thoughtworks.go.server.web.i18n.ResolvableViewableStatus) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 5 with JsonTester

use of com.thoughtworks.go.util.JsonTester in project gocd by gocd.

the class JsonViewTest method testShouldRenderFakeMapsWithoutTheSurroundingMap.

@Test
public void testShouldRenderFakeMapsWithoutTheSurroundingMap() throws Exception {
    List list = new ArrayList();
    Map<String, Object> nestedMap = new LinkedHashMap<>();
    nestedMap.put("key1", "value1");
    list.add(nestedMap);
    list.add("value2");
    JsonView view = new JsonView();
    String json = view.renderJson(asMap(list));
    new JsonTester(json).is("[ { 'key1' : 'value1' }, 'value2' ]");
}
Also used : JsonTester(com.thoughtworks.go.util.JsonTester) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Aggregations

JsonTester (com.thoughtworks.go.util.JsonTester)15 Test (org.junit.Test)15 LinkedHashMap (java.util.LinkedHashMap)7 JobInstance (com.thoughtworks.go.domain.JobInstance)5 Map (java.util.Map)3 AgentConfig (com.thoughtworks.go.config.AgentConfig)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Agents (com.thoughtworks.go.config.Agents)1 DurationBean (com.thoughtworks.go.dto.DurationBean)1 ResolvableViewableStatus (com.thoughtworks.go.server.web.i18n.ResolvableViewableStatus)1 Expectations (org.jmock.Expectations)1 DateTime (org.joda.time.DateTime)1 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)1 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)1