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 package gov.nist.secauto.metaschema.databind.codegen.config;
28
29 import static org.junit.jupiter.api.Assertions.assertEquals;
30 import static org.junit.jupiter.api.Assertions.assertNotNull;
31
32 import gov.nist.secauto.metaschema.core.util.ObjectUtils;
33
34 import org.junit.jupiter.api.Test;
35
36 import java.io.File;
37 import java.io.IOException;
38 import java.net.MalformedURLException;
39 import java.util.HashMap;
40 import java.util.Map;
41
42 class BindingConfigurationLoaderTest {
43
44 @Test
45 void testDefault() {
46 DefaultBindingConfiguration config = new DefaultBindingConfiguration();
47
48
49 Map<String, String> namespaceToPackageName = new HashMap<>();
50 namespaceToPackageName.put("http://csrc.nist.gov/ns/metaschema/testing/assembly",
51 "gov.nist.csrc.ns.metaschema.testing.assembly");
52
53 for (Map.Entry<String, String> entry : namespaceToPackageName.entrySet()) {
54 assertEquals(entry.getValue(), config.getPackageNameForNamespace(ObjectUtils.notNull(entry.getKey())));
55 }
56 }
57
58 @Test
59 void testConfiguredNamespace() {
60 DefaultBindingConfiguration config = new DefaultBindingConfiguration();
61
62
63 Map<String, String> namespaceToPackageName = new HashMap<>();
64 namespaceToPackageName.put("http://csrc.nist.gov/ns/metaschema/testing/assembly",
65 "gov.nist.secauto.metaschema.testing.assembly");
66
67 for (Map.Entry<String, String> entry : namespaceToPackageName.entrySet()) {
68 config.addModelBindingConfig(entry.getKey(), entry.getValue());
69 }
70
71 for (Map.Entry<String, String> entry : namespaceToPackageName.entrySet()) {
72 assertEquals(entry.getValue(), config.getPackageNameForNamespace(ObjectUtils.notNull(entry.getKey())));
73 }
74 }
75
76 @Test
77 void test() throws MalformedURLException, IOException {
78 File configFile = new File("src/main/metaschema-bindings/oscal-metaschema-bindings.xml");
79 DefaultBindingConfiguration config = new DefaultBindingConfiguration();
80 config.load(configFile);
81 assertNotNull(config);
82 }
83
84 }