@@ -51,7 +51,7 @@ class SpreadsheetConfigCollectionIntegrationTest {
51
51
private SpreadsheetConfigCollectionRepository spreadsheetConfigCollectionRepository ;
52
52
53
53
@ AfterEach
54
- public void tearDown () {
54
+ void tearDown () {
55
55
spreadsheetConfigCollectionRepository .deleteAll ();
56
56
}
57
57
@@ -135,6 +135,22 @@ void testDuplicateCollection() throws Exception {
135
135
assertThat (duplicatedCollection .id ()).isNotEqualTo (collectionUuid );
136
136
}
137
137
138
+ @ Test
139
+ void testMergeModelsIntoNewCollection () throws Exception {
140
+ // create a first collection with 2 configs
141
+ SpreadsheetConfigCollectionInfos collectionToCreate = new SpreadsheetConfigCollectionInfos (null , createSpreadsheetConfigs ());
142
+ UUID collectionUuid = postSpreadsheetConfigCollection (collectionToCreate );
143
+ List <UUID > configIds = getSpreadsheetConfigCollection (collectionUuid ).spreadsheetConfigs ().stream ().map (SpreadsheetConfigInfos ::id ).toList ();
144
+ assertThat (configIds ).hasSize (2 );
145
+ // create a second collection duplicating + merging these existing Configs
146
+ UUID mergedCollectionUuid = postMergeSpreadsheetConfigsIntoCollection (configIds );
147
+ List <UUID > duplicatedConfigIds = getSpreadsheetConfigCollection (mergedCollectionUuid ).spreadsheetConfigs ().stream ().map (SpreadsheetConfigInfos ::id ).toList ();
148
+
149
+ assertThat (mergedCollectionUuid ).isNotEqualTo (collectionUuid );
150
+ assertThat (duplicatedConfigIds ).hasSameSizeAs (configIds );
151
+ assertThat (duplicatedConfigIds .stream ().sorted ().toList ()).isNotEqualTo (configIds .stream ().sorted ().toList ());
152
+ }
153
+
138
154
private List <SpreadsheetConfigInfos > createSpreadsheetConfigs () {
139
155
List <CustomColumnInfos > customColumnInfos = Arrays .asList (
140
156
new CustomColumnInfos ("cust_a" , ColumnType .NUMBER , 1 , "cust_b + cust_c" , "[\" cust_b\" , \" cust_c\" ]" , "idA" ),
@@ -184,6 +200,18 @@ private UUID postSpreadsheetConfigCollection(SpreadsheetConfigCollectionInfos co
184
200
return mapper .readValue (mvcPostResult .getResponse ().getContentAsString (), UUID .class );
185
201
}
186
202
203
+ private UUID postMergeSpreadsheetConfigsIntoCollection (List <UUID > configIds ) throws Exception {
204
+ String configIdsJson = mapper .writeValueAsString (configIds );
205
+
206
+ MvcResult mvcPostResult = mockMvc .perform (post (URI_SPREADSHEET_CONFIG_COLLECTION_BASE + "/merge" )
207
+ .content (configIdsJson )
208
+ .contentType (MediaType .APPLICATION_JSON ))
209
+ .andExpect (status ().isCreated ())
210
+ .andReturn ();
211
+
212
+ return mapper .readValue (mvcPostResult .getResponse ().getContentAsString (), UUID .class );
213
+ }
214
+
187
215
private UUID duplicateSpreadsheetConfigCollection (UUID collectionUuid ) throws Exception {
188
216
MvcResult mvcPostResult = mockMvc .perform (post (URI_SPREADSHEET_CONFIG_COLLECTION_BASE + "/duplicate" )
189
217
.queryParam ("duplicateFrom" , collectionUuid .toString ()))
0 commit comments