1   /*******************************************************************************
2    *   Gisgraphy Project 
3    * 
4    *   This library is free software; you can redistribute it and/or
5    *   modify it under the terms of the GNU Lesser General Public
6    *   License as published by the Free Software Foundation; either
7    *   version 2.1 of the License, or (at your option) any later version.
8    * 
9    *   This library is distributed in the hope that it will be useful,
10   *   but WITHOUT ANY WARRANTY; without even the implied warranty of
11   *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   *   Lesser General Public License for more details.
13   * 
14   *   You should have received a copy of the GNU Lesser General Public
15   *   License along with this library; if not, write to the Free Software
16   *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
17   * 
18   *  Copyright 2008  Gisgraphy project 
19   *  David Masclet <davidmasclet@gisgraphy.com>
20   *  
21   *  
22   *******************************************************************************/
23  package com.gisgraphy.domain.geoloc.importer;
24  
25  import static org.junit.Assert.assertEquals;
26  
27  import java.util.List;
28  
29  import junit.framework.Assert;
30  
31  import org.easymock.classextension.EasyMock;
32  import org.junit.Test;
33  
34  import com.gisgraphy.domain.repository.IAdmDao;
35  import com.gisgraphy.domain.valueobject.NameValueDTO;
36  
37  public class GeonamesAdm1ImporterTest {
38  
39      @Test
40      public void rollbackShouldRollback() {
41  	GeonamesAdm1Importer geonamesAdm1Importer = new GeonamesAdm1Importer();
42  	IAdmDao admDao = EasyMock.createMock(IAdmDao.class);
43  	EasyMock.expect(admDao.deleteAllByLevel(1)).andReturn(4);
44  	EasyMock.replay(admDao);
45  	geonamesAdm1Importer.setAdmDao(admDao);
46  	List<NameValueDTO<Integer>> deleted = geonamesAdm1Importer.rollback();
47  	assertEquals(1, deleted.size());
48  	assertEquals(4, deleted.get(0).getValue().intValue());
49      }
50      
51      @Test
52      public void shouldBeSkipShouldReturnCorrectValue(){
53  	ImporterConfig importerConfig = new ImporterConfig();
54  	GeonamesAdm1Importer geonamesAdm1Importer = new GeonamesAdm1Importer();
55  	geonamesAdm1Importer.setImporterConfig(importerConfig);
56  	
57  	importerConfig.setGeonamesImporterEnabled(false);
58  	Assert.assertTrue(geonamesAdm1Importer.shouldBeSkipped());
59  	
60  	importerConfig.setGeonamesImporterEnabled(true);
61  	Assert.assertFalse(geonamesAdm1Importer.shouldBeSkipped());
62  		
63      }
64  
65  }