forked from liferay/liferay-portal
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
LPD-20493 Add integration tests for CalendarBookingInfoItem classes
- Loading branch information
1 parent
cfc202e
commit 0dc1b57
Showing
3 changed files
with
357 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
250 changes: 250 additions & 0 deletions
250
...com/liferay/calendar/info/item/provider/test/CalendarBookingInfoItemFormProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,250 @@ | ||
/** | ||
* SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com | ||
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 | ||
*/ | ||
|
||
package com.liferay.calendar.info.item.provider.test; | ||
|
||
import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian; | ||
import com.liferay.calendar.model.Calendar; | ||
import com.liferay.calendar.model.CalendarBooking; | ||
import com.liferay.calendar.test.util.CalendarBookingTestUtil; | ||
import com.liferay.calendar.test.util.CalendarTestUtil; | ||
import com.liferay.info.field.InfoField; | ||
import com.liferay.info.field.InfoFieldValue; | ||
import com.liferay.info.field.type.BooleanInfoFieldType; | ||
import com.liferay.info.field.type.DateInfoFieldType; | ||
import com.liferay.info.field.type.DisplayPageInfoFieldType; | ||
import com.liferay.info.field.type.HTMLInfoFieldType; | ||
import com.liferay.info.field.type.TextInfoFieldType; | ||
import com.liferay.info.field.type.URLInfoFieldType; | ||
import com.liferay.info.form.InfoForm; | ||
import com.liferay.info.item.ClassPKInfoItemIdentifier; | ||
import com.liferay.info.item.InfoItemFieldValues; | ||
import com.liferay.info.item.InfoItemIdentifier; | ||
import com.liferay.info.item.InfoItemReference; | ||
import com.liferay.info.item.InfoItemServiceRegistry; | ||
import com.liferay.info.item.provider.InfoItemFieldValuesProvider; | ||
import com.liferay.info.item.provider.InfoItemFormProvider; | ||
import com.liferay.layout.test.util.LayoutTestUtil; | ||
import com.liferay.portal.kernel.model.Group; | ||
import com.liferay.portal.kernel.test.rule.AggregateTestRule; | ||
import com.liferay.portal.kernel.test.rule.DeleteAfterTestRun; | ||
import com.liferay.portal.kernel.test.util.GroupTestUtil; | ||
import com.liferay.portal.kernel.util.LocaleUtil; | ||
import com.liferay.portal.test.rule.Inject; | ||
import com.liferay.portal.test.rule.LiferayIntegrationTestRule; | ||
import com.liferay.portal.test.rule.PermissionCheckerMethodTestRule; | ||
|
||
import java.util.Collection; | ||
import java.util.Comparator; | ||
import java.util.Date; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* @author Jonathan McCann | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class CalendarBookingInfoItemFormProviderTest { | ||
|
||
@ClassRule | ||
@Rule | ||
public static final AggregateTestRule aggregateTestRule = | ||
new AggregateTestRule( | ||
new LiferayIntegrationTestRule(), | ||
PermissionCheckerMethodTestRule.INSTANCE); | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
_group = GroupTestUtil.addGroup(); | ||
|
||
_calendar = CalendarTestUtil.addCalendar(_group); | ||
|
||
_calendarBooking = CalendarBookingTestUtil.addRegularCalendarBooking( | ||
_calendar); | ||
|
||
LayoutTestUtil.addTypeContentLayout(_group); | ||
} | ||
|
||
@Test | ||
public void testGetInfoForm() throws Exception { | ||
InfoItemFormProvider<CalendarBooking> infoItemFormProvider = | ||
(InfoItemFormProvider<CalendarBooking>) | ||
_infoItemServiceRegistry.getFirstInfoItemService( | ||
InfoItemFormProvider.class, | ||
CalendarBooking.class.getName()); | ||
|
||
InfoForm infoForm = infoItemFormProvider.getInfoForm(_calendarBooking); | ||
|
||
List<InfoField<?>> infoFields = infoForm.getAllInfoFields(); | ||
|
||
infoFields.sort( | ||
Comparator.comparing( | ||
InfoField::getName, String::compareToIgnoreCase)); | ||
|
||
Assert.assertEquals(infoFields.toString(), 8, infoFields.size()); | ||
|
||
Iterator<InfoField<?>> iterator = infoFields.iterator(); | ||
|
||
InfoField infoField = iterator.next(); | ||
|
||
Assert.assertEquals( | ||
BooleanInfoFieldType.INSTANCE, infoField.getInfoFieldType()); | ||
Assert.assertEquals("allDay", infoField.getName()); | ||
Assert.assertFalse(infoField.isLocalizable()); | ||
|
||
infoField = iterator.next(); | ||
|
||
Assert.assertEquals( | ||
HTMLInfoFieldType.INSTANCE, infoField.getInfoFieldType()); | ||
Assert.assertEquals("description", infoField.getName()); | ||
Assert.assertFalse(infoField.isLocalizable()); | ||
|
||
infoField = iterator.next(); | ||
|
||
Assert.assertEquals( | ||
DisplayPageInfoFieldType.INSTANCE, infoField.getInfoFieldType()); | ||
Assert.assertEquals("displayPageURL", infoField.getName()); | ||
Assert.assertFalse(infoField.isLocalizable()); | ||
|
||
infoField = iterator.next(); | ||
|
||
Assert.assertEquals( | ||
DateInfoFieldType.INSTANCE, infoField.getInfoFieldType()); | ||
Assert.assertEquals("endDate", infoField.getName()); | ||
Assert.assertFalse(infoField.isLocalizable()); | ||
|
||
infoField = iterator.next(); | ||
|
||
Assert.assertEquals( | ||
URLInfoFieldType.INSTANCE, infoField.getInfoFieldType()); | ||
Assert.assertEquals("eventURL", infoField.getName()); | ||
Assert.assertFalse(infoField.isLocalizable()); | ||
|
||
infoField = iterator.next(); | ||
|
||
Assert.assertEquals( | ||
TextInfoFieldType.INSTANCE, infoField.getInfoFieldType()); | ||
Assert.assertEquals("location", infoField.getName()); | ||
Assert.assertFalse(infoField.isLocalizable()); | ||
|
||
infoField = iterator.next(); | ||
|
||
Assert.assertEquals( | ||
DateInfoFieldType.INSTANCE, infoField.getInfoFieldType()); | ||
Assert.assertEquals("startDate", infoField.getName()); | ||
Assert.assertFalse(infoField.isLocalizable()); | ||
|
||
infoField = iterator.next(); | ||
|
||
Assert.assertEquals( | ||
TextInfoFieldType.INSTANCE, infoField.getInfoFieldType()); | ||
Assert.assertEquals("title", infoField.getName()); | ||
Assert.assertFalse(infoField.isLocalizable()); | ||
} | ||
|
||
@Test | ||
public void testGetInfoItemFieldValues() throws Exception { | ||
InfoItemFieldValuesProvider<CalendarBooking> | ||
infoItemFieldValuesProvider = | ||
(InfoItemFieldValuesProvider<CalendarBooking>) | ||
_infoItemServiceRegistry.getFirstInfoItemService( | ||
InfoItemFieldValuesProvider.class, | ||
CalendarBooking.class.getName()); | ||
|
||
InfoItemFieldValues infoItemFieldValues = | ||
infoItemFieldValuesProvider.getInfoItemFieldValues( | ||
_calendarBooking); | ||
|
||
InfoItemReference infoItemReference = | ||
infoItemFieldValues.getInfoItemReference(); | ||
|
||
InfoItemIdentifier infoItemIdentifier = | ||
infoItemReference.getInfoItemIdentifier(); | ||
|
||
Assert.assertTrue( | ||
infoItemIdentifier instanceof ClassPKInfoItemIdentifier); | ||
|
||
ClassPKInfoItemIdentifier classPKInfoItemIdentifier = | ||
(ClassPKInfoItemIdentifier) | ||
infoItemReference.getInfoItemIdentifier(); | ||
|
||
Assert.assertEquals( | ||
_calendarBooking.getPrimaryKey(), | ||
classPKInfoItemIdentifier.getClassPK()); | ||
|
||
Assert.assertEquals( | ||
CalendarBooking.class.getName(), infoItemReference.getClassName()); | ||
|
||
Collection<InfoFieldValue<Object>> infoFieldValues = | ||
infoItemFieldValues.getInfoFieldValues(); | ||
|
||
Assert.assertEquals( | ||
infoFieldValues.toString(), 7, infoFieldValues.size()); | ||
|
||
InfoFieldValue<Object> allDayInfoFieldValue = | ||
infoItemFieldValues.getInfoFieldValue("allDay"); | ||
|
||
Assert.assertFalse((Boolean)allDayInfoFieldValue.getValue()); | ||
|
||
InfoFieldValue<Object> descriptionInfoFieldValue = | ||
infoItemFieldValues.getInfoFieldValue("description"); | ||
|
||
Assert.assertEquals( | ||
_calendarBooking.getDescription(LocaleUtil.getDefault()), | ||
descriptionInfoFieldValue.getValue(LocaleUtil.getDefault())); | ||
|
||
InfoFieldValue<Object> endDateInfoFieldValue = | ||
infoItemFieldValues.getInfoFieldValue("endDate"); | ||
|
||
Assert.assertEquals( | ||
new Date(_calendarBooking.getEndTime()), | ||
endDateInfoFieldValue.getValue()); | ||
|
||
InfoFieldValue<Object> eventURLInfoFieldValue = | ||
infoItemFieldValues.getInfoFieldValue("eventURL"); | ||
|
||
Assert.assertNotNull(eventURLInfoFieldValue.getValue()); | ||
|
||
InfoFieldValue<Object> locationInfoFieldValue = | ||
infoItemFieldValues.getInfoFieldValue("location"); | ||
|
||
Assert.assertEquals( | ||
_calendarBooking.getLocation(), locationInfoFieldValue.getValue()); | ||
|
||
InfoFieldValue<Object> startDateInfoFieldValue = | ||
infoItemFieldValues.getInfoFieldValue("startDate"); | ||
|
||
Assert.assertEquals( | ||
new Date(_calendarBooking.getStartTime()), | ||
startDateInfoFieldValue.getValue()); | ||
|
||
InfoFieldValue<Object> titleInfoFieldValue = | ||
infoItemFieldValues.getInfoFieldValue("title"); | ||
|
||
Assert.assertEquals( | ||
_calendarBooking.getTitle(LocaleUtil.getDefault()), | ||
titleInfoFieldValue.getValue(LocaleUtil.getDefault())); | ||
} | ||
|
||
@DeleteAfterTestRun | ||
private Calendar _calendar; | ||
|
||
@DeleteAfterTestRun | ||
private CalendarBooking _calendarBooking; | ||
|
||
@DeleteAfterTestRun | ||
private Group _group; | ||
|
||
@Inject | ||
private InfoItemServiceRegistry _infoItemServiceRegistry; | ||
|
||
} |
106 changes: 106 additions & 0 deletions
106
...ava/com/liferay/calendar/info/item/provider/test/CalendarBookingInfoItemProviderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/** | ||
* SPDX-FileCopyrightText: (c) 2024 Liferay, Inc. https://liferay.com | ||
* SPDX-License-Identifier: LGPL-2.1-or-later OR LicenseRef-Liferay-DXP-EULA-2.0.0-2023-06 | ||
*/ | ||
|
||
package com.liferay.calendar.info.item.provider.test; | ||
|
||
import com.liferay.arquillian.extension.junit.bridge.junit.Arquillian; | ||
import com.liferay.calendar.model.Calendar; | ||
import com.liferay.calendar.model.CalendarBooking; | ||
import com.liferay.calendar.test.util.CalendarBookingTestUtil; | ||
import com.liferay.calendar.test.util.CalendarTestUtil; | ||
import com.liferay.info.exception.NoSuchInfoItemException; | ||
import com.liferay.info.item.ClassPKInfoItemIdentifier; | ||
import com.liferay.info.item.InfoItemIdentifier; | ||
import com.liferay.info.item.InfoItemServiceRegistry; | ||
import com.liferay.info.item.provider.InfoItemObjectProvider; | ||
import com.liferay.portal.kernel.model.Group; | ||
import com.liferay.portal.kernel.test.rule.AggregateTestRule; | ||
import com.liferay.portal.kernel.test.rule.DeleteAfterTestRun; | ||
import com.liferay.portal.kernel.test.util.GroupTestUtil; | ||
import com.liferay.portal.kernel.test.util.RandomTestUtil; | ||
import com.liferay.portal.test.rule.Inject; | ||
import com.liferay.portal.test.rule.LiferayIntegrationTestRule; | ||
import com.liferay.portal.test.rule.PermissionCheckerMethodTestRule; | ||
|
||
import org.junit.Assert; | ||
import org.junit.Before; | ||
import org.junit.ClassRule; | ||
import org.junit.Rule; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
|
||
/** | ||
* @author Jonathan McCann | ||
*/ | ||
@RunWith(Arquillian.class) | ||
public class CalendarBookingInfoItemProviderTest { | ||
|
||
@ClassRule | ||
@Rule | ||
public static final AggregateTestRule aggregateTestRule = | ||
new AggregateTestRule( | ||
new LiferayIntegrationTestRule(), | ||
PermissionCheckerMethodTestRule.INSTANCE); | ||
|
||
@Before | ||
public void setUp() throws Exception { | ||
_group = GroupTestUtil.addGroup(); | ||
|
||
_calendar = CalendarTestUtil.addCalendar(_group); | ||
} | ||
|
||
@Test | ||
public void testGetInfoItemFromCalendarBookingInfoItemProvider() | ||
throws Exception { | ||
|
||
CalendarBooking calendarBooking = | ||
CalendarBookingTestUtil.addRegularCalendarBooking(_calendar); | ||
|
||
InfoItemIdentifier infoItemIdentifier = new ClassPKInfoItemIdentifier( | ||
calendarBooking.getPrimaryKey()); | ||
|
||
InfoItemObjectProvider<CalendarBooking> | ||
calendarBookingInfoItemProvider = | ||
(InfoItemObjectProvider<CalendarBooking>) | ||
_infoItemServiceRegistry.getFirstInfoItemService( | ||
InfoItemObjectProvider.class, | ||
CalendarBooking.class.getName(), | ||
infoItemIdentifier.getInfoItemServiceFilter()); | ||
|
||
CalendarBooking publishedCalendarBooking = | ||
calendarBookingInfoItemProvider.getInfoItem(infoItemIdentifier); | ||
|
||
Assert.assertEquals( | ||
calendarBooking.getTitle(), publishedCalendarBooking.getTitle()); | ||
} | ||
|
||
@Test(expected = NoSuchInfoItemException.class) | ||
public void testGetInvalidInfoItemFromCalendarBookingInfoItemProvider() | ||
throws Exception { | ||
|
||
InfoItemIdentifier infoItemIdentifier = new ClassPKInfoItemIdentifier( | ||
RandomTestUtil.randomLong()); | ||
|
||
InfoItemObjectProvider<CalendarBooking> | ||
calendarBookingInfoItemProvider = | ||
(InfoItemObjectProvider<CalendarBooking>) | ||
_infoItemServiceRegistry.getFirstInfoItemService( | ||
InfoItemObjectProvider.class, | ||
CalendarBooking.class.getName(), | ||
infoItemIdentifier.getInfoItemServiceFilter()); | ||
|
||
calendarBookingInfoItemProvider.getInfoItem(infoItemIdentifier); | ||
} | ||
|
||
@DeleteAfterTestRun | ||
private Calendar _calendar; | ||
|
||
@DeleteAfterTestRun | ||
private Group _group; | ||
|
||
@Inject | ||
private InfoItemServiceRegistry _infoItemServiceRegistry; | ||
|
||
} |