/modules/apps/fragment/fragment-test/src/testIntegration/java/com/liferay/fragment/service/test/FragmentEntryLocalServiceTest.java

https://github.com/danielreuther/liferay-portal · Java · 1138 lines · 912 code · 210 blank · 16 comment · 0 complexity · 6a811e3d4104e6dbb0d9727fb663f9a1 MD5 · raw file

  1. /**
  2. * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
  3. *
  4. * This library is free software; you can redistribute it and/or modify it under
  5. * the terms of the GNU Lesser General Public License as published by the Free
  6. * Software Foundation; either version 2.1 of the License, or (at your option)
  7. * any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful, but WITHOUT
  10. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  11. * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
  12. * details.
  13. */
  14. package com.liferay.fragment.service.test;
  15. import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
  16. import com.liferay.fragment.constants.FragmentConstants;
  17. import com.liferay.fragment.model.FragmentCollection;
  18. import com.liferay.fragment.model.FragmentEntry;
  19. import com.liferay.fragment.service.FragmentEntryLocalService;
  20. import com.liferay.fragment.service.persistence.FragmentEntryPersistence;
  21. import com.liferay.fragment.util.FragmentEntryTestUtil;
  22. import com.liferay.fragment.util.FragmentTestUtil;
  23. import com.liferay.fragment.util.comparator.FragmentEntryCreateDateComparator;
  24. import com.liferay.fragment.util.comparator.FragmentEntryNameComparator;
  25. import com.liferay.petra.string.StringPool;
  26. import com.liferay.portal.kernel.dao.orm.QueryUtil;
  27. import com.liferay.portal.kernel.json.JSONUtil;
  28. import com.liferay.portal.kernel.model.Group;
  29. import com.liferay.portal.kernel.service.GroupLocalServiceUtil;
  30. import com.liferay.portal.kernel.service.ServiceContext;
  31. import com.liferay.portal.kernel.test.rule.AggregateTestRule;
  32. import com.liferay.portal.kernel.test.rule.DeleteAfterTestRun;
  33. import com.liferay.portal.kernel.test.util.GroupTestUtil;
  34. import com.liferay.portal.kernel.test.util.RandomTestUtil;
  35. import com.liferay.portal.kernel.test.util.ServiceContextTestUtil;
  36. import com.liferay.portal.kernel.test.util.TestPropsValues;
  37. import com.liferay.portal.kernel.transaction.Propagation;
  38. import com.liferay.portal.kernel.util.FileUtil;
  39. import com.liferay.portal.kernel.util.StringUtil;
  40. import com.liferay.portal.kernel.workflow.WorkflowConstants;
  41. import com.liferay.portal.test.rule.Inject;
  42. import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
  43. import com.liferay.portal.test.rule.PersistenceTestRule;
  44. import com.liferay.portal.test.rule.TransactionalTestRule;
  45. import java.sql.Timestamp;
  46. import java.time.LocalDateTime;
  47. import java.time.temporal.ChronoUnit;
  48. import java.util.List;
  49. import org.junit.Assert;
  50. import org.junit.Before;
  51. import org.junit.ClassRule;
  52. import org.junit.Rule;
  53. import org.junit.Test;
  54. import org.junit.runner.RunWith;
  55. /**
  56. * @author Kyle Miho
  57. */
  58. @RunWith(Arquillian.class)
  59. public class FragmentEntryLocalServiceTest {
  60. @ClassRule
  61. @Rule
  62. public static final AggregateTestRule aggregateTestRule =
  63. new AggregateTestRule(
  64. new LiferayIntegrationTestRule(), PersistenceTestRule.INSTANCE,
  65. new TransactionalTestRule(
  66. Propagation.REQUIRED, "com.liferay.fragment.service"));
  67. @Before
  68. public void setUp() throws Exception {
  69. _group = GroupTestUtil.addGroup();
  70. _fragmentCollection = FragmentTestUtil.addFragmentCollection(
  71. _group.getGroupId());
  72. _updatedFragmentCollection = FragmentTestUtil.addFragmentCollection(
  73. _group.getGroupId());
  74. }
  75. @Test
  76. public void testAddFragmentEntryWithFragmentEntryKeyNameCssHtmlJsConfigurationPreviewFileEntryIdTypeAndStatus()
  77. throws Exception {
  78. String fragmentEntryKey = RandomTestUtil.randomString();
  79. String name = RandomTestUtil.randomString();
  80. String css = RandomTestUtil.randomString();
  81. String html = RandomTestUtil.randomString();
  82. String js = RandomTestUtil.randomString();
  83. String configuration = _read("configuration-valid-complete.json");
  84. long previewFileEntryId = RandomTestUtil.randomLong();
  85. int type = FragmentConstants.TYPE_COMPONENT;
  86. int status = WorkflowConstants.STATUS_APPROVED;
  87. FragmentEntry fragmentEntry =
  88. _fragmentEntryLocalService.addFragmentEntry(
  89. TestPropsValues.getUserId(), _group.getGroupId(),
  90. _fragmentCollection.getFragmentCollectionId(), fragmentEntryKey,
  91. name, css, html, js, false, configuration, null,
  92. previewFileEntryId, type, null, status,
  93. ServiceContextTestUtil.getServiceContext(
  94. _group.getGroupId(), TestPropsValues.getUserId()));
  95. FragmentEntry persistedFragmentEntry =
  96. _fragmentEntryPersistence.fetchByPrimaryKey(
  97. fragmentEntry.getFragmentEntryId());
  98. Assert.assertEquals(
  99. StringUtil.toLowerCase(fragmentEntryKey),
  100. persistedFragmentEntry.getFragmentEntryKey());
  101. Assert.assertEquals(name, persistedFragmentEntry.getName());
  102. Assert.assertEquals(css, persistedFragmentEntry.getCss());
  103. Assert.assertEquals(html, persistedFragmentEntry.getHtml());
  104. Assert.assertEquals(js, persistedFragmentEntry.getJs());
  105. Assert.assertEquals(
  106. configuration, persistedFragmentEntry.getConfiguration());
  107. Assert.assertEquals(
  108. previewFileEntryId, persistedFragmentEntry.getPreviewFileEntryId());
  109. Assert.assertEquals(type, persistedFragmentEntry.getType());
  110. Assert.assertEquals(status, persistedFragmentEntry.getStatus());
  111. }
  112. @Test
  113. public void testAddFragmentEntryWithFragmentEntryKeyNameCssHtmlJsPreviewFileEntryIdAndStatus()
  114. throws Exception {
  115. String fragmentEntryKey = RandomTestUtil.randomString();
  116. String name = RandomTestUtil.randomString();
  117. String css = RandomTestUtil.randomString();
  118. String html = RandomTestUtil.randomString();
  119. String js = RandomTestUtil.randomString();
  120. long previewFileEntryId = RandomTestUtil.randomLong();
  121. int status = WorkflowConstants.STATUS_APPROVED;
  122. FragmentEntry fragmentEntry =
  123. _fragmentEntryLocalService.addFragmentEntry(
  124. TestPropsValues.getUserId(), _group.getGroupId(),
  125. _fragmentCollection.getFragmentCollectionId(), fragmentEntryKey,
  126. name, css, html, js, false, StringPool.BLANK, null,
  127. previewFileEntryId, FragmentConstants.TYPE_COMPONENT, null,
  128. status,
  129. ServiceContextTestUtil.getServiceContext(
  130. _group.getGroupId(), TestPropsValues.getUserId()));
  131. FragmentEntry persistedFragmentEntry =
  132. _fragmentEntryPersistence.fetchByPrimaryKey(
  133. fragmentEntry.getFragmentEntryId());
  134. Assert.assertEquals(
  135. StringUtil.toLowerCase(fragmentEntryKey),
  136. persistedFragmentEntry.getFragmentEntryKey());
  137. Assert.assertEquals(name, persistedFragmentEntry.getName());
  138. Assert.assertEquals(css, persistedFragmentEntry.getCss());
  139. Assert.assertEquals(html, persistedFragmentEntry.getHtml());
  140. Assert.assertEquals(js, persistedFragmentEntry.getJs());
  141. Assert.assertEquals(
  142. previewFileEntryId, persistedFragmentEntry.getPreviewFileEntryId());
  143. Assert.assertEquals(status, persistedFragmentEntry.getStatus());
  144. }
  145. @Test
  146. public void testAddFragmentEntryWithFragmentEntryKeyNameCssHtmlJsPreviewFileEntryIdTypeAndStatus()
  147. throws Exception {
  148. String fragmentEntryKey = RandomTestUtil.randomString();
  149. String name = RandomTestUtil.randomString();
  150. String css = RandomTestUtil.randomString();
  151. String html = RandomTestUtil.randomString();
  152. String js = RandomTestUtil.randomString();
  153. long previewFileEntryId = RandomTestUtil.randomLong();
  154. int type = FragmentConstants.TYPE_COMPONENT;
  155. int status = WorkflowConstants.STATUS_APPROVED;
  156. FragmentEntry fragmentEntry =
  157. _fragmentEntryLocalService.addFragmentEntry(
  158. TestPropsValues.getUserId(), _group.getGroupId(),
  159. _fragmentCollection.getFragmentCollectionId(), fragmentEntryKey,
  160. name, css, html, js, false, StringPool.BLANK, null,
  161. previewFileEntryId, type, null, status,
  162. ServiceContextTestUtil.getServiceContext(
  163. _group.getGroupId(), TestPropsValues.getUserId()));
  164. FragmentEntry persistedFragmentEntry =
  165. _fragmentEntryPersistence.fetchByPrimaryKey(
  166. fragmentEntry.getFragmentEntryId());
  167. Assert.assertEquals(
  168. StringUtil.toLowerCase(fragmentEntryKey),
  169. persistedFragmentEntry.getFragmentEntryKey());
  170. Assert.assertEquals(name, persistedFragmentEntry.getName());
  171. Assert.assertEquals(css, persistedFragmentEntry.getCss());
  172. Assert.assertEquals(html, persistedFragmentEntry.getHtml());
  173. Assert.assertEquals(js, persistedFragmentEntry.getJs());
  174. Assert.assertEquals(
  175. previewFileEntryId, persistedFragmentEntry.getPreviewFileEntryId());
  176. Assert.assertEquals(type, persistedFragmentEntry.getType());
  177. Assert.assertEquals(status, persistedFragmentEntry.getStatus());
  178. }
  179. @Test
  180. public void testAddFragmentEntryWithFragmentEntryKeyNameCssHtmlJsTypeAndStatus()
  181. throws Exception {
  182. String fragmentEntryKey = RandomTestUtil.randomString();
  183. String name = RandomTestUtil.randomString();
  184. String css = RandomTestUtil.randomString();
  185. String html = RandomTestUtil.randomString();
  186. String js = RandomTestUtil.randomString();
  187. int type = FragmentConstants.TYPE_COMPONENT;
  188. int status = WorkflowConstants.STATUS_APPROVED;
  189. FragmentEntry fragmentEntry =
  190. _fragmentEntryLocalService.addFragmentEntry(
  191. TestPropsValues.getUserId(), _group.getGroupId(),
  192. _fragmentCollection.getFragmentCollectionId(), fragmentEntryKey,
  193. name, css, html, js, false, StringPool.BLANK, null, 0, type,
  194. null, status,
  195. ServiceContextTestUtil.getServiceContext(
  196. _group.getGroupId(), TestPropsValues.getUserId()));
  197. FragmentEntry persistedFragmentEntry =
  198. _fragmentEntryPersistence.fetchByPrimaryKey(
  199. fragmentEntry.getFragmentEntryId());
  200. Assert.assertEquals(
  201. StringUtil.toLowerCase(fragmentEntryKey),
  202. persistedFragmentEntry.getFragmentEntryKey());
  203. Assert.assertEquals(name, persistedFragmentEntry.getName());
  204. Assert.assertEquals(css, persistedFragmentEntry.getCss());
  205. Assert.assertEquals(html, persistedFragmentEntry.getHtml());
  206. Assert.assertEquals(js, persistedFragmentEntry.getJs());
  207. Assert.assertEquals(type, persistedFragmentEntry.getType());
  208. Assert.assertEquals(status, persistedFragmentEntry.getStatus());
  209. }
  210. @Test
  211. public void testAddFragmentEntryWithFragmentEntryKeyNamePreviewFileEntryIdTypeAndStatus()
  212. throws Exception {
  213. String fragmentEntryKey = RandomTestUtil.randomString();
  214. String name = RandomTestUtil.randomString();
  215. long previewFileEntryId = RandomTestUtil.randomLong();
  216. int type = FragmentConstants.TYPE_COMPONENT;
  217. int status = WorkflowConstants.STATUS_DRAFT;
  218. FragmentEntry fragmentEntry =
  219. _fragmentEntryLocalService.addFragmentEntry(
  220. TestPropsValues.getUserId(), _group.getGroupId(),
  221. _fragmentCollection.getFragmentCollectionId(), fragmentEntryKey,
  222. name, StringPool.BLANK, StringPool.BLANK, StringPool.BLANK,
  223. false, StringPool.BLANK, null, previewFileEntryId, type, null,
  224. status,
  225. ServiceContextTestUtil.getServiceContext(
  226. _group.getGroupId(), TestPropsValues.getUserId()));
  227. FragmentEntry persistedFragmentEntry =
  228. _fragmentEntryPersistence.fetchByPrimaryKey(
  229. fragmentEntry.getFragmentEntryId());
  230. Assert.assertEquals(
  231. StringUtil.toLowerCase(fragmentEntryKey),
  232. persistedFragmentEntry.getFragmentEntryKey());
  233. Assert.assertEquals(name, persistedFragmentEntry.getName());
  234. Assert.assertEquals(
  235. previewFileEntryId, persistedFragmentEntry.getPreviewFileEntryId());
  236. Assert.assertEquals(type, persistedFragmentEntry.getType());
  237. Assert.assertEquals(status, persistedFragmentEntry.getStatus());
  238. }
  239. @Test
  240. public void testAddFragmentEntryWithHtmlWithAmpersand() throws Exception {
  241. String html = "<H1>A&B&amp;C</H1>";
  242. FragmentEntry fragmentEntry =
  243. _fragmentEntryLocalService.addFragmentEntry(
  244. TestPropsValues.getUserId(), _group.getGroupId(),
  245. _fragmentCollection.getFragmentCollectionId(),
  246. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  247. StringPool.BLANK, html, StringPool.BLANK, false,
  248. StringPool.BLANK, null, RandomTestUtil.randomLong(),
  249. FragmentConstants.TYPE_COMPONENT, null,
  250. WorkflowConstants.STATUS_APPROVED,
  251. ServiceContextTestUtil.getServiceContext(
  252. _group.getGroupId(), TestPropsValues.getUserId()));
  253. FragmentEntry persistedFragmentEntry =
  254. _fragmentEntryPersistence.fetchByPrimaryKey(
  255. fragmentEntry.getFragmentEntryId());
  256. Assert.assertEquals(html, persistedFragmentEntry.getHtml());
  257. }
  258. @Test
  259. public void testAddFragmentEntryWithNameCssHtmlJsAndStatus()
  260. throws Exception {
  261. String name = RandomTestUtil.randomString();
  262. String css = RandomTestUtil.randomString();
  263. String html = RandomTestUtil.randomString();
  264. String js = RandomTestUtil.randomString();
  265. int status = WorkflowConstants.STATUS_APPROVED;
  266. FragmentEntry fragmentEntry =
  267. _fragmentEntryLocalService.addFragmentEntry(
  268. TestPropsValues.getUserId(), _group.getGroupId(),
  269. _fragmentCollection.getFragmentCollectionId(),
  270. RandomTestUtil.randomString(), name, css, html, js, false,
  271. StringPool.BLANK, null, RandomTestUtil.randomLong(),
  272. FragmentConstants.TYPE_COMPONENT, null, status,
  273. ServiceContextTestUtil.getServiceContext(
  274. _group.getGroupId(), TestPropsValues.getUserId()));
  275. FragmentEntry persistedFragmentEntry =
  276. _fragmentEntryPersistence.fetchByPrimaryKey(
  277. fragmentEntry.getFragmentEntryId());
  278. Assert.assertEquals(name, persistedFragmentEntry.getName());
  279. Assert.assertEquals(css, persistedFragmentEntry.getCss());
  280. Assert.assertEquals(html, persistedFragmentEntry.getHtml());
  281. Assert.assertEquals(js, persistedFragmentEntry.getJs());
  282. Assert.assertEquals(status, persistedFragmentEntry.getStatus());
  283. }
  284. @Test
  285. public void testAddFragmentEntryWithNameCssHtmlJsPreviewFileEntryIdAndStatus()
  286. throws Exception {
  287. String name = RandomTestUtil.randomString();
  288. String css = RandomTestUtil.randomString();
  289. String html = RandomTestUtil.randomString();
  290. String js = RandomTestUtil.randomString();
  291. long previewFileEntryId = RandomTestUtil.randomLong();
  292. int status = WorkflowConstants.STATUS_APPROVED;
  293. FragmentEntry fragmentEntry =
  294. _fragmentEntryLocalService.addFragmentEntry(
  295. TestPropsValues.getUserId(), _group.getGroupId(),
  296. _fragmentCollection.getFragmentCollectionId(),
  297. RandomTestUtil.randomString(), name, css, html, js, false,
  298. StringPool.BLANK, null, previewFileEntryId,
  299. FragmentConstants.TYPE_COMPONENT, null, status,
  300. ServiceContextTestUtil.getServiceContext(
  301. _group.getGroupId(), TestPropsValues.getUserId()));
  302. FragmentEntry persistedFragmentEntry =
  303. _fragmentEntryPersistence.fetchByPrimaryKey(
  304. fragmentEntry.getFragmentEntryId());
  305. Assert.assertEquals(name, persistedFragmentEntry.getName());
  306. Assert.assertEquals(css, persistedFragmentEntry.getCss());
  307. Assert.assertEquals(html, persistedFragmentEntry.getHtml());
  308. Assert.assertEquals(js, persistedFragmentEntry.getJs());
  309. Assert.assertEquals(
  310. previewFileEntryId, persistedFragmentEntry.getPreviewFileEntryId());
  311. Assert.assertEquals(status, persistedFragmentEntry.getStatus());
  312. }
  313. @Test
  314. public void testAddFragmentEntryWithNameCssHtmlJsPreviewFileEntryIdTypeAndStatus()
  315. throws Exception {
  316. String name = RandomTestUtil.randomString();
  317. String css = RandomTestUtil.randomString();
  318. String html = RandomTestUtil.randomString();
  319. String js = RandomTestUtil.randomString();
  320. long previewFileEntryId = RandomTestUtil.randomLong();
  321. int type = FragmentConstants.TYPE_COMPONENT;
  322. int status = WorkflowConstants.STATUS_APPROVED;
  323. FragmentEntry fragmentEntry =
  324. _fragmentEntryLocalService.addFragmentEntry(
  325. TestPropsValues.getUserId(), _group.getGroupId(),
  326. _fragmentCollection.getFragmentCollectionId(),
  327. RandomTestUtil.randomString(), name, css, html, js, false,
  328. StringPool.BLANK, null, previewFileEntryId,
  329. FragmentConstants.TYPE_COMPONENT, null, status,
  330. ServiceContextTestUtil.getServiceContext(
  331. _group.getGroupId(), TestPropsValues.getUserId()));
  332. FragmentEntry persistedFragmentEntry =
  333. _fragmentEntryPersistence.fetchByPrimaryKey(
  334. fragmentEntry.getFragmentEntryId());
  335. Assert.assertEquals(name, persistedFragmentEntry.getName());
  336. Assert.assertEquals(css, persistedFragmentEntry.getCss());
  337. Assert.assertEquals(html, persistedFragmentEntry.getHtml());
  338. Assert.assertEquals(js, persistedFragmentEntry.getJs());
  339. Assert.assertEquals(
  340. previewFileEntryId, persistedFragmentEntry.getPreviewFileEntryId());
  341. Assert.assertEquals(type, persistedFragmentEntry.getType());
  342. Assert.assertEquals(status, persistedFragmentEntry.getStatus());
  343. }
  344. @Test
  345. public void testAddFragmentEntryWithNameCssHtmlJsTypeAndStatus()
  346. throws Exception {
  347. String name = RandomTestUtil.randomString();
  348. String css = RandomTestUtil.randomString();
  349. String html = RandomTestUtil.randomString();
  350. String js = RandomTestUtil.randomString();
  351. int type = FragmentConstants.TYPE_COMPONENT;
  352. int status = WorkflowConstants.STATUS_APPROVED;
  353. FragmentEntry fragmentEntry =
  354. _fragmentEntryLocalService.addFragmentEntry(
  355. TestPropsValues.getUserId(), _group.getGroupId(),
  356. _fragmentCollection.getFragmentCollectionId(),
  357. RandomTestUtil.randomString(), name, css, html, js, false,
  358. StringPool.BLANK, null, 0, FragmentConstants.TYPE_COMPONENT,
  359. null, status,
  360. ServiceContextTestUtil.getServiceContext(
  361. _group.getGroupId(), TestPropsValues.getUserId()));
  362. FragmentEntry persistedFragmentEntry =
  363. _fragmentEntryPersistence.fetchByPrimaryKey(
  364. fragmentEntry.getFragmentEntryId());
  365. Assert.assertEquals(name, persistedFragmentEntry.getName());
  366. Assert.assertEquals(css, persistedFragmentEntry.getCss());
  367. Assert.assertEquals(html, persistedFragmentEntry.getHtml());
  368. Assert.assertEquals(js, persistedFragmentEntry.getJs());
  369. Assert.assertEquals(type, persistedFragmentEntry.getType());
  370. Assert.assertEquals(status, persistedFragmentEntry.getStatus());
  371. }
  372. @Test
  373. public void testAddInputFragmentEntry() throws Exception {
  374. String fragmentEntryKey = RandomTestUtil.randomString();
  375. String typeOptions = JSONUtil.put(
  376. "fieldTypes", JSONUtil.put("string")
  377. ).toString();
  378. FragmentEntry fragmentEntry =
  379. _fragmentEntryLocalService.addFragmentEntry(
  380. TestPropsValues.getUserId(), _group.getGroupId(),
  381. _fragmentCollection.getFragmentCollectionId(), fragmentEntryKey,
  382. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  383. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  384. false, "{fieldSets: []}", null, 0, FragmentConstants.TYPE_INPUT,
  385. typeOptions, WorkflowConstants.STATUS_APPROVED,
  386. ServiceContextTestUtil.getServiceContext(
  387. _group.getGroupId(), TestPropsValues.getUserId()));
  388. FragmentEntry persistedFragmentEntry =
  389. _fragmentEntryLocalService.fetchFragmentEntry(
  390. _group.getGroupId(), fragmentEntryKey);
  391. Assert.assertEquals(fragmentEntry, persistedFragmentEntry);
  392. Assert.assertEquals(
  393. typeOptions, persistedFragmentEntry.getTypeOptions());
  394. }
  395. @Test
  396. public void testCopyFragmentEntry() throws Exception {
  397. ServiceContext serviceContext =
  398. ServiceContextTestUtil.getServiceContext(
  399. _group.getGroupId(), TestPropsValues.getUserId());
  400. FragmentEntry fragmentEntry =
  401. _fragmentEntryLocalService.addFragmentEntry(
  402. TestPropsValues.getUserId(), _group.getGroupId(),
  403. _fragmentCollection.getFragmentCollectionId(),
  404. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  405. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  406. RandomTestUtil.randomString(), false, StringPool.BLANK, null, 0,
  407. FragmentConstants.TYPE_COMPONENT, null,
  408. WorkflowConstants.STATUS_APPROVED, serviceContext);
  409. FragmentEntry copyFragmentEntry =
  410. _fragmentEntryLocalService.copyFragmentEntry(
  411. TestPropsValues.getUserId(), _group.getGroupId(),
  412. fragmentEntry.getFragmentEntryId(),
  413. fragmentEntry.getFragmentCollectionId(), serviceContext);
  414. _assertCopyFragmentEntry(fragmentEntry, copyFragmentEntry);
  415. Assert.assertEquals(
  416. fragmentEntry.getFragmentCollectionId(),
  417. copyFragmentEntry.getFragmentCollectionId());
  418. }
  419. @Test
  420. public void testCopyFragmentEntryToDifferentCollection() throws Exception {
  421. ServiceContext serviceContext =
  422. ServiceContextTestUtil.getServiceContext(
  423. _group.getGroupId(), TestPropsValues.getUserId());
  424. FragmentCollection targetFragmentCollection =
  425. FragmentTestUtil.addFragmentCollection(_group.getGroupId());
  426. FragmentEntry fragmentEntry =
  427. _fragmentEntryLocalService.addFragmentEntry(
  428. TestPropsValues.getUserId(), _group.getGroupId(),
  429. _fragmentCollection.getFragmentCollectionId(),
  430. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  431. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  432. RandomTestUtil.randomString(), false, StringPool.BLANK, null, 0,
  433. FragmentConstants.TYPE_COMPONENT, null,
  434. WorkflowConstants.STATUS_APPROVED, serviceContext);
  435. FragmentEntry copyFragmentEntry =
  436. _fragmentEntryLocalService.copyFragmentEntry(
  437. TestPropsValues.getUserId(), _group.getGroupId(),
  438. fragmentEntry.getFragmentEntryId(),
  439. targetFragmentCollection.getFragmentCollectionId(),
  440. serviceContext);
  441. _assertCopyFragmentEntry(fragmentEntry, copyFragmentEntry);
  442. Assert.assertEquals(
  443. targetFragmentCollection.getFragmentCollectionId(),
  444. copyFragmentEntry.getFragmentCollectionId());
  445. }
  446. @Test
  447. public void testCopyInputFragmentEntry() throws Exception {
  448. ServiceContext serviceContext =
  449. ServiceContextTestUtil.getServiceContext(
  450. _group.getGroupId(), TestPropsValues.getUserId());
  451. String typeOptions = JSONUtil.put(
  452. "fieldTypes", JSONUtil.put("string")
  453. ).toString();
  454. FragmentEntry fragmentEntry =
  455. _fragmentEntryLocalService.addFragmentEntry(
  456. TestPropsValues.getUserId(), _group.getGroupId(),
  457. _fragmentCollection.getFragmentCollectionId(),
  458. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  459. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  460. RandomTestUtil.randomString(), false, StringPool.BLANK, null, 0,
  461. FragmentConstants.TYPE_INPUT, typeOptions,
  462. WorkflowConstants.STATUS_APPROVED, serviceContext);
  463. FragmentEntry copyFragmentEntry =
  464. _fragmentEntryLocalService.copyFragmentEntry(
  465. TestPropsValues.getUserId(), _group.getGroupId(),
  466. fragmentEntry.getFragmentEntryId(),
  467. fragmentEntry.getFragmentCollectionId(), serviceContext);
  468. _assertCopyFragmentEntry(fragmentEntry, copyFragmentEntry);
  469. Assert.assertEquals(
  470. fragmentEntry.getFragmentCollectionId(),
  471. copyFragmentEntry.getFragmentCollectionId());
  472. Assert.assertEquals(typeOptions, copyFragmentEntry.getTypeOptions());
  473. }
  474. @Test
  475. public void testDeleteFragmentEntry() throws Exception {
  476. FragmentEntry fragmentEntry = FragmentEntryTestUtil.addFragmentEntry(
  477. _fragmentCollection.getFragmentCollectionId());
  478. _fragmentEntryLocalService.deleteFragmentEntry(
  479. fragmentEntry.getFragmentEntryId());
  480. Assert.assertNull(
  481. _fragmentEntryPersistence.fetchByPrimaryKey(
  482. fragmentEntry.getFragmentEntryId()));
  483. }
  484. @Test
  485. public void testDeleteFragmentEntryByFragmentEntryId() throws Exception {
  486. FragmentEntry fragmentEntry = FragmentEntryTestUtil.addFragmentEntry(
  487. _fragmentCollection.getFragmentCollectionId());
  488. _fragmentEntryLocalService.deleteFragmentEntry(
  489. fragmentEntry.getFragmentEntryId());
  490. Assert.assertNull(
  491. _fragmentEntryPersistence.fetchByPrimaryKey(
  492. fragmentEntry.getFragmentEntryId()));
  493. }
  494. @Test
  495. public void testFetchFragmentEntryByFragmentEntryId() throws Exception {
  496. FragmentEntry fragmentEntry = FragmentEntryTestUtil.addFragmentEntry(
  497. _fragmentCollection.getFragmentCollectionId());
  498. FragmentEntry persistedFragmentEntry =
  499. _fragmentEntryLocalService.fetchFragmentEntry(
  500. fragmentEntry.getFragmentEntryId());
  501. Assert.assertEquals(fragmentEntry, persistedFragmentEntry);
  502. }
  503. @Test
  504. public void testFetchFragmentEntryByGroupIdAndFragmentEntryKey()
  505. throws Exception {
  506. String fragmentEntryKey = RandomTestUtil.randomString();
  507. FragmentEntry fragmentEntry =
  508. _fragmentEntryLocalService.addFragmentEntry(
  509. TestPropsValues.getUserId(), _group.getGroupId(),
  510. _fragmentCollection.getFragmentCollectionId(), fragmentEntryKey,
  511. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  512. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  513. false, "{fieldSets: []}", null, 0,
  514. FragmentConstants.TYPE_COMPONENT, null,
  515. WorkflowConstants.STATUS_APPROVED,
  516. ServiceContextTestUtil.getServiceContext(
  517. _group.getGroupId(), TestPropsValues.getUserId()));
  518. FragmentEntry persistedFragmentEntry =
  519. _fragmentEntryLocalService.fetchFragmentEntry(
  520. _group.getGroupId(), fragmentEntryKey);
  521. Assert.assertEquals(fragmentEntry, persistedFragmentEntry);
  522. }
  523. @Test
  524. public void testGenerateFragmentEntryKey() throws Exception {
  525. _fragmentEntryLocalService.addFragmentEntry(
  526. TestPropsValues.getUserId(), _group.getGroupId(),
  527. _fragmentCollection.getFragmentCollectionId(), "test-key",
  528. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  529. RandomTestUtil.randomString(), RandomTestUtil.randomString(), false,
  530. "{fieldSets: []}", null, 0, FragmentConstants.TYPE_COMPONENT, null,
  531. WorkflowConstants.STATUS_APPROVED,
  532. ServiceContextTestUtil.getServiceContext(
  533. _group.getGroupId(), TestPropsValues.getUserId()));
  534. String fragmentEntryKey =
  535. _fragmentEntryLocalService.generateFragmentEntryKey(
  536. _group.getGroupId(), "Test Key");
  537. Assert.assertEquals("test-key-0", fragmentEntryKey);
  538. }
  539. @Test
  540. public void testGetFragmentEntriesByFragmentCollectionId()
  541. throws Exception {
  542. List<FragmentEntry> originalFragmentEntries =
  543. _fragmentEntryLocalService.getFragmentEntries(
  544. _fragmentCollection.getFragmentCollectionId());
  545. FragmentEntryTestUtil.addFragmentEntry(
  546. _fragmentCollection.getFragmentCollectionId());
  547. FragmentEntryTestUtil.addFragmentEntry(
  548. _fragmentCollection.getFragmentCollectionId());
  549. List<FragmentEntry> actualFragmentEntries =
  550. _fragmentEntryLocalService.getFragmentEntries(
  551. _fragmentCollection.getFragmentCollectionId());
  552. Assert.assertEquals(
  553. actualFragmentEntries.toString(),
  554. originalFragmentEntries.size() + 2, actualFragmentEntries.size());
  555. }
  556. @Test
  557. public void testGetFragmentEntriesByGroupIdAndFragmentCollectionIdOrderByCreateDateComparator()
  558. throws Exception {
  559. LocalDateTime localDateTime = LocalDateTime.now();
  560. FragmentEntry fragmentEntry = FragmentEntryTestUtil.addFragmentEntry(
  561. _fragmentCollection.getFragmentCollectionId(), "AB Fragment Entry",
  562. Timestamp.valueOf(localDateTime));
  563. localDateTime = localDateTime.plus(1, ChronoUnit.SECONDS);
  564. FragmentEntryTestUtil.addFragmentEntry(
  565. _fragmentCollection.getFragmentCollectionId(), "AA Fragment Entry",
  566. Timestamp.valueOf(localDateTime));
  567. List<FragmentEntry> fragmentEntries =
  568. _fragmentEntryLocalService.getFragmentEntries(
  569. _group.getGroupId(),
  570. _fragmentCollection.getFragmentCollectionId(),
  571. QueryUtil.ALL_POS, QueryUtil.ALL_POS,
  572. new FragmentEntryCreateDateComparator(true));
  573. FragmentEntry firstFragmentEntry = fragmentEntries.get(0);
  574. Assert.assertEquals(
  575. fragmentEntries.toString(), fragmentEntry.getName(),
  576. firstFragmentEntry.getName());
  577. fragmentEntries = _fragmentEntryLocalService.getFragmentEntries(
  578. _group.getGroupId(), _fragmentCollection.getFragmentCollectionId(),
  579. QueryUtil.ALL_POS, QueryUtil.ALL_POS,
  580. new FragmentEntryCreateDateComparator(false));
  581. FragmentEntry lastFragmentEntry = fragmentEntries.get(
  582. fragmentEntries.size() - 1);
  583. Assert.assertEquals(
  584. fragmentEntries.toString(), fragmentEntry.getName(),
  585. lastFragmentEntry.getName());
  586. }
  587. @Test
  588. public void testGetFragmentEntriesByGroupIdAndFragmentCollectionIdOrderByNameComparator()
  589. throws Exception {
  590. FragmentEntry fragmentEntry = FragmentEntryTestUtil.addFragmentEntry(
  591. _fragmentCollection.getFragmentCollectionId(), "AB Fragment Entry");
  592. FragmentEntryTestUtil.addFragmentEntry(
  593. _fragmentCollection.getFragmentCollectionId(), "AA Fragment Entry");
  594. List<FragmentEntry> fragmentEntries =
  595. _fragmentEntryLocalService.getFragmentEntries(
  596. _group.getGroupId(),
  597. _fragmentCollection.getFragmentCollectionId(),
  598. QueryUtil.ALL_POS, QueryUtil.ALL_POS,
  599. new FragmentEntryNameComparator(true));
  600. FragmentEntry lastFragmentEntry = fragmentEntries.get(
  601. fragmentEntries.size() - 1);
  602. Assert.assertEquals(
  603. fragmentEntries.toString(), fragmentEntry.getName(),
  604. lastFragmentEntry.getName());
  605. fragmentEntries = _fragmentEntryLocalService.getFragmentEntries(
  606. _group.getGroupId(), _fragmentCollection.getFragmentCollectionId(),
  607. QueryUtil.ALL_POS, QueryUtil.ALL_POS,
  608. new FragmentEntryNameComparator(false));
  609. FragmentEntry firstFragmentEntry = fragmentEntries.get(0);
  610. Assert.assertEquals(
  611. fragmentEntries.toString(), fragmentEntry.getName(),
  612. firstFragmentEntry.getName());
  613. }
  614. @Test
  615. public void testGetFragmentEntriesByGroupIdFragmentCollectionIdAndNameOrderByCreateDateComparator()
  616. throws Exception {
  617. LocalDateTime localDateTime = LocalDateTime.now();
  618. FragmentEntry fragmentEntry = FragmentEntryTestUtil.addFragmentEntry(
  619. _fragmentCollection.getFragmentCollectionId(), "AC Fragment Entry",
  620. Timestamp.valueOf(localDateTime));
  621. localDateTime = localDateTime.plus(1, ChronoUnit.SECONDS);
  622. FragmentEntryTestUtil.addFragmentEntry(
  623. _fragmentCollection.getFragmentCollectionId(), "AA Fragment",
  624. Timestamp.valueOf(localDateTime));
  625. localDateTime = localDateTime.plus(1, ChronoUnit.SECONDS);
  626. FragmentEntryTestUtil.addFragmentEntry(
  627. _fragmentCollection.getFragmentCollectionId(), "AB Fragment Entry",
  628. Timestamp.valueOf(localDateTime));
  629. List<FragmentEntry> fragmentEntries =
  630. _fragmentEntryLocalService.getFragmentEntries(
  631. _group.getGroupId(),
  632. _fragmentCollection.getFragmentCollectionId(), "Entry",
  633. QueryUtil.ALL_POS, QueryUtil.ALL_POS,
  634. new FragmentEntryCreateDateComparator(true));
  635. FragmentEntry firstFragmentEntry = fragmentEntries.get(0);
  636. Assert.assertEquals(
  637. fragmentEntries.toString(), fragmentEntry.getName(),
  638. firstFragmentEntry.getName());
  639. fragmentEntries = _fragmentEntryLocalService.getFragmentEntries(
  640. _group.getGroupId(), _fragmentCollection.getFragmentCollectionId(),
  641. "Entry", QueryUtil.ALL_POS, QueryUtil.ALL_POS,
  642. new FragmentEntryCreateDateComparator(false));
  643. FragmentEntry lastFragmentEntry = fragmentEntries.get(
  644. fragmentEntries.size() - 1);
  645. Assert.assertEquals(
  646. fragmentEntries.toString(), fragmentEntry.getName(),
  647. lastFragmentEntry.getName());
  648. }
  649. @Test
  650. public void testGetFragmentEntriesByGroupIdFragmentCollectionIdAndNameOrderByNameComparator()
  651. throws Exception {
  652. FragmentEntry fragmentEntry = FragmentEntryTestUtil.addFragmentEntry(
  653. _fragmentCollection.getFragmentCollectionId(), "AB Fragment Entry");
  654. FragmentEntryTestUtil.addFragmentEntry(
  655. _fragmentCollection.getFragmentCollectionId(), "AA Fragment");
  656. FragmentEntryTestUtil.addFragmentEntry(
  657. _fragmentCollection.getFragmentCollectionId(), "AC Fragment Entry");
  658. List<FragmentEntry> fragmentEntries =
  659. _fragmentEntryLocalService.getFragmentEntries(
  660. _group.getGroupId(),
  661. _fragmentCollection.getFragmentCollectionId(), "Entry",
  662. QueryUtil.ALL_POS, QueryUtil.ALL_POS,
  663. new FragmentEntryNameComparator(true));
  664. FragmentEntry firstFragmentEntry = fragmentEntries.get(0);
  665. Assert.assertEquals(
  666. fragmentEntries.toString(), fragmentEntry.getName(),
  667. firstFragmentEntry.getName());
  668. fragmentEntries = _fragmentEntryLocalService.getFragmentEntries(
  669. _group.getGroupId(), _fragmentCollection.getFragmentCollectionId(),
  670. "Entry", QueryUtil.ALL_POS, QueryUtil.ALL_POS,
  671. new FragmentEntryNameComparator(false));
  672. FragmentEntry lastFragmentEntry = fragmentEntries.get(
  673. fragmentEntries.size() - 1);
  674. Assert.assertEquals(
  675. fragmentEntries.toString(), fragmentEntry.getName(),
  676. lastFragmentEntry.getName());
  677. }
  678. @Test
  679. public void testGetFragmentEntriesByGroupIdFragmentCollectionIdAndStatus()
  680. throws Exception {
  681. List<FragmentEntry> originalFragmentEntries =
  682. _fragmentEntryLocalService.getFragmentEntries(
  683. _group.getGroupId(),
  684. _fragmentCollection.getFragmentCollectionId(),
  685. WorkflowConstants.STATUS_DRAFT);
  686. FragmentEntryTestUtil.addFragmentEntryByStatus(
  687. _fragmentCollection.getFragmentCollectionId(),
  688. WorkflowConstants.STATUS_APPROVED);
  689. FragmentEntryTestUtil.addFragmentEntryByStatus(
  690. _fragmentCollection.getFragmentCollectionId(),
  691. WorkflowConstants.STATUS_DRAFT);
  692. FragmentEntryTestUtil.addFragmentEntryByStatus(
  693. _fragmentCollection.getFragmentCollectionId(),
  694. WorkflowConstants.STATUS_DRAFT);
  695. List<FragmentEntry> actualFragmentEntries =
  696. _fragmentEntryLocalService.getFragmentEntries(
  697. _group.getGroupId(),
  698. _fragmentCollection.getFragmentCollectionId(),
  699. WorkflowConstants.STATUS_DRAFT);
  700. Assert.assertEquals(
  701. actualFragmentEntries.toString(),
  702. originalFragmentEntries.size() + 2, actualFragmentEntries.size());
  703. }
  704. @Test
  705. public void testGetFragmentEntriesByUuidAndCompanyId() throws Exception {
  706. Group group = GroupTestUtil.addGroup();
  707. try {
  708. FragmentEntry fragmentEntry1 =
  709. FragmentEntryTestUtil.addFragmentEntry(
  710. _fragmentCollection.getFragmentCollectionId(),
  711. RandomTestUtil.randomString());
  712. List<FragmentEntry> fragmentEntries1 =
  713. _fragmentEntryLocalService.getFragmentEntriesByUuidAndCompanyId(
  714. fragmentEntry1.getUuid(), _group.getCompanyId());
  715. Assert.assertEquals(
  716. fragmentEntries1.toString(), 1, fragmentEntries1.size());
  717. Assert.assertEquals(fragmentEntry1, fragmentEntries1.get(0));
  718. FragmentCollection fragmentCollection =
  719. FragmentTestUtil.addFragmentCollection(group.getGroupId());
  720. FragmentEntry fragmentEntry2 =
  721. FragmentEntryTestUtil.addFragmentEntry(
  722. fragmentCollection.getFragmentCollectionId(),
  723. RandomTestUtil.randomString());
  724. List<FragmentEntry> fragmentEntries2 =
  725. _fragmentEntryLocalService.getFragmentEntriesByUuidAndCompanyId(
  726. fragmentEntry2.getUuid(), group.getCompanyId());
  727. Assert.assertEquals(
  728. fragmentEntries2.toString(), 1, fragmentEntries2.size());
  729. Assert.assertEquals(fragmentEntry2, fragmentEntries2.get(0));
  730. }
  731. finally {
  732. GroupLocalServiceUtil.deleteGroup(group);
  733. }
  734. }
  735. @Test
  736. public void testGetFragmentEntriesCount() throws Exception {
  737. int originalCount = _fragmentEntryLocalService.getFragmentEntriesCount(
  738. _fragmentCollection.getFragmentCollectionId());
  739. FragmentEntryTestUtil.addFragmentEntry(
  740. _fragmentCollection.getFragmentCollectionId());
  741. FragmentEntryTestUtil.addFragmentEntry(
  742. _fragmentCollection.getFragmentCollectionId());
  743. int actualCount = _fragmentEntryLocalService.getFragmentEntriesCount(
  744. _fragmentCollection.getFragmentCollectionId());
  745. Assert.assertEquals(originalCount + 2, actualCount);
  746. }
  747. @Test
  748. public void testMoveFragmentEntry() throws Exception {
  749. FragmentEntry fragmentEntry = FragmentEntryTestUtil.addFragmentEntry(
  750. _fragmentCollection.getFragmentCollectionId());
  751. FragmentCollection targetFragmentCollection =
  752. FragmentTestUtil.addFragmentCollection(_group.getGroupId());
  753. _fragmentEntryLocalService.moveFragmentEntry(
  754. fragmentEntry.getFragmentEntryId(),
  755. targetFragmentCollection.getFragmentCollectionId());
  756. FragmentEntry persistedFragmentEntry =
  757. _fragmentEntryPersistence.fetchByPrimaryKey(
  758. fragmentEntry.getFragmentEntryId());
  759. Assert.assertEquals(
  760. targetFragmentCollection.getFragmentCollectionId(),
  761. persistedFragmentEntry.getFragmentCollectionId());
  762. }
  763. @Test
  764. public void testUpdateFragmentCollectionId() throws Exception {
  765. FragmentEntry fragmentEntry =
  766. _fragmentEntryLocalService.addFragmentEntry(
  767. TestPropsValues.getUserId(), _group.getGroupId(),
  768. _fragmentCollection.getFragmentCollectionId(),
  769. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  770. RandomTestUtil.randomString(), "<H1>A</H1>",
  771. RandomTestUtil.randomString(), false, StringPool.BLANK, null, 0,
  772. FragmentConstants.TYPE_COMPONENT, null,
  773. WorkflowConstants.STATUS_APPROVED,
  774. ServiceContextTestUtil.getServiceContext(
  775. _group.getGroupId(), TestPropsValues.getUserId()));
  776. _fragmentEntryLocalService.updateFragmentEntry(
  777. fragmentEntry.getUserId(), fragmentEntry.getFragmentEntryId(),
  778. _updatedFragmentCollection.getFragmentCollectionId(),
  779. fragmentEntry.getName(), fragmentEntry.getCss(),
  780. fragmentEntry.getHtml(), fragmentEntry.getJs(), false, null,
  781. fragmentEntry.getIcon(), fragmentEntry.getPreviewFileEntryId(),
  782. WorkflowConstants.STATUS_APPROVED);
  783. FragmentEntry persistedFragmentEntry =
  784. _fragmentEntryPersistence.fetchByPrimaryKey(
  785. fragmentEntry.getFragmentEntryId());
  786. Assert.assertEquals(
  787. _updatedFragmentCollection.getFragmentCollectionId(),
  788. persistedFragmentEntry.getFragmentCollectionId());
  789. }
  790. @Test
  791. public void testUpdateFragmentEntryName() throws Exception {
  792. FragmentEntry fragmentEntry = FragmentEntryTestUtil.addFragmentEntry(
  793. _fragmentCollection.getFragmentCollectionId(),
  794. RandomTestUtil.randomString());
  795. fragmentEntry = _fragmentEntryLocalService.updateFragmentEntry(
  796. fragmentEntry.getFragmentEntryId(), "Fragment Name Updated");
  797. FragmentEntry persistedFragmentEntry =
  798. _fragmentEntryPersistence.fetchByPrimaryKey(
  799. fragmentEntry.getFragmentEntryId());
  800. Assert.assertEquals(
  801. "Fragment Name Updated", persistedFragmentEntry.getName());
  802. }
  803. @Test
  804. public void testUpdateFragmentEntryNameCssHtmlJsConfigurationAndStatus()
  805. throws Exception {
  806. String name = RandomTestUtil.randomString();
  807. String css = RandomTestUtil.randomString();
  808. String html = RandomTestUtil.randomString();
  809. String js = RandomTestUtil.randomString();
  810. String configuration = _read("configuration-valid-complete.json");
  811. int status = WorkflowConstants.STATUS_APPROVED;
  812. FragmentEntry fragmentEntry = FragmentEntryTestUtil.addFragmentEntry(
  813. _fragmentCollection.getFragmentCollectionId());
  814. _fragmentEntryLocalService.updateFragmentEntry(
  815. TestPropsValues.getUserId(), fragmentEntry.getFragmentEntryId(),
  816. fragmentEntry.getFragmentCollectionId(), name, css, html, js,
  817. fragmentEntry.isCacheable(), configuration, fragmentEntry.getIcon(),
  818. fragmentEntry.getFragmentEntryId(), status);
  819. FragmentEntry persistedFragmentEntry =
  820. _fragmentEntryPersistence.fetchByPrimaryKey(
  821. fragmentEntry.getFragmentEntryId());
  822. Assert.assertEquals(name, persistedFragmentEntry.getName());
  823. Assert.assertEquals(css, persistedFragmentEntry.getCss());
  824. Assert.assertEquals(html, persistedFragmentEntry.getHtml());
  825. Assert.assertEquals(js, persistedFragmentEntry.getJs());
  826. Assert.assertEquals(
  827. configuration, persistedFragmentEntry.getConfiguration());
  828. Assert.assertEquals(status, persistedFragmentEntry.getStatus());
  829. }
  830. @Test
  831. public void testUpdateFragmentEntryNameCssHtmlJsConfigurationPreviewFileEntryIdAndStatus()
  832. throws Exception {
  833. String name = RandomTestUtil.randomString();
  834. String css = RandomTestUtil.randomString();
  835. String html = RandomTestUtil.randomString();
  836. String js = RandomTestUtil.randomString();
  837. String configuration = _read("configuration-valid-complete.json");
  838. long previewFileEntryId = RandomTestUtil.randomLong();
  839. int status = WorkflowConstants.STATUS_APPROVED;
  840. FragmentEntry fragmentEntry = FragmentEntryTestUtil.addFragmentEntry(
  841. _fragmentCollection.getFragmentCollectionId());
  842. _fragmentEntryLocalService.updateFragmentEntry(
  843. TestPropsValues.getUserId(), fragmentEntry.getFragmentEntryId(),
  844. fragmentEntry.getFragmentCollectionId(), name, css, html, js,
  845. fragmentEntry.isCacheable(), configuration, fragmentEntry.getIcon(),
  846. previewFileEntryId, status);
  847. FragmentEntry persistedFragmentEntry =
  848. _fragmentEntryPersistence.fetchByPrimaryKey(
  849. fragmentEntry.getFragmentEntryId());
  850. Assert.assertEquals(name, persistedFragmentEntry.getName());
  851. Assert.assertEquals(css, persistedFragmentEntry.getCss());
  852. Assert.assertEquals(html, persistedFragmentEntry.getHtml());
  853. Assert.assertEquals(js, persistedFragmentEntry.getJs());
  854. Assert.assertEquals(
  855. configuration, persistedFragmentEntry.getConfiguration());
  856. Assert.assertEquals(
  857. previewFileEntryId, persistedFragmentEntry.getPreviewFileEntryId());
  858. Assert.assertEquals(status, persistedFragmentEntry.getStatus());
  859. }
  860. @Test
  861. public void testUpdateFragmentEntryPreviewFileEntryId() throws Exception {
  862. FragmentEntry fragmentEntry = FragmentEntryTestUtil.addFragmentEntry(
  863. _fragmentCollection.getFragmentCollectionId());
  864. long previewFileEntryId = fragmentEntry.getPreviewFileEntryId();
  865. _fragmentEntryLocalService.updateFragmentEntry(
  866. fragmentEntry.getFragmentEntryId(), previewFileEntryId + 1);
  867. FragmentEntry persistedFragmentEntry =
  868. _fragmentEntryPersistence.fetchByPrimaryKey(
  869. fragmentEntry.getFragmentEntryId());
  870. Assert.assertEquals(
  871. previewFileEntryId + 1,
  872. persistedFragmentEntry.getPreviewFileEntryId());
  873. }
  874. @Test
  875. public void testUpdateFragmentEntryWithHtmlWithAmpersand()
  876. throws Exception {
  877. FragmentEntry fragmentEntry =
  878. _fragmentEntryLocalService.addFragmentEntry(
  879. TestPropsValues.getUserId(), _group.getGroupId(),
  880. _fragmentCollection.getFragmentCollectionId(),
  881. RandomTestUtil.randomString(), RandomTestUtil.randomString(),
  882. RandomTestUtil.randomString(), "<H1>A</H1>",
  883. RandomTestUtil.randomString(), false, StringPool.BLANK, null,
  884. RandomTestUtil.randomLong(), FragmentConstants.TYPE_COMPONENT,
  885. null, WorkflowConstants.STATUS_APPROVED,
  886. ServiceContextTestUtil.getServiceContext(
  887. _group.getGroupId(), TestPropsValues.getUserId()));
  888. String html = "<H1>A&B&amp;C</H1>";
  889. _fragmentEntryLocalService.updateFragmentEntry(
  890. TestPropsValues.getUserId(), fragmentEntry.getFragmentEntryId(),
  891. fragmentEntry.getFragmentCollectionId(), fragmentEntry.getName(),
  892. fragmentEntry.getCss(), html, fragmentEntry.getJs(),
  893. fragmentEntry.isCacheable(), null, fragmentEntry.getIcon(),
  894. fragmentEntry.getPreviewFileEntryId(),
  895. WorkflowConstants.STATUS_APPROVED);
  896. FragmentEntry persistedFragmentEntry =
  897. _fragmentEntryPersistence.fetchByPrimaryKey(
  898. fragmentEntry.getFragmentEntryId());
  899. Assert.assertEquals(html, persistedFragmentEntry.getHtml());
  900. }
  901. private void _assertCopyFragmentEntry(
  902. FragmentEntry fragmentEntry, FragmentEntry copyFragmentEntry) {
  903. Assert.assertEquals(
  904. fragmentEntry.getGroupId(), copyFragmentEntry.getGroupId());
  905. Assert.assertEquals(
  906. fragmentEntry.getName() + " (Copy)", copyFragmentEntry.getName());
  907. Assert.assertEquals(fragmentEntry.getCss(), copyFragmentEntry.getCss());
  908. Assert.assertEquals(
  909. fragmentEntry.getHtml(), copyFragmentEntry.getHtml());
  910. Assert.assertEquals(fragmentEntry.getJs(), copyFragmentEntry.getJs());
  911. Assert.assertEquals(
  912. fragmentEntry.getStatus(), copyFragmentEntry.getStatus());
  913. Assert.assertEquals(
  914. fragmentEntry.getType(), copyFragmentEntry.getType());
  915. }
  916. private String _read(String fileName) throws Exception {
  917. return new String(
  918. FileUtil.getBytes(getClass(), "dependencies/" + fileName));
  919. }
  920. private FragmentCollection _fragmentCollection;
  921. @Inject
  922. private FragmentEntryLocalService _fragmentEntryLocalService;
  923. @Inject
  924. private FragmentEntryPersistence _fragmentEntryPersistence;
  925. @DeleteAfterTestRun
  926. private Group _group;
  927. private FragmentCollection _updatedFragmentCollection;
  928. }