Skip to content

Commit

Permalink
Ensure StandaloneContextSensitiveTest works with current version of O…
Browse files Browse the repository at this point in the history
…penMRS
  • Loading branch information
mseaton committed Jul 30, 2024
1 parent 746ac5f commit 50ca821
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,17 +1,57 @@
package org.openmrs.module.rwandareports;

import java.util.Properties;

import org.junit.Before;
import org.openmrs.api.context.Context;
import org.openmrs.test.BaseModuleContextSensitiveTest;
import org.openmrs.test.SkipBaseSetup;
import org.springframework.test.context.ContextConfiguration;

@ContextConfiguration(locations = {"classpath:openmrs-servlet.xml"}, inheritLocations = true)
import java.io.File;
import java.nio.file.Files;
import java.util.Properties;

@SkipBaseSetup
public abstract class StandaloneContextSensitiveTest extends BaseModuleContextSensitiveTest {

static {
loadRuntimePropertiesFromSdk();
}

protected static void loadRuntimeProperties() {
System.setProperty("databaseUrl", "jdbc:mysql://localhost:3308/rwinkprotest?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8&useSSL=false");
System.setProperty("databaseUsername", "root");
System.setProperty("databasePassword", "root");
System.setProperty("databaseDriver", "com.mysql.jdbc.Driver");
System.setProperty("databaseDialect", "org.hibernate.dialect.MySQLDialect");
System.setProperty("useInMemoryDatabase", "false");
}

protected static void loadRuntimePropertiesFromSdk() {
Properties props = new Properties();
String serverId = System.getProperty("serverId");
if (serverId != null) {
File homeDir = new File(System.getProperty("user.home"));
File sdkDir = new File(homeDir, "openmrs");
File serverDir = new File(sdkDir, serverId);
File runtimePropertiesFile = new File(serverDir, "openmrs-runtime.properties");
if (!runtimePropertiesFile.exists()) {
throw new RuntimeException("No runtime properties file found at: " + runtimePropertiesFile.getAbsolutePath());
}
props = new Properties();
try {
props.load(Files.newInputStream(runtimePropertiesFile.toPath()));
}
catch (Exception e) {
throw new RuntimeException("Error loading properties from " + runtimePropertiesFile, e);
}
}
System.setProperty("databaseUrl", props.getProperty("connection.url"));
System.setProperty("databaseUsername", props.getProperty("connection.username"));
System.setProperty("databasePassword", props.getProperty("connection.password"));
System.setProperty("databaseDriver", props.getProperty("connection.driver_class"));
System.setProperty("databaseDialect", "org.hibernate.dialect.MySQLDialect");
System.setProperty("useInMemoryDatabase", "false");
}

@Override
public Boolean useInMemoryDatabase() {
return false;
Expand All @@ -23,9 +63,6 @@ public Boolean useInMemoryDatabase() {
@Override
public Properties getRuntimeProperties() {
Properties p = super.getRuntimeProperties();
p.setProperty("connection.url", "jdbc:mysql://localhost:3306/openmrs_rwink?autoReconnect=true&useUnicode=true&characterEncoding=UTF-8");
p.setProperty("connection.username", "root");
p.setProperty("connection.password", "root");
p.setProperty("junit.username", "admin");
p.setProperty("junit.password", "Admin123");
return p;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license.
*
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS
* graphic logo is a trademark of OpenMRS Inc.
*/

package org.openmrs.module.rwandareports.reporting;

import org.junit.Test;
import org.openmrs.module.rwandareports.StandaloneContextSensitiveTest;

/**
* Tests that StandaloneContextSensitiveTest works properly
*/
public class TestStandaloneContextSensitiveTest extends StandaloneContextSensitiveTest {

@Test
public void testPatientWithViralLoadAndCD4TestedCohort() {
System.out.println("Success");
}

}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<openMRSVersion>2.3.3-SNAPSHOT</openMRSVersion>
<openMRSVersion>2.3.3</openMRSVersion>
<calculationVersion>1.3.0</calculationVersion>
<heightweighttrackerVersion>2.1.0-SNAPSHOT</heightweighttrackerVersion>
<htmlwidgetsVersion>1.10.0</htmlwidgetsVersion>
Expand Down

0 comments on commit 50ca821

Please sign in to comment.