-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#201 add system modules to extensions subproject, add request context…
… to script execution
- Loading branch information
Thorsten Marx
committed
May 29, 2024
1 parent
5fddd66
commit 17d22bc
Showing
17 changed files
with
201 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
20 changes: 20 additions & 0 deletions
20
cms-extensions/src/main/resources/com/github/thmarx/cms/extensions/system/features.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
export const AuthFeature = Java.type("com.github.thmarx.cms.api.feature.features.AuthFeature").class | ||
export const ConfigurationFeature = Java.type("com.github.thmarx.cms.api.feature.features.ConfigurationFeature").class | ||
export const ContentNodeMapperFeature = Java.type("com.github.thmarx.cms.api.feature.features.ContentNodeMapperFeature").class | ||
export const ContentParserFeature = Java.type("com.github.thmarx.cms.api.feature.features.ContentParserFeature").class | ||
export const ContentRenderFeature = Java.type("com.github.thmarx.cms.api.feature.features.ContentRenderFeature").class | ||
export const CurrentNodeFeature = Java.type("com.github.thmarx.cms.api.feature.features.CurrentNodeFeature").class | ||
export const CurrentTaxonomyFeature = Java.type("com.github.thmarx.cms.api.feature.features.CurrentTaxonomyFeature").class | ||
export const DBFeature = Java.type("com.github.thmarx.cms.api.feature.features.DBFeature").class | ||
export const EventBusFeature = Java.type("com.github.thmarx.cms.api.feature.features.EventBusFeature").class | ||
export const HookSystemFeature = Java.type("com.github.thmarx.cms.api.feature.features.HookSystemFeature").class | ||
export const InjectorFeature = Java.type("com.github.thmarx.cms.api.feature.features.InjectorFeature").class | ||
export const IsDevModeFeature = Java.type("com.github.thmarx.cms.api.feature.features.IsDevModeFeature").class | ||
export const IsPreviewFeature = Java.type("com.github.thmarx.cms.api.feature.features.IsPreviewFeature").class | ||
export const MarkdownRendererFeature = Java.type("com.github.thmarx.cms.api.feature.features.MarkdownRendererFeature").class | ||
export const ModuleManagerFeature = Java.type("com.github.thmarx.cms.api.feature.features.ModuleManagerFeature").class | ||
export const RequestFeature = Java.type("com.github.thmarx.cms.api.feature.features.RequestFeature").class | ||
export const ServerPropertiesFeature = Java.type("com.github.thmarx.cms.api.feature.features.ServerPropertiesFeature").class | ||
export const SiteMediaServiceFeature = Java.type("com.github.thmarx.cms.api.feature.features.SiteMediaServiceFeature").class | ||
export const SitePropertiesFeature = Java.type("com.github.thmarx.cms.api.feature.features.SitePropertiesFeature").class | ||
export const ThemeFeature = Java.type("com.github.thmarx.cms.api.feature.features.ThemeFeature").class |
File renamed without changes.
4 changes: 4 additions & 0 deletions
4
...ub/thmarx/cms/extensions/system/hooks.mjs → ...ub/thmarx/cms/extensions/system/hooks.mjs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
96 changes: 96 additions & 0 deletions
96
cms-extensions/src/test/java/com/github/thmarx/cms/extensions/ExtensionManagerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
package com.github.thmarx.cms.extensions; | ||
|
||
/*- | ||
* #%L | ||
* cms-extensions | ||
* %% | ||
* Copyright (C) 2023 - 2024 Marx-Software | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
* #L% | ||
*/ | ||
|
||
import com.github.thmarx.cms.api.ServerProperties; | ||
import com.github.thmarx.cms.api.db.DB; | ||
import com.github.thmarx.cms.api.feature.features.HookSystemFeature; | ||
import com.github.thmarx.cms.api.hooks.HookSystem; | ||
import com.github.thmarx.cms.api.request.RequestContext; | ||
import com.github.thmarx.cms.api.theme.Theme; | ||
import com.github.thmarx.cms.filesystem.FileSystem; | ||
import java.io.IOException; | ||
import java.nio.file.Path; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
@ExtendWith(MockitoExtension.class) | ||
public class ExtensionManagerTest { | ||
|
||
@Mock | ||
DB db; | ||
@Mock | ||
Theme theme; | ||
@Mock | ||
ServerProperties properties; | ||
@Mock | ||
FileSystem fileSystem; | ||
|
||
|
||
ExtensionManager extensionManager; | ||
|
||
@BeforeEach | ||
public void setup () throws Exception { | ||
|
||
Mockito.when(fileSystem.resolve("libs/")) | ||
.thenReturn(Path.of("src/test/resources/site/libs")); | ||
Mockito.when(fileSystem.resolve("extensions/")) | ||
.thenReturn(Path.of("src/test/resources/site/extensions")); | ||
Mockito.when(db.getFileSystem()).thenReturn(fileSystem); | ||
Mockito.when(theme.extensionsPath()) | ||
.thenReturn(Path.of("src/test/resources/theme/extensions")); | ||
|
||
extensionManager = new ExtensionManager(db, theme, properties); | ||
extensionManager.init(); | ||
} | ||
|
||
@AfterEach | ||
public void shutdown () throws Exception { | ||
extensionManager.close(); | ||
} | ||
|
||
@Test | ||
public void testSomeMethod() throws IOException { | ||
|
||
var requestContext = new RequestContext(); | ||
final HookSystem hookSystem = new HookSystem(); | ||
requestContext.add(HookSystemFeature.class, new HookSystemFeature(hookSystem)); | ||
extensionManager.newContext(theme, requestContext); | ||
|
||
Assertions.assertThat(hookSystem.call("test").results()) | ||
.hasSize(1) | ||
.containsExactly("hallo") | ||
; | ||
} | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
cms-extensions/src/test/resources/site/extensions/hook-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/*- | ||
* #%L | ||
* cms-extensions | ||
* %% | ||
* Copyright (C) 2023 - 2024 Marx-Software | ||
* %% | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public | ||
* License along with this program. If not, see | ||
* <http://www.gnu.org/licenses/gpl-3.0.html>. | ||
* #L% | ||
*/ | ||
|
||
import { $hooks } from 'system/hooks.mjs'; | ||
|
||
$hooks.register( | ||
"test", | ||
(context) => { | ||
return 'hallo' | ||
} | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters