Package org.apache.agila.impl.memory

Source Code of org.apache.agila.impl.memory.NotificationServiceImplTestCase

/*
* Copyright 2004 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License")
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.agila.impl.memory;

import junit.framework.TestCase;
import org.apache.agila.services.user.UserID;
import org.apache.agila.services.notification.Notification;
import org.apache.agila.services.notification.NotificationID;

import java.util.Iterator;
import java.util.List;

/**
*
* @author <a href="mailto:geir@gluecode.com">Geir Magnusson Jr.</a>
* @version $Id: NotificationServiceImplTestCase.java 38 2005-06-01 19:39:54Z chirino $
*/
public class NotificationServiceImplTestCase extends TestCase{

    private NotificationServiceImpl notificationService;

    public void testCreateNew() {
        Notification notification = notificationService.createNew( new UserID( 1 ), "Hello World" );
       
        assertNotNull( "Notification should not be null.", notification );
        assertEquals( "UserID should be 1.", new UserID( 1 ), notification.getUserID() );
        assertEquals( "Message should be Hello World", "Hello World", notification.getMessage() );
        assertEquals( "Notification should be inserted into notification queue.", 1, notificationService.getForUserID( new UserID( 1 ) ).size() );
    }

    public void testGet() {
        populateNotification();

        List notifications = notificationService.getForUserID( new UserID( 1 ) );
        for( Iterator iterator = notifications.iterator(); iterator.hasNext(); ) {
            Notification notification = (Notification) iterator.next();

            assertNotNull( "Notification should not be null", notification );
        }
    }

    public void testGetForUserID() {
        populateNotification();
       
        List notification1 = notificationService.getForUserID( new UserID( 1 ) );
        List notification2 = notificationService.getForUserID( new UserID( 1 ) );
       
        assertEquals( "Multiple calls to notification should produce the same result. Given that no modifications are made.", notification1, notification2 );
    }

    public void testEmpty() throws Exception {

        NotificationServiceImpl nsi = new NotificationServiceImpl();

        /*
         *  make up a user id and see if something bad happens
         */
        List l = nsi.getForUserID(new UserID(1));

        assertTrue(l != null);
        assertTrue(l.size() == 0);

        nsi.get(new NotificationID(3));
    }

    private void populateNotification() {
        for( int i = 0; i < 10; i++ ) {
            notificationService.createNew( new UserID( 1 ), "Hello World " + i );
        }
    }

    public void setUp() throws Exception {
        notificationService = new NotificationServiceImpl();
    }
   
    public void tearDown() throws Exception {
        notificationService = null;
    }
}
TOP

Related Classes of org.apache.agila.impl.memory.NotificationServiceImplTestCase

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.