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