25
25
26
26
import static jakarta .ws .rs .core .Response .Status .*;
27
27
import static org .hamcrest .CoreMatchers .*;
28
- import static org .hamcrest .CoreMatchers .containsString ;
29
28
import static org .hamcrest .MatcherAssert .assertThat ;
30
29
import static org .hamcrest .Matchers .hasItemInArray ;
31
30
import static org .junit .jupiter .api .Assertions .*;
@@ -702,9 +701,9 @@ public void testListMetadataBlocks() {
702
701
Response setMetadataBlocksResponse = UtilIT .setMetadataBlocks (dataverseAlias , Json .createArrayBuilder ().add ("citation" ).add ("astrophysics" ), apiToken );
703
702
setMetadataBlocksResponse .then ().assertThat ().statusCode (OK .getStatusCode ());
704
703
705
- String [] testInputLevelNames = {"geographicCoverage" , "country" , "city" };
706
- boolean [] testRequiredInputLevels = {false , true , false };
707
- boolean [] testIncludedInputLevels = {false , true , true };
704
+ String [] testInputLevelNames = {"geographicCoverage" , "country" , "city" , "notesText" };
705
+ boolean [] testRequiredInputLevels = {false , true , false , false };
706
+ boolean [] testIncludedInputLevels = {false , true , true , false };
708
707
Response updateDataverseInputLevelsResponse = UtilIT .updateDataverseInputLevels (dataverseAlias , testInputLevelNames , testRequiredInputLevels , testIncludedInputLevels , apiToken );
709
708
updateDataverseInputLevelsResponse .then ().assertThat ().statusCode (OK .getStatusCode ());
710
709
@@ -774,17 +773,22 @@ public void testListMetadataBlocks() {
774
773
// Check dataset fields for the updated input levels are retrieved
775
774
int geospatialMetadataBlockIndex = actualMetadataBlockDisplayName1 .equals ("Geospatial Metadata" ) ? 0 : actualMetadataBlockDisplayName2 .equals ("Geospatial Metadata" ) ? 1 : 2 ;
776
775
776
+ // Since the included property of notesText is set to false, we should retrieve the total number of fields minus one
777
+ int citationMetadataBlockIndex = geospatialMetadataBlockIndex == 0 ? 1 : 0 ;
778
+ listMetadataBlocksResponse .then ().assertThat ()
779
+ .body (String .format ("data[%d].fields.size()" , citationMetadataBlockIndex ), equalTo (78 ));
780
+
777
781
// Since the included property of geographicCoverage is set to false, we should retrieve the total number of fields minus one
778
782
listMetadataBlocksResponse .then ().assertThat ()
779
783
.body (String .format ("data[%d].fields.size()" , geospatialMetadataBlockIndex ), equalTo (10 ));
780
784
781
- String actualMetadataField1 = listMetadataBlocksResponse .then ().extract ().path (String .format ("data[%d].fields.geographicCoverage.name" , geospatialMetadataBlockIndex ));
782
- String actualMetadataField2 = listMetadataBlocksResponse .then ().extract ().path (String .format ("data[%d].fields.country.name" , geospatialMetadataBlockIndex ));
783
- String actualMetadataField3 = listMetadataBlocksResponse .then ().extract ().path (String .format ("data[%d].fields.city.name" , geospatialMetadataBlockIndex ));
785
+ String actualGeospatialMetadataField1 = listMetadataBlocksResponse .then ().extract ().path (String .format ("data[%d].fields.geographicCoverage.name" , geospatialMetadataBlockIndex ));
786
+ String actualGeospatialMetadataField2 = listMetadataBlocksResponse .then ().extract ().path (String .format ("data[%d].fields.country.name" , geospatialMetadataBlockIndex ));
787
+ String actualGeospatialMetadataField3 = listMetadataBlocksResponse .then ().extract ().path (String .format ("data[%d].fields.city.name" , geospatialMetadataBlockIndex ));
784
788
785
- assertNull (actualMetadataField1 );
786
- assertNotNull (actualMetadataField2 );
787
- assertNotNull (actualMetadataField3 );
789
+ assertNull (actualGeospatialMetadataField1 );
790
+ assertNotNull (actualGeospatialMetadataField2 );
791
+ assertNotNull (actualGeospatialMetadataField3 );
788
792
789
793
// Existent dataverse and onlyDisplayedOnCreate=true and returnDatasetFieldTypes=true
790
794
listMetadataBlocksResponse = UtilIT .listMetadataBlocks (dataverseAlias , true , true , apiToken );
@@ -807,13 +811,27 @@ public void testListMetadataBlocks() {
807
811
listMetadataBlocksResponse .then ().assertThat ()
808
812
.body (String .format ("data[%d].fields.size()" , geospatialMetadataBlockIndex ), equalTo (1 ));
809
813
810
- actualMetadataField1 = listMetadataBlocksResponse .then ().extract ().path (String .format ("data[%d].fields.geographicCoverage.name" , geospatialMetadataBlockIndex ));
811
- actualMetadataField2 = listMetadataBlocksResponse .then ().extract ().path (String .format ("data[%d].fields.country.name" , geospatialMetadataBlockIndex ));
812
- actualMetadataField3 = listMetadataBlocksResponse .then ().extract ().path (String .format ("data[%d].fields.city.name" , geospatialMetadataBlockIndex ));
814
+ actualGeospatialMetadataField1 = listMetadataBlocksResponse .then ().extract ().path (String .format ("data[%d].fields.geographicCoverage.name" , geospatialMetadataBlockIndex ));
815
+ actualGeospatialMetadataField2 = listMetadataBlocksResponse .then ().extract ().path (String .format ("data[%d].fields.country.name" , geospatialMetadataBlockIndex ));
816
+ actualGeospatialMetadataField3 = listMetadataBlocksResponse .then ().extract ().path (String .format ("data[%d].fields.city.name" , geospatialMetadataBlockIndex ));
817
+
818
+ assertNull (actualGeospatialMetadataField1 );
819
+ assertNotNull (actualGeospatialMetadataField2 );
820
+ assertNull (actualGeospatialMetadataField3 );
821
+
822
+ citationMetadataBlockIndex = geospatialMetadataBlockIndex == 0 ? 1 : 0 ;
823
+
824
+ // notesText has displayOnCreate=true but has include=false, so should not be retrieved
825
+ String notesTextCitationMetadataField = listMetadataBlocksResponse .then ().extract ().path (String .format ("data[%d].fields.notesText.name" , citationMetadataBlockIndex ));
826
+ assertNull (notesTextCitationMetadataField );
827
+
828
+ // producerName is a conditionally required field, so should not be retrieved
829
+ String producerNameCitationMetadataField = listMetadataBlocksResponse .then ().extract ().path (String .format ("data[%d].fields.producerName.name" , citationMetadataBlockIndex ));
830
+ assertNull (producerNameCitationMetadataField );
813
831
814
- assertNull ( actualMetadataField1 );
815
- assertNotNull ( actualMetadataField2 );
816
- assertNull ( actualMetadataField3 );
832
+ // author is a required field, so should be retrieved
833
+ String authorCitationMetadataField = listMetadataBlocksResponse . then (). extract (). path ( String . format ( "data[%d].fields.author.name" , citationMetadataBlockIndex ) );
834
+ assertNotNull ( authorCitationMetadataField );
817
835
818
836
// User has no permissions on the requested dataverse
819
837
Response createSecondUserResponse = UtilIT .createRandomUser ();
@@ -825,6 +843,15 @@ public void testListMetadataBlocks() {
825
843
826
844
listMetadataBlocksResponse = UtilIT .listMetadataBlocks (secondDataverseAlias , true , true , apiToken );
827
845
listMetadataBlocksResponse .then ().assertThat ().statusCode (UNAUTHORIZED .getStatusCode ());
846
+
847
+ // List metadata blocks from Root
848
+ listMetadataBlocksResponse = UtilIT .listMetadataBlocks ("root" , true , true , apiToken );
849
+ listMetadataBlocksResponse .then ().assertThat ().statusCode (OK .getStatusCode ());
850
+ listMetadataBlocksResponse .then ().assertThat ()
851
+ .statusCode (OK .getStatusCode ())
852
+ .body ("data[0].displayName" , equalTo ("Citation Metadata" ))
853
+ .body ("data[0].fields" , not (equalTo (null )))
854
+ .body ("data.size()" , equalTo (1 ));
828
855
}
829
856
830
857
@ Test
0 commit comments