1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.syncope.core.persistence.jpa.outer;
20
21 import static org.junit.jupiter.api.Assertions.assertEquals;
22 import static org.junit.jupiter.api.Assertions.assertTrue;
23
24 import java.io.ByteArrayOutputStream;
25 import java.nio.charset.Charset;
26 import java.nio.charset.StandardCharsets;
27 import java.util.List;
28 import java.util.stream.Collectors;
29 import org.apache.commons.io.IOUtils;
30 import org.apache.commons.lang3.StringUtils;
31 import org.apache.syncope.common.lib.SyncopeConstants;
32 import org.apache.syncope.core.persistence.api.content.ContentExporter;
33 import org.apache.syncope.core.persistence.jpa.AbstractTest;
34 import org.junit.jupiter.api.Test;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.transaction.annotation.Transactional;
37
38 @Transactional("Master")
39 public class XMLContentExporterTest extends AbstractTest {
40
41 @Autowired
42 private ContentExporter exporter;
43
44
45
46
47
48
49 @Test
50 public void issueSYNCOPE1128() throws Exception {
51 ByteArrayOutputStream baos = new ByteArrayOutputStream();
52
53 exporter.export(SyncopeConstants.MASTER_DOMAIN, 100, baos);
54
55 String exported = baos.toString(Charset.defaultCharset());
56 assertTrue(StringUtils.isNotBlank(exported));
57
58 List<String> realms = IOUtils.readLines(
59 IOUtils.toInputStream(exported, StandardCharsets.UTF_8), StandardCharsets.UTF_8.name()).stream().
60 filter(row -> row.trim().startsWith("<Realm")).collect(Collectors.toList());
61 assertEquals(4, realms.size());
62 assertTrue(realms.get(0).contains("name=\"/\""));
63 assertTrue(realms.get(1).contains("name=\"even\""));
64 assertTrue(realms.get(2).contains("name=\"two\""));
65 assertTrue(realms.get(3).contains("name=\"odd\""));
66 }
67 }