001
014
015 package com.liferay.portal.search.test;
016
017 import com.liferay.portal.kernel.search.Document;
018 import com.liferay.portal.kernel.search.DocumentHelper;
019 import com.liferay.portal.kernel.search.DocumentImpl;
020 import com.liferay.portal.kernel.search.Hits;
021 import com.liferay.portal.kernel.search.HitsImpl;
022 import com.liferay.portal.kernel.search.SearchResult;
023 import com.liferay.portal.kernel.search.result.SearchResultTranslator;
024 import com.liferay.portal.kernel.test.util.RandomTestUtil;
025
026 import java.util.List;
027
028
031 public class SearchTestUtil {
032
033 public static final String ATTACHMENT_OWNER_CLASS_NAME =
034 RandomTestUtil.randomString();
035
036 public static final long ATTACHMENT_OWNER_CLASS_NAME_ID =
037 RandomTestUtil.randomLong();
038
039 public static final long ATTACHMENT_OWNER_CLASS_PK =
040 RandomTestUtil.randomLong();
041
042 public static final long ENTRY_CLASS_PK = RandomTestUtil.randomLong();
043
044 public static final String SUMMARY_CONTENT = RandomTestUtil.randomString();
045
046 public static final String SUMMARY_TITLE = RandomTestUtil.randomString();
047
048 public static Document createAttachmentDocument(String entryClassName) {
049 return createAttachmentDocument(entryClassName, ENTRY_CLASS_PK);
050 }
051
052 public static Document createAttachmentDocument(
053 String entryClassName, long entryClassPK) {
054
055 Document document = createDocument(entryClassName, entryClassPK);
056
057 DocumentHelper documentHelper = new DocumentHelper(document);
058
059 documentHelper.setAttachmentOwnerKey(
060 ATTACHMENT_OWNER_CLASS_NAME_ID, ATTACHMENT_OWNER_CLASS_PK);
061
062 return document;
063 }
064
065 public static Document createDocument(String entryClassName) {
066 return createDocument(entryClassName, ENTRY_CLASS_PK);
067 }
068
069 public static Document createDocument(
070 String entryClassName, long entryClassPK) {
071
072 Document document = new DocumentImpl();
073
074 DocumentHelper documentHelper = new DocumentHelper(document);
075
076 documentHelper.setEntryKey(entryClassName, entryClassPK);
077
078 return document;
079 }
080
081 public static List<SearchResult> getSearchResults(
082 SearchResultTranslator searchResultTranslator, Document... documents) {
083
084 Hits hits = new HitsImpl();
085
086 hits.setDocs(documents);
087
088 return searchResultTranslator.translate(hits, null, null, null);
089 }
090
091 }