Commit 765656e6 authored by Maxym Borodenko's avatar Maxym Borodenko
Browse files

Draft: Junit tests against Sandbox server

parent 92b1cbaf
stages: stages:
- compile - compile
- test-oauth
- deploy - deploy
run tests in branches: run tests in branches:
...@@ -11,6 +12,15 @@ run tests in branches: ...@@ -11,6 +12,15 @@ run tests in branches:
- master - master
- /^genesys\-client\-api\-/ - /^genesys\-client\-api\-/
run tests for Sandbox:
stage: test-oauth
image: maven:3-jdk-8
- MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn test -B -Dtest=SandboxApiTest -Dbase.url=${BASE_URL} -Dclient.key=${CLIENT_KEY} -Dclient.secret=${CLIENT_SECRET}
- master
- /^genesys\-client\-api\-/
publish snapshot artifacts: publish snapshot artifacts:
stage: deploy stage: deploy
image: maven:3-jdk-8 image: maven:3-jdk-8
...@@ -69,6 +69,9 @@ ...@@ -69,6 +69,9 @@
<argLine>-Xms512m -Xmx1024m</argLine> <argLine>-Xms512m -Xmx1024m</argLine>
<useSystemClassLoader>false</useSystemClassLoader> <useSystemClassLoader>false</useSystemClassLoader>
<testFailureIgnore>false</testFailureIgnore> <testFailureIgnore>false</testFailureIgnore>
</configuration> </configuration>
</plugin> </plugin>
<plugin> <plugin>
* Copyright 2020 Global Crop Diversity Trust
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* See the License for the specific language governing permissions and
* limitations under the License.
package org.geneys2.client.oauth.sandbox;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.isEmptyOrNullString;
import static;
import java.util.HashMap;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.genesys2.client.oauth.GenesysApiException;
import org.genesys2.client.oauth.GenesysClient;
import org.genesys2.client.oauth.OAuthAuthenticationException;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.runners.MockitoJUnitRunner;
* @author Maxym Borodenko
public class SandboxApiTest {
/** The object mapper. */
private static final ObjectMapper objectMapper;
protected static GenesysClient genesysClient;
static {
objectMapper = new ObjectMapper();
public static void initGenesysClient() {
final String baseUrl = System.getProperty("base.url");
assertThat(baseUrl, not(isEmptyOrNullString()));
final String clientKey = System.getProperty("client.key");
assertThat(clientKey, not(isEmptyOrNullString()));
final String clientSecret = System.getProperty("client.secret");
assertThat(clientSecret, not(isEmptyOrNullString()));
genesysClient = new GenesysClient(baseUrl, clientKey, clientSecret, "oob", "write");
assertThat(genesysClient, notNullValue());
try {
final String accessToken = genesysClient.getTokens().getAccessToken();
assertThat(accessToken, not(isEmptyOrNullString()));
} catch (OAuthAuthenticationException e) {
fail("Failed while trying to authenticate: " + e.getMessage());
public void getMeTest() {
try {
String me =;
HashMap<String, Object> user = objectMapper.readValue(me, HashMap.class);
assertThat(user.get("sid"), is(equalTo(System.getProperty("client.key"))));
assertThat((int) user.get("id"), is(greaterThan(0)));
} catch (GenesysApiException e) {
fail("Failed while trying to fetch the profile.");
} catch (IOException e) {
fail("Failed while trying to parse the profile data: " + e.getMessage());
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment