Skip to content

Commit

Permalink
fixed tests
Browse files Browse the repository at this point in the history
  • Loading branch information
marcos-lg committed Jun 2, 2021
1 parent 33acef4 commit a3c66b9
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public void collectionMetadataTest() {
MachineTag mtIh = new MachineTag(IH_NAMESPACE, IRN_TAG, "foo");
mtIh.setCreatedBy("test");
machineTagMapper.createMachineTag(mtIh);
institutionMapper.addMachineTag(c1.getKey(), mtIh.getKey());
collectionMapper.addMachineTag(c1.getKey(), mtIh.getKey());

List<DuplicateMetadataDto> metadataDtos =
duplicatesMapper.getCollectionsMetadata(Collections.singleton(c1.getKey()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ public void creationGrSciCollRequestTest() throws Exception {
.andExpect(status().isOk());

// check that the pre check call didn't perform the action
assertEquals(1, institutionService.list(InstitutionSearchRequest.builder().build()).getCount());
assertEquals(2, institutionService.list(InstitutionSearchRequest.builder().build()).getCount());

identityService.deleteEditorRight(EDITOR, INSTITUTION_KEY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,29 +143,47 @@
</sql>

<select id="getInstitutionsMetadata" resultType="DuplicateMetadataDto">
SELECT DISTINCT ON (i.key) i.key, i.active, mtIh IS NOT NULL AS is_ih, mtIdigbio IS NOT NULL AS is_idigbio
SELECT DISTINCT ON (i.key) i.key, i.active, ih IS NOT NULL AS is_ih, idigbio IS NOT NULL AS is_idigbio
FROM institution i
LEFT JOIN institution_machine_tag imt ON imt.institution_key = i.key
LEFT JOIN machine_tag mtIdigbio ON mtIdigbio.key = imt.machine_tag_key AND mtIdigbio.namespace = 'iDigBio.org'
LEFT JOIN machine_tag mtIh ON mtIh.key = imt.machine_tag_key AND mtIh.namespace = 'ih.gbif.org' AND mtIh.name = 'irn'
LEFT JOIN LATERAL (
SELECT imt.institution_key AS inst_key, mt.key AS mt_key
FROM institution_machine_tag imt
INNER JOIN machine_tag mt ON mt.key = imt.machine_tag_key AND mt.namespace = 'iDigBio.org'
WHERE imt.institution_key = i.key
) idigbio ON idigbio.inst_key = i.key
LEFT JOIN LATERAL (
SELECT imt.institution_key AS inst_key, mt.key AS mt_key
FROM institution_machine_tag imt
INNER JOIN machine_tag mt ON mt.key = imt.machine_tag_key AND mt.namespace = 'ih.gbif.org' AND mt.name = 'irn'
WHERE imt.institution_key = i.key
) ih ON ih.inst_key = i.key
WHERE i.key IN
<foreach item="item" collection="institutionKeys" open="(" separator="," close=")">
#{item}
</foreach>
ORDER BY i.key, mtIh.key, mtIdigbio.key NULLS LAST
ORDER BY i.key, ih.mt_key, idigbio.mt_key NULLS LAST
</select>

<select id="getCollectionsMetadata" resultType="DuplicateMetadataDto">
SELECT DISTINCT ON (c.key) c.key, c.active, mtIh IS NOT NULL AS is_ih, mtIdigbio IS NOT NULL AS is_idigbio
SELECT DISTINCT ON (c.key) c.key, c.active, ih IS NOT NULL AS is_ih, idigbio IS NOT NULL AS is_idigbio
FROM collection c
LEFT JOIN collection_machine_tag cmt ON cmt.collection_key = c.key
LEFT JOIN machine_tag mtIdigbio ON mtIdigbio.key = cmt.machine_tag_key AND mtIdigbio.namespace = 'iDigBio.org'
LEFT JOIN machine_tag mtIh ON mtIh.key = cmt.machine_tag_key AND mtIh.namespace = 'ih.gbif.org' AND mtIh.name = 'irn'
LEFT JOIN LATERAL (
SELECT cmt.collection_key AS coll_key, mt.key AS mt_key
FROM collection_machine_tag cmt
INNER JOIN machine_tag mt ON mt.key = cmt.machine_tag_key AND mt.namespace = 'iDigBio.org'
WHERE cmt.collection_key = c.key
) idigbio ON idigbio.coll_key = c.key
LEFT JOIN LATERAL (
SELECT cmt.collection_key AS coll_key, mt.key AS mt_key
FROM collection_machine_tag cmt
INNER JOIN machine_tag mt ON mt.key = cmt.machine_tag_key AND mt.namespace = 'ih.gbif.org' AND mt.name = 'irn'
WHERE cmt.collection_key = c.key
) ih ON ih.coll_key = c.key
WHERE c.key IN
<foreach item="item" collection="collectionKeys" open="(" separator="," close=")">
#{item}
</foreach>
ORDER BY c.key, mtIh.key, mtIdigbio.key NULLS LAST
ORDER BY c.key, ih.mt_key, idigbio.mt_key NULLS LAST
</select>

</mapper>
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,8 @@ private void mockInstitutionConversion(
boolean countryRights)
throws JsonProcessingException {
when(mockAuthenticationFacade.getAuthentication()).thenReturn(mockAuthentication);
when(mockRequest.getRequestURI()).thenReturn("/grscicoll/institution/" + INST_KEY);
when(mockRequest.getRequestURI())
.thenReturn("/grscicoll/institution/" + INST_KEY + "/convertToCollection");
when(mockRequest.getMethod()).thenReturn("PUT");

ConvertToCollectionParams params = new ConvertToCollectionParams();
Expand All @@ -1034,6 +1035,15 @@ private void mockInstitutionConversion(
when(mockAuthentication.getName()).thenReturn(USERNAME);
doReturn(roles).when(mockAuthentication).getAuthorities();
doReturn(INSTITUTION).when(mockInstitutionMapper).get(INST_KEY);

Institution institutionForConvertedCollection = new Institution();
institutionForConvertedCollection.setKey(params.getInstitutionForNewCollectionKey());
institutionForConvertedCollection.setCode(UUID.randomUUID().toString());
institutionForConvertedCollection.setName(UUID.randomUUID().toString());
doReturn(institutionForConvertedCollection)
.when(mockInstitutionMapper)
.get(params.getInstitutionForNewCollectionKey());

doReturn(institutionRights).when(mockUserRightsMapper).keyExistsForUser(USERNAME, INST_KEY);
doReturn(targetInstitutionRights)
.when(mockUserRightsMapper)
Expand Down

0 comments on commit a3c66b9

Please sign in to comment.