diff --git a/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/dictionary/TypeServiceUnitTest.java b/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/dictionary/TypeServiceUnitTest.java index 117702eb..e4de53dc 100644 --- a/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/dictionary/TypeServiceUnitTest.java +++ b/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/dictionary/TypeServiceUnitTest.java @@ -6,6 +6,7 @@ import eu.xenit.alfred.api.alfresco.AlfredApiToAlfrescoConversion; import eu.xenit.alfred.api.alfresco.dictionary.TypeService; import eu.xenit.alfred.api.data.QName; +import org.alfresco.service.ServiceRegistry; import org.alfresco.service.cmr.dictionary.DictionaryService; import org.alfresco.service.namespace.NamespaceException; import org.junit.jupiter.api.Assertions; @@ -20,11 +21,14 @@ public class TypeServiceUnitTest { @Test public void testGetTypeDefinition_returnsNull_whenQnameInvalid() { + ServiceRegistry serviceRegistryMock = mock(ServiceRegistry.class); + when(serviceRegistryMock.getNamespaceService()).thenReturn(null); + when(serviceRegistryMock.getDictionaryService()).thenReturn(null); + QName invalidQname = new QName("someNamespace:someQname"); - DictionaryService dictionaryServiceMock = mock(DictionaryService.class); AlfredApiToAlfrescoConversion alfredApiToAlfrescoConversionMock = mock(AlfredApiToAlfrescoConversion.class); when(alfredApiToAlfrescoConversionMock.alfresco(invalidQname)).thenThrow(NamespaceException.class); - TypeService typeService = new TypeService(dictionaryServiceMock, alfredApiToAlfrescoConversionMock); + TypeService typeService = new TypeService(serviceRegistryMock, alfredApiToAlfrescoConversionMock); Assertions.assertNull(typeService.GetTypeDefinition(invalidQname), "[FAIL] An invalid qname did not result in a null response."); } diff --git a/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/AncestorsFromInaccessibleNodeUnitTest.java b/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/AncestorsFromInaccessibleNodeUnitTest.java index 54359161..5fdfe924 100644 --- a/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/AncestorsFromInaccessibleNodeUnitTest.java +++ b/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/AncestorsFromInaccessibleNodeUnitTest.java @@ -47,7 +47,7 @@ public void getAncestorsOfNodeTest() { Assertions.assertThrows(AccessDeniedException.class, ()->{ eu.xenit.alfred.api.alfresco.metadata.NodeService alfredApiNodeService = new eu.xenit.alfred.api.alfresco.metadata.NodeService( - serviceRegistry, alfredApiAlfrescoConverter); + serviceRegistry, alfredApiAlfrescoConverter, null); NodeRef rootRef = new NodeRef(testNode3.toString()); NodeRef testNode = new NodeRef(testNode1.toString()); alfredApiNodeService.getAncestors(testNode, rootRef); diff --git a/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/AncestorsFromNodeUnitTest.java b/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/AncestorsFromNodeUnitTest.java index 6abf692d..91e4c33e 100644 --- a/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/AncestorsFromNodeUnitTest.java +++ b/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/AncestorsFromNodeUnitTest.java @@ -42,7 +42,7 @@ public void getAncestorsOfNodeTest() { NodeService alfrescoNodeService = serviceRegistry.getNodeService(); eu.xenit.alfred.api.alfresco.metadata.NodeService alfredApiNodeService = new eu.xenit.alfred.api.alfresco.metadata.NodeService( - serviceRegistry, alfredApiAlfrescoConverter); + serviceRegistry, alfredApiAlfrescoConverter, null); NodeRef rootRef = new NodeRef(testNode3.toString()); NodeRef testNode = new NodeRef(testNode1.toString()); List ancestors = alfredApiNodeService.getAncestors(testNode, rootRef); diff --git a/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/AncestorsFromNonExistingNodeUnitTest.java b/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/AncestorsFromNonExistingNodeUnitTest.java index 98c9d605..ec355c1e 100644 --- a/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/AncestorsFromNonExistingNodeUnitTest.java +++ b/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/AncestorsFromNonExistingNodeUnitTest.java @@ -36,7 +36,7 @@ public void getAncestorsOfNodeTest() { Assertions.assertThrows(InvalidNodeRefException.class, ()->{ eu.xenit.alfred.api.alfresco.metadata.NodeService alfredApiNodeService = new eu.xenit.alfred.api.alfresco.metadata.NodeService( - serviceRegistry, alfredApiAlfrescoConverter); + serviceRegistry, alfredApiAlfrescoConverter, null); NodeRef rootRef = new NodeRef(testNode3.toString()); NodeRef testNode = new NodeRef(testNode1.toString()); diff --git a/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/RenameUnitTest.java b/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/RenameUnitTest.java index e8129e0e..00a83bf8 100644 --- a/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/RenameUnitTest.java +++ b/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/RenameUnitTest.java @@ -78,7 +78,7 @@ public void testSetNameCallsRenameOfFileFolderService() { MetadataChanges metadataChanges = new MetadataChanges(null, aspectsToAdd, aspectsToRemove, propertiesToSet); eu.xenit.alfred.api.alfresco.metadata.NodeService alfredApiNodeService = new eu.xenit.alfred.api.alfresco.metadata.NodeService( - serviceRegistry, alfredApiAlfrescoConverter); + serviceRegistry, alfredApiAlfrescoConverter, null); alfredApiNodeService.setMetadata(nodeRef, metadataChanges); //We have to make sure that the rename method of the file folder service was called once. diff --git a/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/SetMetadataUnitTest.java b/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/SetMetadataUnitTest.java index be366c5c..8f69c7b2 100644 --- a/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/SetMetadataUnitTest.java +++ b/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/metadata/SetMetadataUnitTest.java @@ -65,8 +65,8 @@ public void init() { when(serviceRegistryMock.getDictionaryService()).thenReturn(dictionaryServiceMock); //Initialization of nodeService - nodeService = new eu.xenit.alfred.api.alfresco.metadata.NodeService(serviceRegistryMock, - alfredApiAlfrescoConverter); + nodeService = new eu.xenit.alfred.api.alfresco.metadata.NodeService( + serviceRegistryMock, alfredApiAlfrescoConverter, null); } private NodeService initNodeServiceMock() { @@ -207,11 +207,13 @@ public void testGeneralizeTypeWithCleanUpEnabled() { Set targetTypeSet = new HashSet<>(); targetTypeSet.add(targetType); - MetadataChanges changes = new MetadataChanges(alfredApiAlfrescoConverter.alfredApiQNames(targetTypeSet).iterator().next() + MetadataChanges changes = new MetadataChanges( + alfredApiAlfrescoConverter.alfredApiQNames(targetTypeSet).iterator().next() , true, null, null, null); Set testNodeRefSet = new HashSet<>(); testNodeRefSet.add(testNodeRef); - eu.xenit.alfred.api.data.NodeRef alfredApiTestNodeRef = alfredApiAlfrescoConverter.alfredApiNodeRefs(testNodeRefSet).iterator() + eu.xenit.alfred.api.data.NodeRef alfredApiTestNodeRef = alfredApiAlfrescoConverter.alfredApiNodeRefs( + testNodeRefSet).iterator() .next(); eu.xenit.alfred.api.alfresco.metadata.NodeService nodeServiceSpy = spy(nodeService); nodeServiceSpy.setMetadata(alfredApiTestNodeRef, changes); @@ -232,11 +234,13 @@ public void testGeneralizeTypeWithCleanUpEnabledAndAdditionalAspects() { targetTypeSet.add(targetType); eu.xenit.alfred.api.data.QName[] aspectsToAdd = new eu.xenit.alfred.api.data.QName[1]; aspectsToAdd[0] = new eu.xenit.alfred.api.data.QName(ASPECT4); - MetadataChanges changes = new MetadataChanges(alfredApiAlfrescoConverter.alfredApiQNames(targetTypeSet).iterator().next() + MetadataChanges changes = new MetadataChanges( + alfredApiAlfrescoConverter.alfredApiQNames(targetTypeSet).iterator().next() , true, aspectsToAdd, null, null); Set testNodeRefSet = new HashSet<>(); testNodeRefSet.add(testNodeRef); - eu.xenit.alfred.api.data.NodeRef alfredApiTestNodeRef = alfredApiAlfrescoConverter.alfredApiNodeRefs(testNodeRefSet).iterator() + eu.xenit.alfred.api.data.NodeRef alfredApiTestNodeRef = alfredApiAlfrescoConverter.alfredApiNodeRefs( + testNodeRefSet).iterator() .next(); nodeService.setMetadata(alfredApiTestNodeRef, changes); @@ -256,18 +260,21 @@ public void testGeneralizeTypeWithCleanUpEnabledAndAddingAspectToBeCleanedUp() { targetTypeSet.add(targetType); eu.xenit.alfred.api.data.QName[] aspectsToAdd = new eu.xenit.alfred.api.data.QName[1]; aspectsToAdd[0] = new eu.xenit.alfred.api.data.QName(ASPECT3); - MetadataChanges changes = new MetadataChanges(alfredApiAlfrescoConverter.alfredApiQNames(targetTypeSet).iterator().next() + MetadataChanges changes = new MetadataChanges( + alfredApiAlfrescoConverter.alfredApiQNames(targetTypeSet).iterator().next() , true, aspectsToAdd, null, null); Set testNodeRefSet = new HashSet<>(); testNodeRefSet.add(testNodeRef); - eu.xenit.alfred.api.data.NodeRef alfredApiTestNodeRef = alfredApiAlfrescoConverter.alfredApiNodeRefs(testNodeRefSet).iterator() + eu.xenit.alfred.api.data.NodeRef alfredApiTestNodeRef = alfredApiAlfrescoConverter.alfredApiNodeRefs( + testNodeRefSet).iterator() .next(); nodeService.setMetadata(alfredApiTestNodeRef, changes); InOrder inOrder = inOrder(nodeServiceAlfrescoMock); inOrder.verify(nodeServiceAlfrescoMock).setType(eq(testNodeRef), eq(targetType)); inOrder.verify(nodeServiceAlfrescoMock).removeAspect(eq(testNodeRef), eq(QName.createQName(ASPECT3))); - inOrder.verify(nodeServiceAlfrescoMock).addAspect(eq(testNodeRef), eq(QName.createQName(ASPECT3)), any(Map.class)); + inOrder.verify(nodeServiceAlfrescoMock) + .addAspect(eq(testNodeRef), eq(QName.createQName(ASPECT3)), any(Map.class)); } @Test @@ -278,11 +285,13 @@ public void testGeneralizeTypeWithCleanUpDisabled() { QName targetType = initialTypeDef.getParentName(); Set targetTypeSet = new HashSet<>(); targetTypeSet.add(targetType); - MetadataChanges changes = new MetadataChanges(alfredApiAlfrescoConverter.alfredApiQNames(targetTypeSet).iterator().next() + MetadataChanges changes = new MetadataChanges( + alfredApiAlfrescoConverter.alfredApiQNames(targetTypeSet).iterator().next() , false, null, null, null); Set testNodeRefSet = new HashSet<>(); testNodeRefSet.add(testNodeRef); - eu.xenit.alfred.api.data.NodeRef alfredApiTestNodeRef = alfredApiAlfrescoConverter.alfredApiNodeRefs(testNodeRefSet).iterator() + eu.xenit.alfred.api.data.NodeRef alfredApiTestNodeRef = alfredApiAlfrescoConverter.alfredApiNodeRefs( + testNodeRefSet).iterator() .next(); eu.xenit.alfred.api.alfresco.metadata.NodeService nodeServiceSpy = spy(nodeService); nodeServiceSpy.setMetadata(alfredApiTestNodeRef, changes); diff --git a/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/translations/TranslationsServiceUnitTest.java b/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/translations/TranslationsServiceUnitTest.java index 74631b8a..00f8848a 100644 --- a/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/translations/TranslationsServiceUnitTest.java +++ b/alfred-api-impl/src/test/java/eu/xenit/alfred/api/tests/translations/TranslationsServiceUnitTest.java @@ -1,14 +1,14 @@ package eu.xenit.alfred.api.tests.translations; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + import eu.xenit.alfred.api.alfresco.translation.TranslationService; import org.alfresco.repo.i18n.MessageService; import org.alfresco.service.ServiceRegistry; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; import org.junit.jupiter.api.BeforeEach; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; +import org.junit.jupiter.api.Test; public class TranslationsServiceUnitTest { @@ -28,21 +28,21 @@ public void init() { @Test public void TestGetTranslatedMessage_GetMessageFromMessageService() { - TranslationService ts = new TranslationService(serviceRegistryMock, null, null, messageServiceMock); + TranslationService ts = new TranslationService(serviceRegistryMock, null, null); Assertions.assertEquals(facetBucketMonthLabel, ts.getMessageTranslation(facetBucketMonthLabel)); Assertions.assertNotNull(ts.getMessageTranslation(facetBucketMonthLabel)); } @Test public void TestGetTranslatedMessage_NullMessageService() { - TranslationService ts = new TranslationService(serviceRegistryMock, null, null, null); + TranslationService ts = new TranslationService(serviceRegistryMock, null, null); Assertions.assertEquals(facetBucketMonthLabel, ts.getMessageTranslation(facetBucketMonthLabel)); Assertions.assertNotNull(ts.getMessageTranslation(facetBucketMonthLabel)); } @Test public void TestGetTranslatedMessage_NullParameter() { - TranslationService ts = new TranslationService(serviceRegistryMock, null, null, messageServiceMock); + TranslationService ts = new TranslationService(serviceRegistryMock, null, null); Assertions.assertNull(ts.getMessageTranslation(null)); } }