1212import org .folio .search .domain .dto .Contributor ;
1313import org .folio .search .domain .dto .Dates ;
1414import org .folio .search .domain .dto .Instance ;
15+ import org .folio .search .domain .dto .Metadata ;
1516import org .folio .spring .testing .type .IntegrationTest ;
1617import org .folio .support .base .BaseIntegrationTest ;
1718import org .junit .jupiter .api .AfterAll ;
2122@ IntegrationTest
2223class SortInstanceIT extends BaseIntegrationTest {
2324
25+ private static final String ID_ANIMAL_FARM = randomId ();
26+ private static final String ID_ZERO_MINUS_TEN = randomId ();
27+ private static final String ID_CALLING_ME_HOME = randomId ();
28+ private static final String ID_WALK_IN_MY_SOUL = randomId ();
29+ private static final String ID_STAR_WARS = randomId ();
30+
2431 @ BeforeAll
2532 static void prepare () {
2633 setUpTenant (instances ());
@@ -91,6 +98,50 @@ void canSortInstancesByTitle_desc() throws Exception {
9198 .andExpect (jsonPath ("instances[4].title" , is ("Calling Me Home" )));
9299 }
93100
101+ @ Test
102+ void canSortInstancesByMetadataCreatedDate_asc () throws Exception {
103+ doSearchByInstances (allRecordsSortedBy ("metadata.createdDate" , ASCENDING ))
104+ .andExpect (jsonPath ("totalRecords" , is (5 )))
105+ .andExpect (jsonPath ("instances[0].id" , is (ID_ANIMAL_FARM )))
106+ .andExpect (jsonPath ("instances[1].id" , is (ID_ZERO_MINUS_TEN )))
107+ .andExpect (jsonPath ("instances[2].id" , is (ID_CALLING_ME_HOME )))
108+ .andExpect (jsonPath ("instances[3].id" , is (ID_WALK_IN_MY_SOUL )))
109+ .andExpect (jsonPath ("instances[4].id" , is (ID_STAR_WARS )));
110+ }
111+
112+ @ Test
113+ void canSortInstancesByMetadataCreatedDate_desc () throws Exception {
114+ doSearchByInstances (allRecordsSortedBy ("metadata.createdDate" , DESCENDING ))
115+ .andExpect (jsonPath ("totalRecords" , is (5 )))
116+ .andExpect (jsonPath ("instances[0].id" , is (ID_STAR_WARS )))
117+ .andExpect (jsonPath ("instances[1].id" , is (ID_WALK_IN_MY_SOUL )))
118+ .andExpect (jsonPath ("instances[2].id" , is (ID_CALLING_ME_HOME )))
119+ .andExpect (jsonPath ("instances[3].id" , is (ID_ZERO_MINUS_TEN )))
120+ .andExpect (jsonPath ("instances[4].id" , is (ID_ANIMAL_FARM )));
121+ }
122+
123+ @ Test
124+ void canSortInstancesByMetadataUpdatedDate_asc () throws Exception {
125+ doSearchByInstances (allRecordsSortedBy ("metadata.updatedDate" , ASCENDING ))
126+ .andExpect (jsonPath ("totalRecords" , is (5 )))
127+ .andExpect (jsonPath ("instances[0].id" , is (ID_ANIMAL_FARM )))
128+ .andExpect (jsonPath ("instances[1].id" , is (ID_ZERO_MINUS_TEN )))
129+ .andExpect (jsonPath ("instances[2].id" , is (ID_CALLING_ME_HOME )))
130+ .andExpect (jsonPath ("instances[3].id" , is (ID_WALK_IN_MY_SOUL )))
131+ .andExpect (jsonPath ("instances[4].id" , is (ID_STAR_WARS )));
132+ }
133+
134+ @ Test
135+ void canSortInstancesByMetadataUpdatedDate_desc () throws Exception {
136+ doSearchByInstances (allRecordsSortedBy ("metadata.updatedDate" , DESCENDING ))
137+ .andExpect (jsonPath ("totalRecords" , is (5 )))
138+ .andExpect (jsonPath ("instances[0].id" , is (ID_STAR_WARS )))
139+ .andExpect (jsonPath ("instances[1].id" , is (ID_WALK_IN_MY_SOUL )))
140+ .andExpect (jsonPath ("instances[2].id" , is (ID_CALLING_ME_HOME )))
141+ .andExpect (jsonPath ("instances[3].id" , is (ID_ZERO_MINUS_TEN )))
142+ .andExpect (jsonPath ("instances[4].id" , is (ID_ANIMAL_FARM )));
143+ }
144+
94145 @ Test
95146 void search_negative_invalidSortOption () throws Exception {
96147 attemptSearchByInstances (allRecordsSortedBy ("unknownSort" , DESCENDING )).andExpect (
@@ -103,35 +154,52 @@ void search_negative_invalidSortOption() throws Exception {
103154 }
104155
105156 private static Instance [] instances () {
106- var instances = new Instance [] {getSemanticWeb ().id (randomId ()).contributors (new ArrayList <>()),
107- getSemanticWeb ().id (randomId ()).contributors (new ArrayList <>()),
108- getSemanticWeb ().id (randomId ()).contributors (new ArrayList <>()),
109- getSemanticWeb ().id (randomId ()).contributors (new ArrayList <>()),
110- getSemanticWeb ().id (randomId ()).contributors (new ArrayList <>())};
111-
157+ var instances = new Instance [] {
158+ getSemanticWeb ().id (ID_ANIMAL_FARM ).contributors (new ArrayList <>()),
159+ getSemanticWeb ().id (ID_ZERO_MINUS_TEN ).contributors (new ArrayList <>()),
160+ getSemanticWeb ().id (ID_CALLING_ME_HOME ).contributors (new ArrayList <>()),
161+ getSemanticWeb ().id (ID_WALK_IN_MY_SOUL ).contributors (new ArrayList <>()),
162+ getSemanticWeb ().id (ID_STAR_WARS ).contributors (new ArrayList <>())
163+ };
112164 instances [0 ].title ("Animal farm" )
113165 .indexTitle ("B1 Animal farm" )
114166 .addContributorsItem (new Contributor ().name ("yyy zzz" ))
115- .setDates (getDates ("1999" , "2000" ));
167+ .dates (getDates ("1999" , "2000" ))
168+ .metadata (new Metadata ()
169+ .createdDate ("2021-01-01T10:00:00.000+00:00" )
170+ .updatedDate ("2021-01-15T10:00:00.000+00:00" ));
116171
117172 instances [1 ].title ("Zero Minus Ten" )
118173 .indexTitle (null )
119174 .addContributorsItem (new Contributor ().name ("aaa bbb" ).primary (false ))
120175 .addContributorsItem (new Contributor ().name ("bbb ccc" ).primary (true ))
121- .setDates (getDates ("199u" , "2000" ));
176+ .dates (getDates ("199u" , "2000" ))
177+ .metadata (new Metadata ()
178+ .createdDate ("2021-02-01T10:00:00.000+00:00" )
179+ .updatedDate ("2021-02-15T10:00:00.000+00:00" ));
122180
123181 instances [2 ].title ("Calling Me Home" )
124182 .indexTitle ("A1 Calling Me Home" )
125183 .addContributorsItem (new Contributor ().name ("bcc ccc" ))
126- .setDates (getDates ("2021" , "2022" ));
184+ .dates (getDates ("2021" , "2022" ))
185+ .metadata (new Metadata ()
186+ .createdDate ("2021-03-01T10:00:00.000+00:00" )
187+ .updatedDate ("2021-03-15T10:00:00.000+00:00" ));
127188
128189 instances [3 ].title ("Walk in My Soul" )
129190 .indexTitle (null )
130191 .addContributorsItem (new Contributor ().name ("1111 2222" ).primary (true ))
131- .setDates (getDates ("2001" , "2002" ));
132-
133- instances [4 ].title ("Star Wars" ).indexTitle (null ).addContributorsItem (new Contributor ().name ("Śląsk" ).primary (true ))
134- .setDates (getDates ("19u5" , "1998" ));
192+ .dates (getDates ("2001" , "2002" ))
193+ .metadata (new Metadata ()
194+ .createdDate ("2021-04-01T10:00:00.000+00:00" )
195+ .updatedDate ("2021-04-15T10:00:00.000+00:00" ));
196+
197+ instances [4 ].title ("Star Wars" ).indexTitle (null )
198+ .addContributorsItem (new Contributor ().name ("Śląsk" ).primary (true ))
199+ .dates (getDates ("19u5" , "1998" ))
200+ .metadata (new Metadata ()
201+ .createdDate ("2021-05-01T10:00:00.000+00:00" )
202+ .updatedDate ("2021-05-15T10:00:00.000+00:00" ));
135203
136204 return instances ;
137205 }
0 commit comments