Skip to content

Commit

Permalink
adding test cases and test data
Browse files Browse the repository at this point in the history
  • Loading branch information
milinda-ruk committed Aug 18, 2014
1 parent eb3ecf5 commit 7d3dbae
Show file tree
Hide file tree
Showing 4 changed files with 202 additions and 38 deletions.
19 changes: 10 additions & 9 deletions api/pom.xml
Expand Up @@ -52,15 +52,16 @@
<type>test-jar</type>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.openmrs.test</groupId>
<artifactId>openmrs-test</artifactId>
<type>pom</type>
<scope>test</scope>
</dependency>

<!-- End OpenMRS core -->

<dependency>
<groupId>org.openmrs.test</groupId>
<artifactId>openmrs-test</artifactId>
<type>pom</type>
<scope>test</scope>
</dependency>


<!-- End OpenMRS core -->

</dependencies>

Expand Down
@@ -1,30 +1,160 @@
/**
* 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.systemmetrics.api;
import static org.junit.Assert.*;
package org.openmrs.module.systemmetrics.api;



import org.hibernate.Query;
import org.hibernate.SessionFactory;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.openmrs.api.context.Context;
import org.openmrs.test.BaseModuleContextSensitiveTest;
*//**
* Tests {@link ${PerformanceMonitoringService}}.
*//*
public class PerformanceMonitoringServiceTest extends BaseModuleContextSensitiveTest {
@Test
public void shouldSetupContext() {
assertNotNull(Context.getService(PerformanceMonitoringService.class));
}
}*/
import org.openmrs.module.systemmetrics.*;
import org.openmrs.test.BaseContextSensitiveTest;

import java.util.List;

public class PerformanceMonitoringServiceTest extends BaseContextSensitiveTest {

protected static final String INITIAL_DATA_XML = "org/openmrs/api/include/PerformanceMonitoringServiceTest-initialData.xml";
protected PerformanceMonitoringService service;

private SessionFactory sessionFactory;

public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
}

@Before
public void setUp() throws Exception {
service = PerformanceMonitoringUtils.getService();
executeDataSet(INITIAL_DATA_XML);
}



@Test
public void testAddMetricType() throws Exception {
System.out.println("Test method");

MetricType metricType = new MetricType(20,"Test Metric","int");
service.addMetricType(metricType);

// get and assert metric type
MetricType newMetricType = null;
List<MetricType> list = service.getAllMetricTypes();
for(MetricType type: list ){
if(type.getMetricId() == 20){
newMetricType = type;
}
}

Assert.assertNotNull("MetricType should be added", newMetricType);
Assert.assertEquals("Metric name should be set","Test Metric",metricType.getMetricName());
Assert.assertEquals("Metric type should be set","int",metricType.getMetric_type());

}

@org.junit.Test
public void testRemoveMetricType() throws Exception {
MetricType metricType = new MetricType(20,"Test Metric 2","int");
service.addMetricType(metricType);

service.removeMetricType(metricType);
// get and assert metric type doesn't exist
MetricType newMetricType = null;
List<MetricType> list = service.getAllMetricTypes();
for(MetricType type: list ){
if(type.getMetricName().equals("Test Metric 2")){
newMetricType = type;
}
}
Assert.assertNull("Metric type should not be in the db", newMetricType);

}

@org.junit.Test
public void testGetAllMetricTypes() throws Exception {
MetricType metricType = new MetricType(20,"Test Metric 1","int");
service.addMetricType(metricType);
MetricType metricType2 = new MetricType(21,"Test Metric 2","long");
service.addMetricType(metricType);

// get and compare the metric tyes list
List<MetricType> list = service.getAllMetricTypes();
Assert.assertEquals("Metric type list size is two", 2, list.size() );
}



@org.junit.Test
public void testRemoveMetricVale() throws Exception {
MetricValue metricValue = new MetricValue(22,System.currentTimeMillis(),600000);
service.addMetricValue(metricValue);

service.removeMetricVale(metricValue);
Query query = sessionFactory.getCurrentSession().createQuery("from MetricValue where metric_id = 22");
List<MetricValue> valueList = query.list();
Assert.assertEquals("Metric value list is empty", 0, valueList.size() );
}


@org.junit.Test
public void testAddPerMinMetricValue() throws Exception {
PerMinMetricValue perMinMetricValue =
new PerMinMetricValue(23,System.currentTimeMillis(),500000);
service.addPerMinMetricValue(perMinMetricValue);

Query query = sessionFactory.getCurrentSession().createQuery("from PerMinMetricValue where metric_id = 23");
List<MetricValue> valueList = query.list();
Assert.assertEquals("PerMinMetricValue exists in db", 1, valueList.size() );

}


@org.junit.Test
public void testAddLoginValue() throws Exception {
LoginValue loginValue =
new LoginValue(System.currentTimeMillis(),24,5);
service.addLoginValue(loginValue);

Query query = sessionFactory.getCurrentSession().createQuery("from LoginValue where metric_id = 24");
List<MetricValue> valueList = query.list();
Assert.assertEquals("LoginValue exists in db", 1, valueList.size() );

}

@org.junit.Test
public void testRemoveLoginValue() throws Exception {
LoginValue loginValue =
new LoginValue(System.currentTimeMillis(),25,5);
service.addLoginValue(loginValue);

service.removeLoginValue(loginValue);
Query query = sessionFactory.getCurrentSession().createQuery("from LoginValue where metric_id = 25");
List<MetricValue> valueList = query.list();
Assert.assertEquals("LoginValue removed from db", 0, valueList.size() );

}


@org.junit.Test
public void testAddFormsPerHourEntry() throws Exception {

}

@org.junit.Test
public void testAddSavedEncounter() throws Exception {
SavedEncounter savedEncounter =
new SavedEncounter(System.currentTimeMillis(),26);
service.addSavedEncounter(savedEncounter);

Query query = sessionFactory.getCurrentSession().createQuery("from SavedEncounter where metric_id = 26");
List<MetricValue> valueList = query.list();
Assert.assertEquals("SavedEncounter added to db", 1, valueList.size() );

}

@org.junit.Test
public void testRemoveSavedEncounter() throws Exception {

}
}
@@ -0,0 +1,26 @@
<?xml version='1.0' encoding='UTF-8'?>
<dataset>
<!-- Metrics Types Data-->
<systemmetrics_metric_type metric_id="10" metric_name="Test Metric Value" metric_type="long"/>
<systemmetrics_metric_type metric_id="11" metric_name="Test Login Value" metric_type="int"/>
<systemmetrics_metric_type metric_id="12" metric_name="Test Forms Count" metric_type="int"/>
<systemmetrics_metric_type metric_id="13" metric_name="Test Saved Encounter" metric_type="object"/>

<!--Metric Value Data-->
<systemmetrics_metric_value timestamp="1407471659619" metric_id="10" metric_value="12345678"/>

<!--Permin Metric Value Data -->
<systemmetrics_permin_metric_value timestamp="1407471669619" metric_id="10" metric_value="56789012"/>

<!--Log in value data-->
<systemmetrics_login_value timestamp="1407471659619" metric_id="11" login_count="5"/>

<!--Permin login value data-->
<systemmetrics_permin_login_value timestamp="1407471669619" metric_id="11" login_count="3"/>

<!--Forms per hours data-->
<systemmetrics_forms_per_hour timestamp="1407471659619" metric_id="12" form_count="20"/>

<!--Saved Encounter data-->
<systemmetrics_saved_encounter timestamp="1407471659619" metric_id="13"/>
</dataset>
7 changes: 7 additions & 0 deletions pom.xml
Expand Up @@ -98,6 +98,13 @@

<!-- End OpenMRS core -->

<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
</dependency>


</dependencies>
</dependencyManagement>

Expand Down

0 comments on commit 7d3dbae

Please sign in to comment.