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

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:
run tests in branches:
stage: compile
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:
- 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
except:
- master
......@@ -18,8 +20,9 @@ publish snapshot artifacts:
before_script:
- echo "${GPG_KEY_SECRET}" | gpg --batch --import
- 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:
- 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
only:
- master
......@@ -30,8 +33,9 @@ publish artifacts to central:
before_script:
- echo "${GPG_KEY_SECRET}" | gpg --batch --import
- 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:
- 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
only:
- /^glis\-client\-/
......@@ -85,6 +85,12 @@
<version>2.2</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......
......@@ -16,17 +16,12 @@
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.auth.HttpBasicAuth;
import org.junit.BeforeClass;
public abstract class BaseApiTest {
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");
public abstract class BaseApiTest extends ProductionEnvironmentTest {
protected static ApiClient defaultClient;
......@@ -35,14 +30,14 @@ public abstract class BaseApiTest {
@BeforeClass
public static void config() {
defaultClient = new ApiClient();
if ("true".equals(System.getenv("GLIS_DEBUG"))) {
defaultClient.setDebugging(true);
}
defaultClient.setDebugging(isDebugging());
defaultClient.setBasePath(getBasePath());
// Configure HTTP basic authorization: glis_auth
HttpBasicAuth easySmtaAuth = (HttpBasicAuth) defaultClient.getAuthentication("easySmta");
easySmtaAuth.setUsername(GLIS_USERNAME);
easySmtaAuth.setUsername(getUsername());
System.out.println("Using GLIS username " + easySmtaAuth.getUsername());
easySmtaAuth.setPassword(GLIS_PASSWORD);
easySmtaAuth.setPassword(getPassword());
}
}
......@@ -16,8 +16,9 @@
package org.genesys.glis.v1.api;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import java.util.Arrays;
import java.util.List;
......@@ -48,15 +49,14 @@ public class QueryApiTest extends BaseApiTest {
String oper = null;
List<Relationship> response = queryApi.listRelationships(THE_DOI, role, oper);
// GLIS test environment is occasionally cleaned
// assertThat(response.size(), greaterThan(0));
assertThat(response.size(), equalTo(0));
}
/**
* GLIS vocabularies
*
* To describe the kind of information that will be found in the targets, GLIS adopts a simple controlled
* vocabulary.
* To describe the kind of information that will be found in the targets, GLIS
* adopts a simple controlled vocabulary.
*
* @throws ApiException if the Api call fails
*/
......@@ -77,7 +77,6 @@ public class QueryApiTest extends BaseApiTest {
public void searchTest() throws ApiException {
Integer page = null;
Integer perPage = null;
List<String> lang = null;
// String doi = null;
String identifier = null;
String genus = null;
......@@ -104,27 +103,23 @@ public class QueryApiTest extends BaseApiTest {
String biostatus = null;
String mlsstatus = 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,
provcountry, provenance, collwiews, collpid, collname, collcountry, bredwiews, bredpid, bredname, bredcountry, biostatus, mlsstatus, targetkw);
List<PGRFA> response = queryApi.search(page, perPage, null, THE_DOI, identifier, genus, species, name, holdwiews, holdpid, holdname, holdcountry, methodcode, provwiews,
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
*
* Multiple status values can be provided with comma separated strings
* List DOI Holders
*
* @throws ApiException if the Api call fails
*/
@Test
public void listDOIHolders() throws ApiException {
DOIArray dois=new DOIArray();
DOIArray dois = new DOIArray();
dois.addDoisItem(THE_DOI);
List<DOIHolder> response = queryApi.listHolders(dois);
// GLIS test environment is occasionally cleaned
// assertThat(response.size(), greaterThan(0));
assertThat(response.size(), equalTo(1));
}
}
/*
* 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 @@
<version>${gson-version}</version>
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......
......@@ -16,29 +16,25 @@
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.auth.HttpBasicAuth;
import org.junit.BeforeClass;
public abstract class BaseApiTest {
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");
public abstract class BaseApiTest extends ProductionEnvironmentTest {
protected static ApiClient defaultClient;
@BeforeClass
public static void config() {
defaultClient = new ApiClient();
if ("true".equals(System.getenv("GLIS_DEBUG"))) {
defaultClient.setDebugging(true);
}
defaultClient.setDebugging(isDebugging());
defaultClient.setBasePath(getBasePath());
// Configure HTTP basic authorization: glis_auth
HttpBasicAuth easySmtaAuth = (HttpBasicAuth) defaultClient.getAuthentication("easySmta");
easySmtaAuth.setUsername(GLIS_USERNAME);
easySmtaAuth.setUsername(getUsername());
System.out.println("Using GLIS username " + easySmtaAuth.getUsername());
easySmtaAuth.setPassword(GLIS_PASSWORD);
easySmtaAuth.setPassword(getPassword());
}
}
......@@ -16,8 +16,9 @@
package org.genesys.glis.v1.api;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import java.util.Arrays;
import java.util.List;
......@@ -38,15 +39,13 @@ public class QueryApiTest extends BaseApiTest {
/**
* Find passport data on PGRFA in GLIS
*
*
*
* @throws ApiException if the Api call fails
*/
@Test
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,
null, null, null);
assertThat(response.size(), greaterThan(0));
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);
assertThat(response.size(), equalTo(1));
}
/**
......@@ -62,15 +61,14 @@ public class QueryApiTest extends BaseApiTest {
String oper = null;
List<Relationship> response = api.listRelationships(THE_DOI, role, oper);
// GLIS test environment is occasionally cleaned
// assertThat(response.size(), greaterThan(0));
assertThat(response.size(), equalTo(0));
}
/**
* GLIS vocabularies
*
* To describe the kind of information that will be found in the targets, GLIS adopts a simple controlled
* vocabulary.
* To describe the kind of information that will be found in the targets, GLIS
* adopts a simple controlled vocabulary.
*
* @throws ApiException if the Api call fails
*/
......
......@@ -31,7 +31,7 @@
<invokerPackage>org.genesys.glis.v1.invoker</invokerPackage>
<output>${generated-sources-path}</output>
<configOptions>
<withXml>true</withXml>
<withXml>false</withXml>
<java8>true</java8>
<dateLibrary>java8</dateLibrary>
<sourceFolder>${generated-sources-java-path}</sourceFolder>
......
......@@ -42,6 +42,7 @@
</issueManagement>
<modules>
<module>tests</module>
<module>okhttp-gson</module>
<module>jersey2</module>
<module>resteasy</module>
......
......@@ -76,6 +76,12 @@
</dependency>
<!-- test dependencies -->
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
......
......@@ -16,29 +16,27 @@
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.auth.HttpBasicAuth;
import org.junit.BeforeClass;
public abstract class BaseApiTest {
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");
public abstract class BaseApiTest extends ProductionEnvironmentTest {
protected static ApiClient defaultClient;
@BeforeClass
public static void config() {
defaultClient = new ApiClient();
if ("true".equals(System.getenv("GLIS_DEBUG"))) {
defaultClient.setDebugging(true);
}
defaultClient.setDebugging(isDebugging());
defaultClient.setBasePath(getBasePath());
System.out.println("Using GLIS at " + defaultClient.getBasePath());
// Configure HTTP basic authorization: glis_auth
HttpBasicAuth easySmtaAuth = (HttpBasicAuth) defaultClient.getAuthentication("easySmta");
easySmtaAuth.setUsername(GLIS_USERNAME);
easySmtaAuth.setUsername(getUsername());
System.out.println("Using GLIS username " + easySmtaAuth.getUsername());
easySmtaAuth.setPassword(GLIS_PASSWORD);
easySmtaAuth.setPassword(getPassword());
}
}
......@@ -16,8 +16,9 @@
package org.genesys.glis.v1.api;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import java.util.List;
......@@ -49,15 +50,14 @@ public class QueryApiTest extends BaseApiTest {
String oper = null;
List<Relationship> response = api.listRelationships(THE_DOI, role, oper);
// GLIS test environment is occasionally cleaned
// assertThat(response.size(), greaterThan(0));
assertThat(response.size(), is(0));
}
/**
* GLIS vocabularies
*
* To describe the kind of information that will be found in the targets, GLIS adopts a simple controlled
* vocabulary.
* To describe the kind of information that will be found in the targets, GLIS
* adopts a simple controlled vocabulary.
*
* @throws ApiException if the Api call fails
*/
......@@ -105,10 +105,10 @@ public class QueryApiTest extends BaseApiTest {
String biostatus = null;
String mlsstatus = null;
String targetkw = null;
List<PGRFA> response = api.search(page, perPage, lang, THE_DOI, identifier, genus, species, name, holdwiews, holdpid, holdname, holdcountry, methodcode, provwiews, provpid, provname,
provcountry, provenance, collwiews, collpid, collname, collcountry, bredwiews, bredpid, bredname, bredcountry, biostatus, mlsstatus, targetkw);
List<PGRFA> response = api.search(page, perPage, lang, THE_DOI, identifier, genus, species, name, holdwiews, holdpid, holdname, holdcountry, methodcode, provwiews, provpid,
provname, provcountry, provenance, collwiews, collpid, collname, collcountry, bredwiews, bredpid, bredname, bredcountry, biostatus, mlsstatus, targetkw);
// assertThat(response.size(), greaterThan(0));
assertThat(response.size(), is(0));
}
}
......@@ -56,15 +56,10 @@
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
<version>${jackson-version}</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>${jodatime-version}</version>
</dependency>
<!-- XML processing: Jackson -->
<dependency>
......@@ -80,6 +75,12 @@
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.genesys-pgr</groupId>
<artifactId>glis-client-tests</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-library</artifactId>
......
......@@ -23,6 +23,7 @@ import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.dataformat.xml.ser.ToXmlGenerator;
import org.genesys.glis.test.ProductionEnvironmentTest;
import org.genesys.glis.v1.invoker.ApiClient;
import org.genesys.glis.v1.invoker.auth.HttpBasicAuth;
import org.junit.BeforeClass;
......@@ -32,13 +33,12 @@ import org.springframework.http.converter.json.MappingJackson2HttpMessageConvert
import org.springframework.http.converter.xml.MappingJackson2XmlHttpMessageConverter;
import org.springframework.web.client.RestTemplate;
public abstract class BaseApiTest {
public static final String GLIS_DOI_PATTERN = "^(doi:)?10\\.[0-9]+\\/[0123456789ABCDEFGHJKMNPQRSTVWXYZ]+[0123456789ABCDEFGHJKMNPQRSTVWXYZ~\\*\\$=U]$";
public static final String THE_DOI = "10.0155/11";
protected static String GLIS_USERNAME = System.getenv("GLIS_USERNAME");
protected static String GLIS_PASSWORD = System.getenv("GLIS_PASSWORD");
/**
* Tests against the production GLIS API at https://ssl.fao.org
*
* @author Matija Obreza
*/
public abstract class ProductionEnvironmentAPITest extends ProductionEnvironmentTest {
protected static ApiClient defaultClient;
......@@ -56,16 +56,17 @@ public abstract class BaseApiTest {
RestTemplate restTemplate = new RestTemplate(messageConverters);
restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(restTemplate.getRequestFactory()));
defaultClient = new ApiClient(restTemplate);
if ("true".equals(System.getenv("GLIS_DEBUG"))) {
defaultClient.setDebugging(true);
}
defaultClient.setDebugging(isDebugging());
defaultClient.setBasePath(getBasePath());
System.out.println("Using GLIS at " + defaultClient.getBasePath());
// Configure HTTP basic authorization: glis_auth
HttpBasicAuth easySmtaAuth = (HttpBasicAuth) defaultClient.getAuthentication("easySmta");
easySmtaAuth.setUsername(GLIS_USERNAME);
easySmtaAuth.setUsername(getUsername());
System.out.println("Using GLIS username " + easySmtaAuth.getUsername());
easySmtaAuth.setPassword(GLIS_PASSWORD);
easySmtaAuth.setPassword(getPassword());
}
}
......@@ -16,12 +16,15 @@
package org.genesys.glis.v1.api;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import java.util.Arrays;
import java.util.List;
import org.genesys.glis.v1.model.DOIArray;
import org.genesys.glis.v1.model.DOIHolder;
import org.genesys.glis.v1.model.PGRFA;
import org.genesys.glis.v1.model.Relationship;
import org.genesys.glis.v1.model.Term;
......@@ -30,7 +33,7 @@ import org.junit.Test;
/**
* API tests for QueryApi
*/
public class QueryApiTest extends BaseApiTest {
public class QueryApiTest extends ProductionEnvironmentAPITest {
private final QueryApi api = new QueryApi(defaultClient);
......@@ -47,15 +50,14 @@ public class QueryApiTest extends BaseApiTest {
String oper = null;
List<Relationship> response = api.listRelationships(THE_DOI, role, oper);
// GLIS test environment is occasionally cleaned
// assertThat(response.size(), greaterThan(0));
assertThat(response.size(), equalTo(0));
}
/**
* GLIS vocabularies
*