-
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.
Liferay Portal JSP Unit Test Examples
- Loading branch information
0 parents
commit 7ad1855
Showing
21 changed files
with
2,330 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" output="target/classes" path="src/main/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" output="target/test-classes" path="src/test/java"> | ||
<attributes> | ||
<attribute name="optional" value="true"/> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="src" path="target/scratch"/> | ||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry combineaccessrules="false" kind="src" path="/portal-master"/> | ||
<classpathentry kind="lib" path="/portal-master/lib/global/portlet.jar"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7"> | ||
<attributes> | ||
<attribute name="maven.pomderived" value="true"/> | ||
</attributes> | ||
</classpathentry> | ||
<classpathentry kind="output" path="target/classes"/> | ||
</classpath> |
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,2 @@ | ||
/.project | ||
/target |
Large diffs are not rendered by default.
Oops, something went wrong.
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,56 @@ | ||
eclipse.preferences.version=1 | ||
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true | ||
formatter_profile=_Liferay [plug-in] | ||
formatter_settings_version=12 | ||
sp_cleanup.add_default_serial_version_id=true | ||
sp_cleanup.add_generated_serial_version_id=false | ||
sp_cleanup.add_missing_annotations=true | ||
sp_cleanup.add_missing_deprecated_annotations=true | ||
sp_cleanup.add_missing_methods=false | ||
sp_cleanup.add_missing_nls_tags=false | ||
sp_cleanup.add_missing_override_annotations=true | ||
sp_cleanup.add_missing_override_annotations_interface_methods=true | ||
sp_cleanup.add_serial_version_id=false | ||
sp_cleanup.always_use_blocks=true | ||
sp_cleanup.always_use_parentheses_in_expressions=false | ||
sp_cleanup.always_use_this_for_non_static_field_access=false | ||
sp_cleanup.always_use_this_for_non_static_method_access=false | ||
sp_cleanup.convert_to_enhanced_for_loop=false | ||
sp_cleanup.correct_indentation=false | ||
sp_cleanup.format_source_code=true | ||
sp_cleanup.format_source_code_changes_only=false | ||
sp_cleanup.make_local_variable_final=false | ||
sp_cleanup.make_parameters_final=false | ||
sp_cleanup.make_private_fields_final=true | ||
sp_cleanup.make_type_abstract_if_missing_method=false | ||
sp_cleanup.make_variable_declarations_final=false | ||
sp_cleanup.never_use_blocks=false | ||
sp_cleanup.never_use_parentheses_in_expressions=true | ||
sp_cleanup.on_save_use_additional_actions=true | ||
sp_cleanup.organize_imports=true | ||
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false | ||
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true | ||
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true | ||
sp_cleanup.qualify_static_member_accesses_with_declaring_class=false | ||
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false | ||
sp_cleanup.remove_private_constructors=true | ||
sp_cleanup.remove_trailing_whitespaces=true | ||
sp_cleanup.remove_trailing_whitespaces_all=true | ||
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false | ||
sp_cleanup.remove_unnecessary_casts=true | ||
sp_cleanup.remove_unnecessary_nls_tags=false | ||
sp_cleanup.remove_unused_imports=false | ||
sp_cleanup.remove_unused_local_variables=false | ||
sp_cleanup.remove_unused_private_fields=true | ||
sp_cleanup.remove_unused_private_members=false | ||
sp_cleanup.remove_unused_private_methods=true | ||
sp_cleanup.remove_unused_private_types=true | ||
sp_cleanup.sort_members=false | ||
sp_cleanup.sort_members_all=false | ||
sp_cleanup.use_blocks=false | ||
sp_cleanup.use_blocks_only_for_return_and_throw=false | ||
sp_cleanup.use_parentheses_in_expressions=false | ||
sp_cleanup.use_this_for_non_static_field_access=false | ||
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true | ||
sp_cleanup.use_this_for_non_static_method_access=false | ||
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true |
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,4 @@ | ||
activeProfiles= | ||
eclipse.preferences.version=1 | ||
resolveWorkspaceProjects=true | ||
version=1 |
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,40 @@ | ||
Liferay Portal JSP Unit Test examples | ||
===================================== | ||
|
||
How to test actual rendered HTML from your Portal JSP pages and taglibs, without the need to start a web container. | ||
|
||
|
||
How to use | ||
========== | ||
|
||
Your workspace must have a working "portal-master" project. | ||
|
||
Eclipse, "Import", "Existing Maven project". | ||
|
||
Run the tests using the `liferay-portal-jsp-unit-test` launch configuration. | ||
|
||
|
||
Under the hood | ||
============== | ||
|
||
If you ever need to configure a new Liferay Portal JSP Unit Test project from scratch. | ||
|
||
## Eclipse project, Java Build Path | ||
|
||
Required projects in the build path -> `portal-master` | ||
|
||
Libraries -> `portlet.jar - portal-master/lib/global` | ||
|
||
## Launch configuration | ||
|
||
Classpath, User Entries -> `Maven Dependencies` _before_ `liferay-portal-jsp-unit-test` | ||
|
||
Source, Source Lookup Path -> `portal-master` _before_ `Default` | ||
|
||
|
||
Acknowledgements | ||
================ | ||
|
||
Adapted from work by Günther Enthaler, who wrote the original _Jetty JSP unit test simple example_. | ||
|
||
https://github.com/genthaler/jetty-jsp-unit-test-simple/ |
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,26 @@ | ||
<?xml version="1.0" encoding="UTF-8" standalone="no"?> | ||
<launchConfiguration type="org.eclipse.jdt.junit.launchconfig"> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS"> | ||
<listEntry value="/liferay-portal-jsp-unit-test"/> | ||
</listAttribute> | ||
<listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES"> | ||
<listEntry value="4"/> | ||
</listAttribute> | ||
<stringAttribute key="org.eclipse.debug.core.source_locator_id" value="org.eclipse.jdt.launching.sourceLocator.JavaSourceLookupDirector"/> | ||
<stringAttribute key="org.eclipse.debug.core.source_locator_memento" value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <sourceLookupDirector> <sourceContainers duplicates="false"> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;javaProject name=&quot;portal-master&quot;/&gt;&#10;" typeId="org.eclipse.jdt.launching.sourceContainer.javaProject"/> <container memento="&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot; standalone=&quot;no&quot;?&gt;&#10;&lt;default/&gt;&#10;" typeId="org.eclipse.debug.core.containerType.default"/> </sourceContainers> </sourceLookupDirector> "/> | ||
<stringAttribute key="org.eclipse.jdt.junit.CONTAINER" value="=liferay-portal-jsp-unit-test"/> | ||
<booleanAttribute key="org.eclipse.jdt.junit.KEEPRUNNING_ATTR" value="false"/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TESTNAME" value=""/> | ||
<stringAttribute key="org.eclipse.jdt.junit.TEST_KIND" value="org.eclipse.jdt.junit.loader.junit4"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.ATTR_USE_START_ON_FIRST_THREAD" value="true"/> | ||
<listAttribute key="org.eclipse.jdt.launching.CLASSPATH"> | ||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry containerPath="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5" path="1" type="4"/> "/> | ||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry containerPath="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER" path="3" type="4"/> "/> | ||
<listEntry value="<?xml version="1.0" encoding="UTF-8" standalone="no"?> <runtimeClasspathEntry path="3" projectName="liferay-portal-jsp-unit-test" type="1"/> "/> | ||
</listAttribute> | ||
<stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/> | ||
<booleanAttribute key="org.eclipse.jdt.launching.DEFAULT_CLASSPATH" value="false"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value=""/> | ||
<stringAttribute key="org.eclipse.jdt.launching.PROJECT_ATTR" value="liferay-portal-jsp-unit-test"/> | ||
<stringAttribute key="org.eclipse.jdt.launching.SOURCE_PATH_PROVIDER" value="org.eclipse.m2e.launchconfig.sourcepathProvider"/> | ||
</launchConfiguration> |
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,67 @@ | ||
<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"> | ||
<modelVersion>4.0.0</modelVersion> | ||
<groupId>com.liferay.arbo</groupId> | ||
<artifactId>liferay-portal-jsp-unit-test</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<name>Liferay Portal JSP Unit Test Examples</name> | ||
<url>http://maven.apache.org</url> | ||
<dependencies> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>jetty-jsp</artifactId> | ||
<version>${jetty.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<artifactId>test-jetty-servlet</artifactId> | ||
<version>${jetty.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>[3.8.1,)</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.powermock</groupId> | ||
<artifactId> | ||
powermock-release-with-junit-mockito-dependencies | ||
</artifactId> | ||
<version>1.5.1</version> | ||
<type>pom</type> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-test</artifactId> | ||
<version>4.0.1.RELEASE</version> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.1</version> | ||
<configuration> | ||
<source>1.7</source> | ||
<target>1.7</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.eclipse.jetty</groupId> | ||
<version>${jetty.version}</version> | ||
<configuration> | ||
<useTestClasspath>false</useTestClasspath> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
<properties> | ||
<jetty.version>8.1.15.v20140411</jetty.version> | ||
</properties> | ||
</project> |
114 changes: 114 additions & 0 deletions
114
src/test/java/com/liferay/jsp/portlet/blogs/Blogs_view_entry_content_JSPTestSetUp.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,114 @@ | ||
package com.liferay.jsp.portlet.blogs; | ||
|
||
import static org.mockito.Mockito.mock; | ||
import static org.powermock.api.mockito.PowerMockito.mockStatic; | ||
import static org.powermock.api.mockito.PowerMockito.when; | ||
|
||
import java.util.Date; | ||
|
||
import javax.servlet.http.HttpServletRequest; | ||
|
||
import org.eclipse.jetty.testing.ServletTester; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import org.mockito.MockitoAnnotations; | ||
import org.powermock.api.mockito.PowerMockito; | ||
|
||
import com.liferay.jsp.taglib.ui.discussion.Discussion_page_jsp_TestSetUp; | ||
import com.liferay.portal.kernel.comment.CommentManager; | ||
import com.liferay.portal.kernel.settings.SettingsFactory; | ||
import com.liferay.portal.kernel.settings.SettingsFactoryUtil; | ||
import com.liferay.portal.model.Layout; | ||
import com.liferay.portal.security.permission.PermissionChecker; | ||
import com.liferay.portal.util.test.RandomTestUtil; | ||
import com.liferay.portlet.blogs.BlogsPortletInstanceSettings; | ||
import com.liferay.portlet.blogs.BlogsSettings; | ||
import com.liferay.portlet.blogs.model.BlogsEntry; | ||
import com.liferay.portlet.blogs.service.permission.BlogsEntryPermission; | ||
import com.liferay.portlet.blogs.util.BlogsUtil; | ||
import com.liferay.test.jsp.JSPTestEngine; | ||
|
||
class Blogs_view_entry_content_JSPTestSetUp { | ||
|
||
private JSPTestEngine engine; | ||
|
||
public Blogs_view_entry_content_JSPTestSetUp(JSPTestEngine engine) { | ||
this.engine = engine; | ||
} | ||
|
||
void setUp() throws Exception { | ||
MockitoAnnotations.initMocks(this); | ||
|
||
setUpBlogsEntryPermission(); | ||
|
||
setupComments(); | ||
|
||
new Discussion_page_jsp_TestSetUp().setUp(); | ||
} | ||
|
||
void setUpHttpServletRequest(HttpServletRequest request) { | ||
request.setAttribute(com.liferay.portal.util.WebKeys.BLOGS_ENTRY, blogsEntry); | ||
|
||
request.setAttribute("view_entry_content.jsp-entry", blogsEntry); | ||
|
||
when(blogsEntry.isVisible()).thenReturn(true); | ||
when(blogsEntry.getDisplayDate()).thenReturn(new Date()); | ||
} | ||
|
||
void setUpBlogsSettings() { | ||
ServletTester tester = engine.getServletTester(); | ||
|
||
// because NPE Long null to long | ||
tester.setAttribute("scopeGroupId", RandomTestUtil.randomLong()); | ||
|
||
blogsSettings = mock(BlogsSettings.class); | ||
|
||
mockStatic(BlogsSettings.class, Mockito.CALLS_REAL_METHODS); | ||
|
||
PowerMockito.stub(PowerMockito.method(BlogsSettings.class, "getInstance", Long.TYPE)).toReturn(blogsSettings); | ||
} | ||
|
||
void setUpBlogsPortletInstanceSettings() throws Exception { | ||
// BlogsPortletInstanceSettings static initializer :-( | ||
new SettingsFactoryUtil().setSettingsFactory(mock(SettingsFactory.class)); | ||
|
||
blogsPortletInstanceSettings = mock(BlogsPortletInstanceSettings.class); | ||
|
||
mockStatic(BlogsPortletInstanceSettings.class, Mockito.CALLS_REAL_METHODS); | ||
|
||
PowerMockito.stub( | ||
PowerMockito.method( | ||
BlogsPortletInstanceSettings.class, "getInstance", | ||
Layout.class, String.class | ||
)).toReturn(blogsPortletInstanceSettings); | ||
|
||
when(blogsPortletInstanceSettings.getDisplayStyle()).thenReturn(RandomTestUtil.randomString()); | ||
when(blogsPortletInstanceSettings.isEnableComments()).thenReturn(true); | ||
} | ||
|
||
private void setupComments() throws Exception { | ||
mockStatic(BlogsUtil.class, Mockito.CALLS_REAL_METHODS); | ||
PowerMockito.stub( | ||
PowerMockito.method(BlogsUtil.class, "getCommentManager") | ||
).toReturn( | ||
commentManager); | ||
} | ||
|
||
private void setUpBlogsEntryPermission() { | ||
mockStatic(BlogsEntryPermission.class, Mockito.CALLS_REAL_METHODS); | ||
PowerMockito.stub(PowerMockito.method( | ||
BlogsEntryPermission.class, "contains", | ||
PermissionChecker.class, BlogsEntry.class, String.class | ||
)).toReturn(true); | ||
} | ||
|
||
private BlogsPortletInstanceSettings blogsPortletInstanceSettings; | ||
|
||
BlogsSettings blogsSettings; | ||
|
||
|
||
public @Mock BlogsEntry blogsEntry; | ||
|
||
public @Mock CommentManager commentManager; | ||
|
||
} |
Oops, something went wrong.