d10d3ff7aabd2802b24454769cfdbde16225c103
[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
25 package org.onap.blueprintgenerator.test;
26
27 import org.apache.commons.io.FileUtils;
28 import org.junit.Assert;
29 import org.junit.FixMethodOrder;
30 import org.junit.Ignore;
31 import org.junit.Test;
32 import org.junit.jupiter.api.Order;
33 import org.junit.runners.MethodSorters;
34 import org.onap.blueprintgenerator.test.BlueprintGeneratorTests;
35
36 import java.io.File;
37 import java.io.IOException;
38 import java.nio.file.Paths;
39
40
41 /**
42  * @author : Ravi Mantena
43  * @date 10/16/2020
44  * Application: ONAP - Blueprint Generator
45  * ONAP Bueprint Jar Comparision with Previos version to make sure Bps are not broken with new changes
46  */
47
48
49 @Ignore
50 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
51 public class BlueprintJarComparatorTest extends BlueprintGeneratorTests {
52
53     private String previousJarVersion = "0.1";
54     private String latestJarVersion = "1.0";
55     private String previousVersion = "0_1";
56     private String latestVersion = "1_0";
57     private String latestJarPath = Paths.get("target").toAbsolutePath().toString() + "\\";
58     private String previousJarPath = Paths.get("src", "test", "resources", "archives").toAbsolutePath().toString() + "\\";
59     private String inputPath = Paths.get("src", "test", "resources", "componentspecs").toAbsolutePath().toString() + "\\";
60     private String inputPolicyPath = Paths.get("src", "test", "resources", "policyjson").toAbsolutePath().toString() + "\\";
61     private String outputPath = Paths.get("src", "test", "resources", "outputfiles").toAbsolutePath().toString() + "\\";
62     private String previousJar = "onap-blueprint-generator-" + previousJarVersion + ".jar";
63     private String latestJar = "onap-blueprint-generator-" + latestJarVersion + ".jar";
64
65     @Test
66     @Order(value=1)
67     public void filesCleanup() throws IOException {
68         FileUtils.deleteDirectory(new File(outputPath));
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         String previousJarCommand = "java -jar " + previousJarPath + previousJar + " app ONAP -i " + inputPath + inputFileName + " -p  " + outputPath +
78                 " -n " + outputFileName + previousVersion + " -t " + inputPath  + inputImportsFileName  + " -d";
79         Runtime.getRuntime().exec(previousJarCommand);
80
81         String latestJarCommand = "java -jar " + latestJarPath + latestJar + " app ONAP -i " + inputPath + inputFileName + " -p  " + outputPath +
82                 " -n " + outputFileName + latestVersion + " -t " + inputPath  + inputImportsFileName  + " -d";
83         Runtime.getRuntime().exec(latestJarCommand);
84
85         Thread.sleep(8000);
86
87         Assert.assertEquals("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         String previousJarCommand = "java -jar " + previousJarPath + previousJar +  " app ONAP -i "  + inputPath + inputFileName + " -p  " + outputPath +
99                 " -n " + outputFileName + previousVersion  + " -t " + inputPath  + inputImportsFileName ;
100         Runtime.getRuntime().exec(previousJarCommand);
101
102         String latestJarCommand = "java -jar " + latestJarPath + latestJar + " app ONAP -i "  + inputPath + inputFileName + " -p  " + outputPath +
103                 " -n " + outputFileName + latestVersion  + " -t " + inputPath  + inputImportsFileName ;
104         Runtime.getRuntime().exec(latestJarCommand);
105
106         Thread.sleep(8000);
107
108         Assert.assertEquals("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
114 }
115