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 BaseSubscriptionClassTypeTestCase
026            extends BaseSubscriptionTestCase {
027    
028            @Test
029            public void testSubscriptionClassTypeWhenAddingBaseModel()
030                    throws Exception {
031    
032                    long classTypeId = addClassType();
033    
034                    addSubscriptionClassType(classTypeId);
035    
036                    addBaseModelWithClassType(
037                            PARENT_CONTAINER_MODEL_ID_DEFAULT, classTypeId);
038    
039                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
040            }
041    
042            @Test
043            public void testSubscriptionClassTypeWhenUpdatingBaseModel()
044                    throws Exception {
045    
046                    long classTypeId = addClassType();
047    
048                    long baseModelId = addBaseModelWithClassType(
049                            PARENT_CONTAINER_MODEL_ID_DEFAULT, classTypeId);
050    
051                    addSubscriptionClassType(classTypeId);
052    
053                    updateBaseModel(creatorUser.getUserId(), baseModelId);
054    
055                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
056            }
057    
058            @Test
059            public void testSubscriptionDefaultClassTypeWhenAddingBaseModel()
060                    throws Exception {
061    
062                    Long classTypeId = getDefaultClassTypeId();
063    
064                    addSubscriptionClassType(classTypeId);
065    
066                    addBaseModelWithClassType(
067                            PARENT_CONTAINER_MODEL_ID_DEFAULT, classTypeId);
068    
069                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
070    
071                    deleteSubscriptionClassType(classTypeId);
072            }
073    
074            @Test
075            public void testSubscriptionDefaultClassTypeWhenUpdatingBaseModel()
076                    throws Exception {
077    
078                    Long classTypeId = getDefaultClassTypeId();
079    
080                    long baseModelId = addBaseModelWithClassType(
081                            PARENT_CONTAINER_MODEL_ID_DEFAULT, classTypeId);
082    
083                    addSubscriptionClassType(classTypeId);
084    
085                    updateBaseModel(creatorUser.getUserId(), baseModelId);
086    
087                    Assert.assertEquals(1, MailServiceTestUtil.getInboxSize());
088    
089                    deleteSubscriptionClassType(classTypeId);
090            }
091    
092            protected abstract long addBaseModelWithClassType(
093                            long containerModelId, long classTypeId)
094                    throws Exception;
095    
096            protected abstract long addClassType() throws Exception;
097    
098            protected abstract void addSubscriptionClassType(long classTypeId)
099                    throws Exception;
100    
101            protected abstract void deleteSubscriptionClassType(long classTypeId)
102                    throws Exception;
103    
104            protected abstract Long getDefaultClassTypeId() throws Exception;
105    
106    }