diff --git a/.travis.yml b/.travis.yml index 9d93e7b..d0fcf6e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,51 @@ language: java - +#dist: trusty +#sudo: false jdk: - - openjdk9 + - openjdk9 +env: + - GH_URL=https://raw.githubusercontent.com VALIDATOR_URL=http://localhost:5050 URL_TO_VALIDATE=$GH_URL/$TRAVIS_REPO_SLUG/${TRAVIS_PULL_REQUEST_BRANCH:-$TRAVIS_BRANCH} + + +before_install: + skip +# - ./gradlew run +# - git clone https://github.com/NetworkedCoders/speech-rank.git +# - gradlew run +# - npm install +# - npm run gulp +# test1 + + + +script: + - ./gradlew tasks test + # apply plugin: 'java' + +# test { +# testLogging { +# events "failed" +# exceptionFormat "short" +# +# debug { +# events "started", "skipped", "failed" +# exceptionFormat "full" +# } +# info.events = ["failed", "skipped"] +# } +# } +# validate +# - echo "Validating $URL_TO_VALIDATE:" +# - VALIDATION_OUTPUT=`curl -sS "$VALIDATOR_URL=$URL_TO_VALIDATE"` +# +# # print validation errors +# - echo $VALIDATION_OUTPUT +# +# # check if the validation output is an empty array, i.e. no errors +# - test "$VALIDATION_OUTPUT" == "[]" + +after_failure: + skip +# -cat file:///home/travis/build/NetworkedCoders/speech-rank/build/reports/tests/test/index.html + + diff --git a/build.gradle b/build.gradle index 3bf15a8..9b848d2 100644 --- a/build.gradle +++ b/build.gradle @@ -32,6 +32,7 @@ dependencies { exclude module: "groovy-all" } implementation 'junit:junit:4.12' + implementation("com.squareup.okhttp3:okhttp:4.4.0") } diff --git a/src/test/java/com/github/speechrank/rest/GetConferencesTest.java b/src/test/java/com/github/speechrank/rest/GetConferencesTest.java new file mode 100644 index 0000000..93dfa19 --- /dev/null +++ b/src/test/java/com/github/speechrank/rest/GetConferencesTest.java @@ -0,0 +1,40 @@ +package com.github.speechrank.rest; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import org.junit.Test; + +import java.io.IOException; + +import static org.junit.Assert.assertEquals; + +public class GetConferencesTest { + + @Test + public void conferences() throws IOException { + OkHttpClient client = new OkHttpClient().newBuilder() + .build(); + Request request = new Request.Builder() + .url("http://localhost:5050/api/conferences") +// .url("$VALIDATOR_URL/api/conferences") + .method("GET", null) + .build(); + + System.out.println("testowySOUT"); + System.out.println("$VALIDATOR_URL"); +// System.out.println($VALIDATOR_URL); + Response response = client.newCall(request).execute(); + + //check is content-type is application/json +// assertEquals("text/html; charset=utf-8", response.header("content-type")); + + //check if status code is 200 + assertEquals(200, response.code()); + + //check responseBody + String responseBody = response.body().string(); + assertEquals("[{\"year\":\"2019\",\"conferences\":[{\"id\":\"12\",\"name\":\"DevConf\",\"presentations\":25},{\"id\":\"31\",\"name\":\"Boiling Frogs\",\"presentations\":25},{\"id\":\"41\",\"name\":\"Scalar\",\"presentations\":16},{\"id\":\"51\",\"name\":\"Confitura\",\"presentations\":25}]},{\"year\":\"2018\",\"conferences\":[{\"id\":\"21\",\"name\":\"Boiling Frogs\",\"presentations\":25},{\"id\":\"51\",\"name\":\"Confitura\",\"presentations\":25}]},{\"year\":\"2017\",\"conferences\":[{\"id\":\"11\",\"name\":\"DevConf\",\"presentations\":25}]}]", responseBody); + //TODO: powyzsza asercje napewno da sie ulepszyc, ale jeszcze nie wiem jak :) + } +}