alfresco-community-repo/source/java/org/alfresco/repo/publishing/AbstractPublishingIntegrationTest.java

132 lines
4.5 KiB
Java

/*
* Copyright (C) 2005-2011 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.publishing;
import static org.alfresco.repo.publishing.PublishingModel.TYPE_DELIVERY_CHANNEL;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import javax.transaction.Status;
import javax.transaction.UserTransaction;
import org.alfresco.model.ContentModel;
import org.alfresco.repo.security.authentication.AuthenticationUtil;
import org.alfresco.service.ServiceRegistry;
import org.alfresco.service.cmr.model.FileFolderService;
import org.alfresco.service.cmr.publishing.channels.ChannelType;
import org.alfresco.service.cmr.repository.NodeRef;
import org.alfresco.service.cmr.repository.NodeService;
import org.alfresco.service.cmr.site.SiteService;
import org.alfresco.service.cmr.site.SiteVisibility;
import org.alfresco.util.BaseSpringTest;
import org.alfresco.util.GUID;
import org.junit.After;
import org.junit.Before;
/**
* @author Nick Smith
* @since 4.0
*
*/
public abstract class AbstractPublishingIntegrationTest extends BaseSpringTest
{
protected static final String channelTypeId = "MockChannelType";
protected PublishingRootObject rootObject;
protected ServiceRegistry serviceRegistry;
protected SiteService siteService;
protected FileFolderService fileFolderService;
protected NodeService nodeService;
protected String siteId;
protected PublishingQueueImpl queue;
protected Environment environment;
protected NodeRef docLib;
protected UserTransaction transaction;
@Override
@Before
public void onSetUp() throws Exception
{
super.onSetUp();
this.rootObject = (PublishingRootObject) getApplicationContext().getBean("publishingRootObject");
serviceRegistry = (ServiceRegistry) getApplicationContext().getBean("ServiceRegistry");
AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
this.siteService = serviceRegistry.getSiteService();
this.fileFolderService = serviceRegistry.getFileFolderService();
this.nodeService = serviceRegistry.getNodeService();
transaction = serviceRegistry.getTransactionService().getUserTransaction();
transaction.begin();
transaction.setRollbackOnly();
this.siteId = GUID.generate();
siteService.createSite("test", siteId,
"Site created by publishing test",
"Site created by publishing test",
SiteVisibility.PUBLIC);
this.docLib = siteService.createContainer(siteId, SiteService.DOCUMENT_LIBRARY, ContentModel.TYPE_FOLDER, null);
this.environment = rootObject.getEnvironment();
this.queue = rootObject.getPublishingQueue();
}
@After
public void onTearDown() throws Exception
{
AuthenticationUtil.setAdminUserAsFullyAuthenticatedUser();
siteService.deleteSite(siteId);
try
{
if (transaction.getStatus() == Status.STATUS_MARKED_ROLLBACK)
{
transaction.rollback();
}
else
{
transaction.commit();
}
}
catch (Exception e)
{
e.printStackTrace();
throw new RuntimeException(e);
}
super.onTearDown();
}
protected ChannelType mockChannelType()
{
ChannelType channelType = mock(ChannelType.class);
mockChannelTypeBehaviour(channelType);
return channelType;
}
protected void mockChannelTypeBehaviour(ChannelType channelType)
{
when(channelType.getId()).thenReturn(channelTypeId);
when(channelType.getChannelNodeType()).thenReturn(TYPE_DELIVERY_CHANNEL);
}
}