Add unit tests, ignore override if empty

This commit is contained in:
canpan14 2023-07-12 11:07:51 -04:00
parent 70430ea96c
commit 3215bc50c6
2 changed files with 39 additions and 3 deletions

View File

@ -65,6 +65,7 @@ import org.alfresco.service.cmr.usage.ContentQuotaException;
import org.alfresco.service.namespace.QName;
import org.alfresco.util.EqualsHelper;
import org.alfresco.util.TempFileProvider;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.BeansException;
@ -643,7 +644,7 @@ public class ContentServiceImpl implements ContentService, ApplicationContextAwa
String contentUrl = contentData.getContentUrl();
String contentMimetype = contentData.getMimetype();
String fileName = fileNameOverride == null ? getFileName(nodeRef) : fileNameOverride;
String fileName = StringUtils.isEmpty(fileNameOverride) ? getFileName(nodeRef) : fileNameOverride;
validFor = adjustValidFor(validFor);
attachment = adjustAttachment(nodeRef, contentMimetype, attachment);

View File

@ -72,7 +72,8 @@ public class ContentServiceImplUnitTest
private static final NodeRef NODE_REF = new NodeRef("content://Node/Ref");
public static final String SOME_CONTENT_URL = "someContentUrl";
private static final NodeRef NODE_REF_2 = new NodeRef("content://Node/Ref2");;
private static final NodeRef NODE_REF_2 = new NodeRef("content://Node/Ref2");
public static final String SOME_FILE_NAME = "someFilename";
private static final String X_AMZ_HEADER_1 = "x-amz-header1";
private static final String VALUE_1 = "value1";
@ -103,7 +104,7 @@ public class ContentServiceImplUnitTest
when(mockNodeService.getProperty(NODE_REF, ContentModel.PROP_CONTENT)).thenReturn(mockContentData);
when(mockContentData.getContentUrl()).thenReturn(SOME_CONTENT_URL);
when(mockContentData.getMimetype()).thenReturn("someMimetype");
when(mockNodeService.getProperty(NODE_REF, ContentModel.PROP_NAME)).thenReturn("someFilename");
when(mockNodeService.getProperty(NODE_REF, ContentModel.PROP_NAME)).thenReturn(SOME_FILE_NAME);
}
@Test
@ -162,6 +163,40 @@ public class ContentServiceImplUnitTest
verify(mockContentStore, times(1)).requestContentDirectUrl(anyString(), eq(true), anyString(), anyString(), anyLong());
}
@Test
public void testRequestContentDirectUrl_StoreRequestContentDirectUrlIsCalledWithFileNameOverride()
{
final String fileNameOverride = "fileNameOverride.txt";
setupSystemWideDirectAccessConfig(ENABLED);
when(mockContentStore.isContentDirectUrlEnabled()).thenReturn(ENABLED);
DirectAccessUrl directAccessUrl = contentService.requestContentDirectUrl(NODE_REF, PROP_CONTENT_QNAME, true, 20L, fileNameOverride);
assertNull(directAccessUrl);
verify(mockContentStore, times(1)).requestContentDirectUrl(anyString(), eq(true), eq(fileNameOverride), anyString(), anyLong());
}
@Test
public void testRequestContentDirectUrl_StoreRequestContentDirectUrlIsCalledWithNodeNamePropertyWhenFileNameOverrideIsNull()
{
setupSystemWideDirectAccessConfig(ENABLED);
when(mockContentStore.isContentDirectUrlEnabled()).thenReturn(ENABLED);
DirectAccessUrl directAccessUrl = contentService.requestContentDirectUrl(NODE_REF, PROP_CONTENT_QNAME, true, 20L, null);
assertNull(directAccessUrl);
verify(mockContentStore, times(1)).requestContentDirectUrl(anyString(), eq(true), eq(SOME_FILE_NAME), anyString(), anyLong());
}
@Test
public void testRequestContentDirectUrl_StoreRequestContentDirectUrlIsCalledWithNodeNamePropertyWhenFileNameOverrideIsEmpty()
{
setupSystemWideDirectAccessConfig(ENABLED);
when(mockContentStore.isContentDirectUrlEnabled()).thenReturn(ENABLED);
DirectAccessUrl directAccessUrl = contentService.requestContentDirectUrl(NODE_REF, PROP_CONTENT_QNAME, true, 20L, "");
assertNull(directAccessUrl);
verify(mockContentStore, times(1)).requestContentDirectUrl(anyString(), eq(true), eq(SOME_FILE_NAME), anyString(), anyLong());
}
@Test
public void shouldReturnStoragePropertiesWhenTheyExist()
{