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 BaseSubscriptionBaseModelTestCase
026            extends BaseSubscriptionTestCase {
027    
028            @Test
029            public void testSubscriptionBaseModelWhenInContainerModel()
030                    throws Exception {
031    
032                    long containerModelId = addContainerModel(
033                            creatorUser.getUserId(),
034                            BaseSubscriptionTestCase.PARENT_CONTAINER_MODEL_ID_DEFAULT);
035    
036                    long baseModelId = addBaseModel(
037                            creatorUser.getUserId(), containerModelId);
038    
039                    addSubscriptionBaseModel(baseModelId);
040    
041                    updateBaseModel(creatorUser.getUserId(), baseModelId);
042    
043                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
044            }
045    
046            @Test
047            public void testSubscriptionBaseModelWhenInNoViewableContainerModel()
048                    throws Exception {
049    
050                    long containerModelId = addContainerModel(
051                            creatorUser.getUserId(),
052                            BaseSubscriptionTestCase.PARENT_CONTAINER_MODEL_ID_DEFAULT);
053    
054                    long baseModelId = addBaseModel(
055                            creatorUser.getUserId(), containerModelId);
056    
057                    addSubscriptionBaseModel(baseModelId);
058    
059                    removeContainerModelResourceViewPermission();
060    
061                    updateBaseModel(creatorUser.getUserId(), baseModelId);
062    
063                    Assert.assertEquals(0, MailServiceTestUtil.getInboxSize());
064            }
065    
066            @Test
067            public void testSubscriptionBaseModelWhenInRootContainerModel()
068                    throws Exception {
069    
070                    long baseModelId = addBaseModel(
071                            creatorUser.getUserId(),
072                            BaseSubscriptionTestCase.PARENT_CONTAINER_MODEL_ID_DEFAULT);
073    
074                    addSubscriptionBaseModel(baseModelId);
075    
076                    updateBaseModel(creatorUser.getUserId(), baseModelId);
077    
078                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
079            }
080    
081            protected abstract void addSubscriptionBaseModel(long baseModelId)
082                    throws Exception;
083    
084            protected abstract void removeContainerModelResourceViewPermission()
085                    throws Exception;
086    
087    }