View Javadoc
1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *   http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
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       * Also checks for SYNCOPE-1307.
46       *
47       * @throws Exception exception thrown when dealing with IO.
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  }