From fe0d6a543b7995c60e0b5aa91295704d4848d4b5 Mon Sep 17 00:00:00 2001 From: Roxana Lucanu Date: Fri, 15 Apr 2016 13:34:30 +0300 Subject: [PATCH] RM-3285 - added null check for adding in cache --- .../util/ServiceBaseImpl.java | 7 +- .../util/ServiceBaseImplUnitTest.java | 71 +++++++++++++++++++ 2 files changed, 76 insertions(+), 2 deletions(-) create mode 100644 rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImplUnitTest.java diff --git a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java index e4cd7df87d..904a592d96 100644 --- a/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java +++ b/rm-community/rm-community-repo/source/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImpl.java @@ -430,8 +430,11 @@ public class ServiceBaseImpl implements RecordsManagementModel, ApplicationConte } } - // cache result in transaction - transactionCache.put(nodeRef, result); + // cache result in transaction if result is not null + if (result != null) + { + transactionCache.put(nodeRef, result); + } } } diff --git a/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImplUnitTest.java b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImplUnitTest.java new file mode 100644 index 0000000000..e94259c1f6 --- /dev/null +++ b/rm-community/rm-community-repo/unit-test/java/org/alfresco/module/org_alfresco_module_rm/util/ServiceBaseImplUnitTest.java @@ -0,0 +1,71 @@ +/* + * #%L + * Alfresco Records Management Module + * %% + * Copyright (C) 2005 - 2016 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 . + * #L% + */ +package org.alfresco.module.org_alfresco_module_rm.util; + +import static org.mockito.Mockito.never; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; + +import java.util.Map; + +import org.alfresco.module.org_alfresco_module_rm.test.util.BaseUnitTest; +import org.alfresco.service.cmr.repository.NodeRef; +import org.junit.Test; +import org.mockito.InjectMocks; +import org.mockito.Mock; + +/** + * Service Base unit test. + * + * @author Roxana Lucanu + * @since 2.4 + */ +public class ServiceBaseImplUnitTest extends BaseUnitTest +{ + @InjectMocks private ServiceBaseImpl serviceBase; + @Mock private Map mockedCache; + + /** + * Given a node that is not a record + * When retrieving the file plan for it + * Then never put null in cache + */ + @Test + public void getFilePlan() + { + NodeRef nodeRef = generateNodeRef(TYPE_FILE_PLAN); + + when(mockedTransactionalResourceHelper.getMap("rm.servicebase.getFilePlan")) + .thenReturn(mockedCache); + when(mockedCache.containsKey(nodeRef)).thenReturn(false); + + serviceBase.getFilePlan(nodeRef); + + verify(mockedCache, never()).put(nodeRef, null); + } + +}