4822b02ae043aa911e0630dc21b9e5b96bd1ac53
[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.data;
22
23 import static org.junit.jupiter.api.Assertions.assertTrue;
24
25 import java.io.IOException;
26 import java.nio.file.Paths;
27
28 import org.oran.smo.teiv.pgsqlgenerator.schema.BackwardCompatibilityChecker;
29 import org.junit.jupiter.api.AfterEach;
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.beans.factory.annotation.Value;
34 import org.springframework.boot.test.context.SpringBootTest;
35
36 import org.oran.smo.teiv.pgsqlgenerator.TestHelper;
37 import org.oran.smo.teiv.pgsqlgenerator.schema.model.HashInfoDataGenerator;
38
39 @SpringBootTest(classes = { DataSchemaGenerator.class, ModelComparator.class, DataSchemaHelper.class, TableBuilder.class,
40         HashInfoDataGenerator.class, BackwardCompatibilityChecker.class }, properties = {
41                 "green-field-installation=false" })
42 public class DataSchemaGeneratorTest {
43     @Autowired
44     private DataSchemaGenerator dataSchemaGenerator;
45     @Value("${green-field-installation}")
46     private boolean isGreenFieldInstallation;
47     @Value("${schema.data.baseline}")
48     private String baselineDataSqlFile;
49     @Value("${schema.data.output}")
50     private String actualResultSqlFile;
51
52     @Test
53     void prepareSchemaTest() throws IOException {
54         //when
55         dataSchemaGenerator.prepareSchema();
56         //then
57         Assertions.assertFalse(isGreenFieldInstallation);
58         //exclude commit statement in the prepare statement as it will be added in the later stage at the end of the schema.
59         Assertions.assertTrue(TestHelper.filesCompareByLine(Paths.get(baselineDataSqlFile), Paths.get(actualResultSqlFile),
60                 "COMMIT;", ""));
61     }
62
63     @AfterEach
64     public void tearDown() {
65         assertTrue(Paths.get(actualResultSqlFile).toFile().delete());
66     }
67 }