Blueprint Generator - split executable part to separate submodule
[dcaegen2/platform.git] / mod / bpgenerator / onap-executable / src / test / java / org / onap / blueprintgenerator / BlueprintJarComparatorTest.java
1 /*
2  *
3  *  * ============LICENSE_START=======================================================
4  *  *  org.onap.dcae
5  *  *  ================================================================================
6  *  *  Copyright (c) 2020  AT&T Intellectual Property. All rights reserved.
7  *  *  Copyright (c) 2020  Nokia. All rights reserved.
8  *  *  ================================================================================
9  *  *  Licensed under the Apache License, Version 2.0 (the "License");
10  *  *  you may not use this file except in compliance with the License.
11  *  *  You may obtain a copy of the License at
12  *  *
13  *  *       http://www.apache.org/licenses/LICENSE-2.0
14  *  *
15  *  *  Unless required by applicable law or agreed to in writing, software
16  *  *  distributed under the License is distributed on an "AS IS" BASIS,
17  *  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  *  *  See the License for the specific language governing permissions and
19  *  *  limitations under the License.
20  *  *  ============LICENSE_END=========================================================
21  *
22  *
23  */
24
25 package org.onap.blueprintgenerator;
26
27 import java.io.File;
28 import java.io.IOException;
29 import java.nio.file.Paths;
30 import org.apache.commons.io.FileUtils;
31 import org.junit.AfterClass;
32 import org.junit.Assert;
33 import org.junit.BeforeClass;
34 import org.junit.FixMethodOrder;
35 import org.junit.Ignore;
36 import org.junit.Test;
37 import org.junit.runners.MethodSorters;
38
39 /**
40  * @author : Ravi Mantena
41  * @date 10/16/2020 Application: ONAP - Blueprint Generator ONAP Bueprint Jar Comparision with Previos version to make
42  * sure Bps are not broken with new changes
43  */
44 @Ignore
45 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
46 public class BlueprintJarComparatorTest {
47
48     private static final String ves = "ves.json";
49     private static final String testImports = "testImports.yaml";
50     private static final String previousJarVersion = "1.7.0-SNAPSHOT";
51     private static final String latestJarVersion = "1.7.1-SNAPSHOT";
52     private static final String previousVersion = "0_1";
53     private static final String latestVersion = "1_0";
54     private static final String latestJarPath = buildPathAsString("target");
55     private static final String previousJarPath = buildPathAsString("src", "test", "resources", "archives");
56     private static final String inputPath = buildPathAsString("src", "test", "resources", "componentspecs");
57     private static final String outputPath = buildPathAsString("src", "test", "resources", "outputfiles");
58     private static final String previousJar = "blueprint-generator-onap-executable-" + previousJarVersion + ".jar";
59     private static final String latestJar = "blueprint-generator-onap-executable-" + latestJarVersion + ".jar";
60
61     @BeforeClass
62     @AfterClass
63     public static void filesCleanup() throws IOException {
64         FileUtils.deleteDirectory(new File(outputPath));
65     }
66
67     private static String buildPathAsString(String first, String... more) {
68         return Paths.get(first, more).toAbsolutePath().toString() + File.separator;
69     }
70
71     @Test
72     public void jarTestVeswithDmaapK8s() throws IOException, InterruptedException {
73         String inputFileName = ves;
74         String outputFileName = "dcae-ves-collector-dmaap-";
75         String inputImportsFileName = testImports;
76
77         Process process = runBpgenWithDmaap(inputFileName, outputFileName, inputImportsFileName, previousJarPath,
78             previousJar, previousVersion);
79
80         Process process1 = runBpgenWithDmaap(inputFileName, outputFileName, inputImportsFileName, latestJarPath,
81             latestJar, latestVersion);
82
83         process.waitFor();
84         process1.waitFor();
85
86         Assert.assertEquals(
87             "The BluePrint files (" + outputFileName + ") for " + inputFileName + " with -m option don't match!",
88             FileUtils.readFileToString(new File(outputPath + outputFileName + previousVersion + ".yaml"), "utf-8"),
89             FileUtils.readFileToString(new File(outputPath + outputFileName + latestVersion + ".yaml"), "utf-8"));
90     }
91
92     @Test
93     public void jarTestVeswithoutDmaapK8s() throws IOException, InterruptedException {
94         String inputFileName = ves;
95         String outputFileName = "dcae-ves-collector-";
96         String inputImportsFileName = testImports;
97
98         Process process = runBpgenWithoutDmaap(inputFileName, outputFileName, inputImportsFileName, previousJarPath,
99             previousJar, previousVersion);
100
101         Process process1 = runBpgenWithoutDmaap(inputFileName, outputFileName, inputImportsFileName, latestJarPath,
102             latestJar, latestVersion);
103
104         process.waitFor();
105         process1.waitFor();
106
107         Assert.assertEquals(
108             "The BluePrint files (" + outputFileName + ") for " + inputFileName + " with -m option dont match!",
109             FileUtils.readFileToString(new File(outputPath + outputFileName + previousVersion + ".yaml"), "utf-8"),
110             FileUtils.readFileToString(new File(outputPath + outputFileName + latestVersion + ".yaml"), "utf-8"));
111     }
112
113     private Process runBpgenWithoutDmaap(String inputFileName, String outputFileName, String inputImportsFileName,
114             String jarPath, String jarName, String outputFileVersion) throws IOException {
115         String jarCommand = "java -jar " + jarPath + jarName + " app ONAP -i " + inputPath + inputFileName + " -p  " +
116             outputPath + " -n " + outputFileName + outputFileVersion + " -t " + inputPath + inputImportsFileName;
117         return Runtime.getRuntime().exec(jarCommand);
118     }
119
120     private Process runBpgenWithDmaap(String inputFileName, String outputFileName, String inputImportsFileName,
121             String jarPath, String jarName, String outputFileVersion) throws IOException {
122         String jarCommand = "java -jar " + jarPath + jarName + " app ONAP -i " + inputPath + inputFileName + " -p  " +
123             outputPath + " -n " + outputFileName + outputFileVersion + " -t " + inputPath + inputImportsFileName
124             + " -d";
125         return Runtime.getRuntime().exec(jarCommand);
126     }
127
128 }
129