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.inner;
20  
21  import static org.junit.jupiter.api.Assertions.assertEquals;
22  import static org.junit.jupiter.api.Assertions.assertNotNull;
23  import static org.junit.jupiter.api.Assertions.assertNull;
24  
25  import java.util.List;
26  import java.util.UUID;
27  import javax.ws.rs.core.MediaType;
28  import org.apache.syncope.core.persistence.api.dao.ImplementationDAO;
29  import org.apache.syncope.core.persistence.api.dao.ReportDAO;
30  import org.apache.syncope.core.persistence.api.entity.Report;
31  import org.apache.syncope.core.persistence.jpa.AbstractTest;
32  import org.junit.jupiter.api.Test;
33  import org.springframework.beans.factory.annotation.Autowired;
34  import org.springframework.transaction.annotation.Transactional;
35  
36  @Transactional("Master")
37  public class ReportTest extends AbstractTest {
38  
39      @Autowired
40      private ReportDAO reportDAO;
41  
42      @Autowired
43      private ImplementationDAO implementationDAO;
44  
45      @Test
46      public void find() {
47          Report report = reportDAO.find("0062ea9c-924d-4ecf-9961-4492a8cc6d1b");
48          assertNotNull(report);
49  
50          report = reportDAO.find(UUID.randomUUID().toString());
51          assertNull(report);
52      }
53  
54      @Test
55      public void findAll() {
56          List<Report> reports = reportDAO.findAll();
57          assertNotNull(reports);
58          assertEquals(1, reports.size());
59      }
60  
61      @Test
62      public void save() {
63          int beforeCount = reportDAO.findAll().size();
64  
65          Report report = entityFactory.newEntity(Report.class);
66          report.setName("new report");
67          report.setJobDelegate(implementationDAO.find("SampleReportJobDelegate"));
68          report.setMimeType(MediaType.TEXT_PLAIN);
69          report.setFileExt("txt");
70          report.setActive(true);
71  
72          report = reportDAO.save(report);
73          assertNotNull(report);
74          assertNotNull(report.getKey());
75  
76          int afterCount = reportDAO.findAll().size();
77          assertEquals(afterCount, beforeCount + 1);
78      }
79  
80      @Test
81      public void delete() {
82          Report report = reportDAO.find("0062ea9c-924d-4ecf-9961-4492a8cc6d1b");
83          assertNotNull(report);
84  
85          reportDAO.delete("0062ea9c-924d-4ecf-9961-4492a8cc6d1b");
86  
87          report = reportDAO.find("0062ea9c-924d-4ecf-9961-4492a8cc6d1b");
88          assertNull(report);
89      }
90  }