Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Genesys PGR
Java Client API
Commits
4880b4be
Commit
4880b4be
authored
Apr 22, 2021
by
Matija Obreza
Browse files
Merge branch 'drop-obsolete-code' into 'master'
Drop obsolete code for /api/v0 See merge request
!16
parents
fe5db68a
c20b7a71
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
src/main/java/org/genesys2/client/oauth/GenesysClient.java
View file @
4880b4be
This diff is collapsed.
Click to expand it.
src/test/java/org/geneys2/client/oauth/AccessionApiTest.java
deleted
100644 → 0
View file @
fe5db68a
/*
* Copyright 2019 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
;
import
static
org
.
hamcrest
.
CoreMatchers
.*;
import
static
org
.
hamcrest
.
MatcherAssert
.
assertThat
;
import
static
org
.
mockito
.
Matchers
.*;
import
static
org
.
mockito
.
Mockito
.
when
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.List
;
import
org.genesys2.client.oauth.GenesysApiException
;
import
org.genesys2.client.oauth.GenesysClient
;
import
org.genesys2.client.oauth.OAuthAuthenticationException
;
import
org.genesys2.client.oauth.PleaseRetryException
;
import
org.genesys2.client.oauth.api.accession.AccessionJson
;
import
org.hamcrest.CoreMatchers
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Matchers
;
import
org.mockito.Mock
;
import
org.mockito.runners.MockitoJUnitRunner
;
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
;
/**
* Accession API v1 test
*/
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
AccessionApiTest
{
/** The object mapper. */
private
static
final
ObjectMapper
objectMapper
;
/** The genesys client. */
@Mock
protected
GenesysClient
genesysClient
;
/** The inst code. */
private
final
String
instituteCode
=
"INS000"
;
/** The mock server. */
private
final
MockGenesysServer
mockServer
=
new
MockGenesysServer
();
static
{
objectMapper
=
new
ObjectMapper
();
objectMapper
.
configure
(
SerializationFeature
.
WRITE_ENUMS_USING_TO_STRING
,
true
);
objectMapper
.
setSerializationInclusion
(
Include
.
NON_EMPTY
);
objectMapper
.
setSerializationInclusion
(
Include
.
NON_NULL
);
}
/**
* Inits the mocks.
*
* @throws OAuthAuthenticationException the o auth authentication exception
* @throws PleaseRetryException the please retry exception
* @throws GenesysApiException the genesys api exception
* @throws InterruptedException the interrupted exception
* @throws JsonProcessingException the json processing exception
*/
@Before
public
void
initMocks
()
throws
OAuthAuthenticationException
,
PleaseRetryException
,
GenesysApiException
,
InterruptedException
,
JsonProcessingException
{
System
.
err
.
println
(
"Initializing mocks"
);
when
(
genesysClient
.
listAccessions
(
anyString
(),
anyInt
(),
Matchers
.
isNull
(
String
.
class
))).
then
(
mockServer
.
listAccessions
());
when
(
genesysClient
.
updateAccessions
(
anyString
(),
anyCollectionOf
(
AccessionJson
.
class
))).
then
(
mockServer
.
updateAccessions
());
}
/**
* Test accessions0.
*
* @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
testAccessions0
()
throws
OAuthAuthenticationException
,
PleaseRetryException
,
GenesysApiException
,
JsonProcessingException
,
IOException
{
final
List
<
AccessionJson
>
results
=
objectMapper
.
readValue
(
genesysClient
.
listAccessions
(
instituteCode
,
1
,
null
),
new
TypeReference
<
List
<
AccessionJson
>>()
{
});
assertThat
(
"Expected empty list"
,
results
.
size
(),
is
(
0
));
}
/**
* Test accessions1.
*
* @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
testAccessions1
()
throws
OAuthAuthenticationException
,
PleaseRetryException
,
GenesysApiException
,
JsonProcessingException
,
IOException
{
when
(
genesysClient
.
listAccessions
(
instituteCode
,
1
,
null
)).
thenReturn
(
"[{\"instituteCode\":\"INS000\",\"accessionNumber\":\"ACC-1\"}]"
);
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
.
getInstituteCode
(),
is
(
instituteCode
));
acc1
.
setHistoric
(
true
);
}
/**
* Test upsert accessions1.
*
* @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.
* @throws InterruptedException the interrupted exception
*/
@Test
public
void
testUpsertAccessions1
()
throws
OAuthAuthenticationException
,
PleaseRetryException
,
GenesysApiException
,
JsonProcessingException
,
IOException
,
InterruptedException
{
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
>>()
{
});
assertThat
(
"Expected empty list"
,
results
.
size
(),
is
(
0
));
final
List
<
AccessionJson
>
ajList
=
new
ArrayList
<
AccessionJson
>();
for
(
int
i
=
0
;
i
<
4
;
i
++)
{
final
AccessionJson
aj
=
new
AccessionJson
();
aj
.
setInstituteCode
(
instituteCode
);
aj
.
setAccessionNumber
(
"ACC-"
+
(
i
+
1
));
aj
.
getTaxonomy
().
setGenus
(
"Genus"
);
ajList
.
add
(
aj
);
}
result
=
genesysClient
.
updateAccessions
(
instituteCode
,
ajList
);
System
.
err
.
println
(
result
);
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
.
getInstituteCode
(),
is
(
instituteCode
));
assertThat
(
"Expected ACCENUMB starting with"
,
aj1
.
getAccessionNumber
(),
CoreMatchers
.
startsWith
(
"ACC-"
));
assertThat
(
"Expected GENUS=Genus"
,
aj1
.
getTaxonomy
().
getGenus
(),
is
(
"Genus"
));
assertThat
(
"Expected SPECIES=null"
,
aj1
.
getTaxonomy
().
getSpecies
(),
nullValue
());
}
}
}
src/test/java/org/geneys2/client/oauth/AccessionImagesTest.java
View file @
4880b4be
...
@@ -29,7 +29,7 @@ import org.junit.Test;
...
@@ -29,7 +29,7 @@ import org.junit.Test;
public
class
AccessionImagesTest
{
public
class
AccessionImagesTest
{
/** The mapper. */
/** The mapper. */
private
static
ObjectMapper
objectMapper
;
private
static
final
ObjectMapper
objectMapper
;
static
{
static
{
objectMapper
=
new
ObjectMapper
();
objectMapper
=
new
ObjectMapper
();
...
...
src/test/java/org/geneys2/client/oauth/MockGenesysServer.java
deleted
100644 → 0
View file @
fe5db68a
/*
* Copyright 2019 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
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.HashMap
;
import
java.util.List
;
import
java.util.Map
;
import
com.fasterxml.jackson.annotation.JsonInclude.Include
;
import
com.fasterxml.jackson.core.JsonParseException
;
import
com.fasterxml.jackson.databind.JsonMappingException
;
import
com.fasterxml.jackson.databind.ObjectMapper
;
import
com.fasterxml.jackson.databind.SerializationFeature
;
import
org.genesys2.client.oauth.GenesysApiException
;
import
org.genesys2.client.oauth.api.accession.AccessionJson
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.stubbing.Answer
;
// TODO: Auto-generated Javadoc
/**
* Mock Genesys server.
*
* @author mobreza
*/
public
class
MockGenesysServer
{
/** The Constant BLANK_LIST. */
private
static
final
ArrayList
<
AccessionJson
>
BLANK_LIST
=
new
ArrayList
<
AccessionJson
>();
/** The inst acc. */
private
final
Map
<
String
,
List
<
AccessionJson
>>
instAcc
=
new
HashMap
<
String
,
List
<
AccessionJson
>>();
/** The object mapper. */
private
static
final
ObjectMapper
objectMapper
;
static
{
objectMapper
=
new
ObjectMapper
();
objectMapper
.
configure
(
SerializationFeature
.
WRITE_ENUMS_USING_TO_STRING
,
true
);
objectMapper
.
setSerializationInclusion
(
Include
.
NON_EMPTY
);
objectMapper
.
setSerializationInclusion
(
Include
.
NON_NULL
);
}
/**
* List accessions.
*
* @return the answer
*/
public
Answer
<
String
>
listAccessions
()
{
return
new
Answer
<
String
>()
{
@Override
public
String
answer
(
final
InvocationOnMock
invocation
)
throws
Throwable
{
final
Object
[]
args
=
invocation
.
getArguments
();
if
(
args
[
2
]
!=
null
)
{
throw
new
MockGenesysException
(
"Querying is not supported."
);
}
final
String
instituteCode
=
(
String
)
args
[
0
];
final
int
page
=
(
Integer
)
args
[
1
];
System
.
err
.
println
(
"Listing accessions instituteCode="
+
instituteCode
+
" page="
+
page
);
return
objectMapper
.
writeValueAsString
(
getAccessionsPage
(
instituteCode
,
page
));
}
};
}
/**
* Update accessions.
*
* @return the answer
*/
public
Answer
<
String
>
updateAccessions
()
{
return
new
Answer
<
String
>()
{
@Override
public
String
answer
(
final
InvocationOnMock
invocation
)
throws
Throwable
{
final
Object
[]
args
=
invocation
.
getArguments
();
final
String
instituteCode
=
(
String
)
args
[
0
];
final
List
<?>
arrayNode
=
(
List
<?>)
args
[
1
];
final
String
res
=
objectMapper
.
writeValueAsString
(
upsertAccessions
(
instituteCode
,
arrayNode
));
System
.
err
.
println
(
"Result: "
+
res
);
return
res
;
}
};
}
/**
* Upsert accessions.
*
* @param instituteCode the inst code
* @param nodeList the node list
* @return the string
* @throws JsonParseException the json parse exception
* @throws JsonMappingException the json mapping exception
* @throws IOException Signals that an I/O exception has occurred.
* @throws GenesysApiException the genesys api exception
*/
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
(
instituteCode
,
accList
=
new
ArrayList
<
AccessionJson
>());
}
for
(
int
i
=
0
;
i
<
nodeList
.
size
();
i
++)
{
final
AccessionJson
aj
=
(
AccessionJson
)
nodeList
.
get
(
i
);
final
AccessionJson
existing
=
findMatch
(
accList
,
aj
);
merge
(
accList
,
existing
,
aj
);
}
return
"OK"
;
}
/**
* Merge.
*
* @param accList the acc list
* @param existing the existing
* @param aj the aj
* @throws MockGenesysException the mock genesys exception
*/
private
void
merge
(
final
List
<
AccessionJson
>
accList
,
final
AccessionJson
existing
,
final
AccessionJson
aj
)
throws
MockGenesysException
{
if
(
existing
==
null
)
{
accList
.
add
(
aj
);
}
else
{
if
(
aj
.
getAvailable
()
!=
null
)
{
existing
.
setAvailable
(
aj
.
getAvailable
());
}
if
(
aj
.
getHistoric
()
!=
null
)
{
existing
.
setHistoric
(
aj
.
getHistoric
());
}
if
(
aj
.
getInTrust
()
!=
null
)
{
existing
.
setInTrust
(
aj
.
getInTrust
());
}
if
(
aj
.
getMlsStat
()
!=
null
)
{
existing
.
setMlsStat
(
aj
.
getMlsStat
());
}
if
(
aj
.
getAegis
()
!=
null
)
{
existing
.
setAegis
(
aj
.
getAegis
());
}
if
(
aj
.
getAccessionNumber
()
!=
null
)
{
existing
.
setAccessionNumber
(
aj
.
getAccessionNumber
());
}
if
(
aj
.
getAcquisitionDate
()
!=
null
)
{
existing
.
setAcquisitionDate
(
aj
.
getAcquisitionDate
());
}
if
(
aj
.
getAncest
()
!=
null
)
{
existing
.
setAncest
(
aj
.
getAncest
());
}
if
(
aj
.
getBredCode
()
!=
null
)
{
existing
.
setBredCode
(
aj
.
getBredCode
());
}
if
(
aj
.
getColl
()
!=
null
)
{
}
if
(
aj
.
getDonorCode
()
!=
null
)
{
existing
.
setDonorCode
(
aj
.
getDonorCode
());
}
if
(
aj
.
getDonorName
()
!=
null
)
{
existing
.
setDonorName
(
aj
.
getDonorName
());
}
if
(
aj
.
getDonorNumb
()
!=
null
)
{
existing
.
setDonorNumb
(
aj
.
getDonorNumb
());
}
if
(
aj
.
getDuplSite
()
!=
null
)
{
existing
.
setDuplSite
(
aj
.
getDuplSite
());
}
if
(
aj
.
getGeo
()
!=
null
)
{
}
if
(
aj
.
getOrgCty
()
!=
null
)
{
existing
.
setOrgCty
(
aj
.
getOrgCty
());
}
if
(
aj
.
getRemarks
()
!=
null
)
{
existing
.
setRemarks
(
aj
.
getRemarks
());
}
if
(
aj
.
getSampStat
()
!=
null
)
{
existing
.
setSampStat
(
aj
.
getSampStat
());
}
if
(
aj
.
getTaxonomy
()
!=
null
)
{
}
if
(
aj
.
getUuid
()
!=
null
)
{
if
(
existing
.
getUuid
()
==
null
)
{
existing
.
setUuid
(
aj
.
getUuid
());
}
else
if
(!
existing
.
getUuid
().
equals
(
aj
.
getUuid
()))
{
// Can this happen?
throw
new
MockGenesysException
(
"UUID mismatch"
);
}
}
if
(
aj
.
getAvailable
()
!=
null
)
{
existing
.
setAvailable
(
aj
.
getAvailable
());
}
}
}
/**
* Find match.
*
* @param accList the acc list
* @param aj the aj
* @return the accession json
*/
private
AccessionJson
findMatch
(
final
List
<
AccessionJson
>
accList
,
final
AccessionJson
aj
)
{
if
(
aj
.
getUuid
()
!=
null
)
{
return
findMatch
(
accList
,
aj
.
getUuid
());
}
else
{
for
(
final
AccessionJson
m
:
accList
)
{
if
(
m
.
getInstituteCode
().
equals
(
aj
.
getInstituteCode
())
&&
m
.
getAccessionNumber
().
equals
(
aj
.
getAccessionNumber
())
&&
m
.
getTaxonomy
().
getGenus
().
equals
(
aj
.
getTaxonomy
().
getGenus
()))
{
return
m
;
}
}
}
return
null
;
}
/**
* Find match.
*
* @param accList the acc list
* @param uuid the uuid
* @return the accession json
*/
private
AccessionJson
findMatch
(
final
List
<
AccessionJson
>
accList
,
final
String
uuid
)
{
for
(
final
AccessionJson
m
:
accList
)
{
if
(
m
.
getUuid
().
equals
(
uuid
))
{
return
m
;
}
}
return
null
;
}
/**
* Gets the accessions page.
*
* @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
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
;
}
if
(
page
!=
1
)
{
throw
new
MockGenesysException
(
"page argument is not suported"
);
}
return
accList
;
}
}
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment