Migrate "ms/controllerblueprints" from ccsdk/apps
[ccsdk/cds.git] / ms / controllerblueprints / modules / service / src / test / kotlin / org / onap / ccsdk / apps / controllerblueprints / service / controller / mock / MockFilePart.kt
1 /*
2  *  Copyright © 2019 IBM.
3  *
4  *  Licensed under the Apache License, Version 2.0 (the "License");
5  *  you may not use this file except in compliance with the License.
6  *  You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  *  Unless required by applicable law or agreed to in writing, software
11  *  distributed under the License is distributed on an "AS IS" BASIS,
12  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  *  See the License for the specific language governing permissions and
14  *  limitations under the License.
15  */
16
17 package org.onap.ccsdk.apps.controllerblueprints.service.controller.mock
18
19 import org.apache.commons.io.FilenameUtils
20 import org.slf4j.LoggerFactory
21 import org.springframework.core.io.buffer.DataBuffer
22 import org.springframework.http.HttpHeaders
23 import org.springframework.http.codec.multipart.FilePart
24 import org.springframework.util.FileCopyUtils
25 import reactor.core.publisher.Flux
26 import reactor.core.publisher.Mono
27 import java.io.File
28 import java.nio.file.Path
29
30 class MockFilePart(private val fileName: String) : FilePart {
31     val log = LoggerFactory.getLogger(MockFilePart::class.java)!!
32     override fun content(): Flux<DataBuffer> {
33         TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
34     }
35
36     override fun headers(): HttpHeaders {
37         TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
38     }
39
40     override fun filename(): String {
41         return FilenameUtils.getName(fileName)
42     }
43
44     override fun name(): String {
45         return FilenameUtils.getBaseName(fileName)
46     }
47
48     override fun transferTo(path: Path): Mono<Void> {
49         log.info("Copying file($fileName to ${path}")
50         FileCopyUtils.copy(File(fileName), path.toFile())
51         return Mono.empty()
52     }
53 }