Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.core.lookup.AbstractLookup;
import org.apache.logging.log4j.core.lookup.StrLookup;
import org.openmrs.api.APIAuthenticationException;
import org.openmrs.api.AdministrationService;
import org.openmrs.api.ServiceNotFoundException;
import org.openmrs.api.context.Context;
Expand Down Expand Up @@ -76,18 +77,19 @@ private String getGlobalProperty(AdministrationService adminService, String glob
if (adminService == null) {
return null;
}

String value = adminService.getGlobalProperty(globalPropertyName);
if (value == null) {
return null;
} else {
value = value.trim();
}

if (value.isEmpty()) {
return null;
}

return value;

}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/**
* 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.logging;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertNull;

import org.junit.jupiter.api.Test;
import org.openmrs.api.context.Context;
import org.openmrs.test.jupiter.BaseContextSensitiveTest;
import org.openmrs.util.OpenmrsUtil;

/**
* Tests for {@link OpenmrsPropertyLookup}
*/
public class OpenmrsPropertyLookupTest extends BaseContextSensitiveTest {

@Test
public void lookup_shouldReturnApplicationDirectoryWhenAuthenticated() {
OpenmrsPropertyLookup lookup = new OpenmrsPropertyLookup();

String result = lookup.lookup(null, "applicationDirectory");

assertNotNull(result);
assertEquals(OpenmrsUtil.getApplicationDataDirectory(), result);
}

@Test
public void lookup_shouldThrowExceptionForLogLayoutWhenNotAuthenticated() {
Context.logout();
OpenmrsPropertyLookup lookup = new OpenmrsPropertyLookup();

// This will throw error, as we accessing logLocation on unaunthenticated context
String result = lookup.lookup(null, "logLocation");

assertNull(result);
}



}
Loading