Package org.strecks.builder

Source Code of org.strecks.builder.TestPropertiesBuilder

/*
* Copyright 2005-2006 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/

package org.strecks.builder;

import static org.testng.Assert.assertEquals;

import java.util.Iterator;
import java.util.Properties;
import java.util.Set;

import org.strecks.constants.DefaultImplementations;
import org.testng.annotations.Test;

/**
* @author Phil Zoio
*/
public class TestPropertiesBuilder
{

  @Test
  public void testBuilder()
  {
    Builder builder = new PropertiesBuilder();
    builder.build(null);

    assert null != builder.getActionCreator();
    assert null != builder.getControllerDelegate();
    assert null != builder.getActionContextFactory();
    assert null != builder.getFormHandler();
    assert null != builder.getFormValidationHandler();
    assert null != builder.getFormPopulateSource();
    assert null != builder.getRequestPreprocessor();
  }
 
  @Test
  public void testGetFileName()
  {
    PropertiesBuilder builder = new PropertiesBuilder();
    assertEquals("/strecks.properties", builder.getFileName(null));
    assertEquals("/strecks.properties", builder.getFileName(""));
    assertEquals("/strecks.properties", builder.getFileName("/"));
    assertEquals("/strecks_moduleName.properties", builder.getFileName("moduleName"));
    assertEquals("/strecks_moduleName.properties", builder.getFileName("/moduleName"));
  }

  @Test
  public void testGetDefaultConfig()
  {
    PropertiesBuilder builder = new PropertiesBuilder();
    ImplementationConfig implementationConfig = builder.getImplementationConfig(new Properties());

    assertEquals(implementationConfig.getActionCreatorClassName(), DefaultImplementations.ACTION_CREATOR);
    assertEquals(implementationConfig.getBuilderClassName(), DefaultImplementations.BUILDER);
    assertEquals(implementationConfig.getDelegateClassName(), DefaultImplementations.DELEGATE);
    assertEquals(implementationConfig.getContextFactoryClassName(), DefaultImplementations.ACTION_CONTEXT_FACTORY);
    assertEquals(implementationConfig.getFormHandlerClassName(), DefaultImplementations.FORM_HANDLER);
    assertEquals(implementationConfig.getFormValidationHandlerClassName(), DefaultImplementations.FORM_VALIDATION_HANDLER);
    assertEquals(implementationConfig.getFormPopulateSourceClassName(), DefaultImplementations.FORM_POPULATION_SOURCE);
    assertEquals(implementationConfig.getRequestPreprocessorClassName(), DefaultImplementations.REQUEST_PREPROCESSOR);

    InterceptorConfig interceptorConfig = builder.getInterceptorConfig(new Properties());
    assert interceptorConfig.getBeforeInterceptors().isEmpty();
    assert interceptorConfig.getAfterInterceptors().isEmpty();
  }

  @Test
  public void testGetModifiedConfig()
  {
    PropertiesBuilder builder = new PropertiesBuilder();
    Properties properties = ConfigUtils.loadProperties("/org/strecks/builder/strecks.properties");
    ImplementationConfig implementationConfig = builder.getImplementationConfig(properties);

    assertEquals(implementationConfig.getActionCreatorClassName(), "actionCreatorImpl");
    assertEquals(implementationConfig.getBuilderClassName(), "builderImpl");
    assertEquals(implementationConfig.getDelegateClassName(), "delegateImpl");
    assertEquals(implementationConfig.getContextFactoryClassName(), "contextFactoryImpl");
    assertEquals(implementationConfig.getFormHandlerClassName(), "formHandlerImpl");
    assertEquals(implementationConfig.getFormValidationHandlerClassName(), "formValidationHandlerImpl");
    assertEquals(implementationConfig.getFormPopulateSourceClassName(), "formPopulateSourceImpl");
    assertEquals(implementationConfig.getRequestPreprocessorClassName(), "requestPreprocessorImpl");

    InterceptorConfig interceptorConfig = builder.getInterceptorConfig(properties);
    Set<String> beforeInterceptors = interceptorConfig.getBeforeInterceptors();
    assertEquals(beforeInterceptors.size(), 2);
    Iterator<String> iterator = beforeInterceptors.iterator();
    assertEquals(iterator.next(), "org.strecks.interceptor.ActionLoggingInterceptor");
    assertEquals(iterator.next(), "org.strecks.interceptor.RedirectBeforeInterceptor");

    Set<String> afterInterceptors = interceptorConfig.getAfterInterceptors();
    assertEquals(afterInterceptors.size(), 2);
    iterator = afterInterceptors.iterator();
    assertEquals(iterator.next(), "org.strecks.interceptor.HistoryRecorder");
    assertEquals(iterator.next(), "org.strecks.interceptor.ActionLoggingInterceptor");
  }

}
TOP

Related Classes of org.strecks.builder.TestPropertiesBuilder

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.