Package org.strecks.navigate.spring

Source Code of org.strecks.navigate.spring.TestSpringNavigationReader

/*
* 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.navigate.spring;

import static org.testng.Assert.assertEquals;
import static org.testng.Assert.fail;

import org.strecks.exceptions.ApplicationConfigurationException;
import org.strecks.navigate.NavigationHandler;
import org.strecks.navigate.NavigationHandlerFactory;
import org.strecks.navigate.NavigationHolder;
import org.strecks.navigate.factory.IdentityNavigationHandlerFactory;
import org.strecks.navigate.internal.BeanNavigationReader;
import org.strecks.navigate.spring.impl.ActionWithDuffSpringNavigation;
import org.strecks.navigate.spring.impl.ActionWithSpringResolverNavigation;
import org.strecks.navigate.spring.impl.ActionWithSpringViewNavigation;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;

public class TestSpringNavigationReader
{

  private BeanNavigationReader navigationReader;

  @BeforeMethod
  public void setUp()
  {
    navigationReader = new BeanNavigationReader();
  }

  @Test
  public void testResolverNavigationReader()
  {
    SpringViewNavigationHandler h = getAndTestHandler(ActionWithSpringResolverNavigation.class);
    assert h.isUseResolver();
    assertEquals(h.getName(), "resolver_name");
    assert h.getLocaleResolver() instanceof StrecksLocaleResolver;
  }
 
  @Test
  public void testViewNavigationReader()
  {
    SpringViewNavigationHandler h = getAndTestHandler(ActionWithSpringViewNavigation.class);
    assert !h.isUseResolver();
    assert null == h.getName();
    assert h.getLocaleResolver() instanceof StrecksLocaleResolver;
  }

  private SpringViewNavigationHandler getAndTestHandler(Class clazz)
  {
    navigationReader.readAnnotations(clazz);
    NavigationHolder navigationHolder = navigationReader.getNavigationHolder();
    NavigationHandlerFactory factory = navigationHolder.getFactory();
    assert factory instanceof IdentityNavigationHandlerFactory;
   
    NavigationHandler navigationHandler = factory.getNavigationHandler(null,null);
    assert navigationHandler instanceof SpringViewNavigationHandler;
   
    SpringViewNavigationHandler h = (SpringViewNavigationHandler) navigationHandler;
    return h;
  }

  @Test
  public void testIllegalMethodName()
  {

    try
    {
      navigationReader.readAnnotations(ActionWithDuffSpringNavigation.class);
      fail();
    }
    catch (ApplicationConfigurationException e)
    {
      assertEquals(e.getMessage(), "Method getResult() in class "
          + "org.strecks.navigate.spring.impl.ActionWithDuffSpringNavigation "
          + "must return object of type org.springframework.web.servlet.ModelAndView");
    }
  }

}
TOP

Related Classes of org.strecks.navigate.spring.TestSpringNavigationReader

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.