Commit d6adfb06 authored by D's avatar D Committed by GitHub

Merge pull request #12194 from b3log/1.7.0-dev

1.7.0 dev
parents ad474732 f35be702
...@@ -15,20 +15,17 @@ ...@@ -15,20 +15,17 @@
*/ */
package org.b3log.solo.model.feed.atom; package org.b3log.solo.model.feed.atom;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.TimeZone; import java.util.TimeZone;
import org.apache.commons.lang.time.DateFormatUtils; import org.apache.commons.lang.time.DateFormatUtils;
/** /**
* Feed. * Feed.
* *
* <p> * <p>
* See <a href="http://tools.ietf.org/html/rfc4287">RFC 4278</a> for more * See <a href="http://tools.ietf.org/html/rfc4287">RFC 4278</a> for more details.
* details.
* </p> * </p>
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
...@@ -72,7 +69,7 @@ public final class Feed { ...@@ -72,7 +69,7 @@ public final class Feed {
/** /**
* Entries. * Entries.
*/ */
private List<Entry> entries = new ArrayList<Entry>(); private List<Entry> entries = new ArrayList<>();
/** /**
* Link variable. * Link variable.
...@@ -166,7 +163,7 @@ public final class Feed { ...@@ -166,7 +163,7 @@ public final class Feed {
/** /**
* Gets the id. * Gets the id.
* *
* @return id * @return id
*/ */
public String getId() { public String getId() {
...@@ -175,7 +172,7 @@ public final class Feed { ...@@ -175,7 +172,7 @@ public final class Feed {
/** /**
* Sets the id with the specified id. * Sets the id with the specified id.
* *
* @param id the specified id * @param id the specified id
*/ */
public void setId(final String id) { public void setId(final String id) {
...@@ -302,7 +299,7 @@ public final class Feed { ...@@ -302,7 +299,7 @@ public final class Feed {
stringBuilder.append(START_UPDATED_ELEMENT); stringBuilder.append(START_UPDATED_ELEMENT);
stringBuilder.append(DateFormatUtils.format(// using ISO-8601 instead of RFC-3339 stringBuilder.append(DateFormatUtils.format(// using ISO-8601 instead of RFC-3339
updated, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone(TIME_ZONE_ID))); updated, DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT.getPattern(), TimeZone.getTimeZone(TIME_ZONE_ID)));
stringBuilder.append(END_UPDATED_ELEMENT); stringBuilder.append(END_UPDATED_ELEMENT);
stringBuilder.append(START_AUTHOR_ELEMENT); stringBuilder.append(START_AUTHOR_ELEMENT);
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
*/ */
package org.b3log.solo.model.feed.rss; package org.b3log.solo.model.feed.rss;
/** /**
* Category. * Category.
* *
......
...@@ -15,23 +15,21 @@ ...@@ -15,23 +15,21 @@
*/ */
package org.b3log.solo.model.feed.rss; package org.b3log.solo.model.feed.rss;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import org.apache.commons.lang.time.DateFormatUtils; import org.apache.commons.lang.time.DateFormatUtils;
/** /**
* RSS 2.0 channel. * RSS 2.0 channel.
* *
* <p> * <p>
* See <a href="http://cyber.law.harvard.edu/rss/rss.html">RSS 2.0 at Harvard Law</a> * See <a href="http://cyber.law.harvard.edu/rss/rss.html">RSS 2.0 at Harvard Law</a>
* for more details. * for more details.
* </p> * </p>
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.1.0.1, Nov 19, 2011 * @version 1.1.0.2, Nov 4, 2016
* @see Item * @see Item
* @see Category * @see Category
* @since 0.3.1 * @since 0.3.1
...@@ -76,7 +74,7 @@ public final class Channel { ...@@ -76,7 +74,7 @@ public final class Channel {
/** /**
* Items. * Items.
*/ */
private List<Item> items = new ArrayList<Item>(); private List<Item> items = new ArrayList<>();
/** /**
* Time zone id. * Time zone id.
...@@ -86,8 +84,8 @@ public final class Channel { ...@@ -86,8 +84,8 @@ public final class Channel {
/** /**
* Start. * Start.
*/ */
private static final String START = "<?xml version='1.0' encoding='UTF-8'?><rss version=\"2.0\" " private static final String START = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><rss version=\"2.0\" "
+ "xmlns:atom=\"http://www.w3.org/2005/Atom\"><channel>"; + "xmlns:atom=\"http://www.w3.org/2005/Atom\"><channel>";
/** /**
* End. * End.
...@@ -123,7 +121,7 @@ public final class Channel { ...@@ -123,7 +121,7 @@ public final class Channel {
* Atom link element. * Atom link element.
*/ */
private static final String ATOM_LINK_ELEMENT = "<atom:link href=\"" + ATOM_LINK_VARIABLE private static final String ATOM_LINK_ELEMENT = "<atom:link href=\"" + ATOM_LINK_VARIABLE
+ "\" rel=\"self\" type=\"application/rss+xml\" />"; + "\" rel=\"self\" type=\"application/rss+xml\" />";
/** /**
* Start description element. * Start description element.
...@@ -161,13 +159,13 @@ public final class Channel { ...@@ -161,13 +159,13 @@ public final class Channel {
private static final String START_LAST_BUILD_DATE_ELEMENT = "<lastBuildDate>"; private static final String START_LAST_BUILD_DATE_ELEMENT = "<lastBuildDate>";
/** /**
* End last build date element. * End last build date element.
*/ */
private static final String END_LAST_BUILD_DATE_ELEMENT = "</lastBuildDate>"; private static final String END_LAST_BUILD_DATE_ELEMENT = "</lastBuildDate>";
/** /**
* Sets the atom link with the specified atom link. * Sets the atom link with the specified atom link.
* *
* @param atomLink the specified atom link * @param atomLink the specified atom link
*/ */
public void setAtomLink(final String atomLink) { public void setAtomLink(final String atomLink) {
...@@ -176,7 +174,7 @@ public final class Channel { ...@@ -176,7 +174,7 @@ public final class Channel {
/** /**
* Gets the atom link. * Gets the atom link.
* *
* @return atom link * @return atom link
*/ */
public String getAtomLink() { public String getAtomLink() {
...@@ -185,7 +183,7 @@ public final class Channel { ...@@ -185,7 +183,7 @@ public final class Channel {
/** /**
* Gets the last build date. * Gets the last build date.
* *
* @return last build date * @return last build date
*/ */
public Date getLastBuildDate() { public Date getLastBuildDate() {
...@@ -194,7 +192,7 @@ public final class Channel { ...@@ -194,7 +192,7 @@ public final class Channel {
/** /**
* Sets the last build date with the specified last build date. * Sets the last build date with the specified last build date.
* *
* @param lastBuildDate the specified last build date * @param lastBuildDate the specified last build date
*/ */
public void setLastBuildDate(final Date lastBuildDate) { public void setLastBuildDate(final Date lastBuildDate) {
...@@ -203,7 +201,7 @@ public final class Channel { ...@@ -203,7 +201,7 @@ public final class Channel {
/** /**
* Gets generator. * Gets generator.
* *
* @return generator * @return generator
*/ */
public String getGenerator() { public String getGenerator() {
...@@ -212,7 +210,7 @@ public final class Channel { ...@@ -212,7 +210,7 @@ public final class Channel {
/** /**
* Sets the generator with the specified generator. * Sets the generator with the specified generator.
* *
* @param generator the specified generator * @param generator the specified generator
*/ */
public void setGenerator(final String generator) { public void setGenerator(final String generator) {
......
...@@ -15,14 +15,12 @@ ...@@ -15,14 +15,12 @@
*/ */
package org.b3log.solo.model.feed.rss; package org.b3log.solo.model.feed.rss;
import java.util.Date; import java.util.Date;
import java.util.HashSet; import java.util.HashSet;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
import org.apache.commons.lang.time.DateFormatUtils; import org.apache.commons.lang.time.DateFormatUtils;
/** /**
* Item. * Item.
* *
...@@ -75,7 +73,7 @@ public final class Item { ...@@ -75,7 +73,7 @@ public final class Item {
/** /**
* Categories. * Categories.
*/ */
private Set<Category> categories = new HashSet<Category>(); private Set<Category> categories = new HashSet<>();
/** /**
* Start guid element. * Start guid element.
...@@ -129,7 +127,7 @@ public final class Item { ...@@ -129,7 +127,7 @@ public final class Item {
/** /**
* Gets the GUID. * Gets the GUID.
* *
* @return GUID * @return GUID
*/ */
public String getGUID() { public String getGUID() {
...@@ -138,7 +136,7 @@ public final class Item { ...@@ -138,7 +136,7 @@ public final class Item {
/** /**
* Sets the GUID with the specified GUID. * Sets the GUID with the specified GUID.
* *
* @param guid the specified GUID * @param guid the specified GUID
*/ */
public void setGUID(final String guid) { public void setGUID(final String guid) {
......
...@@ -28,7 +28,7 @@ import org.pegdown.PegDownProcessor; ...@@ -28,7 +28,7 @@ import org.pegdown.PegDownProcessor;
* Uses the <a href="http://markdown.tautua.org/">MarkdownPapers</a> as the converter.</p> * Uses the <a href="http://markdown.tautua.org/">MarkdownPapers</a> as the converter.</p>
* *
* @author <a href="http://88250.b3log.org">Liang Ding</a> * @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 2.0.0.1, May 16, 2016 * @version 2.0.0.2, Nov 3, 2016
* @since 0.4.5 * @since 0.4.5
*/ */
public final class Markdowns { public final class Markdowns {
...@@ -50,7 +50,7 @@ public final class Markdowns { ...@@ -50,7 +50,7 @@ public final class Markdowns {
return ""; return "";
} }
final PegDownProcessor pegDownProcessor = new PegDownProcessor(Extensions.ALL, 5000); final PegDownProcessor pegDownProcessor = new PegDownProcessor(Extensions.ALL_OPTIONALS | Extensions.ALL_WITH_OPTIONALS, 5000);
String ret = pegDownProcessor.markdownToHtml(markdownText); String ret = pegDownProcessor.markdownToHtml(markdownText);
if (!StringUtils.startsWith(ret, "<p>")) { if (!StringUtils.startsWith(ret, "<p>")) {
......
package org.b3log.solo.processor;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.Keys;
import org.b3log.latke.model.User;
import org.b3log.latke.repository.Query;
import org.b3log.solo.AbstractTestCase;
import org.b3log.solo.service.InitService;
import org.b3log.solo.service.UserQueryService;
import org.json.JSONObject;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* {@link FeedProcessor} test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Nov 4, 2016
* @since 1.7.0
*/
@Test(suiteName = "processor")
public class FeedProcessorTestCase extends AbstractTestCase {
/**
* Init.
*
* @throws Exception exception
*/
@Test
public void init() throws Exception {
final InitService initService = getInitService();
final JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(User.USER_EMAIL, "test@gmail.com");
requestJSONObject.put(User.USER_NAME, "Admin");
requestJSONObject.put(User.USER_PASSWORD, "pass");
initService.init(requestJSONObject);
final UserQueryService userQueryService = getUserQueryService();
Assert.assertNotNull(userQueryService.getUserByEmail("test@gmail.com"));
}
/**
* blogArticlesAtom.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = "init")
public void blogArticlesAtom() throws Exception {
final HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getServletContext()).thenReturn(mock(ServletContext.class));
when(request.getRequestURI()).thenReturn("/blog-articles-feed.do");
when(request.getMethod()).thenReturn("GET");
final MockDispatcherServlet dispatcherServlet = new MockDispatcherServlet();
dispatcherServlet.init();
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
final HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getWriter()).thenReturn(printWriter);
dispatcherServlet.service(request, response);
final String content = stringWriter.toString();
Assert.assertTrue(StringUtils.startsWith(content, "<?xml version=\"1.0\"?>"));
}
/**
* tagArticlesAtom.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = "init")
public void tagArticlesAtom() throws Exception {
final HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getServletContext()).thenReturn(mock(ServletContext.class));
when(request.getRequestURI()).thenReturn("/tag-articles-feed.do");
when(request.getMethod()).thenReturn("GET");
final JSONObject tag = getTagRepository().get(new Query()).optJSONArray(Keys.RESULTS).optJSONObject(0);
when(request.getQueryString()).thenReturn("tag=" + tag.optString(Keys.OBJECT_ID));
final MockDispatcherServlet dispatcherServlet = new MockDispatcherServlet();
dispatcherServlet.init();
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
final HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getWriter()).thenReturn(printWriter);
dispatcherServlet.service(request, response);
final String content = stringWriter.toString();
Assert.assertTrue(StringUtils.startsWith(content, "<?xml version=\"1.0\""));
}
/**
* blogArticlesRSS.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = "init")
public void blogArticlesRSS() throws Exception {
final HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getServletContext()).thenReturn(mock(ServletContext.class));
when(request.getRequestURI()).thenReturn("/blog-articles-rss.do");
when(request.getMethod()).thenReturn("GET");
final MockDispatcherServlet dispatcherServlet = new MockDispatcherServlet();
dispatcherServlet.init();
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
final HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getWriter()).thenReturn(printWriter);
dispatcherServlet.service(request, response);
final String content = stringWriter.toString();
Assert.assertTrue(StringUtils.startsWith(content, "<?xml version=\"1.0\""));
}
/**
* tagArticlesRSS.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = "init")
public void tagArticlesRSS() throws Exception {
final HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getServletContext()).thenReturn(mock(ServletContext.class));
when(request.getRequestURI()).thenReturn("/tag-articles-rss.do");
when(request.getMethod()).thenReturn("GET");
final JSONObject tag = getTagRepository().get(new Query()).optJSONArray(Keys.RESULTS).optJSONObject(0);
when(request.getQueryString()).thenReturn("tag=" + tag.optString(Keys.OBJECT_ID));
final MockDispatcherServlet dispatcherServlet = new MockDispatcherServlet();
dispatcherServlet.init();
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
final HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getWriter()).thenReturn(printWriter);
dispatcherServlet.service(request, response);
final String content = stringWriter.toString();
Assert.assertTrue(StringUtils.startsWith(content, "<?xml version=\"1.0\""));
}
}
/*
* Copyright (c) 2010-2016, b3log.org & hacpai.com
*
* Licensed 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.b3log.solo.processor;
import java.io.PrintWriter;
import java.io.StringWriter;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.commons.lang.StringUtils;
import org.b3log.latke.Keys;
import org.b3log.latke.model.User;
import org.b3log.solo.AbstractTestCase;
import org.b3log.solo.service.InitService;
import org.b3log.solo.service.UserQueryService;
import org.json.JSONObject;
import static org.mockito.Mockito.*;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* {@link IndexProcessor} test case.
*
* @author <a href="http://88250.b3log.org">Liang Ding</a>
* @version 1.0.0.0, Nov 2, 2016
* @since 1.7.0
*/
@Test(suiteName = "processor")
public class InitProcessorTestCase extends AbstractTestCase {
/**
* Init.
*
* @throws Exception exception
*/
@Test
public void init() throws Exception {
final InitService initService = getInitService();
final JSONObject requestJSONObject = new JSONObject();
requestJSONObject.put(User.USER_EMAIL, "test@gmail.com");
requestJSONObject.put(User.USER_NAME, "Admin");
requestJSONObject.put(User.USER_PASSWORD, "pass");
initService.init(requestJSONObject);
final UserQueryService userQueryService = getUserQueryService();
Assert.assertNotNull(userQueryService.getUserByEmail("test@gmail.com"));
}
/**
* showIndex.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = "init")
public void showIndex() throws Exception {
final HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getServletContext()).thenReturn(mock(ServletContext.class));
when(request.getRequestURI()).thenReturn("");
when(request.getMethod()).thenReturn("GET");
when(request.getAttribute(Keys.TEMAPLTE_DIR_NAME)).thenReturn("next");
when(request.getAttribute(Keys.HttpRequest.START_TIME_MILLIS)).thenReturn(System.currentTimeMillis());
final MockDispatcherServlet dispatcherServlet = new MockDispatcherServlet();
dispatcherServlet.init();
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
final HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getWriter()).thenReturn(printWriter);
dispatcherServlet.service(request, response);
final String content = stringWriter.toString();
Assert.assertTrue(StringUtils.contains(content, "<title>Solo 示例</title>"));
}
/**
* showKillBrowser.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = "init")
public void showKillBrowser() throws Exception {
final HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getServletContext()).thenReturn(mock(ServletContext.class));
when(request.getRequestURI()).thenReturn("/kill-browser");
when(request.getMethod()).thenReturn("GET");
when(request.getAttribute(Keys.TEMAPLTE_DIR_NAME)).thenReturn("next");
when(request.getAttribute(Keys.HttpRequest.START_TIME_MILLIS)).thenReturn(System.currentTimeMillis());
final MockDispatcherServlet dispatcherServlet = new MockDispatcherServlet();
dispatcherServlet.init();
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
final HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getWriter()).thenReturn(printWriter);
dispatcherServlet.service(request, response);
final String content = stringWriter.toString();
Assert.assertTrue(StringUtils.contains(content, "<title>Solo 示例</title>"));
}
/**
* register.
*
* @throws Exception exception
*/
@Test(dependsOnMethods = "init")
public void register() throws Exception {
final HttpServletRequest request = mock(HttpServletRequest.class);
when(request.getServletContext()).thenReturn(mock(ServletContext.class));
when(request.getRequestURI()).thenReturn("/register");
when(request.getMethod()).thenReturn("GET");
when(request.getAttribute(Keys.TEMAPLTE_DIR_NAME)).thenReturn("next");
when(request.getAttribute(Keys.HttpRequest.START_TIME_MILLIS)).thenReturn(System.currentTimeMillis());
final MockDispatcherServlet dispatcherServlet = new MockDispatcherServlet();
dispatcherServlet.init();
final StringWriter stringWriter = new StringWriter();
final PrintWriter printWriter = new PrintWriter(stringWriter);
final HttpServletResponse response = mock(HttpServletResponse.class);
when(response.getWriter()).thenReturn(printWriter);
dispatcherServlet.service(request, response);
final String content = stringWriter.toString();
Assert.assertTrue(StringUtils.contains(content, "<title>Solo 示例</title>"));
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment