@Test
  public void deserializationSimpleQueryContextResponse() throws IOException {

    String json = getJsonOrionQueryContextResponse();
    QueryContextResponse queryContextResponse =
        objectMapper.readValue(json, QueryContextResponse.class);

    assertNull(queryContextResponse.getErrorCode());
    assertEquals(2, queryContextResponse.getContextElementResponses().size());
    assertEquals(
        1,
        queryContextResponse
            .getContextElementResponses()
            .get(0)
            .getContextElement()
            .getContextAttributeList()
            .size());
    assertEquals(
        "temperature",
        queryContextResponse
            .getContextElementResponses()
            .get(0)
            .getContextElement()
            .getContextAttributeList()
            .get(0)
            .getName());
    assertEquals(
        "float",
        queryContextResponse
            .getContextElementResponses()
            .get(0)
            .getContextElement()
            .getContextAttributeList()
            .get(0)
            .getType());
    assertEquals(
        "23",
        queryContextResponse
            .getContextElementResponses()
            .get(0)
            .getContextElement()
            .getContextAttributeList()
            .get(0)
            .getValue());
    assertEquals(
        "Room1",
        queryContextResponse
            .getContextElementResponses()
            .get(0)
            .getContextElement()
            .getEntityId()
            .getId());
    assertEquals(
        "Room",
        queryContextResponse
            .getContextElementResponses()
            .get(0)
            .getContextElement()
            .getEntityId()
            .getType());
    assertEquals(
        false,
        queryContextResponse
            .getContextElementResponses()
            .get(0)
            .getContextElement()
            .getEntityId()
            .getIsPattern());
    assertEquals(
        CodeEnum.CODE_200.getLabel(),
        queryContextResponse.getContextElementResponses().get(0).getStatusCode().getCode());
    assertEquals(
        CodeEnum.CODE_200.getShortPhrase(),
        queryContextResponse.getContextElementResponses().get(0).getStatusCode().getReasonPhrase());
    assertEquals(
        1,
        queryContextResponse
            .getContextElementResponses()
            .get(1)
            .getContextElement()
            .getContextAttributeList()
            .size());
    assertEquals(
        "temperature",
        queryContextResponse
            .getContextElementResponses()
            .get(1)
            .getContextElement()
            .getContextAttributeList()
            .get(0)
            .getName());
    assertEquals(
        "float",
        queryContextResponse
            .getContextElementResponses()
            .get(1)
            .getContextElement()
            .getContextAttributeList()
            .get(0)
            .getType());
    assertEquals(
        "21",
        queryContextResponse
            .getContextElementResponses()
            .get(1)
            .getContextElement()
            .getContextAttributeList()
            .get(0)
            .getValue());
    assertEquals(
        "Room2",
        queryContextResponse
            .getContextElementResponses()
            .get(1)
            .getContextElement()
            .getEntityId()
            .getId());
    assertEquals(
        "Room",
        queryContextResponse
            .getContextElementResponses()
            .get(1)
            .getContextElement()
            .getEntityId()
            .getType());
    assertEquals(
        false,
        queryContextResponse
            .getContextElementResponses()
            .get(1)
            .getContextElement()
            .getEntityId()
            .getIsPattern());
    assertEquals(
        CodeEnum.CODE_481.getLabel(),
        queryContextResponse.getContextElementResponses().get(1).getStatusCode().getCode());
    assertEquals(
        CodeEnum.CODE_481.getShortPhrase(),
        queryContextResponse.getContextElementResponses().get(1).getStatusCode().getReasonPhrase());
    assertEquals(
        "test details",
        queryContextResponse.getContextElementResponses().get(1).getStatusCode().getDetail());
  }
  @Test
  public void testUpdateContextAttributeValue_OK() throws Exception {
    ArgumentCaptor<UpdateContext> updateContextArg = ArgumentCaptor.forClass(UpdateContext.class);

    ContextAttribute attribute = new ContextAttribute("temp", "float", "15.5");
    attribute.setMetadata(
        Collections.singletonList(new ContextMetadata("ID", "string", "DEADBEEF")));

    ContextElement contextElement = new ContextElement();
    contextElement.setEntityId(new EntityId("12345678", "", false));
    contextElement.setContextAttributeList(Collections.singletonList(attribute));
    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);

    UpdateContextAttribute updateContextAttribute = new UpdateContextAttribute();
    updateContextAttribute.setAttribute(attribute);

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

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

    UpdateContext updateContextRequest = updateContextArg.getValue();
    assertNotNull(updateContextRequest);
    assertEquals(UpdateAction.UPDATE, updateContextRequest.getUpdateAction());
    assertNotNull(updateContextRequest.getContextElements());
    assertEquals(1, updateContextRequest.getContextElements().size());
    assertNotNull(updateContextRequest.getContextElements().get(0).getEntityId());
    assertEquals(
        "12345678", updateContextRequest.getContextElements().get(0).getEntityId().getId());
    assertEquals("", updateContextRequest.getContextElements().get(0).getEntityId().getType());
    assertEquals(
        false, updateContextRequest.getContextElements().get(0).getEntityId().getIsPattern());
    assertNotNull(updateContextRequest.getContextElements().get(0).getContextAttributeList());
    assertEquals(
        1, updateContextRequest.getContextElements().get(0).getContextAttributeList().size());
    assertEquals(
        "temp",
        updateContextRequest
            .getContextElements()
            .get(0)
            .getContextAttributeList()
            .get(0)
            .getName());
    assertEquals(
        "float",
        updateContextRequest
            .getContextElements()
            .get(0)
            .getContextAttributeList()
            .get(0)
            .getType());
    assertEquals(
        "15.5",
        updateContextRequest
            .getContextElements()
            .get(0)
            .getContextAttributeList()
            .get(0)
            .getValue());
    assertNotNull(
        updateContextRequest
            .getContextElements()
            .get(0)
            .getContextAttributeList()
            .get(0)
            .getMetadata());
    assertEquals(
        1,
        updateContextRequest
            .getContextElements()
            .get(0)
            .getContextAttributeList()
            .get(0)
            .getMetadata()
            .size());
    assertEquals(
        "ID",
        updateContextRequest
            .getContextElements()
            .get(0)
            .getContextAttributeList()
            .get(0)
            .getMetadata()
            .get(0)
            .getName());
    assertEquals(
        "string",
        updateContextRequest
            .getContextElements()
            .get(0)
            .getContextAttributeList()
            .get(0)
            .getMetadata()
            .get(0)
            .getType());
    assertEquals(
        "DEADBEEF",
        updateContextRequest
            .getContextElements()
            .get(0)
            .getContextAttributeList()
            .get(0)
            .getMetadata()
            .get(0)
            .getValue());
  }