@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());
  }
  @Test
  public void testUpdateContextElement_OK() throws Exception {
    ArgumentCaptor<UpdateContext> updateContextArg = ArgumentCaptor.forClass(UpdateContext.class);

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

    ContextElement contextElement = new ContextElement();
    contextElement.setEntityId(new EntityId("12345678", "", false));
    contextElement.setContextAttributeList(attributes);
    ContextElementResponse contextElementResponse =
        new ContextElementResponse(contextElement, new StatusCode(CodeEnum.CODE_200));
    UpdateContextResponse response = new UpdateContextResponse();
    response.setContextElementResponses(Collections.singletonList(contextElementResponse));
    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").doesNotExist())
        .andExpect(jsonPath("$.contextResponses[0].attributes[0].name").value("test"))
        .andExpect(jsonPath("$.contextResponses[0].attributes[0].type").value("string"))
        .andExpect(jsonPath("$.contextResponses[0].attributes[0].value").value("OK"))
        .andExpect(jsonPath("$.contextResponses[0].statusCode.code").value("200"));

    verify(ngsiController).updateContext(updateContextArg.capture());

    UpdateContext updateContextRequest = updateContextArg.getValue();
    assertNotNull(updateContextRequest);
    assertEquals(UpdateAction.UPDATE, updateContextRequest.getUpdateAction());
    assertEquals(
        "12345678", updateContextRequest.getContextElements().get(0).getEntityId().getId());
    assertEquals("", updateContextRequest.getContextElements().get(0).getEntityId().getType());
    assertEquals(
        false, updateContextRequest.getContextElements().get(0).getEntityId().getIsPattern());
  }