Commit 5fa04f96 authored by Matija Obreza's avatar Matija Obreza
Browse files

Merge branch '24-json-only-client' into 'master'

Resolve "JSON-only client"

Closes #24

See merge request genesys-pgr/glis-client!16
parents e9e8126c c45367d0
...@@ -5,8 +5,10 @@ stages: ...@@ -5,8 +5,10 @@ stages:
run tests in branches: run tests in branches:
stage: compile stage: compile
image: maven:3-jdk-8 image: maven:3-jdk-8
before_script:
- echo "Using username ${GLISTEST_USERNAME} for authentication against https://glistest.planttreaty.org"
- echo "Using username ${GLIS_USERNAME} for authentication against https://ssl.fao.org"
script: script:
- echo "Using username ${GLIS_USERNAME} for authentication against https://glistest.planttreaty.org"
- MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn test -B -U -DskipTests=false - MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn test -B -U -DskipTests=false
except: except:
- master - master
...@@ -18,8 +20,9 @@ publish snapshot artifacts: ...@@ -18,8 +20,9 @@ publish snapshot artifacts:
before_script: before_script:
- echo "${GPG_KEY_SECRET}" | gpg --batch --import - echo "${GPG_KEY_SECRET}" | gpg --batch --import
- gpg --list-keys - gpg --list-keys
- echo "Using username ${GLISTEST_USERNAME} for authentication against https://glistest.planttreaty.org"
- echo "Using username ${GLIS_USERNAME} for authentication against https://ssl.fao.org"
script: script:
- echo "Using username ${GLIS_USERNAME} for authentication against https://glistest.planttreaty.org"
- MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn clean deploy -B -U --settings .ci-maven-settings.xml -B -U -DskipTests=false - MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn clean deploy -B -U --settings .ci-maven-settings.xml -B -U -DskipTests=false
only: only:
- master - master
...@@ -30,8 +33,9 @@ publish artifacts to central: ...@@ -30,8 +33,9 @@ publish artifacts to central:
before_script: before_script:
- echo "${GPG_KEY_SECRET}" | gpg --batch --import - echo "${GPG_KEY_SECRET}" | gpg --batch --import
- gpg --list-keys - gpg --list-keys
- echo "Using username ${GLISTEST_USERNAME} for authentication against https://glistest.planttreaty.org"
- echo "Using username ${GLIS_USERNAME} for authentication against https://ssl.fao.org"
script: script:
- echo "Using username ${GLIS_USERNAME} for authentication against https://glistest.planttreaty.org"
- MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn -P release clean deploy --settings .ci-maven-settings.xml -B -U -DskipTests=false - MAVEN_OPTS="${MAVEN_OPTS} -Dorg.slf4j.simpleLogger.defaultLogLevel=warn" mvn -P release clean deploy --settings .ci-maven-settings.xml -B -U -DskipTests=false
only: only:
- /^glis\-client\-/ - /^glis\-client\-/
...@@ -85,6 +85,12 @@ ...@@ -85,6 +85,12 @@
<version>2.2</version> <version>2.2</version>
</dependency> </dependency>
<!-- test dependencies --> <!-- test dependencies -->
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
......
...@@ -16,17 +16,12 @@ ...@@ -16,17 +16,12 @@
package org.genesys.glis.v1.api; package org.genesys.glis.v1.api;
import org.genesys.glis.test.ProductionEnvironmentTest;
import org.genesys.glis.v1.invoker.ApiClient; import org.genesys.glis.v1.invoker.ApiClient;
import org.genesys.glis.v1.invoker.auth.HttpBasicAuth; import org.genesys.glis.v1.invoker.auth.HttpBasicAuth;
import org.junit.BeforeClass; import org.junit.BeforeClass;
public abstract class BaseApiTest { public abstract class BaseApiTest extends ProductionEnvironmentTest {
public static final String GLIS_DOI_PATTERN = "^(doi:)?10\\.[0-9]+\\/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]+[0123456789ABCDEFGHJKMNPQRSTVWXYZ~\\*\\$=U]$";
public static final String THE_DOI = "10.0155/AA";
protected static String GLIS_USERNAME = System.getenv("GLIS_USERNAME");
protected static String GLIS_PASSWORD = System.getenv("GLIS_PASSWORD");
protected static ApiClient defaultClient; protected static ApiClient defaultClient;
...@@ -35,14 +30,14 @@ public abstract class BaseApiTest { ...@@ -35,14 +30,14 @@ public abstract class BaseApiTest {
@BeforeClass @BeforeClass
public static void config() { public static void config() {
defaultClient = new ApiClient(); defaultClient = new ApiClient();
if ("true".equals(System.getenv("GLIS_DEBUG"))) { defaultClient.setDebugging(isDebugging());
defaultClient.setDebugging(true); defaultClient.setBasePath(getBasePath());
}
// Configure HTTP basic authorization: glis_auth // Configure HTTP basic authorization: glis_auth
HttpBasicAuth easySmtaAuth = (HttpBasicAuth) defaultClient.getAuthentication("easySmta"); HttpBasicAuth easySmtaAuth = (HttpBasicAuth) defaultClient.getAuthentication("easySmta");
easySmtaAuth.setUsername(GLIS_USERNAME); easySmtaAuth.setUsername(getUsername());
System.out.println("Using GLIS username " + easySmtaAuth.getUsername()); System.out.println("Using GLIS username " + easySmtaAuth.getUsername());
easySmtaAuth.setPassword(GLIS_PASSWORD); easySmtaAuth.setPassword(getPassword());
} }
} }
...@@ -16,8 +16,9 @@ ...@@ -16,8 +16,9 @@
package org.genesys.glis.v1.api; package org.genesys.glis.v1.api;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.*; import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -48,15 +49,14 @@ public class QueryApiTest extends BaseApiTest { ...@@ -48,15 +49,14 @@ public class QueryApiTest extends BaseApiTest {
String oper = null; String oper = null;
List<Relationship> response = queryApi.listRelationships(THE_DOI, role, oper); List<Relationship> response = queryApi.listRelationships(THE_DOI, role, oper);
// GLIS test environment is occasionally cleaned assertThat(response.size(), equalTo(0));
// assertThat(response.size(), greaterThan(0));
} }
/** /**
* GLIS vocabularies * GLIS vocabularies
* *
* To describe the kind of information that will be found in the targets, GLIS adopts a simple controlled * To describe the kind of information that will be found in the targets, GLIS
* vocabulary. * adopts a simple controlled vocabulary.
* *
* @throws ApiException if the Api call fails * @throws ApiException if the Api call fails
*/ */
...@@ -77,7 +77,6 @@ public class QueryApiTest extends BaseApiTest { ...@@ -77,7 +77,6 @@ public class QueryApiTest extends BaseApiTest {
public void searchTest() throws ApiException { public void searchTest() throws ApiException {
Integer page = null; Integer page = null;
Integer perPage = null; Integer perPage = null;
List<String> lang = null;
// String doi = null; // String doi = null;
String identifier = null; String identifier = null;
String genus = null; String genus = null;
...@@ -104,27 +103,23 @@ public class QueryApiTest extends BaseApiTest { ...@@ -104,27 +103,23 @@ public class QueryApiTest extends BaseApiTest {
String biostatus = null; String biostatus = null;
String mlsstatus = null; String mlsstatus = null;
String targetkw = null; String targetkw = null;
List<PGRFA> response = queryApi.search(page, perPage, null, THE_DOI, identifier, genus, species, name, holdwiews, holdpid, holdname, holdcountry, methodcode, provwiews, provpid, provname, List<PGRFA> response = queryApi.search(page, perPage, null, THE_DOI, identifier, genus, species, name, holdwiews, holdpid, holdname, holdcountry, methodcode, provwiews,
provcountry, provenance, collwiews, collpid, collname, collcountry, bredwiews, bredpid, bredname, bredcountry, biostatus, mlsstatus, targetkw); provpid, provname, provcountry, provenance, collwiews, collpid, collname, collcountry, bredwiews, bredpid, bredname, bredcountry, biostatus, mlsstatus, targetkw);
// assertThat(response.size(), greaterThan(0)); assertThat(response.size(), equalTo(1));
} }
/** /**
* Get PGRFA relationships * List DOI Holders
*
* Multiple status values can be provided with comma separated strings
* *
* @throws ApiException if the Api call fails * @throws ApiException if the Api call fails
*/ */
@Test @Test
public void listDOIHolders() throws ApiException { public void listDOIHolders() throws ApiException {
DOIArray dois=new DOIArray(); DOIArray dois = new DOIArray();
dois.addDoisItem(THE_DOI); dois.addDoisItem(THE_DOI);
List<DOIHolder> response = queryApi.listHolders(dois); List<DOIHolder> response = queryApi.listHolders(dois);
// GLIS test environment is occasionally cleaned assertThat(response.size(), equalTo(1));
// assertThat(response.size(), greaterThan(0));
} }
} }
/*
* Copyright 2017 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.genesys.glis.v1.api;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.genesys.glis.v1.invoker.ApiException;
import org.genesys.glis.v1.model.Acquisition;
import org.genesys.glis.v1.model.Actor;
import org.genesys.glis.v1.model.Collection;
import org.genesys.glis.v1.model.Collector;
import org.genesys.glis.v1.model.Location;
import org.genesys.glis.v1.model.Registration;
import org.genesys.glis.v1.model.RegistrationResponse;
import org.genesys.glis.v1.model.Relationship;
import org.junit.Ignore;
import org.junit.Test;
/**
* API tests for ManagerApi
*/
@Ignore
public class RegistrationApiTest extends BaseApiTest {
private final ManagerApi api = new ManagerApi(defaultClient);
/**
* Register PGRFA in GLIS
*
* @throws ApiException if the Api call fails
*/
@Test
public void registerPGRFA() throws ApiException {
Registration pgrfa = makePGRFA("Matija", "Matija ");
RegistrationResponse response = api.registerPGRFA(pgrfa);
assertThat(response.getError(), is(nullValue()));
assertThat(response.getSampleid(), is(pgrfa.getSampleid()));
assertThat(response.getGenus(), is(pgrfa.getGenus()));
assertThat(response.getDoi(), not(nullValue()));
assertTrue("GLIS did not return a valid DOI", response.getDoi().matches(GLIS_DOI_PATTERN));
}
public Registration makePGRFA(String cropName, String prefix) {
Registration pgrfa = new Registration();
pgrfa.setUsername(GLIS_USERNAME);
pgrfa.setPassword(GLIS_PASSWORD);
SimpleDateFormat df = new SimpleDateFormat("YYYY-MM-dd");
pgrfa.setDate(df.format(new Date()));
pgrfa.addCropnamesItem(cropName);
pgrfa.setSampleid(prefix + System.currentTimeMillis());
pgrfa.setMethod("obna");
Location location = new Location();
location.setWiews("NLD037");
pgrfa.setLocation(location);
return pgrfa;
}
@Test
public void relsTest() throws ApiException {
Registration pgrfa1 = makePGRFA("Matija", "Matija ");
RegistrationResponse response1 = api.registerPGRFA(pgrfa1);
assertThat(response1.getDoi(), not(nullValue()));
Registration pgrfa2 = makePGRFA("Matija", "Matija ").method("nodi");
pgrfa2.addProgdoiItem(response1.getDoi()).addProgdoiItem(response1.getDoi());
RegistrationResponse response2 = api.registerPGRFA(pgrfa2);
assertThat(response2.getDoi(), not(nullValue()));
List<Relationship> rels = queryApi.listRelationships(response1.getDoi(), null, null);
assertThat(rels.size(), greaterThan(0));
}
@Test
public void testAcquisition() throws ApiException {
Registration pgrfa = makePGRFA("Matija", "Matija ").method("acqu").acquisition(new Acquisition().provenance("SVN").provider(new Actor().name("Genesys GLIS Tool").country("DEU")))
.date("2017-07-23");
RegistrationResponse response = api.registerPGRFA(pgrfa);
assertThat(response.getDoi(), not(nullValue()));
}
@Test
public void testCollection() throws ApiException {
Registration pgrfa = makePGRFA("Matija", "Matija ").method("acqu").collection(new Collection().date("2017-07-23").elevation(100).missid("Genesys GLIS"));
RegistrationResponse response = api.registerPGRFA(pgrfa);
assertThat(response.getDoi(), not(nullValue()));
}
@Test
public void testCollectionCollector() throws ApiException {
Registration pgrfa = makePGRFA("Matija", "Matija ").method("acqu")
.collection(new Collection().date("2017-07-23").elevation(100).missid("Genesys GLIS").addCollectorsItem(new Collector().name("Matija Obreza").country("SVN")));
RegistrationResponse response = api.registerPGRFA(pgrfa);
assertThat(response.getDoi(), not(nullValue()));
}
}
...@@ -42,6 +42,12 @@ ...@@ -42,6 +42,12 @@
<version>${gson-version}</version> <version>${gson-version}</version>
</dependency> </dependency>
<!-- test dependencies --> <!-- test dependencies -->
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
......
...@@ -16,29 +16,25 @@ ...@@ -16,29 +16,25 @@
package org.genesys.glis.v1.api; package org.genesys.glis.v1.api;
import org.genesys.glis.test.ProductionEnvironmentTest;
import org.genesys.glis.v1.invoker.ApiClient; import org.genesys.glis.v1.invoker.ApiClient;
import org.genesys.glis.v1.invoker.auth.HttpBasicAuth; import org.genesys.glis.v1.invoker.auth.HttpBasicAuth;
import org.junit.BeforeClass; import org.junit.BeforeClass;
public abstract class BaseApiTest { public abstract class BaseApiTest extends ProductionEnvironmentTest {
public static final String THE_DOI = "10.0155/AA";
protected static String GLIS_USERNAME = System.getenv("GLIS_USERNAME");
protected static String GLIS_PASSWORD = System.getenv("GLIS_PASSWORD");
protected static ApiClient defaultClient; protected static ApiClient defaultClient;
@BeforeClass @BeforeClass
public static void config() { public static void config() {
defaultClient = new ApiClient(); defaultClient = new ApiClient();
if ("true".equals(System.getenv("GLIS_DEBUG"))) { defaultClient.setDebugging(isDebugging());
defaultClient.setDebugging(true); defaultClient.setBasePath(getBasePath());
}
// Configure HTTP basic authorization: glis_auth // Configure HTTP basic authorization: glis_auth
HttpBasicAuth easySmtaAuth = (HttpBasicAuth) defaultClient.getAuthentication("easySmta"); HttpBasicAuth easySmtaAuth = (HttpBasicAuth) defaultClient.getAuthentication("easySmta");
easySmtaAuth.setUsername(GLIS_USERNAME); easySmtaAuth.setUsername(getUsername());
System.out.println("Using GLIS username " + easySmtaAuth.getUsername()); System.out.println("Using GLIS username " + easySmtaAuth.getUsername());
easySmtaAuth.setPassword(GLIS_PASSWORD); easySmtaAuth.setPassword(getPassword());
} }
} }
...@@ -16,8 +16,9 @@ ...@@ -16,8 +16,9 @@
package org.genesys.glis.v1.api; package org.genesys.glis.v1.api;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.*; import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
...@@ -38,15 +39,13 @@ public class QueryApiTest extends BaseApiTest { ...@@ -38,15 +39,13 @@ public class QueryApiTest extends BaseApiTest {
/** /**
* Find passport data on PGRFA in GLIS * Find passport data on PGRFA in GLIS
* *
*
*
* @throws ApiException if the Api call fails * @throws ApiException if the Api call fails
*/ */
@Test @Test
public void findPgrfaTest() throws ApiException { public void findPgrfaTest() throws ApiException {
List<PGRFA> response = api.search(null, null, null, THE_DOI, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, List<PGRFA> response = api.search(null, null, null, THE_DOI, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null,
null, null, null); null, null, null, null, null, null);
assertThat(response.size(), greaterThan(0)); assertThat(response.size(), equalTo(1));
} }
/** /**
...@@ -62,15 +61,14 @@ public class QueryApiTest extends BaseApiTest { ...@@ -62,15 +61,14 @@ public class QueryApiTest extends BaseApiTest {
String oper = null; String oper = null;
List<Relationship> response = api.listRelationships(THE_DOI, role, oper); List<Relationship> response = api.listRelationships(THE_DOI, role, oper);
// GLIS test environment is occasionally cleaned assertThat(response.size(), equalTo(0));
// assertThat(response.size(), greaterThan(0));
} }
/** /**
* GLIS vocabularies * GLIS vocabularies
* *
* To describe the kind of information that will be found in the targets, GLIS adopts a simple controlled * To describe the kind of information that will be found in the targets, GLIS
* vocabulary. * adopts a simple controlled vocabulary.
* *
* @throws ApiException if the Api call fails * @throws ApiException if the Api call fails
*/ */
......
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
<invokerPackage>org.genesys.glis.v1.invoker</invokerPackage> <invokerPackage>org.genesys.glis.v1.invoker</invokerPackage>
<output>${generated-sources-path}</output> <output>${generated-sources-path}</output>
<configOptions> <configOptions>
<withXml>true</withXml> <withXml>false</withXml>
<java8>true</java8> <java8>true</java8>
<dateLibrary>java8</dateLibrary> <dateLibrary>java8</dateLibrary>
<sourceFolder>${generated-sources-java-path}</sourceFolder> <sourceFolder>${generated-sources-java-path}</sourceFolder>
......
...@@ -42,6 +42,7 @@ ...@@ -42,6 +42,7 @@
</issueManagement> </issueManagement>
<modules> <modules>
<module>tests</module>
<module>okhttp-gson</module> <module>okhttp-gson</module>
<module>jersey2</module> <module>jersey2</module>
<module>resteasy</module> <module>resteasy</module>
......
...@@ -76,6 +76,12 @@ ...@@ -76,6 +76,12 @@
</dependency> </dependency>
<!-- test dependencies --> <!-- test dependencies -->
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
......
...@@ -16,29 +16,27 @@ ...@@ -16,29 +16,27 @@
package org.genesys.glis.v1.api; package org.genesys.glis.v1.api;
import org.genesys.glis.test.ProductionEnvironmentTest;
import org.genesys.glis.v1.invoker.ApiClient; import org.genesys.glis.v1.invoker.ApiClient;
import org.genesys.glis.v1.invoker.auth.HttpBasicAuth; import org.genesys.glis.v1.invoker.auth.HttpBasicAuth;
import org.junit.BeforeClass; import org.junit.BeforeClass;
public abstract class BaseApiTest { public abstract class BaseApiTest extends ProductionEnvironmentTest {
public static final String THE_DOI = "10.0155/AA";
protected static String GLIS_USERNAME = System.getenv("GLIS_USERNAME");
protected static String GLIS_PASSWORD = System.getenv("GLIS_PASSWORD");
protected static ApiClient defaultClient; protected static ApiClient defaultClient;
@BeforeClass @BeforeClass
public static void config() { public static void config() {
defaultClient = new ApiClient(); defaultClient = new ApiClient();
if ("true".equals(System.getenv("GLIS_DEBUG"))) { defaultClient.setDebugging(isDebugging());
defaultClient.setDebugging(true); defaultClient.setBasePath(getBasePath());
}
System.out.println("Using GLIS at " + defaultClient.getBasePath());
// Configure HTTP basic authorization: glis_auth // Configure HTTP basic authorization: glis_auth
HttpBasicAuth easySmtaAuth = (HttpBasicAuth) defaultClient.getAuthentication("easySmta"); HttpBasicAuth easySmtaAuth = (HttpBasicAuth) defaultClient.getAuthentication("easySmta");
easySmtaAuth.setUsername(GLIS_USERNAME); easySmtaAuth.setUsername(getUsername());
System.out.println("Using GLIS username " + easySmtaAuth.getUsername()); System.out.println("Using GLIS username " + easySmtaAuth.getUsername());
easySmtaAuth.setPassword(GLIS_PASSWORD); easySmtaAuth.setPassword(getPassword());
} }
} }
...@@ -16,8 +16,9 @@ ...@@ -16,8 +16,9 @@
package org.genesys.glis.v1.api; package org.genesys.glis.v1.api;
import static org.hamcrest.Matchers.*; import static org.hamcrest.Matchers.greaterThan;
import static org.junit.Assert.*;