/*
* 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.Link;
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 LinkParserTest {
@Autowired private LinkParser linkParser;
@Autowired private DAO baseDao;
@Before
public void init() throws Exception {
Link link = new Link();
link.setReadableText(new I18nText());
link.getReadableText().add(new Locale("en"), "hi");
link.getReadableText().add(new Locale("es"), "hola");
link.setUrl("http://localhost/application");
link.setTooltipText(new I18nText());
link.getTooltipText().add(new Locale("en"), "hi");
link.getTooltipText().add(new Locale("es"), "hola");
baseDao.create(link);
}
@Test
public void testParse() {
assertNull(linkParser.parse(null));
Link link = new Link();
assertEquals(link, linkParser.parse(link));
Link unique = baseDao.first(Link.class);
link.setId(unique.getId());
link = linkParser.parse(link);
assertNull(link.getReadableText());
assertNull(link.getTooltipText());
link = new Link();
link.setId(unique.getId());
link.setReadableText(new I18nText());
link.getReadableText().add(new Locale("en"), "new");
link.getReadableText().add(new Locale("es"), "nuevo");
link.setTooltipText(new I18nText());
link.getTooltipText().add(new Locale("en"), "tooltip");
link.getTooltipText().add(new Locale("es"), "etiqueta");
link = linkParser.parse(link);
assertEquals(link.getReadableText().getId(), unique.getReadableText().getId());
assertEquals("new", link.getReadableText().getData().get(0).getTranslation());
assertEquals(link.getTooltipText().getId(), unique.getTooltipText().getId());
assertEquals("etiqueta", link.getTooltipText().getData().get(1).getTranslation());
}
}