Skip to content

Commit

Permalink
ALFREDAPI-562: Adapt tests to new constructors
Browse files Browse the repository at this point in the history
  • Loading branch information
WimCrols committed Dec 11, 2024
1 parent 421dfe7 commit 82d2e8b
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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.");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NodeRef> ancestors = alfredApiNodeService.getAncestors(testNode, rootRef);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -207,11 +207,13 @@ public void testGeneralizeTypeWithCleanUpEnabled() {
Set<QName> 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<NodeRef> 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);
Expand All @@ -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<NodeRef> 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);

Expand All @@ -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<NodeRef> 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
Expand All @@ -278,11 +285,13 @@ public void testGeneralizeTypeWithCleanUpDisabled() {
QName targetType = initialTypeDef.getParentName();
Set<QName> 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<NodeRef> 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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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 {

Expand All @@ -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));
}
}

0 comments on commit 82d2e8b

Please sign in to comment.