forked from fegorama/alfviral
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from TIBHannover/fix-nullable-contentreader
Fix nullable contentreader
- Loading branch information
Showing
2 changed files
with
71 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
alfviral/src/test/java/com/fegor/alfresco/services/AntivirusServiceImplTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.fegor.alfresco.services; | ||
|
||
import static org.junit.Assert.fail; | ||
import static org.mockito.Mockito.when; | ||
|
||
import org.alfresco.service.ServiceRegistry; | ||
import org.alfresco.service.cmr.repository.ContentService; | ||
import org.alfresco.service.cmr.repository.NodeRef; | ||
import org.alfresco.service.cmr.repository.NodeService; | ||
import org.alfresco.service.namespace.QName; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.MockitoJUnitRunner; | ||
|
||
@RunWith(MockitoJUnitRunner.class) | ||
public class AntivirusServiceImplTest { | ||
|
||
private AntivirusServiceImpl service; | ||
private NodeRef testNode; | ||
|
||
@Mock | ||
private ServiceRegistry serviceRegistry; | ||
@Mock | ||
private NodeService nodeService; | ||
@Mock | ||
private ContentService contentService; | ||
|
||
@Before | ||
public void setup() { | ||
service = new AntivirusServiceImpl(); | ||
service.setServiceRegistry(serviceRegistry); | ||
testNode = new NodeRef("workspace://TestStore/test"); | ||
service.setFileExceptions("text/html|text/xml|application/pdf|image/jpeg|image/png|image/giftext/plain"); | ||
service.setFileOnly("application/octet-stream|application/x-dosexec|application/bat|application/x-bat|application/x-msdos-program|application/textedit|application/cmd|application/x-ms-dos-executable"); | ||
service.setFileOnlyOrExceptions("exceptions"); | ||
} | ||
|
||
@Test | ||
public void testNullContentReader() { | ||
when(serviceRegistry.getNodeService()).thenReturn(nodeService); | ||
when(serviceRegistry.getContentService()).thenReturn(contentService); | ||
when(nodeService.exists(testNode)).thenReturn(true); | ||
when(contentService.getReader(Mockito.any(NodeRef.class), Mockito.any(QName.class))).thenReturn(null); | ||
|
||
try { | ||
service.scanFile(testNode); | ||
} catch (Exception e) { | ||
fail("There should be no exception when the content reader is null"); | ||
} | ||
} | ||
} |