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.model.IFlagContainer;
33 import gov.nist.secauto.metaschema.core.model.IModule;
34 import gov.nist.secauto.metaschema.core.model.ModelType;
35 import gov.nist.secauto.metaschema.core.util.ObjectUtils;
36
37 import org.jmock.Expectations;
38 import org.jmock.junit5.JUnit5Mockery;
39 import org.junit.jupiter.api.Test;
40 import org.junit.jupiter.api.extension.RegisterExtension;
41
42 import java.io.File;
43 import java.io.IOException;
44 import java.net.MalformedURLException;
45 import java.net.URI;
46
47 class DefaultBindingConfigurationTest {
48 private static final URI METASCHEMA_LOCATION
49 = new File("src/test/resources/metaschema/metaschema.xml").getAbsoluteFile().toURI();
50 private static final String DEFINITION_NAME = "grandchild";
51 private static final ModelType DEFINITION_MODEL_TYPE = ModelType.ASSEMBLY;
52 private static final String DEFINITION__CLASS_NAME = "TheChild";
53
54 @RegisterExtension
55 JUnit5Mockery context = new JUnit5Mockery();
56 private final IFlagContainer definition = context.mock(IFlagContainer.class);
57 private final IModule module = context.mock(IModule.class);
58
59 @Test
60 void testLoader() throws MalformedURLException, IOException {
61 File bindingConfigFile = new File("src/test/resources/metaschema/binding-config.xml");
62
63 DefaultBindingConfiguration config = new DefaultBindingConfiguration();
64 config.load(bindingConfigFile);
65
66 assertEquals("gov.nist.itl.metaschema.codegen.xml.example.assembly",
67 config.getPackageNameForNamespace("http://csrc.nist.gov/ns/metaschema/testing/assembly"));
68
69 context.checking(new Expectations() {
70 {
71 oneOf(module).getLocation();
72 will(returnValue(METASCHEMA_LOCATION));
73 allowing(definition).getContainingModule();
74 will(returnValue(module));
75 allowing(definition).getModelType();
76 will(returnValue(DEFINITION_MODEL_TYPE));
77 allowing(definition).getName();
78 will(returnValue(DEFINITION_NAME));
79 }
80 });
81 IDefinitionBindingConfiguration defConfig = config.getBindingConfigurationForDefinition(
82 ObjectUtils.notNull(definition));
83 assertNotNull(defConfig);
84 assertEquals(DEFINITION__CLASS_NAME, defConfig.getClassName());
85 }
86
87 }