Skip to content

Commit

Permalink
Merge pull request #41 from glugg23/release/v0.3.0
Browse files Browse the repository at this point in the history
Release/v0.3.0
  • Loading branch information
jacobbarrow authored Mar 20, 2019
2 parents 87dbac6 + b90e02c commit 73650dc
Show file tree
Hide file tree
Showing 18 changed files with 1,082 additions and 83 deletions.
37 changes: 32 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,40 @@ sudo: required

language: java

addons:
hosts:
- db

jdk:
- oraclejdk11
- openjdk11

services:
- docker

after_success:
- mvn install
- sudo service mariadb stop
install:
- mvn clean install -DskipTests=true -D"maven.javadoc.skip=true" -B -V

jobs:
include:
- stage: Units
install: skip
script: mvn test -Dtest="com.napier.group20.places.*Test"
- stage: Integration
script:
- sudo docker-compose up -d db
- mvn test -Dtest="com.napier.group20.utils.*Test"
- stage: Deployment
install: skip
script:
- mvn package -DskipTests=true -D"maven.javadoc.skip=true"
- sudo docker-compose up --build --abort-on-container-exit

before_script:
- sudo service mysql stop
- sudo service postgresql stop
- sudo docker-compose up --build --abort-on-container-exit

after_success:
- bash <(curl -s https://codecov.io/bash)
- wget https://raw.githubusercontent.com/DiscordHooks/travis-ci-discord-webhook/master/send.sh
- chmod +x send.sh
- ./send.sh success $WEBHOOK_URL
Expand All @@ -23,3 +44,9 @@ after_failure:
- wget https://raw.githubusercontent.com/DiscordHooks/travis-ci-discord-webhook/master/send.sh
- chmod +x send.sh
- ./send.sh failure $WEBHOOK_URL

stages:
- Units
- Integration
- name: Deployment
if: branch = master
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM openjdk:11
COPY ./target/SET08103-G20-0.2.0-jar-with-dependencies.jar /tmp
COPY ./target/SET08103-G20-jar-with-dependencies.jar /tmp
WORKDIR /tmp
ENTRYPOINT ["java", "-jar","SET08103-G20-0.2.0-jar-with-dependencies.jar"]
ENTRYPOINT ["java", "-jar","SET08103-G20-jar-with-dependencies.jar"]
49 changes: 48 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>com.napier.group20</groupId>
<artifactId>SET08103-G20</artifactId>
<version>0.2.0</version>
<version>0.3.0</version>

<dependencies>
<!-- https://mvnrepository.com/artifact/org.mariadb.jdbc/mariadb-java-client -->
Expand All @@ -15,6 +15,21 @@
<artifactId>mariadb-java-client</artifactId>
<version>2.3.0</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.4.0</version>
<scope>test</scope>
</dependency>
</dependencies>

<properties>
Expand All @@ -27,6 +42,7 @@
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<finalName>SET08103-G20</finalName>
<archive>
<manifest>
<mainClass>com.napier.group20.Main</mainClass>
Expand All @@ -46,6 +62,37 @@
</execution>
</executions>
</plugin>

<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.0</version>
</plugin>

<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.0</version>
</plugin>

<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.2</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>test</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>

</plugins>
</build>
</project>
47 changes: 15 additions & 32 deletions src/main/java/com/napier/group20/Main.java
Original file line number Diff line number Diff line change
@@ -1,45 +1,28 @@
package com.napier.group20;

import java.util.concurrent.TimeUnit;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import com.napier.group20.places.City;
import com.napier.group20.places.Country;
import com.napier.group20.utils.App;

import java.util.ArrayList;

public class Main {
public static void main(String[] args) {
Connection connection = null;
int count = 10;
App app = new App();
app.connect("db:3306", 10);

if (args.length > 0) {
count = Integer.parseInt(args[0]);
}
app.loadDatabase();

for (int i = 0; (i < count) && (connection == null); i++){
try {
TimeUnit.SECONDS.sleep(5);
connection = DriverManager.getConnection("jdbc:mariadb://db:3306/world", "root", "secret");
} catch (Exception e) {
System.err.println("Connection to MariaDB container failed, retrying.");
}
}
app.disconnect();

if (connection == null) {
System.out.println("Cannot find instance of MariaDB. Closing program.");
System.exit(-1);
ArrayList<Country> countriesInWorld = app.countriesInWorld();
for(Country country : countriesInWorld) {
System.out.println(country.toString());
}

try {
String query = "SELECT * FROM country;";
Statement statement = connection.createStatement();
ResultSet resultSet = statement.executeQuery(query);

while(resultSet.next()) {
System.out.println(resultSet.getString("Name"));
}
connection.close();
} catch(Exception e) {
e.printStackTrace();
ArrayList<City> citiesInWorld = app.citiesInWorld();
for(City city : citiesInWorld) {
System.out.println(city.toString());
}
}
}
39 changes: 24 additions & 15 deletions src/main/java/com/napier/group20/places/City.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,31 @@
/**
* City.java
*
* Stores information about a city including its name, country,
* district, population and if it is the capital city.
* Stores information about a city including its name,
* population and if it is the capital city.
*
*/

public class City implements Population {

private String name;
private Country country;
private District district;
private int population;
private boolean isCapital;
private String country;
private String district;

public City(String name, Country country, District district, int population, boolean isCapital) {
public City(String name, int population, boolean isCapital, String country, String district) {
this.name = name;
this.country = country;
this.district = district;
this.population = population;
this.isCapital = isCapital;
this.country = country;
this.district = district;
}

public String getName() {
return name;
}

public Country getCountry() {
return country;
}

public District getDistrict() {
return district;
}

public long getPopulation() {
return (long)population;
}
Expand All @@ -46,4 +38,21 @@ public boolean isCapital() {
return isCapital;
}

public String getCountry() {
return country;
}

public String getDistrict() {
return district;
}

@Override
public String toString() {
return "City{" +
"name='" + name + '\'' +
", population=" + population +
", country='" + country + '\'' +
", district='" + district + '\'' +
'}';
}
}
63 changes: 50 additions & 13 deletions src/main/java/com/napier/group20/places/Country.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,24 @@ public class Country implements Population {

private String countryCode;
private String name;
private Continent continent;
private Region region;
private ArrayList<District> districts;
private City capital;
private ArrayList<Language> language;
private ArrayList<Language> languages;
private long population;
private String continent;
private String region;

public Country(String countryCode, String name, ArrayList<District> districts, City capital,
ArrayList<Language> languages, long population, String continent, String region) {
this.countryCode = countryCode;
this.name = name;
this.districts = districts;
this.capital = capital;
this.languages = languages;
this.population = population;
this.continent = continent;
this.region = region;
}

public String getCountryCode() {
return countryCode;
Expand All @@ -30,14 +42,6 @@ public String getName() {
return name;
}

public Continent getContinent() {
return continent;
}

public Region getRegion() {
return region;
}

public ArrayList<District> getDistricts() {
return districts;
}
Expand All @@ -46,8 +50,23 @@ public City getCapital() {
return capital;
}

public ArrayList<Language> getLanguage() {
return language;
public ArrayList<Language> getLanguages() {
return languages;
}

public ArrayList<Language> getOfficialLanguages() {
ArrayList<Language> officialLanguages = new ArrayList<>();
for(Language language : languages) {
if(language.isOfficial()) {
officialLanguages.add(language);
}
}

if(officialLanguages.isEmpty()) {
return null;
}

return officialLanguages;
}

public long getPopulation() {
Expand All @@ -62,5 +81,23 @@ public long getCitiesPopulation() {
return countryPopulation;
}

public String getContinent() {
return continent;
}

public String getRegion() {
return region;
}

@Override
public String toString() {
return "Country{" +
"countryCode='" + countryCode + '\'' +
", name='" + name + '\'' +
", continent='" + continent + '\'' +
", region='" + region + '\'' +
", population=" + population +
", capital=" + capital +
'}';
}
}
Loading

0 comments on commit 73650dc

Please sign in to comment.