001: /*
002: * Copyright 2005-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005: * in compliance with the License. You may obtain a copy of the License at
006: *
007: * http://www.apache.org/licenses/LICENSE-2.0
008: *
009: * Unless required by applicable law or agreed to in writing, software distributed under the License
010: * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011: * or implied. See the License for the specific language governing permissions and limitations under
012: * the License.
013: */
014:
015: package org.strecks.builder;
016:
017: import static org.testng.Assert.assertEquals;
018:
019: import java.util.Iterator;
020: import java.util.Properties;
021: import java.util.Set;
022:
023: import org.strecks.constants.DefaultImplementations;
024: import org.testng.annotations.Test;
025:
026: /**
027: * @author Phil Zoio
028: */
029: public class TestPropertiesBuilder {
030:
031: @Test
032: public void testBuilder() {
033: Builder builder = new PropertiesBuilder();
034: builder.build(null);
035:
036: assert null != builder.getActionCreator();
037: assert null != builder.getControllerDelegate();
038: assert null != builder.getActionContextFactory();
039: assert null != builder.getFormHandler();
040: assert null != builder.getFormValidationHandler();
041: assert null != builder.getFormPopulateSource();
042: assert null != builder.getRequestPreprocessor();
043: }
044:
045: @Test
046: public void testGetFileName() {
047: PropertiesBuilder builder = new PropertiesBuilder();
048: assertEquals("/strecks.properties", builder.getFileName(null));
049: assertEquals("/strecks.properties", builder.getFileName(""));
050: assertEquals("/strecks.properties", builder.getFileName("/"));
051: assertEquals("/strecks_moduleName.properties", builder
052: .getFileName("moduleName"));
053: assertEquals("/strecks_moduleName.properties", builder
054: .getFileName("/moduleName"));
055: }
056:
057: @Test
058: public void testGetDefaultConfig() {
059: PropertiesBuilder builder = new PropertiesBuilder();
060: ImplementationConfig implementationConfig = builder
061: .getImplementationConfig(new Properties());
062:
063: assertEquals(implementationConfig.getActionCreatorClassName(),
064: DefaultImplementations.ACTION_CREATOR);
065: assertEquals(implementationConfig.getBuilderClassName(),
066: DefaultImplementations.BUILDER);
067: assertEquals(implementationConfig.getDelegateClassName(),
068: DefaultImplementations.DELEGATE);
069: assertEquals(implementationConfig.getContextFactoryClassName(),
070: DefaultImplementations.ACTION_CONTEXT_FACTORY);
071: assertEquals(implementationConfig.getFormHandlerClassName(),
072: DefaultImplementations.FORM_HANDLER);
073: assertEquals(implementationConfig
074: .getFormValidationHandlerClassName(),
075: DefaultImplementations.FORM_VALIDATION_HANDLER);
076: assertEquals(implementationConfig
077: .getFormPopulateSourceClassName(),
078: DefaultImplementations.FORM_POPULATION_SOURCE);
079: assertEquals(implementationConfig
080: .getRequestPreprocessorClassName(),
081: DefaultImplementations.REQUEST_PREPROCESSOR);
082:
083: InterceptorConfig interceptorConfig = builder
084: .getInterceptorConfig(new Properties());
085: assert interceptorConfig.getBeforeInterceptors().isEmpty();
086: assert interceptorConfig.getAfterInterceptors().isEmpty();
087: }
088:
089: @Test
090: public void testGetModifiedConfig() {
091: PropertiesBuilder builder = new PropertiesBuilder();
092: Properties properties = ConfigUtils
093: .loadProperties("/org/strecks/builder/strecks.properties");
094: ImplementationConfig implementationConfig = builder
095: .getImplementationConfig(properties);
096:
097: assertEquals(implementationConfig.getActionCreatorClassName(),
098: "actionCreatorImpl");
099: assertEquals(implementationConfig.getBuilderClassName(),
100: "builderImpl");
101: assertEquals(implementationConfig.getDelegateClassName(),
102: "delegateImpl");
103: assertEquals(implementationConfig.getContextFactoryClassName(),
104: "contextFactoryImpl");
105: assertEquals(implementationConfig.getFormHandlerClassName(),
106: "formHandlerImpl");
107: assertEquals(implementationConfig
108: .getFormValidationHandlerClassName(),
109: "formValidationHandlerImpl");
110: assertEquals(implementationConfig
111: .getFormPopulateSourceClassName(),
112: "formPopulateSourceImpl");
113: assertEquals(implementationConfig
114: .getRequestPreprocessorClassName(),
115: "requestPreprocessorImpl");
116:
117: InterceptorConfig interceptorConfig = builder
118: .getInterceptorConfig(properties);
119: Set<String> beforeInterceptors = interceptorConfig
120: .getBeforeInterceptors();
121: assertEquals(beforeInterceptors.size(), 2);
122: Iterator<String> iterator = beforeInterceptors.iterator();
123: assertEquals(iterator.next(),
124: "org.strecks.interceptor.ActionLoggingInterceptor");
125: assertEquals(iterator.next(),
126: "org.strecks.interceptor.RedirectBeforeInterceptor");
127:
128: Set<String> afterInterceptors = interceptorConfig
129: .getAfterInterceptors();
130: assertEquals(afterInterceptors.size(), 2);
131: iterator = afterInterceptors.iterator();
132: assertEquals(iterator.next(),
133: "org.strecks.interceptor.HistoryRecorder");
134: assertEquals(iterator.next(),
135: "org.strecks.interceptor.ActionLoggingInterceptor");
136: }
137:
138: }
|