@Test
public void convert_Valid(){
PageTemplate mongoPageTemplate1 = new MongoDbPageTemplate();
PageTemplate mongoPageTemplate2 = new MongoDbPageTemplate();
PageLayoutRepository tempPageLayoutRepository = createMock(PageLayoutRepository.class);
WidgetRepository tempWidgetRepository = createMock(WidgetRepository.class);
((MongoDbPageTemplate)mongoPageTemplate1).setPageLayoutRepository(tempPageLayoutRepository);
((MongoDbPageTemplate)mongoPageTemplate2).setPageLayoutRepository(tempPageLayoutRepository);
PageTemplateRegion pageTemplateRegion = new PageTemplateRegionImpl();
PageTemplateWidget pageTemplateWidget = new PageTemplateWidgetImpl();
//the source PageTemplate tested in the first recursion
((MongoDbPageTemplate)mongoPageTemplate1).setId("1234");
mongoPageTemplate1.setName("Blah");
mongoPageTemplate1.setDescription("Blahty Blahty Blah");
mongoPageTemplate1.setPageType(PageType.get("user"));
MongoDbPageLayout mongoDbPageLayout1 = new MongoDbPageLayout();
mongoDbPageLayout1.setId("7777");
mongoDbPageLayout1.setCode("4321");
mongoPageTemplate1.setPageLayout(mongoDbPageLayout1);
mongoPageTemplate1.setRenderSequence(9999);
mongoPageTemplate1.setDefaultTemplate(true);
//the PageTemplate to be inserted into the subPageTemplates array, tested in the second recursion loop
((MongoDbPageTemplate)mongoPageTemplate2).setId("3232");
mongoPageTemplate2.setName("Yeah");
mongoPageTemplate2.setDescription("Yeah Yeah Ya");
mongoPageTemplate2.setPageType(PageType.get("user"));
MongoDbPageLayout mongoDbPageLayout2 = new MongoDbPageLayout();
mongoDbPageLayout2.setId("8888");
mongoDbPageLayout2.setCode("2345");
mongoPageTemplate2.setPageLayout(mongoDbPageLayout2);
mongoPageTemplate2.setRenderSequence(8787);
mongoPageTemplate2.setDefaultTemplate(true);
//the PageTemplateWidget to be add as a field to the pageTemplateWidgets array of the PageTemplateRegion
((PageTemplateWidgetImpl)pageTemplateWidget).setId("3333");
pageTemplateWidget.setHideChrome(true);
pageTemplateWidget.setRenderSeq(3456);
Widget widget = new WidgetImpl();
((WidgetImpl)widget).setId("87623876");
((PageTemplateWidgetImpl)pageTemplateWidget).setWidgetId("4444");
pageTemplateWidget.setLocked(true);
//the PageTemplateRegion to be converted
((PageTemplateRegionImpl)pageTemplateRegion).setId("2929");
pageTemplateRegion.setRenderSequence(56376);
pageTemplateRegion.setLocked(true);
//create and add subPageTemplate array to the first PageTemplate
List<PageTemplate> subPageTemplates = Arrays.asList(
(PageTemplate)mongoPageTemplate2
);
mongoPageTemplate1.setSubPageTemplates(subPageTemplates);
//create and add pageTemplateWidgets to the PageTemplateRegion
List<PageTemplateWidget> pageTemplateWidgets = Arrays.asList(
pageTemplateWidget
);
pageTemplateRegion.setPageTemplateWidgets(pageTemplateWidgets);
//create and add pageTemplateRegions to the first PageTemplate
List<PageTemplateRegion> pageTemplateRegions = Arrays.asList(
pageTemplateRegion
);
mongoPageTemplate1.setPageTemplateRegions(pageTemplateRegions);
expect(tempPageLayoutRepository.getByPageLayoutCode("4321")).andReturn(mongoDbPageLayout1);
expect(tempPageLayoutRepository.getByPageLayoutCode("2345")).andReturn(mongoDbPageLayout2);
expect(tempWidgetRepository.get("4444")).andReturn(widget);
replay(tempPageLayoutRepository, tempWidgetRepository);
MongoDbPageTemplate convertedTemplate = pageTemplateConverter.convert(mongoPageTemplate1);