ACS-2200: Java API for archive/archive-restore content (#825)

* ACS-2200: Java API for archive/archive-restore content + unit tests.

* Bump restapi from 1.64 to 1.65 (#795)

* Bump utility from 3.0.45 to 3.0.47 (#794)

* ACS-2200: Applying review comments.

* ACS-2200: Applying review comments.

* ACS-2200: Adding new unit test to suite.

* ACS-2200: Adding optional archive params to archive operation.

* Bump restapi from 1.64 to 1.65 (#795)

* Bump utility from 3.0.45 to 3.0.47 (#794)

* ACS-2200: Applying review comments.

* ACS-2200: Java API for archive/archive-restore content + unit tests.
This commit is contained in:
mpichura
2021-12-08 16:33:20 +01:00
committed by GitHub
parent 8862645dea
commit 4f1397eeee
14 changed files with 773 additions and 100 deletions

View File

@@ -187,6 +187,7 @@ import org.junit.runners.Suite;
org.alfresco.repo.content.filestore.FileIOTest.class,
org.alfresco.repo.content.filestore.SpoofedTextContentReaderTest.class,
org.alfresco.repo.content.ContentDataTest.class,
org.alfresco.repo.content.replication.AggregatingContentStoreUnitTest.class,
org.alfresco.service.cmr.repository.TransformationOptionLimitsTest.class,
org.alfresco.service.cmr.repository.TransformationOptionPairTest.class,
org.alfresco.repo.content.transform.TransformerConfigTestSuite.class,

View File

@@ -30,7 +30,6 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
@@ -54,6 +53,7 @@ import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import java.io.Serializable;
import java.util.Collections;
import java.util.Map;
@@ -205,6 +205,75 @@ public class ContentServiceImplUnitTest
});
}
@Test
public void shouldRequestSendContentToArchiveSucceed()
{
final boolean expectedResult = true;
final Map<String, Serializable> archiveParams = Collections.emptyMap();
when(mockContentStore.requestSendContentToArchive(SOME_CONTENT_URL, archiveParams)).thenReturn(expectedResult);
boolean sendContentToArchive = contentService.requestSendContentToArchive(NODE_REF, ContentModel.PROP_CONTENT, archiveParams);
assertEquals(expectedResult, sendContentToArchive);
}
@Test
public void requestSendContentToArchiveThrowsExceptionWhenNotImplemented()
{
final Map<String, Serializable> archiveParams = Collections.emptyMap();
when(mockContentStore.requestSendContentToArchive(SOME_CONTENT_URL, archiveParams)).thenCallRealMethod();
assertThrows(UnsupportedOperationException.class, () -> {
contentService.requestSendContentToArchive(NODE_REF, ContentModel.PROP_CONTENT, archiveParams);
});
}
@Test
public void requestSendContentToArchiveThrowsExceptionWhenContentNotFound()
{
final String dummyContentProperty = "dummy";
final Map<String, Serializable> archiveParams = Collections.emptyMap();
when(mockNodeService.getProperty(NODE_REF_2, ContentModel.PROP_CONTENT)).thenReturn(dummyContentProperty);
when(mockDictionaryService.getProperty(ContentModel.PROP_CONTENT)).thenReturn(null);
assertThrows(IllegalArgumentException.class, () -> {
contentService.requestSendContentToArchive(NODE_REF_2, ContentModel.PROP_CONTENT, archiveParams);
});
}
@Test
public void requestRestoreContentFromArchiveThrowsExceptionWhenContentNotFound()
{
final String dummyContentProperty = "dummy";
when(mockNodeService.getProperty(NODE_REF_2, ContentModel.PROP_CONTENT)).thenReturn(dummyContentProperty);
when(mockDictionaryService.getProperty(ContentModel.PROP_CONTENT)).thenReturn(null);
final Map<String, Serializable> restoreParams = Map.of(ContentRestoreParams.RESTORE_PRIORITY.name(), "High");
assertThrows(IllegalArgumentException.class, () -> {
contentService.requestRestoreContentFromArchive(NODE_REF_2, ContentModel.PROP_CONTENT, restoreParams);
});
}
@Test
public void shouldRequestRestoreContentFromArchiveSucceed()
{
final boolean expectedResult = true;
final Map<String, Serializable> restoreParams = Map.of(ContentRestoreParams.RESTORE_PRIORITY.name(), "High");
when(mockContentStore.requestRestoreContentFromArchive(SOME_CONTENT_URL, restoreParams)).thenReturn(expectedResult);
boolean restoreContentFromArchive =
contentService.requestRestoreContentFromArchive(NODE_REF, ContentModel.PROP_CONTENT, restoreParams);
assertEquals(expectedResult, restoreContentFromArchive);
}
@Test
public void requestRestoreContentFromArchiveThrowsExceptionWhenNotImplemented()
{
final Map<String, Serializable> restoreParams = Map.of(ContentRestoreParams.RESTORE_PRIORITY.name(), "High");
when(mockContentStore.requestRestoreContentFromArchive(SOME_CONTENT_URL, restoreParams)).thenCallRealMethod();
assertThrows(UnsupportedOperationException.class, () -> {
contentService.requestRestoreContentFromArchive(NODE_REF, ContentModel.PROP_CONTENT, restoreParams);
});
}
/* Helper method to set system-wide direct access url configuration settings */
private void setupSystemWideDirectAccessConfig(Boolean isEnabled)
{

View File

@@ -29,6 +29,7 @@ package org.alfresco.repo.content.caching;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -45,10 +46,13 @@ import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.io.Serializable;
import java.util.Collections;
import java.util.Locale;
import java.util.Map;
import org.alfresco.repo.content.ContentContext;
import org.alfresco.repo.content.ContentRestoreParams;
import org.alfresco.repo.content.ContentStore;
import org.alfresco.repo.content.caching.quota.QuotaManagerStrategy;
import org.alfresco.repo.content.caching.quota.UnlimitedQuotaStrategy;
@@ -540,4 +544,54 @@ public class CachingContentStoreTest
Map<String, String> storageProperties = cachingStore.getStorageProperties("url");
assertTrue(storageProperties.isEmpty());
}
@Test
public void shouldCompleteArchiveContentRequest()
{
final boolean expectedResult = true;
final String contentUrl = "url";
final Map<String, Serializable> archiveParams = Collections.emptyMap();
when(backingStore.requestSendContentToArchive(contentUrl, archiveParams)).thenReturn(expectedResult);
final boolean sendContentToArchive = cachingStore.requestSendContentToArchive(contentUrl, archiveParams);
assertEquals(expectedResult, sendContentToArchive);
}
@Test
public void shouldThrowExceptionOnArchiveContentRequest()
{
final String contentUrl = "url";
final Map<String, Serializable> archiveParams = Collections.emptyMap();
when(backingStore.requestSendContentToArchive(contentUrl, archiveParams)).thenCallRealMethod();
assertThrows(UnsupportedOperationException.class, () -> {
cachingStore.requestSendContentToArchive(contentUrl, archiveParams);
});
}
@Test
public void shouldCompleteRestoreContentFromArchiveRequest()
{
final String contentUrl = "url";
final Map<String, Serializable> restoreParams = Map.of(ContentRestoreParams.RESTORE_PRIORITY.name(), "High");
final boolean expectedResult = true;
when(backingStore.requestRestoreContentFromArchive(contentUrl, restoreParams)).thenReturn(expectedResult);
final boolean sendContentToArchive = cachingStore.requestRestoreContentFromArchive(contentUrl, restoreParams);
assertEquals(expectedResult, sendContentToArchive);
}
@Test
public void shouldThrowExceptionOnRestoreContentFromArchiveRequest()
{
final String contentUrl = "url";
final Map<String, Serializable> restoreParams = Map.of(ContentRestoreParams.RESTORE_PRIORITY.name(), "High");
when(backingStore.requestRestoreContentFromArchive(contentUrl, restoreParams)).thenCallRealMethod();
assertThrows(UnsupportedOperationException.class, () -> {
cachingStore.requestRestoreContentFromArchive(contentUrl, restoreParams);
});
}
}

View File

@@ -27,9 +27,7 @@ package org.alfresco.repo.content.replication;
import java.io.File;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import org.alfresco.repo.content.AbstractWritableContentStoreTest;
import org.alfresco.repo.content.ContentContext;
@@ -60,8 +58,6 @@ import static org.junit.Assert.fail;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/**
* Tests read and write functionality for the aggregating store.
@@ -316,48 +312,4 @@ public class AggregatingContentStoreTest extends AbstractWritableContentStoreTes
assertNotNull(directAccessUrl);
}
@Test
public void shouldReturnStoragePropertiesFromPrimaryStore()
{
final String contentUrl = "url";
final Map<String, String> primaryStorePropertiesMap = Map.of(X_AMZ_HEADER_1, VALUE_1, X_AMZ_HEADER_2, VALUE_2);;
when(primaryStoreMock.getStorageProperties(contentUrl)).thenReturn(primaryStorePropertiesMap);
final Map<String, String> storageProperties = aggregatingStore.getStorageProperties(contentUrl);
assertFalse(storageProperties.isEmpty());
assertEquals(primaryStorePropertiesMap, storageProperties);
verify(secondaryStoreMock, times(0)).getStorageProperties(contentUrl);
}
@Test
public void shouldReturnStoragePropertiesFromSecondaryStore()
{
final String contentUrl = "url";
final Map<String, String> secondaryStorePropertiesMap = Map.of(X_AMZ_HEADER_1, VALUE_1, X_AMZ_HEADER_2, VALUE_2);;
when(primaryStoreMock.getStorageProperties(contentUrl)).thenReturn(Collections.emptyMap());
when(secondaryStoreMock.getStorageProperties(contentUrl)).thenReturn(secondaryStorePropertiesMap);
final Map<String, String> storageProperties = aggregatingStore.getStorageProperties(contentUrl);
assertFalse(storageProperties.isEmpty());
assertEquals(secondaryStorePropertiesMap, storageProperties);
verify(secondaryStoreMock, times(1)).getStorageProperties(contentUrl);
verify(primaryStoreMock, times(1)).getStorageProperties(contentUrl);
}
@Test
public void shouldReturnEmptyStorageProperties()
{
final String contentUrl = "url";
when(primaryStoreMock.getStorageProperties(contentUrl)).thenReturn(Collections.emptyMap());
when(secondaryStoreMock.getStorageProperties(contentUrl)).thenReturn(Collections.emptyMap());
final Map<String, String> storageProperties = aggregatingStore.getStorageProperties(contentUrl);
assertTrue(storageProperties.isEmpty());
verify(secondaryStoreMock, times(1)).getStorageProperties(contentUrl);
verify(primaryStoreMock, times(1)).getStorageProperties(contentUrl);
}
}

View File

@@ -0,0 +1,219 @@
/*
* #%L
* Alfresco Remote API
* %%
* Copyright (C) 2005 - 2021 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.content.replication;
import org.alfresco.repo.content.ContentRestoreParams;
import org.alfresco.repo.content.ContentStore;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.io.Serializable;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThrows;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
/**
* Unit tests class for {@code AggregatingContentStore}
*
* Currently does not cover all methods.
*
* @author mpichura
*/
@RunWith(MockitoJUnitRunner.class)
public class AggregatingContentStoreUnitTest
{
private static final String X_AMZ_HEADER_1 = "x-amz-header1";
private static final String VALUE_1 = "value1";
private static final String X_AMZ_HEADER_2 = "x-amz-header2";
private static final String VALUE_2 = "value2";
private List<ContentStore> secondaryStores;
@Mock
ContentStore primaryStore;
@Mock
ContentStore secondaryStore;
@InjectMocks
private AggregatingContentStore objectUnderTest;
@Before
public void setUp() {
secondaryStores = List.of(secondaryStore);
objectUnderTest.setSecondaryStores(secondaryStores);
}
@Test
public void shouldReturnStoragePropertiesFromPrimaryStore()
{
final String contentUrl = "url";
final Map<String, String> primaryStorePropertiesMap = Map.of(X_AMZ_HEADER_1, VALUE_1, X_AMZ_HEADER_2, VALUE_2);;
when(primaryStore.getStorageProperties(contentUrl)).thenReturn(primaryStorePropertiesMap);
final Map<String, String> storageProperties = objectUnderTest.getStorageProperties(contentUrl);
assertFalse(storageProperties.isEmpty());
assertEquals(primaryStorePropertiesMap, storageProperties);
verify(secondaryStore, times(0)).getStorageProperties(contentUrl);
}
@Test
public void shouldReturnStoragePropertiesFromSecondaryStore()
{
final String contentUrl = "url";
final Map<String, String> secondaryStorePropertiesMap = Map.of(X_AMZ_HEADER_1, VALUE_1, X_AMZ_HEADER_2, VALUE_2);;
when(primaryStore.getStorageProperties(contentUrl)).thenReturn(Collections.emptyMap());
when(secondaryStore.getStorageProperties(contentUrl)).thenReturn(secondaryStorePropertiesMap);
final Map<String, String> storageProperties = objectUnderTest.getStorageProperties(contentUrl);
assertFalse(storageProperties.isEmpty());
assertEquals(secondaryStorePropertiesMap, storageProperties);
verify(secondaryStore, times(1)).getStorageProperties(contentUrl);
verify(primaryStore, times(1)).getStorageProperties(contentUrl);
}
@Test
public void shouldReturnEmptyStorageProperties()
{
final String contentUrl = "url";
when(primaryStore.getStorageProperties(contentUrl)).thenReturn(Collections.emptyMap());
when(secondaryStore.getStorageProperties(contentUrl)).thenReturn(Collections.emptyMap());
final Map<String, String> storageProperties = objectUnderTest.getStorageProperties(contentUrl);
assertTrue(storageProperties.isEmpty());
verify(primaryStore, times(1)).getStorageProperties(contentUrl);
}
@Test
public void shouldRequestContentArchiveThroughPrimaryStore()
{
final String contentUrl = "url";
final boolean expectedResult = true;
final Map<String, Serializable> archiveParams = Collections.emptyMap();
when(primaryStore.requestSendContentToArchive(contentUrl, archiveParams)).thenReturn(expectedResult);
boolean sendContentToArchive = objectUnderTest.requestSendContentToArchive(contentUrl, archiveParams);
assertEquals(expectedResult, sendContentToArchive);
verify(secondaryStore, never()).requestSendContentToArchive(contentUrl,archiveParams);
}
@Test
public void shouldRequestContentArchiveThroughSecondaryStore()
{
final String contentUrl = "url";
final boolean expectedResult = true;
final Map<String, Serializable> archiveParams = Collections.emptyMap();
when(primaryStore.requestSendContentToArchive(contentUrl, archiveParams)).thenThrow(UnsupportedOperationException.class);
when(secondaryStore.requestSendContentToArchive(contentUrl, archiveParams)).thenReturn(expectedResult);
boolean sendContentToArchive = objectUnderTest.requestSendContentToArchive(contentUrl, archiveParams);
assertEquals(expectedResult, sendContentToArchive);
verify(primaryStore, times(1)).requestSendContentToArchive(contentUrl, archiveParams);
verify(secondaryStore, times(1)).requestSendContentToArchive(contentUrl, archiveParams);
}
@Test
public void shouldThrowExceptionWhenRequestContentArchiveNotImplemented()
{
final String contentUrl = "url";
when(primaryStore.getStorageProperties(contentUrl)).thenReturn(Collections.emptyMap());
when(secondaryStore.getStorageProperties(contentUrl)).thenReturn(Collections.emptyMap());
final Map<String, String> storageProperties = objectUnderTest.getStorageProperties(contentUrl);
assertTrue(storageProperties.isEmpty());
verify(primaryStore, times(1)).getStorageProperties(contentUrl);
}
@Test
public void shouldRequestRestoreContentFromArchiveThroughPrimaryStore()
{
final String contentUrl = "url";
final boolean expectedResult = true;
final Map<String, Serializable> restoreParams = Map.of(ContentRestoreParams.RESTORE_PRIORITY.name(), "High");
when(primaryStore.requestRestoreContentFromArchive(contentUrl, restoreParams)).thenReturn(expectedResult);
boolean sendContentToArchive = objectUnderTest.requestRestoreContentFromArchive(contentUrl, restoreParams);
assertEquals(expectedResult, sendContentToArchive);
verify(secondaryStore, never()).requestRestoreContentFromArchive(contentUrl, restoreParams);
}
@Test
public void shouldRequestRestoreContentFromArchiveThroughSecondaryStore()
{
final String contentUrl = "url";
final boolean expectedResult = true;
final Map<String, Serializable> restoreParams = Map.of(ContentRestoreParams.RESTORE_PRIORITY.name(), "High");
when(primaryStore.requestRestoreContentFromArchive(contentUrl, restoreParams)).thenThrow(UnsupportedOperationException.class);
when(secondaryStore.requestRestoreContentFromArchive(contentUrl, restoreParams)).thenReturn(expectedResult);
boolean sendContentToArchive = objectUnderTest.requestRestoreContentFromArchive(contentUrl, restoreParams);
assertEquals(expectedResult, sendContentToArchive);
verify(primaryStore, times(1)).requestRestoreContentFromArchive(contentUrl, restoreParams);
verify(secondaryStore, times(1)).requestRestoreContentFromArchive(contentUrl, restoreParams);
}
@Test
public void shouldThrowExceptionWhenRequestRestoreContentFromArchiveNotImplemented()
{
final String contentUrl = "url";
final Map<String, Serializable> restoreParams = Map.of(ContentRestoreParams.RESTORE_PRIORITY.name(), "High");
when(primaryStore.requestRestoreContentFromArchive(contentUrl, restoreParams)).thenCallRealMethod();
when(secondaryStore.requestRestoreContentFromArchive(contentUrl, restoreParams)).thenCallRealMethod();
assertThrows(UnsupportedOperationException.class, () -> {
objectUnderTest.requestRestoreContentFromArchive(contentUrl, restoreParams);
});
verify(primaryStore, times(1)).requestRestoreContentFromArchive(contentUrl, restoreParams);
verify(secondaryStore, times(1)).requestRestoreContentFromArchive(contentUrl, restoreParams);
}
}