2 * Copyright (C) 2019 Bell Canada. All rights reserved.
4 * NOTICE: All the intellectual and technical concepts contained herein are
5 * proprietary to Bell Canada and are protected by trade secret or copyright law.
6 * Unauthorized copying of this file, via any medium is strictly prohibited.
9 package org.onap.ccsdk.cds.cdssdclistener.service;
11 import static junit.framework.TestCase.assertTrue;
12 import java.io.IOException;
13 import java.nio.file.Files;
14 import java.nio.file.Path;
15 import java.nio.file.Paths;
16 import org.junit.Before;
17 import org.junit.Rule;
18 import org.junit.Test;
19 import org.junit.rules.TemporaryFolder;
20 import org.junit.runner.RunWith;
21 import org.onap.ccsdk.cds.cdssdclistener.client.CdsSdcListenerAuthClientInterceptor;
22 import org.onap.ccsdk.cds.cdssdclistener.handler.BluePrintProcesssorHandler;
23 import org.onap.sdc.impl.mock.DistributionClientDownloadResultStubImpl;
24 import org.springframework.beans.factory.annotation.Autowired;
25 import org.springframework.boot.context.properties.EnableConfigurationProperties;
26 import org.springframework.boot.test.context.SpringBootTest;
27 import org.springframework.test.context.junit4.SpringRunner;
29 @RunWith(SpringRunner.class)
30 @EnableConfigurationProperties({ListenerServiceImpl.class, CdsSdcListenerAuthClientInterceptor.class,
31 BluePrintProcesssorHandler.class})
32 @SpringBootTest(classes = {ListenerServiceImplTest.class})
33 public class ListenerServiceImplTest {
35 private static final String CSAR_SAMPLE = "src/test/resources/service-Testsvc140.csar";
36 private static final String ZIP_FILE = ".zip";
37 private static final String CSAR_FILE = ".csar";
38 private String csarArchivePath;
39 private Path tempDirectoryPath;
42 public TemporaryFolder folder = new TemporaryFolder();
45 private ListenerServiceImpl listenerService;
49 csarArchivePath = folder.getRoot().toString();
50 tempDirectoryPath = Paths.get(csarArchivePath, "cds-sdc-listener-test");
53 public void extractBluePrintSuccessfully() throws IOException {
55 listenerService.extractBluePrint(CSAR_SAMPLE, tempDirectoryPath.toString());
58 String result = checkFileExists(tempDirectoryPath);
59 assertTrue(result.contains(ZIP_FILE));
63 public void storeCsarArtifactToFileSuccessfully() throws IOException {
65 DistributionClientDownloadResultStubImpl resultStub = new DistributionClientDownloadResultStubImpl();
68 listenerService.extractCsarAndStore(resultStub, tempDirectoryPath.toString());
71 String result = checkFileExists(tempDirectoryPath);
72 assertTrue(result.contains(CSAR_FILE));
75 private String checkFileExists(Path path) throws IOException {
76 return Files.walk(path)
77 .filter(Files::isRegularFile)