Commit d7fe2da1 authored by Matija Obreza's avatar Matija Obreza

Use API v1 endpoints

parent 58d9733a
Pipeline #7739 passed with stage
in 27 seconds
This diff is collapsed.
/*
* Copyright 2016 Global Crop Diversity Trust
* Copyright 2018 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.
......@@ -32,16 +32,16 @@ public class AccessionJson {
private Long genesysId;
/** The puid. */
@JsonProperty(value = Accession.PUID)
private String puid;
@JsonProperty(value = Accession.DOI)
private String doi;
/** The inst code. */
@JsonProperty(value = Accession.INSTCODE)
private String instCode;
private String instituteCode;
/** The acce numb. */
@JsonProperty(value = Accession.ACCENUMB)
private String acceNumb;
private String accessionNumber;
/** The new acce numb. */
@JsonProperty(value = Accession.ACCENUMB_NEW)
......@@ -81,7 +81,7 @@ public class AccessionJson {
/** The acq date. */
@JsonProperty(value = Accession.ACQDATE)
private String acqDate;
private String acquisitionDate;
/** The mls stat. */
@JsonProperty(value = Accession.MLSSTAT)
......@@ -109,7 +109,11 @@ public class AccessionJson {
/** The bred code. */
@JsonProperty(value = Accession.BREDCODE)
private String[] bredCode;
private String[] breederCode;
/** The bred code. */
@JsonProperty(value = Accession.BREDNAME)
private String[] breederName;
/** The ancest. */
@JsonProperty(value = Accession.ANCEST)
......@@ -205,56 +209,49 @@ public class AccessionJson {
* @return the puid
*/
public String getPuid() {
return puid;
}
/**
* @param puid the puid to set
*/
public void setPuid(String puid) {
this.puid = puid;
return doi;
}
/**
* Gets the inst code.
* Gets the FAO WIEWS institute code.
*
* @return the inst code
*/
public String getInstCode() {
return instCode;
public String getInstituteCode() {
return instituteCode;
}
/**
* Sets the inst code.
*
* @param instCode the new inst code
* @param instituteCode the new inst code
*/
public void setInstCode(final String instCode) {
this.instCode = instCode;
public void setInstituteCode(final String instituteCode) {
this.instituteCode = instituteCode;
}
/**
* Gets the acce numb.
* Gets the accession number.
*
* @return the acce numb
* @return the accession number
*/
public String getAcceNumb() {
return acceNumb;
public String getAccessionNumber() {
return accessionNumber;
}
/**
* Sets the acce numb.
* Sets the accession number.
*
* @param acceNumb the new acce numb
* @param accessionNumber the new accession number
*/
public void setAcceNumb(final String acceNumb) {
this.acceNumb = acceNumb;
public void setAccessionNumber(String accessionNumber) {
this.accessionNumber = accessionNumber;
}
/**
* Gets the new acce numb.
* Gets the new accession number.
*
* @return the new acce numb
* @return the new accession number
*/
public String getNewAcceNumb() {
return newAcceNumb;
......@@ -414,21 +411,21 @@ public class AccessionJson {
}
/**
* Gets the acq date.
* Gets the acquisition date.
*
* @return the acq date
* @return the acquisition date
*/
public String getAcqDate() {
return acqDate;
public String getAcquisitionDate() {
return acquisitionDate;
}
/**
* Sets the acq date.
* Sets the acquisition date.
*
* @param acqDate the new acq date
* @param acquisitionDate the new acquisition date
*/
public void setAcqDate(final String acqDate) {
this.acqDate = acqDate;
public void setAcquisitionDate(String acquisitionDate) {
this.acquisitionDate = acquisitionDate;
}
/**
......@@ -545,7 +542,7 @@ public class AccessionJson {
* @return the bred code
*/
public String[] getBredCode() {
return bredCode;
return breederCode;
}
/**
......@@ -554,7 +551,7 @@ public class AccessionJson {
* @param bredCode the new bred code
*/
public void setBredCode(final String[] bredCode) {
this.bredCode = bredCode;
this.breederCode = bredCode;
}
/**
......
......@@ -40,12 +40,12 @@ public interface Api1Constants {
/**
* WIEWS code of accession holding institute.
*/
public static final String INSTCODE = "instCode";
public static final String INSTCODE = "instituteCode";
/**
* Accession number.
*/
public static final String ACCENUMB = "acceNumb";
public static final String ACCENUMB = "accessionNumber";
/** Used to assign new ACCENUMB. */
public static final String ACCENUMB_NEW = "newAcceNumb";
......@@ -84,13 +84,13 @@ public interface Api1Constants {
/**
* ISO3 country code of country of origin.
*/
public static final String ORIGCTY = "orgCty";
public static final String ORIGCTY = "origCty";
/**
* Date on which the accession entered the collection as YYYYMMDD. Missing data (MM or DD)
* should be indicated with hyphens. Leading zeros are required.
*/
public static final String ACQDATE = "acqDate";
public static final String ACQDATE = "acquisitionDate";
/**
* The status of an accession with regards to the Multilateral System (MLS) of the
......@@ -123,7 +123,12 @@ public interface Api1Constants {
/**
* Corresponds to BREDCODE.
*/
public static final String BREDCODE = "bredCode";
public static final String BREDCODE = "breederCode";
/**
* Corresponds to BREDNAME.
*/
public static final String BREDNAME = "breederName";
/**
* Corresponds to ANCEST.
......
......@@ -17,20 +17,14 @@
package org.geneys2.client.oauth;
import static org.hamcrest.CoreMatchers.*;
import static org.hamcrest.MatcherAssert.*;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.when;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import org.genesys2.client.oauth.GenesysApiException;
import org.genesys2.client.oauth.GenesysClient;
import org.genesys2.client.oauth.OAuthAuthenticationException;
......@@ -44,9 +38,14 @@ import org.mockito.Matchers;
import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner;
// TODO: Auto-generated Javadoc
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
/**
* The Class AccessionApiTest.
* Accession API v1 test
*/
@RunWith(MockitoJUnitRunner.class)
public class AccessionApiTest {
......@@ -59,7 +58,7 @@ public class AccessionApiTest {
protected GenesysClient genesysClient;
/** The inst code. */
private final String instCode = "INS000";
private final String instituteCode = "INS000";
/** The mock server. */
private final MockGenesysServer mockServer = new MockGenesysServer();
......@@ -99,7 +98,7 @@ public class AccessionApiTest {
@Test
public void testAccessions0() throws OAuthAuthenticationException, PleaseRetryException, GenesysApiException, JsonProcessingException, IOException {
final List<AccessionJson> results = objectMapper.readValue(genesysClient.listAccessions(instCode, 1, null), new TypeReference<List<AccessionJson>>() {
final List<AccessionJson> results = objectMapper.readValue(genesysClient.listAccessions(instituteCode, 1, null), new TypeReference<List<AccessionJson>>() {
});
assertThat("Expected empty list", results.size(), is(0));
......@@ -117,14 +116,14 @@ public class AccessionApiTest {
@Test
public void testAccessions1() throws OAuthAuthenticationException, PleaseRetryException, GenesysApiException, JsonProcessingException, IOException {
when(genesysClient.listAccessions(instCode, 1, null)).thenReturn("[{\"instCode\":\"INS000\",\"acceNumb\":\"ACC-1\"}]");
when(genesysClient.listAccessions(instituteCode, 1, null)).thenReturn("[{\"instituteCode\":\"INS000\",\"accessionNumber\":\"ACC-1\"}]");
final List<AccessionJson> results = objectMapper.readValue(genesysClient.listAccessions(instCode, 1, null), new TypeReference<List<AccessionJson>>() {
final List<AccessionJson> results = objectMapper.readValue(genesysClient.listAccessions(instituteCode, 1, null), new TypeReference<List<AccessionJson>>() {
});
assertThat("Expected empty list", results.size(), is(1));
final AccessionJson acc1 = results.get(0);
assertThat("INSTCODE doesn't match", acc1.getInstCode(), is(instCode));
assertThat("INSTCODE doesn't match", acc1.getInstituteCode(), is(instituteCode));
acc1.setHistoric(true);
......@@ -143,7 +142,7 @@ public class AccessionApiTest {
@Test
public void testUpsertAccessions1() throws OAuthAuthenticationException, PleaseRetryException, GenesysApiException, JsonProcessingException, IOException, InterruptedException {
String result = genesysClient.listAccessions(instCode, 1, null);
String result = genesysClient.listAccessions(instituteCode, 1, null);
assertThat("Non-null result expected from genesysClient", result, notNullValue());
List<AccessionJson> results = objectMapper.readValue(result, new TypeReference<List<AccessionJson>>() {
});
......@@ -154,23 +153,23 @@ public class AccessionApiTest {
for (int i = 0; i < 4; i++) {
final AccessionJson aj = new AccessionJson();
aj.setInstCode(instCode);
aj.setAcceNumb("ACC-" + (i + 1));
aj.setInstituteCode(instituteCode);
aj.setAccessionNumber("ACC-" + (i + 1));
aj.setGenus("Genus");
ajList.add(aj);
}
result = genesysClient.updateAccessions(instCode, ajList);
result = genesysClient.updateAccessions(instituteCode, ajList);
System.err.println(result);
results = objectMapper.readValue(genesysClient.listAccessions(instCode, 1, null), new TypeReference<List<AccessionJson>>() {
results = objectMapper.readValue(genesysClient.listAccessions(instituteCode, 1, null), new TypeReference<List<AccessionJson>>() {
});
assertThat("Expected list with 4 entries", results.size(), is(4));
for (final AccessionJson aj1 : results) {
assertThat("Expected matching INSTCODE", aj1.getInstCode(), is(instCode));
assertThat("Expected ACCENUMB starting with", aj1.getAcceNumb(), CoreMatchers.startsWith("ACC-"));
assertThat("Expected matching INSTCODE", aj1.getInstituteCode(), is(instituteCode));
assertThat("Expected ACCENUMB starting with", aj1.getAccessionNumber(), CoreMatchers.startsWith("ACC-"));
assertThat("Expected GENUS=Genus", aj1.getGenus(), is("Genus"));
assertThat("Expected SPECIES=null", aj1.getSpecies(), nullValue());
}
......
......@@ -51,7 +51,6 @@ import org.mockito.invocation.InvocationOnMock;
import org.mockito.runners.MockitoJUnitRunner;
import org.mockito.stubbing.Answer;
// TODO: Auto-generated Javadoc
/**
* The Class ApiTest.
*/
......@@ -105,95 +104,6 @@ public class ApiTest {
MockitoAnnotations.initMocks(this);
when(httpGetMock.getMethod()).thenReturn("GET");
when(httpPostMock.getMethod()).thenReturn("POST");
when(genesysClient.getCrop("banana")).thenReturn(bananaJson);
}
/**
* Test mock get crop.
*
* @throws OAuthAuthenticationException the o auth authentication exception
* @throws PleaseRetryException the please retry exception
* @throws GenesysApiException the genesys api exception
* @throws JsonProcessingException the json processing exception
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
public void testMockGetCrop() throws OAuthAuthenticationException, PleaseRetryException, GenesysApiException, JsonProcessingException, IOException {
final String json = genesysClient.getCrop("banana");
assertThat("Returned banana JSON doesn't match", json, equalTo(bananaJson));
// Must be able to read the json
objectMapper.readTree(json);
}
/**
* Test mock update crop.
*
* @throws OAuthAuthenticationException the o auth authentication exception
* @throws PleaseRetryException the please retry exception
* @throws GenesysApiException the genesys api exception
* @throws JsonProcessingException the json processing exception
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
public void testMockUpdateCrop() throws OAuthAuthenticationException, PleaseRetryException, GenesysApiException, JsonProcessingException, IOException {
final String json = genesysClient.getCrop("banana");
assertThat("Returned banana JSON doesn't match", json, equalTo(bananaJson));
// Must be able to read the json
objectMapper.readTree(json);
}
/**
* Test organization members.
*
* @throws OAuthAuthenticationException the o auth authentication exception
* @throws PleaseRetryException the please retry exception
* @throws GenesysApiException the genesys api exception
* @throws JsonProcessingException the json processing exception
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
public void testOrganizationMembers() throws OAuthAuthenticationException, PleaseRetryException, GenesysApiException, JsonProcessingException, IOException {
final String orgSlug = "org";
when(genesysClient.getOrganizationMembers(orgSlug)).then(returnOrganizationMembers(orgSlug));
final String members = genesysClient.getOrganizationMembers(orgSlug);
objectMapper.readTree(members);
System.err.println(members);
}
/**
* Return organization members.
*
* @param orgSlug the org slug
* @return the answer
*/
private Answer<String> returnOrganizationMembers(final String orgSlug) {
return new Answer<String>() {
@Override
public String answer(final InvocationOnMock invocation) throws Throwable {
return "[\"ORG1\",\"ORG2\"]";
}
};
}
/**
* Test please retry exception.
*
* @throws OAuthAuthenticationException the o auth authentication exception
* @throws PleaseRetryException the please retry exception
* @throws GenesysApiException the genesys api exception
* @throws JsonProcessingException the json processing exception
*/
@SuppressWarnings("deprecation")
@Test(expected = PleaseRetryException.class)
public void testPleaseRetryException() throws OAuthAuthenticationException, PleaseRetryException, GenesysApiException, JsonProcessingException {
when(genesysClient.updateMLS("INS000", null)).thenThrow(PleaseRetryException.class);
genesysClient.updateMLS("INS000", null);
}
/**
......
......@@ -70,12 +70,12 @@ public class MockGenesysServer {
if (args[2] != null) {
throw new MockGenesysException("Querying is not supported.");
}
final String instCode = (String) args[0];
final String instituteCode = (String) args[0];
final int page = (Integer) args[1];
System.err.println("Listing accessions instCode=" + instCode + " page=" + page);
System.err.println("Listing accessions instituteCode=" + instituteCode + " page=" + page);
return objectMapper.writeValueAsString(getAccessionsPage(instCode, page));
return objectMapper.writeValueAsString(getAccessionsPage(instituteCode, page));
}
};
}
......@@ -90,10 +90,10 @@ public class MockGenesysServer {
@Override
public String answer(final InvocationOnMock invocation) throws Throwable {
final Object[] args = invocation.getArguments();
final String instCode = (String) args[0];
final String instituteCode = (String) args[0];
final List<?> arrayNode = (List<?>) args[1];
final String res = objectMapper.writeValueAsString(upsertAccessions(instCode, arrayNode));
final String res = objectMapper.writeValueAsString(upsertAccessions(instituteCode, arrayNode));
System.err.println("Result: " + res);
return res;
}
......@@ -103,7 +103,7 @@ public class MockGenesysServer {
/**
* Upsert accessions.
*
* @param instCode the inst code
* @param instituteCode the inst code
* @param nodeList the node list
* @return the string
* @throws JsonParseException the json parse exception
......@@ -111,10 +111,10 @@ public class MockGenesysServer {
* @throws IOException Signals that an I/O exception has occurred.
* @throws GenesysApiException the genesys api exception
*/
protected String upsertAccessions(final String instCode, final List<?> nodeList) throws JsonParseException, JsonMappingException, IOException, GenesysApiException {
List<AccessionJson> accList = instAcc.get(instCode);
protected String upsertAccessions(final String instituteCode, final List<?> nodeList) throws JsonParseException, JsonMappingException, IOException, GenesysApiException {
List<AccessionJson> accList = instAcc.get(instituteCode);
if (accList == null) {
instAcc.put(instCode, accList = new ArrayList<AccessionJson>());
instAcc.put(instituteCode, accList = new ArrayList<AccessionJson>());
}
for (int i = 0; i < nodeList.size(); i++) {
final AccessionJson aj = (AccessionJson) nodeList.get(i);
......@@ -149,11 +149,11 @@ public class MockGenesysServer {
if (aj.getMlsStat() != null) {
existing.setMlsStat(aj.getMlsStat());
}
if (aj.getAcceNumb() != null) {
existing.setAcceNumb(aj.getAcceNumb());
if (aj.getAccessionNumber() != null) {
existing.setAccessionNumber(aj.getAccessionNumber());
}
if (aj.getAcqDate() != null) {
existing.setAcqDate(aj.getAcqDate());
if (aj.getAcquisitionDate() != null) {
existing.setAcquisitionDate(aj.getAcquisitionDate());
}
if (aj.getAncest() != null) {
existing.setAncest(aj.getAncest());
......@@ -226,7 +226,7 @@ public class MockGenesysServer {
return findMatch(accList, aj.getUuid());
} else {
for (final AccessionJson m : accList) {
if (m.getInstCode().equals(aj.getInstCode()) && m.getAcceNumb().equals(aj.getAcceNumb()) && m.getGenus().equals(aj.getGenus())) {
if (m.getInstituteCode().equals(aj.getInstituteCode()) && m.getAccessionNumber().equals(aj.getAccessionNumber()) && m.getGenus().equals(aj.getGenus())) {
return m;
}
}
......@@ -253,13 +253,13 @@ public class MockGenesysServer {
/**
* Gets the accessions page.
*
* @param instCode the inst code
* @param instituteCode the inst code
* @param page the page
* @return the accessions page
* @throws MockGenesysException the mock genesys exception
*/
protected List<AccessionJson> getAccessionsPage(final String instCode, final int page) throws MockGenesysException {
final List<AccessionJson> accList = instAcc.get(instCode);
protected List<AccessionJson> getAccessionsPage(final String instituteCode, final int page) throws MockGenesysException {
final List<AccessionJson> accList = instAcc.get(instituteCode);
if (accList == null || accList.isEmpty()) {
System.err.println("Returning blank list");
return BLANK_LIST;
......
......@@ -57,8 +57,8 @@ public class ModelTests {
@Test
public void serializeCore() throws IOException {
final AccessionJson aj = new AccessionJson();
aj.setInstCode("INS000");
aj.setAcceNumb("ACC-1");
aj.setInstituteCode("INS000");
aj.setAccessionNumber("ACC-1");
aj.setGenus("Genus");
final JsonNode tree = getJsonTree(aj);
......
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