BpGen refactor Code Quality Issue-ID: DCAEGEN2-2502
[dcaegen2/platform.git] / mod / bpgenerator / onap / src / test / java / org / onap / blueprintgenerator / test / BlueprintJarComparatorTest.java
1 /*
2  *
3  *  * ============LICENSE_START=======================================================
4  *  *  org.onap.dcae
5  *  *  ================================================================================
6  *  *  Copyright (c) 2020  AT&T Intellectual Property. All rights reserved.
7  *  *  ================================================================================
8  *  *  Licensed under the Apache License, Version 2.0 (the "License");
9  *  *  you may not use this file except in compliance with the License.
10  *  *  You may obtain a copy of the License at
11  *  *
12  *  *       http://www.apache.org/licenses/LICENSE-2.0
13  *  *
14  *  *  Unless required by applicable law or agreed to in writing, software
15  *  *  distributed under the License is distributed on an "AS IS" BASIS,
16  *  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  *  *  See the License for the specific language governing permissions and
18  *  *  limitations under the License.
19  *  *  ============LICENSE_END=========================================================
20  *
21  *
22  */
23
24 package org.onap.blueprintgenerator.test;
25
26 import org.apache.commons.io.FileUtils;
27 import org.junit.Assert;
28 import org.junit.FixMethodOrder;
29 import org.junit.Ignore;
30 import org.junit.Test;
31 import org.junit.jupiter.api.Order;
32 import org.junit.runners.MethodSorters;
33 import org.onap.blueprintgenerator.test.BlueprintGeneratorTests;
34
35 import java.io.File;
36 import java.io.IOException;
37 import java.nio.file.Paths;
38
39 /**
40  * @author : Ravi Mantena
41  * @date 10/16/2020 Application: ONAP - Blueprint Generator ONAP Bueprint Jar Comparision with
42  * Blueprint Comparator using preious and new Jar files to make sure the new code doesnt break previous changes.
43  */
44 @Ignore
45 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
46 public class BlueprintJarComparatorTest extends BlueprintGeneratorTests {
47
48     private String previousJarVersion = "0.1";
49     private String latestJarVersion = "1.0";
50     private String previousVersion = "0_1";
51     private String latestVersion = "1_0";
52     private String latestJarPath = Paths.get("target").toAbsolutePath().toString() + "\\";
53     private String previousJarPath =
54         Paths.get("src", "test", "resources", "archives").toAbsolutePath().toString() + "\\";
55     private String inputPath =
56         Paths.get("src", "test", "resources", "componentspecs").toAbsolutePath().toString() + "\\";
57     private String inputPolicyPath =
58         Paths.get("src", "test", "resources", "policyjson").toAbsolutePath().toString() + "\\";
59     private String outputPath =
60         Paths.get("src", "test", "resources", "outputfiles").toAbsolutePath().toString() + "\\";
61     private String previousJar = "onap-blueprint-generator-" + previousJarVersion + ".jar";
62     private String latestJar = "onap-blueprint-generator-" + latestJarVersion + ".jar";
63
64     @Test
65     @Order(value = 1)
66     public void filesCleanup() throws IOException {
67         FileUtils.deleteDirectory(new File(outputPath));
68     }
69
70     @Test
71     public void jarTestVeswithDmaapK8s() throws IOException, InterruptedException {
72         String inputFileName = ves;
73         String outputFileName = "dcae-ves-collector-dmaap-";
74         String inputImportsFileName = testImports;
75
76         String previousJarCommand =
77             "java -jar "
78                 + previousJarPath
79                 + previousJar
80                 + " app ONAP -i "
81                 + inputPath
82                 + inputFileName
83                 + " -p  "
84                 + outputPath
85                 + " -n "
86                 + outputFileName
87                 + previousVersion
88                 + " -t "
89                 + inputPath
90                 + inputImportsFileName
91                 + " -d";
92         Runtime.getRuntime().exec(previousJarCommand);
93
94         String latestJarCommand =
95             "java -jar "
96                 + latestJarPath
97                 + latestJar
98                 + " app ONAP -i "
99                 + inputPath
100                 + inputFileName
101                 + " -p  "
102                 + outputPath
103                 + " -n "
104                 + outputFileName
105                 + latestVersion
106                 + " -t "
107                 + inputPath
108                 + inputImportsFileName
109                 + " -d";
110         Runtime.getRuntime().exec(latestJarCommand);
111
112         Thread.sleep(8000);
113
114         Assert.assertEquals(
115             "The BluePrint files ("
116                 + outputFileName
117                 + ") for "
118                 + inputFileName
119                 + " with -m option don't match!",
120             FileUtils.readFileToString(
121                 new File(outputPath + outputFileName + previousVersion + ".yaml"), "utf-8"),
122             FileUtils.readFileToString(
123                 new File(outputPath + outputFileName + latestVersion + ".yaml"), "utf-8"));
124     }
125
126     @Test
127     public void jarTestVeswithoutDmaapK8s() throws IOException, InterruptedException {
128         String inputFileName = ves;
129         String outputFileName = "dcae-ves-collector-";
130         String inputImportsFileName = testImports;
131
132         String previousJarCommand =
133             "java -jar "
134                 + previousJarPath
135                 + previousJar
136                 + " app ONAP -i "
137                 + inputPath
138                 + inputFileName
139                 + " -p  "
140                 + outputPath
141                 + " -n "
142                 + outputFileName
143                 + previousVersion
144                 + " -t "
145                 + inputPath
146                 + inputImportsFileName;
147         Runtime.getRuntime().exec(previousJarCommand);
148
149         String latestJarCommand =
150             "java -jar "
151                 + latestJarPath
152                 + latestJar
153                 + " app ONAP -i "
154                 + inputPath
155                 + inputFileName
156                 + " -p  "
157                 + outputPath
158                 + " -n "
159                 + outputFileName
160                 + latestVersion
161                 + " -t "
162                 + inputPath
163                 + inputImportsFileName;
164         Runtime.getRuntime().exec(latestJarCommand);
165
166         Thread.sleep(8000);
167
168         Assert.assertEquals(
169             "The BluePrint files ("
170                 + outputFileName
171                 + ") for "
172                 + inputFileName
173                 + " with -m option dont match!",
174             FileUtils.readFileToString(
175                 new File(outputPath + outputFileName + previousVersion + ".yaml"), "utf-8"),
176             FileUtils.readFileToString(
177                 new File(outputPath + outputFileName + latestVersion + ".yaml"), "utf-8"));
178     }
179 }