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 shouldQueryForConceptByName() throws Exception {
    String query = "Test";
    URI url = config.toInstancePathWithParams("/concept?v=full&q={conceptName}", query);

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

    ConceptListResult result = conceptResource.queryForConceptsByName(config, query);

    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 shouldGetConceptById() throws Exception {
    String conceptId = "LLL";
    URI url = config.toInstancePathWithParams("/concept/{uuid}", conceptId);

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

    Concept concept = conceptResource.getConceptById(config, conceptId);

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

    assertThat(concept, equalTo(readFromFile(CONCEPT_CREATE_JSON, Concept.class)));
    assertThat(requestCaptor.getValue().getHeaders(), equalTo(getHeadersForGet(config)));
    assertThat(requestCaptor.getValue().getBody(), nullValue());
  }
  @Test
  public void shouldUpdateConcept() throws Exception {
    Concept concept = prepareConcept();
    URI url = config.toInstancePathWithParams("/concept/{uuid}", concept.getUuid());

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

    Concept updated = conceptResource.updateConcept(config, concept);

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

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