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 Jose Angel Jim??nez
024     */
025    public abstract class BaseSubscriptionAuthorTestCase
026            extends BaseSubscriptionTestCase {
027    
028            @Test
029            public void testSubscriptionForAuthorWhenAddingBaseModel()
030                    throws Exception {
031    
032                    long containerModelId = addContainerModel(
033                            creatorUser.getUserId(),
034                            BaseSubscriptionTestCase.PARENT_CONTAINER_MODEL_ID_DEFAULT);
035    
036                    addSubscription(creatorUser.getUserId(), containerModelId);
037    
038                    addBaseModel(creatorUser.getUserId(), containerModelId);
039    
040                    if (isSubscriptionForAuthorEnabled()) {
041                            Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
042                    }
043                    else {
044                            Assert.assertEquals(0, MailServiceTestUtil.getInboxSize());
045                    }
046            }
047    
048            @Test
049            public void testSubscriptionForAuthorWhenUpdatingBaseModel()
050                    throws Exception {
051    
052                    long containerModelId = addContainerModel(
053                            creatorUser.getUserId(), PARENT_CONTAINER_MODEL_ID_DEFAULT);
054    
055                    long baseModelId = addBaseModel(
056                            creatorUser.getUserId(), containerModelId);
057    
058                    addSubscription(creatorUser.getUserId(), containerModelId);
059    
060                    updateBaseModel(creatorUser.getUserId(), baseModelId);
061    
062                    if (isSubscriptionForAuthorEnabled()) {
063                            Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
064                    }
065                    else {
066                            Assert.assertEquals(0, MailServiceTestUtil.getInboxSize());
067                    }
068            }
069    
070            protected abstract void addSubscription(long userId, long containerModelId)
071                    throws Exception;
072    
073            protected boolean isSubscriptionForAuthorEnabled() {
074                    return false;
075            }
076    
077    }