Skip to content

Commit a884e05

Browse files
committed
Add missing geocodes for countries
Affects issues: - Fixed #3843
1 parent 7de29e7 commit a884e05

File tree

4 files changed

+320
-8
lines changed

4 files changed

+320
-8
lines changed

Plan/common/src/main/resources/assets/plan/geocodes.json

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717
"hong kong": "HKG",
1818
"armenia": "ARM",
1919
"vietnam": "VNM",
20+
"vatican city": "VAT",
2021
"australia": "AUS",
2122
"laos": "LAO",
2223
"aruba": "ABW",
2324
"solomon islands": "SLB",
2425
"turkey": "TUR",
26+
"türkiye": "TUR",
2527
"ukraine": "UKR",
2628
"austria": "AUT",
2729
"united states": "USA",
@@ -33,7 +35,8 @@
3335
"greece": "GRC",
3436
"paraguay": "PRY",
3537
"palau": "PLW",
36-
"congo, republic of the": "COG",
38+
"congo republic": "COD",
39+
"dr congo": "COG",
3740
"vanuatu": "VUT",
3841
"cyprus": "CYP",
3942
"colombia": "COL",
@@ -93,6 +96,7 @@
9396
"zimbabwe": "ZWE",
9497
"el salvador": "SLV",
9598
"macedonia": "MKD",
99+
"north macedonia": "MKD",
96100
"saint lucia": "LCA",
97101
"bolivia": "BOL",
98102
"china": "CHN",
@@ -187,6 +191,7 @@
187191
"tanzania": "TZA",
188192
"grenada": "GRD",
189193
"netherlands": "NLD",
194+
"the netherlands": "NLD",
190195
"sao tome and principe": "STP",
191196
"guam": "GUM",
192197
"eritrea": "ERI",
@@ -221,5 +226,30 @@
221226
"saint vincent and the grenadines": "VCT",
222227
"tonga": "TON",
223228
"barbados": "BRB",
224-
"new caledonia": "NCL"
229+
"new caledonia": "NCL",
230+
"réunion": "REU",
231+
"mayotte": "MYT",
232+
"martinique": "MTQ",
233+
"guadeloupe": "GLP",
234+
"french guiana": "GUF",
235+
"eswatini": "SWZ",
236+
"cocos (keeling) islands": "CCK",
237+
"macao": "MAC",
238+
"st kitts and nevis": "KNA",
239+
"saint barthélemy": "BLM",
240+
"st vincent and grenadines": "VCT",
241+
"bahamas": "BHS",
242+
"myanmar": "MMR",
243+
"tokelau": "TKL",
244+
"wallis and futuna": "WLF",
245+
"ivory coast": "CIV",
246+
"côte d'ivoire": "CIV",
247+
"gambia": "GMB",
248+
"nauru": "NRU",
249+
"federated states of micronesia": "FSM",
250+
"curaçao": "CUW",
251+
"são tomé and príncipe": "STP",
252+
"turks and caicos islands": "TCA",
253+
"norfolk island": "NFK",
254+
"pitcairn islands": "PCN"
225255
}

Plan/common/src/test/java/com/djrapitops/plan/gathering/geolocation/GeolocationTest.java

Lines changed: 46 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,28 +17,34 @@
1717
package com.djrapitops.plan.gathering.geolocation;
1818

1919
import com.djrapitops.plan.PlanSystem;
20+
import com.djrapitops.plan.delivery.rendering.json.graphs.Graphs;
2021
import com.djrapitops.plan.processing.Processing;
2122
import com.djrapitops.plan.settings.ConfigSystem;
2223
import com.djrapitops.plan.settings.config.PlanConfig;
2324
import com.djrapitops.plan.settings.config.paths.DataGatheringSettings;
2425
import com.djrapitops.plan.settings.locale.Locale;
2526
import com.djrapitops.plan.storage.file.PlanFiles;
27+
import com.google.gson.Gson;
28+
import com.google.gson.reflect.TypeToken;
2629
import extension.FullSystemExtension;
2730
import net.playeranalytics.plugin.server.PluginLogger;
28-
import org.junit.jupiter.api.AfterEach;
29-
import org.junit.jupiter.api.BeforeAll;
30-
import org.junit.jupiter.api.BeforeEach;
31-
import org.junit.jupiter.api.Test;
31+
import org.junit.jupiter.api.*;
3232
import org.junit.jupiter.api.extension.ExtendWith;
3333
import org.mockito.junit.jupiter.MockitoExtension;
3434
import utilities.TestErrorLogger;
3535
import utilities.TestPluginLogger;
36+
import utilities.TestResources;
3637
import utilities.mocks.TestProcessing;
3738

39+
import java.io.File;
3840
import java.io.IOException;
41+
import java.io.StringReader;
42+
import java.net.URISyntaxException;
3943
import java.nio.file.Files;
40-
import java.util.HashMap;
41-
import java.util.Map;
44+
import java.nio.file.Path;
45+
import java.nio.file.StandardOpenOption;
46+
import java.util.*;
47+
import java.util.stream.Stream;
4248

4349
import static org.junit.jupiter.api.Assertions.*;
4450

@@ -118,4 +124,38 @@ void callsToCachedIPsReturnCachedEntries() {
118124
assertEquals(expIp, countryThirdCall);
119125
}
120126
}
127+
128+
// Test utility for reading https://cable.ayra.ch/ip/data/countries.json for getting first IP of each country
129+
// Have to manually remove 3 first ones and the IPv6 addresses at the end.
130+
public static void main(String[] args) throws URISyntaxException, IOException {
131+
File testResourceFile = TestResources.getTestResourceFile("countries.json", GeolocationTest.class);
132+
String read = Files.readString(testResourceFile.toPath());
133+
Map<String, Map<String, List<String>>> contents = new Gson().fromJson(new StringReader(read), new TypeToken<>() {}.getType());
134+
List<String> singleIpPerCountry = contents.values().stream()
135+
.map(Map::values)
136+
.map(set -> set.stream().findFirst())
137+
.filter(Optional::isPresent)
138+
.map(Optional::get)
139+
.map(list -> list.get(0))
140+
.map(string -> string.split("/")[0])
141+
.toList();
142+
Path write = new File("src/test/resources/countries-reduced.txt").toPath();
143+
Files.write(write, singleIpPerCountry, StandardOpenOption.CREATE, StandardOpenOption.WRITE);
144+
}
145+
146+
@TestFactory
147+
@DisplayName("Country has geocode")
148+
Collection<DynamicTest> everyCountryHasCodeInGeocodesJson(Graphs graphs) throws URISyntaxException, IOException {
149+
Map<String, String> geocodes = graphs.special().getGeocodes();
150+
File testResourceFile = TestResources.getTestResourceFile("countries-reduced.txt", GeolocationTest.class);
151+
try (Stream<String> lines = Files.lines(testResourceFile.toPath())) {
152+
return lines
153+
.map(underTest::getCountry)
154+
.distinct()
155+
.map(country -> DynamicTest.dynamicTest(country, () -> {
156+
assertTrue(geocodes.containsKey(country.toLowerCase()),
157+
() -> "Country '" + country + "' had no geocode associated with it.");
158+
})).toList();
159+
}
160+
}
121161
}

Plan/common/src/test/java/extension/FullSystemExtension.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import com.djrapitops.plan.delivery.DeliveryUtilities;
2222
import com.djrapitops.plan.delivery.export.Exporter;
2323
import com.djrapitops.plan.delivery.formatting.Formatters;
24+
import com.djrapitops.plan.delivery.rendering.json.graphs.Graphs;
2425
import com.djrapitops.plan.delivery.webserver.Addresses;
2526
import com.djrapitops.plan.identification.ServerUUID;
2627
import com.djrapitops.plan.settings.ConfigSystem;
@@ -89,6 +90,7 @@ public FullSystemExtension() {
8990
.put(PublicHtmlFiles.class, () -> planSystem.getDeliveryUtilities().getPublicHtmlFiles())
9091
.put(Webserver.class, () -> planSystem.getWebServerSystem().getWebServer())
9192
.put(Exporter.class, () -> planSystem.getExportSystem().getExporter())
93+
.put(Graphs.class, () -> planSystem.getDeliveryUtilities().getGraphs())
9294
.build();
9395
}
9496

0 commit comments

Comments
 (0)