/modules/apps/layout/layout-test/src/testIntegration/java/com/liferay/layout/util/template/test/LayoutConverterTest.java

https://github.com/kiyoshilee/liferay-portal · Java · 1243 lines · 1052 code · 175 blank · 16 comment · 9 complexity · f437e3869c561f67c183ec1d72084227 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.layout.util.template.test;
  15. import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian;
  16. import com.liferay.fragment.model.FragmentEntryLink;
  17. import com.liferay.fragment.service.FragmentEntryLinkLocalService;
  18. import com.liferay.layout.test.util.LayoutTestUtil;
  19. import com.liferay.layout.util.template.LayoutConverter;
  20. import com.liferay.layout.util.template.LayoutConverterRegistry;
  21. import com.liferay.layout.util.template.LayoutData;
  22. import com.liferay.petra.string.StringPool;
  23. import com.liferay.portal.kernel.json.JSONFactoryUtil;
  24. import com.liferay.portal.kernel.json.JSONObject;
  25. import com.liferay.portal.kernel.model.Group;
  26. import com.liferay.portal.kernel.model.Layout;
  27. import com.liferay.portal.kernel.model.LayoutConstants;
  28. import com.liferay.portal.kernel.model.LayoutTypePortlet;
  29. import com.liferay.portal.kernel.model.LayoutTypePortletConstants;
  30. import com.liferay.portal.kernel.model.Portlet;
  31. import com.liferay.portal.kernel.portlet.PortletIdCodec;
  32. import com.liferay.portal.kernel.service.PortletLocalService;
  33. import com.liferay.portal.kernel.service.ServiceContextThreadLocal;
  34. import com.liferay.portal.kernel.test.rule.AggregateTestRule;
  35. import com.liferay.portal.kernel.test.rule.DeleteAfterTestRun;
  36. import com.liferay.portal.kernel.test.util.GroupTestUtil;
  37. import com.liferay.portal.kernel.test.util.ServiceContextTestUtil;
  38. import com.liferay.portal.kernel.test.util.TestPropsValues;
  39. import com.liferay.portal.kernel.util.FileUtil;
  40. import com.liferay.portal.kernel.util.HashMapBuilder;
  41. import com.liferay.portal.kernel.util.ListUtil;
  42. import com.liferay.portal.kernel.util.Portal;
  43. import com.liferay.portal.kernel.util.StringUtil;
  44. import com.liferay.portal.kernel.util.TreeMapBuilder;
  45. import com.liferay.portal.kernel.util.UnicodeProperties;
  46. import com.liferay.portal.kernel.util.Validator;
  47. import com.liferay.portal.test.rule.Inject;
  48. import com.liferay.portal.test.rule.LiferayIntegrationTestRule;
  49. import com.liferay.portal.test.rule.PermissionCheckerMethodTestRule;
  50. import java.util.ArrayList;
  51. import java.util.Collections;
  52. import java.util.Comparator;
  53. import java.util.HashMap;
  54. import java.util.HashSet;
  55. import java.util.List;
  56. import java.util.Map;
  57. import java.util.Set;
  58. import java.util.TreeMap;
  59. import org.junit.After;
  60. import org.junit.Assert;
  61. import org.junit.Before;
  62. import org.junit.ClassRule;
  63. import org.junit.Rule;
  64. import org.junit.Test;
  65. import org.junit.runner.RunWith;
  66. /**
  67. * @author Rubén Pulido
  68. */
  69. @RunWith(Arquillian.class)
  70. public class LayoutConverterTest {
  71. @ClassRule
  72. @Rule
  73. public static final AggregateTestRule aggregateTestRule =
  74. new AggregateTestRule(
  75. new LiferayIntegrationTestRule(),
  76. PermissionCheckerMethodTestRule.INSTANCE);
  77. @Before
  78. public void setUp() throws Exception {
  79. _group = GroupTestUtil.addGroup();
  80. ServiceContextThreadLocal.pushServiceContext(
  81. ServiceContextTestUtil.getServiceContext(
  82. _group, TestPropsValues.getUserId()));
  83. }
  84. @After
  85. public void tearDown() throws Exception {
  86. ServiceContextThreadLocal.popServiceContext();
  87. }
  88. @Test
  89. public void testConvertOneColumnMultiplePortlets() throws Exception {
  90. Map<String, String[]> portletIdsMap = HashMapBuilder.put(
  91. "column-1",
  92. new String[] {
  93. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet",
  94. "com_liferay_hello_world_web_portlet_HelloWorldPortlet",
  95. "hello_soy_portlet"
  96. }
  97. ).build();
  98. List<Map<String, String[]>> portletIdsMaps =
  99. new ArrayList<Map<String, String[]>>() {
  100. {
  101. add(portletIdsMap);
  102. }
  103. };
  104. _testConvert("1_column", portletIdsMaps);
  105. }
  106. @Test
  107. public void testConvertOneColumnNoPortlets() throws Exception {
  108. _testConvertNoPortlets("1_column");
  109. }
  110. @Test
  111. public void testConvertOneColumnSinglePortlet() throws Exception {
  112. Map<String, String[]> portletIdsMap = HashMapBuilder.put(
  113. "column-1",
  114. new String[] {
  115. "com_liferay_hello_world_web_portlet_HelloWorldPortlet"
  116. }
  117. ).build();
  118. List<Map<String, String[]>> portletIdsMaps =
  119. new ArrayList<Map<String, String[]>>() {
  120. {
  121. add(portletIdsMap);
  122. }
  123. };
  124. _testConvert("1_column", portletIdsMaps);
  125. }
  126. @Test
  127. public void testConvertOneThreeOneColumnsMultiplePortlets()
  128. throws Exception {
  129. Map<String, String[]> portletIdsMap1 = TreeMapBuilder.put(
  130. "column-1",
  131. new String[] {
  132. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  133. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  134. }
  135. ).build();
  136. Map<String, String[]> portletIdsMap2 = TreeMapBuilder.put(
  137. "column-1",
  138. new String[] {
  139. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet",
  140. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  141. }
  142. ).put(
  143. "column-2",
  144. new String[] {
  145. "com_liferay_hello_world_web_portlet_HelloWorldPortlet",
  146. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  147. }
  148. ).put(
  149. "column-3",
  150. new String[] {
  151. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  152. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  153. }
  154. ).build();
  155. Map<String, String[]> portletIdsMap3 = TreeMapBuilder.put(
  156. "column-1",
  157. new String[] {
  158. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  159. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  160. }
  161. ).build();
  162. List<Map<String, String[]>> portletIdsMaps =
  163. new ArrayList<Map<String, String[]>>() {
  164. {
  165. add(portletIdsMap1);
  166. add(portletIdsMap2);
  167. add(portletIdsMap3);
  168. }
  169. };
  170. _testConvert("1_3_1_columns", portletIdsMaps);
  171. }
  172. @Test
  173. public void testConvertOneThreeOneColumnsNoPortlets() throws Exception {
  174. _testConvertNoPortlets("1_3_1_columns");
  175. }
  176. @Test
  177. public void testConvertOneThreeOneColumnsSinglePortlet() throws Exception {
  178. Map<String, String[]> portletIdsMap1 = TreeMapBuilder.put(
  179. "column-1",
  180. new String[] {
  181. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  182. }
  183. ).build();
  184. Map<String, String[]> portletIdsMap2 = TreeMapBuilder.put(
  185. "column-1",
  186. new String[] {
  187. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet"
  188. }
  189. ).put(
  190. "column-2",
  191. new String[] {
  192. "com_liferay_hello_world_web_portlet_HelloWorldPortlet"
  193. }
  194. ).put(
  195. "column-3",
  196. new String[] {
  197. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  198. }
  199. ).build();
  200. Map<String, String[]> portletIdsMap3 = TreeMapBuilder.put(
  201. "column-1",
  202. new String[] {
  203. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  204. }
  205. ).build();
  206. List<Map<String, String[]>> portletIdsMaps =
  207. new ArrayList<Map<String, String[]>>() {
  208. {
  209. add(portletIdsMap1);
  210. add(portletIdsMap2);
  211. add(portletIdsMap3);
  212. }
  213. };
  214. _testConvert("1_3_1_columns", portletIdsMaps);
  215. }
  216. @Test
  217. public void testConvertOneThreeTwoColumnsMultiplePortlets()
  218. throws Exception {
  219. Map<String, String[]> portletIdsMap1 = TreeMapBuilder.put(
  220. "column-1",
  221. new String[] {
  222. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  223. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  224. }
  225. ).build();
  226. Map<String, String[]> portletIdsMap2 = TreeMapBuilder.put(
  227. "column-1",
  228. new String[] {
  229. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet",
  230. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  231. }
  232. ).put(
  233. "column-2",
  234. new String[] {
  235. "com_liferay_hello_world_web_portlet_HelloWorldPortlet",
  236. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  237. }
  238. ).put(
  239. "column-3",
  240. new String[] {
  241. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  242. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  243. }
  244. ).build();
  245. Map<String, String[]> portletIdsMap3 = TreeMapBuilder.put(
  246. "column-1",
  247. new String[] {
  248. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  249. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  250. }
  251. ).put(
  252. "column-2",
  253. new String[] {
  254. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  255. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  256. }
  257. ).build();
  258. List<Map<String, String[]>> portletIdsMaps =
  259. new ArrayList<Map<String, String[]>>() {
  260. {
  261. add(portletIdsMap1);
  262. add(portletIdsMap2);
  263. add(portletIdsMap3);
  264. }
  265. };
  266. _testConvert("1_3_2_columns", portletIdsMaps);
  267. }
  268. @Test
  269. public void testConvertOneThreeTwoColumnsNoPortlets() throws Exception {
  270. _testConvertNoPortlets("1_3_2_columns");
  271. }
  272. @Test
  273. public void testConvertOneThreeTwoColumnsSinglePortlet() throws Exception {
  274. Map<String, String[]> portletIdsMap1 = TreeMapBuilder.put(
  275. "column-1",
  276. new String[] {
  277. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  278. }
  279. ).build();
  280. Map<String, String[]> portletIdsMap2 = TreeMapBuilder.put(
  281. "column-1",
  282. new String[] {
  283. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet"
  284. }
  285. ).put(
  286. "column-2",
  287. new String[] {
  288. "com_liferay_hello_world_web_portlet_HelloWorldPortlet"
  289. }
  290. ).put(
  291. "column-3",
  292. new String[] {
  293. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  294. }
  295. ).build();
  296. Map<String, String[]> portletIdsMap3 = TreeMapBuilder.put(
  297. "column-1",
  298. new String[] {
  299. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  300. }
  301. ).put(
  302. "column-2",
  303. new String[] {
  304. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  305. }
  306. ).build();
  307. List<Map<String, String[]>> portletIdsMaps =
  308. new ArrayList<Map<String, String[]>>() {
  309. {
  310. add(portletIdsMap1);
  311. add(portletIdsMap2);
  312. add(portletIdsMap3);
  313. }
  314. };
  315. _testConvert("1_3_2_columns", portletIdsMaps);
  316. }
  317. @Test
  318. public void testConvertOneTwoColumnsIIMultiplePortlets() throws Exception {
  319. _testConvertOneTwoColumnsMultiplePortlets("1_2_columns_ii");
  320. }
  321. @Test
  322. public void testConvertOneTwoColumnsIINoPortlets() throws Exception {
  323. _testConvertNoPortlets("1_2_columns_ii");
  324. }
  325. @Test
  326. public void testConvertOneTwoColumnsIISinglePortlet() throws Exception {
  327. _testConvertOneTwoColumnsSinglePortlet("1_2_columns_ii");
  328. }
  329. @Test
  330. public void testConvertOneTwoColumnsIMultiplePortlets() throws Exception {
  331. _testConvertOneTwoColumnsMultiplePortlets("1_2_columns_i");
  332. }
  333. @Test
  334. public void testConvertOneTwoColumnsINoPortlets() throws Exception {
  335. _testConvertNoPortlets("1_2_columns_i");
  336. }
  337. @Test
  338. public void testConvertOneTwoColumnsISinglePortlet() throws Exception {
  339. _testConvertOneTwoColumnsSinglePortlet("1_2_columns_i");
  340. }
  341. @Test
  342. public void testConvertOneTwoOneColumnsIIMultiplePortlets()
  343. throws Exception {
  344. _testConvertOneTwoOneColumnsMultiplePortlets("1_2_1_columns_i");
  345. }
  346. @Test
  347. public void testConvertOneTwoOneColumnsIINoPortlets() throws Exception {
  348. _testConvertNoPortlets("1_2_1_columns_ii");
  349. }
  350. @Test
  351. public void testConvertOneTwoOneColumnsIISinglePortlet() throws Exception {
  352. _testConvertOneTwoOneColumnsSinglePortlet("1_2_1_columns_ii");
  353. }
  354. @Test
  355. public void testConvertOneTwoOneColumnsIMultiplePortlets()
  356. throws Exception {
  357. _testConvertOneTwoOneColumnsMultiplePortlets("1_2_1_columns_i");
  358. }
  359. @Test
  360. public void testConvertOneTwoOneColumnsINoPortlets() throws Exception {
  361. _testConvertNoPortlets("1_2_1_columns_i");
  362. }
  363. @Test
  364. public void testConvertOneTwoOneColumnsISinglePortlet() throws Exception {
  365. _testConvertOneTwoOneColumnsSinglePortlet("1_2_1_columns_i");
  366. }
  367. @Test
  368. public void testConvertThreeColumnsMultiplePortlets() throws Exception {
  369. Map<String, String[]> portletIdsMap = TreeMapBuilder.put(
  370. "column-1",
  371. new String[] {
  372. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet",
  373. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  374. }
  375. ).put(
  376. "column-2",
  377. new String[] {
  378. "com_liferay_hello_world_web_portlet_HelloWorldPortlet",
  379. "hello_soy_portlet"
  380. }
  381. ).put(
  382. "column-3",
  383. new String[] {
  384. "com_liferay_clay_sample_web_portlet_ClaySamplePortlet",
  385. "com_liferay_clay_sample_web_portlet_ClaySamplePortlet"
  386. }
  387. ).build();
  388. _testConvert("3_columns", Collections.singletonList(portletIdsMap));
  389. }
  390. @Test
  391. public void testConvertThreeColumnsNoPortlets() throws Exception {
  392. _testConvertNoPortlets("3_columns");
  393. }
  394. @Test
  395. public void testConvertThreeColumnsSinglePortlet() throws Exception {
  396. Map<String, String[]> portletIdsMap = TreeMapBuilder.put(
  397. "column-1",
  398. new String[] {
  399. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet"
  400. }
  401. ).put(
  402. "column-2",
  403. new String[] {
  404. "com_liferay_hello_world_web_portlet_HelloWorldPortlet"
  405. }
  406. ).put(
  407. "column-3", new String[] {"hello_soy_portlet"}
  408. ).build();
  409. _testConvert("3_columns", Collections.singletonList(portletIdsMap));
  410. }
  411. @Test
  412. public void testConvertThreeTwoThreeColumnsMultiplePortlets()
  413. throws Exception {
  414. Map<String, String[]> portletIdsMap1 = TreeMapBuilder.put(
  415. "column-1",
  416. new String[] {
  417. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  418. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  419. }
  420. ).put(
  421. "column-2",
  422. new String[] {
  423. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  424. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  425. }
  426. ).put(
  427. "column-3",
  428. new String[] {
  429. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  430. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  431. }
  432. ).build();
  433. Map<String, String[]> portletIdsMap2 = TreeMapBuilder.put(
  434. "column-1",
  435. new String[] {
  436. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet",
  437. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  438. }
  439. ).put(
  440. "column-2",
  441. new String[] {
  442. "com_liferay_hello_world_web_portlet_HelloWorldPortlet",
  443. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  444. }
  445. ).build();
  446. Map<String, String[]> portletIdsMap3 = TreeMapBuilder.put(
  447. "column-1",
  448. new String[] {
  449. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  450. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  451. }
  452. ).put(
  453. "column-2",
  454. new String[] {
  455. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  456. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  457. }
  458. ).put(
  459. "column-3|",
  460. new String[] {
  461. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  462. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  463. }
  464. ).build();
  465. List<Map<String, String[]>> portletIdsMaps =
  466. new ArrayList<Map<String, String[]>>() {
  467. {
  468. add(portletIdsMap1);
  469. add(portletIdsMap2);
  470. add(portletIdsMap3);
  471. }
  472. };
  473. _testConvert("3_2_3_columns", portletIdsMaps);
  474. }
  475. @Test
  476. public void testConvertThreeTwoThreeColumnsNoPortlets() throws Exception {
  477. _testConvertNoPortlets("3_2_3_columns");
  478. }
  479. @Test
  480. public void testConvertThreeTwoThreeColumnsSinglePortlet()
  481. throws Exception {
  482. Map<String, String[]> portletIdsMap1 = TreeMapBuilder.put(
  483. "column-1",
  484. new String[] {
  485. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  486. }
  487. ).put(
  488. "column-2",
  489. new String[] {
  490. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  491. }
  492. ).put(
  493. "column-3",
  494. new String[] {
  495. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  496. }
  497. ).build();
  498. Map<String, String[]> portletIdsMap2 = TreeMapBuilder.put(
  499. "column-1",
  500. new String[] {
  501. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet"
  502. }
  503. ).put(
  504. "column-2",
  505. new String[] {
  506. "com_liferay_hello_world_web_portlet_HelloWorldPortlet"
  507. }
  508. ).build();
  509. Map<String, String[]> portletIdsMap3 = TreeMapBuilder.put(
  510. "column-1",
  511. new String[] {
  512. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  513. }
  514. ).put(
  515. "column-2",
  516. new String[] {
  517. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  518. }
  519. ).put(
  520. "column-3|",
  521. new String[] {
  522. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  523. }
  524. ).build();
  525. List<Map<String, String[]>> portletIdsMaps =
  526. new ArrayList<Map<String, String[]>>() {
  527. {
  528. add(portletIdsMap1);
  529. add(portletIdsMap2);
  530. add(portletIdsMap3);
  531. }
  532. };
  533. _testConvert("3_2_3_columns", portletIdsMaps);
  534. }
  535. @Test
  536. public void testConvertTwoColumnsIIIMultiplePortlets() throws Exception {
  537. _testConvertTwoColumnsMultiplePortlets("2_columns_iii");
  538. }
  539. @Test
  540. public void testConvertTwoColumnsIIINoPortlets() throws Exception {
  541. _testConvertNoPortlets("2_columns_iii");
  542. }
  543. @Test
  544. public void testConvertTwoColumnsIIISinglePortlet() throws Exception {
  545. _testConvertTwoColumnsSinglePortlet("2_columns_iii");
  546. }
  547. @Test
  548. public void testConvertTwoColumnsIIMultiplePortlets() throws Exception {
  549. _testConvertTwoColumnsMultiplePortlets("2_columns_ii");
  550. }
  551. @Test
  552. public void testConvertTwoColumnsIINoPortlets() throws Exception {
  553. _testConvertNoPortlets("2_columns_ii");
  554. }
  555. @Test
  556. public void testConvertTwoColumnsIISinglePortlet() throws Exception {
  557. _testConvertTwoColumnsSinglePortlet("2_columns_ii");
  558. }
  559. @Test
  560. public void testConvertTwoColumnsIMultiplePortlets() throws Exception {
  561. _testConvertTwoColumnsMultiplePortlets("2_columns_i");
  562. }
  563. @Test
  564. public void testConvertTwoColumnsINoPortlets() throws Exception {
  565. _testConvertNoPortlets("2_columns_i");
  566. }
  567. @Test
  568. public void testConvertTwoColumnsISinglePortlet() throws Exception {
  569. _testConvertTwoColumnsSinglePortlet("2_columns_i");
  570. }
  571. @Test
  572. public void testConvertTwoOneTwoColumnsMultiplePortlets() throws Exception {
  573. Map<String, String[]> portletIdsMap1 = TreeMapBuilder.put(
  574. "column-1",
  575. new String[] {
  576. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  577. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  578. }
  579. ).put(
  580. "column-2",
  581. new String[] {
  582. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  583. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  584. }
  585. ).build();
  586. Map<String, String[]> portletIdsMap2 = TreeMapBuilder.put(
  587. "column-1",
  588. new String[] {
  589. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet",
  590. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  591. }
  592. ).build();
  593. Map<String, String[]> portletIdsMap3 = TreeMapBuilder.put(
  594. "column-1",
  595. new String[] {
  596. "com_liferay_hello_world_web_portlet_HelloWorldPortlet",
  597. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  598. }
  599. ).put(
  600. "column-2",
  601. new String[] {
  602. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  603. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  604. }
  605. ).build();
  606. List<Map<String, String[]>> portletIdsMaps =
  607. new ArrayList<Map<String, String[]>>() {
  608. {
  609. add(portletIdsMap1);
  610. add(portletIdsMap2);
  611. add(portletIdsMap3);
  612. }
  613. };
  614. _testConvert("2_1_2_columns", portletIdsMaps);
  615. }
  616. @Test
  617. public void testConvertTwoOneTwoColumnsNoPortlets() throws Exception {
  618. _testConvertNoPortlets("2_1_2_columns");
  619. }
  620. @Test
  621. public void testConvertTwoOneTwoColumnsSinglePortlet() throws Exception {
  622. Map<String, String[]> portletIdsMap1 = TreeMapBuilder.put(
  623. "column-1",
  624. new String[] {
  625. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  626. }
  627. ).put(
  628. "column-2",
  629. new String[] {
  630. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  631. }
  632. ).build();
  633. Map<String, String[]> portletIdsMap2 = TreeMapBuilder.put(
  634. "column-1",
  635. new String[] {
  636. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet"
  637. }
  638. ).build();
  639. Map<String, String[]> portletIdsMap3 = TreeMapBuilder.put(
  640. "column-1",
  641. new String[] {
  642. "com_liferay_hello_world_web_portlet_HelloWorldPortlet"
  643. }
  644. ).put(
  645. "column-2",
  646. new String[] {
  647. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  648. }
  649. ).build();
  650. List<Map<String, String[]>> portletIdsMaps =
  651. new ArrayList<Map<String, String[]>>() {
  652. {
  653. add(portletIdsMap1);
  654. add(portletIdsMap2);
  655. add(portletIdsMap3);
  656. }
  657. };
  658. _testConvert("2_1_2_columns", portletIdsMaps);
  659. }
  660. @Test
  661. public void testConvertTwoTwoColumnsMultiplePortlets() throws Exception {
  662. Map<String, String[]> portletIdsMap1 = TreeMapBuilder.put(
  663. "column-1",
  664. new String[] {
  665. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  666. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  667. }
  668. ).put(
  669. "column-2",
  670. new String[] {
  671. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  672. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  673. }
  674. ).build();
  675. Map<String, String[]> portletIdsMap2 = TreeMapBuilder.put(
  676. "column-1",
  677. new String[] {
  678. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet",
  679. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  680. }
  681. ).put(
  682. "column-2",
  683. new String[] {
  684. "com_liferay_hello_world_web_portlet_HelloWorldPortlet",
  685. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  686. }
  687. ).build();
  688. List<Map<String, String[]>> portletIdsMaps =
  689. new ArrayList<Map<String, String[]>>() {
  690. {
  691. add(portletIdsMap1);
  692. add(portletIdsMap2);
  693. }
  694. };
  695. _testConvert("2_2_columns", portletIdsMaps);
  696. }
  697. @Test
  698. public void testConvertTwoTwoColumnsNoPortlets() throws Exception {
  699. _testConvertNoPortlets("2_2_columns");
  700. }
  701. @Test
  702. public void testConvertTwoTwoColumnsSinglePortlet() throws Exception {
  703. Map<String, String[]> portletIdsMap1 = TreeMapBuilder.put(
  704. "column-1",
  705. new String[] {
  706. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  707. }
  708. ).put(
  709. "column-2",
  710. new String[] {
  711. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  712. }
  713. ).build();
  714. Map<String, String[]> portletIdsMap2 = TreeMapBuilder.put(
  715. "column-1",
  716. new String[] {
  717. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet"
  718. }
  719. ).put(
  720. "column-2",
  721. new String[] {
  722. "com_liferay_hello_world_web_portlet_HelloWorldPortlet"
  723. }
  724. ).build();
  725. List<Map<String, String[]>> portletIdsMaps =
  726. new ArrayList<Map<String, String[]>>() {
  727. {
  728. add(portletIdsMap1);
  729. add(portletIdsMap2);
  730. }
  731. };
  732. _testConvert("2_2_columns", portletIdsMaps);
  733. }
  734. @Test
  735. public void testIsConvertibleTrue() throws Exception {
  736. Layout layout = LayoutTestUtil.addLayout(_group.getGroupId());
  737. LayoutConverter layoutConverter =
  738. _layoutConverterRegistry.getLayoutConverter(
  739. _getLayoutTemplateId(layout));
  740. Assert.assertTrue(layoutConverter.isConvertible(layout));
  741. }
  742. @Test
  743. public void testIsConvertibleTrueWidgetPageCustomizable() throws Exception {
  744. UnicodeProperties typeSettingsProperties = new UnicodeProperties();
  745. typeSettingsProperties.setProperty(
  746. LayoutConstants.CUSTOMIZABLE_LAYOUT, Boolean.TRUE.toString());
  747. Layout layout = LayoutTestUtil.addLayout(
  748. _group.getGroupId(), typeSettingsProperties.toString());
  749. LayoutConverter layoutConverter =
  750. _layoutConverterRegistry.getLayoutConverter(
  751. _getLayoutTemplateId(layout));
  752. Assert.assertTrue(layoutConverter.isConvertible(layout));
  753. }
  754. @Test
  755. public void testIsConvertibleTrueWidgetPageWithNestedApplicationsWidget()
  756. throws Exception {
  757. UnicodeProperties typeSettingsProperties = new UnicodeProperties();
  758. typeSettingsProperties.put(
  759. LayoutTypePortletConstants.NESTED_COLUMN_IDS,
  760. StringUtil.randomString());
  761. Layout layout = LayoutTestUtil.addLayout(
  762. _group.getGroupId(), typeSettingsProperties.toString());
  763. LayoutConverter layoutConverter =
  764. _layoutConverterRegistry.getLayoutConverter(
  765. _getLayoutTemplateId(layout));
  766. Assert.assertTrue(layoutConverter.isConvertible(layout));
  767. }
  768. private String _getLayoutTemplateId(Layout layout) {
  769. LayoutTypePortlet layoutTypePortlet =
  770. (LayoutTypePortlet)layout.getLayoutType();
  771. return layoutTypePortlet.getLayoutTemplateId();
  772. }
  773. private String _read(String fileName) throws Exception {
  774. return new String(
  775. FileUtil.getBytes(getClass(), "dependencies/" + fileName));
  776. }
  777. private void _testConvert(
  778. String layoutTemplateId, List<Map<String, String[]>> portletIdsMaps)
  779. throws Exception {
  780. int columnId = 0;
  781. List<Map<String, List<String>>> encodedPortletIdsMaps =
  782. new ArrayList<>();
  783. UnicodeProperties typeSettingsProperties = new UnicodeProperties();
  784. typeSettingsProperties.setProperty(
  785. LayoutTypePortletConstants.LAYOUT_TEMPLATE_ID, layoutTemplateId);
  786. Layout layout = LayoutTestUtil.addLayout(
  787. _group.getGroupId(), typeSettingsProperties.toString());
  788. for (Map<String, String[]> portletIdsMap : portletIdsMaps) {
  789. Set<Map.Entry<String, String[]>> entries = portletIdsMap.entrySet();
  790. Map<String, List<String>> encodedPortletIdsMap = new TreeMap<>();
  791. for (Map.Entry<String, String[]> entry : entries) {
  792. columnId++;
  793. encodedPortletIdsMap.put(entry.getKey(), new ArrayList<>());
  794. List<String> encodedPortletIds = encodedPortletIdsMap.get(
  795. entry.getKey());
  796. for (String portletId : entry.getValue()) {
  797. Portlet portlet = _portletLocalService.getPortletById(
  798. _group.getCompanyId(), portletId);
  799. String encodedPortletId = portletId;
  800. if (portlet.isInstanceable()) {
  801. encodedPortletId = PortletIdCodec.encode(portletId);
  802. }
  803. LayoutTestUtil.addPortletToLayout(
  804. TestPropsValues.getUserId(), layout, encodedPortletId,
  805. "column-" + columnId, new HashMap<>());
  806. encodedPortletIds.add(encodedPortletId);
  807. }
  808. }
  809. encodedPortletIdsMaps.add(encodedPortletIdsMap);
  810. }
  811. LayoutConverter layoutConverter =
  812. _layoutConverterRegistry.getLayoutConverter(
  813. _getLayoutTemplateId(layout));
  814. LayoutData layoutData = layoutConverter.convert(layout);
  815. JSONObject layoutDataJSONObject = layoutData.getLayoutDataJSONObject();
  816. String expectedLayoutData = _read(
  817. String.format("expected_layout_data_%s.json", layoutTemplateId));
  818. List<FragmentEntryLink> fragmentEntryLinks =
  819. _fragmentEntryLinkLocalService.getFragmentEntryLinks(
  820. _group.getGroupId(),
  821. _portal.getClassNameId(Layout.class.getName()),
  822. layout.getPlid());
  823. List<FragmentEntryLink> sortedFragmentEntryLinks = ListUtil.sort(
  824. fragmentEntryLinks,
  825. Comparator.comparing(FragmentEntryLink::getFragmentEntryLinkId));
  826. int fromIndex = 0;
  827. for (Map<String, List<String>> encodedPortletIdsMap :
  828. encodedPortletIdsMaps) {
  829. for (Map.Entry<String, List<String>> entry :
  830. encodedPortletIdsMap.entrySet()) {
  831. List<String> portletIds = entry.getValue();
  832. int numberOfPortletsInColumn = portletIds.size();
  833. List<FragmentEntryLink> fragmentEntryLinksInColumn =
  834. sortedFragmentEntryLinks.subList(
  835. fromIndex, fromIndex + numberOfPortletsInColumn);
  836. fromIndex = fromIndex + numberOfPortletsInColumn;
  837. Set<String> existingPortletIds = new HashSet<>();
  838. List<String> fragmentEntryLinkIdsInColumn = new ArrayList<>();
  839. for (FragmentEntryLink fragmentEntryLink :
  840. fragmentEntryLinksInColumn) {
  841. fragmentEntryLinkIdsInColumn.add(
  842. String.format(
  843. "\"%s\"",
  844. fragmentEntryLink.getFragmentEntryLinkId()));
  845. JSONObject jsonObject = JSONFactoryUtil.createJSONObject(
  846. fragmentEntryLink.getEditableValues());
  847. String portletId = jsonObject.getString("portletId");
  848. String instanceId = jsonObject.getString("instanceId");
  849. if (Validator.isNotNull(instanceId)) {
  850. portletId = PortletIdCodec.encode(
  851. portletId, instanceId);
  852. }
  853. existingPortletIds.add(portletId);
  854. }
  855. Assert.assertEquals(
  856. fragmentEntryLinkIdsInColumn.toString(), portletIds.size(),
  857. fragmentEntryLinkIdsInColumn.size());
  858. for (String portletId : portletIds) {
  859. Assert.assertTrue(existingPortletIds.contains(portletId));
  860. }
  861. String fragmentEntryLinkIdsJoined = StringUtil.merge(
  862. fragmentEntryLinkIdsInColumn, StringPool.COMMA_AND_SPACE);
  863. expectedLayoutData = StringUtil.replaceFirst(
  864. expectedLayoutData, "[]",
  865. String.format("[%s]", fragmentEntryLinkIdsJoined));
  866. }
  867. }
  868. JSONObject expectedLayoutDataJSONObject =
  869. JSONFactoryUtil.createJSONObject(expectedLayoutData);
  870. Assert.assertEquals(
  871. expectedLayoutDataJSONObject.toJSONString(),
  872. layoutDataJSONObject.toJSONString());
  873. }
  874. private void _testConvertNoPortlets(String layoutTemplateId)
  875. throws Exception {
  876. _testConvert(layoutTemplateId, new ArrayList<>());
  877. }
  878. private void _testConvertOneTwoColumnsMultiplePortlets(
  879. String layoutTemplateId)
  880. throws Exception {
  881. Map<String, String[]> portletIdsMap1 = TreeMapBuilder.put(
  882. "column-1",
  883. new String[] {
  884. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  885. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  886. }
  887. ).build();
  888. Map<String, String[]> portletIdsMap2 = TreeMapBuilder.put(
  889. "column-1",
  890. new String[] {
  891. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet",
  892. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  893. }
  894. ).put(
  895. "column-2",
  896. new String[] {
  897. "com_liferay_hello_world_web_portlet_HelloWorldPortlet",
  898. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  899. }
  900. ).build();
  901. List<Map<String, String[]>> portletIdsMaps =
  902. new ArrayList<Map<String, String[]>>() {
  903. {
  904. add(portletIdsMap1);
  905. add(portletIdsMap2);
  906. }
  907. };
  908. _testConvert(layoutTemplateId, portletIdsMaps);
  909. }
  910. private void _testConvertOneTwoColumnsSinglePortlet(String layoutTemplateId)
  911. throws Exception {
  912. Map<String, String[]> portletIdsMap1 = TreeMapBuilder.put(
  913. "column-1",
  914. new String[] {
  915. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  916. }
  917. ).build();
  918. Map<String, String[]> portletIdsMap2 = TreeMapBuilder.put(
  919. "column-1",
  920. new String[] {
  921. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet"
  922. }
  923. ).put(
  924. "column-2",
  925. new String[] {
  926. "com_liferay_hello_world_web_portlet_HelloWorldPortlet"
  927. }
  928. ).build();
  929. List<Map<String, String[]>> portletIdsMaps =
  930. new ArrayList<Map<String, String[]>>() {
  931. {
  932. add(portletIdsMap1);
  933. add(portletIdsMap2);
  934. }
  935. };
  936. _testConvert(layoutTemplateId, portletIdsMaps);
  937. }
  938. private void _testConvertOneTwoOneColumnsMultiplePortlets(
  939. String layoutTemplateId)
  940. throws Exception {
  941. Map<String, String[]> portletIdsMap1 = TreeMapBuilder.put(
  942. "column-1",
  943. new String[] {
  944. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  945. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  946. }
  947. ).build();
  948. Map<String, String[]> portletIdsMap2 = TreeMapBuilder.put(
  949. "column-1",
  950. new String[] {
  951. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet",
  952. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  953. }
  954. ).put(
  955. "column-2",
  956. new String[] {
  957. "com_liferay_hello_world_web_portlet_HelloWorldPortlet",
  958. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  959. }
  960. ).build();
  961. Map<String, String[]> portletIdsMap3 = TreeMapBuilder.put(
  962. "column-1",
  963. new String[] {
  964. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet",
  965. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  966. }
  967. ).build();
  968. List<Map<String, String[]>> portletIdsMaps =
  969. new ArrayList<Map<String, String[]>>() {
  970. {
  971. add(portletIdsMap1);
  972. add(portletIdsMap2);
  973. add(portletIdsMap3);
  974. }
  975. };
  976. _testConvert(layoutTemplateId, portletIdsMaps);
  977. }
  978. private void _testConvertOneTwoOneColumnsSinglePortlet(
  979. String layoutTemplateId)
  980. throws Exception {
  981. Map<String, String[]> portletIdsMap1 = TreeMapBuilder.put(
  982. "column-1",
  983. new String[] {
  984. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  985. }
  986. ).build();
  987. Map<String, String[]> portletIdsMap2 = TreeMapBuilder.put(
  988. "column-1",
  989. new String[] {
  990. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet"
  991. }
  992. ).put(
  993. "column-2",
  994. new String[] {
  995. "com_liferay_hello_world_web_portlet_HelloWorldPortlet"
  996. }
  997. ).build();
  998. Map<String, String[]> portletIdsMap3 = TreeMapBuilder.put(
  999. "column-3",
  1000. new String[] {
  1001. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  1002. }
  1003. ).build();
  1004. List<Map<String, String[]>> portletIdsMaps =
  1005. new ArrayList<Map<String, String[]>>() {
  1006. {
  1007. add(portletIdsMap1);
  1008. add(portletIdsMap2);
  1009. add(portletIdsMap3);
  1010. }
  1011. };
  1012. _testConvert(layoutTemplateId, portletIdsMaps);
  1013. }
  1014. private void _testConvertTwoColumnsMultiplePortlets(String layoutTemplateId)
  1015. throws Exception {
  1016. Map<String, String[]> portletIdsMap = TreeMapBuilder.put(
  1017. "column-1",
  1018. new String[] {
  1019. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet",
  1020. "com_liferay_chart_sample_web_portlet_ChartSamplePortlet"
  1021. }
  1022. ).put(
  1023. "column-2",
  1024. new String[] {
  1025. "com_liferay_hello_world_web_portlet_HelloWorldPortlet",
  1026. "hello_soy_portlet"
  1027. }
  1028. ).build();
  1029. List<Map<String, String[]>> portletIdsMaps =
  1030. new ArrayList<Map<String, String[]>>() {
  1031. {
  1032. add(portletIdsMap);
  1033. }
  1034. };
  1035. _testConvert(layoutTemplateId, portletIdsMaps);
  1036. }
  1037. private void _testConvertTwoColumnsSinglePortlet(String layoutTemplateId)
  1038. throws Exception {
  1039. Map<String, String[]> portletIdsMap = TreeMapBuilder.put(
  1040. "column-1",
  1041. new String[] {
  1042. "com_liferay_hello_velocity_web_portlet_HelloVelocityPortlet"
  1043. }
  1044. ).put(
  1045. "column-2",
  1046. new String[] {
  1047. "com_liferay_hello_world_web_portlet_HelloWorldPortlet"
  1048. }
  1049. ).build();
  1050. List<Map<String, String[]>> portletIdsMaps =
  1051. new ArrayList<Map<String, String[]>>() {
  1052. {
  1053. add(portletIdsMap);
  1054. }
  1055. };
  1056. _testConvert(layoutTemplateId, portletIdsMaps);
  1057. }
  1058. @Inject
  1059. private FragmentEntryLinkLocalService _fragmentEntryLinkLocalService;
  1060. @DeleteAfterTestRun
  1061. private Group _group;
  1062. @Inject
  1063. private LayoutConverterRegistry _layoutConverterRegistry;
  1064. @Inject
  1065. private Portal _portal;
  1066. @Inject
  1067. private PortletLocalService _portletLocalService;
  1068. }