-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Use jwiki published on GitHub Packages - Make Travis able to access GitHub Packages - Make Google Cloud build able to access GitHub Packages - Make use of new features in jwiki (Namespace constructor, Wiki builder - Add e2e tests - Change logging back from logback to slf4j-log12
- Loading branch information
Showing
11 changed files
with
181 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<settings xmlns="http://maven.apache.org/SETTINGS/1.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0 | ||
http://maven.apache.org/xsd/settings-1.0.0.xsd"> | ||
|
||
<activeProfiles> | ||
<activeProfile>github</activeProfile> | ||
</activeProfiles> | ||
|
||
<profiles> | ||
<profile> | ||
<id>github</id> | ||
<repositories> | ||
<repository> | ||
<id>central</id> | ||
<url>https://repo1.maven.org/maven2</url> | ||
<releases><enabled>true</enabled></releases> | ||
<snapshots><enabled>false</enabled></snapshots> | ||
</repository> | ||
<repository> | ||
<id>github-benjaminkomen</id> | ||
<name>GitHub Benjamin Komen Apache Maven Packages</name> | ||
<url>https://maven.pkg.github.com/benjaminkomen/jwiki</url> | ||
</repository> | ||
</repositories> | ||
</profile> | ||
</profiles> | ||
|
||
<servers> | ||
<server> | ||
<id>github-benjaminkomen</id> | ||
<username>benjaminkomen</username> | ||
<password>${env.GITHUB_TOKEN}</password> | ||
</server> | ||
</servers> | ||
</settings> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,26 @@ | ||
steps: | ||
# build the container image | ||
- name: 'gcr.io/cloud-builders/docker' | ||
args: ['build', '-t', 'gcr.io/tibiawikiapi-246008/tibiawikiapi', '.'] | ||
# push the container image to Container Registry | ||
entrypoint: 'bash' | ||
args: [ | ||
'-c', | ||
'docker build -t gcr.io/$PROJECT_ID/tibiawikiapi -f Dockerfile --build-arg GITHUB_TOKEN=$$GITHUB_TOKEN .' | ||
] | ||
secretEnv: ['GITHUB_TOKEN'] | ||
|
||
# push the container image to Container Registry | ||
- name: 'gcr.io/cloud-builders/docker' | ||
args: ['push', 'gcr.io/tibiawikiapi-246008/tibiawikiapi'] | ||
|
||
|
||
# Deploy container image to Cloud Run | ||
- name: 'gcr.io/cloud-builders/gcloud' | ||
args: ['beta', 'run', 'deploy', 'tibiawikiapi', '--image', 'gcr.io/tibiawikiapi-246008/tibiawikiapi', '--region', 'europe-west1','--platform', 'managed', '--memory', '1Gi', '--project', 'tibiawikiapi-246008', '--quiet'] | ||
|
||
images: | ||
- gcr.io/tibiawikiapi-246008/tibiawikiapi | ||
|
||
secrets: | ||
- kmsKeyName: projects/tibiawikiapi-246008/locations/global/keyRings/my-secrets/cryptoKeys/github-token | ||
secretEnv: | ||
GITHUB_TOKEN: CiQA5BHiVau0r93/go0GclWewjQvi10erqEHGi7nG5CHJpJudLwSUgAVCO4xq1IpCWVcMlDAM8Hg87XsjBcSojA7bS8W+gMGT43KLQNAf+1aj6qnjJ+l+Z6mST8nIGQW6bONZ014xy5SlW681SdgKUo6CoyVfAeyBf4= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
104 changes: 104 additions & 0 deletions
104
src/it/java/com/tibiawiki/serviceinterface/LootStatisticsResourceIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package com.tibiawiki.serviceinterface; | ||
|
||
import benjaminkomen.jwiki.core.NS; | ||
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 java.util.Map; | ||
|
||
import static com.tibiawiki.process.RetrieveAny.CATEGORY_LISTS; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.is; | ||
import static org.mockito.Mockito.doReturn; | ||
|
||
@ExtendWith(SpringExtension.class) | ||
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) | ||
public class LootStatisticsResourceIT { | ||
|
||
private static final NS LOOT_NAMESPACE = new NS(112); | ||
@Autowired | ||
private TestRestTemplate restTemplate; | ||
|
||
@MockBean | ||
private ArticleRepository articleRepository; // don't instantiate this real class, but use a mock implementation | ||
|
||
private static final String LOOT_AMAZON_TEXT = "{{Loot2\n" + | ||
"|version=8.6\n" + | ||
"|kills=22009\n" + | ||
"|name=Amazon\n" + | ||
"|Empty, times:253\n" + | ||
"|Dagger, times:17626, amount:1, total:17626\n" + | ||
"|Skull, times:17604, amount:1-2, total:26348\n" + | ||
"|Gold Coin, times:8829, amount:1-20, total:93176\n" + | ||
"|Brown Bread, times:6496, amount:1, total:6496\n" + | ||
"|Sabre, times:5098, amount:1, total:5098\n" + | ||
"|Girlish Hair Decoration, times:2179, amount:1, total:2179\n" + | ||
"|Protective Charm, times:1154, amount:1, total:1154\n" + | ||
"|Torch, times:223, amount:1, total:223\n" + | ||
"|Crystal Necklace, times:56, amount:1, total:56\n" + | ||
"|Small Ruby, times:27, amount:1, total:27\n" + | ||
"}}\n"; | ||
|
||
@Test | ||
void givenGetLootsNotExpanded_whenCorrectRequest_thenResponseIsOkAndContainsTwoLootNames() { | ||
doReturn(Arrays.asList("foo", "bar")).when(articleRepository).getPageNamesFromCategory(InfoboxTemplate.LOOT.getCategoryName(), LOOT_NAMESPACE); | ||
|
||
final ResponseEntity<List> result = restTemplate.getForEntity("/api/loot?expand=false", List.class); | ||
|
||
assertThat(result.getStatusCode(), is(HttpStatus.OK)); | ||
assertThat(result.getBody().size(), is(2)); | ||
assertThat(result.getBody().get(0), is("foo")); | ||
assertThat(result.getBody().get(1), is("bar")); | ||
} | ||
|
||
@Test | ||
void givenGetLootsExpanded_whenCorrectRequest_thenResponseIsOkAndContainsOneLoot() { | ||
doReturn(Collections.emptyList()).when(articleRepository).getPageNamesFromCategory(CATEGORY_LISTS); | ||
doReturn(Collections.singletonList("Loot:Amazon")).when(articleRepository).getPageNamesFromCategory(InfoboxTemplate.LOOT.getCategoryName(), LOOT_NAMESPACE); | ||
doReturn(Map.of("Loot:Amazon", LOOT_AMAZON_TEXT)).when(articleRepository).getArticlesFromCategory(Collections.singletonList("Loot:Amazon")); | ||
|
||
final ResponseEntity<List> result = restTemplate.getForEntity("/api/loot?expand=true", List.class); | ||
|
||
assertThat(result.getStatusCode(), is(HttpStatus.OK)); | ||
assertThat(result.getBody().size(), is(1)); | ||
assertThat(((Map) result.getBody().get(0)).get("kills"), is("22009")); | ||
assertThat(((Map) result.getBody().get(0)).get("name"), is("Amazon")); | ||
assertThat(((Map) result.getBody().get(0)).get("version"), is("8.6")); | ||
assertThat(((Map) result.getBody().get(0)).get("pageName"), is("Loot:Amazon")); | ||
} | ||
|
||
@Test | ||
void givenGetLootsByName_whenCorrectRequest_thenResponseIsOkAndContainsTheLoot() { | ||
doReturn(LOOT_AMAZON_TEXT).when(articleRepository).getArticle("Loot_Statistics:Amazon"); | ||
|
||
final ResponseEntity<String> result = restTemplate.getForEntity("/api/loot/Amazon", String.class); | ||
assertThat(result.getStatusCode(), is(HttpStatus.OK)); | ||
|
||
final JSONObject resultAsJSON = new JSONObject(result.getBody()); | ||
assertThat(resultAsJSON.get("kills"), is("22009")); | ||
assertThat(resultAsJSON.get("name"), is("Amazon")); | ||
assertThat(resultAsJSON.get("version"), is("8.6")); | ||
assertThat(resultAsJSON.get("pageName"), is("Loot_Statistics:Amazon")); | ||
} | ||
|
||
@Test | ||
void givenGetLootsByName_whenWrongRequest_thenResponseIsNotFound() { | ||
doReturn(null).when(articleRepository).getArticle("Loot:Foobar"); | ||
|
||
final ResponseEntity<String> result = restTemplate.getForEntity("/api/loot/Foobar", String.class); | ||
assertThat(result.getStatusCode(), is(HttpStatus.NOT_FOUND)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.