-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test added, unnecessary fields are removed (gbif/registry#579)
- Loading branch information
Showing
11 changed files
with
58 additions
and
114 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,12 @@ | |
import org.gbif.api.model.collections.Collection; | ||
import org.gbif.api.model.collections.Institution; | ||
import org.gbif.api.model.collections.MasterSourceMetadata; | ||
import org.gbif.api.model.collections.suggestions.InstitutionChangeSuggestion; | ||
import org.gbif.api.model.collections.suggestions.CollectionChangeSuggestion; | ||
import org.gbif.api.model.collections.suggestions.Type; | ||
import org.gbif.api.model.registry.Identifier; | ||
import org.gbif.api.vocabulary.IdentifierType; | ||
import org.gbif.api.vocabulary.collections.Source; | ||
import org.gbif.collections.sync.SyncResult; | ||
import org.gbif.collections.sync.clients.proxy.GrSciCollProxyClient; | ||
import org.gbif.collections.sync.ih.match.IHMatchResult; | ||
import org.gbif.collections.sync.ih.model.IHInstitution; | ||
|
||
|
@@ -26,10 +26,6 @@ | |
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyString; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.when; | ||
|
||
public class IHSynchronizerHandlersTest extends BaseIHTest { | ||
|
||
|
@@ -112,66 +108,32 @@ public void noMatchTest() { | |
expectedCollection.setName( | ||
String.format(DEFAULT_COLLECTION_NAME_FORMAT, expectedInstitution.getName())); | ||
expectedCollection.setNumberSpecimens(1000); | ||
expectedCollection.setMasterSourceMetadata(new MasterSourceMetadata(Source.IH_IRN, IRN_TEST)); | ||
expectedCollection.setMasterSourceMetadata( | ||
new MasterSourceMetadata(Source.IH_IRN, ih.getIrn())); | ||
|
||
// add identifier to expected entities | ||
Identifier newIdentifier = new Identifier(IdentifierType.IH_IRN, encodeIRN(IRN_TEST)); | ||
newIdentifier.setCreatedBy(TEST_USER); | ||
expectedInstitution.getIdentifiers().add(newIdentifier); | ||
expectedCollection.getIdentifiers().add(newIdentifier); | ||
|
||
IHMatchResult match = IHMatchResult.builder().ihInstitution(ih).build(); | ||
SyncResult.NoEntityMatch noEntityMatch = synchronizer.handleNoMatch(match); | ||
assertTrue(noEntityMatch.getNewCollection().lenientEquals(expectedCollection)); | ||
assertTrue(noEntityMatch.getNewInstitution().lenientEquals(expectedInstitution)); | ||
assertEmptyContactMatch(noEntityMatch.getContactMatch()); | ||
} | ||
|
||
@Test | ||
public void noMatchWithExistingInstitutionNameTest() { | ||
|
||
GrSciCollProxyClient proxyClient = mock(GrSciCollProxyClient.class); | ||
// IH institution | ||
IHInstitution ih = new IHInstitution(); | ||
ih.setIrn(IRN_TEST); | ||
ih.setCode("foo"); | ||
ih.setOrganization("foo"); | ||
ih.setSpecimenTotal(1000); | ||
|
||
// Expected institution | ||
Institution expectedInstitution = new Institution(); | ||
expectedInstitution.setCode(ih.getCode()); | ||
expectedInstitution.setName(ih.getOrganization()); | ||
expectedInstitution.setMasterSourceMetadata(new MasterSourceMetadata(Source.IH_IRN, IRN_TEST)); | ||
|
||
// Expected collection | ||
Collection expectedCollection = new Collection(); | ||
expectedCollection.setCode(ih.getCode()); | ||
expectedCollection.setName(String.format(DEFAULT_COLLECTION_NAME_FORMAT, expectedInstitution.getName())); | ||
expectedCollection.setNumberSpecimens(1000); | ||
expectedCollection.setMasterSourceMetadata(new MasterSourceMetadata(Source.IH_IRN, IRN_TEST)); | ||
|
||
// add identifier to expected entities | ||
Identifier newIdentifier = new Identifier(IdentifierType.IH_IRN, encodeIRN(IRN_TEST)); | ||
newIdentifier.setCreatedBy(TEST_USER); | ||
expectedInstitution.getIdentifiers().add(newIdentifier); | ||
expectedCollection.getIdentifiers().add(newIdentifier); | ||
//Expected Suggestion | ||
CollectionChangeSuggestion changeSuggestion = new CollectionChangeSuggestion(); | ||
changeSuggestion.setType(Type.CREATE); | ||
changeSuggestion.setCreateInstitution(true); | ||
changeSuggestion.setIhIdentifier(newIdentifier.getIdentifier()); | ||
changeSuggestion.setSuggestedEntity(expectedCollection); | ||
changeSuggestion.setProposerEmail("[email protected]"); | ||
List<String> comments = new ArrayList<>(); | ||
comments.add(COMMENT); | ||
changeSuggestion.setComments(comments); | ||
|
||
IHMatchResult match = IHMatchResult.builder().ihInstitution(ih).build(); | ||
|
||
// Mock behavior for findInstitutionByName | ||
List<Institution> institutionsWithSameName = new ArrayList<>(); | ||
institutionsWithSameName.add(expectedInstitution); | ||
|
||
when(proxyClient.findInstitutionByName(anyString())).thenReturn(institutionsWithSameName); | ||
when(proxyClient.createChangeSuggestion(any(InstitutionChangeSuggestion.class))).thenReturn(1); | ||
// Call the method under test | ||
SyncResult.NoEntityMatch noEntityMatch = synchronizer.handleNoMatch(match); | ||
|
||
// Assertions | ||
assertEquals(1, noEntityMatch.getNewChangeSuggestion()); | ||
assertTrue(noEntityMatch.getNewInstitution().lenientEquals(expectedInstitution)); | ||
assertEmptyContactMatch(noEntityMatch.getContactMatch()); | ||
assertEquals(noEntityMatch.getNewChangeSuggestion().getIhIdentifier(), | ||
expectedCollection.getIdentifiers().get(0).getIdentifier()); | ||
assertTrue(noEntityMatch.getNewChangeSuggestion().getCreateInstitution()); | ||
assertEquals(noEntityMatch.getNewChangeSuggestion(),changeSuggestion); | ||
} | ||
|
||
@Test | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters