Commit 9e63d667 authored by Maxym Borodenko's avatar Maxym Borodenko Committed by Matija Obreza
Browse files

Draft: Junit tests against Sandbox server

parent fe5db68a
Pipeline #16369 failed with stages
in 45 seconds
......@@ -9,6 +9,7 @@ variables:
stages:
- compile
- test-oauth
- deploy
run tests in branches:
......@@ -20,6 +21,15 @@ run tests in branches:
- master
- /^genesys\-client\-api\-/
run tests for Sandbox:
stage: test-oauth
image: maven:3-jdk-8
script:
- 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}
except:
- master
- /^genesys\-client\-api\-/
publish snapshot artifacts:
stage: deploy
image: maven:3-openjdk-11
......
......@@ -69,6 +69,9 @@
<argLine>-Xms512m -Xmx1024m</argLine>
<useSystemClassLoader>false</useSystemClassLoader>
<testFailureIgnore>false</testFailureIgnore>
<excludes>
<exclude>**/SandboxApiTest.java</exclude>
</excludes>
</configuration>
</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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* 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 org.junit.Assert.fail;
import java.io.IOException;
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
*/
@RunWith(MockitoJUnitRunner.class)
public class SandboxApiTest {
/** The object mapper. */
private static final ObjectMapper objectMapper;
protected static GenesysClient genesysClient;
static {
objectMapper = new ObjectMapper();
}
@BeforeClass
public static void initGenesysClient() {
final String baseUrl = System.getProperty("base.url");
assertThat("base.url is empty!", baseUrl, not(isEmptyOrNullString()));
final String clientKey = System.getProperty("client.key");
assertThat("client.key is empty!", clientKey, not(isEmptyOrNullString()));
final String clientSecret = System.getProperty("client.secret");
assertThat("client.secret is empty!", clientSecret, not(isEmptyOrNullString()));
genesysClient = new GenesysClient(baseUrl, clientKey, clientSecret, "oob", "write");
assertThat(genesysClient, notNullValue());
try {
genesysClient.authenticate();
final String accessToken = genesysClient.getTokens().getAccessToken();
assertThat(accessToken, not(isEmptyOrNullString()));
} catch (OAuthAuthenticationException e) {
fail("Failed while trying to authenticate: " + e.getMessage());
}
}
@Test
public void getMeTest() {
try {
String me = genesysClient.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());
}
}
}
Markdown is supported
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