/* * The contents of this file are subject to the OpenMRS Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://license.openmrs.org * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the * License for the specific language governing rights and limitations * under the License. * * Copyright (C) OpenMRS, LLC. All Rights Reserved. */ package org.openmrs.module.reporting.data.encounter.evaluator; import org.junit.Before; import org.junit.Test; import org.openmrs.module.reporting.common.Age; import org.openmrs.module.reporting.common.DateUtil; import org.openmrs.module.reporting.common.TestUtil; import org.openmrs.module.reporting.data.encounter.EvaluatedEncounterData; import org.openmrs.module.reporting.data.encounter.definition.AgeAtEncounterDataDefinition; import org.openmrs.module.reporting.data.encounter.service.EncounterDataService; import org.openmrs.module.reporting.evaluation.context.EncounterEvaluationContext; import org.openmrs.module.reporting.query.encounter.EncounterIdSet; import org.openmrs.test.BaseModuleContextSensitiveTest; import org.springframework.beans.factory.annotation.Autowired; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThat; public class AgeAtEncounterDataEvaluatorTest extends BaseModuleContextSensitiveTest { @Autowired private EncounterDataService encounterDataService; protected static final String XML_DATASET_PATH = "org/openmrs/module/reporting/include/"; protected static final String XML_REPORT_TEST_DATASET = "ReportTestDataset"; @Before public void setup() throws Exception { executeDataSet(XML_DATASET_PATH + new TestUtil().getTestDatasetFilename(XML_REPORT_TEST_DATASET)); } @Test public void testEvaluate() throws Exception { EncounterEvaluationContext context = new EncounterEvaluationContext(); context.setBaseEncounters(new EncounterIdSet(3)); EvaluatedEncounterData result = encounterDataService.evaluate(new AgeAtEncounterDataDefinition(), context); assertThat(result.getData().size(), is(1)); assertThat(((Age) result.getData().get(3)).getBirthDate().getTime(), is(DateUtil.parseYmd("1976-08-25").getTime())); assertThat(((Age) result.getData().get(3)).getCurrentDate().getTime(), is(DateUtil.parseYmd("2008-08-01").getTime())); } }