Package org.internna.iwebmvc.spring.mvc.controllers

Source Code of org.internna.iwebmvc.spring.mvc.controllers.EntityControllerTest

/*
* Copyright 2002-2007 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.internna.iwebmvc.spring.mvc.controllers;

import java.io.File;
import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import org.internna.iwebmvc.core.context.ContextHolder;
import org.springframework.ui.ModelMap;
import org.internna.iwebmvc.core.crypto.impl.DES3CiphererDecipherer;
import org.internna.iwebmvc.model.core.Locale;
import org.internna.iwebmvc.utils.ClassUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.core.io.FileSystemResourceLoader;
import org.springframework.mock.web.MockHttpSession;
import org.springframework.mock.web.MockServletContext;
import static org.junit.Assert.*;

/**
*
* @author Jose Noheda
* @since 1.0
*/
public class EntityControllerTest {

    private static EntityController controller;
    private static DES3CiphererDecipherer crypto;

    @BeforeClass
    public static void setUpClass() throws Exception {
        controller = new EntityController();
        crypto = new DES3CiphererDecipherer().init();
        Field ciphererField = ClassUtils.getField(EntityController.class, "cipherer");
        ciphererField.setAccessible(true);
        ciphererField.set(controller, crypto);
        Field controllerField = ClassUtils.getField(EntityController.class, "decipherer");
        controllerField.setAccessible(true);
        controllerField.set(controller, crypto);
        Field contextField = ClassUtils.getField(EntityController.class, "context");
        contextField.setAccessible(true);
        contextField.set(controller, new ContextHolder() {
            @Override
            public List<Locale> getAvailableLocales() {
                Locale l = new Locale();
                l.setDescription("English");
                l.setLocale("en");
                List<Locale> list = new ArrayList<Locale>(1);
                list.add(l);
                return list;
            }
        });
    }

    @Test
    public void showForm() throws Exception {
        controller.setServletContext(new MockServletContext());
        assertEquals("No jsp in WEB-INF", "crud/template", controller.showForm("stubs.TrivialDomainEntity", null, null, new ModelMap(), new MockHttpSession()));
        controller.setServletContext(new MockServletContext("web", new FileSystemResourceLoader()));
        assertEquals("JSP in WEB-INF", "crud/demoapp/domain/book", controller.showForm("demoapp.domain.Book", null, null, new ModelMap(), new MockHttpSession()));
    }

}
TOP

Related Classes of org.internna.iwebmvc.spring.mvc.controllers.EntityControllerTest

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.