|
| 1 | +/** |
| 2 | + * This Source Code Form is subject to the terms of the Mozilla Public License, |
| 3 | + * v. 2.0. If a copy of the MPL was not distributed with this file, You can |
| 4 | + * obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under |
| 5 | + * the terms of the Healthcare Disclaimer located at http://openmrs.org/license. |
| 6 | + * |
| 7 | + * Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS |
| 8 | + * graphic logo is a trademark of OpenMRS Inc. |
| 9 | + */ |
| 10 | +package org.openmrs.module.initializer.api.loaders; |
| 11 | + |
| 12 | +import org.junit.Assert; |
| 13 | +import org.junit.Test; |
| 14 | +import org.openmrs.GlobalProperty; |
| 15 | +import org.openmrs.api.context.Context; |
| 16 | +import org.openmrs.module.initializer.DomainBaseModuleContextSensitive_2_7_Test; |
| 17 | +import org.openmrs.module.initializer.api.gp.GlobalPropertiesLoader; |
| 18 | +import org.springframework.beans.factory.annotation.Autowired; |
| 19 | + |
| 20 | +/** |
| 21 | + * This test is intended to be a copy of the GlobalPropertiesLoaderIntegrationTest from the api module, |
| 22 | + * but included within the api-2.7 module to test that global properties loading from xml works successfully |
| 23 | + * in an OpenMRS 2.7 environment |
| 24 | + */ |
| 25 | +public class GlobalPropertiesLoaderIntegration_2_7_Test extends DomainBaseModuleContextSensitive_2_7_Test { |
| 26 | + |
| 27 | + @Autowired |
| 28 | + private GlobalPropertiesLoader loader; |
| 29 | + |
| 30 | + @Test |
| 31 | + public void loadGlobalProperties_shouldLoadGlobalProperties() { |
| 32 | + |
| 33 | + // Replay |
| 34 | + loader.load(); |
| 35 | + |
| 36 | + // Verif |
| 37 | + Assert.assertEquals("GP one one", Context.getAdministrationService().getGlobalProperty("gp.gp11")); |
| 38 | + Assert.assertEquals("GP one two", Context.getAdministrationService().getGlobalProperty("gp.gp12")); |
| 39 | + Assert.assertEquals("GP two one", Context.getAdministrationService().getGlobalProperty("gp.gp21")); |
| 40 | + Assert.assertEquals("GP three one", Context.getAdministrationService().getGlobalProperty("gp.gp31")); |
| 41 | + Assert.assertEquals("GP three two", Context.getAdministrationService().getGlobalProperty("gp.gp32")); |
| 42 | + Assert.assertEquals("GP three three", Context.getAdministrationService().getGlobalProperty("gp.gp33")); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + public void load_shouldOverrideGlobalProperties() { |
| 47 | + |
| 48 | + // Setup |
| 49 | + Context.getAdministrationService().saveGlobalProperty(new GlobalProperty("gp.gp11", "foobar")); |
| 50 | + Assert.assertEquals("foobar", Context.getAdministrationService().getGlobalProperty("gp.gp11")); |
| 51 | + |
| 52 | + // Replay |
| 53 | + loader.load(); |
| 54 | + |
| 55 | + // Verif |
| 56 | + Assert.assertEquals("GP one one", Context.getAdministrationService().getGlobalProperty("gp.gp11")); |
| 57 | + } |
| 58 | + |
| 59 | + @Test |
| 60 | + public void load_shouldNotAffectOtherGlobalProperties() { |
| 61 | + |
| 62 | + // Setup |
| 63 | + Context.getAdministrationService().saveGlobalProperty(new GlobalProperty("gp.foo", "Foo")); |
| 64 | + Context.getAdministrationService().saveGlobalProperty(new GlobalProperty("gp.bar", "Bar")); |
| 65 | + Context.getAdministrationService().saveGlobalProperty(new GlobalProperty("gp.baz", "Baz")); |
| 66 | + |
| 67 | + // Replay |
| 68 | + loader.load(); |
| 69 | + |
| 70 | + // Verif |
| 71 | + Assert.assertEquals("Foo", Context.getAdministrationService().getGlobalProperty("gp.foo")); |
| 72 | + Assert.assertEquals("Bar", Context.getAdministrationService().getGlobalProperty("gp.bar")); |
| 73 | + Assert.assertEquals("Baz", Context.getAdministrationService().getGlobalProperty("gp.baz")); |
| 74 | + } |
| 75 | +} |
0 commit comments