25
25
import static org .assertj .core .groups .Tuple .tuple ;
26
26
import static org .hamcrest .Matchers .equalTo ;
27
27
import static org .hamcrest .Matchers .iterableWithSize ;
28
+ import static org .junit .Assert .assertEquals ;
28
29
29
30
import java .util .List ;
30
31
import java .util .concurrent .TimeUnit ;
36
37
37
38
import com .b2international .commons .exceptions .BadRequestException ;
38
39
import com .b2international .snowowl .core .Resource ;
40
+ import com .b2international .snowowl .core .codesystem .CodeSystem ;
39
41
import com .b2international .snowowl .core .codesystem .CodeSystemRequests ;
40
42
import com .b2international .snowowl .core .domain .IComponent ;
41
43
import com .b2international .snowowl .core .id .IDs ;
44
+ import com .b2international .snowowl .core .request .CommitResult ;
42
45
import com .b2international .snowowl .core .request .ResourceConverter ;
43
46
import com .b2international .snowowl .core .request .ResourceRequests ;
44
47
import com .b2international .snowowl .core .rest .BundleApiAssert ;
@@ -66,6 +69,22 @@ public class ResourceApiTest {
66
69
public static void setup () {
67
70
bus = Services .bus ();
68
71
}
72
+
73
+ @ After
74
+ public void deleteAllResources () {
75
+ ResourceRequests
76
+ .prepareSearch ()
77
+ .buildAsync ()
78
+ .execute (Services .bus ())
79
+ .getSync (1 , TimeUnit .MINUTES )
80
+ .forEach (resource -> {
81
+ ResourceRequests
82
+ .prepareDelete (resource .getId ())
83
+ .build (RestExtensions .USER , "Delete " + resource .getId ())
84
+ .execute (Services .bus ())
85
+ .getSync (1 , TimeUnit .MINUTES );
86
+ });
87
+ }
69
88
70
89
@ Test
71
90
public void noResourcesPresent () {
@@ -131,58 +150,42 @@ public void searchAfter() throws Exception {
131
150
createDefaultCodeSystem (id1 , oid1 );
132
151
133
152
CodeSystemRequests .prepareSearchCodeSystem ()
134
- .filterById (id1 )
135
- .setSearchAfter ("codesystem" )
136
- .buildAsync ()
137
- .execute (bus )
138
- .getSync ();
153
+ .filterById (id1 )
154
+ .setSearchAfter ("codesystem" )
155
+ .buildAsync ()
156
+ .execute (bus )
157
+ .getSync ();
139
158
}
140
159
141
160
private void createCodeSystemWithStatus (final String shortName , final String status ) {
142
- CodeSystemRequests
143
- .prepareNewCodeSystem ()
144
- .setId (shortName )
145
- .setTitle (shortName )
146
- .setUrl (SnomedTerminologyComponentConstants .SNOMED_URI_DEV + "/" + shortName )
147
- .setDescription (DEFAULT_CODE_SYSTEM_DESCRIPTION )
148
- .setLanguage (DEFAULT_CODE_SYSTEM_LANGUAGE )
149
- .setToolingId (DEFAULT_CODE_SYSTEM_TOOLING_ID )
150
- .setStatus (status )
151
- .setOid ("https://b2i.sg/" + shortName )
152
- .build (RestExtensions .USER , String .format ("New code system %s" , shortName ))
153
- .execute (bus ).getSync ();
161
+ CodeSystemRequests .prepareNewCodeSystem ()
162
+ .setId (shortName )
163
+ .setTitle (shortName )
164
+ .setUrl (SnomedTerminologyComponentConstants .SNOMED_URI_DEV + "/" + shortName )
165
+ .setDescription (DEFAULT_CODE_SYSTEM_DESCRIPTION )
166
+ .setLanguage (DEFAULT_CODE_SYSTEM_LANGUAGE )
167
+ .setToolingId (DEFAULT_CODE_SYSTEM_TOOLING_ID )
168
+ .setStatus (status )
169
+ .setOid ("https://b2i.sg/" + shortName )
170
+ .build (RestExtensions .USER , String .format ("New code system %s" , shortName ))
171
+ .execute (bus ).getSync ();
154
172
155
173
}
156
174
157
175
private void createDefaultCodeSystem (final String shortName , final String oid ) {
158
- CodeSystemRequests
159
- .prepareNewCodeSystem ()
160
- .setId (shortName )
161
- .setTitle (String .format ("%s - %s" , shortName , oid ))
162
- .setUrl (SnomedTerminologyComponentConstants .SNOMED_URI_DEV + "/" + shortName )
163
- .setDescription (DEFAULT_CODE_SYSTEM_DESCRIPTION )
164
- .setLanguage (DEFAULT_CODE_SYSTEM_LANGUAGE )
165
- .setToolingId (DEFAULT_CODE_SYSTEM_TOOLING_ID )
166
- .setOid (oid ).build (RestExtensions .USER , String .format ("New code system %s" , shortName ))
167
- .execute (bus ).getSync ();
176
+ CodeSystemRequests .prepareNewCodeSystem ()
177
+ .setId (shortName )
178
+ .setTitle (String .format ("%s - %s" , shortName , oid ))
179
+ .setUrl (SnomedTerminologyComponentConstants .SNOMED_URI_DEV + "/" + shortName )
180
+ .setDescription (DEFAULT_CODE_SYSTEM_DESCRIPTION )
181
+ .setLanguage (DEFAULT_CODE_SYSTEM_LANGUAGE )
182
+ .setToolingId (DEFAULT_CODE_SYSTEM_TOOLING_ID )
183
+ .setOid (oid )
184
+ .build (RestExtensions .USER , String .format ("New code system %s" , shortName ))
185
+ .execute (bus )
186
+ .getSync ();
168
187
}
169
188
170
- @ After
171
- public void deleteAllResources () {
172
- ResourceRequests
173
- .prepareSearch ()
174
- .buildAsync ()
175
- .execute (Services .bus ())
176
- .getSync (1 , TimeUnit .MINUTES )
177
- .forEach (resource -> {
178
- ResourceRequests
179
- .prepareDelete (resource .getId ())
180
- .build (RestExtensions .USER , "Delete " + resource .getId ())
181
- .execute (Services .bus ())
182
- .getSync (1 , TimeUnit .MINUTES );
183
- });
184
- }
185
-
186
189
@ Test
187
190
public void sortByResourceTypeAsc () {
188
191
final String id1 = "A" ;
@@ -217,8 +220,8 @@ public void sortByResourceTypeDesc() {
217
220
BundleApiAssert .createBundle (BundleApiAssert .prepareBundleCreateRequestBody (id4 ));
218
221
219
222
assertResourceSearch (ImmutableMap .of ("sort" , ImmutableList .of ("typeRank:desc" , "title:asc" )))
220
- .statusCode (200 )
221
- .body ("items.id" , Matchers .contains (id1 , id2 , id3 , id4 ));
223
+ .statusCode (200 )
224
+ .body ("items.id" , Matchers .contains (id1 , id2 , id3 , id4 ));
222
225
}
223
226
224
227
@ Test
@@ -239,4 +242,32 @@ public void expandPathLabels() {
239
242
.body ("resourcePathSegments" , Matchers .contains (IComponent .ROOT_ID , rootBundleId , subBundleId ))
240
243
.body ("resourcePathLabels" , Matchers .contains (ResourceConverter .ROOT_LABEL , "Bundle " + rootBundleId , "Bundle " + subBundleId ));
241
244
}
245
+
246
+ @ Test
247
+ public void createdAtAndUpdatedAt () throws Exception {
248
+ createDefaultCodeSystem (DEFAULT_CODE_SYSTEM_SHORT_NAME , DEFAULT_CODE_SYSTEM_OID );
249
+
250
+ // assert that createdAt and updatedAt values are the same after create
251
+ CodeSystem createdCodeSystem = assertResourceGet (DEFAULT_CODE_SYSTEM_SHORT_NAME )
252
+ .statusCode (200 )
253
+ .extract ()
254
+ .as (CodeSystem .class );
255
+ assertEquals (createdCodeSystem .getCreatedAt (), createdCodeSystem .getUpdatedAt ());
256
+
257
+ CommitResult updateResult = CodeSystemRequests .prepareUpdateCodeSystem (DEFAULT_CODE_SYSTEM_SHORT_NAME )
258
+ .setCopyright ("Updated copyright" )
259
+ .build (RestExtensions .USER , String .format ("Updated copyright %s" , DEFAULT_CODE_SYSTEM_SHORT_NAME ))
260
+ .execute (bus )
261
+ .getSync ();
262
+
263
+ // assert that createdAt and updatedAt values are the same after create
264
+ CodeSystem updatedCodeSystem = assertResourceGet (DEFAULT_CODE_SYSTEM_SHORT_NAME )
265
+ .statusCode (200 )
266
+ .extract ()
267
+ .as (CodeSystem .class );
268
+ // createdAt stays as is, but updatedAt got updated to a time after the marked value
269
+ assertEquals (createdCodeSystem .getCreatedAt (), updatedCodeSystem .getCreatedAt ());
270
+ assertEquals ((Long ) updateResult .getCommitTimestamp (), updatedCodeSystem .getUpdatedAt ());
271
+ }
272
+
242
273
}
0 commit comments