-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJunitExampleTest
More file actions
57 lines (46 loc) · 1.99 KB
/
JunitExampleTest
File metadata and controls
57 lines (46 loc) · 1.99 KB
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
50
51
52
53
54
55
56
57
package com...
import static java.lang.boolean.TRUE;
import java.io.InputStream;
import java.util.Map;
@Slf4j
class TscmPropertyConfigTest{
private final Map<String, Object> applicationYml = getApplicationYmlAsMap(*filename:* "../classes/application.yml");
private final Map<String, Object> applicationAccYml = getApplicationYmlAsMap(*filename:* "../classes/application-ACC.yml");
private final Map<String, Object> applicationProdYml = getApplicationYmlAsMap(*filename:* "../classes/application-PRD.yml");
//************************************************************************************************************************
// SSL Tests - TSCM Chapter 10.1
//************************************************************************************************************************
@Test
void serverSslEnabled_inCentralYml_shouldBeTrue(){
// Arrange
String targetProperty = "server.ssl.enabled";
// Act
Object propertyValue = getPropertyFromMap(targetProperty, applicationYml);
// Assert
assertThat(propertyValue).isEqualTo(true);
}
//************************************************************************************************************************
// Helper
//************************************************************************************************************************
// loads yaml file as Map
private Map<String, Object> getApplicationYmlAsMap(String filename){
Yaml yaml = new Yaml();
InputStream inputStream = this.getClass()
.getClassLoader()
.getResourceAsStream(filename);
return yaml.load(inputStream);
}
// iterates over yaml as Map, returns null if property could not be found
private Object getPropertyFromMap(String property, Map<String, Object> ymlMap{
String[] pathList = propertyPath.split(*reger:*"\\.");
for (String pathPart : pathList) {
Object element = ymlMap.get(pathPart);
if (element instanceof Map){
ymlMap = (Map<String, Object> element);
} else {
return element;
}
}
return null;
}
}