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 BaseSubscriptionContainerModelTestCase
026            extends BaseSubscriptionTestCase {
027    
028            @Test
029            public void
030                            testSubscriptionContainerModelWhenAddingBaseModelInContainerModel()
031                    throws Exception {
032    
033                    long containerModelId = addContainerModel(
034                            creatorUser.getUserId(),
035                            BaseSubscriptionTestCase.PARENT_CONTAINER_MODEL_ID_DEFAULT);
036    
037                    addSubscriptionContainerModel(containerModelId);
038    
039                    addBaseModel(creatorUser.getUserId(), containerModelId);
040    
041                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
042            }
043    
044            @Test
045            public void
046                            testSubscriptionContainerModelWhenAddingBaseModelInRootContainerModel()
047                    throws Exception {
048    
049                    long containerModelId = addContainerModel(
050                            creatorUser.getUserId(),
051                            BaseSubscriptionTestCase.PARENT_CONTAINER_MODEL_ID_DEFAULT);
052    
053                    addSubscriptionContainerModel(containerModelId);
054    
055                    addBaseModel(
056                            creatorUser.getUserId(),
057                            BaseSubscriptionTestCase.PARENT_CONTAINER_MODEL_ID_DEFAULT);
058    
059                    Assert.assertEquals(0, MailServiceTestUtil.getInboxSize());
060            }
061    
062            @Test
063            public void
064                            testSubscriptionContainerModelWhenAddingBaseModelInSubcontainerModel()
065                    throws Exception {
066    
067                    long containerModelId = addContainerModel(
068                            creatorUser.getUserId(),
069                            BaseSubscriptionTestCase.PARENT_CONTAINER_MODEL_ID_DEFAULT);
070    
071                    addSubscriptionContainerModel(containerModelId);
072    
073                    long subcontainerModelId = addContainerModel(
074                            creatorUser.getUserId(), containerModelId);
075    
076                    addBaseModel(creatorUser.getUserId(), subcontainerModelId);
077    
078                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
079            }
080    
081            @Test
082            public void
083                            testSubscriptionContainerModelWhenUpdatingBaseModelInContainerModel()
084                    throws Exception {
085    
086                    long containerModelId = addContainerModel(
087                            creatorUser.getUserId(), PARENT_CONTAINER_MODEL_ID_DEFAULT);
088    
089                    long baseModelId = addBaseModel(
090                            creatorUser.getUserId(), containerModelId);
091    
092                    addSubscriptionContainerModel(containerModelId);
093    
094                    updateBaseModel(creatorUser.getUserId(), baseModelId);
095    
096                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
097            }
098    
099            @Test
100            public void
101                            testSubscriptionContainerModelWhenUpdatingBaseModelInRootContainerModel()
102                    throws Exception {
103    
104                    long containerModelId = addContainerModel(
105                            creatorUser.getUserId(), PARENT_CONTAINER_MODEL_ID_DEFAULT);
106    
107                    long baseModelId = addBaseModel(
108                            creatorUser.getUserId(), PARENT_CONTAINER_MODEL_ID_DEFAULT);
109    
110                    addSubscriptionContainerModel(containerModelId);
111    
112                    updateBaseModel(creatorUser.getUserId(), baseModelId);
113    
114                    Assert.assertEquals(0, MailServiceTestUtil.getInboxSize());
115            }
116    
117            @Test
118            public void
119                            testSubscriptionContainerModelWhenUpdatingBaseModelInSubcontainerModel()
120                    throws Exception {
121    
122                    long containerModelId = addContainerModel(
123                            creatorUser.getUserId(), PARENT_CONTAINER_MODEL_ID_DEFAULT);
124    
125                    long subcontainerModelId = addContainerModel(
126                            creatorUser.getUserId(), containerModelId);
127    
128                    long baseModelId = addBaseModel(
129                            creatorUser.getUserId(), subcontainerModelId);
130    
131                    addSubscriptionContainerModel(containerModelId);
132    
133                    updateBaseModel(creatorUser.getUserId(), baseModelId);
134    
135                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
136            }
137    
138            protected abstract void addSubscriptionContainerModel(long containerModelId)
139                    throws Exception;
140    
141    }