- CountryLocator
CountryLocator is a Java application that determines the country code (ISO 3166-1 alpha-2 format) for given latitude and longitude coordinates. The application interacts with a MySQL database to fetch the country details and includes functionality for unit and performance testing.
** Table of Contents
1.[Overview] 2.[Setup] 3.[Database Setup] 4.[Application Setup] 5.[Usage] 6.[Running the Application] 7.[Running Tests] 8.[Performance Testing] 9.[Technologies Used]
** Overview
The CountryLocator application provides the following functionality:
- Accepts latitude and longitude as input and returns the corresponding country code.
- Connects to a MySQL database to retrieve country boundary information.
- Includes unit tests to verify the functionality of the
CountryLocatorclass. - Provides a performance test to simulate 100 requests per second and measure the average response time.
** Setup
** Database Setup
-
Install MySQL and create a database named
GeoLocation. -
Create a table
CountryBoundarieswith the following schema: sqlCREATE TABLE CountryBoundaries ( id INT AUTO_INCREMENT PRIMARY KEY, country_code VARCHAR(2) NOT NULL, min_lat DOUBLE NOT NULL, max_lat DOUBLE NOT NULL, min_lon DOUBLE NOT NULL, max_lon DOUBLE NOT NULL );
-
Populate the table with country boundary data.
*** Application Setup
- Download and install JDK 17.
- Ensure the MySQL Connector/ (JAR file) is added to your project's classpath. You can download it from the MySQL website.
- Copy the Java source files (
CountryLocator.java,CountryLocatorTest.java,PerformanceTest.java) into your project directory.
** Usage
*** Running the Application
-
Compile the Java source files:
javac backend/CountryLocator.java backend/PerformanceTest.java
-
Run the
CountryLocatorclass:java backend.CountryLocator
-
Enter the latitude and longitude when prompted.
-
The application will display the corresponding country code or a message indicating that no country was found.
*** Running Tests
-
Ensure JUnit 4 is added to your project's classpath.
-
Compile and run the
CountryLocatorTestclass: -
The tests will verify the functionality of the
getCountryCodemethod and its exception handling.
*** Performance Testing
-
Compile and run the
PerformanceTestclass to simulate 100 requests per second and measure the average response time:javac backend/PerformanceTest.java java backend.PerformanceTest
** Technologies Used
- Java (JDK 17)
- MySQL
- JUnit 4.13.2
- MySQL Connector/Jar 8.0.11