Package org.internna.iwebmvc.parsers

Source Code of org.internna.iwebmvc.parsers.I18nTextParserTest

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

import java.util.Locale;
import org.internna.iwebmvc.dao.DAO;
import org.internna.iwebmvc.model.I18nText;
import org.internna.iwebmvc.model.LocalizedValue;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import static org.junit.Assert.*;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = {"/spring.xml"})
public class I18nTextParserTest {

    @Autowired private DAO baseDao;
    @Autowired private I18nTextParser textParser;

    private int number = -1;

    @Before
    public void init() {
        if (number < 0) number = baseDao.find(LocalizedValue.class, 0, 100).size();
    }

    @Test
    public void testParse() {
        assertNull(textParser.parse(null));
        I18nText text = new I18nText();
        assertEquals(text, textParser.parse(text));
        text.add(new Locale("en"), "hi");
        text.add(new Locale("es"), "hola");
        baseDao.create(text);
        I18nText textNew = new I18nText();
        textNew.setId(text.getId());
        textNew.add(new Locale("en"), "other");
        textNew.add(new Locale("es"), "otro");
        I18nText parsed = textParser.parse(textNew);
        assertNotNull(parsed.getData().get(0).getId());
        assertEquals(parsed.getData().get(0).getTranslation(), "other");
        baseDao.update(parsed);
        assertTrue(baseDao.find(LocalizedValue.class, 0, 100).size() == 2 + number);
        assertTrue(baseDao.find(I18nText.class, parsed.getId()).getData().size() == 2);
    }

}
TOP

Related Classes of org.internna.iwebmvc.parsers.I18nTextParserTest

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.