taskid 78006 Test metadata field caching branch - PR 3160

This commit is contained in:
Samuel
2021-03-30 09:57:00 +02:00
parent b44fdd2de4
commit c53c1f6909

View File

@@ -0,0 +1,76 @@
/**
* The contents of this file are subject to the license and copyright
* detailed in the LICENSE and NOTICE files at the root of the source
* tree and available online at
*
* http://www.dspace.org/license/
*/
package org.dspace.content.service;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import org.dspace.AbstractUnitTest;
import org.dspace.content.MetadataField;
import org.dspace.content.MetadataSchema;
import org.dspace.content.factory.ContentServiceFactory;
import org.dspace.core.Context;
import org.junit.Test;
public class MetadataFieldServiceTest extends AbstractUnitTest {
private MetadataFieldService metadataFieldService =
ContentServiceFactory.getInstance().getMetadataFieldService();
private MetadataSchemaService metadataSchemaService =
ContentServiceFactory.getInstance().getMetadataSchemaService();
@Test
public void testMetadataFieldCaching() throws Exception {
MetadataField subjectField = metadataFieldService.findByElement(context, "dc", "subject", null);
MetadataField issnField = metadataFieldService.findByElement(context, "dc", "identifier", "issn");
MetadataSchema dspaceSchema = metadataSchemaService.find(context, "dspace");
subjectField.setMetadataSchema(dspaceSchema);
issnField.setMetadataSchema(dspaceSchema);
// Searching for dspace.subject and dspace.identifier.issn should return the already stored metadatafields
assertEquals(
subjectField,
metadataFieldService.findByElement(context, "dspace", "subject", null)
);
assertEquals(
issnField,
metadataFieldService.findByElement(context, "dspace", "identifier", "issn")
);
// Metadatafields dc.subject and dc.identifier.issn should no longer be found
assertNull(
metadataFieldService.findByElement(context, "dc", "subject", null)
);
assertNull(
metadataFieldService.findByElement(context, "dc", "identifier", "issn")
);
// Same tests, new context
context.complete();
context = new Context();
assertEquals(
subjectField,
metadataFieldService.findByElement(context, "dspace", "subject", null)
);
assertEquals(
issnField,
metadataFieldService.findByElement(context, "dspace", "identifier", "issn")
);
assertNull(
metadataFieldService.findByElement(context, "dc", "subject", null)
);
assertNull(
metadataFieldService.findByElement(context, "dc", "identifier", "issn")
);
}
}