Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixes species caching bug #911

Merged
merged 1 commit into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,8 @@ class SpeciesReMatchService {
}

def searchBie(String name, int limit = 1) {
cacheService.get('bie-search-auto', {
name = name?.toLowerCase() ?: ""
cacheService.get('bie-search-auto-' + name, {
def encodedQuery = URLEncoder.encode(name ?: '', "UTF-8")
def url = "${grailsApplication.config.getProperty('bie.url')}ws/search/auto.jsonp?q=${encodedQuery}&limit=${limit}&idxType=TAXON"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ class BulkImportControllerSpec extends Specification implements ControllerUnitT
response.getJson().error == "Missing id"
}

def "get: test get missing bulk import id"() {
def "get: test wrong bulk import id is provided"() {

when:
params.id = "123"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package au.org.ala.ecodata


import grails.testing.services.ServiceUnitTest
import spock.lang.Specification

class SpeciesReMatchServiceSpec extends Specification implements ServiceUnitTest<SpeciesReMatchService> {

// write test case for SpeciesReMatchService.searchBie
void setup() {
service.cacheService = new CacheService()
service.webService = Mock(WebService)
grailsApplication.config.bie.url = "http://localhost:8080"
}

void "test searchBie"() {
setup:
def resp = [
autoCompleteList: [
[name: "name", guid: "guid", commonName: "commonName"]
]
]
service.webService.getJson(_) >> resp
when:
def result = service.searchBie("name")

then:
result == resp
}

// test same name returns same result
void "test searchBie cache correctly"() {
setup:
int callCount = 0
def resp = [
autoCompleteList: [
[name: "name", guid: "guid", commonName: "commonName"]
]
]
def resp2 = [
autoCompleteList: [
[name: "name2", guid: "guid2", commonName: "commonName2"]
]
]

when:
def result = service.searchBie("name")
def result2 = service.searchBie("name")
service.webService.getJson(_) >> {
callCount++
if (callCount == 0) {
resp
} else {
resp2
}
}

then:
result == resp
result2 == resp
result2 != resp2

when:
result2 = service.searchBie("name2")

then:
result2 == resp2
}

}
Loading