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