2 * Copyright © 2018 IBM Intellectual Property.
\r
3 * Modifications Copyright © 2018 IBM.
\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
9 * http://www.apache.org/licenses/LICENSE-2.0
\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
18 package org.onap.ccsdk.apps.controllerblueprints.service;
\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
34 * CbaFileManagementServiceTest.java Purpose: Test the decompressing method of CbaCompressionService
\r
36 * @author Vinal Patel
\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
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
52 CbaFileManagementService cbaCompressionService;
\r
59 public void setUp() {
\r
61 zipfilepath = BluePrintFileUtils.Companion.getCbaStorageDirectory(cbaPath);
\r
62 } catch (Exception e) {
\r
63 e.printStackTrace();
\r
65 zipfile = "CBA_Zip_Test.zip";
\r
66 directorypath = zipfilepath.resolve(zipfile.substring(0,zipfile.lastIndexOf("."))).toAbsolutePath().toString();
\r
69 public void clenup() throws BluePrintException {
\r
72 //Delete the Zip file from the repository
\r
73 FileSystemUtils.deleteRecursively(BluePrintFileUtils.Companion.getBluePrintFile(directorypath, zipfilepath));
\r
75 catch (Exception ex){
\r
76 throw new BluePrintException("Fail while cleaning up CBA saved!", ex);
\r
81 * @throws BluePrintException
\r
82 * Test will get success if it is able to decompress CBA file and returns the folder path
\r
85 public void testDecompressCBAFile_success() throws BluePrintException {
\r
86 Assert.assertEquals(directorypath,cbaCompressionService.decompressCBAFile(zipfile,zipfilepath));
\r