001: /***************************************************************
002: * This file is part of the [fleXive](R) project.
003: *
004: * Copyright (c) 1999-2008
005: * UCS - unique computing solutions gmbh (http://www.ucs.at)
006: * All rights reserved
007: *
008: * The [fleXive](R) project is free software; you can redistribute
009: * it and/or modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation;
011: * either version 2 of the License, or (at your option) any
012: * later version.
013: *
014: * The GNU General Public License can be found at
015: * http://www.gnu.org/copyleft/gpl.html.
016: * A copy is found in the textfile GPL.txt and important notices to the
017: * license from the author are found in LICENSE.txt distributed with
018: * these libraries.
019: *
020: * This library is distributed in the hope that it will be useful,
021: * but WITHOUT ANY WARRANTY; without even the implied warranty of
022: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
023: * GNU General Public License for more details.
024: *
025: * For further information about UCS - unique computing solutions gmbh,
026: * please see the company website: http://www.ucs.at
027: *
028: * For further information about [fleXive](R), please see the
029: * project website: http://www.flexive.org
030: *
031: *
032: * This copyright notice MUST APPEAR in all copies of the file!
033: ***************************************************************/package com.flexive.tests.shared;
034:
035: import com.flexive.shared.configuration.ParameterPath;
036: import com.flexive.shared.configuration.ParameterScope;
037: import com.flexive.shared.configuration.SystemParameterPaths;
038: import org.testng.annotations.Test;
039:
040: import java.util.List;
041:
042: /**
043: * com.flexive.shared.configuration.Parameter and related unit tests.
044: *
045: * @author Daniel Lichtenberger (daniel.lichtenberger@flexive.com), UCS - unique computing solutions gmbh (http://www.ucs.at)
046: */
047: @Test(groups={"shared","configuration"})
048: public class ParameterTest {
049:
050: /**
051: * Test parameter scope fallbacks.
052: *
053: * @throws Exception if an error occured
054: */
055: @Test
056: public void fallbackGlobal() throws Exception {
057: checkFallbacks(SystemParameterPaths.TEST_GLOBAL);
058: }
059:
060: /**
061: * Test parameter scope fallbacks.
062: *
063: * @throws Exception if an error occured
064: */
065: @Test
066: public void fallbackDivision() throws Exception {
067: checkFallbacks(SystemParameterPaths.TEST_DIVISION,
068: ParameterScope.GLOBAL);
069: }
070:
071: /**
072: * Test parameter scope fallbacks.
073: *
074: * @throws Exception if an error occured
075: */
076: @Test
077: public void fallbackDivisionOnly() throws Exception {
078: checkFallbacks(SystemParameterPaths.TEST_DIVISION_ONLY);
079: }
080:
081: /**
082: * Test parameter scope fallbacks.
083: *
084: * @throws Exception if an error occured
085: */
086: @Test
087: public void fallbackUser() throws Exception {
088: checkFallbacks(SystemParameterPaths.TEST_USER,
089: ParameterScope.DIVISION, ParameterScope.GLOBAL);
090: }
091:
092: /**
093: * Test parameter scope fallbacks.
094: *
095: * @throws Exception if an error occured
096: */
097: @Test
098: public void fallbackUserOnly() throws Exception {
099: checkFallbacks(SystemParameterPaths.TEST_USER_ONLY);
100: }
101:
102: /**
103: * Helper method to check expected parameter scope fallbacks.
104: *
105: * @param path paramaterpath to be checked
106: * @param expected expected fallback values
107: */
108: private void checkFallbacks(ParameterPath path,
109: ParameterScope... expected) {
110: List<ParameterScope> fallbacks = path.getScope().getFallbacks();
111: assert expected.length == fallbacks.size() : "Number of fallback scopes mismatch.";
112: for (ParameterScope scope : expected) {
113: if (fallbacks.indexOf(scope) == -1) {
114: assert false : "Expected fallback scope not found: "
115: + scope;
116: }
117: }
118: }
119: }
|