Created
May 6, 2012 17:47
-
-
Save krimple/2623484 to your computer and use it in GitHub Desktop.
Revisions
-
krimple created this gist
May 6, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,83 @@ package com.t.coursemanager.web; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import org.apache.log4j.Logger; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.core.convert.converter.Converter; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; import org.springframework.transaction.annotation.Transactional; import com.t.coursemanager.model.Course; import com.t.coursemanager.model.CourseDataOnDemand; import com.t.coursemanager.model.Tag; import com.t.coursemanager.model.TagDataOnDemand; @ContextConfiguration(locations = {"classpath:META-INF/spring/applicationContext*.xml"}) @RunWith(SpringJUnit4ClassRunner.class) public class ApplicationConversionServiceFactoryBeanTest { private static final Logger logger = Logger.getLogger(ApplicationConversionServiceFactoryBeanTest.class); private ApplicationConversionServiceFactoryBean conversionService; private Converter<String, Tag> stringToTagConverter; private Converter<Long, Tag> idToTagConverter; private Converter<Tag, String> tagToStringConverter; private Tag tag; @Before public void setUp() { conversionService = new ApplicationConversionServiceFactoryBean(); stringToTagConverter = conversionService.getStringToTagConverter(); idToTagConverter = conversionService.getIdToTagConverter(); tagToStringConverter = conversionService.getTagToStringConverter(); tag = createCourseAndTagAndAssociate(); } @Test @Transactional public void testConvertIdStringToTag() { assertThat(tag.getId(), notNullValue()); String tagString = tagToStringConverter.convert(tag); logger.debug("value of tag -> String is"); logger.debug(tagString); String idString = String.valueOf(tag.getId()); Tag convertedTag = stringToTagConverter.convert(idString); assertThat(convertedTag, is(tag)); logger.debug(convertedTag); } @Test @Transactional public void testConvertIdToTag() { assertThat(tag.getId(), notNullValue()); Tag convertedTag = idToTagConverter.convert(tag.getId()); assertThat(convertedTag, is(tag)); logger.debug(convertedTag); } @Test @Transactional public void testTagToString() { String tagString = tagToStringConverter.convert(tag); assertThat(tagString, notNullValue()); logger.debug("value of tag -> String is"); logger.debug(tagString); } private Tag createCourseAndTagAndAssociate() { CourseDataOnDemand cdod = new CourseDataOnDemand(); TagDataOnDemand tdod = new TagDataOnDemand(); Course course = cdod.getRandomCourse(); Tag tag = tdod.getRandomTag(); tag.getCourses().add(course); tag.flush(); return tag; } }