formatting work
This commit is contained in:
@@ -18,8 +18,11 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class OperationIntegrationTest {
|
||||
private InputStream jsonInputStream = this.getClass().getClassLoader().getResourceAsStream("intro_api.json");
|
||||
private String jsonDataSourceString = new Scanner(jsonInputStream, "UTF-8").useDelimiter("\\Z").next();
|
||||
private InputStream jsonInputStream = this.getClass()
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("intro_api.json");
|
||||
private String jsonDataSourceString = new Scanner(jsonInputStream, "UTF-8").useDelimiter("\\Z")
|
||||
.next();
|
||||
|
||||
@Test
|
||||
public void givenJsonPathWithoutPredicates_whenReading_thenCorrect() {
|
||||
@@ -38,21 +41,27 @@ public class OperationIntegrationTest {
|
||||
|
||||
@Test
|
||||
public void givenJsonPathWithFilterPredicate_whenReading_thenCorrect() {
|
||||
Filter expensiveFilter = Filter.filter(Criteria.where("price").gt(20.00));
|
||||
List<Map<String, Object>> expensive = JsonPath.parse(jsonDataSourceString).read("$['book'][?]", expensiveFilter);
|
||||
Filter expensiveFilter = Filter.filter(Criteria.where("price")
|
||||
.gt(20.00));
|
||||
List<Map<String, Object>> expensive = JsonPath.parse(jsonDataSourceString)
|
||||
.read("$['book'][?]", expensiveFilter);
|
||||
predicateUsageAssertionHelper(expensive);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenJsonPathWithCustomizedPredicate_whenReading_thenCorrect() {
|
||||
Predicate expensivePredicate = context -> Float.valueOf(context.item(Map.class).get("price").toString()) > 20.00;
|
||||
List<Map<String, Object>> expensive = JsonPath.parse(jsonDataSourceString).read("$['book'][?]", expensivePredicate);
|
||||
Predicate expensivePredicate = context -> Float.valueOf(context.item(Map.class)
|
||||
.get("price")
|
||||
.toString()) > 20.00;
|
||||
List<Map<String, Object>> expensive = JsonPath.parse(jsonDataSourceString)
|
||||
.read("$['book'][?]", expensivePredicate);
|
||||
predicateUsageAssertionHelper(expensive);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void givenJsonPathWithInlinePredicate_whenReading_thenCorrect() {
|
||||
List<Map<String, Object>> expensive = JsonPath.parse(jsonDataSourceString).read("$['book'][?(@['price'] > $['price range']['medium'])]");
|
||||
List<Map<String, Object>> expensive = JsonPath.parse(jsonDataSourceString)
|
||||
.read("$['book'][?(@['price'] > $['price range']['medium'])]");
|
||||
predicateUsageAssertionHelper(expensive);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,12 +18,16 @@ import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
public class ServiceTest {
|
||||
private InputStream jsonInputStream = this.getClass().getClassLoader().getResourceAsStream("intro_service.json");
|
||||
private String jsonString = new Scanner(jsonInputStream, "UTF-8").useDelimiter("\\Z").next();
|
||||
private InputStream jsonInputStream = this.getClass()
|
||||
.getClassLoader()
|
||||
.getResourceAsStream("intro_service.json");
|
||||
private String jsonString = new Scanner(jsonInputStream, "UTF-8").useDelimiter("\\Z")
|
||||
.next();
|
||||
|
||||
@Test
|
||||
public void givenId_whenRequestingRecordData_thenSucceed() {
|
||||
Object dataObject = JsonPath.parse(jsonString).read("$[?(@.id == 2)]");
|
||||
Object dataObject = JsonPath.parse(jsonString)
|
||||
.read("$[?(@.id == 2)]");
|
||||
String dataString = dataObject.toString();
|
||||
|
||||
assertThat(dataString, containsString("2"));
|
||||
@@ -33,8 +37,10 @@ public class ServiceTest {
|
||||
|
||||
@Test
|
||||
public void givenStarring_whenRequestingMovieTitle_thenSucceed() {
|
||||
List<Map<String, Object>> dataList = JsonPath.parse(jsonString).read("$[?('Eva Green' in @['starring'])]");
|
||||
String title = (String) dataList.get(0).get("title");
|
||||
List<Map<String, Object>> dataList = JsonPath.parse(jsonString)
|
||||
.read("$[?('Eva Green' in @['starring'])]");
|
||||
String title = (String) dataList.get(0)
|
||||
.get("title");
|
||||
|
||||
assertEquals("Casino Royale", title);
|
||||
}
|
||||
@@ -59,8 +65,12 @@ public class ServiceTest {
|
||||
Arrays.sort(revenueArray);
|
||||
|
||||
int highestRevenue = revenueArray[revenueArray.length - 1];
|
||||
Configuration pathConfiguration = Configuration.builder().options(Option.AS_PATH_LIST).build();
|
||||
List<String> pathList = JsonPath.using(pathConfiguration).parse(jsonString).read("$[?(@['box office'] == " + highestRevenue + ")]");
|
||||
Configuration pathConfiguration = Configuration.builder()
|
||||
.options(Option.AS_PATH_LIST)
|
||||
.build();
|
||||
List<String> pathList = JsonPath.using(pathConfiguration)
|
||||
.parse(jsonString)
|
||||
.read("$[?(@['box office'] == " + highestRevenue + ")]");
|
||||
|
||||
Map<String, String> dataRecord = context.read(pathList.get(0));
|
||||
String title = dataRecord.get("title");
|
||||
@@ -83,7 +93,8 @@ public class ServiceTest {
|
||||
|
||||
long latestTime = dateArray[dateArray.length - 1];
|
||||
List<Map<String, Object>> finalDataList = context.read("$[?(@['director'] == 'Sam Mendes' && @['release date'] == " + latestTime + ")]");
|
||||
String title = (String) finalDataList.get(0).get("title");
|
||||
String title = (String) finalDataList.get(0)
|
||||
.get("title");
|
||||
|
||||
assertEquals("Spectre", title);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user