/** * internals for {@link #copyPageTemplatesDeep(List, CatalogVersionModel, ContentCatalogModel)} * separated from platform so could be tested separately somehow */ protected static List<PageTemplateModel> copyPageTemplatesDeepImpl( final List<PageTemplateModel> sourceTemplates, final CatalogVersionModel catVersion, final ContentCatalogModel contentCatalog, final ModelService modelService, final RandomProducer random) { final List<PageTemplateModel> clonedTemplates = new ArrayList<PageTemplateModel>(); for (final PageTemplateModel template : sourceTemplates) { final String catalogId = template.getCatalogVersion().getCatalog().getId(); final String catalogVersionId = template.getCatalogVersion().getVersion(); final PageTemplateModel clonedPageTemplate = modelService.clone(template); clonedPageTemplate.setUid(template.getUid()); clonedPageTemplate.setName(getUidWithSuffix(template.getName(), contentCatalog.getName())); clonedPageTemplate.setCatalogVersion(catVersion); final List<ContentSlotNameModel> slotsNameList = new ArrayList<ContentSlotNameModel>(16); for (final ContentSlotNameModel contentSlotNameModel : template.getAvailableContentSlots()) // possible unique problem { final ContentSlotNameModel clonedSlotNameModel = modelService.create(ContentSlotNameModel.class); clonedSlotNameModel.setName(contentSlotNameModel.getName()); clonedSlotNameModel.setTemplate(clonedPageTemplate); slotsNameList.add(clonedSlotNameModel); } clonedPageTemplate.setAvailableContentSlots(slotsNameList); for (final ContentSlotForTemplateModel contentSlotForTemplate : template.getContentSlots()) { final ContentSlotForTemplateModel clonedContentSlotForTemplate = modelService.clone(contentSlotForTemplate); clonedContentSlotForTemplate.setCatalogVersion(catVersion); clonedContentSlotForTemplate.setPageTemplate(clonedPageTemplate); clonedContentSlotForTemplate.setUid( getUidWithSuffix(contentSlotForTemplate.getUid(), catalogId, catalogVersionId)); final ContentSlotModel contentSlotModel = contentSlotForTemplate.getContentSlot(); final ContentSlotModel clonedContentSlotModel = modelService.clone(contentSlotModel); clonedContentSlotModel.setUid( getUidWithSuffix( template.getUid(), contentSlotModel.getUid(), catalogId, catalogVersionId)); clonedContentSlotModel.setCatalogVersion(catVersion); final List<AbstractCMSComponentModel> clonedComponents = new ArrayList<AbstractCMSComponentModel>(16); for (final AbstractCMSComponentModel component : contentSlotModel.getCmsComponents()) { final AbstractCMSComponentModel clonedComponent = modelService.clone(component); clonedComponent.setUid( random.getSequenceUidValue(AbstractCMSComponentModel._TYPECODE, CMSITEM_UID_PREFIX)); clonedComponent.setSlots(Collections.<ContentSlotModel>emptyList()); clonedComponent.setCatalogVersion(catVersion); clonedComponents.add(clonedComponent); } clonedContentSlotModel.setCmsComponents(clonedComponents); clonedContentSlotForTemplate.setContentSlot(clonedContentSlotModel); modelService.save(clonedContentSlotForTemplate); } modelService.save(clonedPageTemplate); clonedTemplates.add(clonedPageTemplate); } return clonedTemplates; }
@Before public void prepare() { MockitoAnnotations.initMocks(this); BDDMockito.given(modelService.create(Mockito.any(Class.class))) .willAnswer( new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) throws Throwable { final Class clazz = (Class) invocation.getArguments()[0]; return clazz.newInstance(); } }); BDDMockito.given(contentCatalog.getName()).willReturn("root_content_catalog"); BDDMockito.given(modelService.clone(Mockito.isA(ContentSlotForTemplateModel.class))) .willAnswer( new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) throws Throwable { return slotTemplateClone; } }); BDDMockito.given(modelService.clone(Mockito.isA(PageTemplateModel.class))) .willAnswer( new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) throws Throwable { return pageTemplateClone; } }); BDDMockito.given(modelService.clone(Mockito.isA(SimpleCMSComponentModel.class))) .willAnswer( new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) throws Throwable { return componentClone; } }); BDDMockito.given(modelService.clone(Mockito.isA(ContentSlotModel.class))) .willAnswer( new Answer<Object>() { @Override public Object answer(final InvocationOnMock invocation) throws Throwable { return contentSlotClone; } }); }