-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from folio-org/MODTLR-7
MODTLR-7 Added the client for mod-search
- Loading branch information
Showing
5 changed files
with
92 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package org.folio.client.feign; | ||
|
||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import org.folio.model.ResultList; | ||
import org.folio.spring.config.FeignClientConfiguration; | ||
import org.folio.support.CqlQuery; | ||
import org.springframework.cloud.openfeign.FeignClient; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
|
||
@FeignClient(name = "search", configuration = FeignClientConfiguration.class) | ||
public interface SearchClient { | ||
|
||
@GetMapping("/instances") | ||
ResultList<Instance> searchInstances(@RequestParam("query") CqlQuery cql, @RequestParam("expandAll") Boolean expandAll); | ||
|
||
@AllArgsConstructor | ||
@Data | ||
@JsonIgnoreProperties(ignoreUnknown = true) | ||
class Instance { | ||
private String id; | ||
private String tenantId; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package org.folio.model; | ||
|
||
import com.fasterxml.jackson.annotation.JsonAlias; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Data; | ||
import lombok.NoArgsConstructor; | ||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Data | ||
@NoArgsConstructor | ||
@AllArgsConstructor(staticName = "of") | ||
public class ResultList<T> { | ||
@JsonAlias("total_records") | ||
private int totalRecords = 0; | ||
|
||
private List<T> result = Collections.emptyList(); | ||
|
||
public static <R> ResultList<R> of(List<R> result) { | ||
return new ResultList<>(result.size(), result); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package org.folio.support; | ||
|
||
import static java.lang.String.format; | ||
|
||
public record CqlQuery(String query) { | ||
public static CqlQuery exactMatch(String index, String value) { | ||
return new CqlQuery(format("%s==\"%s\"", index, value)); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package org.folio.client; | ||
|
||
import org.folio.support.CqlQuery; | ||
import org.folio.client.feign.SearchClient; | ||
import org.folio.model.ResultList; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.ArgumentMatchers.anyBoolean; | ||
import static org.mockito.Mockito.when; | ||
|
||
@ExtendWith(MockitoExtension.class) | ||
class SearchClientTest { | ||
@Mock | ||
private SearchClient searchClient; | ||
|
||
@Test | ||
void canGetInstances() { | ||
SearchClient.Instance instance = new SearchClient.Instance(UUID.randomUUID().toString(), "tenant1"); | ||
ResultList<SearchClient.Instance> mockResult = ResultList.of(List.of(instance)); | ||
when(searchClient.searchInstances(any(CqlQuery.class), anyBoolean())).thenReturn(mockResult); | ||
var response = searchClient.searchInstances(CqlQuery.exactMatch("id", UUID.randomUUID().toString()), true); | ||
assertNotNull(response); | ||
assertTrue(response.getTotalRecords() > 0); | ||
} | ||
} |