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/31 17:41:21 UTC

[jspwiki] 09/14: add some unit tests

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 fc5044b32532c663d6665505b9b6e9cf9422aa52
Author: juanpablo <ju...@apache.org>
AuthorDate: Tue Mar 31 19:22:43 2020 +0200

    add some unit tests
---
 .../org/apache/wiki/api/core/ContextEnumTest.java  | 36 +++++++++++++
 .../api/filters/FilterSupportOperationsTest.java   | 34 ++++++++++++
 .../apache/wiki/api/filters/PageFilterTest.java    | 39 ++++++++++++++
 .../apache/wiki/api/filters/TestPageFilter.java    | 24 +++++++++
 .../org/apache/wiki/api/spi/AclsSPITestImpl.java   | 19 +++++++
 .../apache/wiki/api/spi/ContentsSPITestImpl.java   | 20 ++++++++
 .../apache/wiki/api/spi/ContextSPITestImpl.java    | 33 ++++++++++++
 .../org/apache/wiki/api/spi/EngineSPITestImpl.java | 15 ++++++
 .../apache/wiki/api/spi/SessionSPITestImpl.java    | 25 +++++++++
 .../java/org/apache/wiki/api/spi/WikiTest.java     | 60 ++++++++++++++++++++++
 .../services/org.apache.wiki.api.spi.AclsSPI       |  1 +
 .../services/org.apache.wiki.api.spi.ContentsSPI   |  1 +
 .../services/org.apache.wiki.api.spi.ContextSPI    |  1 +
 .../services/org.apache.wiki.api.spi.EngineSPI     |  1 +
 .../services/org.apache.wiki.api.spi.SessionSPI    |  1 +
 .../src/test/resources/ini/jspwiki.properties      |  5 ++
 16 files changed, 315 insertions(+)

diff --git a/jspwiki-api/src/test/java/org/apache/wiki/api/core/ContextEnumTest.java b/jspwiki-api/src/test/java/org/apache/wiki/api/core/ContextEnumTest.java
new file mode 100644
index 0000000..51a16ea
--- /dev/null
+++ b/jspwiki-api/src/test/java/org/apache/wiki/api/core/ContextEnumTest.java
@@ -0,0 +1,36 @@
+/*
+    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.
+ */
+package org.apache.wiki.api.core;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+
+public class ContextEnumTest {
+
+    @Test
+    public void testEnumData() {
+        Assertions.assertEquals( 27, ContextEnum.values().length );
+
+        Assertions.assertEquals( "view", ContextEnum.PAGE_VIEW.getRequestContext() );
+        Assertions.assertEquals( "%uWiki.jsp?page=%n", ContextEnum.PAGE_VIEW.getUrlPattern() );
+        Assertions.assertEquals( "PageContent.jsp", ContextEnum.PAGE_VIEW.getContentTemplate() );
+    }
+
+}
diff --git a/jspwiki-api/src/test/java/org/apache/wiki/api/filters/FilterSupportOperationsTest.java b/jspwiki-api/src/test/java/org/apache/wiki/api/filters/FilterSupportOperationsTest.java
new file mode 100644
index 0000000..bf4478d
--- /dev/null
+++ b/jspwiki-api/src/test/java/org/apache/wiki/api/filters/FilterSupportOperationsTest.java
@@ -0,0 +1,34 @@
+/*
+    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.
+ */
+package org.apache.wiki.api.filters;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+
+public class FilterSupportOperationsTest {
+
+    @Test
+    public void testFilterSupportOperations() {
+        // the other branch of these methods is properly tested through the jspwiki-210-adapers module
+        Assertions.assertNull( FilterSupportOperations.methodOfNonPublicAPI( new TestPageFilter(), "preTranslate" ) );
+        Assertions.assertEquals( "duh", FilterSupportOperations.executePageFilterPhase( () -> "duh", null, new TestPageFilter() ) );
+    }
+
+}
diff --git a/jspwiki-api/src/test/java/org/apache/wiki/api/filters/PageFilterTest.java b/jspwiki-api/src/test/java/org/apache/wiki/api/filters/PageFilterTest.java
new file mode 100644
index 0000000..9ab4f45
--- /dev/null
+++ b/jspwiki-api/src/test/java/org/apache/wiki/api/filters/PageFilterTest.java
@@ -0,0 +1,39 @@
+/*
+    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.
+ */
+package org.apache.wiki.api.filters;
+
+import org.apache.wiki.api.exceptions.FilterException;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+
+public class PageFilterTest {
+
+    @Test
+    public void testLifeCycle() throws FilterException {
+        final TestPageFilter filter = new TestPageFilter();
+        Assertions.assertDoesNotThrow( () -> filter.initialize( null, null ) );
+        Assertions.assertEquals( "duh", filter.preSave( null, "duh" ) );
+        Assertions.assertEquals( "duh", filter.preTranslate( null, "duh" ) );
+        Assertions.assertEquals( "duh", filter.postTranslate( null, "duh" ) );
+        Assertions.assertDoesNotThrow( () -> filter.postSave( null, null ) );
+        Assertions.assertDoesNotThrow( () -> filter.destroy( null ) );
+    }
+
+}
diff --git a/jspwiki-api/src/test/java/org/apache/wiki/api/filters/TestPageFilter.java b/jspwiki-api/src/test/java/org/apache/wiki/api/filters/TestPageFilter.java
new file mode 100644
index 0000000..e602cea
--- /dev/null
+++ b/jspwiki-api/src/test/java/org/apache/wiki/api/filters/TestPageFilter.java
@@ -0,0 +1,24 @@
+/*
+    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.
+ */
+package org.apache.wiki.api.filters;
+
+// do nothing filter to test basic lifecycle
+public class TestPageFilter extends BasePageFilter {
+
+}
diff --git a/jspwiki-api/src/test/java/org/apache/wiki/api/spi/AclsSPITestImpl.java b/jspwiki-api/src/test/java/org/apache/wiki/api/spi/AclsSPITestImpl.java
new file mode 100644
index 0000000..c80d4cb
--- /dev/null
+++ b/jspwiki-api/src/test/java/org/apache/wiki/api/spi/AclsSPITestImpl.java
@@ -0,0 +1,19 @@
+package org.apache.wiki.api.spi;
+
+import org.apache.wiki.api.core.Acl;
+import org.apache.wiki.api.core.AclEntry;
+
+
+public class AclsSPITestImpl implements AclsSPI {
+
+    @Override
+    public Acl acl() {
+        return null;
+    }
+
+    @Override
+    public AclEntry entry() {
+        return null;
+    }
+
+}
diff --git a/jspwiki-api/src/test/java/org/apache/wiki/api/spi/ContentsSPITestImpl.java b/jspwiki-api/src/test/java/org/apache/wiki/api/spi/ContentsSPITestImpl.java
new file mode 100644
index 0000000..39b3f0b
--- /dev/null
+++ b/jspwiki-api/src/test/java/org/apache/wiki/api/spi/ContentsSPITestImpl.java
@@ -0,0 +1,20 @@
+package org.apache.wiki.api.spi;
+
+import org.apache.wiki.api.core.Attachment;
+import org.apache.wiki.api.core.Engine;
+import org.apache.wiki.api.core.Page;
+
+
+public class ContentsSPITestImpl implements ContentsSPI {
+
+    @Override
+    public Attachment attachment( final Engine engine, final String parentPage, final String fileName ) {
+        return null;
+    }
+
+    @Override
+    public Page page( final Engine engine, final String name ) {
+        return null;
+    }
+
+}
diff --git a/jspwiki-api/src/test/java/org/apache/wiki/api/spi/ContextSPITestImpl.java b/jspwiki-api/src/test/java/org/apache/wiki/api/spi/ContextSPITestImpl.java
new file mode 100644
index 0000000..aba20c7
--- /dev/null
+++ b/jspwiki-api/src/test/java/org/apache/wiki/api/spi/ContextSPITestImpl.java
@@ -0,0 +1,33 @@
+package org.apache.wiki.api.spi;
+
+import org.apache.wiki.api.core.Command;
+import org.apache.wiki.api.core.Context;
+import org.apache.wiki.api.core.Engine;
+import org.apache.wiki.api.core.Page;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+public class ContextSPITestImpl implements ContextSPI {
+
+    @Override
+    public Context create( final Engine engine, final Page page ) {
+        return null;
+    }
+
+    @Override
+    public Context create( final Engine engine, final HttpServletRequest request, final Command command ) {
+        return null;
+    }
+
+    @Override
+    public Context create( final Engine engine, final HttpServletRequest request, final Page page ) {
+        return null;
+    }
+
+    @Override
+    public Context create( final Engine engine, final HttpServletRequest request, final String requestContext ) {
+        return null;
+    }
+
+}
diff --git a/jspwiki-api/src/test/java/org/apache/wiki/api/spi/EngineSPITestImpl.java b/jspwiki-api/src/test/java/org/apache/wiki/api/spi/EngineSPITestImpl.java
new file mode 100644
index 0000000..346734f
--- /dev/null
+++ b/jspwiki-api/src/test/java/org/apache/wiki/api/spi/EngineSPITestImpl.java
@@ -0,0 +1,15 @@
+package org.apache.wiki.api.spi;
+
+import org.apache.wiki.api.core.Engine;
+
+import javax.servlet.ServletContext;
+import java.util.Properties;
+
+
+public class EngineSPITestImpl implements EngineSPI {
+
+    @Override
+    public Engine find( final ServletContext context, final Properties props ) {
+        return null;
+    }
+}
diff --git a/jspwiki-api/src/test/java/org/apache/wiki/api/spi/SessionSPITestImpl.java b/jspwiki-api/src/test/java/org/apache/wiki/api/spi/SessionSPITestImpl.java
new file mode 100644
index 0000000..d48af6b
--- /dev/null
+++ b/jspwiki-api/src/test/java/org/apache/wiki/api/spi/SessionSPITestImpl.java
@@ -0,0 +1,25 @@
+package org.apache.wiki.api.spi;
+
+import org.apache.wiki.api.core.Engine;
+import org.apache.wiki.api.core.Session;
+
+import javax.servlet.http.HttpServletRequest;
+
+
+public class SessionSPITestImpl implements SessionSPI {
+
+    @Override
+    public void remove( final Engine engine, final HttpServletRequest request ) {
+
+    }
+
+    @Override
+    public Session find( final Engine engine, final HttpServletRequest request ) {
+        return null;
+    }
+
+    @Override
+    public Session guest( final Engine engine ) {
+        return null;
+    }
+}
diff --git a/jspwiki-api/src/test/java/org/apache/wiki/api/spi/WikiTest.java b/jspwiki-api/src/test/java/org/apache/wiki/api/spi/WikiTest.java
new file mode 100644
index 0000000..1edbbba
--- /dev/null
+++ b/jspwiki-api/src/test/java/org/apache/wiki/api/spi/WikiTest.java
@@ -0,0 +1,60 @@
+/*
+    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.
+ */
+package org.apache.wiki.api.spi;
+
+import org.junit.jupiter.api.Assertions;
+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;
+
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletContext;
+import java.util.Properties;
+
+
+@ExtendWith( MockitoExtension.class )
+public class WikiTest {
+
+    @Mock
+    ServletContext sc;
+
+    @Mock
+    ServletConfig conf;
+
+    @Test
+    public void testWikiInit() {
+        Mockito.doReturn( sc ).when( conf ).getServletContext();
+        final Properties properties = Wiki.init( sc );
+        Assertions.assertEquals( 5, properties.size() );
+
+        // verify SPIs are initialized and can be invoked
+        Assertions.assertNull( Wiki.acls().acl() );
+        Assertions.assertNull( Wiki.acls().entry() );
+        Assertions.assertNull( Wiki.contents().attachment( null, null, null ) );
+        Assertions.assertNull( Wiki.contents().page( null, null ) );
+        Assertions.assertNull( Wiki.context().create( null, null ) );
+        Assertions.assertNull( Wiki.engine().find( conf ) );
+        Assertions.assertNull( Wiki.engine().find( conf, properties ) );
+        Assertions.assertNull( Wiki.session().find( null, null ) );
+        Assertions.assertNull( Wiki.session().guest( null ) );
+    }
+
+}
diff --git a/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.AclsSPI b/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.AclsSPI
new file mode 100644
index 0000000..94a8fdd
--- /dev/null
+++ b/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.AclsSPI
@@ -0,0 +1 @@
+org.apache.wiki.api.spi.AclsSPITestImpl
\ No newline at end of file
diff --git a/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.ContentsSPI b/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.ContentsSPI
new file mode 100644
index 0000000..73e6494
--- /dev/null
+++ b/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.ContentsSPI
@@ -0,0 +1 @@
+org.apache.wiki.api.spi.ContentsSPITestImpl
\ No newline at end of file
diff --git a/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.ContextSPI b/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.ContextSPI
new file mode 100644
index 0000000..cffe181
--- /dev/null
+++ b/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.ContextSPI
@@ -0,0 +1 @@
+org.apache.wiki.api.spi.ContextSPITestImpl
\ No newline at end of file
diff --git a/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.EngineSPI b/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.EngineSPI
new file mode 100644
index 0000000..27efc1e
--- /dev/null
+++ b/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.EngineSPI
@@ -0,0 +1 @@
+org.apache.wiki.api.spi.EngineSPITestImpl
\ No newline at end of file
diff --git a/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.SessionSPI b/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.SessionSPI
new file mode 100644
index 0000000..6101eff
--- /dev/null
+++ b/jspwiki-api/src/test/resources/META-INF/services/org.apache.wiki.api.spi.SessionSPI
@@ -0,0 +1 @@
+org.apache.wiki.api.spi.SessionSPITestImpl
\ No newline at end of file
diff --git a/jspwiki-api/src/test/resources/ini/jspwiki.properties b/jspwiki-api/src/test/resources/ini/jspwiki.properties
new file mode 100644
index 0000000..b529eda
--- /dev/null
+++ b/jspwiki-api/src/test/resources/ini/jspwiki.properties
@@ -0,0 +1,5 @@
+jspwiki.provider.impl.acls=org.apache.wiki.api.spi.AclsSPITestImpl
+jspwiki.provider.impl.contents=org.apache.wiki.api.spi.ContentsSPITestImpl
+jspwiki.provider.impl.context=org.apache.wiki.api.spi.ContextSPITestImpl
+jspwiki.provider.impl.engine=org.apache.wiki.api.spi.EngineSPITestImpl
+jspwiki.provider.impl.session=org.apache.wiki.api.spi.SessionSPITestImpl
\ No newline at end of file