001    /**
002     * Copyright (c) 2000-present Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portlet.subscriptions.test;
016    
017    import com.liferay.portal.util.test.MailServiceTestUtil;
018    
019    import org.junit.Assert;
020    import org.junit.Test;
021    
022    /**
023     * @author Roberto D??az
024     */
025    public abstract class BaseSubscriptionRootContainerModelTestCase
026            extends BaseSubscriptionTestCase {
027    
028            @Test
029            public void
030                            testSubscriptionRootContainerModelWhenAddingBaseModelInContainerModel()
031                    throws Exception {
032    
033                    addSubscriptionContainerModel(PARENT_CONTAINER_MODEL_ID_DEFAULT);
034    
035                    long containerModelId = addContainerModel(
036                            creatorUser.getUserId(), PARENT_CONTAINER_MODEL_ID_DEFAULT);
037    
038                    addBaseModel(creatorUser.getUserId(), containerModelId);
039    
040                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
041            }
042    
043            @Test
044            public void
045                            testSubscriptionRootContainerModelWhenAddingBaseModelInRootContainerModel()
046                    throws Exception {
047    
048                    addSubscriptionContainerModel(PARENT_CONTAINER_MODEL_ID_DEFAULT);
049    
050                    addBaseModel(
051                            creatorUser.getUserId(), PARENT_CONTAINER_MODEL_ID_DEFAULT);
052    
053                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
054            }
055    
056            @Test
057            public void
058                            testSubscriptionRootContainerModelWhenAddingBaseModelInSubcontainerModel()
059                    throws Exception {
060    
061                    addSubscriptionContainerModel(PARENT_CONTAINER_MODEL_ID_DEFAULT);
062    
063                    long containerModelId = addContainerModel(
064                            creatorUser.getUserId(), PARENT_CONTAINER_MODEL_ID_DEFAULT);
065    
066                    long subcontainerModelId = addContainerModel(
067                            creatorUser.getUserId(), containerModelId);
068    
069                    addBaseModel(creatorUser.getUserId(), subcontainerModelId);
070    
071                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
072            }
073    
074            @Test
075            public void
076                            testSubscriptionRootContainerModelWhenUpdatingBaseModelInContainerModel()
077                    throws Exception {
078    
079                    long containerModelId = addContainerModel(
080                            creatorUser.getUserId(), PARENT_CONTAINER_MODEL_ID_DEFAULT);
081    
082                    long baseModelId = addBaseModel(
083                            creatorUser.getUserId(), containerModelId);
084    
085                    addSubscriptionContainerModel(PARENT_CONTAINER_MODEL_ID_DEFAULT);
086    
087                    updateBaseModel(creatorUser.getUserId(), baseModelId);
088    
089                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
090            }
091    
092            @Test
093            public void
094                            testSubscriptionRootContainerModelWhenUpdatingBaseModelInRootContainerModel()
095                    throws Exception {
096    
097                    long baseModelId = addBaseModel(
098                            creatorUser.getUserId(), PARENT_CONTAINER_MODEL_ID_DEFAULT);
099    
100                    addSubscriptionContainerModel(PARENT_CONTAINER_MODEL_ID_DEFAULT);
101    
102                    updateBaseModel(creatorUser.getUserId(), baseModelId);
103    
104                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
105            }
106    
107            @Test
108            public void
109                            testSubscriptionRootContainerModelWhenUpdatingBaseModelInSubcontainerModel()
110                    throws Exception {
111    
112                    long containerModelId = addContainerModel(
113                            creatorUser.getUserId(), PARENT_CONTAINER_MODEL_ID_DEFAULT);
114    
115                    long subcontainerModelId = addContainerModel(
116                            creatorUser.getUserId(), containerModelId);
117    
118                    long baseModelId = addBaseModel(
119                            creatorUser.getUserId(), subcontainerModelId);
120    
121                    addSubscriptionContainerModel(PARENT_CONTAINER_MODEL_ID_DEFAULT);
122    
123                    updateBaseModel(creatorUser.getUserId(), baseModelId);
124    
125                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
126            }
127    
128            protected abstract void addSubscriptionContainerModel(long containerModelId)
129                    throws Exception;
130    
131    }