Exemplo n.º 1
0
 private Service makeService(String name, String url, String message, ServiceStatus status) {
   Service s = new Service();
   s.setId(ObjectId.get());
   s.setDashboardId(ObjectId.get());
   s.setApplicationName("appName");
   s.setLastUpdated(System.currentTimeMillis());
   s.setName(name);
   s.setMessage(message);
   s.setStatus(status);
   s.setUrl(url);
   return s;
 }
Exemplo n.º 2
0
  @Test
  public void updateService() throws Exception {
    ObjectId dashboardId = ObjectId.get();
    ObjectId serviceId = ObjectId.get();
    Service service = new Service();
    ServiceRequest request = makeServiceRequest(ServiceStatus.Ok, "Ok now");

    when(serviceService.get(serviceId)).thenReturn(service);

    mockMvc
        .perform(
            put("/dashboard/" + dashboardId.toString() + "/service/" + serviceId.toString())
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJsonBytes(request)))
        .andExpect(status().isOk());

    verify(serviceService).update(dashboardId, service);
    assertThat(service.getStatus(), is(ServiceStatus.Ok));
    assertThat(service.getMessage(), is("Ok now"));
  }
Exemplo n.º 3
0
  @Test
  public void services() throws Exception {
    Service s = makeService("serviceName", "http://abc123456.com", "message", ServiceStatus.Ok);
    when(serviceService.all()).thenReturn(Arrays.asList(s));

    mockMvc
        .perform(get("/service"))
        .andExpect(status().isOk())
        .andExpect(jsonPath("$", hasSize(1)))
        .andExpect(jsonPath("$[0].id", is(s.getId().toString())))
        .andExpect(jsonPath("$[0].dashboardId", is(s.getDashboardId().toString())))
        .andExpect(jsonPath("$[0].lastUpdated", is(s.getLastUpdated())))
        .andExpect(jsonPath("$[0].applicationName", is(s.getApplicationName())))
        .andExpect(jsonPath("$[0].name", is(s.getName())))
        .andExpect(jsonPath("$[0].url", is(s.getUrl())))
        .andExpect(jsonPath("$[0].message", is(s.getMessage())))
        .andExpect(jsonPath("$[0].status", is(s.getStatus().toString())));
  }
Exemplo n.º 4
0
  @Test
  public void dashboardServices() throws Exception {
    ObjectId dashboardId = ObjectId.get();
    Service s =
        makeService("serviceName", "http://abc123456.com", "message", ServiceStatus.Warning);
    Service dep =
        makeService("depServiceName", "http://abc123456.com", "depMessage", ServiceStatus.Alert);

    when(serviceService.dashboardServices(dashboardId)).thenReturn(Arrays.asList(s));
    when(serviceService.dashboardDependentServices(dashboardId)).thenReturn(Arrays.asList(dep));

    mockMvc
        .perform(get("/dashboard/" + dashboardId.toString() + "/service"))
        .andExpect(status().isOk())
        .andExpect(jsonPath("$.result.services", hasSize(1)))
        .andExpect(jsonPath("$.result.services[0].id", is(s.getId().toString())))
        .andExpect(jsonPath("$.result.services[0].dashboardId", is(s.getDashboardId().toString())))
        .andExpect(jsonPath("$.result.services[0].lastUpdated", is(s.getLastUpdated())))
        .andExpect(jsonPath("$.result.services[0].applicationName", is(s.getApplicationName())))
        .andExpect(jsonPath("$.result.services[0].name", is(s.getName())))
        .andExpect(jsonPath("$.result.services[0].message", is(s.getMessage())))
        .andExpect(jsonPath("$.result.services[0].status", is(s.getStatus().toString())))
        .andExpect(jsonPath("$.result.dependencies", hasSize(1)))
        .andExpect(jsonPath("$.result.dependencies[0].id", is(dep.getId().toString())))
        .andExpect(
            jsonPath("$.result.dependencies[0].dashboardId", is(dep.getDashboardId().toString())))
        .andExpect(jsonPath("$.result.dependencies[0].lastUpdated", is(dep.getLastUpdated())))
        .andExpect(
            jsonPath("$.result.dependencies[0].applicationName", is(dep.getApplicationName())))
        .andExpect(jsonPath("$.result.dependencies[0].name", is(dep.getName())))
        .andExpect(jsonPath("$.result.dependencies[0].message", is(dep.getMessage())))
        .andExpect(jsonPath("$.result.dependencies[0].status", is(dep.getStatus().toString())));
  }