Skip to content

Commit

Permalink
Release of version 1.8.2 (#67)
Browse files Browse the repository at this point in the history
* Cleanup of dependencies and imports.
* Use springboot version in one place.
* Fix bug with hunting places names with a slash and adding tests.
  • Loading branch information
benjaminkomen authored May 16, 2020
1 parent a23ba53 commit 97e9560
Show file tree
Hide file tree
Showing 27 changed files with 382 additions and 141 deletions.
60 changes: 37 additions & 23 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,26 @@
buildscript {
ext {
springBootVersion = '2.2.6.RELEASE'
}
repositories {
jcenter()
}
dependencies {
classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
}
}

plugins {
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'java'
id 'idea'
id 'jacoco'
id "org.sonarqube" version "2.8"
}

apply plugin: 'org.springframework.boot'

group = 'com.tibiawiki'
version = '1.8.1'
version = '1.8.2'
description = 'TibiaWikiApi'
sourceCompatibility = '14'
targetCompatibility = '14'
Expand All @@ -25,28 +38,29 @@ repositories {
}
}

ext {
slf4jVersion = '1.7.30'
junitVersion = '5.6.2'
lombokVersion = '1.18.12'
}

dependencies {
implementation 'org.springframework.boot:spring-boot-starter:2.2.6.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-jersey:2.2.6.RELEASE'
implementation 'org.springframework.boot:spring-boot-starter-web:2.2.6.RELEASE'
implementation 'benjaminkomen:jwiki:2.2.0'
implementation 'org.slf4j:slf4j-api:1.7.30'
implementation 'org.slf4j:slf4j-log4j12:1.7.30'
implementation 'org.json:json:20190722'
implementation 'org.jetbrains:annotations:19.0.0'
implementation 'one.util:streamex:0.7.2'
implementation 'javax.xml.bind:jaxb-api:2.3.1'
implementation 'javax.activation:activation:1.1.1'
implementation 'com.google.guava:guava:29.0-jre'
implementation 'io.swagger:swagger-jersey2-jaxrs:1.6.1'
implementation 'io.vavr:vavr:0.10.2'
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.6.2'
testImplementation 'org.junit.jupiter:junit-jupiter-engine:5.6.2'
testImplementation 'org.mockito:mockito-core:3.3.3'
testImplementation 'org.hamcrest:hamcrest:2.2'
testImplementation 'org.springframework.boot:spring-boot-starter-test:2.2.6.RELEASE'
annotationProcessor 'org.projectlombok:lombok:1.18.12'
compileOnly 'org.projectlombok:lombok:1.18.12'
implementation "org.springframework.boot:spring-boot-starter:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-jersey:${springBootVersion}"
implementation "org.springframework.boot:spring-boot-starter-web:${springBootVersion}"
implementation "benjaminkomen:jwiki:2.2.0"
implementation "org.slf4j:slf4j-api:${slf4jVersion}"
implementation "org.slf4j:slf4j-log4j12:${slf4jVersion}"
implementation "org.json:json:20190722"
implementation "io.swagger:swagger-jersey2-jaxrs:1.6.1"
implementation "io.vavr:vavr:0.10.2"
testImplementation "org.junit.jupiter:junit-jupiter-api:${junitVersion}"
testImplementation "org.junit.jupiter:junit-jupiter-engine:${junitVersion}"
testImplementation "org.mockito:mockito-core:3.3.3"
testImplementation "org.hamcrest:hamcrest:2.2"
testImplementation "org.springframework.boot:spring-boot-starter-test:${springBootVersion}"
annotationProcessor "org.projectlombok:lombok:${lombokVersion}"
compileOnly "org.projectlombok:lombok:${lombokVersion}"
}

sonarqube {
Expand Down
12 changes: 12 additions & 0 deletions src/integrationTest/java/com/tibiawiki/TestUtils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.tibiawiki;

import org.springframework.http.HttpHeaders;

public class TestUtils {

public static HttpHeaders makeHttpHeaders(String editSummary) {
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("X-WIKI-Edit-Summary", editSummary);
return httpHeaders;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.tibiawiki.domain.enums.YesNo;
import com.tibiawiki.domain.objects.Achievement;
import com.tibiawiki.domain.repositories.ArticleRepository;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -24,6 +23,7 @@
import java.util.List;
import java.util.Map;

import static com.tibiawiki.TestUtils.makeHttpHeaders;
import static com.tibiawiki.process.RetrieveAny.CATEGORY_LISTS;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -158,11 +158,4 @@ private Achievement makeAchievement() {
.relatedpages("[[Muck Remover]], [[Mucus Plug]]")
.build();
}

@NotNull
private HttpHeaders makeHttpHeaders(String editSummary) {
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("X-WIKI-Edit-Summary", editSummary);
return httpHeaders;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import com.tibiawiki.domain.enums.InfoboxTemplate;
import com.tibiawiki.domain.objects.Book;
import com.tibiawiki.domain.repositories.ArticleRepository;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -24,6 +23,7 @@
import java.util.List;
import java.util.Map;

import static com.tibiawiki.TestUtils.makeHttpHeaders;
import static com.tibiawiki.process.RetrieveAny.CATEGORY_LISTS;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -153,11 +153,4 @@ private Book makeBook() {
.text("Dungeon Survival Guide<br><br>Don't explore the dungeons before you tested your skills in the training cellars of our academy. You will find dungeons somewhere in the wilderness. Don't enter dungeons without equipment. Especially a rope and a shovel will prove valuable. Make sure you have a supply of torches with you, while wandering into the unknown. It's wise to travel the dungeons in groups and not alone. For more help read all the books of the academy before you begin exploring. Traveling in the dungeons will reward the cautious and brave, but punish the reckless.")
.build();
}

@NotNull
private HttpHeaders makeHttpHeaders(String editSummary) {
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("X-WIKI-Edit-Summary", editSummary);
return httpHeaders;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
import com.tibiawiki.domain.objects.LootItem;
import com.tibiawiki.domain.objects.Percentage;
import com.tibiawiki.domain.repositories.ArticleRepository;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -32,6 +31,7 @@
import java.util.List;
import java.util.Map;

import static com.tibiawiki.TestUtils.makeHttpHeaders;
import static com.tibiawiki.process.RetrieveAny.CATEGORY_LISTS;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -302,11 +302,4 @@ private Creature makeCreature() {
.history("Dragons are")
.build();
}

@NotNull
private HttpHeaders makeHttpHeaders(String editSummary) {
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("X-WIKI-Edit-Summary", editSummary);
return httpHeaders;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
package com.tibiawiki.serviceinterface;

import com.tibiawiki.domain.enums.InfoboxTemplate;
import com.tibiawiki.domain.repositories.ArticleRepository;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.junit.jupiter.SpringExtension;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import static com.tibiawiki.process.RetrieveAny.CATEGORY_LISTS;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;
import static org.mockito.Mockito.doReturn;

@ExtendWith(SpringExtension.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
public class HuntingPlacesIT {

@Autowired
private TestRestTemplate restTemplate;

@MockBean
private ArticleRepository articleRepository; // don't instantiate this real class, but use a mock implementation

private static final String INFOBOX_HUNT_TEXT = """
{{Infobox Hunt
| name = Tiquanda Bandit Caves
| image = Bandit
| implemented = 7.5
| city = Port Hope
| location = [[Tiquanda]], north of [[Port Hope]], {{Mapper Coords|127.43|127.167|7|3|text=here}}.
| vocation = All vocations.
| lvlknights = 20
| lvlpaladins = 20
| lvlmages = 15
| skknights = 50
| skpaladins = 50
| skmages =
| defknights = 45
| defpaladins = 40
| defmages =
| exp = Bad
| expstar = 2
| loot = Very Bad
| lootstar = 1
| bestloot = Deer Trophy
| bestloot2 = Iron Helmet
| bestloot3 = Brass Armor
| bestloot4 = Wolf Paw
| map = Tiquanda Bandit,Reptile,Crustacean Caves-1.gif
| map2 = Tiquanda Bandit,Reptile,Crustacean Caves-2.gif
| map3 = Tiquanda Bandit,Reptile,Crustacean Caves-3.gif
| mapwidth = 250px
}}
""";

@Test
void givenGetHuntingPlacesNotExpanded_whenCorrectRequest_thenResponseIsOkAndContainsTwoHuntingPlaceNames() {
doReturn(Collections.singletonList("baz")).when(articleRepository).getPageNamesFromCategory(CATEGORY_LISTS);
doReturn(Arrays.asList("foo", "bar", "baz")).when(articleRepository).getPageNamesFromCategory(InfoboxTemplate.HUNT.getCategoryName());

final ResponseEntity<List> result = restTemplate.getForEntity("/api/huntingplaces?expand=false", List.class);

assertThat(result.getStatusCode(), is(HttpStatus.OK));
assertThat(result.getBody(), is(notNullValue()));
assertThat(result.getBody().size(), is(2));
assertThat(result.getBody().get(0), is("foo"));
assertThat(result.getBody().get(1), is("bar"));
}

@Test
void givenGetHuntingPlaceByName_whenCorrectRequest_thenResponseIsOkAndContainsTheHuntingPlaceWithSlashInName() {
doReturn(INFOBOX_HUNT_TEXT).when(articleRepository).getArticle("Tiquanda/Bandit Caves");

final ResponseEntity<String> result = restTemplate.getForEntity("/api/huntingplaces/Tiquanda/Bandit Caves", String.class);
assertThat(result.getStatusCode(), is(HttpStatus.OK));

final JSONObject resultAsJSON = new JSONObject(result.getBody());
assertThat(resultAsJSON.get("templateType"), is("Hunt"));
assertThat(resultAsJSON.get("city"), is("Port Hope"));
assertThat(resultAsJSON.get("lvlmages"), is("15"));
assertThat(resultAsJSON.get("lvlknights"), is("20"));
assertThat(resultAsJSON.get("defpaladins"), is("40"));
assertThat(resultAsJSON.get("mapwidth"), is("250px"));
assertThat(resultAsJSON.get("expstar"), is("2"));
assertThat(resultAsJSON.get("lvlpaladins"), is("20"));
assertThat(resultAsJSON.get("bestloot"), is("Deer Trophy"));
assertThat(resultAsJSON.get("implemented"), is("7.5"));
assertThat(resultAsJSON.get("loot"), is("Very Bad"));
assertThat(resultAsJSON.get("exp"), is("Bad"));
assertThat(resultAsJSON.get("map"), is("Tiquanda Bandit,Reptile,Crustacean Caves-1.gif"));
assertThat(resultAsJSON.get("image"), is("Bandit"));
assertThat(resultAsJSON.get("skpaladins"), is("50"));
assertThat(resultAsJSON.get("map3"), is("Tiquanda Bandit,Reptile,Crustacean Caves-3.gif"));
assertThat(resultAsJSON.get("map2"), is("Tiquanda Bandit,Reptile,Crustacean Caves-2.gif"));
assertThat(resultAsJSON.get("bestloot4"), is("Wolf Paw"));
assertThat(resultAsJSON.get("bestloot2"), is("Iron Helmet"));
assertThat(resultAsJSON.get("bestloot3"), is("Brass Armor"));
assertThat(resultAsJSON.get("skknights"), is("50"));
assertThat(resultAsJSON.get("defknights"), is("45"));
assertThat(resultAsJSON.get("lootstar"), is("1"));
assertThat(resultAsJSON.get("vocation"), is("All vocations."));
assertThat(resultAsJSON.get("name"), is("Tiquanda Bandit Caves"));
assertThat(resultAsJSON.get("location"), is("[[Tiquanda]], north of [[Port Hope]], {{Mapper Coords|127.43|127.167|7|3|text=here}}."));
}

@Test
void givenGetHuntingPlaceByName_whenWrongRequest_thenResponseIsNotFound() {
doReturn(null).when(articleRepository).getArticle("Foobar");

final ResponseEntity<String> result = restTemplate.getForEntity("/api/huntingplaces/Foobar", String.class);
assertThat(result.getStatusCode(), is(HttpStatus.NOT_FOUND));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import com.tibiawiki.domain.enums.YesNo;
import com.tibiawiki.domain.objects.Item;
import com.tibiawiki.domain.repositories.ArticleRepository;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
Expand All @@ -30,6 +29,7 @@
import java.util.List;
import java.util.Map;

import static com.tibiawiki.TestUtils.makeHttpHeaders;
import static com.tibiawiki.process.RetrieveAny.CATEGORY_LISTS;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
Expand Down Expand Up @@ -234,11 +234,4 @@ private Item makeItem() {
.notes("If you have one of these ")
.build();
}

@NotNull
private HttpHeaders makeHttpHeaders(String editSummary) {
final HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.set("X-WIKI-Edit-Summary", editSummary);
return httpHeaders;
}
}
Loading

0 comments on commit 97e9560

Please sign in to comment.