@@ -1744,18 +1744,21 @@ public void testSearchFilesAndUrlImages() throws InterruptedException {
1744
1744
}
1745
1745
1746
1746
@ Test
1747
- public void testShowTypeCounts () {
1747
+ public void testShowTypeCounts () throws InterruptedException {
1748
1748
//Create 1 user and 1 Dataverse/Collection
1749
1749
Response createUser = UtilIT .createRandomUser ();
1750
1750
String username = UtilIT .getUsernameFromResponse (createUser );
1751
1751
String apiToken = UtilIT .getApiTokenFromResponse (createUser );
1752
1752
String affiliation = "testAffiliation" ;
1753
1753
1754
- // test total_count_per_object_type is not included because the results are empty
1754
+ // test total_count_per_object_type is included with zero counts for each type
1755
1755
Response searchResp = UtilIT .search (username , apiToken , "&show_type_counts=true" );
1756
1756
searchResp .then ().assertThat ()
1757
1757
.statusCode (OK .getStatusCode ())
1758
- .body ("data.total_count_per_object_type" , CoreMatchers .equalTo (null ));
1758
+ .body ("data.total_count_per_object_type.Dataverses" , CoreMatchers .is (0 ))
1759
+ .body ("data.total_count_per_object_type.Datasets" , CoreMatchers .is (0 ))
1760
+ .body ("data.total_count_per_object_type.Files" , CoreMatchers .is (0 ));
1761
+
1759
1762
1760
1763
Response createDataverseResponse = UtilIT .createRandomDataverse (apiToken , affiliation );
1761
1764
assertEquals (201 , createDataverseResponse .getStatusCode ());
@@ -1782,6 +1785,7 @@ public void testShowTypeCounts() {
1782
1785
1783
1786
// This call forces a wait for dataset indexing to finish and gives time for file uploads to complete
1784
1787
UtilIT .search ("id:dataset_" + datasetId , apiToken );
1788
+ UtilIT .sleepForReindex (datasetId , apiToken , 3 );
1785
1789
}
1786
1790
1787
1791
// Test Search without show_type_counts
@@ -1797,10 +1801,41 @@ public void testShowTypeCounts() {
1797
1801
// Test Search with show_type_counts = TRUE
1798
1802
searchResp = UtilIT .search (dataverseAlias , apiToken , "&show_type_counts=true" );
1799
1803
searchResp .prettyPrint ();
1804
+
1800
1805
searchResp .then ().assertThat ()
1801
1806
.statusCode (OK .getStatusCode ())
1802
1807
.body ("data.total_count_per_object_type.Dataverses" , CoreMatchers .is (1 ))
1803
1808
.body ("data.total_count_per_object_type.Datasets" , CoreMatchers .is (3 ))
1804
1809
.body ("data.total_count_per_object_type.Files" , CoreMatchers .is (6 ));
1810
+
1811
+
1812
+
1813
+ // go through the same exercise with only a collection to verify that Dataasets and Files
1814
+ // are there with a count of 0
1815
+
1816
+ createDataverseResponse = UtilIT .createRandomDataverse (apiToken , affiliation );
1817
+ assertEquals (201 , createDataverseResponse .getStatusCode ());
1818
+ dataverseAlias = UtilIT .getAliasFromResponse (createDataverseResponse );
1819
+
1820
+ sleep (4000 ); //make sure new dataverse gets indexed
1821
+
1822
+ // Test Search without show_type_counts
1823
+ searchResp = UtilIT .search (dataverseAlias , apiToken );
1824
+ searchResp .then ().assertThat ()
1825
+ .statusCode (OK .getStatusCode ())
1826
+ .body ("data.total_count_per_object_type" , CoreMatchers .equalTo (null ));
1827
+ // Test Search with show_type_counts = FALSE
1828
+ searchResp = UtilIT .search (dataverseAlias , apiToken , "&show_type_counts=false" );
1829
+ searchResp .then ().assertThat ()
1830
+ .statusCode (OK .getStatusCode ())
1831
+ .body ("data.total_count_per_object_type" , CoreMatchers .equalTo (null ));
1832
+ // Test Search with show_type_counts = TRUE
1833
+ searchResp = UtilIT .search (dataverseAlias , apiToken , "&show_type_counts=true" );
1834
+ searchResp .prettyPrint ();
1835
+ searchResp .then ().assertThat ()
1836
+ .statusCode (OK .getStatusCode ())
1837
+ .body ("data.total_count_per_object_type.Dataverses" , CoreMatchers .is (1 ))
1838
+ .body ("data.total_count_per_object_type.Datasets" , CoreMatchers .is (0 ))
1839
+ .body ("data.total_count_per_object_type.Files" , CoreMatchers .is (0 ));
1805
1840
}
1806
1841
}
0 commit comments