|
9 | 9 |
|
10 | 10 | import static org.hamcrest.CoreMatchers.equalTo; |
11 | 11 | import static org.hamcrest.MatcherAssert.assertThat; |
| 12 | +import static org.junit.Assert.assertEquals; |
| 13 | +import static org.junit.Assert.assertNotNull; |
| 14 | +import static org.junit.Assert.assertNull; |
12 | 15 | import static org.junit.Assert.fail; |
13 | 16 |
|
14 | 17 | import java.io.BufferedWriter; |
|
20 | 23 |
|
21 | 24 | import org.apache.commons.io.FileUtils; |
22 | 25 | import org.apache.logging.log4j.Logger; |
23 | | -import org.dspace.AbstractUnitTest; |
| 26 | +import org.dspace.AbstractIntegrationTestWithDatabase; |
| 27 | +import org.dspace.builder.CollectionBuilder; |
| 28 | +import org.dspace.builder.CommunityBuilder; |
| 29 | +import org.dspace.builder.ItemBuilder; |
| 30 | +import org.dspace.content.Collection; |
| 31 | +import org.dspace.content.Item; |
| 32 | +import org.dspace.services.ConfigurationService; |
| 33 | +import org.dspace.services.factory.DSpaceServicesFactory; |
| 34 | +import org.junit.Before; |
24 | 35 | import org.junit.Test; |
25 | 36 |
|
26 | 37 |
|
|
29 | 40 | * |
30 | 41 | * @author Stuart Lewis |
31 | 42 | */ |
32 | | -public class DSpaceCSVTest extends AbstractUnitTest { |
| 43 | +public class DSpaceCSVIT extends AbstractIntegrationTestWithDatabase { |
33 | 44 | /** |
34 | 45 | * log4j category |
35 | 46 | */ |
36 | | - private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(DSpaceCSVTest.class); |
| 47 | + private static final Logger log = org.apache.logging.log4j.LogManager.getLogger(DSpaceCSVIT.class); |
| 48 | + |
| 49 | + ConfigurationService configurationService = DSpaceServicesFactory.getInstance().getConfigurationService(); |
| 50 | + |
| 51 | + Item testItem; |
| 52 | + |
| 53 | + |
| 54 | + @Override |
| 55 | + @Before |
| 56 | + public void setUp() throws Exception { |
| 57 | + super.setUp(); |
| 58 | + context.turnOffAuthorisationSystem(); |
| 59 | + |
| 60 | + parentCommunity = CommunityBuilder.createCommunity(context) |
| 61 | + .withName("Parent Community") |
| 62 | + .build(); |
| 63 | + configurationService.addPropertyValue("metadata.hide.dc.subject", true); |
| 64 | + |
| 65 | + Collection parentCollection = CollectionBuilder.createCollection(context, parentCommunity) |
| 66 | + .withName("Parent Collection") |
| 67 | + .build(); |
| 68 | + |
| 69 | + testItem = ItemBuilder.createItem(context, parentCollection).withTitle("Test Item") |
| 70 | + .withMetadata("dc", "description", "provenance", "provenance") |
| 71 | + .withMetadata("dc", "subject", null, "hidden subject") |
| 72 | + .build(); |
| 73 | + |
| 74 | + context.restoreAuthSystemState(); |
| 75 | + } |
37 | 76 |
|
38 | 77 | /** |
39 | 78 | * Test the reading and parsing of CSV files |
@@ -147,4 +186,63 @@ public void testDSpaceCSV() { |
147 | 186 | fail("IO Error while creating test CSV file"); |
148 | 187 | } |
149 | 188 | } |
| 189 | + |
| 190 | + /** |
| 191 | + * Test the hidden metadata for csv is respected |
| 192 | + * |
| 193 | + */ |
| 194 | + @Test |
| 195 | + public void testHiddenDspaceCSV() throws Exception { |
| 196 | + |
| 197 | + DSpaceCSV dSpaceCSV = new DSpaceCSV(false); |
| 198 | + |
| 199 | + dSpaceCSV.addItem(testItem); |
| 200 | + |
| 201 | + List<DSpaceCSVLine> lines = dSpaceCSV.getCSVLines(); |
| 202 | + |
| 203 | + assertThat(lines.size(), equalTo(1)); |
| 204 | + |
| 205 | + DSpaceCSVLine line = lines.get(0); |
| 206 | + |
| 207 | + List<String> subject = line.get("dc.subject"); |
| 208 | + List<String> provenance = line.get("dc.description.provenance"); |
| 209 | + List<String> title = line.get("dc.title"); |
| 210 | + |
| 211 | + assertNull(subject); |
| 212 | + assertNull(provenance); |
| 213 | + assertNotNull(title); |
| 214 | + assertEquals("Test Item", title.get(0)); |
| 215 | + |
| 216 | + } |
| 217 | + |
| 218 | + /** |
| 219 | + * Test the hidden metadata is still shown when force is applied. |
| 220 | + * |
| 221 | + */ |
| 222 | + @Test |
| 223 | + public void testHiddenDspaceForceCSV() throws Exception { |
| 224 | + |
| 225 | + DSpaceCSV dSpaceCSV = new DSpaceCSV(true); |
| 226 | + |
| 227 | + dSpaceCSV.addItem(testItem); |
| 228 | + |
| 229 | + List<DSpaceCSVLine> lines = dSpaceCSV.getCSVLines(); |
| 230 | + |
| 231 | + assertThat(lines.size(), equalTo(1)); |
| 232 | + |
| 233 | + DSpaceCSVLine line = lines.get(0); |
| 234 | + |
| 235 | + List<String> subject = line.get("dc.subject"); |
| 236 | + List<String> provenance = line.get("dc.description.provenance"); |
| 237 | + List<String> title = line.get("dc.title"); |
| 238 | + |
| 239 | + assertNotNull(subject); |
| 240 | + assertNotNull(provenance); |
| 241 | + assertEquals("hidden subject", subject.get(0)); |
| 242 | + assertEquals("provenance", provenance.get(0)); |
| 243 | + assertNotNull(title); |
| 244 | + assertEquals("Test Item", title.get(0)); |
| 245 | + |
| 246 | + } |
| 247 | + |
150 | 248 | } |
0 commit comments