60ac6db413971ccc78e44a08b88ea487338ab99f
[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 import org.springframework.util.ResourceUtils;
39
40 @SpringBootTest(classes = { DataSchemaGenerator.class, ModelComparator.class, DataSchemaHelper.class, TableBuilder.class,
41         HashInfoDataGenerator.class, BackwardCompatibilityChecker.class }, properties = {
42                 "green-field-installation=false" })
43 public class DataSchemaGeneratorTest {
44     @Autowired
45     private DataSchemaGenerator dataSchemaGenerator;
46     @Value("${green-field-installation}")
47     private boolean isGreenFieldInstallation;
48     @Value("${schema.data.baseline}")
49     private String baselineDataSqlFile;
50     @Value("${schema.data.output}")
51     private String actualResultSqlFile;
52
53     @Test
54     void prepareSchemaTest() throws IOException {
55         //when
56         dataSchemaGenerator.prepareSchema();
57         //then
58         Assertions.assertFalse(isGreenFieldInstallation);
59         //exclude commit statement in the prepare statement as it will be added in the later stage at the end of the schema.
60         Assertions.assertTrue(TestHelper.filesCompareByLine(ResourceUtils.getFile("classpath:" + baselineDataSqlFile)
61                 .toPath(), Paths.get(actualResultSqlFile), "COMMIT;", ""));
62     }
63
64     @AfterEach
65     public void tearDown() {
66         assertTrue(Paths.get(actualResultSqlFile).toFile().delete());
67     }
68 }