private int getGeneratedJSONObjectsCount(int amountOfConfigs) throws IOException {
    List<Config> simpleConfigs = new ArrayList<>();

    for (int i = 0; i < amountOfConfigs; i++) {
      Config simpleConfig = new Config();
      simpleConfig.setName("simpleConfiguration" + Integer.toString(i));
      simpleConfigs.add(simpleConfig);
    }

    Configs configs = new Configs(simpleConfigs, "simpleConfiguration");

    when(configService.getConfigs()).thenReturn(configs);
    openMRSTaskDataProviderBuilder.setOpenMRSConfigService(configService);

    VelocityEngineFactoryBean vefb = new VelocityEngineFactoryBean();
    Map<String, Object> velocityPropertiesMap = new HashMap<String, Object>();
    velocityPropertiesMap.put("resource.loader", "class");
    velocityPropertiesMap.put(
        "class.resource.loader.class", "org.motechproject.openmrs.tasks.VelocityResourceLoader");
    vefb.setVelocityPropertiesMap(velocityPropertiesMap);

    VelocityEngine velocityEngine = vefb.createVelocityEngine();
    assertNotNull(velocityEngine);

    openMRSTaskDataProviderBuilder.setVelocityEngine(velocityEngine);

    String generatedJSON = openMRSTaskDataProviderBuilder.generateDataProvider();

    JSONObject jsonResult = new JSONObject(generatedJSON);
    JSONArray objects = jsonResult.getJSONArray("objects");

    return objects.length();
  }
예제 #2
0
  @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());
  }
예제 #3
0
  @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());
  }
예제 #4
0
  @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)));
  }