e3cea38008ffe5a21b1fddf999beba8ffe8f7273
[ccsdk/cds.git] /
1 /*\r
2  * Copyright © 2018 IBM Intellectual Property.\r
3  * Modifications Copyright © 2018 IBM.\r
4  *\r
5  * Licensed under the Apache License, Version 2.0 (the "License");\r
6  * you may not use this file except in compliance with the License.\r
7  * You may obtain a copy of the License at\r
8  *\r
9  *     http://www.apache.org/licenses/LICENSE-2.0\r
10  *\r
11  * Unless required by applicable law or agreed to in writing, software\r
12  * distributed under the License is distributed on an "AS IS" BASIS,\r
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
14  * See the License for the specific language governing permissions and\r
15  * limitations under the License.\r
16  */\r
17 \r
18 package org.onap.ccsdk.apps.controllerblueprints.service;\r
19 import org.junit.*;\r
20 import org.junit.runner.RunWith;\r
21 import org.onap.ccsdk.apps.controllerblueprints.TestApplication;\r
22 import org.onap.ccsdk.apps.controllerblueprints.core.BluePrintException;\r
23 import org.onap.ccsdk.apps.controllerblueprints.core.utils.BluePrintFileUtils;\r
24 import org.springframework.beans.factory.annotation.Autowired;\r
25 import org.springframework.beans.factory.annotation.Value;\r
26 import org.springframework.boot.test.context.SpringBootTest;\r
27 import org.springframework.test.context.ContextConfiguration;\r
28 import org.springframework.test.context.junit4.SpringRunner;\r
29 import org.springframework.util.FileSystemUtils;\r
30 import java.nio.file.Path;\r
31 \r
32 \r
33 /**\r
34  * CbaFileManagementServiceTest.java Purpose: Test the decompressing method of CbaCompressionService\r
35  *\r
36  * @author Vinal Patel\r
37  * @version 1.0\r
38  */\r
39 \r
40 @RunWith(SpringRunner.class)\r
41 @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)\r
42 @ContextConfiguration(classes = {TestApplication.class})\r
43 public class CbaFileManagementServiceTest {\r
44 \r
45     @Value("${controllerblueprints.loadBlueprintsExamplesPath}")\r
46     private String cbaPath;\r
47     private String zipfile;\r
48     private String directorypath;\r
49     private Path zipfilepath;\r
50 \r
51     @Autowired\r
52     CbaFileManagementService cbaCompressionService;\r
53 \r
54 \r
55     /**\r
56      *\r
57      */\r
58     @Before\r
59     public void setUp() {\r
60         try {\r
61             zipfilepath = BluePrintFileUtils.Companion.getCbaStorageDirectory(cbaPath);\r
62         } catch (Exception e) {\r
63             e.printStackTrace();\r
64         }\r
65         zipfile = "CBA_Zip_Test.zip";\r
66         directorypath = zipfilepath.resolve(zipfile.substring(0,zipfile.lastIndexOf("."))).toAbsolutePath().toString();\r
67     }\r
68     @After\r
69     public void clenup() throws BluePrintException {\r
70 \r
71         try {\r
72             //Delete the Zip file from the repository\r
73             FileSystemUtils.deleteRecursively(BluePrintFileUtils.Companion.getBluePrintFile(directorypath, zipfilepath));\r
74         }\r
75         catch (Exception ex){\r
76             throw new BluePrintException("Fail while cleaning up CBA saved!", ex);\r
77         }\r
78     }\r
79 \r
80     /**\r
81      * @throws BluePrintException\r
82      * Test will get success if it is able to decompress CBA file and returns the folder path\r
83      */\r
84     @Test\r
85     public void testDecompressCBAFile_success() throws BluePrintException {\r
86         Assert.assertEquals(directorypath,cbaCompressionService.decompressCBAFile(zipfile,zipfilepath));\r
87     }\r
88 \r
89 }\r