mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-09-17 14:21:39 +00:00
ACS-1607 : Update & tests for ContentServiceImpl (#488)
- added impl and tests
This commit is contained in:
@@ -25,6 +25,13 @@
|
||||
*/
|
||||
package org.alfresco.repo.content;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.ContentServicePolicies.OnContentPropertyUpdatePolicy;
|
||||
@@ -62,13 +69,6 @@ import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.extensions.surf.util.I18NUtil;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* Service implementation acting as a level of indirection between the client
|
||||
* and the underlying content store.
|
||||
@@ -586,4 +586,69 @@ public class ContentServiceImpl implements ContentService, ApplicationContextAwa
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isStorageClassesSupported(Set<String> storageClasses)
|
||||
{
|
||||
return store.isStorageClassesSupported(storageClasses);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getSupportedStorageClasses()
|
||||
{
|
||||
return store.getSupportedStorageClasses();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateStorageClasses(NodeRef nodeRef, Set<String> storageClasses, Map<String, Object> parameters)
|
||||
{
|
||||
ContentData contentData = getContentData(nodeRef, ContentModel.PROP_CONTENT);
|
||||
|
||||
// check that the URL is available
|
||||
if (contentData == null || contentData.getContentUrl() == null)
|
||||
{
|
||||
throw new IllegalArgumentException("The supplied nodeRef " + nodeRef + " has no content.");
|
||||
}
|
||||
|
||||
if (!isStorageClassesSupported(storageClasses))
|
||||
{
|
||||
throw new UnsupportedStorageClassException(store, storageClasses, "The supplied storage classes are not supported");
|
||||
}
|
||||
|
||||
store.updateStorageClasses(contentData.getContentUrl(), storageClasses, parameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> findStorageClasses(NodeRef nodeRef)
|
||||
{
|
||||
ContentData contentData = getContentData(nodeRef, ContentModel.PROP_CONTENT);
|
||||
|
||||
// check that the URL is available
|
||||
if (contentData == null || contentData.getContentUrl() == null)
|
||||
{
|
||||
throw new IllegalArgumentException("The supplied nodeRef " + nodeRef + " has no content.");
|
||||
}
|
||||
|
||||
return store.findStorageClasses(contentData.getContentUrl());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Set<String>, Set<Set<String>>> getStorageClassesTransitions()
|
||||
{
|
||||
return store.getStorageClassesTransitions();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<Set<String>, Set<Set<String>>> findStorageClassesTransitions(NodeRef nodeRef)
|
||||
{
|
||||
ContentData contentData = getContentData(nodeRef, ContentModel.PROP_CONTENT);
|
||||
|
||||
// check that the URL is available
|
||||
if (contentData == null || contentData.getContentUrl() == null)
|
||||
{
|
||||
throw new IllegalArgumentException("The supplied nodeRef " + nodeRef + " has no content.");
|
||||
}
|
||||
|
||||
return store.findStorageClassesTransitions(contentData.getContentUrl());
|
||||
}
|
||||
}
|
@@ -191,6 +191,7 @@ import org.junit.runners.Suite;
|
||||
org.alfresco.repo.content.caching.quota.StandardQuotaStrategyMockTest.class,
|
||||
org.alfresco.repo.content.caching.quota.UnlimitedQuotaStrategyTest.class,
|
||||
org.alfresco.repo.content.caching.CachingContentStoreTest.class,
|
||||
org.alfresco.repo.version.ContentServiceImplWithMockedContentStoreTest.class,
|
||||
org.alfresco.repo.content.caching.ContentCacheImplTest.class,
|
||||
org.alfresco.repo.domain.permissions.FixedAclUpdaterUnitTest.class,
|
||||
org.alfresco.repo.domain.propval.PropertyTypeConverterTest.class,
|
||||
|
@@ -25,30 +25,23 @@
|
||||
*/
|
||||
package org.alfresco.repo.version;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import java.util.Date;
|
||||
|
||||
import org.alfresco.model.ContentModel;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.repo.content.EmptyContentReader;
|
||||
import org.alfresco.repo.content.MimetypeMap;
|
||||
import org.alfresco.repo.content.MimetypeMapTest;
|
||||
import org.alfresco.service.cmr.repository.ContentReader;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.alfresco.service.cmr.repository.ContentWriter;
|
||||
import org.alfresco.service.cmr.repository.NoTransformerException;
|
||||
import org.alfresco.service.cmr.repository.NodeRef;
|
||||
import org.alfresco.service.cmr.repository.TransformationOptions;
|
||||
import org.alfresco.service.cmr.version.Version;
|
||||
import org.alfresco.service.namespace.QName;
|
||||
import org.alfresco.test_category.OwnJVMTestsCategory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.experimental.categories.Category;
|
||||
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* Tests for getting content readers and writers.
|
||||
*
|
||||
@@ -179,4 +172,18 @@ public class ContentServiceImplTest extends BaseVersionStoreTest
|
||||
assertEquals(null, contentService.getDirectAccessUrl(nodeRef, null));
|
||||
assertEquals(null, contentService.getDirectAccessUrl(nodeRef, expiresAt));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindStorageClasses()
|
||||
{
|
||||
final NodeRef newNode = createNewNode();
|
||||
assertTrue(contentService.findStorageClasses(newNode).isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindStorageClassesTransitions()
|
||||
{
|
||||
final NodeRef newNode = createNewNode();
|
||||
assertNotNull(contentService.findStorageClassesTransitions(newNode));
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,88 @@
|
||||
/*
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
* the paid license agreement will prevail. Otherwise, the software is
|
||||
* provided under the following open source license terms:
|
||||
*
|
||||
* 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/>.
|
||||
* #L%
|
||||
*/
|
||||
package org.alfresco.repo.version;
|
||||
|
||||
import static java.util.Collections.emptyMap;
|
||||
import static java.util.Collections.emptySet;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import org.alfresco.repo.content.ContentServiceImpl;
|
||||
import org.alfresco.repo.content.ContentStore;
|
||||
import org.alfresco.service.cmr.repository.ContentService;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.springframework.test.util.ReflectionTestUtils;
|
||||
|
||||
/**
|
||||
* Tests for the CachingContentStore class. Tests use mock backing store and cache.
|
||||
*
|
||||
* @author Lucian Tuca
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ContentServiceImplWithMockedContentStoreTest
|
||||
{
|
||||
@Mock
|
||||
private ContentStore store;
|
||||
|
||||
private ContentService contentService;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception
|
||||
{
|
||||
contentService = new ContentServiceImpl();
|
||||
ReflectionTestUtils.setField(contentService, "store", store);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreIsCalledForIsStorageClassesSupported()
|
||||
{
|
||||
when(store.isStorageClassesSupported(emptySet())).thenReturn(true);
|
||||
assertTrue(contentService.isStorageClassesSupported(emptySet()));
|
||||
verify(store, times(1)).isStorageClassesSupported(emptySet());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreIsCalledForGetSupportedStorageClasses()
|
||||
{
|
||||
when(store.getSupportedStorageClasses()).thenReturn(emptySet());
|
||||
assertTrue(contentService.getSupportedStorageClasses().isEmpty());
|
||||
verify(store, times(1)).getSupportedStorageClasses();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreIsCalledForGetStorageClassesTransitions()
|
||||
{
|
||||
when(store.getStorageClassesTransitions()).thenReturn(emptyMap());
|
||||
assertTrue(contentService.getStorageClassesTransitions().isEmpty());
|
||||
verify(store, times(1)).getStorageClassesTransitions();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user