Ejemplo n.º 1
0
  @Test
  public void testUpdateContextElement_Error() throws Exception {
    ArgumentCaptor<UpdateContext> updateContextArg = ArgumentCaptor.forClass(UpdateContext.class);

    List attributes = Collections.singletonList(new ContextAttribute("test", "string", "OK"));

    UpdateContextResponse response = new UpdateContextResponse();
    response.setErrorCode(new StatusCode(CodeEnum.CODE_400));
    when(ngsiController.updateContext(any())).thenReturn(response);

    UpdateContextElement updateContextElement = new UpdateContextElement();
    updateContextElement.setContextAttributes(attributes);

    mockMvc
        .perform(
            put("/v1/contextEntities/12345678")
                .contentType(MediaType.APPLICATION_JSON)
                .accept(MediaType.APPLICATION_JSON)
                .content(json(mapper, updateContextElement)))
        .andExpect(status().isOk())
        .andExpect(jsonPath("$.errorCode.code").value("400"))
        .andExpect(jsonPath("$.contextResponses").doesNotExist());

    verify(ngsiController).updateContext(any());
  }
Ejemplo n.º 2
0
  @Test
  public void testDeleteContextElement_Error() throws Exception {
    ArgumentCaptor<UpdateContext> updateContextArg = ArgumentCaptor.forClass(UpdateContext.class);

    UpdateContextResponse response = new UpdateContextResponse();
    response.setErrorCode(new StatusCode(CodeEnum.CODE_400));
    when(ngsiController.updateContext(any())).thenReturn(response);

    mockMvc
        .perform(delete("/v1/contextEntities/12345678").accept(MediaType.APPLICATION_JSON))
        .andExpect(status().isOk())
        .andExpect(jsonPath("$.code").value("400"));

    verify(ngsiController).updateContext(any());
  }
Ejemplo n.º 3
0
  @Test
  public void testUpdateContextAttribute_Error() throws Exception {

    UpdateContextResponse response = new UpdateContextResponse();
    response.setErrorCode(new StatusCode(CodeEnum.CODE_500));
    when(ngsiController.updateContext(any())).thenReturn(response);

    UpdateContextAttribute updateContextAttribute = new UpdateContextAttribute();
    updateContextAttribute.setAttribute(new ContextAttribute("temp", "float", "15.5"));

    mockMvc
        .perform(
            put("/v1/contextEntities/12345678/attributes/temp")
                .contentType(MediaType.APPLICATION_JSON)
                .accept(MediaType.APPLICATION_JSON)
                .content(json(mapper, updateContextAttribute)))
        .andExpect(status().isOk())
        .andExpect(jsonPath("$.code").value(CodeEnum.CODE_500.getLabel()));

    verify(ngsiController).updateContext(any());
  }