ce97ec63a11122dff6dd68db597351fa7ab1838c
[smo/teiv.git] /
1 /*
2  *  ============LICENSE_START=======================================================
3  *  Copyright (C) 2024 Ericsson
4  *  Modifications Copyright (C) 2024 OpenInfra Foundation Europe
5  *  ================================================================================
6  *  Licensed under the Apache License, Version 2.0 (the "License");
7  *  you may not use this file except in compliance with the License.
8  *  You may obtain a copy of the License at
9  *
10  *        http://www.apache.org/licenses/LICENSE-2.0
11  *
12  *  Unless required by applicable law or agreed to in writing, software
13  *  distributed under the License is distributed on an "AS IS" BASIS,
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  *  See the License for the specific language governing permissions and
16  *  limitations under the License.
17  *
18  *  SPDX-License-Identifier: Apache-2.0
19  *  ============LICENSE_END=========================================================
20  */
21 package org.oran.smo.teiv.pgsqlgenerator.schema;
22
23 import org.oran.smo.teiv.pgsqlgenerator.Table;
24 import org.oran.smo.teiv.pgsqlgenerator.Column;
25 import org.oran.smo.teiv.pgsqlgenerator.PrimaryKeyConstraint;
26 import org.oran.smo.teiv.pgsqlgenerator.PgSchemaGeneratorException;
27 import org.oran.smo.teiv.pgsqlgenerator.UniqueConstraint;
28 import org.oran.smo.teiv.pgsqlgenerator.Relationship;
29
30 import org.junit.jupiter.api.Assertions;
31 import org.junit.jupiter.api.Test;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.boot.test.context.SpringBootTest;
34
35 import java.util.List;
36
37 @SpringBootTest(classes = { BackwardCompatibilityChecker.class }, properties = { "green-field-installation=false" })
38 class BackwardCompatibilityCheckerTest {
39
40     @Autowired
41     private BackwardCompatibilityChecker nbcChecker;
42
43     //spotless:off
44
45     private List<Table> mockModelServiceEntities = List.of(
46             Table.builder().name("Sector").columns(
47                 List.of(
48                         Column.builder().name("azimuth").dataType("DECIMAL").build(),
49                         Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
50                                 PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id")
51                                         .columnToAddConstraintTo("id").build())).build(),
52                         Column.builder().name("sectorId").dataType("jsonb").defaultValue("101").build(),
53                         Column.builder().name("geo-location").dataType("geography").build())).build(),
54             Table.builder().name("Namespace").columns(
55                 List.of(
56                         Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
57                                 PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
58                                         .columnToAddConstraintTo("id").build())).build(),
59                         Column.builder().name("name").dataType("TEXT").build())).build());
60
61     //Data:Entities
62     @Test
63     void verifyExceptionThrownOnDeletedTableWhenGreenfieldDisabledTest()  {
64
65         // When - baseline
66         List<Table> mockBaselineEntities = List.of(
67                 Table.builder().name("Sector").columns(
68                     List.of(
69                             Column.builder().name("azimuth").dataType("DECIMAL").build(),
70                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
71                                     PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id")
72                                             .columnToAddConstraintTo("id").build())).build(),
73                             Column.builder().name("sectorId").dataType("jsonb").defaultValue("101").build(),
74                             Column.builder().name("geo-location").dataType("geography").build())).build(),
75                 Table.builder().name("Namespace").columns(
76                     List.of(
77                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
78                                     PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
79                                             .columnToAddConstraintTo("id").build())).build(),
80                             Column.builder().name("name").dataType("TEXT").build())).build(),
81                 Table.builder().name("NRCellDU").columns(
82                     List.of(
83                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
84                                     PrimaryKeyConstraint.builder().tableName("NRCellDU").constraintName("PK_NRCellDU_id")
85                                             .columnToAddConstraintTo("id").build())).build(),
86                             Column.builder().name("name").dataType("TEXT").build())).build());
87
88         //Then
89         Assertions.assertEquals(
90                 String.format("NBC change has been introduced: modified/removed table(NRCellDU) present in baseline, please make sure you've enabled green-field installation!!%nFor more info please refer to README"),
91                 Assertions.assertThrowsExactly(PgSchemaGeneratorException.class, () -> nbcChecker.checkForNBCChangesInData(
92                         mockBaselineEntities, mockModelServiceEntities)).getMessage());
93
94     }
95
96     @Test
97     void verifyExceptionThrownOnDeletedColumnWhenGreenfieldDisabledTest()  {
98
99         // Given baseline
100         List<Table> mockBaselineEntities = List.of(
101                 Table.builder().name("Sector").columns(
102                     List.of(
103                             Column.builder().name("azimuth").dataType("DECIMAL").build(),
104                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
105                                     PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id")
106                                             .columnToAddConstraintTo("id").build())).build(),
107                             Column.builder().name("sectorId").dataType("jsonb").defaultValue("101").build(),
108                             Column.builder().name("geo-location").dataType("geography").build())).build(),
109                 Table.builder().name("Namespace").columns(
110                     List.of(
111                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
112                                     PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
113                                             .columnToAddConstraintTo("id").build())).build(),
114                             Column.builder().name("name").dataType("TEXT").build())).build(),
115                 Table.builder().name("NRCellDU").columns(
116                     List.of(
117                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
118                                     PrimaryKeyConstraint.builder().tableName("NRCellDU").constraintName("PK_NRCellDU_id")
119                                             .columnToAddConstraintTo("id").build())).build(),
120                             Column.builder().name("name").dataType("TEXT").build())).build());
121
122         // When - entities from Model svc with Sector.sectorId deleted
123         mockModelServiceEntities = List.of(
124                 Table.builder().name("Sector").columns(
125                     List.of(
126                             Column.builder().name("azimuth").dataType("DECIMAL").build(),
127                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
128                                     PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id")
129                                             .columnToAddConstraintTo("id").build())).build(),
130                             Column.builder().name("geo-location").dataType("geography").build())).build(),
131                 Table.builder().name("Namespace").columns(
132                     List.of(
133                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
134                                     PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
135                                             .columnToAddConstraintTo("id").build())).build(),
136                             Column.builder().name("name").dataType("TEXT").build())).build(),
137                 Table.builder().name("NRCellDU").columns(
138                     List.of(
139                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
140                                     PrimaryKeyConstraint.builder().tableName("NRCellDU").constraintName("PK_NRCellDU_id")
141                                             .columnToAddConstraintTo("id").build())).build(),
142                             Column.builder().name("name").dataType("TEXT").build())).build());
143
144         //Then
145         Assertions.assertEquals(
146                 String.format("NBC change has been introduced: modified/removed column(Sector.sectorId) present in baseline, please make sure you've enabled green-field installation!!%nFor more info please refer to README"),
147                 Assertions.assertThrowsExactly(PgSchemaGeneratorException.class, () -> nbcChecker.checkForNBCChangesInData(
148                         mockBaselineEntities, mockModelServiceEntities)).getMessage());
149
150     }
151
152     @Test
153     void verifyExceptionThrownOnColumnNameModifiedWhenGreenfieldDisabledTest()  {
154         // rename column name
155         // Given baseline
156         List<Table> mockBaselineEntities = List.of(
157                 Table.builder().name("Sector").columns(
158                     List.of(
159                             Column.builder().name("azimuth").dataType("DECIMAL").build(),
160                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
161                                     PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id")
162                                             .columnToAddConstraintTo("id").build())).build(),
163                             Column.builder().name("sectorId").dataType("jsonb").defaultValue("101").build(),
164                             Column.builder().name("geo-location").dataType("geography").build())).build(),
165                 Table.builder().name("Namespace").columns(
166                     List.of(
167                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
168                                     PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
169                                             .columnToAddConstraintTo("id").build())).build(),
170                             Column.builder().name("name").dataType("TEXT").build())).build(),
171                 Table.builder().name("NRCellDU").columns(
172                     List.of(
173                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
174                                     PrimaryKeyConstraint.builder().tableName("NRCellDU").constraintName("PK_NRCellDU_id")
175                                             .columnToAddConstraintTo("id").build())).build(),
176                             Column.builder().name("name").dataType("TEXT").build())).build());
177
178         // When - entities from Model svc with renamed column name
179         mockModelServiceEntities = List.of(
180                 Table.builder().name("Sector").columns(
181                     List.of(
182                             Column.builder().name("azimuth").dataType("DECIMAL").build(),
183                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
184                                     PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id")
185                                             .columnToAddConstraintTo("id").build())).build(),
186                             Column.builder().name("sectorId123").dataType("jsonb").defaultValue("101").build(),
187                             Column.builder().name("geo-location").dataType("geography").build())).build(),
188                 Table.builder().name("Namespace").columns(
189                     List.of(
190                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
191                                     PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
192                                             .columnToAddConstraintTo("id").build())).build(),
193                             Column.builder().name("name").dataType("TEXT").build())).build(),
194                 Table.builder().name("NRCellDU").columns(
195                     List.of(
196                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
197                                     PrimaryKeyConstraint.builder().tableName("NRCellDU").constraintName("PK_NRCellDU_id")
198                                             .columnToAddConstraintTo("id").build())).build(),
199                             Column.builder().name("name").dataType("TEXT").build())).build());
200
201         //Then
202         Assertions.assertEquals(
203                 String.format("NBC change has been introduced: modified/removed column(Sector.sectorId) present in baseline, please make sure you've enabled green-field installation!!%nFor more info please refer to README"),
204                 Assertions.assertThrowsExactly(PgSchemaGeneratorException.class, () -> nbcChecker.checkForNBCChangesInData(
205                         mockBaselineEntities, mockModelServiceEntities)).getMessage());
206     }
207
208     @Test
209     void verifyExceptionThrownOnColumnDataModifiedWhenGreenfieldDisabledTest()  {
210         // Given baseline
211         List<Table> mockBaselineEntities = List.of(
212                 Table.builder().name("Sector").columns(
213                     List.of(
214                             Column.builder().name("azimuth").dataType("DECIMAL").build(),
215                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
216                                     PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id")
217                                             .columnToAddConstraintTo("id").build())).build(),
218                             Column.builder().name("sectorId").dataType("jsonb").defaultValue("101").build(),
219                             Column.builder().name("geo-location").dataType("geography").build())).build(),
220                 Table.builder().name("Namespace").columns(
221                     List.of(
222                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
223                                     PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
224                                             .columnToAddConstraintTo("id").build())).build(),
225                             Column.builder().name("name").dataType("TEXT").build())).build(),
226                 Table.builder().name("NRCellDU").columns(
227                     List.of(
228                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
229                                     PrimaryKeyConstraint.builder().tableName("NRCellDU").constraintName("PK_NRCellDU_id")
230                                             .columnToAddConstraintTo("id").build())).build(),
231                             Column.builder().name("name").dataType("TEXT").build())).build());
232
233         // When - entities from Model svc with modified column datatype
234         mockModelServiceEntities = List.of(
235                 Table.builder().name("Sector").columns(
236                     List.of(
237                             Column.builder().name("azimuth").dataType("DECIMAL").build(),
238                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
239                                     PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id")
240                                             .columnToAddConstraintTo("id").build())).build(),
241                             Column.builder().name("sectorId").dataType("jsonb").defaultValue("101").build(),
242                             Column.builder().name("geo-location").dataType("geography").build())).build(),
243                 Table.builder().name("Namespace").columns(
244                     List.of(
245                             Column.builder().name("id").dataType("SMALLINT").postgresConstraints(List.of(
246                                     PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
247                                             .columnToAddConstraintTo("id").build())).build(),
248                             Column.builder().name("name").dataType("TEXT").build())).build(),
249                 Table.builder().name("NRCellDU").columns(
250                     List.of(
251                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
252                                     PrimaryKeyConstraint.builder().tableName("NRCellDU").constraintName("PK_NRCellDU_id")
253                                             .columnToAddConstraintTo("id").build())).build(),
254                             Column.builder().name("name").dataType("TEXT").build())).build());
255
256         // Then
257         Assertions.assertEquals(
258                 String.format("NBC change has been introduced: modified/removed datatype for column(Namespace.id) present in baseline, please make sure you've enabled green-field installation!!%nFor more info please refer to README"),
259                 Assertions.assertThrowsExactly(PgSchemaGeneratorException.class, () -> nbcChecker.checkForNBCChangesInData(
260                         mockBaselineEntities, mockModelServiceEntities)).getMessage());
261     }
262
263     @Test
264     void verifyExceptionThrownOnColumnConstraintModifiedWhenGreenfieldDisabledTest()  {
265
266         // Given baseline
267         List<Table> mockBaselineEntities = List.of(
268                 Table.builder().name("Sector").columns(
269                     List.of(
270                             Column.builder().name("azimuth").dataType("DECIMAL").build(),
271                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
272                                     PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id")
273                                             .columnToAddConstraintTo("id").build())).build(),
274                             Column.builder().name("sectorId").dataType("jsonb").defaultValue("101").build(),
275                             Column.builder().name("geo-location").dataType("geography").build())).build(),
276                 Table.builder().name("Namespace").columns(
277                     List.of(
278                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
279                                     PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
280                                             .columnToAddConstraintTo("id").build())).build(),
281                             Column.builder().name("name").dataType("TEXT").build())).build(),
282                 Table.builder().name("NRCellDU").columns(
283                     List.of(
284                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
285                                     PrimaryKeyConstraint.builder().tableName("NRCellDU").constraintName("PK_NRCellDU_id")
286                                             .columnToAddConstraintTo("id").build())).build(),
287                             Column.builder().name("name").dataType("TEXT").build())).build());
288
289         // When - entities from Model svc with modified column constraints
290         mockModelServiceEntities = List.of(
291                 Table.builder().name("Sector").columns(
292                     List.of(
293                             Column.builder().name("azimuth").dataType("DECIMAL").build(),
294                             Column.builder().name("id").dataType("VARCHAR(511)").build(),
295                             Column.builder().name("sectorId").dataType("jsonb").defaultValue("101").build(),
296                             Column.builder().name("geo-location").dataType("geography").build())).build(),
297                 Table.builder().name("Namespace").columns(
298                     List.of(
299                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
300                                     PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
301                                             .columnToAddConstraintTo("id").build())).build(),
302                             Column.builder().name("name").dataType("TEXT").build())).build(),
303                 Table.builder().name("NRCellDU").columns(
304                     List.of(
305                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
306                                     PrimaryKeyConstraint.builder().tableName("NRCellDU").constraintName("PK_NRCellDU_id")
307                                             .columnToAddConstraintTo("id").build())).build(),
308                             Column.builder().name("name").dataType("TEXT").build())).build());
309
310         // Then
311         Assertions.assertEquals(
312                 String.format("NBC change has been introduced: modified/removed constraint for column(Sector.id) present in baseline, please make sure you've enabled green-field installation!!%nFor more info please refer to README"),
313                 Assertions.assertThrowsExactly(PgSchemaGeneratorException.class, () -> nbcChecker.checkForNBCChangesInData(
314                         mockBaselineEntities, mockModelServiceEntities)).getMessage());
315
316         // When - entities from Model svc with Sector.id's pk constraint name changed
317         mockModelServiceEntities = List.of(
318                 Table.builder().name("Sector").columns(
319                         List.of(
320                                 Column.builder().name("azimuth").dataType("DECIMAL").build(),
321                                 Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
322                                         PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id_123")
323                                                 .columnToAddConstraintTo("id").build())).build(),
324                                 Column.builder().name("sectorId").dataType("jsonb").defaultValue("101").build(),
325                                 Column.builder().name("geo-location").dataType("geography").build())).build(),
326                 Table.builder().name("Namespace").columns(
327                         List.of(
328                                 Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
329                                         PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
330                                                 .columnToAddConstraintTo("id").build())).build(),
331                                 Column.builder().name("name").dataType("TEXT").build())).build(),
332                 Table.builder().name("NRCellDU").columns(
333                         List.of(
334                                 Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
335                                         PrimaryKeyConstraint.builder().tableName("NRCellDU").constraintName("PK_NRCellDU_id")
336                                                 .columnToAddConstraintTo("id").build())).build(),
337                                 Column.builder().name("name").dataType("TEXT").build())).build());
338
339         // Then
340         Assertions.assertEquals(
341                 String.format("NBC change has been introduced: modified/removed constraint for column(Sector.id) present in baseline, please make sure you've enabled green-field installation!!%nFor more info please refer to README"),
342                 Assertions.assertThrowsExactly(PgSchemaGeneratorException.class, () -> nbcChecker.checkForNBCChangesInData(
343                         mockBaselineEntities, mockModelServiceEntities)).getMessage());
344
345     }
346
347     //Data:Relationships
348     @Test
349     void verifyExceptionThrownOnModifiedRelationshipCardinalityWhenGreenfieldDisabledTest() {
350         // Given
351         // ONE_TO_ONE
352         List<Table> mockBaselineEntities = List.of(
353                 Table.builder().name("Sector").columns(
354                     List.of(
355                             Column.builder().name("azimuth").dataType("DECIMAL").build(),
356                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
357                                     PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id")
358                                             .columnToAddConstraintTo("id").build())).build(),
359                             Column.builder().name("sectorId").dataType("jsonb").defaultValue("101").build(),
360                             Column.builder().name("geo-location").dataType("geography").build(),
361                             Column.builder().name("REL_FK_managed-Namespace").dataType("VARCHAR(511)").postgresConstraints(List.of()).build(),
362                             Column.builder().name("REL_ID_SECTOR_MANAGES_NAMESPACE").dataType("VARCHAR(511)").postgresConstraints(List.of(
363                                     UniqueConstraint.builder().constraintName("UNIQUE_Sector_REL_ID_SECTOR_MANAGES_NAMESPACE").tableName("Sector")
364                                             .columnToAddConstraintTo("REL_ID_SECTOR_MANAGES_NAMESPACE").build())).build())).build(),
365                 Table.builder().name("Namespace").columns(
366                     List.of(
367                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
368                                     PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
369                                             .columnToAddConstraintTo("id").build())).build(),
370                             Column.builder().name("name").dataType("TEXT").build())).build());
371
372         // When
373         // Changing SECTOR_MANAGES_NAMESPACE from ONE_TO_ONE to ONE_TO_MANY
374         mockModelServiceEntities = List.of(
375                 Table.builder().name("Sector").columns(
376                     List.of(
377                             Column.builder().name("azimuth").dataType("DECIMAL").build(),
378                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
379                                     PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id")
380                                             .columnToAddConstraintTo("id").build())).build(),
381                             Column.builder().name("sectorId").dataType("jsonb").defaultValue("101").build(),
382                             Column.builder().name("geo-location").dataType("geography").build())).build(),
383                 Table.builder().name("Namespace").columns(
384                     List.of(
385                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
386                                     PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
387                                             .columnToAddConstraintTo("id").build())).build(),
388                             Column.builder().name("name").dataType("TEXT").build(),
389                             Column.builder().name("REL_FK_managed-by-Sector").dataType("VARCHAR(511)").postgresConstraints(List.of()).build(),
390                             Column.builder().name("REL_ID_SECTOR_MANAGES_NAMESPACE").dataType("VARCHAR(511)").postgresConstraints(List.of(
391                                     UniqueConstraint.builder().constraintName("UNIQUE_Namespace_REL_ID_SECTOR_MANAGES_NAMESPACE").tableName("Namespace")
392                                             .columnToAddConstraintTo("REL_ID_SECTOR_MANAGES_NAMESPACE").build())).build())).build());
393
394         // Then
395         Assertions.assertEquals(
396                 String.format("NBC change has been introduced: modified/removed column(Sector.REL_FK_managed-Namespace) present in baseline, please make sure you've enabled green-field installation!!%nFor more info please refer to README"),
397                 Assertions.assertThrowsExactly(PgSchemaGeneratorException.class, () -> nbcChecker.checkForNBCChangesInData(
398                         mockBaselineEntities, mockModelServiceEntities)).getMessage());
399
400         // When
401         // Changing SECTOR_MANAGES_NAMESPACE rel from ONE_TO_ONE to MANY_TO_MANY
402         mockModelServiceEntities = List.of(
403                 Table.builder().name("Sector").columns(
404                     List.of(
405                             Column.builder().name("azimuth").dataType("DECIMAL").build(),
406                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
407                                     PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id")
408                                             .columnToAddConstraintTo("id").build())).build(),
409                             Column.builder().name("sectorId").dataType("jsonb").defaultValue("101").build(),
410                             Column.builder().name("geo-location").dataType("geography").build())).build(),
411                 Table.builder().name("Namespace").columns(
412                     List.of(
413                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
414                                     PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
415                                             .columnToAddConstraintTo("id").build())).build(),
416                             Column.builder().name("name").dataType("TEXT").build())).build(),
417                 Table.builder().name("SECTOR_MANAGES_NAMESPACE").columns(
418                         List.of(
419                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
420                                     PrimaryKeyConstraint.builder().tableName("SECTOR_MANAGES_NAMESPACE").constraintName("PK_SECTOR_MANAGES_NAMESPACE_id")
421                                             .columnToAddConstraintTo("id").build())).build(),
422                             Column.builder().name("aSide_Sector").dataType("VARCHAR(511)").postgresConstraints(List.of(
423                                     UniqueConstraint.builder().constraintName("FK_SECTOR_MANAGES_NAMESPACE_aSide_Sector")
424                                             .tableName("SECTOR_MANAGES_NAMESPACE").columnToAddConstraintTo("aSide_Sector").build())).build(),
425                             Column.builder().name("bSide_Namespace").dataType("VARCHAR(511)").postgresConstraints(List.of(
426                                     UniqueConstraint.builder().constraintName("FK_SECTOR_MANAGES_NAMESPACE_bSide_Namespace")
427                                             .tableName("SECTOR_MANAGES_NAMESPACE").columnToAddConstraintTo("bSide_Namespace").build())).build())).build());
428
429         // Then
430         Assertions.assertEquals(
431                 String.format("NBC change has been introduced: modified/removed column(Sector.REL_FK_managed-Namespace) present in baseline, please make sure you've enabled green-field installation!!%nFor more info please refer to README"),
432                 Assertions.assertThrowsExactly(PgSchemaGeneratorException.class, () -> nbcChecker.checkForNBCChangesInData(
433                         mockBaselineEntities, mockModelServiceEntities)).getMessage());
434
435
436         // Given
437         // Changing SECTOR_MANAGES_NAMESPACE rel from ONE_TO_MANY to ONE_TO_ONE - Changing cardinality
438         List<Table> mockBaseline = List.of(
439                 Table.builder().name("Sector").columns(
440                         List.of(
441                             Column.builder().name("azimuth").dataType("DECIMAL").build(),
442                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
443                                     PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id")
444                                             .columnToAddConstraintTo("id").build())).build(),
445                             Column.builder().name("sectorId").dataType("jsonb").defaultValue("101").build(),
446                             Column.builder().name("geo-location").dataType("geography").build())).build(),
447                 Table.builder().name("Namespace").columns(
448                         List.of(
449                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
450                                     PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
451                                             .columnToAddConstraintTo("id").build())).build(),
452                             Column.builder().name("name").dataType("TEXT").build(),
453                             Column.builder().name("REL_FK_managed-by-Sector").dataType("VARCHAR(511)").postgresConstraints(List.of()).build(),
454                             Column.builder().name("REL_ID_SECTOR_MANAGES_NAMESPACE").dataType("VARCHAR(511)").postgresConstraints(List.of(
455                                     UniqueConstraint.builder().constraintName("UNIQUE_Namespace_REL_ID_SECTOR_MANAGES_NAMESPACE").tableName("Namespace")
456                                             .columnToAddConstraintTo("REL_ID_SECTOR_MANAGES_NAMESPACE").build())).build())).build());
457
458         // When
459         mockModelServiceEntities = List.of(
460                 Table.builder().name("Sector").columns(
461                         List.of(
462                             Column.builder().name("azimuth").dataType("DECIMAL").build(),
463                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
464                                     PrimaryKeyConstraint.builder().tableName("Sector").constraintName("PK_Source_id")
465                                             .columnToAddConstraintTo("id").build())).build(),
466                             Column.builder().name("sectorId").dataType("jsonb").defaultValue("101").build(),
467                             Column.builder().name("geo-location").dataType("geography").build(),
468                             Column.builder().name("REL_FK_managed-Namespace").dataType("VARCHAR(511)").postgresConstraints(List.of()).build(),
469                             Column.builder().name("REL_ID_SECTOR_MANAGES_NAMESPACE").dataType("VARCHAR(511)").postgresConstraints(List.of(
470                                     UniqueConstraint.builder().constraintName("UNIQUE_Sector_REL_ID_SECTOR_MANAGES_NAMESPACE").tableName("Sector")
471                                             .columnToAddConstraintTo("REL_ID_SECTOR_MANAGES_NAMESPACE").build())).build())).build(),
472                 Table.builder().name("Namespace").columns(
473                         List.of(
474                             Column.builder().name("id").dataType("VARCHAR(511)").postgresConstraints(List.of(
475                                     PrimaryKeyConstraint.builder().tableName("Namespace").constraintName("PK_Namespace_id")
476                                             .columnToAddConstraintTo("id").build())).build(),
477                             Column.builder().name("name").dataType("TEXT").build())).build());
478
479         // Then
480         Assertions.assertEquals(
481                 String.format("NBC change has been introduced: modified/removed column(Namespace.REL_FK_managed-by-Sector) present in baseline, please make sure you've enabled green-field installation!!%nFor more info please refer to README"),
482                 Assertions.assertThrowsExactly(PgSchemaGeneratorException.class, () -> nbcChecker.checkForNBCChangesInData(
483                         mockBaseline, mockModelServiceEntities)).getMessage());
484     }
485
486     //Model
487     @Test
488     void verifyExceptionThrownOnChangingRelAttributesWhenGreenfieldDisabledTest() {
489
490         //from ONE_TO_ONE to MANY_TO_ONE
491         //Given
492         List<Relationship> baselineRel = List.of(
493                 Relationship.builder().name("ENODEBFUNCTION_PROVIDES_LTESECTORCARRIER")
494                         .aSideAssociationName("provided-lteSectorCarrier")
495                         .aSideMOType("ENodeBFunction")
496                         .aSideMinCardinality(0)
497                         .aSideMaxCardinality(1)
498                         .bSideAssociationName("provided-by-enodebFunction")
499                         .bSideMOType("LTESectorCarrier")
500                         .bSideMinCardinality(0)
501                         .bSideMaxCardinality(1)
502                         .associationKind("BI_DIRECTIONAL")
503                         .relationshipDataLocation("B_SIDE")
504                         .connectSameEntity(false)
505                         .moduleReferenceName("o-ran-smo-teiv-ran").build());
506         //When
507         List<Relationship> mockModelSvcRel1 = List.of(
508                 Relationship.builder().name("ENODEBFUNCTION_PROVIDES_LTESECTORCARRIER")
509                         .aSideAssociationName("provided-lteSectorCarrier")
510                         .aSideMOType("ENodeBFunction")
511                         .aSideMinCardinality(0)
512                         .aSideMaxCardinality(100)
513                         .bSideAssociationName("provided-by-enodebFunction")
514                         .bSideMOType("LTESectorCarrier")
515                         .bSideMinCardinality(0)
516                         .bSideMaxCardinality(1)
517                         .associationKind("BI_DIRECTIONAL")
518                         .relationshipDataLocation("A_SIDE")
519                         .connectSameEntity(false)
520                         .moduleReferenceName("o-ran-smo-teiv-ran").build());
521         //Then
522         Assertions.assertEquals(
523                 String.format("NBC change has been introduced: modified cardinalities for relationship(ENODEBFUNCTION_PROVIDES_LTESECTORCARRIER), please make sure you've enabled green-field installation!!%nFor more info please refer to README"),
524                 Assertions.assertThrowsExactly(PgSchemaGeneratorException.class, () -> nbcChecker.checkForNBCChangesInModel(
525                         baselineRel, mockModelSvcRel1)).getMessage());
526
527         //from ONE_TO_ONE to MANY_TO_MANY
528         //When
529         List<Relationship> mockModelSvcRel2 = List.of(
530                 Relationship.builder().name("ENODEBFUNCTION_PROVIDES_LTESECTORCARRIER")
531                         .aSideAssociationName("provided-lteSectorCarrier")
532                         .aSideMOType("ENodeBFunction")
533                         .aSideMinCardinality(1)
534                         .aSideMaxCardinality(100)
535                         .bSideAssociationName("provided-by-enodebFunction")
536                         .bSideMOType("LTESectorCarrier")
537                         .bSideMinCardinality(0)
538                         .bSideMaxCardinality(100)
539                         .associationKind("BI_DIRECTIONAL")
540                         .relationshipDataLocation("A_SIDE")
541                         .connectSameEntity(false)
542                         .moduleReferenceName("o-ran-smo-teiv-ran").build());
543         //Then
544         Assertions.assertEquals(
545                 String.format("NBC change has been introduced: modified cardinalities for relationship(ENODEBFUNCTION_PROVIDES_LTESECTORCARRIER), please make sure you've enabled green-field installation!!%nFor more info please refer to README"),
546                 Assertions.assertThrowsExactly(PgSchemaGeneratorException.class, () -> nbcChecker.checkForNBCChangesInModel(
547                         baselineRel, mockModelSvcRel2)).getMessage());
548
549         //Change aSide and bSide
550         //When
551         List<Relationship> mockModelSvcRel3 = List.of(
552                 Relationship.builder().name("LTESECTORCARRIER_PROVIDES_ENODEBFUNCTION")
553                         .aSideAssociationName("provided-eNodeBFunction")
554                         .aSideMOType("LTESectorCarrier")
555                         .aSideMinCardinality(0)
556                         .aSideMaxCardinality(100)
557                         .bSideAssociationName("provided-by-lteSectorCarrier")
558                         .bSideMOType("ENodeBFunction")
559                         .bSideMinCardinality(0)
560                         .bSideMaxCardinality(100)
561                         .associationKind("BI_DIRECTIONAL")
562                         .relationshipDataLocation("RELATION")
563                         .connectSameEntity(false)
564                         .moduleReferenceName("o-ran-smo-teiv-ran").build());
565         //Then
566         Assertions.assertEquals(
567                 String.format("NBC change has been introduced: modified/removed relationship(ENODEBFUNCTION_PROVIDES_LTESECTORCARRIER) present in baseline, please make sure you've enabled green-field installation!!%nFor more info please refer to README"),
568                 Assertions.assertThrowsExactly(PgSchemaGeneratorException.class, () -> nbcChecker.checkForNBCChangesInModel(
569                         baselineRel, mockModelSvcRel3)).getMessage());
570
571         //When
572         List<Relationship> mockModelSvcRel4 = List.of(
573                 Relationship.builder().name("ENODEBFUNCTION_PROVIDES_LTESECTORCARRIER")
574                         .aSideAssociationName("provided-lteSectorCarrier")
575                         .aSideMOType("ENodeBFunction")
576                         .aSideMinCardinality(0)
577                         .aSideMaxCardinality(1)
578                         .bSideAssociationName("provided-by-enodebFunction")
579                         .bSideMOType("LTESectorCarrier")
580                         .bSideMinCardinality(0)
581                         .bSideMaxCardinality(1)
582                         .associationKind("BI_DIRECTIONAL")
583                         .relationshipDataLocation("A_SIDE")
584                         .connectSameEntity(false)
585                         .moduleReferenceName("o-ran-smo-teiv-ran").build());
586         //Then
587         Assertions.assertDoesNotThrow(() -> nbcChecker.checkForNBCChangesInModel(
588                         baselineRel, mockModelSvcRel4));
589     }
590     //spotless:on
591 }