From 0b4f036c1d90e50a30a2cbb389a77fc5f3830913 Mon Sep 17 00:00:00 2001 From: krwong <69482343+krwong@users.noreply.github.com> Date: Tue, 12 Sep 2023 11:37:41 -0400 Subject: [PATCH] BXC-4290 replace deprecated MockitoAnnotations.initMocks (#1610) * replace deprecated MockitoAnnotations.initMocks with MockitoAnnotations.openMocks, removed unused imports * add autocloseable instance variable and close mocks * switch StoreAccessLevelFilterTest.class to this --- ...tObjectAccessRestrictionValidatorTest.java | 11 +++++++-- .../GlobalPermissionEvaluatorTest.java | 12 ++++++++-- .../services/InheritedAclFactoryTest.java | 12 ++++++++-- .../InheritedPermissionEvaluatorTest.java | 12 ++++++++-- .../fcrepo/services/ObjectACLFactoryTest.java | 11 +++++++-- .../fcrepo4/AbstractDepositJobTest.java | 9 +++++--- .../VerifyObjectsAreInFedoraServiceTest.java | 12 +++++++--- .../impl/model/JobStatusFactoryTest.java | 11 +++++++-- .../submit/CDRMETSDepositHandlerTest.java | 12 ++++++++-- .../submit/DepositSubmissionServiceTest.java | 12 ++++++++-- .../submit/FileServerDepositHandlerTest.java | 13 ++++++++--- .../SimpleObjectDepositHandlerTest.java | 12 ++++++++-- .../utils/FedoraTransactionRefresherTest.java | 12 ++++------ .../utils/TransactionalFcrepoClientTest.java | 14 +++++++---- .../solr/action/DeleteSolrTreeTest.java | 12 +++++++--- .../solr/action/IndexTreeCleanActionTest.java | 15 ++++++++---- .../solr/action/RecursiveTreeIndexerTest.java | 12 +++++++--- .../solr/action/UpdateTreeActionTest.java | 13 +++++++---- .../solr/action/UpdateTreeSetActionTest.java | 14 +++++++---- .../filter/SetAccessControlFilterTest.java | 12 +++++++--- .../filter/SetAccessStatusFilterTest.java | 12 +++++++--- .../filter/SetContentStatusFilterTest.java | 13 +++++++---- .../solr/filter/SetContentTypeFilterTest.java | 11 +++++++-- .../solr/filter/SetDatastreamFilterTest.java | 13 ++++++++--- .../SetDescriptiveMetadataFilterTest.java | 12 ++++++++-- .../solr/filter/SetFullTextFilterTest.java | 12 +++++++--- .../solr/filter/SetMemberOrderFilterTest.java | 12 ++++++++-- .../solr/filter/SetObjectTypeFilterTest.java | 12 +++++++--- .../solr/filter/SetPathFilterTest.java | 13 ++++++++--- .../solr/filter/SetRecordDatesFilterTest.java | 13 ++++++++--- ...DocumentIndexingPackageDataLoaderTest.java | 14 +++++++---- .../DocumentIndexingPipelineTest.java | 13 +++++++---- .../solr/indexing/SolrUpdateDriverTest.java | 13 ++++++++--- .../solr/utils/MemberOrderServiceTest.java | 15 ++++++++---- .../fcrepo/FedoraTransactionIT.java | 12 +++++++--- .../event/RepositoryPremisLoggerIT.java | 12 ++++++++-- .../objects/AbstractFedoraObjectTest.java | 11 +++++++-- .../model/fcrepo/objects/AdminUnitTest.java | 11 +++++++-- .../fcrepo/objects/BinaryObjectTest.java | 12 ++++++++-- .../model/fcrepo/objects/WorkObjectTest.java | 13 ++++++++--- .../RepositoryObjectCacheLoaderTest.java | 11 +++++++-- .../services/RepositoryObjectFactoryTest.java | 11 +++++++-- .../services/RepositoryObjectLoaderTest.java | 11 +++++++-- .../jms/indexing/IndexingServiceTest.java | 13 ++++++----- .../impl/acl/ExpireEmbargoServiceIT.java | 12 +++++++--- .../acl/PatronAccessAssignmentServiceIT.java | 14 +++++++---- .../acl/StaffRoleAssignmentServiceIT.java | 13 ++++++++--- .../impl/delete/MarkForDeletionJobTest.java | 13 +++++++---- .../impl/delete/RestoreDeletedJobTest.java | 13 +++++++---- .../DestroyObjectsCompletelyJobIT.java | 13 ++++++++--- .../impl/destroy/DestroyObjectsJobIT.java | 12 ++++++++-- .../impl/edit/EditFilenameServiceTest.java | 12 +++++++--- .../impl/edit/EditTitleServiceTest.java | 13 +++++++---- .../impl/edit/UpdateDescriptionServiceIT.java | 13 ++++++++--- .../edit/UpdateDescriptionServiceTest.java | 13 +++++++---- .../impl/importxml/ImportXMLJobIT.java | 12 +++++++--- .../impl/importxml/ImportXMLJobTest.java | 11 +++++++-- .../impl/move/MoveObjectsServiceTest.java | 10 ++++---- .../impl/order/ClearOrderJobTest.java | 11 +++++++-- .../impl/order/OrderJobFactoryTest.java | 11 +++++++-- .../impl/order/OrderValidatorFactoryTest.java | 11 +++++++-- .../impl/order/RemoveFromJobTest.java | 13 ++++++++--- .../order/RemoveFromOrderValidatorTest.java | 11 +++++++-- .../impl/order/SetOrderJobTest.java | 11 +++++++-- .../impl/order/SetOrderValidatorTest.java | 11 +++++++-- .../versioning/DatastreamHistoryLogTest.java | 12 +++++++--- .../sources/IngestSourceManagerImplTest.java | 12 ++++++++-- .../StorageLocationManagerImplTest.java | 13 ++++++++--- .../BinaryTransferSessionImplTest.java | 13 +++++++---- .../transfer/FSToFSTransferClientTest.java | 12 +++++++--- .../transfer/FSToPosixTransferClientTest.java | 12 +++++++--- ...ltiDestinationTransferSessionImplTest.java | 13 +++++++---- .../StreamToFSTransferClientTest.java | 11 +++++++-- .../StreamToPosixTransferClientTest.java | 12 +++++++--- .../solr/services/ChildrenCountServiceIT.java | 13 +++++++---- .../solr/services/FacetValuesServiceIT.java | 11 +++++++-- .../services/GetCollectionIdServiceIT.java | 13 +++++++---- .../MultiSelectFacetListServiceIT.java | 11 +++++++-- .../solr/services/NeighborQueryServiceIT.java | 14 +++++++---- .../solr/services/ObjectPathFactoryIT.java | 14 +++++++---- .../services/SetFacetTitleByIdServiceIT.java | 19 +++++++-------- .../services/StructureQueryServiceIT.java | 16 +++++++------ .../solr/utils/AccessRestrictionUtilTest.java | 13 ++++++++--- .../camel/BinaryEnhancementProcessorTest.java | 12 +++++++--- .../camel/BinaryMetadataProcessorTest.java | 11 +++++++-- .../NonBinaryEnhancementProcessorTest.java | 12 +++++++--- .../binaryCleanup/BinaryCleanupRouterIT.java | 12 ++++++++-- .../cdrEvents/CdrEventProcessorTest.java | 13 +++++++---- .../camel/cdrEvents/CdrEventRoutingTest.java | 11 +++++++-- .../destroy/DestroyObjectsRouterTest.java | 14 +++++++---- .../DestroyDerivativesProcessorTest.java | 12 +++++++--- .../DestroyDerivativesRouterIT.java | 14 +++++++---- .../enhancements/EnhancementRouterIT.java | 12 ++++++++-- .../camel/exportxml/ExportXMLRouteIT.java | 12 ++++++++-- .../camel/fulltext/FulltextProcessorTest.java | 13 ++++++++--- .../images/AddDerivativeProcessorTest.java | 12 ++++++++-- .../services/camel/importxml/ImportXMLIT.java | 13 ++++++++--- .../order/OrderNotificationServiceTest.java | 12 ++++++++-- .../order/OrderRequestProcessorTest.java | 12 +++++++--- .../PatronAccessAssignmentRouterTest.java | 11 +++++++-- .../CdrEventToSolrUpdateProcessorTest.java | 11 +++++++-- .../camel/solr/SolrIngestProcessorIT.java | 15 +++++++----- .../camel/solr/SolrIngestProcessorTest.java | 14 +++++++---- .../solrUpdate/SolrUpdateProcessorIT.java | 21 ++++++++--------- .../solrUpdate/SolrUpdateProcessorTest.java | 11 +++++++-- .../TriplesReindexingRouterIT.java | 6 +++-- .../util/CacheInvalidatingProcessorTest.java | 12 ++++++++-- .../auth/PatronPrincipalProviderTest.java | 11 +++++++-- .../StoreUserAccessControlFilterTest.java | 8 ++++--- .../services/AccessCopiesServiceTest.java | 23 ++++++++----------- .../services/FindingAidUrlServiceTest.java | 13 +++++++---- .../services/PermissionsHelperTest.java | 12 ++++++++-- .../services/StoreAccessLevelFilterTest.java | 11 ++++----- .../common/utils/SerializationUtilTest.java | 1 - .../processing/AddContainerServiceTest.java | 11 +++++++-- .../MemberOrderCsvExporterTest.java | 12 ++++++++-- .../SetAsPrimaryObjectServiceTest.java | 11 +++++++-- .../rest/ItemInfoRestControllerIT.java | 11 +++++++-- .../web/services/rest/RunEnhancementsIT.java | 12 ++++++++-- .../web/services/rest/modify/ExportXMLIT.java | 6 +++-- .../rest/modify/UpdateDescriptionIT.java | 11 +++++++-- .../rest/modify/UpdatePatronAccessIT.java | 6 +++-- 122 files changed, 1098 insertions(+), 384 deletions(-) diff --git a/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/ContentObjectAccessRestrictionValidatorTest.java b/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/ContentObjectAccessRestrictionValidatorTest.java index 1d5a5e5a5e..129d44a629 100644 --- a/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/ContentObjectAccessRestrictionValidatorTest.java +++ b/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/ContentObjectAccessRestrictionValidatorTest.java @@ -4,7 +4,7 @@ import static edu.unc.lib.boxc.auth.api.AccessPrincipalConstants.PUBLIC_PRINC; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Calendar; @@ -12,6 +12,7 @@ import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.rdf.model.Resource; import org.apache.jena.vocabulary.RDF; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -36,6 +37,7 @@ public class ContentObjectAccessRestrictionValidatorTest { "http://example.com/rest/content/99/9a/01/a2/999a01a2-c836-499a-a72e-57f1039f4f45"; private ContentObjectAccessRestrictionValidator validator; + private AutoCloseable closeable; @Mock private PID pid; @@ -45,7 +47,7 @@ public class ContentObjectAccessRestrictionValidatorTest { @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); validator = new ContentObjectAccessRestrictionValidator(); when(pid.getURI()).thenReturn(PID_URI); @@ -54,6 +56,11 @@ public void init() { resc = model.getResource(PID_URI); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void workNoAclsTest() throws Exception { model.add(resc, RDF.type, Cdr.Work); diff --git a/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/GlobalPermissionEvaluatorTest.java b/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/GlobalPermissionEvaluatorTest.java index 71e1005fc2..0c4ff794d9 100644 --- a/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/GlobalPermissionEvaluatorTest.java +++ b/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/GlobalPermissionEvaluatorTest.java @@ -2,7 +2,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Arrays; import java.util.Collections; @@ -10,6 +10,7 @@ import java.util.Properties; import java.util.Set; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,15 +31,22 @@ public class GlobalPermissionEvaluatorTest { private GlobalPermissionEvaluator evaluator; + private AutoCloseable closeable; + @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); configProperties = new Properties(); principals = new HashSet<>(Arrays.asList(PRINC_GRP1)); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void hasGlobalPermissionTest() { addGlobalAssignment(UserRole.administrator, PRINC_GRP1); diff --git a/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/InheritedAclFactoryTest.java b/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/InheritedAclFactoryTest.java index 94ace09620..60245a6afc 100644 --- a/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/InheritedAclFactoryTest.java +++ b/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/InheritedAclFactoryTest.java @@ -19,7 +19,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.time.ZonedDateTime; import java.util.ArrayList; @@ -33,6 +33,7 @@ import java.util.UUID; import java.util.stream.Collectors; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -49,6 +50,8 @@ public class InheritedAclFactoryTest { private static final String OWNER_PRINC = "owner"; private static final String PATRON_GROUP = PATRON_NAMESPACE + "special"; + private AutoCloseable closeable; + @Mock private ContentPathFactory pathFactory; @@ -63,7 +66,7 @@ public class InheritedAclFactoryTest { @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); aclFactory = new InheritedAclFactory(); aclFactory.setObjectAclFactory(objectAclFactory); @@ -77,6 +80,11 @@ public void init() { pid = PIDs.get(UUID.randomUUID().toString()); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void unitBasePrincRoles() { Map> princRoles = aclFactory.getPrincipalRoles(pid); diff --git a/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/InheritedPermissionEvaluatorTest.java b/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/InheritedPermissionEvaluatorTest.java index b2a00130d8..06bf7cd661 100644 --- a/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/InheritedPermissionEvaluatorTest.java +++ b/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/InheritedPermissionEvaluatorTest.java @@ -14,7 +14,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.ArrayList; import java.util.Arrays; @@ -29,6 +29,7 @@ import java.util.UUID; import java.util.stream.Collectors; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -57,6 +58,8 @@ public class InheritedPermissionEvaluatorTest { private static final Set PATRON_GROUP_PRINCIPLES = new HashSet<>( asList(PUBLIC_PRINC, PATRON_GROUP)); + private AutoCloseable closeable; + @Mock private ContentPathFactory pathFactory; @@ -71,7 +74,7 @@ public class InheritedPermissionEvaluatorTest { @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); evaluator = new InheritedPermissionEvaluator(); evaluator.setPathFactory(pathFactory); @@ -85,6 +88,11 @@ public void init() { pid = PIDs.get(UUID.randomUUID().toString()); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void unitHasPatronPermissionTest() { assertTrue(evaluator.hasPermission(pid, PATRON_PRINCIPLES, Permission.viewMetadata)); diff --git a/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/ObjectACLFactoryTest.java b/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/ObjectACLFactoryTest.java index 751dbfb855..ced69ac7b6 100644 --- a/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/ObjectACLFactoryTest.java +++ b/auth-fcrepo/src/test/java/edu/unc/lib/boxc/auth/fcrepo/services/ObjectACLFactoryTest.java @@ -11,7 +11,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.text.SimpleDateFormat; import java.time.LocalDateTime; @@ -29,6 +29,7 @@ import org.apache.jena.rdf.model.Property; import org.apache.jena.rdf.model.Resource; import org.apache.jena.vocabulary.RDF; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -59,6 +60,7 @@ public class ObjectACLFactoryTest { private static final LocalDateTime TOMORROW = LocalDateTime.now().plusDays(1); private ObjectAclFactory aclFactory; + private AutoCloseable closeable; @Mock private RepositoryObjectLoader repositoryObjectLoader; @@ -71,7 +73,7 @@ public class ObjectACLFactoryTest { @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); aclFactory = new ObjectAclFactory(); aclFactory.setRepositoryObjectLoader(repositoryObjectLoader); @@ -87,6 +89,11 @@ public void init() { when(repositoryObjectLoader.getRepositoryObject(pid)).thenReturn(repoObj); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void getPrincipalRolesTest() throws Exception { objResc.addLiteral(CdrAcl.canManage, MANAGE_GRP); diff --git a/deposit-app/src/test/java/edu/unc/lib/boxc/deposit/fcrepo4/AbstractDepositJobTest.java b/deposit-app/src/test/java/edu/unc/lib/boxc/deposit/fcrepo4/AbstractDepositJobTest.java index 3635411114..1b063d3a5e 100644 --- a/deposit-app/src/test/java/edu/unc/lib/boxc/deposit/fcrepo4/AbstractDepositJobTest.java +++ b/deposit-app/src/test/java/edu/unc/lib/boxc/deposit/fcrepo4/AbstractDepositJobTest.java @@ -4,7 +4,7 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Mockito.doAnswer; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.nio.file.Files; @@ -52,6 +52,8 @@ public class AbstractDepositJobTest { protected static final String FEDORA_BASE = "http://localhost:48085/rest/"; protected static final String TX_URI = "http://localhost:48085/rest/tx:99b58d30-06f5-477b-a44c-d614a9049d38"; + private AutoCloseable closeable; + @Mock protected RepositoryObjectDriver driver; @Mock @@ -94,7 +96,7 @@ public class AbstractDepositJobTest { @BeforeEach public void initBase() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(FEDORA_BASE); @@ -144,7 +146,8 @@ public Void answer(InvocationOnMock invocation) throws Throwable { } @AfterEach - public void tearDown() { + public void tearDown() throws Exception { + closeable.close(); depositModelManager.close(); } diff --git a/deposit-app/src/test/java/edu/unc/lib/boxc/deposit/validate/VerifyObjectsAreInFedoraServiceTest.java b/deposit-app/src/test/java/edu/unc/lib/boxc/deposit/validate/VerifyObjectsAreInFedoraServiceTest.java index 2a4af40fb3..13e45c38ef 100644 --- a/deposit-app/src/test/java/edu/unc/lib/boxc/deposit/validate/VerifyObjectsAreInFedoraServiceTest.java +++ b/deposit-app/src/test/java/edu/unc/lib/boxc/deposit/validate/VerifyObjectsAreInFedoraServiceTest.java @@ -4,7 +4,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.net.URI; import java.util.ArrayList; @@ -19,11 +19,11 @@ import org.fcrepo.client.FcrepoOperationFailedException; import org.fcrepo.client.FcrepoResponse; import org.fcrepo.client.HeadBuilder; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; -import edu.unc.lib.boxc.deposit.validate.VerifyObjectsAreInFedoraService; import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; @@ -38,6 +38,7 @@ public class VerifyObjectsAreInFedoraServiceTest { private PID workPid; private PID filePid; private Collection pids; + private AutoCloseable closeable; @Mock private FcrepoClient client; @Mock @@ -52,7 +53,7 @@ public class VerifyObjectsAreInFedoraServiceTest { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); verificationService = new VerifyObjectsAreInFedoraService(); setField(verificationService, "fcrepoClient", client); @@ -61,6 +62,11 @@ public void init() throws Exception { pids = new HashSet<>(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void allObjectsInFedoraTest() throws FcrepoOperationFailedException { when(client.head(any(URI.class))).thenReturn(builder); diff --git a/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/model/JobStatusFactoryTest.java b/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/model/JobStatusFactoryTest.java index bb12aeb309..4a41adb273 100644 --- a/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/model/JobStatusFactoryTest.java +++ b/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/model/JobStatusFactoryTest.java @@ -2,6 +2,7 @@ import edu.unc.lib.boxc.deposit.api.RedisWorkerConstants.JobField; import edu.unc.lib.boxc.model.api.exceptions.RepositoryException; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -19,12 +20,13 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author bbpennel */ public class JobStatusFactoryTest { + private AutoCloseable closeable; @Mock private JedisPool jedisPool; @@ -37,7 +39,7 @@ public class JobStatusFactoryTest { @BeforeEach public void setup() { - initMocks(this); + closeable = openMocks(this); when(jedisPool.getResource()).thenReturn(jedis); @@ -49,6 +51,11 @@ public void setup() { statusFactory.setJedisPool(jedisPool); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void incrCompletionSuccess() { statusFactory.incrCompletion(jobUUID, 1); diff --git a/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/CDRMETSDepositHandlerTest.java b/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/CDRMETSDepositHandlerTest.java index 95ed5e6599..8a87cf0cf7 100644 --- a/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/CDRMETSDepositHandlerTest.java +++ b/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/CDRMETSDepositHandlerTest.java @@ -7,7 +7,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.ByteArrayInputStream; import java.io.File; @@ -18,6 +18,7 @@ import java.util.Map; import java.util.UUID; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -53,6 +54,8 @@ public class CDRMETSDepositHandlerTest { private static final String DEPOSITOR = "adminuser"; private static final String DEPOSIT_METHOD = "unitTest"; + private AutoCloseable closeable; + @TempDir public Path tmpFolder; @@ -74,7 +77,7 @@ public class CDRMETSDepositHandlerTest { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); Files.createDirectory(tmpFolder.resolve("deposits")); depositsDir = tmpFolder.resolve("deposits").toFile(); @@ -93,6 +96,11 @@ public void init() throws Exception { depositHandler.setDepositStatusFactory(depositStatusFactory); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testNoInputStream() throws Exception { Assertions.assertThrows(DepositException.class, () -> { diff --git a/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/DepositSubmissionServiceTest.java b/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/DepositSubmissionServiceTest.java index 5a4a03aff1..9fd9e78518 100644 --- a/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/DepositSubmissionServiceTest.java +++ b/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/DepositSubmissionServiceTest.java @@ -1,13 +1,14 @@ package edu.unc.lib.boxc.deposit.impl.submit; import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.nio.file.Path; import java.nio.file.Paths; import java.util.HashMap; import java.util.Map; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -33,6 +34,8 @@ public class DepositSubmissionServiceTest { private static final String DEPOSIT_METHOD = "unitTest"; private static final Path FILEPATH = Paths.get(FILENAME); + private AutoCloseable closeable; + @Mock private AccessControlService aclService; @@ -53,7 +56,7 @@ public class DepositSubmissionServiceTest { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); packageHandlers = new HashMap<>(); packageHandlers.put(PackagingType.SIMPLE_OBJECT, depositHandler1); @@ -64,6 +67,11 @@ public void init() throws Exception { depositService.setAclService(aclService); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testSubmitDepositSimplePackage() throws Exception { DepositData deposit = new DepositData(FILEPATH.toUri(), diff --git a/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/FileServerDepositHandlerTest.java b/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/FileServerDepositHandlerTest.java index 3a11b6f384..fc0a74da61 100644 --- a/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/FileServerDepositHandlerTest.java +++ b/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/FileServerDepositHandlerTest.java @@ -8,13 +8,14 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.nio.file.Files; import java.nio.file.Path; import java.util.Map; import java.util.UUID; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -32,7 +33,6 @@ import edu.unc.lib.boxc.deposit.api.RedisWorkerConstants.Priority; import edu.unc.lib.boxc.deposit.api.submit.DepositData; import edu.unc.lib.boxc.deposit.impl.model.DepositStatusFactory; -import edu.unc.lib.boxc.deposit.impl.submit.FileServerDepositHandler; import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.model.api.ids.PIDMinter; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; @@ -44,6 +44,8 @@ public class FileServerDepositHandlerTest { private static final String DEPOSIT_METHOD = "unitTest"; private static final String DEPOSITOR_EMAIL = "adminuser@example.com"; + private AutoCloseable closeable; + @TempDir public Path tmpFolder; private Path sourcePath; @@ -65,7 +67,7 @@ public class FileServerDepositHandlerTest { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); sourcePath = tmpFolder.resolve("source"); Files.createDirectory(sourcePath); @@ -83,6 +85,11 @@ public void init() throws Exception { depositHandler.setDepositStatusFactory(depositStatusFactory); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testDepositBagPackage() throws Exception { DepositData deposit = new DepositData(sourcePath.toUri(), null, diff --git a/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/SimpleObjectDepositHandlerTest.java b/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/SimpleObjectDepositHandlerTest.java index 0a03bbb8ad..4898b6ebbe 100644 --- a/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/SimpleObjectDepositHandlerTest.java +++ b/deposit-utils/src/test/java/edu/unc/lib/boxc/deposit/impl/submit/SimpleObjectDepositHandlerTest.java @@ -7,7 +7,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.ByteArrayInputStream; import java.io.File; @@ -18,6 +18,7 @@ import java.util.Map; import java.util.UUID; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -55,6 +56,8 @@ public class SimpleObjectDepositHandlerTest { private static final String FILE_CONTENT = "Simply content"; private static final String DEPOSIT_METHOD = "unitTest"; + private AutoCloseable closeable; + @TempDir public Path tmpFolder; @@ -76,7 +79,7 @@ public class SimpleObjectDepositHandlerTest { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); depositsDir = tmpFolder.resolve("deposits").toFile(); Files.createDirectory(tmpFolder.resolve("deposits")); @@ -95,6 +98,11 @@ public void init() throws Exception { depositHandler.setDepositStatusFactory(depositStatusFactory); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testNoInputStream() throws Exception { Assertions.assertThrows(DepositException.class, () -> { diff --git a/fcrepo-utils/src/test/java/edu/unc/lib/boxc/fcrepo/utils/FedoraTransactionRefresherTest.java b/fcrepo-utils/src/test/java/edu/unc/lib/boxc/fcrepo/utils/FedoraTransactionRefresherTest.java index fcc875633d..35d87bb315 100644 --- a/fcrepo-utils/src/test/java/edu/unc/lib/boxc/fcrepo/utils/FedoraTransactionRefresherTest.java +++ b/fcrepo-utils/src/test/java/edu/unc/lib/boxc/fcrepo/utils/FedoraTransactionRefresherTest.java @@ -7,7 +7,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.net.URI; @@ -16,14 +16,11 @@ import org.junit.jupiter.api.Test; import org.mockito.Mock; -import edu.unc.lib.boxc.fcrepo.utils.FedoraTransaction; -import edu.unc.lib.boxc.fcrepo.utils.FedoraTransactionRefresher; -import edu.unc.lib.boxc.fcrepo.utils.TransactionManager; - /** * @author bbpennel */ public class FedoraTransactionRefresherTest { + private AutoCloseable closeable; @Mock private TransactionManager txManager; @@ -37,7 +34,7 @@ public class FedoraTransactionRefresherTest { @BeforeEach public void setup() { - initMocks(this); + closeable = openMocks(this); txUri = URI.create("http://example.com/tx"); when(tx.getTransactionManager()).thenReturn(txManager); @@ -45,7 +42,8 @@ public void setup() { } @AfterEach - public void cleanup() { + public void cleanup() throws Exception { + closeable.close(); FedoraTransactionRefresher.setMaxTimeToLive(originalMaxTimeToLive); FedoraTransactionRefresher.setRefreshInterval(originalRefreshInterval); } diff --git a/fcrepo-utils/src/test/java/edu/unc/lib/boxc/fcrepo/utils/TransactionalFcrepoClientTest.java b/fcrepo-utils/src/test/java/edu/unc/lib/boxc/fcrepo/utils/TransactionalFcrepoClientTest.java index 1eb42ed387..e13c223dee 100644 --- a/fcrepo-utils/src/test/java/edu/unc/lib/boxc/fcrepo/utils/TransactionalFcrepoClientTest.java +++ b/fcrepo-utils/src/test/java/edu/unc/lib/boxc/fcrepo/utils/TransactionalFcrepoClientTest.java @@ -7,6 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.openMocks; import java.net.URI; @@ -18,14 +19,11 @@ import org.apache.http.impl.client.CloseableHttpClient; import org.fcrepo.client.FcrepoClient.FcrepoClientBuilder; import org.fcrepo.client.FcrepoResponse; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import edu.unc.lib.boxc.fcrepo.utils.FedoraTransaction; -import edu.unc.lib.boxc.fcrepo.utils.TransactionManager; -import edu.unc.lib.boxc.fcrepo.utils.TransactionalFcrepoClient; import edu.unc.lib.boxc.persist.api.transfer.BinaryTransferService; /** @@ -44,6 +42,7 @@ public class TransactionalFcrepoClientTest { private TransactionalFcrepoClient txClient; private FedoraTransaction tx; private TransactionManager txManager; + private AutoCloseable closeable; @Mock private HttpRequestBase request; @@ -60,7 +59,7 @@ public class TransactionalFcrepoClientTest { @BeforeEach public void setup() throws Exception { - MockitoAnnotations.initMocks(this); + closeable = openMocks(this); URI uri = URI.create(TX_URI); FcrepoClientBuilder builder = TransactionalFcrepoClient.client(BASE_URI); txClient = (TransactionalFcrepoClient) builder.build(); @@ -81,6 +80,11 @@ public void setup() throws Exception { when(request.getMethod()).thenReturn("GET"); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void executeRequestWithTxTest() throws Exception { URI rescUri = URI.create(RESC_URI); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/DeleteSolrTreeTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/DeleteSolrTreeTest.java index 82c4bfb4d9..60647ca499 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/DeleteSolrTreeTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/DeleteSolrTreeTest.java @@ -1,7 +1,7 @@ package edu.unc.lib.boxc.indexing.solr.action; import static edu.unc.lib.boxc.operations.jms.indexing.IndexingActionType.DELETE_SOLR_TREE; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.IOException; import java.util.Properties; @@ -9,6 +9,7 @@ import org.apache.solr.client.solrj.SolrServerException; import org.apache.solr.common.SolrDocument; import org.apache.solr.common.SolrDocumentList; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -16,7 +17,6 @@ import edu.unc.lib.boxc.auth.fcrepo.models.AccessGroupSetImpl; import edu.unc.lib.boxc.common.test.TestHelpers; import edu.unc.lib.boxc.indexing.solr.SolrUpdateRequest; -import edu.unc.lib.boxc.indexing.solr.action.DeleteSolrTreeAction; import edu.unc.lib.boxc.indexing.solr.test.TestCorpus; import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.search.solr.config.SearchSettings; @@ -33,6 +33,7 @@ public class DeleteSolrTreeTest extends BaseEmbeddedSolrTest { protected TestCorpus corpus; + private AutoCloseable closeable; @Mock private AccessRestrictionUtil restrictionUtil; @@ -48,7 +49,7 @@ public class DeleteSolrTreeTest extends BaseEmbeddedSolrTest { @BeforeEach public void setup() throws SolrServerException, IOException { - initMocks(this); + closeable = openMocks(this); corpus = new TestCorpus(); @@ -80,6 +81,11 @@ public void setup() throws SolrServerException, IOException { server.commit(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void deleteTree() throws Exception { SolrUpdateRequest updateRequest = new SolrUpdateRequest(corpus.pid2.getId(), DELETE_SOLR_TREE); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/IndexTreeCleanActionTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/IndexTreeCleanActionTest.java index 145f135dd1..d4629fe030 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/IndexTreeCleanActionTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/IndexTreeCleanActionTest.java @@ -6,12 +6,13 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.UUID; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -19,9 +20,6 @@ import org.mockito.Mock; import edu.unc.lib.boxc.indexing.solr.SolrUpdateRequest; -import edu.unc.lib.boxc.indexing.solr.action.DeleteSolrTreeAction; -import edu.unc.lib.boxc.indexing.solr.action.IndexTreeCleanAction; -import edu.unc.lib.boxc.indexing.solr.action.RecursiveTreeIndexer; import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPipeline; import edu.unc.lib.boxc.indexing.solr.indexing.SolrUpdateDriver; import edu.unc.lib.boxc.model.api.ids.PID; @@ -37,6 +35,8 @@ public class IndexTreeCleanActionTest { private static final String USER = "user"; + private AutoCloseable closeable; + @Mock private SolrUpdateDriver driver; @Mock @@ -64,7 +64,7 @@ public class IndexTreeCleanActionTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); pid = PIDs.get(UUID.randomUUID().toString()); when(request.getPid()).thenReturn(pid); @@ -85,6 +85,11 @@ public void setup() throws Exception { when(containerObj.getResource()).thenReturn(model.getResource(pid.getRepositoryPath())); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testPerformAction() throws Exception { request = new SolrUpdateRequest(pid.getRepositoryPath(), CLEAN_REINDEX, "1", USER); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/RecursiveTreeIndexerTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/RecursiveTreeIndexerTest.java index 59eca6088a..86439ff2b2 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/RecursiveTreeIndexerTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/RecursiveTreeIndexerTest.java @@ -10,19 +10,19 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.List; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import edu.unc.lib.boxc.indexing.solr.action.RecursiveTreeIndexer; import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader; import edu.unc.lib.boxc.model.api.sparql.SparqlQueryService; @@ -42,6 +42,7 @@ public class RecursiveTreeIndexerTest { private static final String USER = "user"; private RecursiveTreeIndexer indexer; + private AutoCloseable closeable; @Mock private ContentContainerObject containerObj; @@ -60,7 +61,7 @@ public class RecursiveTreeIndexerTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); containerObj = makeContainer(makePid(), repositoryObjectLoader); @@ -74,6 +75,11 @@ public void setup() throws Exception { indexer.setSparqlQueryService(sparqlQueryService); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testNonContainer() throws Exception { FileObject fileObj = makeFileObject(makePid(), repositoryObjectLoader); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/UpdateTreeActionTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/UpdateTreeActionTest.java index 8cde9bca5d..564e39601e 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/UpdateTreeActionTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/UpdateTreeActionTest.java @@ -11,12 +11,13 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.List; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -24,8 +25,6 @@ import org.mockito.Mock; import edu.unc.lib.boxc.indexing.solr.SolrUpdateRequest; -import edu.unc.lib.boxc.indexing.solr.action.RecursiveTreeIndexer; -import edu.unc.lib.boxc.indexing.solr.action.UpdateTreeAction; import edu.unc.lib.boxc.indexing.solr.test.TestCorpus; import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader; @@ -46,6 +45,7 @@ public class UpdateTreeActionTest { protected static final String USER = "user"; protected TestCorpus corpus; + private AutoCloseable closeable; @Mock private RepositoryObjectLoader repositoryObjectLoader; @@ -65,7 +65,7 @@ public class UpdateTreeActionTest { @BeforeEach public void setupTreeAction() throws Exception { - initMocks(this); + closeable = openMocks(this); corpus = new TestCorpus(); @@ -95,6 +95,11 @@ protected UpdateTreeAction getAction() { return new UpdateTreeAction(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testVerifyQueued() throws Exception { action.performAction(new SolrUpdateRequest(corpus.pid2.getRepositoryPath(), diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/UpdateTreeSetActionTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/UpdateTreeSetActionTest.java index 606ee3b3d5..c89e4fd9b6 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/UpdateTreeSetActionTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/action/UpdateTreeSetActionTest.java @@ -8,12 +8,13 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.List; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,8 +24,6 @@ import edu.unc.lib.boxc.indexing.solr.ChildSetRequest; import edu.unc.lib.boxc.indexing.solr.SolrUpdateRequest; -import edu.unc.lib.boxc.indexing.solr.action.RecursiveTreeIndexer; -import edu.unc.lib.boxc.indexing.solr.action.UpdateTreeSetAction; import edu.unc.lib.boxc.indexing.solr.exception.IndexingException; import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader; @@ -43,6 +42,8 @@ public class UpdateTreeSetActionTest { private static final String USER = "user"; + private AutoCloseable closeable; + @Mock private RepositoryObjectLoader repositoryObjectLoader; @Mock @@ -61,7 +62,7 @@ public class UpdateTreeSetActionTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); sparqlModel = ModelFactory.createDefaultModel(); sparqlQueryService = new JenaSparqlQueryServiceImpl(sparqlModel); @@ -76,6 +77,11 @@ public void setup() throws Exception { action.setActionType(IndexingActionType.ADD.name()); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testSingleEmptyChild() throws Exception { ContentContainerObject containerObj = makeContainer(repositoryObjectLoader); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetAccessControlFilterTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetAccessControlFilterTest.java index 2821eb1438..ca85fee88c 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetAccessControlFilterTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetAccessControlFilterTest.java @@ -12,11 +12,12 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.ArrayList; import java.util.List; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -28,7 +29,6 @@ import edu.unc.lib.boxc.search.solr.models.IndexDocumentBean; import edu.unc.lib.boxc.auth.api.AccessPrincipalConstants; import edu.unc.lib.boxc.auth.fcrepo.services.InheritedAclFactory; -import edu.unc.lib.boxc.indexing.solr.filter.SetAccessControlFilter; import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPackage; import edu.unc.lib.boxc.auth.api.UserRole; import edu.unc.lib.boxc.auth.api.models.RoleAssignment; @@ -42,6 +42,7 @@ public class SetAccessControlFilterTest { private static final String PRINC1 = "group1"; private static final String PRINC2 = "group2"; + private AutoCloseable closeable; @Mock private DocumentIndexingPackage dip; @@ -60,7 +61,7 @@ public class SetAccessControlFilterTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); when(dip.getDocument()).thenReturn(idb); when(dip.getPid()).thenReturn(pid); @@ -69,6 +70,11 @@ public void setup() throws Exception { filter.setAclFactory(aclFactory); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testHasPatronPrincipal() throws Exception { addPatronAccess(PUBLIC_PRINC, canViewOriginals); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetAccessStatusFilterTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetAccessStatusFilterTest.java index 9375f70cf1..9380da524e 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetAccessStatusFilterTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetAccessStatusFilterTest.java @@ -7,7 +7,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Arrays; import java.util.Calendar; @@ -17,6 +17,7 @@ import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -38,7 +39,6 @@ import edu.unc.lib.boxc.auth.api.AccessPrincipalConstants; import edu.unc.lib.boxc.auth.fcrepo.services.InheritedAclFactory; import edu.unc.lib.boxc.auth.fcrepo.services.ObjectAclFactory; -import edu.unc.lib.boxc.indexing.solr.filter.SetAccessStatusFilter; import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPackage; /** @@ -46,6 +46,7 @@ */ public class SetAccessStatusFilterTest { private static final String CUSTOM_GROUP = AccessPrincipalConstants.IP_PRINC_NAMESPACE + "special"; + private AutoCloseable closeable; @Mock private DocumentIndexingPackage dip; @@ -77,7 +78,7 @@ public class SetAccessStatusFilterTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); pid = PIDs.get(UUID.randomUUID().toString()); parentPid = PIDs.get(UUID.randomUUID().toString()); @@ -119,6 +120,11 @@ public void setup() throws Exception { filter.setInheritedAclFactory(inheritedAclFactory); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testIsMarkedForDeletion() throws Exception { Model model = new AclModelBuilder(pid).markForDeletion().model; diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetContentStatusFilterTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetContentStatusFilterTest.java index a9522a3586..ed17400290 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetContentStatusFilterTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetContentStatusFilterTest.java @@ -5,19 +5,19 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.List; import org.apache.jena.rdf.model.Property; import org.apache.jena.rdf.model.Resource; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import edu.unc.lib.boxc.indexing.solr.filter.SetContentStatusFilter; import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPackage; import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.model.api.rdf.Cdr; @@ -31,6 +31,7 @@ * @author harring */ public class SetContentStatusFilterTest { + private AutoCloseable closeable; @Mock private DocumentIndexingPackage dip; @Mock @@ -52,7 +53,7 @@ public class SetContentStatusFilterTest { @BeforeEach public void setUp() throws Exception { - initMocks(this); + closeable = openMocks(this); when(dip.getDocument()).thenReturn(idb); when(dip.getPid()).thenReturn(pid); @@ -60,10 +61,14 @@ public void setUp() throws Exception { when(resc.hasProperty(any(Property.class))).thenReturn(false); when(fileObj.getParent()).thenReturn(workObj); - filter = new SetContentStatusFilter(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testDescribedWork() throws Exception { when(dip.getContentObject()).thenReturn(workObj); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetContentTypeFilterTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetContentTypeFilterTest.java index 52c9389a70..5dc094706f 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetContentTypeFilterTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetContentTypeFilterTest.java @@ -23,6 +23,7 @@ import edu.unc.lib.boxc.search.solr.responses.SearchResultResponse; import edu.unc.lib.boxc.search.solr.services.SolrSearchService; import org.apache.commons.collections.CollectionUtils; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -46,7 +47,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; /** * @@ -57,6 +58,7 @@ public class SetContentTypeFilterTest { private DocumentIndexingPackage dip; private PID pid; + private AutoCloseable closeable; @Mock private FileObject fileObj; @Mock @@ -87,7 +89,7 @@ public class SetContentTypeFilterTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); pid = PIDs.get(UUID.randomUUID().toString()); dip = new DocumentIndexingPackage(pid, null, documentIndexingPackageDataLoader); @@ -111,6 +113,11 @@ public void setup() throws Exception { filter.setContentPathFactory(contentPathFactory); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testGetContentTypeFromWorkObjectWithPrimary() throws Exception { dip.setContentObject(workObj); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetDatastreamFilterTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetDatastreamFilterTest.java index 59b63e717a..90b04fd9f5 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetDatastreamFilterTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetDatastreamFilterTest.java @@ -10,7 +10,6 @@ import edu.unc.lib.boxc.model.api.objects.ContentObject; import edu.unc.lib.boxc.model.api.objects.FileObject; import edu.unc.lib.boxc.model.api.objects.FolderObject; -import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader; import edu.unc.lib.boxc.model.api.objects.WorkObject; import edu.unc.lib.boxc.model.api.rdf.Ebucore; import edu.unc.lib.boxc.model.api.rdf.Premis; @@ -23,6 +22,7 @@ import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.rdf.model.Resource; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -50,7 +50,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; /** * @@ -89,6 +89,8 @@ public class SetDatastreamFilterTest { private static final String PREMIS_DIGEST = "urn:sha1:da39a3ee5e6b4b0d3255bfef95601890afd80709"; private static final long PREMIS_SIZE = 893l; + private AutoCloseable closeable; + @TempDir public Path derivDir; @@ -113,7 +115,7 @@ public class SetDatastreamFilterTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); pid = PIDs.get(PID_STRING); @@ -135,6 +137,11 @@ public void setup() throws Exception { fileResource(ORIGINAL_FILE.getId(), FILE_SIZE, FILE_MIMETYPE, FILE_NAME, FILE_DIGEST)); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void fileObjectTest() throws Exception { dip.setContentObject(fileObj); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetDescriptiveMetadataFilterTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetDescriptiveMetadataFilterTest.java index 1a97e0bb7f..0fa228f9f3 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetDescriptiveMetadataFilterTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetDescriptiveMetadataFilterTest.java @@ -6,7 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.io.FileInputStream; @@ -22,6 +22,7 @@ import org.apache.jena.rdf.model.Statement; import org.jdom2.Document; import org.jdom2.input.SAXBuilder; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -45,6 +46,8 @@ public class SetDescriptiveMetadataFilterTest { private static final String PID_STRING = "uuid:07d9594f-310d-4095-ab67-79a1056e7430"; + private AutoCloseable closeable; + @Mock private DocumentIndexingPackageDataLoader loader; @Mock @@ -74,7 +77,7 @@ public class SetDescriptiveMetadataFilterTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); when(pid.getId()).thenReturn(PID_STRING); @@ -91,6 +94,11 @@ public void setup() throws Exception { filter.setTitleRetrievalService(titleRetrievalService); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testInventory() throws Exception { runFilterOnInventoryMods(); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetFullTextFilterTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetFullTextFilterTest.java index e50d8da5a4..34a13f37e9 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetFullTextFilterTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetFullTextFilterTest.java @@ -5,7 +5,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.nio.file.Files; @@ -13,12 +13,12 @@ import java.util.UUID; import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; import org.mockito.Mock; -import edu.unc.lib.boxc.indexing.solr.filter.SetFullTextFilter; import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPackage; import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPackageDataLoader; import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPackageFactory; @@ -34,6 +34,7 @@ * @author harring */ public class SetFullTextFilterTest { + private AutoCloseable closeable; @TempDir public Path tempDir; @@ -60,7 +61,7 @@ public class SetFullTextFilterTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); derivativeDir = tempDir.resolve("testFolder").toFile(); Files.createDirectory(tempDir.resolve("testFolder")); @@ -81,6 +82,11 @@ public void setup() throws Exception { filter.setDerivativeService(derivativeService); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testFullTextWithWorkObject() throws Exception { dip = factory.createDip(workPid); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetMemberOrderFilterTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetMemberOrderFilterTest.java index bf15db0831..5389bb2399 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetMemberOrderFilterTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetMemberOrderFilterTest.java @@ -7,6 +7,7 @@ import edu.unc.lib.boxc.model.api.objects.FileObject; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; import edu.unc.lib.boxc.search.solr.models.IndexDocumentBean; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -15,7 +16,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author bbpennel @@ -23,6 +24,8 @@ public class SetMemberOrderFilterTest { private static final String SUBJECT_UUID = "f277bb38-272c-471c-a28a-9887a1328a1f"; + private AutoCloseable closeable; + @Mock private MemberOrderService memberOrderService; @Mock @@ -35,7 +38,7 @@ public class SetMemberOrderFilterTest { @BeforeEach public void setup() { - initMocks(this); + closeable = openMocks(this); subjectPid = PIDs.get(SUBJECT_UUID); dip = new DocumentIndexingPackage(subjectPid, null, documentIndexingPackageDataLoader); dip.setPid(subjectPid); @@ -44,6 +47,11 @@ public void setup() { filter.setMemberOrderService(memberOrderService); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void withFileInUnorderedWorkTest() { var subject = mock(FileObject.class); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetObjectTypeFilterTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetObjectTypeFilterTest.java index f69ef586b9..a0c2e9ff84 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetObjectTypeFilterTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetObjectTypeFilterTest.java @@ -3,18 +3,18 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Arrays; import java.util.Collections; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import edu.unc.lib.boxc.indexing.solr.exception.IndexingException; -import edu.unc.lib.boxc.indexing.solr.filter.SetObjectTypeFilter; import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPackage; import edu.unc.lib.boxc.model.api.ResourceType; import edu.unc.lib.boxc.model.api.ids.PID; @@ -31,6 +31,7 @@ public class SetObjectTypeFilterTest { private SetObjectTypeFilter filter; + private AutoCloseable closeable; @Mock private DocumentIndexingPackage dip; @@ -44,7 +45,7 @@ public class SetObjectTypeFilterTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); when(dip.getDocument()).thenReturn(idb); when(dip.getPid()).thenReturn(pid); @@ -54,6 +55,11 @@ public void setup() throws Exception { filter = new SetObjectTypeFilter(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testWorkResourceType() throws Exception { when(contentObj.getTypes()).thenReturn(Arrays.asList(Cdr.Work.getURI())); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetPathFilterTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetPathFilterTest.java index 5bfab46a30..7f4130d7de 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetPathFilterTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetPathFilterTest.java @@ -9,7 +9,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.ArrayList; import java.util.Collections; @@ -18,6 +18,7 @@ import java.util.stream.Collectors; import edu.unc.lib.boxc.search.solr.services.TitleRetrievalService; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -26,7 +27,6 @@ import org.mockito.Mock; import edu.unc.lib.boxc.indexing.solr.exception.IndexingException; -import edu.unc.lib.boxc.indexing.solr.filter.SetPathFilter; import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPackage; import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPackageDataLoader; import edu.unc.lib.boxc.model.api.ResourceType; @@ -48,6 +48,8 @@ public class SetPathFilterTest { private final static String UNIT_TITLE = "Administration of Boxy"; private final static String COLLECTION_TITLE = "Collection of Boxes"; + private AutoCloseable closeable; + @Mock private ContentPathFactory pathFactory; @Mock @@ -74,7 +76,7 @@ public class SetPathFilterTest { @BeforeEach public void setUp() throws Exception { - initMocks(this); + closeable = openMocks(this); pid = PIDs.get(UUID.randomUUID().toString()); @@ -88,6 +90,11 @@ public void setUp() throws Exception { filter.setTitleRetrievalService(titleRetrievalService); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testUnitPath() throws Exception { // Assert that the parent unit and collection are not set diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetRecordDatesFilterTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetRecordDatesFilterTest.java index 9d71b6e302..8685243b6c 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetRecordDatesFilterTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/filter/SetRecordDatesFilterTest.java @@ -3,20 +3,20 @@ import static org.junit.Assert.assertTrue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.text.SimpleDateFormat; import org.apache.jena.rdf.model.Literal; import org.apache.jena.rdf.model.Resource; import org.apache.jena.rdf.model.Statement; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import edu.unc.lib.boxc.indexing.solr.exception.IndexingException; -import edu.unc.lib.boxc.indexing.solr.filter.SetRecordDatesFilter; import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPackage; import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPackageDataLoader; import edu.unc.lib.boxc.model.api.ids.PID; @@ -33,6 +33,8 @@ public class SetRecordDatesFilterTest { private static final String DATE_MODIFIED = "2017-05-31"; private static final String BAD_DATE = "abcd"; + private AutoCloseable closeable; + @Mock private DocumentIndexingPackageDataLoader loader; @Mock @@ -62,7 +64,7 @@ public class SetRecordDatesFilterTest { @BeforeEach public void setup() throws Exception { idb = new IndexDocumentBean(); - initMocks(this); + closeable = openMocks(this); when(dip.getDocument()).thenReturn(idb); when(dip.getPid()).thenReturn(pid); @@ -84,6 +86,11 @@ public void setup() throws Exception { filter = new SetRecordDatesFilter(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testCreateDate() throws Exception { filter.filter(dip); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/indexing/DocumentIndexingPackageDataLoaderTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/indexing/DocumentIndexingPackageDataLoaderTest.java index 6e647de30a..4dcb489c22 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/indexing/DocumentIndexingPackageDataLoaderTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/indexing/DocumentIndexingPackageDataLoaderTest.java @@ -7,7 +7,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.ByteArrayInputStream; import java.io.File; @@ -15,13 +15,11 @@ import java.io.InputStream; import org.jdom2.Element; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; -import edu.unc.lib.boxc.indexing.solr.exception.IndexingException; -import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPackage; -import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPackageDataLoader; import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.model.api.objects.ContentObject; import edu.unc.lib.boxc.model.api.objects.BinaryObject; @@ -35,6 +33,7 @@ public class DocumentIndexingPackageDataLoaderTest { private DocumentIndexingPackageDataLoader dataLoader; + private AutoCloseable closeable; @Mock private RepositoryObjectLoaderImpl repoObjLoader; @@ -50,7 +49,7 @@ public class DocumentIndexingPackageDataLoaderTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); dataLoader = new DocumentIndexingPackageDataLoader(); dataLoader.setRepositoryObjectLoader(repoObjLoader); @@ -58,6 +57,11 @@ public void setup() throws Exception { when(dip.getPid()).thenReturn(pid); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testLoadMods() throws Exception { InputStream modsStream = new FileInputStream(new File( diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/indexing/DocumentIndexingPipelineTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/indexing/DocumentIndexingPipelineTest.java index 5e530ce086..39af38ff1e 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/indexing/DocumentIndexingPipelineTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/indexing/DocumentIndexingPipelineTest.java @@ -2,11 +2,12 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Arrays; import java.util.List; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -14,8 +15,6 @@ import edu.unc.lib.boxc.indexing.solr.exception.IndexingException; import edu.unc.lib.boxc.indexing.solr.filter.IndexDocumentFilter; -import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPackage; -import edu.unc.lib.boxc.indexing.solr.indexing.DocumentIndexingPipeline; /** * @@ -25,6 +24,7 @@ public class DocumentIndexingPipelineTest extends Assertions { private DocumentIndexingPipeline pipeline; + private AutoCloseable closeable; @Mock private DocumentIndexingPackage dip; @@ -37,7 +37,7 @@ public class DocumentIndexingPipelineTest extends Assertions { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); filters = Arrays.asList(mockFilter1, mockFilter2); @@ -45,6 +45,11 @@ public void setup() throws Exception { pipeline.setFilters(filters); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testProcessFilters() throws Exception { pipeline.process(dip); diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/indexing/SolrUpdateDriverTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/indexing/SolrUpdateDriverTest.java index dbb6d021cb..7649fbd5c0 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/indexing/SolrUpdateDriverTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/indexing/SolrUpdateDriverTest.java @@ -3,20 +3,20 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.HashMap; import java.util.Map; import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.common.SolrInputDocument; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; import edu.unc.lib.boxc.indexing.solr.exception.IndexingException; -import edu.unc.lib.boxc.indexing.solr.indexing.SolrUpdateDriver; import edu.unc.lib.boxc.search.solr.config.SolrSettings; import edu.unc.lib.boxc.search.solr.models.IndexDocumentBean; @@ -26,6 +26,8 @@ * */ public class SolrUpdateDriverTest { + private AutoCloseable closeable; + @Mock private SolrClient solrClient; @Mock @@ -54,7 +56,7 @@ public class SolrUpdateDriverTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); driver = new SolrUpdateDriver(); driver.setUpdateSolrClient(updateSolrClient); @@ -64,6 +66,11 @@ public void setup() throws Exception { when(solrSettings.getRequiredFields()).thenReturn(REQUIRED_INDEXING_FIELDS); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testRequiredIndexingFieldsMissing() throws Exception { Assertions.assertThrows(IndexingException.class, () -> { diff --git a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/utils/MemberOrderServiceTest.java b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/utils/MemberOrderServiceTest.java index 78032083f0..2eb6ffb4f4 100644 --- a/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/utils/MemberOrderServiceTest.java +++ b/indexing-solr/src/test/java/edu/unc/lib/boxc/indexing/solr/utils/MemberOrderServiceTest.java @@ -7,15 +7,12 @@ import edu.unc.lib.boxc.model.api.objects.FileObject; import edu.unc.lib.boxc.model.api.objects.FolderObject; import edu.unc.lib.boxc.model.api.objects.RepositoryObject; -import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader; import edu.unc.lib.boxc.model.api.objects.WorkObject; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.mockito.Mock; -import org.mockito.MockitoAnnotations; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.UUID; @@ -25,6 +22,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author bbpennel @@ -36,13 +34,20 @@ public class MemberOrderServiceTest { private MemberOrderService memberOrderService; + private AutoCloseable closeable; + @BeforeEach public void setup() { - MockitoAnnotations.initMocks(this); + closeable = openMocks(this); memberOrderService = new MemberOrderService(); memberOrderService.init(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void getOrderValueForAdminUnitTest() { orderNotSupportedTest(AdminUnit.class, ContentRootObject.class); diff --git a/integration/src/test/java/edu/unc/lib/boxc/integration/fcrepo/FedoraTransactionIT.java b/integration/src/test/java/edu/unc/lib/boxc/integration/fcrepo/FedoraTransactionIT.java index 0ffe639a85..47e0efd819 100644 --- a/integration/src/test/java/edu/unc/lib/boxc/integration/fcrepo/FedoraTransactionIT.java +++ b/integration/src/test/java/edu/unc/lib/boxc/integration/fcrepo/FedoraTransactionIT.java @@ -6,7 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.IOException; @@ -16,6 +16,7 @@ import org.fcrepo.client.FcrepoClient; import org.fcrepo.client.FcrepoOperationFailedException; import org.fcrepo.client.FcrepoResponse; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,20 +38,25 @@ * */ public class FedoraTransactionIT extends AbstractFedoraIT { - + private AutoCloseable closeable; private Model model; @Mock private BinaryTransferService binaryTransferService; @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); txManager.setBinaryTransferService(binaryTransferService); model = ModelFactory.createDefaultModel(); Resource resc = model.createResource(""); resc.addProperty(DcElements.title, "Folder Title"); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void createTxTest() throws Exception { FedoraTransaction tx = txManager.startTransaction(); diff --git a/integration/src/test/java/edu/unc/lib/boxc/integration/model/fcrepo/event/RepositoryPremisLoggerIT.java b/integration/src/test/java/edu/unc/lib/boxc/integration/model/fcrepo/event/RepositoryPremisLoggerIT.java index 72577a3a7f..47972e5cb9 100644 --- a/integration/src/test/java/edu/unc/lib/boxc/integration/model/fcrepo/event/RepositoryPremisLoggerIT.java +++ b/integration/src/test/java/edu/unc/lib/boxc/integration/model/fcrepo/event/RepositoryPremisLoggerIT.java @@ -11,7 +11,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.InputStream; import java.nio.file.Files; @@ -32,6 +32,7 @@ import org.apache.jena.rdf.model.Resource; import org.apache.jena.vocabulary.DCTerms; import org.apache.jena.vocabulary.RDF; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -72,6 +73,8 @@ public class RepositoryPremisLoggerIT extends AbstractFedoraIT { private Map previousDigestMap; + private AutoCloseable closeable; + @Mock private BinaryTransferService transferService; @Mock @@ -81,7 +84,7 @@ public class RepositoryPremisLoggerIT extends AbstractFedoraIT { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); lockManager = PidLockManager.getDefaultPidLockManager(); @@ -110,6 +113,11 @@ public BinaryTransferOutcome answer(InvocationOnMock invocation) throws Throwabl previousDigestMap = new HashMap<>(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + private void initPremisLogger(RepositoryObject repoObj) { logger = new RepositoryPremisLogger(parentObject, mockSession, pidMinter, repoObjLoader, repoObjFactory); diff --git a/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/AbstractFedoraObjectTest.java b/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/AbstractFedoraObjectTest.java index ccb1c5554f..e832f3ceac 100644 --- a/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/AbstractFedoraObjectTest.java +++ b/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/AbstractFedoraObjectTest.java @@ -1,7 +1,8 @@ package edu.unc.lib.boxc.model.fcrepo.objects; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.mockito.Mock; @@ -20,6 +21,8 @@ public class AbstractFedoraObjectTest { protected static final String FEDORA_BASE = "http://example.com/"; + private AutoCloseable closeable; + @Mock protected RepositoryObjectDriver driver; @Mock @@ -31,9 +34,13 @@ public class AbstractFedoraObjectTest { @BeforeEach public void initBase() { - initMocks(this); + closeable = openMocks(this); pidMinter = new RepositoryPIDMinter(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } } diff --git a/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/AdminUnitTest.java b/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/AdminUnitTest.java index adc6837e9b..e64884d625 100644 --- a/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/AdminUnitTest.java +++ b/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/AdminUnitTest.java @@ -5,12 +5,13 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Arrays; import java.util.List; import java.util.UUID; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -40,6 +41,8 @@ public class AdminUnitTest extends AbstractFedoraObjectTest { private PID collectionChildPid; + private AutoCloseable closeable; + @Mock private CollectionObject collectionChildObj; @Mock @@ -47,7 +50,7 @@ public class AdminUnitTest extends AbstractFedoraObjectTest { @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); pid = PIDs.get(UUID.randomUUID().toString()); @@ -55,7 +58,11 @@ public void init() { collectionChildPid = PIDs.get(UUID.randomUUID().toString()); when(collectionChildObj.getPid()).thenReturn(collectionChildPid); + } + @AfterEach + void closeService() throws Exception { + closeable.close(); } @Test diff --git a/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/BinaryObjectTest.java b/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/BinaryObjectTest.java index 647ec8eb6b..f5702ff39f 100644 --- a/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/BinaryObjectTest.java +++ b/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/BinaryObjectTest.java @@ -5,6 +5,7 @@ import static org.mockito.Matchers.anyBoolean; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.ByteArrayInputStream; import java.net.URI; @@ -15,11 +16,11 @@ import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.rdf.model.Resource; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -38,6 +39,8 @@ * */ public class BinaryObjectTest extends AbstractFedoraObjectTest { + private AutoCloseable closeable; + @Mock private PID mockPid; @@ -51,7 +54,7 @@ public class BinaryObjectTest extends AbstractFedoraObjectTest { @BeforeEach public void init() throws URISyntaxException { - MockitoAnnotations.initMocks(this); + closeable = openMocks(this); byte[] buf = new byte[10]; stream = new ByteArrayInputStream(buf); @@ -68,6 +71,11 @@ public void init() throws URISyntaxException { setupModel(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + private void setupModel() { model = ModelFactory.createDefaultModel(); binObj.storeModel(model); diff --git a/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/WorkObjectTest.java b/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/WorkObjectTest.java index 67dbeb2ee5..8470d79f17 100644 --- a/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/WorkObjectTest.java +++ b/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/objects/WorkObjectTest.java @@ -12,20 +12,20 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.net.URI; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.UUID; -import java.util.stream.Collectors; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.rdf.model.Resource; import org.apache.jena.vocabulary.DC; import org.apache.jena.vocabulary.RDF; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -65,6 +65,8 @@ public class WorkObjectTest extends AbstractFedoraObjectTest { private WorkObjectImpl work; + private AutoCloseable closeable; + @Mock private FileObject fileObj; private URI contentUri; @@ -75,7 +77,7 @@ public class WorkObjectTest extends AbstractFedoraObjectTest { @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); pid = makePid(); @@ -108,6 +110,11 @@ public RepositoryObjectDriver answer(InvocationOnMock invocation) throws Throwab when(driver.getRepositoryObject(any(PID.class))).thenReturn(fileObj); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void validTypeTest() { assertEquals(work, work.validateType()); diff --git a/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/services/RepositoryObjectCacheLoaderTest.java b/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/services/RepositoryObjectCacheLoaderTest.java index 7898d64100..1043af5095 100644 --- a/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/services/RepositoryObjectCacheLoaderTest.java +++ b/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/services/RepositoryObjectCacheLoaderTest.java @@ -7,7 +7,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.IOException; import java.util.UUID; @@ -19,6 +19,7 @@ import org.fcrepo.client.FcrepoClient; import org.fcrepo.client.FcrepoResponse; import org.fcrepo.client.RequestBuilder; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -56,6 +57,7 @@ public class RepositoryObjectCacheLoaderTest { private static final String ETAG_HEADER = "\"etag\""; private RepositoryObjectCacheLoader objectCacheLoader; + private AutoCloseable closeable; @Mock private RepositoryObjectDriver driver; @@ -69,7 +71,7 @@ public class RepositoryObjectCacheLoaderTest { @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); client = mock(FcrepoClient.class, new BuilderReturningAnswer()); @@ -82,6 +84,11 @@ public void init() { pid = PIDs.get(UUID.randomUUID().toString()); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void loadDepositRecordTest() throws Exception { diff --git a/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/services/RepositoryObjectFactoryTest.java b/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/services/RepositoryObjectFactoryTest.java index 8949b8e9c0..91ae67e75e 100644 --- a/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/services/RepositoryObjectFactoryTest.java +++ b/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/services/RepositoryObjectFactoryTest.java @@ -10,7 +10,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.InputStream; import java.net.URI; @@ -25,6 +25,7 @@ import org.fcrepo.client.FcrepoResponse; import org.fcrepo.client.PostBuilder; import org.fcrepo.client.PutBuilder; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -50,6 +51,7 @@ * */ public class RepositoryObjectFactoryTest { + private AutoCloseable closeable; @Mock private LdpContainerFactory ldpFactory; @@ -74,7 +76,7 @@ public class RepositoryObjectFactoryTest { @BeforeEach public void init() throws FcrepoOperationFailedException, URISyntaxException { - initMocks(this); + closeable = openMocks(this); repoObjFactory = new RepositoryObjectFactoryImpl(); repoObjFactory.setClient(fcrepoClient); repoObjFactory.setLdpFactory(ldpFactory); @@ -97,6 +99,11 @@ public void init() throws FcrepoOperationFailedException, URISyntaxException { } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void createDepositRecordTest() { when(repoObjLoader.getDepositRecord(any(PID.class))).thenReturn(mock(DepositRecord.class)); diff --git a/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/services/RepositoryObjectLoaderTest.java b/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/services/RepositoryObjectLoaderTest.java index d795ef2677..d3cd923e81 100644 --- a/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/services/RepositoryObjectLoaderTest.java +++ b/model-fcrepo/src/test/java/edu/unc/lib/boxc/model/fcrepo/services/RepositoryObjectLoaderTest.java @@ -7,10 +7,11 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.net.URI; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -41,6 +42,7 @@ * */ public class RepositoryObjectLoaderTest { + private AutoCloseable closeable; @Mock private RepositoryObjectCacheLoader objectCacheLoader; @@ -54,7 +56,7 @@ public class RepositoryObjectLoaderTest { @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); contentPid = PIDs.get("content/uuid:0311cf7e-9ac0-4ab0-8c24-ff367e8e77f5"); depositRecordPid = PIDs.get("deposit/uuid:0411cf7e-9ac0-4ab0-8c24-ff367e8e77f6"); @@ -71,6 +73,11 @@ public void init() { when(pidMinter.mintPremisEventPid(any(PID.class))).thenReturn(premisPid); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void getBinaryTest() { PID pid = getBinaryPid(); diff --git a/operations-jms/src/test/java/edu/unc/lib/boxc/operations/jms/indexing/IndexingServiceTest.java b/operations-jms/src/test/java/edu/unc/lib/boxc/operations/jms/indexing/IndexingServiceTest.java index 28521b4245..2c8f67b2e4 100644 --- a/operations-jms/src/test/java/edu/unc/lib/boxc/operations/jms/indexing/IndexingServiceTest.java +++ b/operations-jms/src/test/java/edu/unc/lib/boxc/operations/jms/indexing/IndexingServiceTest.java @@ -7,7 +7,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.UUID; @@ -23,12 +23,10 @@ import edu.unc.lib.boxc.auth.api.models.AccessGroupSet; import edu.unc.lib.boxc.auth.api.models.AgentPrincipals; import edu.unc.lib.boxc.auth.api.services.AccessControlService; -import edu.unc.lib.boxc.auth.fcrepo.models.AccessGroupSetImpl; import edu.unc.lib.boxc.auth.fcrepo.services.GroupsThreadStore; import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.model.api.objects.ContentObject; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; -import edu.unc.lib.boxc.operations.jms.indexing.IndexingService; /** * @@ -38,6 +36,8 @@ public class IndexingServiceTest { private static final String USERNAME = "username"; + private AutoCloseable closeable; + @Mock private AccessControlService aclService; @Mock @@ -60,8 +60,8 @@ public class IndexingServiceTest { private PID objPid; @BeforeEach - public void init() throws Exception{ - initMocks(this); + public void init() throws Exception { + closeable = openMocks(this); when(agent.getPrincipals()).thenReturn(groups); when(agent.getUsername()).thenReturn(USERNAME); @@ -74,7 +74,8 @@ public void init() throws Exception{ } @AfterEach - public void tearDown() { + public void tearDown() throws Exception { + closeable.close(); GroupsThreadStore.clearStore(); } diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/acl/ExpireEmbargoServiceIT.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/acl/ExpireEmbargoServiceIT.java index 13ccae4faa..bffd5bfdf5 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/acl/ExpireEmbargoServiceIT.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/acl/ExpireEmbargoServiceIT.java @@ -10,7 +10,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.ArrayList; import java.util.Calendar; @@ -21,6 +21,7 @@ import org.apache.jena.rdf.model.Statement; import org.apache.jena.rdf.model.StmtIterator; import org.apache.jena.vocabulary.RDF; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -51,7 +52,6 @@ import edu.unc.lib.boxc.model.fcrepo.test.RepositoryObjectTreeIndexer; import edu.unc.lib.boxc.model.fcrepo.test.TestHelper; import edu.unc.lib.boxc.operations.api.events.PremisLoggerFactory; -import edu.unc.lib.boxc.operations.impl.acl.ExpireEmbargoService; import edu.unc.lib.boxc.operations.jms.JMSMessageUtil; import edu.unc.lib.boxc.operations.jms.OperationsMessageSender; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -62,6 +62,7 @@ @ContextConfiguration("/spring-test/cdr-client-container.xml") }) public class ExpireEmbargoServiceIT { + private AutoCloseable closeable; @Autowired private String baseAddress; @@ -90,7 +91,7 @@ public class ExpireEmbargoServiceIT { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(baseAddress); service = new ExpireEmbargoService(); @@ -106,6 +107,11 @@ public void init() throws Exception { contentRoot = repoObjLoader.getContentRootObject(contentRootPid); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void expireSingleEmbargoTest() throws Exception { Calendar embargoUntil = getDayFromNow(-1); diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/acl/PatronAccessAssignmentServiceIT.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/acl/PatronAccessAssignmentServiceIT.java index 2c8402bcc4..c3b20f2624 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/acl/PatronAccessAssignmentServiceIT.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/acl/PatronAccessAssignmentServiceIT.java @@ -20,7 +20,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.net.URI; import java.nio.file.Files; @@ -35,6 +35,7 @@ import org.apache.jena.rdf.model.Statement; import org.apache.jena.rdf.model.StmtIterator; import org.apache.jena.vocabulary.RDF; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -79,8 +80,6 @@ import edu.unc.lib.boxc.model.fcrepo.test.RepositoryObjectTreeIndexer; import edu.unc.lib.boxc.model.fcrepo.test.TestHelper; import edu.unc.lib.boxc.operations.api.events.PremisLoggerFactory; -import edu.unc.lib.boxc.operations.impl.acl.PatronAccessAssignmentService; -import edu.unc.lib.boxc.operations.impl.acl.PatronAccessDetails; import edu.unc.lib.boxc.operations.impl.acl.PatronAccessAssignmentService.PatronAccessAssignmentRequest; import edu.unc.lib.boxc.operations.jms.OperationsMessageSender; import edu.unc.lib.boxc.operations.jms.JMSMessageUtil.CDRActions; @@ -98,6 +97,8 @@ public class PatronAccessAssignmentServiceIT { private static final String origFilename = "original.txt"; private static final String origMimetype = "text/plain"; + private AutoCloseable closeable; + @Autowired private String baseAddress; @Mock @@ -129,7 +130,7 @@ public class PatronAccessAssignmentServiceIT { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(baseAddress); groups = new AccessGroupSetImpl(GRP_PRINC); @@ -148,6 +149,11 @@ public void init() throws Exception { contentRoot = repoObjLoader.getContentRootObject(contentRootPid); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void insufficientPermissions() throws Exception { Assertions.assertThrows(AccessRestrictionException.class, () -> { diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/acl/StaffRoleAssignmentServiceIT.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/acl/StaffRoleAssignmentServiceIT.java index b8de7aa3a1..f19ec0adf0 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/acl/StaffRoleAssignmentServiceIT.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/acl/StaffRoleAssignmentServiceIT.java @@ -18,7 +18,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.time.ZonedDateTime; import java.util.Calendar; @@ -32,6 +32,7 @@ import org.apache.jena.rdf.model.Statement; import org.apache.jena.rdf.model.StmtIterator; import org.apache.jena.vocabulary.RDF; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -77,7 +78,6 @@ import edu.unc.lib.boxc.model.fcrepo.test.RepositoryObjectTreeIndexer; import edu.unc.lib.boxc.model.fcrepo.test.TestHelper; import edu.unc.lib.boxc.operations.api.events.PremisLoggerFactory; -import edu.unc.lib.boxc.operations.impl.acl.StaffRoleAssignmentService; import edu.unc.lib.boxc.operations.jms.OperationsMessageSender; import edu.unc.lib.boxc.operations.jms.JMSMessageUtil.CDRActions; @@ -98,6 +98,8 @@ public class StaffRoleAssignmentServiceIT { private static final String GRP_PRINC = "group"; private static final Calendar TOMORROW = GregorianCalendar.from(ZonedDateTime.now().plusDays(1)); + private AutoCloseable closeable; + @Autowired private String baseAddress; @Mock @@ -132,7 +134,7 @@ public class StaffRoleAssignmentServiceIT { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(baseAddress); groups = new AccessGroupSetImpl(GRP_PRINC); @@ -152,6 +154,11 @@ public void init() throws Exception { contentRoot = repoObjLoader.getContentRootObject(contentRootPid); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testInsufficientPermissions() throws Exception { Assertions.assertThrows(AccessRestrictionException.class, () -> { diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/delete/MarkForDeletionJobTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/delete/MarkForDeletionJobTest.java index fd91c0a23b..34c8b4e2f5 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/delete/MarkForDeletionJobTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/delete/MarkForDeletionJobTest.java @@ -11,12 +11,13 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.net.URI; import java.util.List; import java.util.UUID; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -28,7 +29,6 @@ import edu.unc.lib.boxc.auth.api.models.AccessGroupSet; import edu.unc.lib.boxc.auth.api.models.AgentPrincipals; import edu.unc.lib.boxc.auth.api.services.AccessControlService; -import edu.unc.lib.boxc.auth.fcrepo.models.AccessGroupSetImpl; import edu.unc.lib.boxc.common.test.SelfReturningAnswer; import edu.unc.lib.boxc.model.api.exceptions.InvalidOperationForObjectType; import edu.unc.lib.boxc.model.api.ids.PID; @@ -42,7 +42,6 @@ import edu.unc.lib.boxc.operations.api.events.PremisEventBuilder; import edu.unc.lib.boxc.operations.api.events.PremisLogger; import edu.unc.lib.boxc.operations.api.events.PremisLoggerFactory; -import edu.unc.lib.boxc.operations.impl.delete.MarkForDeletionJob; import edu.unc.lib.boxc.operations.jms.OperationsMessageSender; /** @@ -53,6 +52,7 @@ public class MarkForDeletionJobTest { private static final String MESSAGE = "Reason for the deletion"; + private AutoCloseable closeable; @Mock private AccessControlService aclService; @@ -86,7 +86,7 @@ public class MarkForDeletionJobTest { @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); when(repositoryObjectLoader.getRepositoryObject(any(PID.class))).thenReturn(contentObj); @@ -105,6 +105,11 @@ public void init() { premisLoggerFactory); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void insufficientAccessTest() { Assertions.assertThrows(AccessRestrictionException.class, () -> { diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/delete/RestoreDeletedJobTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/delete/RestoreDeletedJobTest.java index 9c86bd67fa..be32e3b733 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/delete/RestoreDeletedJobTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/delete/RestoreDeletedJobTest.java @@ -9,11 +9,12 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.net.URI; import java.util.UUID; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -23,7 +24,6 @@ import edu.unc.lib.boxc.auth.api.models.AccessGroupSet; import edu.unc.lib.boxc.auth.api.models.AgentPrincipals; import edu.unc.lib.boxc.auth.api.services.AccessControlService; -import edu.unc.lib.boxc.auth.fcrepo.models.AccessGroupSetImpl; import edu.unc.lib.boxc.common.test.SelfReturningAnswer; import edu.unc.lib.boxc.model.api.exceptions.InvalidOperationForObjectType; import edu.unc.lib.boxc.model.api.ids.PID; @@ -37,7 +37,6 @@ import edu.unc.lib.boxc.operations.api.events.PremisEventBuilder; import edu.unc.lib.boxc.operations.api.events.PremisLogger; import edu.unc.lib.boxc.operations.api.events.PremisLoggerFactory; -import edu.unc.lib.boxc.operations.impl.delete.RestoreDeletedJob; /** * @@ -45,6 +44,7 @@ * */ public class RestoreDeletedJobTest { + private AutoCloseable closeable; @Mock private AccessControlService aclService; @@ -73,7 +73,7 @@ public class RestoreDeletedJobTest { @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); when(repositoryObjectLoader.getRepositoryObject(any(PID.class))).thenReturn(contentObj); @@ -92,6 +92,11 @@ public void init() { aclService, premisLoggerFactory); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void insufficientAccessTest() { Assertions.assertThrows(AccessRestrictionException.class, () -> { diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/destroy/DestroyObjectsCompletelyJobIT.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/destroy/DestroyObjectsCompletelyJobIT.java index 39005fcddc..f82a43ee16 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/destroy/DestroyObjectsCompletelyJobIT.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/destroy/DestroyObjectsCompletelyJobIT.java @@ -14,7 +14,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.nio.file.Files; @@ -32,6 +32,7 @@ import org.fcrepo.client.FcrepoResponse; import org.jdom2.Document; import org.jdom2.Element; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -70,7 +71,6 @@ import edu.unc.lib.boxc.model.fcrepo.test.AclModelBuilder; import edu.unc.lib.boxc.model.fcrepo.test.RepositoryObjectTreeIndexer; import edu.unc.lib.boxc.model.fcrepo.test.TestHelper; -import edu.unc.lib.boxc.operations.impl.destroy.DestroyObjectsCompletelyJob; import edu.unc.lib.boxc.operations.impl.edit.EditTitleService; import edu.unc.lib.boxc.operations.jms.MessageSender; import edu.unc.lib.boxc.operations.jms.destroy.DestroyObjectsRequest; @@ -94,6 +94,8 @@ public class DestroyObjectsCompletelyJobIT { private static final String USER_NAME = "user"; private static final String USER_GROUPS = "edu:lib:staff_grp"; + private AutoCloseable closeable; + @TempDir public Path tmpFolder; @@ -141,7 +143,7 @@ public class DestroyObjectsCompletelyJobIT { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(baseAddress); AccessGroupSet testPrincipals = new AccessGroupSetImpl(USER_GROUPS); @@ -152,6 +154,11 @@ public void init() throws Exception { treeIndexer = new RepositoryObjectTreeIndexer(queryModel, fcrepoClient); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + private void createContentTree() throws Exception { PID contentRootPid = getContentRootPid(); repoInitializer.initializeRepository(); diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/destroy/DestroyObjectsJobIT.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/destroy/DestroyObjectsJobIT.java index 123b205d78..4ce860c14e 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/destroy/DestroyObjectsJobIT.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/destroy/DestroyObjectsJobIT.java @@ -49,6 +49,7 @@ import org.fcrepo.client.FcrepoClient; import org.jdom2.Document; import org.jdom2.Element; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -90,7 +91,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; /** * @@ -108,6 +109,8 @@ public class DestroyObjectsJobIT { private static final String USER_NAME = "user"; private static final String USER_GROUPS = "edu:lib:staff_grp"; + private AutoCloseable closeable; + @TempDir public Path tmpFolder; @@ -166,7 +169,7 @@ public class DestroyObjectsJobIT { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(baseAddress); AccessGroupSet testPrincipals = new AccessGroupSetImpl(USER_GROUPS); @@ -181,6 +184,11 @@ public void init() throws Exception { when(path.toIdPath()).thenReturn("pid0/pid1/pid2/pid3"); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void destroySingleFileObjectTest() throws Exception { PID fileObjPid = objsToDestroy.get(2); diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/EditFilenameServiceTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/EditFilenameServiceTest.java index 9fcd899b87..703ce59132 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/EditFilenameServiceTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/EditFilenameServiceTest.java @@ -9,13 +9,14 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.List; import java.util.UUID; import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.Resource; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,7 +31,6 @@ import edu.unc.lib.boxc.auth.api.models.AccessGroupSet; import edu.unc.lib.boxc.auth.api.models.AgentPrincipals; import edu.unc.lib.boxc.auth.api.services.AccessControlService; -import edu.unc.lib.boxc.auth.fcrepo.models.AccessGroupSetImpl; import edu.unc.lib.boxc.common.test.SelfReturningAnswer; import edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException; import edu.unc.lib.boxc.fcrepo.utils.FedoraTransaction; @@ -56,6 +56,7 @@ * */ public class EditFilenameServiceTest { + private AutoCloseable closeable; @Mock private AccessControlService aclService; @@ -101,7 +102,7 @@ public class EditFilenameServiceTest { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); pid = PIDs.get(UUID.randomUUID().toString()); @@ -137,6 +138,11 @@ public Object answer(InvocationOnMock invocation) throws Throwable { }).when(tx).cancel(any(Throwable.class)); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void editFilenameTest() { when(binaryObj.getFilename()).thenReturn("Old file name"); diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/EditTitleServiceTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/EditTitleServiceTest.java index 02b5b2f890..6ed3f56f18 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/EditTitleServiceTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/EditTitleServiceTest.java @@ -11,7 +11,7 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -25,6 +25,7 @@ import org.jdom2.JDOMException; import org.jdom2.input.SAXBuilder; import org.jdom2.output.XMLOutputter; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -43,12 +44,11 @@ import edu.unc.lib.boxc.model.api.objects.ContentObject; import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; -import edu.unc.lib.boxc.operations.impl.edit.EditTitleService; -import edu.unc.lib.boxc.operations.impl.edit.UpdateDescriptionService; import edu.unc.lib.boxc.operations.impl.edit.UpdateDescriptionService.UpdateDescriptionRequest; import edu.unc.lib.boxc.operations.jms.OperationsMessageSender; public class EditTitleServiceTest { + private AutoCloseable closeable; @Mock private AccessControlService aclService; @@ -78,7 +78,7 @@ public class EditTitleServiceTest { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); pid = PIDs.get(UUID.randomUUID().toString()); service = new EditTitleService(); @@ -99,6 +99,11 @@ public void init() throws Exception { document = new Document(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void editTitleTest() throws Exception { String title = "new title"; diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/UpdateDescriptionServiceIT.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/UpdateDescriptionServiceIT.java index 46508ffd7f..f9647d0c3b 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/UpdateDescriptionServiceIT.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/UpdateDescriptionServiceIT.java @@ -7,7 +7,7 @@ import static edu.unc.lib.boxc.operations.test.ModsTestHelper.modsWithTitleAndDate; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.IOException; import java.io.InputStream; @@ -17,6 +17,7 @@ import org.jdom2.Element; import org.jdom2.JDOMException; import org.jdom2.input.SAXBuilder; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -35,7 +36,6 @@ import edu.unc.lib.boxc.model.api.services.RepositoryObjectFactory; import edu.unc.lib.boxc.model.fcrepo.ids.DatastreamPids; import edu.unc.lib.boxc.model.fcrepo.test.TestHelper; -import edu.unc.lib.boxc.operations.impl.edit.UpdateDescriptionService; import edu.unc.lib.boxc.operations.impl.edit.UpdateDescriptionService.UpdateDescriptionRequest; /** @@ -48,6 +48,8 @@ @ContextConfiguration("/spring-test/import-job-it.xml") }) public class UpdateDescriptionServiceIT { + private AutoCloseable closeable; + @Autowired private String baseAddress; @Autowired @@ -61,11 +63,16 @@ public class UpdateDescriptionServiceIT { @BeforeEach public void init_() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(baseAddress); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void addDescriptionToWork() throws Exception { WorkObject workObj = repoObjFactory.createWorkObject(null); diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/UpdateDescriptionServiceTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/UpdateDescriptionServiceTest.java index 7ffed7cc56..93e4cbb75b 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/UpdateDescriptionServiceTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/edit/UpdateDescriptionServiceTest.java @@ -10,7 +10,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.ByteArrayInputStream; import java.io.InputStream; @@ -18,6 +18,7 @@ import java.util.UUID; import org.apache.commons.io.IOUtils; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -30,7 +31,6 @@ import edu.unc.lib.boxc.auth.api.models.AccessGroupSet; import edu.unc.lib.boxc.auth.api.models.AgentPrincipals; import edu.unc.lib.boxc.auth.api.services.AccessControlService; -import edu.unc.lib.boxc.auth.fcrepo.models.AccessGroupSetImpl; import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.model.api.objects.BinaryObject; import edu.unc.lib.boxc.model.api.objects.ContentObject; @@ -43,7 +43,6 @@ import edu.unc.lib.boxc.operations.impl.versioning.VersionedDatastreamService; import edu.unc.lib.boxc.operations.impl.versioning.VersionedDatastreamService.DatastreamVersion; import edu.unc.lib.boxc.operations.jms.OperationsMessageSender; -import edu.unc.lib.boxc.operations.jms.indexing.IndexingPriority; import edu.unc.lib.boxc.persist.api.storage.StorageLocation; import edu.unc.lib.boxc.persist.api.transfer.BinaryTransferSession; @@ -55,6 +54,7 @@ public class UpdateDescriptionServiceTest { private static final String FILE_CONTENT = "Some content"; + private AutoCloseable closeable; @Mock private AccessControlService aclService; @@ -95,7 +95,7 @@ public class UpdateDescriptionServiceTest { @SuppressWarnings("unchecked") @BeforeEach public void init() throws Exception{ - initMocks(this); + closeable = openMocks(this); when(agent.getPrincipals()).thenReturn(groups); when(agent.getUsername()).thenReturn("username"); @@ -119,6 +119,11 @@ public void init() throws Exception{ service.setVersionedDatastreamService(versioningService); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void updateDescriptionTest() throws Exception { service.updateDescription(new UpdateDescriptionRequest(agent, objPid, modsStream)); diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/importxml/ImportXMLJobIT.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/importxml/ImportXMLJobIT.java index 0dbdc7f9c1..75aa7237a1 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/importxml/ImportXMLJobIT.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/importxml/ImportXMLJobIT.java @@ -12,12 +12,11 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.nio.file.Files; import java.nio.file.Path; import java.time.Instant; import java.util.UUID; @@ -28,6 +27,7 @@ import org.jdom2.Element; import org.jdom2.JDOMException; import org.jdom2.input.SAXBuilder; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; @@ -69,6 +69,7 @@ public class ImportXMLJobIT { private ImportXMLJob job; + private AutoCloseable closeable; private final static String USER_EMAIL = "user@example.com"; @@ -117,7 +118,7 @@ public class ImportXMLJobIT { @BeforeEach public void init_() throws Exception { - initMocks(this); + closeable = openMocks(this); tempDir = tmpFolder.resolve("tempDir").toFile(); @@ -127,6 +128,11 @@ public void init_() throws Exception { TestHelper.setContentBase(baseAddress); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testMODSGetsUpdated() throws Exception { PID workPid = populateFedora(); diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/importxml/ImportXMLJobTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/importxml/ImportXMLJobTest.java index 20158fae39..4e135e7698 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/importxml/ImportXMLJobTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/importxml/ImportXMLJobTest.java @@ -16,7 +16,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.nio.file.Files; @@ -36,6 +36,7 @@ import org.jdom2.Document; import org.jdom2.Element; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -80,6 +81,7 @@ public class ImportXMLJobTest { private static final String ADMIN_EMAIL = "admin@example.com"; private ImportXMLJob job; + private AutoCloseable closeable; @Mock private AgentPrincipals agent; @@ -129,7 +131,7 @@ public class ImportXMLJobTest { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); when(mailSender.createMimeMessage()).thenReturn(msg); @@ -138,6 +140,11 @@ public void init() throws Exception { when(locationManager.getStorageLocation(any(PID.class))).thenReturn(storageLocation); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @SuppressWarnings("unchecked") @Test public void emptyFileTest() throws Exception { diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/move/MoveObjectsServiceTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/move/MoveObjectsServiceTest.java index 92a7012b79..2e083f4525 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/move/MoveObjectsServiceTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/move/MoveObjectsServiceTest.java @@ -1,7 +1,6 @@ package edu.unc.lib.boxc.operations.impl.move; import static java.util.Arrays.asList; -import static org.hamcrest.CoreMatchers.isA; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertTrue; @@ -15,7 +14,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.ArrayList; import java.util.Iterator; @@ -48,7 +47,6 @@ import edu.unc.lib.boxc.auth.api.models.AccessGroupSet; import edu.unc.lib.boxc.auth.api.models.AgentPrincipals; import edu.unc.lib.boxc.auth.api.services.AccessControlService; -import edu.unc.lib.boxc.auth.fcrepo.models.AccessGroupSetImpl; import edu.unc.lib.boxc.fcrepo.exceptions.TransactionCancelledException; import edu.unc.lib.boxc.fcrepo.utils.FedoraTransaction; import edu.unc.lib.boxc.fcrepo.utils.TransactionManager; @@ -74,6 +72,7 @@ public class MoveObjectsServiceTest { private final static String DEST_OBJ_PATH = "/path/to/destination"; private final static String SOURCE_OBJ_PATH = "/path/to/source"; + private AutoCloseable closeable; @Mock private AccessControlService aclService; @@ -119,7 +118,7 @@ public class MoveObjectsServiceTest { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); service = new MoveObjectsService(); service.setAclService(aclService); @@ -165,7 +164,8 @@ public Exception answer(InvocationOnMock invocation) throws Throwable { } @AfterEach - public void after() { + public void after() throws Exception { + closeable.close(); actionAppender.stop(); } diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/ClearOrderJobTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/ClearOrderJobTest.java index 241f2957ae..a512eec7c7 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/ClearOrderJobTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/ClearOrderJobTest.java @@ -7,19 +7,21 @@ import edu.unc.lib.boxc.model.api.services.RepositoryObjectFactory; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; import edu.unc.lib.boxc.operations.jms.order.OrderOperationType; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author bbpennel */ public class ClearOrderJobTest { private static final String PARENT_UUID = "f277bb38-272c-471c-a28a-9887a1328a1f"; + private AutoCloseable closeable; @Mock private RepositoryObjectFactory repositoryObjectFactory; @Mock @@ -31,7 +33,7 @@ public class ClearOrderJobTest { @BeforeEach public void init() { - MockitoAnnotations.initMocks(this); + closeable = openMocks(this); parentPid = PIDs.get(PARENT_UUID); orderJobFactory = new OrderJobFactory(); orderJobFactory.setRepositoryObjectFactory(repositoryObjectFactory); @@ -39,6 +41,11 @@ public void init() { when(repositoryObjectLoader.getRepositoryObject(parentPid)).thenReturn(parentWork); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void clearChildrenTest() { var request = OrderRequestFactory.createRequest(OrderOperationType.CLEAR, PARENT_UUID); diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/OrderJobFactoryTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/OrderJobFactoryTest.java index e5abf702ef..4aefd441cf 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/OrderJobFactoryTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/OrderJobFactoryTest.java @@ -3,15 +3,16 @@ import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader; import edu.unc.lib.boxc.model.api.services.RepositoryObjectFactory; import edu.unc.lib.boxc.operations.jms.order.OrderOperationType; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import java.util.Arrays; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author bbpennel @@ -20,6 +21,7 @@ public class OrderJobFactoryTest { private static final String CHILD1_UUID = "83c2d7f8-2e6b-4f0b-ab7e-7397969c0682"; private static final String CHILD2_UUID = "0e33ad0b-7a16-4bfa-b833-6126c262d889"; private static final String PARENT_UUID = "9cb6cc61-d88e-403e-b959-2396cd331a12"; + private AutoCloseable closeable; @Mock private RepositoryObjectFactory repositoryObjectFactory; @Mock @@ -28,12 +30,17 @@ public class OrderJobFactoryTest { @BeforeEach public void init() { - MockitoAnnotations.initMocks(this); + closeable = openMocks(this); factory = new OrderJobFactory(); factory.setRepositoryObjectFactory(repositoryObjectFactory); factory.setRepositoryObjectLoader(repositoryObjectLoader); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void createClearRequestTest() { var request = OrderRequestFactory.createRequest(OrderOperationType.CLEAR, PARENT_UUID); diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/OrderValidatorFactoryTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/OrderValidatorFactoryTest.java index f14f0bd8ba..4cd886e796 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/OrderValidatorFactoryTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/OrderValidatorFactoryTest.java @@ -3,14 +3,15 @@ import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader; import edu.unc.lib.boxc.model.api.services.MembershipService; import edu.unc.lib.boxc.operations.jms.order.OrderOperationType; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import java.util.Arrays; import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author bbpennel @@ -18,6 +19,7 @@ public class OrderValidatorFactoryTest { private static final String PARENT_UUID = "f277bb38-272c-471c-a28a-9887a1328a1f"; private static final String CHILD1_UUID = "83c2d7f8-2e6b-4f0b-ab7e-7397969c0682"; + private AutoCloseable closeable; @Mock private RepositoryObjectLoader repositoryObjectLoader; @Mock @@ -26,12 +28,17 @@ public class OrderValidatorFactoryTest { @BeforeEach public void setup() { - MockitoAnnotations.initMocks(this); + closeable = openMocks(this); factory = new OrderValidatorFactory(); factory.setMembershipService(membershipService); factory.setRepositoryObjectLoader(repositoryObjectLoader); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void forSetOrderRequestTest() { var request = OrderRequestFactory.createRequest(OrderOperationType.SET, PARENT_UUID, Arrays.asList(CHILD1_UUID)); diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/RemoveFromJobTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/RemoveFromJobTest.java index 070c411f5d..d2ae334ba1 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/RemoveFromJobTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/RemoveFromJobTest.java @@ -7,13 +7,12 @@ import edu.unc.lib.boxc.model.api.services.RepositoryObjectFactory; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; import edu.unc.lib.boxc.operations.jms.order.OrderOperationType; -import edu.unc.lib.boxc.operations.test.OrderTestHelper; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import java.util.Arrays; import java.util.LinkedList; @@ -24,6 +23,7 @@ import static org.mockito.Mockito.when; import static edu.unc.lib.boxc.operations.test.OrderTestHelper.createRequest; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author snluong @@ -34,6 +34,8 @@ public class RemoveFromJobTest { private static final String CHILD2_UUID = "0e33ad0b-7a16-4bfa-b833-6126c262d889"; private static final String CHILD3_UUID = "9cb6cc61-d88e-403e-b959-2396cd331a12"; + private AutoCloseable closeable; + @Mock private RepositoryObjectFactory repositoryObjectFactory; @Mock @@ -47,7 +49,7 @@ public class RemoveFromJobTest { @BeforeEach public void init() { - MockitoAnnotations.initMocks(this); + closeable = openMocks(this); parentPid = PIDs.get(PARENT_UUID); orderJobFactory = new OrderJobFactory(); orderJobFactory.setRepositoryObjectFactory(repositoryObjectFactory); @@ -59,6 +61,11 @@ public void init() { when(parentWork.getMemberOrder()).thenReturn(childrenOrder); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void removeOneChildFromMemberOrder() { var request = createRequest(OrderOperationType.REMOVE_FROM, PARENT_UUID, CHILD1_UUID); diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/RemoveFromOrderValidatorTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/RemoveFromOrderValidatorTest.java index 26fae5b999..349e016fff 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/RemoveFromOrderValidatorTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/RemoveFromOrderValidatorTest.java @@ -8,10 +8,10 @@ import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; import edu.unc.lib.boxc.operations.jms.order.OrderOperationType; import edu.unc.lib.boxc.operations.test.OrderTestHelper; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import java.util.Arrays; import java.util.List; @@ -21,6 +21,7 @@ import static org.mockito.Mockito.when; import static edu.unc.lib.boxc.operations.test.OrderTestHelper.mockParentType; import static edu.unc.lib.boxc.operations.test.OrderTestHelper.assertHasErrors; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author snluong @@ -30,6 +31,7 @@ public class RemoveFromOrderValidatorTest { private static final String CHILD1_UUID = "83c2d7f8-2e6b-4f0b-ab7e-7397969c0682"; private static final String CHILD2_UUID = "0e33ad0b-7a16-4bfa-b833-6126c262d889"; private static final String CHILD3_UUID = "9cb6cc61-d88e-403e-b959-2396cd331a12"; + private AutoCloseable closeable; @Mock private RepositoryObjectLoader repositoryObjectLoader; @Mock @@ -44,7 +46,7 @@ public class RemoveFromOrderValidatorTest { @BeforeEach public void setup() { - MockitoAnnotations.initMocks(this); + closeable = openMocks(this); validator = new RemoveFromOrderValidator(); validator.setRepositoryObjectLoader(repositoryObjectLoader); @@ -56,6 +58,11 @@ public void setup() { mockParentType(parentObj, ResourceType.Work); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void targetNotAWorkTest() { OrderTestHelper.mockParentType(parentObj, ResourceType.AdminUnit); diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/SetOrderJobTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/SetOrderJobTest.java index 55e55f34e1..01e9cf5d0f 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/SetOrderJobTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/SetOrderJobTest.java @@ -8,17 +8,18 @@ import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; import edu.unc.lib.boxc.operations.jms.order.OrderOperationType; import edu.unc.lib.boxc.operations.test.OrderTestHelper; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author bbpennel @@ -28,6 +29,7 @@ public class SetOrderJobTest { private static final String CHILD1_UUID = "83c2d7f8-2e6b-4f0b-ab7e-7397969c0682"; private static final String CHILD2_UUID = "0e33ad0b-7a16-4bfa-b833-6126c262d889"; private static final String CHILD3_UUID = "9cb6cc61-d88e-403e-b959-2396cd331a12"; + private AutoCloseable closeable; @Mock private RepositoryObjectFactory repositoryObjectFactory; @@ -42,7 +44,7 @@ public class SetOrderJobTest { @BeforeEach public void init() { - MockitoAnnotations.initMocks(this); + closeable = openMocks(this); parentPid = PIDs.get(PARENT_UUID); orderJobFactory = new OrderJobFactory(); orderJobFactory.setRepositoryObjectFactory(repositoryObjectFactory); @@ -50,6 +52,11 @@ public void init() { when(repositoryObjectLoader.getRepositoryObject(parentPid)).thenReturn(parentWork); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void singleChildTest() { var request = OrderTestHelper.createRequest(OrderOperationType.SET, PARENT_UUID, CHILD1_UUID); diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/SetOrderValidatorTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/SetOrderValidatorTest.java index b0f430108e..fb968b2b67 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/SetOrderValidatorTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/order/SetOrderValidatorTest.java @@ -7,10 +7,10 @@ import edu.unc.lib.boxc.model.api.services.MembershipService; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; import edu.unc.lib.boxc.operations.jms.order.OrderOperationType; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import java.util.Arrays; import java.util.Collections; @@ -20,6 +20,7 @@ import static org.mockito.Mockito.when; import static edu.unc.lib.boxc.operations.test.OrderTestHelper.assertHasErrors; import static edu.unc.lib.boxc.operations.test.OrderTestHelper.mockParentType; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author bbpennel @@ -29,6 +30,7 @@ public class SetOrderValidatorTest { private static final String CHILD1_UUID = "83c2d7f8-2e6b-4f0b-ab7e-7397969c0682"; private static final String CHILD2_UUID = "0e33ad0b-7a16-4bfa-b833-6126c262d889"; private static final String CHILD3_UUID = "9cb6cc61-d88e-403e-b959-2396cd331a12"; + private AutoCloseable closeable; @Mock private RepositoryObjectLoader repositoryObjectLoader; @Mock @@ -44,7 +46,7 @@ public class SetOrderValidatorTest { @BeforeEach public void setup() { - MockitoAnnotations.initMocks(this); + closeable = openMocks(this); validator = new SetOrderValidator(); validator.setRepositoryObjectLoader(repositoryObjectLoader); validator.setMembershipService(membershipService); @@ -57,6 +59,11 @@ public void setup() { mockParentType(parentObj, ResourceType.Work); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void targetNotAWorkTest() throws Exception { mockParentType(parentObj, ResourceType.AdminUnit); diff --git a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/versioning/DatastreamHistoryLogTest.java b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/versioning/DatastreamHistoryLogTest.java index d2f234a593..fd03140188 100644 --- a/operations/src/test/java/edu/unc/lib/boxc/operations/impl/versioning/DatastreamHistoryLogTest.java +++ b/operations/src/test/java/edu/unc/lib/boxc/operations/impl/versioning/DatastreamHistoryLogTest.java @@ -4,7 +4,7 @@ import static edu.unc.lib.boxc.model.api.xml.JDOMNamespaceUtil.DCR_PACKAGING_NS; import static edu.unc.lib.boxc.model.api.xml.JDOMNamespaceUtil.MODS_V3_NS; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -17,6 +17,7 @@ import org.jdom2.Element; import org.jdom2.output.Format; import org.jdom2.output.XMLOutputter; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -25,7 +26,6 @@ import edu.unc.lib.boxc.fcrepo.exceptions.ServiceException; import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; -import edu.unc.lib.boxc.operations.impl.versioning.DatastreamHistoryLog; /** * @author bbpennel @@ -40,13 +40,19 @@ public class DatastreamHistoryLogTest { private static final Date VERSION2_DATE = parseUTCToDate(VERSION2_TIME); private PID dsPid; + private AutoCloseable closeable; @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); dsPid = PIDs.get(TEST_ID); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void addVersion_NewLog_XmlContent() throws Exception { DatastreamHistoryLog historyLog = new DatastreamHistoryLog(dsPid); diff --git a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/sources/IngestSourceManagerImplTest.java b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/sources/IngestSourceManagerImplTest.java index 30fbaa0df4..0a2176197d 100644 --- a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/sources/IngestSourceManagerImplTest.java +++ b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/sources/IngestSourceManagerImplTest.java @@ -12,7 +12,7 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.net.URI; import java.nio.file.Files; @@ -22,6 +22,7 @@ import java.util.Map; import java.util.UUID; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -42,6 +43,8 @@ * @author bbpennel */ public class IngestSourceManagerImplTest { + private AutoCloseable closeable; + @TempDir public Path tmpFolder; private Path sourceFolderPath; @@ -62,7 +65,7 @@ public class IngestSourceManagerImplTest { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); sourceFolderPath = tmpFolder.resolve("sourceFolder"); Files.createDirectory(sourceFolderPath); @@ -75,6 +78,11 @@ public void init() throws Exception { mockAncestors(destPid, rootPid, adminUnitPid); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + private void initializeManager() throws Exception { mappingPath = serializeLocationMappings(mappingList); diff --git a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/storage/StorageLocationManagerImplTest.java b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/storage/StorageLocationManagerImplTest.java index 11576857b2..121e8a832b 100644 --- a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/storage/StorageLocationManagerImplTest.java +++ b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/storage/StorageLocationManagerImplTest.java @@ -7,7 +7,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.net.URI; import java.nio.file.Path; @@ -18,6 +18,7 @@ import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.ModelFactory; import org.apache.jena.rdf.model.Resource; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -34,7 +35,6 @@ import edu.unc.lib.boxc.persist.api.storage.StorageLocation; import edu.unc.lib.boxc.persist.api.storage.StorageType; import edu.unc.lib.boxc.persist.api.storage.UnknownStorageLocationException; -import edu.unc.lib.boxc.persist.impl.storage.StorageLocationManagerImpl; /** * @author bbpennel @@ -48,6 +48,8 @@ public class StorageLocationManagerImplTest { private static final String LOC2_NAME = "Stor2"; private static final String LOC2_BASE = "file://some/other"; + private AutoCloseable closeable; + @Mock private ContentPathFactory pathFactory; @Mock @@ -62,7 +64,7 @@ public class StorageLocationManagerImplTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); locManager = new StorageLocationManagerImpl(); locManager.setPathFactory(pathFactory); @@ -71,6 +73,11 @@ public void setup() throws Exception { helper = new StorageLocationTestHelper(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + private void initializeManager() throws Exception { locManager.setConfigPath(helper.serializeLocationConfig()); locManager.setMappingPath(helper.serializeLocationMappings()); diff --git a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/BinaryTransferSessionImplTest.java b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/BinaryTransferSessionImplTest.java index 6cbd0b2702..161f646128 100644 --- a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/BinaryTransferSessionImplTest.java +++ b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/BinaryTransferSessionImplTest.java @@ -7,7 +7,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.net.URI; import java.nio.file.Files; @@ -15,6 +15,7 @@ import java.nio.file.Paths; import org.apache.commons.lang3.NotImplementedException; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -26,8 +27,6 @@ import edu.unc.lib.boxc.persist.api.storage.StorageLocation; import edu.unc.lib.boxc.persist.api.transfer.BinaryTransferOutcome; import edu.unc.lib.boxc.persist.api.transfer.BinaryTransferService; -import edu.unc.lib.boxc.persist.impl.transfer.BinaryTransferServiceImpl; -import edu.unc.lib.boxc.persist.impl.transfer.BinaryTransferSessionImpl; /** * @author bbpennel @@ -36,6 +35,7 @@ public class BinaryTransferSessionImplTest extends AbstractBinaryTransferTest { private BinaryTransferSessionImpl session; + private AutoCloseable closeable; private BinaryTransferService bts; @Mock @@ -50,7 +50,7 @@ public class BinaryTransferSessionImplTest extends AbstractBinaryTransferTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); createPaths(); binPid = makeBinPid(); @@ -65,6 +65,11 @@ public void setup() throws Exception { bts = new BinaryTransferServiceImpl(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void transferFSToFSInTry() throws Exception { when(ingestSource.getStorageType()).thenReturn(FILESYSTEM); diff --git a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/FSToFSTransferClientTest.java b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/FSToFSTransferClientTest.java index 33a06148ec..917f49f71f 100644 --- a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/FSToFSTransferClientTest.java +++ b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/FSToFSTransferClientTest.java @@ -9,7 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.io.RandomAccessFile; @@ -22,6 +22,7 @@ import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.NotImplementedException; import org.awaitility.Awaitility; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -37,7 +38,6 @@ import edu.unc.lib.boxc.persist.api.transfer.BinaryTransferException; import edu.unc.lib.boxc.persist.api.transfer.BinaryTransferOutcome; import edu.unc.lib.boxc.persist.impl.storage.HashedFilesystemStorageLocation; -import edu.unc.lib.boxc.persist.impl.transfer.FSToFSTransferClient; /** * @author bbpennel @@ -50,6 +50,7 @@ public class FSToFSTransferClientTest { protected static final String FILE_CONTENT_SHA1 = "6c4244329888770c6fa7f3fbf1d3b8baf9ccb7d0"; protected FSToFSTransferClient client; + private AutoCloseable closeable; @TempDir public Path tmpFolder; @@ -63,7 +64,7 @@ public class FSToFSTransferClientTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); sourcePath = tmpFolder.resolve("source"); Files.createDirectory(sourcePath); storagePath = tmpFolder.resolve("storage"); @@ -79,6 +80,11 @@ public void setup() throws Exception { binPid = getOriginalFilePid(PIDs.get(TEST_UUID)); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void transferFileThatDoesNotExist() { Assertions.assertThrows(BinaryTransferException.class, () -> { diff --git a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/FSToPosixTransferClientTest.java b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/FSToPosixTransferClientTest.java index 2f7dea307b..da71c6ce91 100644 --- a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/FSToPosixTransferClientTest.java +++ b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/FSToPosixTransferClientTest.java @@ -3,7 +3,7 @@ import static edu.unc.lib.boxc.model.fcrepo.ids.DatastreamPids.getOriginalFilePid; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.net.URI; import java.nio.file.Files; @@ -12,13 +12,13 @@ import java.nio.file.attribute.PosixFilePermission; import java.util.Set; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; import edu.unc.lib.boxc.persist.api.transfer.BinaryTransferOutcome; import edu.unc.lib.boxc.persist.impl.storage.HashedPosixStorageLocation; -import edu.unc.lib.boxc.persist.impl.transfer.FSToPosixTransferClient; /** * @author bbpennel @@ -26,11 +26,12 @@ public class FSToPosixTransferClientTest extends FSToFSTransferClientTest { private FSToPosixTransferClient posixClient; + private AutoCloseable closeable; @Override @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); sourcePath = tmpFolder.resolve("source"); Files.createDirectory(sourcePath); storagePath = tmpFolder.resolve("storage"); @@ -47,6 +48,11 @@ public void setup() throws Exception { binPid = getOriginalFilePid(PIDs.get(TEST_UUID)); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void transfer_NewFile_WithPermissions() throws Exception { ((HashedPosixStorageLocation) storageLoc).setPermissions("0600"); diff --git a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/MultiDestinationTransferSessionImplTest.java b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/MultiDestinationTransferSessionImplTest.java index 0266e495f6..e9417fa3b5 100644 --- a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/MultiDestinationTransferSessionImplTest.java +++ b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/MultiDestinationTransferSessionImplTest.java @@ -4,13 +4,14 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.net.URI; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -24,8 +25,6 @@ import edu.unc.lib.boxc.persist.api.transfer.BinaryTransferOutcome; import edu.unc.lib.boxc.persist.api.transfer.BinaryTransferService; import edu.unc.lib.boxc.persist.api.transfer.BinaryTransferSession; -import edu.unc.lib.boxc.persist.impl.transfer.BinaryTransferServiceImpl; -import edu.unc.lib.boxc.persist.impl.transfer.MultiDestinationTransferSessionImpl; /** * @author bbpennel @@ -36,6 +35,7 @@ public class MultiDestinationTransferSessionImplTest extends AbstractBinaryTrans private static final String FILE_CONTENT = "File content"; private Path storagePath2; + private AutoCloseable closeable; @Mock private IngestSourceManager sourceManager; @Mock @@ -53,7 +53,7 @@ public class MultiDestinationTransferSessionImplTest extends AbstractBinaryTrans @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); createPaths(); binPid = makeBinPid(); @@ -70,6 +70,11 @@ public void setup() throws Exception { bts = new BinaryTransferServiceImpl(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void noDestination() throws Exception { Assertions.assertThrows(IllegalArgumentException.class, () -> { diff --git a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/StreamToFSTransferClientTest.java b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/StreamToFSTransferClientTest.java index 54cd02a583..d568700ffc 100644 --- a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/StreamToFSTransferClientTest.java +++ b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/StreamToFSTransferClientTest.java @@ -10,7 +10,7 @@ import static org.mockito.Matchers.anyInt; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.ByteArrayInputStream; import java.io.File; @@ -22,6 +22,7 @@ import java.nio.file.Paths; import org.apache.commons.io.FileUtils; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -47,6 +48,7 @@ public class StreamToFSTransferClientTest { protected static final String STREAM_CONTENT_SHA1 = "bf29c7fd7f87fe7395b89012e73d91c85a0cb19b"; protected StreamToFSTransferClient client; + private AutoCloseable closeable; @TempDir public Path tmpFolder; @@ -58,7 +60,7 @@ public class StreamToFSTransferClientTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); sourcePath = tmpFolder.resolve("source"); Files.createDirectory(sourcePath); storagePath = tmpFolder.resolve("storage"); @@ -74,6 +76,11 @@ public void setup() throws Exception { binPid = getOriginalFilePid(PIDs.get(TEST_UUID)); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void transfer_NewFile() throws Exception { InputStream sourceStream = toStream(STREAM_CONTENT); diff --git a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/StreamToPosixTransferClientTest.java b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/StreamToPosixTransferClientTest.java index 96b7b2bb72..658c1bac52 100644 --- a/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/StreamToPosixTransferClientTest.java +++ b/persistence/src/test/java/edu/unc/lib/boxc/persist/impl/transfer/StreamToPosixTransferClientTest.java @@ -3,7 +3,7 @@ import static edu.unc.lib.boxc.model.fcrepo.ids.DatastreamPids.getOriginalFilePid; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.InputStream; import java.net.URI; @@ -12,13 +12,13 @@ import java.nio.file.attribute.PosixFilePermission; import java.util.Set; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; import edu.unc.lib.boxc.persist.api.transfer.BinaryTransferOutcome; import edu.unc.lib.boxc.persist.impl.storage.HashedPosixStorageLocation; -import edu.unc.lib.boxc.persist.impl.transfer.StreamToPosixTransferClient; /** * @author bbpennel @@ -26,11 +26,12 @@ public class StreamToPosixTransferClientTest extends StreamToFSTransferClientTest { private StreamToPosixTransferClient posixClient; + private AutoCloseable closeable; @Override @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); storagePath = tmpFolder.resolve("storage"); Files.createDirectory(storagePath); @@ -45,6 +46,11 @@ public void setup() throws Exception { binPid = getOriginalFilePid(PIDs.get(TEST_UUID)); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void transfer_NewFile_WithPermissions() throws Exception { ((HashedPosixStorageLocation) storageLoc).setPermissions("0600"); diff --git a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/ChildrenCountServiceIT.java b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/ChildrenCountServiceIT.java index 1a59886e2f..db6663d383 100644 --- a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/ChildrenCountServiceIT.java +++ b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/ChildrenCountServiceIT.java @@ -9,7 +9,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Matchers.anySetOf; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.ArrayList; import java.util.List; @@ -17,6 +17,7 @@ import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.common.SolrInputDocument; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -30,8 +31,6 @@ import edu.unc.lib.boxc.search.api.models.ContentObjectRecord; import edu.unc.lib.boxc.search.api.requests.SimpleIdRequest; import edu.unc.lib.boxc.search.solr.config.SearchSettings; -import edu.unc.lib.boxc.search.solr.services.ChildrenCountService; -import edu.unc.lib.boxc.search.solr.services.SolrSearchService; import edu.unc.lib.boxc.search.solr.test.BaseEmbeddedSolrTest; import edu.unc.lib.boxc.search.solr.test.TestCorpus; import edu.unc.lib.boxc.search.solr.utils.AccessRestrictionUtil; @@ -42,6 +41,7 @@ * */ public class ChildrenCountServiceIT extends BaseEmbeddedSolrTest { + private AutoCloseable closeable; @Mock private GlobalPermissionEvaluator globalPermissionEvaluator; @@ -62,7 +62,7 @@ public ChildrenCountServiceIT() { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); index(testCorpus.populate()); @@ -87,6 +87,11 @@ public void init() throws Exception { principals = new AccessGroupSetImpl(PUBLIC_PRINC); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testGetChildrenCount() throws Exception { ContentObjectRecord bom = getObject(testCorpus.coll1Pid); diff --git a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/FacetValuesServiceIT.java b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/FacetValuesServiceIT.java index cc27558bbb..172cd86949 100644 --- a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/FacetValuesServiceIT.java +++ b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/FacetValuesServiceIT.java @@ -20,6 +20,7 @@ import edu.unc.lib.boxc.search.solr.utils.FacetFieldUtil; import org.apache.commons.lang3.ArrayUtils; import org.apache.solr.common.SolrInputDocument; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -33,7 +34,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author bbpennel @@ -47,6 +48,7 @@ public class FacetValuesServiceIT extends BaseEmbeddedSolrTest { private final static String SUBJECT_6 = "University of North Carolina"; private final static String SUBJECT_7 = "Chapel Hill"; private final static String SUBJECT_8 = "Boxy"; + private AutoCloseable closeable; @Mock private GlobalPermissionEvaluator globalPermissionEvaluator; @@ -67,7 +69,7 @@ public FacetValuesServiceIT() { @BeforeEach public void setupFacets() throws Exception { - initMocks(this); + closeable = openMocks(this); accessRestrictionUtil = new AccessRestrictionUtil(); accessRestrictionUtil.setSearchSettings(searchSettings); @@ -101,6 +103,11 @@ public void setupFacets() throws Exception { } } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void singlePageOfResultsTest() throws Exception { var request = buildFacetRequest(); diff --git a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/GetCollectionIdServiceIT.java b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/GetCollectionIdServiceIT.java index 02b5844d0a..fbd9378876 100644 --- a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/GetCollectionIdServiceIT.java +++ b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/GetCollectionIdServiceIT.java @@ -3,8 +3,9 @@ import static edu.unc.lib.boxc.common.test.TestHelpers.setField; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -12,8 +13,6 @@ import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.search.api.models.ContentObjectRecord; import edu.unc.lib.boxc.search.api.requests.SimpleIdRequest; -import edu.unc.lib.boxc.search.solr.services.GetCollectionIdService; -import edu.unc.lib.boxc.search.solr.services.SolrSearchService; import edu.unc.lib.boxc.search.solr.test.BaseEmbeddedSolrTest; import edu.unc.lib.boxc.search.solr.test.TestCorpus; import edu.unc.lib.boxc.search.solr.utils.AccessRestrictionUtil; @@ -25,6 +24,7 @@ public class GetCollectionIdServiceIT extends BaseEmbeddedSolrTest { private TestCorpus testCorpus; private GetCollectionIdService collIdService; private SolrSearchService solrSearchService; + private AutoCloseable closeable; @Mock private AccessRestrictionUtil restrictionUtil; @@ -34,7 +34,7 @@ public GetCollectionIdServiceIT() { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); index(testCorpus.populate()); @@ -48,6 +48,11 @@ public void init() throws Exception { setField(collIdService, "solrClient", server); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void collectionIdFromAncestorTest() throws Exception { ContentObjectRecord mdObj = getObject(testCorpus.work1Pid); diff --git a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/MultiSelectFacetListServiceIT.java b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/MultiSelectFacetListServiceIT.java index c094604fde..12276f2733 100644 --- a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/MultiSelectFacetListServiceIT.java +++ b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/MultiSelectFacetListServiceIT.java @@ -22,6 +22,7 @@ import edu.unc.lib.boxc.search.solr.test.TestCorpus; import edu.unc.lib.boxc.search.solr.utils.AccessRestrictionUtil; import edu.unc.lib.boxc.search.solr.utils.FacetFieldUtil; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -41,7 +42,7 @@ import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author bbpennel @@ -57,6 +58,7 @@ public class MultiSelectFacetListServiceIT extends BaseEmbeddedSolrTest { private TestCorpus testCorpus; private boolean corpusLoaded; private AccessGroupSet accessGroups; + private AutoCloseable closeable; @Mock private GlobalPermissionEvaluator globalPermissionEvaluator; @@ -72,7 +74,7 @@ public MultiSelectFacetListServiceIT() { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); if (!corpusLoaded) { corpusLoaded = true; index(testCorpus.populate()); @@ -106,6 +108,11 @@ public void init() throws Exception { accessGroups = new AccessGroupSetImpl("unitOwner", PUBLIC_PRINC); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void noFacetFiltersTest() throws Exception { SearchState searchState = new SearchState(); diff --git a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/NeighborQueryServiceIT.java b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/NeighborQueryServiceIT.java index dadabb6710..d607d9fd68 100644 --- a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/NeighborQueryServiceIT.java +++ b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/NeighborQueryServiceIT.java @@ -4,7 +4,7 @@ import static edu.unc.lib.boxc.common.test.TestHelpers.setField; import static java.util.Arrays.asList; import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.ArrayList; import java.util.List; @@ -12,6 +12,7 @@ import org.apache.commons.lang3.StringUtils; import org.apache.solr.common.SolrInputDocument; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -26,8 +27,6 @@ import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; import edu.unc.lib.boxc.search.api.models.ContentObjectRecord; import edu.unc.lib.boxc.search.api.requests.SimpleIdRequest; -import edu.unc.lib.boxc.search.solr.services.NeighborQueryService; -import edu.unc.lib.boxc.search.solr.services.SolrSearchService; import edu.unc.lib.boxc.search.solr.test.BaseEmbeddedSolrTest; import edu.unc.lib.boxc.search.solr.test.TestCorpus; import edu.unc.lib.boxc.search.solr.utils.AccessRestrictionUtil; @@ -53,6 +52,8 @@ public class NeighborQueryServiceIT extends BaseEmbeddedSolrTest { private TestCorpus testCorpus; + private AutoCloseable closeable; + @Mock private GlobalPermissionEvaluator globalPermissionEvaluator; @@ -71,7 +72,7 @@ public NeighborQueryServiceIT() { @Override @BeforeEach public void setUp() throws Exception { - initMocks(this); + closeable = openMocks(this); super.setUp(); @@ -103,6 +104,11 @@ public void setUp() throws Exception { setField(queryService, "solrClient", server); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testNeighborsMiddleList() throws Exception { populateNeighborhood(ResourceType.File, WINDOW_SIZE, WINDOW_SIZE, ResourceType.File); diff --git a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/ObjectPathFactoryIT.java b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/ObjectPathFactoryIT.java index d9b838ad69..6ba6c3d64d 100644 --- a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/ObjectPathFactoryIT.java +++ b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/ObjectPathFactoryIT.java @@ -3,12 +3,13 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Mockito.mock; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -19,8 +20,6 @@ import edu.unc.lib.boxc.search.api.models.ObjectPath; import edu.unc.lib.boxc.search.api.models.ObjectPathEntry; import edu.unc.lib.boxc.search.api.requests.SimpleIdRequest; -import edu.unc.lib.boxc.search.solr.services.ObjectPathFactory; -import edu.unc.lib.boxc.search.solr.services.SolrSearchService; import edu.unc.lib.boxc.search.solr.test.BaseEmbeddedSolrTest; import edu.unc.lib.boxc.search.solr.test.TestCorpus; import edu.unc.lib.boxc.search.solr.utils.AccessRestrictionUtil; @@ -36,6 +35,8 @@ public class ObjectPathFactoryIT extends BaseEmbeddedSolrTest { private ObjectPathFactory objPathFactory; + private AutoCloseable closeable; + @Mock private AccessRestrictionUtil restrictionUtil; @@ -45,7 +46,7 @@ public ObjectPathFactoryIT() { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); index(testCorpus.populate()); @@ -62,6 +63,11 @@ public void init() throws Exception { objPathFactory.init(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testGetWorkPathByPid() throws Exception { ObjectPath path = objPathFactory.getPath(testCorpus.work1Pid); diff --git a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/SetFacetTitleByIdServiceIT.java b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/SetFacetTitleByIdServiceIT.java index 3819ce06cb..f9c8cbe380 100644 --- a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/SetFacetTitleByIdServiceIT.java +++ b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/SetFacetTitleByIdServiceIT.java @@ -1,20 +1,17 @@ package edu.unc.lib.boxc.search.solr.services; import static edu.unc.lib.boxc.auth.api.AccessPrincipalConstants.PUBLIC_PRINC; -import static edu.unc.lib.boxc.search.api.SearchFieldKey.FILE_FORMAT_CATEGORY; import static edu.unc.lib.boxc.search.api.SearchFieldKey.PARENT_COLLECTION; import static edu.unc.lib.boxc.search.api.SearchFieldKey.PARENT_UNIT; import static edu.unc.lib.boxc.search.api.SearchFieldKey.SUBJECT; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; -import java.util.Arrays; import java.util.Map; -import edu.unc.lib.boxc.search.solr.facets.GenericFacet; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -24,12 +21,9 @@ import edu.unc.lib.boxc.auth.fcrepo.models.AccessGroupSetImpl; import edu.unc.lib.boxc.model.api.ids.PID; import edu.unc.lib.boxc.search.api.SearchFieldKey; -import edu.unc.lib.boxc.search.api.facets.FacetFieldList; import edu.unc.lib.boxc.search.api.facets.FacetFieldObject; import edu.unc.lib.boxc.search.api.facets.SearchFacet; -import edu.unc.lib.boxc.search.api.requests.SearchRequest; import edu.unc.lib.boxc.search.api.requests.SearchState; -import edu.unc.lib.boxc.search.solr.responses.SearchResultResponse; import edu.unc.lib.boxc.search.solr.test.BaseEmbeddedSolrTest; import edu.unc.lib.boxc.search.solr.test.TestCorpus; import edu.unc.lib.boxc.search.solr.utils.AccessRestrictionUtil; @@ -49,6 +43,8 @@ public class SetFacetTitleByIdServiceIT extends BaseEmbeddedSolrTest { private MultiSelectFacetListService facetListService; + private AutoCloseable closeable; + @Mock private GlobalPermissionEvaluator globalPermissionEvaluator; private FacetFieldFactory facetFieldFactory; @@ -63,7 +59,7 @@ public SetFacetTitleByIdServiceIT() { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); if (!corpusLoaded) { corpusLoaded = true; index(testCorpus.populate()); @@ -109,6 +105,11 @@ public void init() throws Exception { searchStateFactory.setSearchSettings(searchSettings); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void populateSearchStateCollectionAndUnitTest() throws Exception { var subject = "Digital Repositories"; diff --git a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/StructureQueryServiceIT.java b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/StructureQueryServiceIT.java index 79a9eb5fc1..bc04d6177d 100644 --- a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/StructureQueryServiceIT.java +++ b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/services/StructureQueryServiceIT.java @@ -13,12 +13,13 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Matchers.anySetOf; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.NoSuchElementException; import java.util.UUID; import org.apache.solr.common.SolrInputDocument; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -35,11 +36,6 @@ import edu.unc.lib.boxc.search.solr.facets.GenericFacet; import edu.unc.lib.boxc.search.solr.responses.HierarchicalBrowseResultResponse; import edu.unc.lib.boxc.search.solr.responses.HierarchicalBrowseResultResponse.ResultNode; -import edu.unc.lib.boxc.search.solr.services.ChildrenCountService; -import edu.unc.lib.boxc.search.solr.services.FacetFieldFactory; -import edu.unc.lib.boxc.search.solr.services.SearchStateFactory; -import edu.unc.lib.boxc.search.solr.services.SolrSearchService; -import edu.unc.lib.boxc.search.solr.services.StructureQueryService; import edu.unc.lib.boxc.search.solr.test.BaseEmbeddedSolrTest; import edu.unc.lib.boxc.search.solr.test.TestCorpus; import edu.unc.lib.boxc.search.solr.utils.AccessRestrictionUtil; @@ -51,6 +47,7 @@ * */ public class StructureQueryServiceIT extends BaseEmbeddedSolrTest { + private AutoCloseable closeable; @Mock private GlobalPermissionEvaluator globalPermissionEvaluator; @@ -77,7 +74,7 @@ public StructureQueryServiceIT() { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); index(testCorpus.populate()); @@ -128,6 +125,11 @@ public void init() throws Exception { rootId = getContentRootPid().getId(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testExpandedStructureToContentRoot() throws Exception { HierarchicalBrowseRequest browseRequest = makeRequest(testCorpus.rootPid); diff --git a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/utils/AccessRestrictionUtilTest.java b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/utils/AccessRestrictionUtilTest.java index 10f7cda897..19c4e365b2 100644 --- a/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/utils/AccessRestrictionUtilTest.java +++ b/search-solr/src/test/java/edu/unc/lib/boxc/search/solr/utils/AccessRestrictionUtilTest.java @@ -3,9 +3,10 @@ import static org.junit.jupiter.api.Assertions.assertEquals; import static org.mockito.Matchers.anySetOf; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import org.apache.solr.client.solrj.SolrQuery; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -16,7 +17,6 @@ import edu.unc.lib.boxc.auth.api.services.GlobalPermissionEvaluator; import edu.unc.lib.boxc.auth.fcrepo.models.AccessGroupSetImpl; import edu.unc.lib.boxc.search.solr.config.SearchSettings; -import edu.unc.lib.boxc.search.solr.utils.AccessRestrictionUtil; /** * @@ -28,6 +28,8 @@ public class AccessRestrictionUtilTest { private final static String BASE_QUERY = "*:*"; private final static String ACCESS_GROUP = "group"; + private AutoCloseable closeable; + @Mock private GlobalPermissionEvaluator globalPermissionEvaluator; @Mock @@ -39,7 +41,7 @@ public class AccessRestrictionUtilTest { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); restrictionUtil = new AccessRestrictionUtil(); restrictionUtil.setGlobalPermissionEvaluator(globalPermissionEvaluator); @@ -48,6 +50,11 @@ public void init() throws Exception { accessGroups = new AccessGroupSetImpl(ACCESS_GROUP); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void addAccessDisabledTest() { restrictionUtil.setDisablePermissionFiltering(true); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/BinaryEnhancementProcessorTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/BinaryEnhancementProcessorTest.java index d8e834cd95..69858751ae 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/BinaryEnhancementProcessorTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/BinaryEnhancementProcessorTest.java @@ -11,7 +11,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Collections; @@ -22,6 +22,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.junit.rules.TemporaryFolder; import org.mockito.Mock; @@ -30,7 +31,6 @@ import edu.unc.lib.boxc.model.api.objects.RepositoryObject; import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader; import edu.unc.lib.boxc.model.fcrepo.test.TestHelper; -import edu.unc.lib.boxc.services.camel.BinaryEnhancementProcessor; /** * @@ -39,6 +39,7 @@ */ public class BinaryEnhancementProcessorTest { private BinaryEnhancementProcessor processor; + private AutoCloseable closeable; @Rule public final TemporaryFolder tmpFolder = new TemporaryFolder(); @@ -61,7 +62,7 @@ public class BinaryEnhancementProcessorTest { @Before public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(FEDORA_BASE); @@ -74,6 +75,11 @@ public void init() throws Exception { when(repoObj.getTypes()).thenReturn(Collections.singletonList(Binary.getURI())); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testUpdateHeadersText() throws Exception { setMessageBody("text/plain", true, false); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/BinaryMetadataProcessorTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/BinaryMetadataProcessorTest.java index 8981bdeac3..a56b52a6f3 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/BinaryMetadataProcessorTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/BinaryMetadataProcessorTest.java @@ -9,7 +9,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -27,6 +27,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.junit.rules.TemporaryFolder; import org.mockito.Mock; @@ -49,6 +50,7 @@ public class BinaryMetadataProcessorTest { private BinaryMetadataProcessor processor; + private AutoCloseable closeable; @Rule public final TemporaryFolder tmpFolder = new TemporaryFolder(); @@ -79,7 +81,7 @@ public class BinaryMetadataProcessorTest { @Before public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(FEDORA_BASE); @@ -98,6 +100,11 @@ public void init() throws Exception { binaryPid = PIDs.get(RESC_ID); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void validExternalBinary() throws Exception { File file = new File(binaryBase + "/61/67/3d/" + CHECKSUM); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/NonBinaryEnhancementProcessorTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/NonBinaryEnhancementProcessorTest.java index d49e1903ef..797276d316 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/NonBinaryEnhancementProcessorTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/NonBinaryEnhancementProcessorTest.java @@ -6,7 +6,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.nio.charset.StandardCharsets; @@ -20,17 +20,18 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.junit.rules.TemporaryFolder; import org.mockito.Mock; import edu.unc.lib.boxc.model.fcrepo.test.TestHelper; -import edu.unc.lib.boxc.services.camel.NonBinaryEnhancementProcessor; /** * @author lfarrell */ public class NonBinaryEnhancementProcessorTest { private NonBinaryEnhancementProcessor processor; + private AutoCloseable closeable; @Rule public final TemporaryFolder tmpDir = new TemporaryFolder(); @@ -49,7 +50,7 @@ public class NonBinaryEnhancementProcessorTest { @Before public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); dataDir = tmpDir.newFolder().getAbsolutePath(); TestHelper.setContentBase(FEDORA_BASE); @@ -60,6 +61,11 @@ public void init() throws Exception { when(message.getHeader(FCREPO_URI)).thenReturn(RESC_URI); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testCollectionWithImage() throws Exception { String derivativeFinalPath = "de/75/d8/11/" + RESC_ID; diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/binaryCleanup/BinaryCleanupRouterIT.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/binaryCleanup/BinaryCleanupRouterIT.java index 03563ee306..38a4b1964e 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/binaryCleanup/BinaryCleanupRouterIT.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/binaryCleanup/BinaryCleanupRouterIT.java @@ -4,7 +4,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.net.URI; @@ -17,6 +17,7 @@ import org.apache.camel.builder.NotifyBuilder; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.context.ContextConfiguration; @@ -85,9 +86,11 @@ public class BinaryCleanupRouterIT { private CollectionObject collection; + private AutoCloseable closeable; + @Before public void init() { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(baseAddress); @@ -101,6 +104,11 @@ public void init() { adminUnit.addMember(collection); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void noBinariesTest() throws Exception { PID pid = pidMinter.mintContentPid(); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/cdrEvents/CdrEventProcessorTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/cdrEvents/CdrEventProcessorTest.java index c11b402e78..871c7f92d1 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/cdrEvents/CdrEventProcessorTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/cdrEvents/CdrEventProcessorTest.java @@ -6,7 +6,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.ByteArrayInputStream; @@ -20,12 +20,11 @@ import org.joda.time.format.ISODateTimeFormat; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; -import edu.unc.lib.boxc.services.camel.cdrEvents.CdrEventProcessor; - /** * * @author lfarrell @@ -34,6 +33,7 @@ public class CdrEventProcessorTest { private CdrEventProcessor processor; private String actionType = "action_placeholder"; + private AutoCloseable closeable; @Mock private Exchange exchange; @@ -46,7 +46,7 @@ public class CdrEventProcessorTest { @Before public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); processor = new CdrEventProcessor(); @@ -54,6 +54,11 @@ public void init() throws Exception { .thenReturn(message); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testCreateSolrActionHeader() throws Exception { Document msg = new Document(); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/cdrEvents/CdrEventRoutingTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/cdrEvents/CdrEventRoutingTest.java index b6f9cc752c..0986f51ef7 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/cdrEvents/CdrEventRoutingTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/cdrEvents/CdrEventRoutingTest.java @@ -8,7 +8,7 @@ import static org.mockito.Matchers.any; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.ArrayList; import java.util.List; @@ -22,6 +22,7 @@ import org.apache.camel.test.spring.CamelTestContextBootstrapper; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; @@ -60,6 +61,7 @@ public class CdrEventRoutingTest { private static final String USER_ID = "user"; private static final String DEPOSIT_ID = "deposit"; private static final String BASE_URI = "http://example.com/rest/"; + private AutoCloseable closeable; @Autowired private OperationsMessageSender opsMsgSender; @@ -82,7 +84,7 @@ public class CdrEventRoutingTest { @Before public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(BASE_URI); @@ -93,6 +95,11 @@ public void init() throws Exception { .thenReturn(mockIndexingAction); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testAddAction() throws Exception { List added = pidList(3); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/destroy/DestroyObjectsRouterTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/destroy/DestroyObjectsRouterTest.java index 878d99a8bd..0e8d69f515 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/destroy/DestroyObjectsRouterTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/destroy/DestroyObjectsRouterTest.java @@ -7,17 +7,15 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Collections; import java.util.UUID; -import edu.unc.lib.boxc.model.api.objects.RepositoryObject; import edu.unc.lib.boxc.model.api.rdf.Premis; import edu.unc.lib.boxc.operations.api.events.PremisEventBuilder; import edu.unc.lib.boxc.operations.api.events.PremisLogger; import edu.unc.lib.boxc.operations.api.events.PremisLoggerFactory; -import edu.unc.lib.boxc.operations.impl.events.PremisEventBuilderImpl; import org.apache.camel.BeanInject; import org.apache.camel.Produce; import org.apache.camel.ProducerTemplate; @@ -28,6 +26,7 @@ import org.apache.jena.vocabulary.RDF; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.mockito.Mock; import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -61,6 +60,8 @@ public class DestroyObjectsRouterTest extends CamelSpringTestSupport { private static final String USER_NAME = "user"; private static final String USER_GROUPS = "edu:lib:staff_grp"; + private AutoCloseable closeable; + @Produce(uri = "direct:start") protected ProducerTemplate template; @@ -93,13 +94,18 @@ public class DestroyObjectsRouterTest extends CamelSpringTestSupport { @Before public void setup() { - initMocks(this); + closeable = openMocks(this); AccessGroupSet testPrincipals = new AccessGroupSetImpl(USER_GROUPS); agent = new AgentPrincipalsImpl(USER_NAME, testPrincipals); when(txManager.startTransaction()).thenReturn(tx); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Override protected AbstractApplicationContext createApplicationContext() { return new ClassPathXmlApplicationContext("/service-context.xml", "/destroy-objects-context.xml"); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/destroyDerivatives/DestroyDerivativesProcessorTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/destroyDerivatives/DestroyDerivativesProcessorTest.java index 02710ed737..a45afc0335 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/destroyDerivatives/DestroyDerivativesProcessorTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/destroyDerivatives/DestroyDerivativesProcessorTest.java @@ -9,7 +9,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.nio.charset.StandardCharsets; @@ -20,12 +20,12 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.junit.rules.TemporaryFolder; import org.mockito.Mock; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; import edu.unc.lib.boxc.model.fcrepo.test.TestHelper; -import edu.unc.lib.boxc.services.camel.destroyDerivatives.DestroyDerivativesProcessor; public class DestroyDerivativesProcessorTest { private DestroyDerivativesProcessor processor; @@ -40,6 +40,7 @@ public class DestroyDerivativesProcessorTest { private static final String PID_ID = "content/" + PID_UUID; private static final String PID_PATH = "content/de/75/d8/11/" + PID_UUID; private static final String RESC_ID = FEDORA_BASE + PID_PATH; + private AutoCloseable closeable; @Rule public TemporaryFolder derivativeDir = new TemporaryFolder(); @@ -52,7 +53,7 @@ public class DestroyDerivativesProcessorTest { @Before public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(FEDORA_BASE); @@ -66,6 +67,11 @@ public void init() throws Exception { derivativeDirBase = derivativeDir.getRoot().getAbsolutePath(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void deleteFulltextTest() throws Exception { derivativeTypeDir = FULLTEXT_EXTRACTION.getId(); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/destroyDerivatives/DestroyDerivativesRouterIT.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/destroyDerivatives/DestroyDerivativesRouterIT.java index a4a3cc7d13..284c9e1c4d 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/destroyDerivatives/DestroyDerivativesRouterIT.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/destroyDerivatives/DestroyDerivativesRouterIT.java @@ -9,7 +9,7 @@ import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.nio.file.Files; @@ -27,6 +27,7 @@ import org.fcrepo.client.FcrepoClient; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.junit.runner.RunWith; import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; @@ -64,8 +65,6 @@ import edu.unc.lib.boxc.persist.impl.storage.StorageLocationManagerImpl; import edu.unc.lib.boxc.search.api.models.ObjectPath; import edu.unc.lib.boxc.search.solr.services.ObjectPathFactory; -import edu.unc.lib.boxc.services.camel.destroyDerivatives.DestroyDerivativesProcessor; -import edu.unc.lib.boxc.services.camel.destroyDerivatives.DestroyedMsgProcessor; /** * @@ -151,9 +150,11 @@ public class DestroyDerivativesRouterIT { private final static String LOC1_ID = "loc1"; + private AutoCloseable closeable; + @Before public void init() { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(baseAddress); @@ -187,6 +188,11 @@ public void init() { when(path.toIdPath()).thenReturn("pid0/pid1/pid2/pid3"); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void destroyImageTest() throws Exception { WorkObject work = repoObjectFactory.createWorkObject(null); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/enhancements/EnhancementRouterIT.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/enhancements/EnhancementRouterIT.java index 136afe53ab..a6d9ee79f7 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/enhancements/EnhancementRouterIT.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/enhancements/EnhancementRouterIT.java @@ -17,7 +17,7 @@ import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.ByteArrayInputStream; import java.io.File; @@ -39,6 +39,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -82,6 +83,8 @@ public class EnhancementRouterIT { private final static long ALLOW_WAIT = 5000; + private AutoCloseable closeable; + @Autowired private String baseAddress; @@ -125,7 +128,7 @@ public class EnhancementRouterIT { @Before public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); reset(solrIngestProcessor); reset(addSmallThumbnailProcessor); @@ -149,6 +152,11 @@ public void init() throws Exception { jp2ScriptFile.deleteOnExit(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void nonBinaryWithSourceImages() throws Exception { CollectionObject collObject = repoObjectFactory.createCollectionObject(null); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/exportxml/ExportXMLRouteIT.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/exportxml/ExportXMLRouteIT.java index b7885edfc0..b4f40a8d7c 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/exportxml/ExportXMLRouteIT.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/exportxml/ExportXMLRouteIT.java @@ -13,7 +13,7 @@ import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.io.IOException; @@ -43,6 +43,7 @@ import org.jdom2.output.XMLOutputter; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; @@ -99,6 +100,8 @@ public class ExportXMLRouteIT { private static final String EMAIL = "test@example.com"; + private AutoCloseable closeable; + @Autowired private CamelContext cdrExportXML; @Autowired @@ -149,7 +152,7 @@ public class ExportXMLRouteIT { @Before public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); reset(emailHandler); TestHelper.setContentBase("http://localhost:48085/rest"); agent = new AgentPrincipalsImpl("user", new AccessGroupSetImpl("adminGroup")); @@ -157,6 +160,11 @@ public void setup() throws Exception { exportXmlProcessor.setObjectsPerExport(500); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void exportWorksExcludeChildrenTest() throws Exception { indexAll(); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/fulltext/FulltextProcessorTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/fulltext/FulltextProcessorTest.java index fb01ee0edd..608c73428f 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/fulltext/FulltextProcessorTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/fulltext/FulltextProcessorTest.java @@ -8,7 +8,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; @@ -18,13 +18,13 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.junit.rules.TemporaryFolder; import org.mockito.Mock; import com.google.common.io.Files; import edu.unc.lib.boxc.model.fcrepo.test.TestHelper; -import edu.unc.lib.boxc.services.camel.fulltext.FulltextProcessor; public class FulltextProcessorTest { private FulltextProcessor processor; @@ -40,6 +40,8 @@ public class FulltextProcessorTest { private static final String RESC_ID = FEDORA_BASE + "content/de/75/d8/11/de75d811-9e0f-4b1f-8631-2060ab3580cc"; + private AutoCloseable closeable; + @Rule public TemporaryFolder tmpDir = new TemporaryFolder(); @@ -51,7 +53,7 @@ public class FulltextProcessorTest { @Before public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(FEDORA_BASE); @@ -67,6 +69,11 @@ public void init() throws Exception { finalDerivativeFile.delete(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void extractFulltextTest() throws Exception { originalFile = tmpDir.newFile(originalFileName); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/images/AddDerivativeProcessorTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/images/AddDerivativeProcessorTest.java index f68f72d222..7b63dd62a6 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/images/AddDerivativeProcessorTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/images/AddDerivativeProcessorTest.java @@ -7,6 +7,7 @@ import org.apache.camel.Exchange; import org.apache.camel.Message; import org.apache.camel.component.exec.ExecResult; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -24,7 +25,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; public class AddDerivativeProcessorTest { @@ -40,6 +41,8 @@ public class AddDerivativeProcessorTest { private static final String RESC_ID = FEDORA_BASE + "content/de/75/d8/11/de75d811-9e0f-4b1f-8631-2060ab3580cc"; + private AutoCloseable closeable; + @TempDir public Path tmpFolder; @@ -57,7 +60,7 @@ public class AddDerivativeProcessorTest { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(FEDORA_BASE); @@ -88,6 +91,11 @@ public void init() throws Exception { destinationPath = moveFolder.resolve(fileName + ".PNG"); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void createEnhancementTest() throws Exception { processor.process(exchange); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/importxml/ImportXMLIT.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/importxml/ImportXMLIT.java index 2678b731d6..2ae43a1e52 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/importxml/ImportXMLIT.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/importxml/ImportXMLIT.java @@ -6,7 +6,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.InputStream; import java.util.concurrent.TimeUnit; @@ -21,6 +21,7 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.junit.rules.TemporaryFolder; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -43,7 +44,6 @@ import edu.unc.lib.boxc.operations.test.ModsTestHelper; import edu.unc.lib.boxc.persist.api.storage.StorageLocationManager; import edu.unc.lib.boxc.persist.impl.transfer.BinaryTransferServiceImpl; -import edu.unc.lib.boxc.services.camel.importxml.ImportXMLProcessor; /** * @author bbpennel @@ -63,6 +63,8 @@ public class ImportXMLIT { private final static String UPDATED_TITLE = "Updated Work Title"; private final static String UPDATED_DATE = "2018-04-06"; + private AutoCloseable closeable; + @Rule public final TemporaryFolder tmpFolder = new TemporaryFolder(); @@ -99,7 +101,7 @@ public class ImportXMLIT { @Before public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(baseAddress); @@ -118,6 +120,11 @@ public void setup() throws Exception { when(updateCompleteTemplate.execute(any())).thenReturn(""); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void updateDescription() throws Exception { FolderObject folderObject = repoObjectFactory.createFolderObject(null); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/order/OrderNotificationServiceTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/order/OrderNotificationServiceTest.java index b6d0cdaa48..4f7b2f7c6b 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/order/OrderNotificationServiceTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/order/OrderNotificationServiceTest.java @@ -10,8 +10,8 @@ import edu.unc.lib.boxc.operations.jms.order.OrderOperationType; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import static org.mockito.Matchers.any; import static org.mockito.Matchers.isNull; @@ -20,6 +20,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.util.Arrays; @@ -38,6 +39,7 @@ public class OrderNotificationServiceTest { private AgentPrincipals agent = new AgentPrincipalsImpl(USERNAME, new AccessGroupSetImpl("agroup")); private MultiParentOrderRequest request = new MultiParentOrderRequest(); private OrderNotificationService orderNotificationService; + private AutoCloseable closeable; @Mock private EmailHandler emailHandler; @@ -46,7 +48,7 @@ public class OrderNotificationServiceTest { @Before public void setup() { - MockitoAnnotations.initMocks(this); + closeable = openMocks(this); request.setAgent(agent); request.setOperation(OrderOperationType.SET); parentPid1 = PIDs.get(PARENT1_UUID); @@ -55,6 +57,12 @@ public void setup() { orderNotificationService.setOrderNotificationBuilder(orderNotificationBuilder); orderNotificationService.setEmailHandler(emailHandler); } + + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void sendResultsSendsEmail() { when(orderNotificationBuilder.construct(any(), any(), any())).thenReturn("Hi there"); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/order/OrderRequestProcessorTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/order/OrderRequestProcessorTest.java index f37a294f38..53770dc4e1 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/order/OrderRequestProcessorTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/order/OrderRequestProcessorTest.java @@ -17,14 +17,13 @@ import edu.unc.lib.boxc.operations.jms.order.OrderRequestSerializationHelper; import edu.unc.lib.boxc.services.camel.ProcessorTestHelper; import org.apache.camel.Exchange; -import org.apache.camel.Message; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.MockitoAnnotations; import java.io.IOException; import java.util.Arrays; @@ -44,6 +43,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author bbpennel @@ -58,6 +58,7 @@ public class OrderRequestProcessorTest { private static final String EMAIL = "user1@example.com"; private PID parentPid1; private PID parentPid2; + private AutoCloseable closeable; @Mock private AccessControlService accessControlService; @Mock @@ -82,7 +83,7 @@ public class OrderRequestProcessorTest { @Before public void setup() { - MockitoAnnotations.initMocks(this); + closeable = openMocks(this); processor = new OrderRequestProcessor(); processor.setAccessControlService(accessControlService); processor.setOrderJobFactory(orderJobFactory); @@ -96,6 +97,11 @@ public void setup() { when(orderValidatorFactory.createValidator(any())).thenReturn(orderValidator); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void emptyParentToChildMapTest() throws Exception { mockRequestAsValid(); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/patronAccess/PatronAccessAssignmentRouterTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/patronAccess/PatronAccessAssignmentRouterTest.java index d1b5bce5fc..b6a034ab99 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/patronAccess/PatronAccessAssignmentRouterTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/patronAccess/PatronAccessAssignmentRouterTest.java @@ -7,13 +7,14 @@ import static org.mockito.Mockito.timeout; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import org.apache.camel.BeanInject; import org.apache.camel.test.spring.CamelSpringTestSupport; import org.jgroups.util.UUID; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.springframework.context.support.AbstractApplicationContext; @@ -37,6 +38,7 @@ public class PatronAccessAssignmentRouterTest extends CamelSpringTestSupport { private static final String USER = "someone"; private static final String PRINCIPALS = "my:special:group;everyone;authenticated"; + private AutoCloseable closeable; @BeanInject(value = "patronAccessAssignmentService") private PatronAccessAssignmentService patronAccessAssignmentService; @@ -49,7 +51,12 @@ public class PatronAccessAssignmentRouterTest extends CamelSpringTestSupport { @Before public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); + } + + @AfterEach + void closeService() throws Exception { + closeable.close(); } @Override diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solr/CdrEventToSolrUpdateProcessorTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solr/CdrEventToSolrUpdateProcessorTest.java index d5f5a6be5c..0a2ebaee41 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solr/CdrEventToSolrUpdateProcessorTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solr/CdrEventToSolrUpdateProcessorTest.java @@ -13,7 +13,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.ArrayList; import java.util.Collection; @@ -26,6 +26,7 @@ import org.jdom2.Element; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; @@ -47,6 +48,7 @@ public class CdrEventToSolrUpdateProcessorTest { private static final String USER_ID = "user_id"; private CdrEventToSolrUpdateProcessor processor; + private AutoCloseable closeable; @Mock private IndexingMessageSender messageSender; @@ -68,7 +70,7 @@ public class CdrEventToSolrUpdateProcessorTest { @Before public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); processor = new CdrEventToSolrUpdateProcessor(); processor.setIndexingMessageSender(messageSender); @@ -79,6 +81,11 @@ public void init() throws Exception { when(msg.getHeader(eq("name"))).thenReturn(USER_ID); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testNoMessageBody() throws Exception { when(msg.getBody()).thenReturn(null); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solr/SolrIngestProcessorIT.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solr/SolrIngestProcessorIT.java index dad93be0a3..e45eed6093 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solr/SolrIngestProcessorIT.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solr/SolrIngestProcessorIT.java @@ -12,7 +12,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.InputStream; import java.nio.file.Path; @@ -25,17 +25,14 @@ import edu.unc.lib.boxc.auth.fcrepo.models.AgentPrincipalsImpl; import edu.unc.lib.boxc.auth.fcrepo.services.InheritedAclFactory; import edu.unc.lib.boxc.fcrepo.utils.TransactionManager; -import edu.unc.lib.boxc.model.api.services.RepositoryObjectFactory; import edu.unc.lib.boxc.model.api.sparql.SparqlUpdateService; import edu.unc.lib.boxc.operations.api.events.PremisLoggerFactory; import edu.unc.lib.boxc.operations.impl.delete.MarkForDeletionJob; -import edu.unc.lib.boxc.operations.impl.delete.MarkForDeletionService; import edu.unc.lib.boxc.operations.impl.destroy.DestroyObjectsJob; import edu.unc.lib.boxc.operations.jms.MessageSender; import edu.unc.lib.boxc.operations.jms.destroy.DestroyObjectsRequest; import edu.unc.lib.boxc.operations.jms.indexing.IndexingMessageSender; import edu.unc.lib.boxc.operations.jms.order.MemberOrderRequestSender; -import edu.unc.lib.boxc.persist.api.storage.StorageLocationManager; import edu.unc.lib.boxc.persist.api.transfer.BinaryTransferService; import edu.unc.lib.boxc.search.solr.services.ObjectPathFactory; import org.apache.commons.collections.CollectionUtils; @@ -46,6 +43,7 @@ import org.fcrepo.client.FcrepoClient; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; @@ -68,7 +66,6 @@ import edu.unc.lib.boxc.search.api.SearchFieldKey; import edu.unc.lib.boxc.search.api.models.ContentObjectRecord; import edu.unc.lib.boxc.search.api.requests.SimpleIdRequest; -import edu.unc.lib.boxc.services.camel.solr.SolrIngestProcessor; /** * @@ -78,6 +75,7 @@ public class SolrIngestProcessorIT extends AbstractSolrProcessorIT { private SolrIngestProcessor processor; + private AutoCloseable closeable; private static final String CONTENT_TEXT = "Content"; private static final String TEXT_EXTRACT = "Cone Tent"; @@ -118,7 +116,7 @@ public class SolrIngestProcessorIT extends AbstractSolrProcessorIT { @Before public void setUp() throws Exception { - initMocks(this); + closeable = openMocks(this); agent = new AgentPrincipalsImpl("user", new AccessGroupSetImpl("group")); TestHelper.setContentBase(baseAddress); @@ -131,6 +129,11 @@ public void setUp() throws Exception { generateBaseStructure(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testIndexDescribedWork() throws Exception { WorkObject workObj = repositoryObjectFactory.createWorkObject(null); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solr/SolrIngestProcessorTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solr/SolrIngestProcessorTest.java index abc07fa6a9..8c7dba016b 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solr/SolrIngestProcessorTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solr/SolrIngestProcessorTest.java @@ -8,20 +8,19 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; -import edu.unc.lib.boxc.indexing.solr.SolrUpdateRequest; import edu.unc.lib.boxc.model.api.objects.FileObject; import edu.unc.lib.boxc.model.api.objects.WorkObject; import edu.unc.lib.boxc.model.api.rdf.Fcrepo4Repository; import edu.unc.lib.boxc.model.fcrepo.ids.DatastreamPids; import edu.unc.lib.boxc.model.fcrepo.ids.PIDs; import edu.unc.lib.boxc.operations.jms.MessageSender; -import edu.unc.lib.boxc.operations.jms.indexing.IndexingActionType; import org.apache.camel.Exchange; import org.apache.camel.Message; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.mockito.Mock; import edu.unc.lib.boxc.indexing.solr.exception.IndexingException; @@ -33,7 +32,6 @@ import edu.unc.lib.boxc.model.api.objects.RepositoryObjectLoader; import edu.unc.lib.boxc.model.fcrepo.test.TestHelper; import edu.unc.lib.boxc.search.solr.models.IndexDocumentBean; -import edu.unc.lib.boxc.services.camel.solr.SolrIngestProcessor; import java.util.UUID; @@ -50,6 +48,7 @@ public class SolrIngestProcessorTest { "http://localhost:48085/rest/content/7c/73/29/6f/7c73296f-54ae-438e-b8d5-1890eba41676"; private SolrIngestProcessor processor; + private AutoCloseable closeable; @Mock private DocumentIndexingPackageFactory dipFactory; @@ -74,7 +73,7 @@ public class SolrIngestProcessorTest { @Before public void init() throws Exception { TestHelper.setContentBase(CONTENT_BASE_URI); - initMocks(this); + closeable = openMocks(this); processor = new SolrIngestProcessor(dipFactory, pipeline, solrUpdateDriver, repoObjLoader); processor.setUpdateWorkSender(messageSender); @@ -86,6 +85,11 @@ public void init() throws Exception { when(dipFactory.createDip(any(PID.class))).thenReturn(dip); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testIndexObject() throws Exception { processor.process(exchange); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solrUpdate/SolrUpdateProcessorIT.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solrUpdate/SolrUpdateProcessorIT.java index 2dc307a446..a4edb3e2fa 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solrUpdate/SolrUpdateProcessorIT.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solrUpdate/SolrUpdateProcessorIT.java @@ -19,19 +19,15 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; -import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; -import java.util.Objects; import java.util.concurrent.TimeUnit; import javax.annotation.Resource; @@ -42,10 +38,8 @@ import edu.unc.lib.boxc.model.api.objects.WorkObject; import edu.unc.lib.boxc.model.api.rdf.IanaRelation; import edu.unc.lib.boxc.model.fcrepo.ids.DatastreamPids; -import edu.unc.lib.boxc.model.fcrepo.services.RepositoryObjectLoaderImpl; import edu.unc.lib.boxc.operations.impl.order.OrderJobFactory; import edu.unc.lib.boxc.operations.impl.order.OrderRequestFactory; -import edu.unc.lib.boxc.operations.impl.order.SetOrderJob; import edu.unc.lib.boxc.operations.jms.MessageSender; import edu.unc.lib.boxc.operations.jms.indexing.IndexingMessageSender; import edu.unc.lib.boxc.operations.jms.order.OrderOperationType; @@ -58,11 +52,11 @@ import org.apache.solr.client.solrj.SolrClient; import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.SolrInputDocument; import org.jdom2.Document; import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.junit.rules.TemporaryFolder; import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; @@ -75,9 +69,7 @@ import edu.unc.lib.boxc.indexing.solr.action.IndexingAction; import edu.unc.lib.boxc.indexing.solr.filter.SetCollectionSupplementalInformationFilter; import edu.unc.lib.boxc.indexing.solr.filter.collection.RLASupplementalFilter; -import edu.unc.lib.boxc.model.api.ResourceType; import edu.unc.lib.boxc.model.api.ids.PID; -import edu.unc.lib.boxc.model.api.objects.AdminUnit; import edu.unc.lib.boxc.model.api.objects.CollectionObject; import edu.unc.lib.boxc.model.api.objects.RepositoryObject; import edu.unc.lib.boxc.model.fcrepo.test.TestHelper; @@ -88,7 +80,6 @@ import edu.unc.lib.boxc.search.api.models.ContentObjectRecord; import edu.unc.lib.boxc.search.solr.models.ContentObjectSolrRecord; import edu.unc.lib.boxc.services.camel.solr.AbstractSolrProcessorIT; -import edu.unc.lib.boxc.services.camel.solrUpdate.SolrUpdateProcessor; /** * @@ -101,6 +92,7 @@ }) @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public class SolrUpdateProcessorIT extends AbstractSolrProcessorIT { + private AutoCloseable closeable; @Rule public final TemporaryFolder tmpFolder = new TemporaryFolder(); @@ -133,7 +125,7 @@ public class SolrUpdateProcessorIT extends AbstractSolrProcessorIT { @Before public void setUp() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(baseAddress); @@ -150,6 +142,11 @@ public void setUp() throws Exception { generateBaseStructure(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testReindexAcls() throws Exception { indexObjectsInTripleStore(); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solrUpdate/SolrUpdateProcessorTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solrUpdate/SolrUpdateProcessorTest.java index f83485da53..1542aef975 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solrUpdate/SolrUpdateProcessorTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/solrUpdate/SolrUpdateProcessorTest.java @@ -11,7 +11,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.ArrayList; import java.util.HashMap; @@ -30,6 +30,7 @@ import org.jdom2.Element; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; @@ -47,6 +48,7 @@ * */ public class SolrUpdateProcessorTest { + private AutoCloseable closeable; private SolrUpdateProcessor processor; @@ -74,7 +76,7 @@ public class SolrUpdateProcessorTest { @Before public void init() { - initMocks(this); + closeable = openMocks(this); indexingActionMap = new HashMap<>(); indexingActionMap.put(ADD, mockAddAction); @@ -92,6 +94,11 @@ public void init() { targetPid = ProcessorTestHelper.makePid(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testMessageNoChildren() throws Exception { populateEntry(ADD); diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/triplesReindexing/TriplesReindexingRouterIT.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/triplesReindexing/TriplesReindexingRouterIT.java index 09fa2d63c8..00e87edf7f 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/triplesReindexing/TriplesReindexingRouterIT.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/triplesReindexing/TriplesReindexingRouterIT.java @@ -7,7 +7,7 @@ import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.util.concurrent.TimeUnit; @@ -72,6 +72,7 @@ }) @DirtiesContext(classMode = ClassMode.AFTER_EACH_TEST_METHOD) public class TriplesReindexingRouterIT { + private AutoCloseable closeable; @Autowired private CamelContext fcrepoTriplestoreIndexer; @@ -115,7 +116,7 @@ public class TriplesReindexingRouterIT { @Before public void setUp() throws Exception { - initMocks(this); + closeable = openMocks(this); fusekiModel = createDefaultModel(); @@ -139,6 +140,7 @@ public void setUp() throws Exception { @After public void tearDown() throws Exception { + closeable.close(); fusekiServer.stop(); } diff --git a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/util/CacheInvalidatingProcessorTest.java b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/util/CacheInvalidatingProcessorTest.java index 96699b3a9f..34ab37c843 100644 --- a/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/util/CacheInvalidatingProcessorTest.java +++ b/services-camel-app/src/test/java/edu/unc/lib/boxc/services/camel/util/CacheInvalidatingProcessorTest.java @@ -14,6 +14,7 @@ import org.apache.camel.Message; import org.junit.Before; import org.junit.Test; +import org.junit.jupiter.api.AfterEach; import org.mockito.Mock; import static org.mockito.Matchers.any; @@ -22,7 +23,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author bbpennel @@ -32,6 +33,8 @@ public class CacheInvalidatingProcessorTest { private static final String PID_UUID = "de75d811-9e0f-4b1f-8631-2060ab3580cc"; private static final String PID_PATH = "/de/75/d8/11/" + PID_UUID; + private AutoCloseable closeable; + @Mock private RepositoryObjectLoaderImpl repoObjLoader; @Mock @@ -47,7 +50,7 @@ public class CacheInvalidatingProcessorTest { @Before public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); TestHelper.setContentBase(FEDORA_BASE); processor = new CacheInvalidatingProcessor(); processor.setRepositoryObjectLoader(repoObjLoader); @@ -57,6 +60,11 @@ public void init() throws Exception { processor.setMemberOrderService(memberOrderService); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void invalidatesContentPidTest() throws Exception { String objPath = PIDConstants.CONTENT_QUALIFIER + PID_PATH; diff --git a/web-common/src/test/java/edu/unc/lib/boxc/web/common/auth/PatronPrincipalProviderTest.java b/web-common/src/test/java/edu/unc/lib/boxc/web/common/auth/PatronPrincipalProviderTest.java index 237ae5f413..4da8b7ac9e 100644 --- a/web-common/src/test/java/edu/unc/lib/boxc/web/common/auth/PatronPrincipalProviderTest.java +++ b/web-common/src/test/java/edu/unc/lib/boxc/web/common/auth/PatronPrincipalProviderTest.java @@ -8,7 +8,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.nio.file.Path; @@ -20,6 +20,7 @@ import javax.servlet.http.HttpServletRequest; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -32,6 +33,7 @@ * @author bbpennel */ public class PatronPrincipalProviderTest { + private AutoCloseable closeable; @TempDir public Path tmpFolder; @@ -53,7 +55,7 @@ public class PatronPrincipalProviderTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); provider = new PatronPrincipalProvider(); configFile = tmpFolder.resolve("patronConfig.json").toFile(); @@ -81,6 +83,11 @@ private void serializeConfigAndInit() throws Exception { provider.init(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void emptyConfigTest() throws Exception { serializeConfigAndInit(); diff --git a/web-common/src/test/java/edu/unc/lib/boxc/web/common/auth/filters/StoreUserAccessControlFilterTest.java b/web-common/src/test/java/edu/unc/lib/boxc/web/common/auth/filters/StoreUserAccessControlFilterTest.java index 76c0ff7521..a5057d3aba 100644 --- a/web-common/src/test/java/edu/unc/lib/boxc/web/common/auth/filters/StoreUserAccessControlFilterTest.java +++ b/web-common/src/test/java/edu/unc/lib/boxc/web/common/auth/filters/StoreUserAccessControlFilterTest.java @@ -13,7 +13,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.io.File; import java.nio.charset.StandardCharsets; @@ -43,6 +43,7 @@ public class StoreUserAccessControlFilterTest { private StoreUserAccessControlFilter filter; + private AutoCloseable closeable; @Mock private HttpServletRequest request; @@ -64,7 +65,7 @@ public class StoreUserAccessControlFilterTest { @BeforeEach public void init() throws Exception { - initMocks(this); + closeable = openMocks(this); configFile = tmpFolder.resolve("patronConfig.json").toFile(); FileUtils.writeStringToFile(configFile, CONFIG, StandardCharsets.US_ASCII); @@ -80,7 +81,8 @@ public void init() throws Exception { } @AfterEach - public void cleanup() { + public void cleanup() throws Exception { + closeable.close(); GroupsThreadStore.clearStore(); } diff --git a/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/AccessCopiesServiceTest.java b/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/AccessCopiesServiceTest.java index 3c0bb67d8e..fc17173f61 100644 --- a/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/AccessCopiesServiceTest.java +++ b/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/AccessCopiesServiceTest.java @@ -9,20 +9,12 @@ import edu.unc.lib.boxc.search.api.ContentCategory; import edu.unc.lib.boxc.search.api.models.ContentObjectRecord; import edu.unc.lib.boxc.search.api.requests.SearchRequest; -import edu.unc.lib.boxc.search.api.requests.SearchState; -import edu.unc.lib.boxc.search.solr.config.SearchSettings; -import edu.unc.lib.boxc.search.solr.config.SolrSettings; import edu.unc.lib.boxc.search.solr.filters.NamedDatastreamFilter; import edu.unc.lib.boxc.search.solr.models.ContentObjectSolrRecord; import edu.unc.lib.boxc.search.solr.responses.SearchResultResponse; import edu.unc.lib.boxc.search.solr.services.SolrSearchService; -import edu.unc.lib.boxc.search.solr.utils.AccessRestrictionUtil; -import edu.unc.lib.boxc.search.solr.utils.FacetFieldUtil; -import org.apache.solr.client.solrj.SolrClient; -import org.apache.solr.client.solrj.SolrQuery; import org.apache.solr.client.solrj.SolrServerException; -import org.apache.solr.client.solrj.response.QueryResponse; -import org.apache.solr.common.SolrDocumentList; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.ArgumentCaptor; @@ -33,7 +25,6 @@ import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.Properties; import java.util.UUID; import static edu.unc.lib.boxc.auth.api.Permission.viewOriginal; @@ -46,9 +37,8 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author lfarrell @@ -70,6 +60,8 @@ public class AccessCopiesServiceTest { private AccessCopiesService accessCopiesService; + private AutoCloseable closeable; + @Mock private AccessControlService accessControlService; @Mock @@ -83,7 +75,7 @@ public class AccessCopiesServiceTest { @BeforeEach public void init() throws IOException, SolrServerException { - initMocks(this); + closeable = openMocks(this); mdObject = createPdfObject(ResourceType.Work); mdObjectImg = createImgObject(ResourceType.Work); @@ -109,6 +101,11 @@ public void init() throws IOException, SolrServerException { when(searchResultResponse.getResultCount()).thenReturn(1l); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + private ContentObjectSolrRecord createAudioObject(ResourceType resourceType) { var mdObjectAudio = new ContentObjectSolrRecord(); mdObjectAudio.setResourceType(resourceType.name()); diff --git a/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/FindingAidUrlServiceTest.java b/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/FindingAidUrlServiceTest.java index 5a3f085321..d6edf9027a 100644 --- a/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/FindingAidUrlServiceTest.java +++ b/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/FindingAidUrlServiceTest.java @@ -4,26 +4,26 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.mockito.Matchers.any; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import org.apache.http.HttpStatus; import org.apache.http.StatusLine; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpHead; import org.apache.http.impl.client.CloseableHttpClient; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; -import edu.unc.lib.boxc.web.common.services.FindingAidUrlService; - /** * @author bbpennel */ public class FindingAidUrlServiceTest { private FindingAidUrlService service; + private AutoCloseable closeable; private static final String BASE_URL = "http://example.com/"; @@ -36,7 +36,7 @@ public class FindingAidUrlServiceTest { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); service = new FindingAidUrlService(); service.setHttpClient(httpClient); service.setFindingAidBaseUrl(BASE_URL); @@ -48,6 +48,11 @@ public void setup() throws Exception { when(httpResp.getStatusLine()).thenReturn(statusLine); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void nullCollectionIdTest() { assertNull(service.getFindingAidUrl(null)); diff --git a/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/PermissionsHelperTest.java b/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/PermissionsHelperTest.java index f5c226d98f..68ec7c9622 100644 --- a/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/PermissionsHelperTest.java +++ b/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/PermissionsHelperTest.java @@ -11,12 +11,13 @@ import static org.mockito.Matchers.any; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -44,12 +45,14 @@ public class PermissionsHelperTest { private AccessGroupSet principals; + private AutoCloseable closeable; + @Mock private AccessControlService accessControlService; @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); roleGroups = new ArrayList<>(); @@ -67,6 +70,11 @@ public void init() { helper.setAccessControlService(accessControlService); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testAllowsPublicAccess() { roleGroups.add("canViewOriginals|everyone"); diff --git a/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/StoreAccessLevelFilterTest.java b/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/StoreAccessLevelFilterTest.java index 1d44999ecd..b09218f44a 100644 --- a/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/StoreAccessLevelFilterTest.java +++ b/web-common/src/test/java/edu/unc/lib/boxc/web/common/services/StoreAccessLevelFilterTest.java @@ -9,7 +9,7 @@ import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Arrays; import java.util.HashSet; @@ -22,12 +22,10 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; import edu.unc.lib.boxc.auth.api.AccessPrincipalConstants; import edu.unc.lib.boxc.auth.api.UserRole; @@ -41,8 +39,8 @@ /** * @author bbpennel */ -@ExtendWith(MockitoExtension.class) public class StoreAccessLevelFilterTest { + private AutoCloseable closeable; @Mock private HttpServletRequest request; @Mock @@ -64,7 +62,7 @@ public class StoreAccessLevelFilterTest { @BeforeEach public void setup() { - initMocks(StoreAccessLevelFilterTest.class); + closeable = openMocks(this); principals = new AccessGroupSetImpl(); GroupsThreadStore.storeGroups(principals); @@ -72,7 +70,8 @@ public void setup() { } @AfterEach - public void tearDown() { + public void tearDown() throws Exception { + closeable.close(); GroupsThreadStore.clearStore(); } diff --git a/web-common/src/test/java/edu/unc/lib/boxc/web/common/utils/SerializationUtilTest.java b/web-common/src/test/java/edu/unc/lib/boxc/web/common/utils/SerializationUtilTest.java index 54dc5728ef..11ba569609 100644 --- a/web-common/src/test/java/edu/unc/lib/boxc/web/common/utils/SerializationUtilTest.java +++ b/web-common/src/test/java/edu/unc/lib/boxc/web/common/utils/SerializationUtilTest.java @@ -41,7 +41,6 @@ * @author bbpennel * */ -@ExtendWith(MockitoExtension.class) @MockitoSettings(strictness = Strictness.LENIENT) public class SerializationUtilTest extends Assertions { private static final List DATASTREAMS = diff --git a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/processing/AddContainerServiceTest.java b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/processing/AddContainerServiceTest.java index bc7462523d..43cceab0fc 100644 --- a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/processing/AddContainerServiceTest.java +++ b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/processing/AddContainerServiceTest.java @@ -12,7 +12,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Collection; import java.util.UUID; @@ -20,6 +20,7 @@ import org.apache.jena.rdf.model.Model; import org.apache.jena.rdf.model.Resource; import org.apache.jena.rdf.model.impl.ModelCom; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -65,6 +66,7 @@ public class AddContainerServiceTest { private static final String STORAGE_LOC_ID = "loc1"; + private AutoCloseable closeable; @Mock private AccessControlService aclService; @@ -107,7 +109,7 @@ public class AddContainerServiceTest { @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); when(agent.getPrincipals()).thenReturn(groups); when(agent.getUsername()).thenReturn("user"); @@ -143,6 +145,11 @@ public Object answer(InvocationOnMock invocation) throws Throwable { service.setPremisLoggerFactory(premisLoggerFactory); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + private AddContainerRequest createRequest(String label, boolean staffOnly, ResourceType containerType) { AddContainerRequest req = new AddContainerRequest(); req.setParentPid(parentPid); diff --git a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/processing/MemberOrderCsvExporterTest.java b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/processing/MemberOrderCsvExporterTest.java index 827d51da64..50edfac2ea 100644 --- a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/processing/MemberOrderCsvExporterTest.java +++ b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/processing/MemberOrderCsvExporterTest.java @@ -19,11 +19,11 @@ import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVRecord; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; -import org.mockito.MockitoAnnotations; import java.io.IOException; import java.io.Reader; @@ -41,6 +41,7 @@ import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.when; +import static org.mockito.MockitoAnnotations.openMocks; /** * @author bbpennel @@ -54,6 +55,8 @@ public class MemberOrderCsvExporterTest { private static final String COLLECTION_UUID = "9cb6cc61-d88e-403e-b959-2396cd331a12"; private static final String ADMIN_UNIT_UUID = "5158b962-9e59-4ed8-b920-fc948213efd3"; + private AutoCloseable closeable; + @Mock private SolrSearchService solrSearchService; @Mock @@ -63,12 +66,17 @@ public class MemberOrderCsvExporterTest { @BeforeEach public void setup() { - MockitoAnnotations.initMocks(this); + closeable = openMocks(this); csvService = new MemberOrderCsvExporter(); csvService.setSolrSearchService(solrSearchService); csvService.setAclService(aclService); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void exportUnorderedObjectTest() throws Exception { var parentRec = makeWorkRecord(PARENT1_UUID, "Work"); diff --git a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/processing/SetAsPrimaryObjectServiceTest.java b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/processing/SetAsPrimaryObjectServiceTest.java index 6eb6f0fdd8..28a9b06a2f 100644 --- a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/processing/SetAsPrimaryObjectServiceTest.java +++ b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/processing/SetAsPrimaryObjectServiceTest.java @@ -10,12 +10,13 @@ import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import java.util.Collection; import java.util.UUID; import org.apache.jena.rdf.model.Resource; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -43,6 +44,7 @@ * */ public class SetAsPrimaryObjectServiceTest { + private AutoCloseable closeable; @Mock private AccessControlService aclService; @@ -74,7 +76,7 @@ public class SetAsPrimaryObjectServiceTest { @BeforeEach public void init() { - initMocks(this); + closeable = openMocks(this); fileObjPid = makePid(); folderObjPid = makePid(); @@ -94,6 +96,11 @@ public void init() { service.setOperationsMessageSender(messageSender); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void setFileObjectAsPrimaryTest() { when(fileObj.getParent()).thenReturn(workObj); diff --git a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/ItemInfoRestControllerIT.java b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/ItemInfoRestControllerIT.java index e2f10bc188..c2c579fd42 100644 --- a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/ItemInfoRestControllerIT.java +++ b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/ItemInfoRestControllerIT.java @@ -5,7 +5,7 @@ import static org.mockito.Mockito.mock; import static org.mockito.Mockito.reset; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -14,6 +14,7 @@ import java.util.List; import java.util.Map; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; @@ -30,16 +31,22 @@ @ContextConfiguration("/item-info-it-servlet.xml") public class ItemInfoRestControllerIT extends AbstractAPIIT { + private AutoCloseable closeable; @Autowired private SolrQueryLayerService solrSearchService; @BeforeEach public void setup() { - initMocks(this); + closeable = openMocks(this); reset(solrSearchService); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testGetVersion() throws Exception { PID objPid = makePid(); diff --git a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/RunEnhancementsIT.java b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/RunEnhancementsIT.java index 351d95ef83..255270eade 100644 --- a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/RunEnhancementsIT.java +++ b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/RunEnhancementsIT.java @@ -16,7 +16,7 @@ import static org.mockito.Mockito.reset; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -29,6 +29,7 @@ import org.apache.commons.io.FileUtils; import org.jdom2.Document; import org.jdom2.Element; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; @@ -74,6 +75,8 @@ public class RunEnhancementsIT extends AbstractAPIIT { private static final String USER_NAME = "user"; private static final String ADMIN_GROUP = "adminGroup"; + private AutoCloseable closeable; + @Autowired private AccessControlServiceImpl aclServices; @Autowired @@ -93,7 +96,7 @@ public class RunEnhancementsIT extends AbstractAPIIT { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); reset(messageSender); AccessGroupSet testPrincipals = new AccessGroupSetImpl(ADMIN_GROUP); @@ -108,6 +111,11 @@ public void setup() throws Exception { setupContentRoot(); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void runEnhancementsFileObject() throws Exception { FileObject fileObj = repositoryObjectFactory.createFileObject(null); diff --git a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/modify/ExportXMLIT.java b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/modify/ExportXMLIT.java index 742be5693b..febc0a19f0 100644 --- a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/modify/ExportXMLIT.java +++ b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/modify/ExportXMLIT.java @@ -6,7 +6,7 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -58,6 +58,7 @@ public class ExportXMLIT extends AbstractAPIIT { private Connection conn; private Session session; private MessageConsumer consumer; + private AutoCloseable closeable; @Autowired private ExportXMLRequestService exportXmlRequestService; private PIDMinter pidMinter; @@ -68,7 +69,7 @@ public class ExportXMLIT extends AbstractAPIIT { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); pidMinter = new RepositoryPIDMinter(); ConnectionFactory connectionFactory = new ActiveMQConnectionFactory( "vm://embedded-broker?create=false&waitForStart=5000"); @@ -98,6 +99,7 @@ public void onMessage(Message message) { @AfterEach public void shutdown() throws Exception { + closeable.close(); consumer.close(); session.close(); conn.stop(); diff --git a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/modify/UpdateDescriptionIT.java b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/modify/UpdateDescriptionIT.java index 028aab1594..84f878d495 100644 --- a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/modify/UpdateDescriptionIT.java +++ b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/modify/UpdateDescriptionIT.java @@ -8,7 +8,7 @@ import static org.mockito.Matchers.anyString; import static org.mockito.Matchers.eq; import static org.mockito.Mockito.doThrow; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -18,6 +18,7 @@ import java.util.Map; import org.apache.tika.io.IOUtils; +import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.mockito.Mock; @@ -44,6 +45,7 @@ @ContextConfiguration("/update-description-it-servlet.xml") }) public class UpdateDescriptionIT extends AbstractAPIIT { + private AutoCloseable closeable; @Mock private ContentPathFactory pathFactory; @Autowired @@ -51,11 +53,16 @@ public class UpdateDescriptionIT extends AbstractAPIIT { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); updateDescriptionService.setValidate(true); } + @AfterEach + void closeService() throws Exception { + closeable.close(); + } + @Test public void testUpdateDescription() throws Exception { File file = new File("src/test/resources/mods/valid-mods.xml"); diff --git a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/modify/UpdatePatronAccessIT.java b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/modify/UpdatePatronAccessIT.java index 7fa20170dc..5203878cc3 100644 --- a/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/modify/UpdatePatronAccessIT.java +++ b/web-services-app/src/test/java/edu/unc/lib/boxc/web/services/rest/modify/UpdatePatronAccessIT.java @@ -16,7 +16,7 @@ import static org.mockito.Mockito.reset; import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; -import static org.mockito.MockitoAnnotations.initMocks; +import static org.mockito.MockitoAnnotations.openMocks; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -75,6 +75,7 @@ public class UpdatePatronAccessIT extends AbstractAPIIT { private AdminUnit adminUnit; private CollectionObject collObj; + private AutoCloseable closeable; @Autowired private JmsTemplate patronAccessOperationTemplate; @Autowired @@ -85,7 +86,7 @@ public class UpdatePatronAccessIT extends AbstractAPIIT { @BeforeEach public void setup() throws Exception { - initMocks(this); + closeable = openMocks(this); reset(patronAccessOperationTemplate); reset(patronAccessOperationSender); AccessGroupSet testPrincipals = new AccessGroupSetImpl(USER_GROUPS); @@ -98,6 +99,7 @@ public void setup() throws Exception { @AfterEach public void teardown() throws Exception { + closeable.close(); GroupsThreadStore.clearStore(); }