1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.juneau.utils;
18
19 import static org.junit.jupiter.api.Assertions.*;
20
21 import java.util.*;
22 import java.util.jar.*;
23
24 import org.apache.juneau.*;
25 import org.junit.jupiter.api.*;
26
27 class ManifestFile_Test extends TestBase {
28
29
30
31
32 @Test void a01_basic() throws Exception {
33 var manifest = new Manifest();
34 manifest.getMainAttributes().put(java.util.jar.Attributes.Name.MANIFEST_VERSION, "1.0");
35 manifest.getMainAttributes().put(new java.util.jar.Attributes.Name("Bundle-Name"), "Test Bundle");
36 manifest.getMainAttributes().put(new java.util.jar.Attributes.Name("Bundle-Version"), "1.0.0");
37
38 var mf = new ManifestFile(manifest);
39
40 assertEquals("1.0", mf.get("Manifest-Version"));
41 assertEquals("Test Bundle", mf.get("Bundle-Name"));
42 assertEquals("1.0.0", mf.get("Bundle-Version"));
43 }
44
45
46
47
48 @Test void a02_fluentSetters() throws Exception {
49 var manifest = new Manifest();
50 manifest.getMainAttributes().put(java.util.jar.Attributes.Name.MANIFEST_VERSION, "1.0");
51
52 var mf = new ManifestFile(manifest);
53
54
55 var innerMap = new HashMap<String,Object>();
56 innerMap.put("test", "value");
57 assertSame(mf, mf.inner(innerMap));
58
59
60 BeanSession session = BeanContext.DEFAULT.getSession();
61 assertSame(mf, mf.session(session));
62
63
64 assertSame(mf, mf.append("Custom-Key", "custom-value"));
65 assertEquals("custom-value", mf.get("Custom-Key"));
66
67
68 var appendMap = new HashMap<String,Object>();
69 appendMap.put("Another-Key", "another-value");
70 assertSame(mf, mf.append(appendMap));
71 assertEquals("another-value", mf.get("Another-Key"));
72
73
74 assertSame(mf, mf.appendIf(true, "Conditional-Key", "conditional-value"));
75 assertEquals("conditional-value", mf.get("Conditional-Key"));
76 assertSame(mf, mf.appendIf(false, "Skipped-Key", "skipped-value"));
77 assertNull(mf.get("Skipped-Key"));
78
79
80 assertSame(mf, mf.filtered(x -> x != null));
81
82
83 assertSame(mf, mf.keepAll("Custom-Key", "Another-Key"));
84
85
86 assertSame(mf, mf.setBeanSession(session));
87
88
89 assertSame(mf, mf.modifiable());
90
91
92 assertSame(mf, mf.unmodifiable());
93 }
94
95 @Test void a03_fluentChaining() throws Exception {
96 var manifest = new Manifest();
97 manifest.getMainAttributes().put(java.util.jar.Attributes.Name.MANIFEST_VERSION, "1.0");
98
99
100 var mf = new ManifestFile(manifest)
101 .append("Key1", "value1")
102 .append("Key2", "value2")
103 .appendIf(true, "Key3", "value3");
104
105 assertEquals("value1", mf.get("Key1"));
106 assertEquals("value2", mf.get("Key2"));
107 assertEquals("value3", mf.get("Key3"));
108 }
109 }