blob: fa6265ecf8ec9ef5bcde23a57c3df7ad2ce65288 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.container.di
import java.io.{FileOutputStream, OutputStream, File}
import DirConfigSource._
import java.util.Random
import org.junit.rules.TemporaryFolder
import com.yahoo.config.subscription.{ConfigSource, ConfigSourceSet}
// TODO: Make this a junit rule. Does not yet work. Look out for junit updates
// (@Rule def configSourceRule = dirConfigSource)
/**
* @author tonytv
* @author gjoranv
*/
class DirConfigSource(val testSourcePrefix: String) {
private val tempFolder = createTemporaryFolder()
val configSource : ConfigSource = new ConfigSourceSet(testSourcePrefix + new Random().nextLong)
def writeConfig(name: String, contents: String) {
val file = new File(tempFolder.getRoot, name + ".cfg")
if (!file.exists())
file.createNewFile()
printFile(file, contents + "\n")
}
def configId = "dir:" + tempFolder.getRoot.getPath
def cleanup() {
tempFolder.delete()
}
}
private object DirConfigSource {
def printFile(f: File, content: String) {
var out: OutputStream = new FileOutputStream(f)
out.write(content.getBytes("UTF-8"))
out.close()
}
def createTemporaryFolder() = {
val folder = new TemporaryFolder
folder.create()
folder
}
}
|