コード例 #1
0
  @Test
  public void testGetAllAnalyticsLogs() throws Exception {
    mapper.setConfig(mapper.getSerializationConfig().withView(View.Meta.class));
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    String value = mapper.writeValueAsString(testData);

    when(service.findAll(null, null)).thenReturn(testData);
    restUserMockMvc
        .perform(get("/client/analytics/logs").accept(MediaType.APPLICATION_JSON))
        .andExpect(status().isOk())
        .andExpect(content().string(value));
  }
コード例 #2
0
  @Test
  public void testAddAnalyticsLogs() throws Exception {
    mapper.setConfig(mapper.getSerializationConfig().withView(View.Meta.class));
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);

    AnalyticsLog log = testData.get(0);
    String value = mapper.writeValueAsString(log);

    when(service.save((AnalyticsLog) anyObject(), (UUID) anyObject())).thenReturn(log);
    restUserMockMvc
        .perform(
            post("/client/analytics/logs/" + app.getApplicationKey().toString())
                .content(value)
                .contentType(MediaType.APPLICATION_JSON)
                .accept(MediaType.APPLICATION_JSON))
        .andExpect(status().isCreated())
        .andExpect(content().string(value));
  }
コード例 #3
0
  @Test
  public void testGetAllAnalyticsLogsWithRange() throws Exception {
    mapper.setConfig(mapper.getSerializationConfig().withView(View.Meta.class));
    mapper.setSerializationInclusion(JsonInclude.Include.NON_EMPTY);
    List<AnalyticsLog> sTestData = new ArrayList<AnalyticsLog>();
    sTestData.add(testData.get(1));

    String value = mapper.writeValueAsString(sTestData);
    DateTime from = new DateTime().minusDays(10);
    DateTime to = new DateTime().minusDays(3);

    when(service.findAll(from, to)).thenReturn(sTestData);
    DateTimeFormatter formatter = ISODateTimeFormat.dateTime();
    String requestString =
        "/client/analytics/logs?from=" + from.toString(formatter) + "&to=" + to.toString(formatter);
    restUserMockMvc
        .perform(get(requestString).accept(MediaType.APPLICATION_JSON))
        .andExpect(status().isOk())
        .andExpect(content().string(value));
  }