@Test
  public void subscribeContextRequestOK() throws Exception {

    ngsiClient.protocolRegistry.registerHost(baseUrl, true);
    String responseBody = json(jsonConverter, createSubscribeContextResponseTemperature());

    this.mockServer
        .expect(requestTo(baseUrl + "/ngsi10/subscribeContext"))
        .andExpect(method(HttpMethod.POST))
        .andExpect(header("Content-Type", MediaType.APPLICATION_JSON_VALUE))
        .andExpect(header("Accept", MediaType.APPLICATION_JSON_VALUE))
        .andExpect(jsonPath("$.entities[*]", hasSize(1)))
        .andExpect(jsonPath("$.entities[0].id").value("Room1"))
        .andExpect(jsonPath("$.entities[0].type").value("Room"))
        .andExpect(jsonPath("$.entities[0].isPattern").value("false"))
        .andExpect(jsonPath("$.attributes[*]", hasSize(1)))
        .andExpect(jsonPath("$.attributes[0]").value("temperature"))
        .andExpect(jsonPath("$.reference").value("http://localhost:1028/accumulate"))
        .andExpect(jsonPath("$.duration").value("P1M"))
        .andRespond(withSuccess(responseBody, MediaType.APPLICATION_JSON));

    SubscribeContextResponse response =
        ngsiClient.subscribeContext(baseUrl, null, createSubscribeContextTemperature()).get();
    this.mockServer.verify();

    Assert.assertNull(response.getSubscribeError());
    Assert.assertEquals("12345678", response.getSubscribeResponse().getSubscriptionId());
    Assert.assertEquals("P1M", response.getSubscribeResponse().getDuration());
  }
  @Test
  public void subscribeContextRequestOK_XML() throws Exception {

    ngsiClient.protocolRegistry.unregisterHost(baseUrl);
    String responseBody = xml(xmlConverter, createSubscribeContextResponseTemperature());

    this.mockServer
        .expect(requestTo(baseUrl + "/ngsi10/subscribeContext"))
        .andExpect(method(HttpMethod.POST))
        .andExpect(header("Content-Type", MediaType.APPLICATION_XML_VALUE))
        .andExpect(header("Accept", MediaType.APPLICATION_XML_VALUE))
        .andExpect(xpath("subscribeContextRequest/entityIdList/*").nodeCount(1))
        .andExpect(xpath("subscribeContextRequest/entityIdList/entityId/id").string("Room1"))
        .andExpect(xpath("subscribeContextRequest/entityIdList/entityId/@type").string("Room"))
        .andExpect(
            xpath("subscribeContextRequest/entityIdList/entityId/@isPattern").string("false"))
        .andExpect(xpath("subscribeContextRequest/attributeList/*").nodeCount(1))
        .andExpect(xpath("subscribeContextRequest/attributeList/attribute").string("temperature"))
        .andExpect(
            xpath("subscribeContextRequest/reference").string("http://localhost:1028/accumulate"))
        .andExpect(xpath("subscribeContextRequest/duration").string("P1M"))
        .andRespond(withSuccess(responseBody, MediaType.APPLICATION_XML));

    SubscribeContextResponse response =
        ngsiClient.subscribeContext(baseUrl, null, createSubscribeContextTemperature()).get();
    this.mockServer.verify();

    Assert.assertNull(response.getSubscribeError());
    Assert.assertEquals("12345678", response.getSubscribeResponse().getSubscriptionId());
    Assert.assertEquals("P1M", response.getSubscribeResponse().getDuration());
  }
  @Test(expected = HttpClientErrorException.class)
  public void subscribeContextRequestWith404() throws Exception {

    this.mockServer
        .expect(requestTo(baseUrl + "/ngsi10/subscribeContext"))
        .andExpect(method(HttpMethod.POST))
        .andRespond(withStatus(HttpStatus.NOT_FOUND));

    ngsiClient.subscribeContext(baseUrl, null, createSubscribeContextTemperature()).get();
  }
  @Test(expected = HttpServerErrorException.class)
  public void subscribeContextRequestWith500() throws Exception {

    mockServer
        .expect(requestTo(baseUrl + "/ngsi10/subscribeContext"))
        .andExpect(method(HttpMethod.POST))
        .andRespond(withStatus(HttpStatus.INTERNAL_SERVER_ERROR));

    ngsiClient.subscribeContext(baseUrl, null, createSubscribeContextTemperature()).get();
  }