You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jspwiki.apache.org by ju...@apache.org on 2020/03/16 21:58:02 UTC

[jspwiki] 12/47: JSPWIKI-303: add module with adapters to allow backwards compatibility with 3rd party extensions not using the public api

This is an automated email from the ASF dual-hosted git repository.

juanpablo pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/jspwiki.git

commit 37f4f8105405971a65608fc12c02fb9e77cc996b
Author: juanpablo <ju...@apache.org>
AuthorDate: Wed Mar 11 19:06:02 2020 +0100

    JSPWIKI-303: add module with adapters to allow backwards compatibility with 3rd party extensions not using the public api
---
 jspwiki-210-adapters/pom.xml                       | 84 ++++++++++++++++++++++
 .../org/apache/wiki/filters/FilterFrom210Test.java | 31 ++++++++
 .../org/apache/wiki/plugin/PluginFrom210Test.java  | 27 +++++++
 .../src/test/resources/filters.xml                 | 31 ++++++++
 4 files changed, 173 insertions(+)

diff --git a/jspwiki-210-adapters/pom.xml b/jspwiki-210-adapters/pom.xml
new file mode 100644
index 0000000..8b4126b
--- /dev/null
+++ b/jspwiki-210-adapters/pom.xml
@@ -0,0 +1,84 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing,
+  software distributed under the License is distributed on an
+  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+  KIND, either express or implied.  See the License for the
+  specific language governing permissions and limitations
+  under the License.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+
+  <parent>
+    <groupId>org.apache.jspwiki</groupId>
+    <artifactId>jspwiki-builder</artifactId>
+    <version>2.11.0.M7-SNAPSHOT</version>
+  </parent>
+
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>jspwiki-210-adapters</artifactId>
+  <name>Apache JSPWiki adapters for extensions not using public api</name>
+
+  <dependencies>
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>jspwiki-main</artifactId>
+      <version>${project.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>javax.servlet</groupId>
+      <artifactId>javax.servlet-api</artifactId>
+      <scope>provided</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>net.sourceforge.stripes</groupId>
+      <artifactId>stripes</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>jspwiki-main</artifactId>
+      <version>${project.version}</version>
+      <type>test-jar</type>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>${project.groupId}</groupId>
+      <artifactId>jspwiki-210-test-adaptees</artifactId>
+      <scope>test</scope>
+      <version>${project.version}</version>
+    </dependency>
+
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-api</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-params</artifactId>
+      <scope>test</scope>
+    </dependency>
+
+    <dependency>
+      <groupId>org.junit.jupiter</groupId>
+      <artifactId>junit-jupiter-engine</artifactId>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>
diff --git a/jspwiki-210-adapters/src/test/java/org/apache/wiki/filters/FilterFrom210Test.java b/jspwiki-210-adapters/src/test/java/org/apache/wiki/filters/FilterFrom210Test.java
new file mode 100644
index 0000000..3412d3e
--- /dev/null
+++ b/jspwiki-210-adapters/src/test/java/org/apache/wiki/filters/FilterFrom210Test.java
@@ -0,0 +1,31 @@
+package org.apache.wiki.filters;
+
+import org.apache.wiki.TestEngine;
+import org.apache.wiki.WikiContext;
+import org.apache.wiki.WikiEngine;
+import org.apache.wiki.WikiPage;
+import org.apache.wiki.render.RenderingManager;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Properties;
+
+
+public class FilterFrom210Test {
+
+    @Test
+    public void testFilterNotUsingPublicApiStillWorks() {
+        final Properties props = TestEngine.getTestProperties();
+        // props.setProperty( FilterManager.PROP_FILTERXML, "filters.xml" );
+        final WikiEngine engine = TestEngine.build( props ); // trigger page filter#initialize
+        final FilterManager fm = engine.getManager( FilterManager.class );
+        final RenderingManager rm = engine.getManager( RenderingManager.class );
+        Assertions.assertTrue( fm.getFilterList().stream().anyMatch( f -> f instanceof ProfanityFilter ) );
+
+        final WikiContext context = new WikiContext( engine, new WikiPage( engine, "Testpage" ) );
+        final String res = rm.textToHTML( context,"Incredible and super important content here" ); // trigger pre / post translate
+        // Assertions.assertEquals( "see how I care about yor content - hmmm...", res );
+        Assertions.assertEquals( "Incredible and super important content here", res );
+    }
+
+}
diff --git a/jspwiki-210-adapters/src/test/java/org/apache/wiki/plugin/PluginFrom210Test.java b/jspwiki-210-adapters/src/test/java/org/apache/wiki/plugin/PluginFrom210Test.java
new file mode 100644
index 0000000..bb3dd1f
--- /dev/null
+++ b/jspwiki-210-adapters/src/test/java/org/apache/wiki/plugin/PluginFrom210Test.java
@@ -0,0 +1,27 @@
+package org.apache.wiki.plugin;
+
+import org.apache.wiki.TestEngine;
+import org.apache.wiki.WikiContext;
+import org.apache.wiki.WikiEngine;
+import org.apache.wiki.WikiPage;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.util.Properties;
+
+
+public class PluginFrom210Test {
+
+    @Test
+    public void testPluginNotUsingPublicApiStillWorks() throws Exception {
+        final Properties props = TestEngine.getTestProperties();
+        props.setProperty( PluginManager.PROP_SEARCHPATH, "com.example.plugins" );
+        final WikiEngine engine = TestEngine.build( props );
+        final PluginManager pm = engine.getManager( PluginManager.class );
+        final WikiContext context = new WikiContext( engine, new WikiPage( engine, "Testpage" ) );
+
+        final String res = pm.execute( context,"{TwoXPlugin}" );
+        Assertions.assertEquals( "hakuna matata", res );
+    }
+
+}
diff --git a/jspwiki-210-adapters/src/test/resources/filters.xml b/jspwiki-210-adapters/src/test/resources/filters.xml
new file mode 100644
index 0000000..3ad3892
--- /dev/null
+++ b/jspwiki-210-adapters/src/test/resources/filters.xml
@@ -0,0 +1,31 @@
+<?xml version="1.0"?>
+<!--
+    Licensed to the Apache Software Foundation (ASF) under one
+    or more contributor license agreements.  See the NOTICE file
+    distributed with this work for additional information
+    regarding copyright ownership.  The ASF licenses this file
+    to you under the Apache License, Version 2.0 (the
+    "License"); you may not use this file except in compliance
+    with the License.  You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+    Unless required by applicable law or agreed to in writing,
+    software distributed under the License is distributed on an
+    "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+    KIND, either express or implied.  See the License for the
+    specific language governing permissions and limitations
+    under the License.  
+-->
+
+<pagefilters>
+
+   <filter>
+      <class>org.apache.wiki.filters.ProfanityFilter</class>
+   </filter>
+   
+   <!-- <filter>
+      <class>com.example.filters.TwoXFilter</class>
+   </filter> -->
+
+</pagefilters>