Java 类org.hamcrest.text.StringContains 实例源码

项目:motech    文件:BrokerStatisticsControllerTest.java   
@Test
public void shouldReturnAllTopicInformation() throws Exception {
    given(mBeanService.getTopicStatistics()).willReturn(Arrays.asList(new TopicMBean("topic-1"), new TopicMBean("topic-2")));
    mockMvc.perform(MockMvcRequestBuilders
            .get("/topics"))
            .andExpect(status().isOk())
            .andExpect(content().string(new StringContains("\"destination\":\"topic-1\"")))
            .andExpect(content().string(new StringContains("\"destination\":\"topic-2\"")));
}
项目:motech    文件:BrokerStatisticsControllerTest.java   
@Test
public void shouldReturnAllQueueInformation() throws Exception {
    given(mBeanService.getQueueStatistics()).willReturn(Arrays.asList(new QueueMBean("queue-1"), new QueueMBean("queue-2")));
    mockMvc.perform(MockMvcRequestBuilders
            .get("/queues"))
            .andExpect(status().isOk())
            .andExpect(content().string(new StringContains("\"destination\":\"queue-1\"")))
            .andExpect(content().string(new StringContains("\"destination\":\"queue-2\"")));
}
项目:motech    文件:BrokerStatisticsControllerTest.java   
@Test
public void shouldReturnMessageInformationGivenQueueName() throws Exception {
    given(mBeanService.getQueueMessages("foo")).willReturn(Arrays.asList(new QueueMessage("123", false, new DateTime())));
    mockMvc.perform(MockMvcRequestBuilders
            .get("/queues/browse?queueName=foo"))
            .andExpect(status().isOk())
            .andExpect(content().string(new StringContains("\"messageId\":\"123")))
            .andExpect(content().string(new StringContains("\"redelivered\":false")));
}
项目:HotswapAgent    文件:AgentLoggerHandlerTest.java   
@Test
public void testHandler() {
    AgentLoggerHandler handler = new AgentLoggerHandler();
    handler.setPrintStream(printStream);

    context.checking(new Expectations() {{
        oneOf(printStream).println(with(new StringContains("DEBUG (org.hotswap.agent.config.PluginManager) - A 1 B 2 C 3")));
    }});

    handler.print(PluginManager.class, AgentLogger.Level.DEBUG, "A {} B {} C {}", null, "1", 2, 3L);
}
项目:openhds-server    文件:VisitResourceTest.java   
@Test
public void testPostVisit() throws Exception {

    String expectedDate = "01-01-2015";

    final String VISIT_POST_XML = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
            + "<visit>"
                + "<extId>ISE000012000</extId>"
                + "<visitLocation>"
                    + "<extId>NJA000001</extId>"
                + "</visitLocation>"
                + "<collectedBy>"
                    + "<extId>FWEK1D</extId>"
                + "</collectedBy>"
                + "<roundNumber>1</roundNumber>"
                + "<visitDate>2015-01-01</visitDate>"
            + "</visit>";

    /* Expected result:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
        <visit>
            <collectedBy>
                <extId>FWEK1D</extId>
            </collectedBy>
            <extId>ISE000012000</extId>
            <roundNumber>1</roundNumber>
            <visitDate>01-01-2015</visitDate>
            <visitLocation>
                <extId>NJA000001</extId>
            </visitLocation>
        </visit>
     */

    if(siteProperties != null && siteProperties.getEthiopianCalendar()){
        expectedDate = "23-04-2007";
    }

     //If visitLevel is set to location, post should be successfull
     if(siteConfigService.getVisitAt().equalsIgnoreCase("location")){
            mockMvc.perform(post("/visits").session(session)
                    .contentType(MediaType.APPLICATION_XML)
                    .body(VISIT_POST_XML.getBytes()))
                    .andExpect(status().isCreated())
                    .andExpect(content().mimeType(MediaType.APPLICATION_XML))
                    .andExpect(xpath("/visit/collectedBy/extId").string("FWEK1D"))
                    .andExpect(xpath("/visit/extId").string("ISE000012000"))
                    .andExpect(xpath("/visit/roundNumber").string("1"))
                    .andExpect(xpath("/visit/visitDate").string(expectedDate))
                    .andExpect(xpath("/visit/visitLocation/extId").string("NJA000001"));
     }else{
            mockMvc.perform(post("/visits").session(session)
                    .contentType(MediaType.APPLICATION_XML)
                    .body(VISIT_POST_XML.getBytes()))
                    .andExpect(status().isBadRequest())
                    .andExpect(content().mimeType(MediaType.APPLICATION_XML))
                    .andExpect(xpath("/failure").nodeCount(1))
                    .andExpect(xpath("failure/errors").string(new StringContains("is not of the required length as specified in the IdScheme."))); 
     }

}