コード例 #1
0
  @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);
  }
コード例 #2
0
  @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);
  }