|
30 | 30 | import org.junit.jupiter.api.Test; |
31 | 31 | import org.slf4j.LoggerFactory; |
32 | 32 |
|
| 33 | +import com.google.common.collect.ImmutableMap; |
| 34 | + |
33 | 35 | import io.wcm.devops.conga.generator.spi.PostProcessorPlugin; |
34 | 36 | import io.wcm.devops.conga.generator.spi.context.FileContext; |
35 | 37 | import io.wcm.devops.conga.generator.spi.context.PluginContextOptions; |
36 | 38 | import io.wcm.devops.conga.generator.spi.context.PostProcessorContext; |
37 | 39 | import io.wcm.devops.conga.generator.util.PluginManagerImpl; |
38 | 40 | import io.wcm.devops.conga.plugins.sling.postprocessor.ProvisioningOsgiConfigPostProcessor; |
39 | 41 |
|
40 | | -public class ContentPackagePropertiesPostProcessorTest { |
| 42 | +class ContentPackagePropertiesPostProcessorTest { |
41 | 43 |
|
42 | 44 | private PostProcessorPlugin underTest; |
43 | 45 |
|
44 | 46 | @BeforeEach |
45 | | - public void setUp() { |
| 47 | + void setUp() { |
46 | 48 | underTest = new PluginManagerImpl().get(ContentPackagePropertiesPostProcessor.NAME, PostProcessorPlugin.class); |
47 | 49 | } |
48 | 50 |
|
49 | 51 | @SuppressWarnings("unchecked") |
50 | 52 | @Test |
51 | | - public void testContentPackage() throws Exception { |
| 53 | + void testContentPackage() throws Exception { |
52 | 54 |
|
53 | 55 | FileContext fileContext = new FileContext() |
54 | 56 | .file(new File("src/test/resources/package/example.zip")); |
55 | 57 |
|
56 | 58 | // post-process |
57 | | - applyPlugin(fileContext); |
| 59 | + applyPlugin(fileContext, ImmutableMap.of()); |
58 | 60 |
|
59 | 61 | // validate |
60 | 62 | Map<String, Object> props = (Map<String, Object>)fileContext.getModelOptions().get(ContentPackagePropertiesPostProcessor.MODEL_OPTIONS_PROPERTY); |
61 | 63 | assertEquals("mapping-sample", props.get("name")); |
62 | 64 | assertEquals(false, props.get("requiresRoot")); |
63 | 65 | assertEquals(2, props.get("packageFormatVersion")); |
| 66 | + assertNull(props.get("packageType")); |
| 67 | + } |
| 68 | + |
| 69 | + @SuppressWarnings("unchecked") |
| 70 | + @Test |
| 71 | + void testContentPackageOverridePackageType() throws Exception { |
| 72 | + |
| 73 | + FileContext fileContext = new FileContext() |
| 74 | + .file(new File("src/test/resources/package/example.zip")); |
| 75 | + |
| 76 | + // post-process |
| 77 | + applyPlugin(fileContext, ImmutableMap.of("contentPackage", ImmutableMap.of("packageType", "mytype"))); |
| 78 | + |
| 79 | + // validate |
| 80 | + Map<String, Object> props = (Map<String, Object>)fileContext.getModelOptions().get(ContentPackagePropertiesPostProcessor.MODEL_OPTIONS_PROPERTY); |
| 81 | + assertEquals("mytype", props.get("packageType")); |
64 | 82 | } |
65 | 83 |
|
66 | 84 | @Test |
67 | | - public void testNonContentPackage() throws Exception { |
| 85 | + void testNonContentPackage() throws Exception { |
68 | 86 |
|
69 | 87 | FileContext fileContext = new FileContext() |
70 | 88 | .file(new File("src/test/resources/package/no-content-package.zip")); |
71 | 89 |
|
72 | 90 | // post-process |
73 | | - applyPlugin(fileContext); |
| 91 | + applyPlugin(fileContext, ImmutableMap.of()); |
74 | 92 |
|
75 | 93 | // validate |
76 | 94 | assertNull(fileContext.getModelOptions().get(ContentPackagePropertiesPostProcessor.MODEL_OPTIONS_PROPERTY)); |
77 | 95 | } |
78 | 96 |
|
79 | | - private void applyPlugin(FileContext fileContext) { |
| 97 | + private void applyPlugin(FileContext fileContext, Map<String, Object> options) { |
80 | 98 | PluginContextOptions pluginContextOptions = new PluginContextOptions() |
81 | 99 | .pluginManager(new PluginManagerImpl()) |
82 | 100 | .logger(LoggerFactory.getLogger(ProvisioningOsgiConfigPostProcessor.class)); |
83 | 101 | PostProcessorContext context = new PostProcessorContext() |
84 | | - .pluginContextOptions(pluginContextOptions); |
| 102 | + .pluginContextOptions(pluginContextOptions) |
| 103 | + .options(options); |
85 | 104 |
|
86 | 105 | assertTrue(underTest.accepts(fileContext, context)); |
87 | 106 | underTest.apply(fileContext, context); |
|
0 commit comments