1
1
package edu .harvard .iq .dataverse .api ;
2
2
3
+ import edu .harvard .iq .dataverse .search .SearchFields ;
3
4
import io .restassured .RestAssured ;
4
5
import io .restassured .path .json .JsonPath ;
5
6
import io .restassured .response .Response ;
6
7
import static jakarta .ws .rs .core .Response .Status .CREATED ;
7
8
import static jakarta .ws .rs .core .Response .Status .OK ;
9
+ import org .hamcrest .CoreMatchers ;
10
+ import static org .hamcrest .CoreMatchers .equalTo ;
8
11
import static org .junit .jupiter .api .Assertions .assertEquals ;
9
12
import org .junit .jupiter .api .BeforeAll ;
10
13
import org .junit .jupiter .api .Test ;
@@ -45,10 +48,31 @@ public void testCreateSoftwareDatasetNative() {
45
48
String datasetType = JsonPath .from (getDatasetJson .getBody ().asString ()).getString ("data.datasetType" );
46
49
System .out .println ("datasetType: " + datasetType );
47
50
assertEquals ("software" , datasetType );
51
+
52
+ Response searchDraft = UtilIT .searchAndShowFacets ("id:dataset_" + datasetId + "_draft" , apiToken );
53
+ searchDraft .prettyPrint ();
54
+ searchDraft .then ().assertThat ()
55
+ .body ("data.total_count" , CoreMatchers .is (1 ))
56
+ .body ("data.count_in_response" , CoreMatchers .is (1 ))
57
+ .body ("data.facets[0].datasetType_s.friendly" , CoreMatchers .is ("Dataset Type" ))
58
+ .body ("data.facets[0].datasetType_s.labels[0].software" , CoreMatchers .is (1 ))
59
+ .statusCode (OK .getStatusCode ());
60
+
61
+ UtilIT .publishDataverseViaNativeApi (dataverseAlias , apiToken ).then ().assertThat ().statusCode (OK .getStatusCode ());
62
+ UtilIT .publishDatasetViaNativeApi (datasetPid , "major" , apiToken ).then ().assertThat ().statusCode (OK .getStatusCode ());
63
+
64
+ // Response searchAsGuest = UtilIT.search(SearchFields.DATASET_TYPE + ":software", null);
65
+ // searchAsGuest.prettyPrint();
66
+ // searchAsGuest.then().assertThat()
67
+ // .body("data.total_count", CoreMatchers.is(1))
68
+ // .body("data.count_in_response", CoreMatchers.is(1))
69
+ // .body("data.facets[0].datasetType_s.friendly", CoreMatchers.is("Dataset Type"))
70
+ // .body("data.facets[0].datasetType_s.labels[0].software", CoreMatchers.is(1))
71
+ // .statusCode(OK.getStatusCode());
48
72
}
49
73
50
74
@ Test
51
- public void testCreateSoftwareDatasetSemantic () {
75
+ public void testCreateWorkflowDatasetSemantic () {
52
76
Response createUser = UtilIT .createRandomUser ();
53
77
createUser .then ().assertThat ().statusCode (OK .getStatusCode ());
54
78
String username = UtilIT .getUsernameFromResponse (createUser );
@@ -76,6 +100,7 @@ public void testCreateSoftwareDatasetSemantic() {
76
100
String datasetType = JsonPath .from (getDatasetJson .getBody ().asString ()).getString ("data.datasetType" );
77
101
System .out .println ("datasetType: " + datasetType );
78
102
assertEquals ("software" , datasetType );
103
+
79
104
}
80
105
81
106
@ Test
@@ -113,7 +138,7 @@ public void testImportJson() {
113
138
}
114
139
115
140
@ Test
116
- public void testImportDDI () {
141
+ public void testImportDdiWorkflow () {
117
142
Response createUser = UtilIT .createRandomUser ();
118
143
createUser .then ().assertThat ().statusCode (OK .getStatusCode ());
119
144
String username = UtilIT .getUsernameFromResponse (createUser );
@@ -126,11 +151,13 @@ public void testImportDDI() {
126
151
String dataverseAlias = UtilIT .getAliasFromResponse (createDataverse );
127
152
Integer dataverseId = UtilIT .getDataverseIdFromResponse (createDataverse );
128
153
154
+ UtilIT .publishDataverseViaNativeApi (dataverseAlias , apiToken ).then ().assertThat ().statusCode (OK .getStatusCode ());
155
+
129
156
String jsonIn = UtilIT .getDatasetJson ("doc/sphinx-guides/source/_static/api/dataset-create-software-ddi.xml" );
130
157
131
158
String randomString = UtilIT .getRandomString (6 );
132
159
133
- Response importJson = UtilIT .importDatasetDDIViaNativeApi (apiToken , dataverseAlias , jsonIn , "doi:10.5072/FK2/" + randomString , "no " );
160
+ Response importJson = UtilIT .importDatasetDDIViaNativeApi (apiToken , dataverseAlias , jsonIn , "doi:10.5072/FK2/" + randomString , "yes " );
134
161
importJson .prettyPrint ();
135
162
importJson .then ().assertThat ().statusCode (CREATED .getStatusCode ());
136
163
@@ -142,7 +169,16 @@ public void testImportDDI() {
142
169
getDatasetJson .then ().assertThat ().statusCode (OK .getStatusCode ());
143
170
String datasetType = JsonPath .from (getDatasetJson .getBody ().asString ()).getString ("data.datasetType" );
144
171
System .out .println ("datasetType: " + datasetType );
145
- assertEquals ("software" , datasetType );
172
+ assertEquals ("workflow" , datasetType );
173
+
174
+ Response search = UtilIT .searchAndShowFacets ("id:dataset_" + datasetId , apiToken );
175
+ search .prettyPrint ();
176
+ search .then ().assertThat ()
177
+ .body ("data.total_count" , CoreMatchers .is (1 ))
178
+ .body ("data.count_in_response" , CoreMatchers .is (1 ))
179
+ .body ("data.facets[0].datasetType_s.friendly" , CoreMatchers .is ("Dataset Type" ))
180
+ .body ("data.facets[0].datasetType_s.labels[0].workflow" , CoreMatchers .is (1 ))
181
+ .statusCode (OK .getStatusCode ());
146
182
147
183
}
148
184
0 commit comments