23e436c95086bbc7bd513b809c8a012908d2554e
[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.model;
22
23 import java.io.File;
24 import java.io.IOException;
25
26 import org.oran.smo.teiv.pgsqlgenerator.schema.BackwardCompatibilityChecker;
27 import org.junit.jupiter.api.AfterAll;
28 import org.junit.jupiter.api.Test;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.beans.factory.annotation.Value;
31 import org.springframework.boot.test.context.SpringBootTest;
32 import org.springframework.core.io.ClassPathResource;
33
34 import org.oran.smo.teiv.pgsqlgenerator.TestHelper;
35 import org.oran.smo.teiv.pgsqlgenerator.YangParser;
36
37 import static org.junit.jupiter.api.Assertions.assertTrue;
38
39 @SpringBootTest(classes = { HashInfoDataGenerator.class, ModelSchemaGenerator.class, YangParser.class,
40         BackwardCompatibilityChecker.class }, properties = { "green-field-installation=false" })
41 public class ModelSchemaGeneratorTest {
42
43     @Autowired
44     private ModelSchemaGenerator modelSchemaGenerator;
45
46     static File generatedResultFile;
47     static File tempBaselineFile;
48     @Value("${test-result.model}")
49     private String expectedResultSqlFile;
50     @Value("${schema.model.output}")
51     private String actualResultSqlFile;
52     @Value("${schema.model.skeleton}")
53     private String skeletonModelSqlFile;
54     @Value("${schema.model.baseline}")
55     private String baselineModelSqlFile;
56     @Value("${schema.model.temp-baseline}")
57     private String tempBaselineModelSqlFile;
58
59     @Test
60     void prepareSchemaTest() throws IOException {
61         //when
62         modelSchemaGenerator.prepareSchema();
63         File skeletionFile = new ClassPathResource(skeletonModelSqlFile).getFile();
64         generatedResultFile = new File(actualResultSqlFile);
65         tempBaselineFile = new File(tempBaselineModelSqlFile);
66
67         //then
68         assertTrue(generatedResultFile.exists());
69         assertTrue(tempBaselineFile.exists());
70         assertTrue(TestHelper.filesCompareByLine(skeletionFile.toPath(), generatedResultFile.toPath()));
71         assertTrue(TestHelper.filesCompareByLine(new File(baselineModelSqlFile).toPath(), tempBaselineFile.toPath()));
72     }
73
74     @AfterAll
75     public static void teardown() {
76         assertTrue(generatedResultFile.delete());
77         assertTrue(tempBaselineFile.delete());
78     }
79
80 }