View Javadoc
1   package fr.ifremer.dali.service.synchro;
2   
3   /*
4    * #%L
5    * Dali :: Core
6    * $Id:$
7    * $HeadURL:$
8    * %%
9    * Copyright (C) 2014 - 2015 Ifremer
10   * %%
11   * This program is free software: you can redistribute it and/or modify
12   * it under the terms of the GNU Affero General Public License as published by
13   * the Free Software Foundation, either version 3 of the License, or
14   * (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   * 
21   * You should have received a copy of the GNU Affero General Public License
22   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23   * #L%
24   */
25  
26  
27  import fr.ifremer.dali.config.DaliConfiguration;
28  import fr.ifremer.dali.dao.DaliDatabaseFixtures;
29  import fr.ifremer.dali.dao.DaliDatabaseResource;
30  import fr.ifremer.dali.dto.system.synchronization.SynchroChangesDTO;
31  import fr.ifremer.dali.service.DaliServiceLocator;
32  import fr.ifremer.quadrige3.core.ProgressionCoreModel;
33  import fr.ifremer.quadrige3.synchro.vo.SynchroImportContextVO;
34  import org.apache.commons.logging.Log;
35  import org.apache.commons.logging.LogFactory;
36  import org.junit.*;
37  
38  import java.io.File;
39  
40  /**
41   *
42   * @author Ludovic
43   */
44  public class SynchroClientServiceWriteTest {
45  
46      private static final Log log = LogFactory.getLog(SynchroClientServiceWriteTest.class);
47      
48      @ClassRule
49      public static final DaliDatabaseResource dbResource = DaliDatabaseResource.writeDb();
50  
51      private SynchroClientService service;
52      
53      private DaliConfiguration config;
54      
55      @Before
56      public void setUp() throws Exception {
57          config = DaliConfiguration.getInstance();
58          service = DaliServiceLocator.instance().getSynchroClientService();
59      }
60      
61      @Test
62      public void getImportFileChangesAsDTO() {
63          DaliDatabaseFixtures fixtures = dbResource.getFixtures();
64          int userId = fixtures.getUserIdWithDataForSynchro();
65  
66          File importedFile = getImportTestFile();
67  
68          SynchroImportContextVO context = new SynchroImportContextVO();
69          context.setWithReferential(true);
70          context.setWithData(true);
71  
72          SynchroChangesDTO changes = service.getImportFileChangesAsDTO(userId,
73                  importedFile,
74                  context,
75                  newApplicationProgressionModel(),
76                  100);
77  
78          Assert.assertNotNull(changes);
79      }
80  
81  	/* -- Internal methods -- */
82  
83      protected File getImportTestFile() {
84          File importFile = new File("src/test/misc/importFromFile.zip");
85          Assume.assumeTrue("Could not found test file: " + importFile.getPath(), importFile.exists());
86  
87          return importFile;
88      }
89  
90      protected ProgressionCoreModel newApplicationProgressionModel() {
91          ProgressionCoreModel progressionModel = new ProgressionCoreModel();
92          // Init progression model at 0/100
93          progressionModel.setTotal(100);
94          progressionModel.setCurrent(0);
95  
96          return progressionModel;
97      }
98  }