@Test
  public void testSetIsInFields_first_ok_second_null_isInAlreadyFilled() {
    OpenStreetMapSimpleImporter openStreetMapSimpleImporter = new OpenStreetMapSimpleImporter();

    final String cityName = "cityName";
    final Integer population = 123;
    final String adm2name = "adm2name";
    final City city = new City();
    city.setPopulation(population);
    city.setAdm2Name(adm2name);
    city.setName(cityName);
    city.setMunicipality(false);
    city.setFeatureId(1L);
    city.setId(123L);
    final Set<ZipCode> zipCodes = new HashSet<ZipCode>();
    zipCodes.add(new ZipCode("zip1"));
    city.addZipCodes(zipCodes);
    Point location = GeolocHelper.createPoint(2F, 3F);

    String countryCode = "FR";

    AlternateName an1 = new AlternateName("an1", AlternateNameSource.OPENSTREETMAP);
    AlternateName an2 = new AlternateName("an2", AlternateNameSource.OPENSTREETMAP);
    city.addAlternateName(an1);
    city.addAlternateName(an2);

    ICityDao cityDao = EasyMock.createMock(ICityDao.class);
    EasyMock.expect(
            cityDao.getByShape(
                EasyMock.anyObject(Point.class),
                EasyMock.anyObject(String.class),
                EasyMock.eq(true)))
        .andReturn(null);
    EasyMock.expect(
            cityDao.getNearest(location, countryCode, true, OpenStreetMapSimpleImporter.DISTANCE))
        .andReturn(city);
    EasyMock.expect(
            cityDao.getNearest(location, countryCode, false, OpenStreetMapSimpleImporter.DISTANCE))
        .andReturn(null);
    EasyMock.replay(cityDao);
    openStreetMapSimpleImporter.setCityDao(cityDao);

    OpenStreetMap street = new OpenStreetMap();
    street.setCountryCode(countryCode);
    street.setLocation(location);
    street.setIsIn("AlreadyFilled");
    street.setCityId(456L);
    openStreetMapSimpleImporter.setIsInFields(street);

    Set<String> expectedZip = new HashSet<String>();
    expectedZip.add("ZIP1");
    Assert.assertEquals(expectedZip, street.getIsInZip());
    Assert.assertEquals("adm2name", street.getIsInAdm());
    Assert.assertEquals("AlreadyFilled", street.getIsIn());
    Assert.assertEquals(456L, street.getCityId());
    Assert.assertEquals(null, street.getIsInPlace());
    Assert.assertTrue(street.getIsInCityAlternateNames().size() == 2);

    EasyMock.verify(cityDao);
  }
  @Test
  public void testGetNearestCity_filterMunicipality() {
    ImporterConfig importerConfig = new ImporterConfig();
    importerConfig.setGeonamesImporterEnabled(true);
    importerConfig.setOpenStreetMapFillIsIn(true);
    OpenStreetMapSimpleImporter openStreetMapImporter = new OpenStreetMapSimpleImporter();
    openStreetMapImporter.setImporterConfig(importerConfig);
    final String cityName = "cityName";
    final Integer population = 123;
    final City city = new City();
    city.setName(cityName);
    city.setPopulation(population);

    ICityDao citydao = EasyMock.createMock(ICityDao.class);
    Point location = GeolocHelper.createPoint(2F, 3F);
    String countryCode = "FR";
    EasyMock.expect(
            citydao.getNearest(location, countryCode, true, OpenStreetMapSimpleImporter.DISTANCE))
        .andReturn(city);
    EasyMock.replay(citydao);

    openStreetMapImporter.setCityDao(citydao);

    City actual = openStreetMapImporter.getNearestCity(location, countryCode, true);
    Assert.assertEquals(cityName, actual.getName());
    Assert.assertEquals(population, actual.getPopulation());
    EasyMock.verify(citydao);
  }
  @Test
  public void testSetIsInFields_GetByShape() {
    OpenStreetMapSimpleImporter openStreetMapSimpleImporter = new OpenStreetMapSimpleImporter();

    Point location = GeolocHelper.createPoint(2F, 3F);

    String countryCode = "FR";

    ICityDao cityDao = EasyMock.createMock(ICityDao.class);
    City cityByShape = new City();
    cityByShape.addZipCode(new ZipCode("zip"));
    cityByShape.setName("name");
    cityByShape.setPopulation(1000000);
    Adm adm = new Adm(2);
    adm.setName("admName");
    cityByShape.setAdm(adm);
    cityByShape.setFeatureId(1L);
    cityByShape.setId(123L);
    EasyMock.expect(
            cityDao.getByShape(
                EasyMock.anyObject(Point.class),
                EasyMock.anyObject(String.class),
                EasyMock.eq(true)))
        .andReturn(cityByShape);
    EasyMock.replay(cityDao);
    openStreetMapSimpleImporter.setCityDao(cityDao);

    OpenStreetMap street = new OpenStreetMap();
    street.setCountryCode(countryCode);
    street.setLocation(location);
    openStreetMapSimpleImporter.setIsInFields(street);

    Set<String> expectedZip = new HashSet<String>();
    expectedZip.add("ZIP");
    Assert.assertEquals(expectedZip, street.getIsInZip());
    Assert.assertEquals(true, street.isCityConfident());
    Assert.assertEquals("admName", street.getIsInAdm());
    Assert.assertEquals("name", street.getIsIn());
    Assert.assertEquals(123L, street.getCityId());
    Assert.assertEquals(null, street.getIsInPlace());

    EasyMock.verify(cityDao);
  }
  @Test
  public void testSetIsInFields_both_null() {
    OpenStreetMapSimpleImporter openStreetMapSimpleImporter = new OpenStreetMapSimpleImporter();

    final City city = new City();
    city.setMunicipality(false);
    final List<ZipCode> zipCodes = new ArrayList<ZipCode>();
    zipCodes.add(new ZipCode("zip1"));
    Point location = GeolocHelper.createPoint(2F, 3F);

    String countryCode = "FR";

    ICityDao cityDao = EasyMock.createMock(ICityDao.class);
    EasyMock.expect(
            cityDao.getByShape(
                EasyMock.anyObject(Point.class),
                EasyMock.anyObject(String.class),
                EasyMock.eq(true)))
        .andReturn(null);
    EasyMock.expect(
            cityDao.getNearest(location, countryCode, true, OpenStreetMapSimpleImporter.DISTANCE))
        .andReturn(city);
    EasyMock.expect(
            cityDao.getNearest(location, countryCode, false, OpenStreetMapSimpleImporter.DISTANCE))
        .andReturn(null);
    EasyMock.replay(cityDao);
    openStreetMapSimpleImporter.setCityDao(cityDao);

    OpenStreetMap street = new OpenStreetMap();
    street.setCountryCode(countryCode);
    street.setLocation(location);
    openStreetMapSimpleImporter.setIsInFields(street);

    Assert.assertEquals(null, street.getIsInZip());
    Assert.assertEquals(null, street.getIsInAdm());
    Assert.assertEquals(null, street.getIsIn());
    Assert.assertEquals(null, street.getIsInPlace());

    EasyMock.verify(cityDao);
  }
  @Test
  public void testImporterShouldImport() throws InterruptedException {
    System.out.println(openStreetMapImporter.getClass());
    openStreetMapImporter.process();
    /*if (openStreetMapImporter.getClass() != OpenStreetMapImporter.class){
        Thread.sleep(10000L);
    }*/
    assertEquals(4L, openStreetMapDao.count());
    openStreetMapDao.getAll();
    Long firstIdAssigned = (idGenerator.getGid() - 4 + 1);
    OpenStreetMap openStreetMap = openStreetMapDao.getByGid(firstIdAssigned);
    assertTrue("The oneWay attribute is not correct", openStreetMap.isOneWay());
    assertEquals("The countryCode is not correct ", "FR", openStreetMap.getCountryCode());
    assertEquals("The is_in is not correct ", "a city", openStreetMap.getIsIn());
    assertEquals(
        "The openstreetmapId is not correct ", new Long(11), openStreetMap.getOpenstreetmapId());
    assertEquals(
        "The streetType is not correct", StreetType.RESIDENTIAL, openStreetMap.getStreetType());
    assertEquals("The name is not correct", "Bachlettenstrasse", openStreetMap.getName());
    assertEquals(
        "The location->X is not correct ",
        ((Point)
                GeolocHelper.convertFromHEXEWKBToGeometry(
                    "010100000006C82291A0521E4054CC39B16BC64740"))
            .getX(),
        openStreetMap.getLocation().getX());
    assertEquals(
        "The location->Y is not correct ",
        ((Point)
                GeolocHelper.convertFromHEXEWKBToGeometry(
                    "010100000006C82291A0521E4054CC39B16BC64740"))
            .getY(),
        openStreetMap.getLocation().getY());
    assertEquals("The length is not correct", 0.00142246604529, openStreetMap.getLength());
    assertEquals(
        "The shape is not correct ",
        GeolocHelper.convertFromHEXEWKBToGeometry(
                "01020000000200000009B254CD6218024038E22428D9EF484075C93846B217024090A8AB96CFEF4840")
            .toString(),
        openStreetMap.getShape().toString());

    // check alternate names when there is 2
    Assert.assertEquals(2, openStreetMap.getAlternateNames().size());
    Assert.assertTrue(
        alternateNamesContain(openStreetMap.getAlternateNames(), "Rue de Bachlettenstrasse"));
    Assert.assertTrue(
        alternateNamesContain(openStreetMap.getAlternateNames(), "Bachletten strasse"));

    // check alternate names when there is no name but alternate
    openStreetMap = openStreetMapDao.getByGid(firstIdAssigned + 1);
    Assert.assertEquals(1, openStreetMap.getAlternateNames().size());
    Assert.assertEquals(
        "When there is no name and some alternatename, the first alternatename is set to name ",
        "noName BUT an alternate",
        openStreetMap.getName());
    Assert.assertTrue(alternateNamesContain(openStreetMap.getAlternateNames(), "other an"));

    // one alternate name
    openStreetMap = openStreetMapDao.getByGid(firstIdAssigned + 2);
    Assert.assertEquals(1, openStreetMap.getAlternateNames().size());
    Assert.assertTrue(alternateNamesContain(openStreetMap.getAlternateNames(), "Friedhof"));

    // no alternate names
    openStreetMap = openStreetMapDao.getByGid(firstIdAssigned + 3);
    Assert.assertEquals(0, openStreetMap.getAlternateNames().size());
  }
  @Test
  public void testSetIsInFields_both_ok_different_id_municipality_near() {
    OpenStreetMapSimpleImporter openStreetMapSimpleImporter = new OpenStreetMapSimpleImporter();

    final String cityName = "cityName";
    final Integer population = 123;
    final String adm2name = "adm2name";
    final City city = new City();
    city.setFeatureId(1L);
    city.setId(123L);
    city.setPopulation(population);
    city.setAdm2Name(adm2name);
    city.setName(cityName);
    city.setMunicipality(false);
    final Set<ZipCode> zipCodes = new HashSet<ZipCode>();
    zipCodes.add(new ZipCode("zip1"));
    city.addZipCodes(zipCodes);
    city.setLocation(GeolocHelper.createPoint(2.1F, 5.1F));

    final String cityName2 = "cityName2";
    final Integer population2 = 456;
    final String adm2name2 = "adm2name2";
    final City city2 = new City();
    city2.setFeatureId(2L);
    city2.setId(456L);
    city2.setPopulation(population2);
    city2.setAdm2Name(adm2name2);
    city2.setName(cityName2);
    final Set<ZipCode> zipCodes2 = new HashSet<ZipCode>();
    zipCodes2.add(new ZipCode("zip2"));
    city2.addZipCodes(zipCodes2);
    city2.setLocation(GeolocHelper.createPoint(4F, 5F));

    Point location = GeolocHelper.createPoint(2F, 3F);

    String countryCode = "FR";

    AlternateName an1 = new AlternateName("an1", AlternateNameSource.OPENSTREETMAP);
    AlternateName an2 = new AlternateName("an2", AlternateNameSource.OPENSTREETMAP);
    city.addAlternateName(an1);
    city.addAlternateName(an2);

    ICityDao cityDao = EasyMock.createMock(ICityDao.class);
    EasyMock.expect(
            cityDao.getByShape(
                EasyMock.anyObject(Point.class),
                EasyMock.anyObject(String.class),
                EasyMock.eq(true)))
        .andReturn(null);
    EasyMock.expect(
            cityDao.getNearest(location, countryCode, true, OpenStreetMapSimpleImporter.DISTANCE))
        .andReturn(city);
    EasyMock.expect(
            cityDao.getNearest(location, countryCode, false, OpenStreetMapSimpleImporter.DISTANCE))
        .andReturn(city2);
    EasyMock.replay(cityDao);
    openStreetMapSimpleImporter.setCityDao(cityDao);

    OpenStreetMap street = new OpenStreetMap();
    street.setCountryCode(countryCode);
    street.setLocation(location);
    openStreetMapSimpleImporter.setIsInFields(street);

    Set<String> expectedZip = new HashSet<String>();
    expectedZip.add("ZIP1");
    Assert.assertEquals(expectedZip, street.getIsInZip());
    Assert.assertEquals("adm2name", street.getIsInAdm());
    Assert.assertEquals("cityName", street.getIsIn());
    Assert.assertEquals(123L, street.getCityId());
    Assert.assertEquals(
        "isIn should not be filled with only isin if result are different and municipality is the nearest",
        cityName,
        street.getIsIn());
    Assert.assertEquals(
        "isIn place should not be filled if result are different and municipality is the nearest",
        null,
        street.getIsInPlace());
    Assert.assertTrue(street.getIsInCityAlternateNames().size() == 2);

    EasyMock.verify(cityDao);
  }