Example #1
0
 private URI buildUrl(Config config, String path, Object... params) {
   URI url;
   if (params.length > 0) {
     url = config.toInstancePathWithParams(path, params);
   } else {
     url = config.toInstancePath(path);
   }
   return url;
 }
  @Test
  public void shouldGetAllConcepts() throws Exception {
    URI url = config.toInstancePath("/concept?v=full");

    when(restOperations.exchange(
            eq(url), eq(HttpMethod.GET), any(HttpEntity.class), eq(String.class)))
        .thenReturn(getResponse(CONCEPT_LIST_RESPONSE_JSON));

    ConceptListResult result = conceptResource.getAllConcepts(config);

    verify(restOperations)
        .exchange(eq(url), eq(HttpMethod.GET), requestCaptor.capture(), eq(String.class));

    assertThat(result, equalTo(readFromFile(CONCEPT_LIST_RESPONSE_JSON, ConceptListResult.class)));
    assertThat(requestCaptor.getValue().getHeaders(), equalTo(getHeadersForGet(config)));
    assertThat(requestCaptor.getValue().getBody(), nullValue());
  }
  @Test
  public void shouldCreateConcept() throws Exception {
    Concept concept = prepareConcept();
    URI url = config.toInstancePath("/concept");

    when(restOperations.exchange(
            eq(url), eq(HttpMethod.POST), any(HttpEntity.class), eq(String.class)))
        .thenReturn(getResponse(CONCEPT_RESPONSE_JSON));

    Concept created = conceptResource.createConcept(config, concept);

    verify(restOperations)
        .exchange(eq(url), eq(HttpMethod.POST), requestCaptor.capture(), eq(String.class));

    assertThat(created, equalTo(concept));
    assertThat(requestCaptor.getValue().getHeaders(), equalTo(getHeadersForPost(config)));
    assertThat(
        JsonUtils.readJson(requestCaptor.getValue().getBody(), JsonObject.class),
        equalTo(readFromFile(CONCEPT_CREATE_JSON, JsonObject.class)));
  }