⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 notificationplugintest.java

📁 Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI
💻 JAVA
字号:
/*--------------------------------------------------------------------------*
 | Copyright (C) 2006 Christopher Kohlhaas                                  |
 |                                                                          |
 | This program is free software; you can redistribute it and/or modify     |
 | it under the terms of the GNU General Public License as published by the |
 | Free Software Foundation. A copy of the license has been included with   |
 | these distribution in the COPYING file, if not go to www.fsf.org         |
 |                                                                          |
 | As a special exception, you are granted the permissions to link this     |
 | program with every library, which license fulfills the Open Source       |
 | Definition as published by the Open Source Initiative (OSI).             |
 *--------------------------------------------------------------------------*/
package org.rapla.plugin.tests;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import org.apache.avalon.framework.configuration.ConfigurationException;
import org.rapla.MockMailer;
import org.rapla.ServletTestBase;
import org.rapla.components.mail.MailInterface;
import org.rapla.components.util.DateTools;
import org.rapla.entities.configuration.Preferences;
import org.rapla.entities.configuration.RaplaMap;
import org.rapla.entities.domain.Allocatable;
import org.rapla.entities.domain.Appointment;
import org.rapla.entities.domain.Reservation;
import org.rapla.entities.storage.RefEntity;
import org.rapla.facade.ClientFacade;
import org.rapla.framework.RaplaException;
import org.rapla.plugin.notification.NotificationService;
import org.rapla.server.ServerService;

/** listens for allocation changes */
public class NotificationPluginTest extends ServletTestBase
{
    ServerService raplaServer;

    ClientFacade facade1;
    Locale locale;

    public NotificationPluginTest( String name )
    {
        super( name );
    }

    protected void setUp() throws Exception
    {
        super.setUp();
        // start the server
        raplaServer = (ServerService) getContext().lookup( ServerService.ROLE + "/" + getStorageName() );

        // start the client service
        facade1 = (ClientFacade) getContext().lookup( ClientFacade.ROLE + "/remote-facade" );
        facade1.login( "homer", "duffs".toCharArray() );
        locale = Locale.getDefault();
    }

    protected void tearDown() throws Exception
    {
        facade1.logout();
        super.tearDown();
    }

    protected String getStorageName()
    {
        return "storage-file";
    }

    private void add( Allocatable allocatable ) throws ConfigurationException, RaplaException
    {
        Preferences preferences = (Preferences) facade1.edit( facade1.getPreferences() );
        RaplaMap raplaEntityList = (RaplaMap) preferences.getEntry( NotificationService.ALLOCATIONLISTENERS_CONFIG );
        List list;
        if ( raplaEntityList != null )
        {
            list = new ArrayList( raplaEntityList.values() );
        }
        else
        {
            list = new ArrayList();
        }
        list.add( allocatable );
        //getLogger().info( "Adding notificationEntry " + allocatable );
        preferences.putEntry( NotificationService.ALLOCATIONLISTENERS_CONFIG, facade1.newRaplaMap( list ) );
        preferences.putEntry( NotificationService.NOTIFY_IF_OWNER_CONFIG, String.valueOf( true ) );
        facade1.store( preferences );
    }

    public void testAdd() throws Exception
    {
        Allocatable allocatable = facade1.getAllocatables()[0];

        add( allocatable );

        Reservation r = facade1.newReservation();
        String reservationName = "New Reservation";
        r.getClassification().setValue( "name", reservationName );
        Appointment appointment = facade1.newAppointment( new Date(), new Date( new Date().getTime()
                + DateTools.MILLISECONDS_PER_HOUR ) );
        r.addAppointment( appointment );
        r.addAllocatable( allocatable );

        System.out.println( ( (RefEntity) r ).getVersion() );

        facade1.store( r );

        System.out.println( ( (RefEntity) r ).getVersion() );

        MockMailer mailMock = (MockMailer) raplaServer.getContext().lookup( MailInterface.ROLE );
        Thread.sleep( 1000 );

        assertNotNull( mailMock.getMailBody() );
        assertTrue( mailMock.getMailBody().indexOf( reservationName ) >= 0 );

        reservationName = "Another name";
        r.getClassification().setValue( "name", reservationName );
        r.getAppointments()[0].move( new Date( new Date().getTime() + DateTools.MILLISECONDS_PER_HOUR ) );
        facade1.store( r );

        System.out.println( ( (RefEntity) r ).getVersion() );

        Thread.sleep( 1000 );
        assertEquals( 2, mailMock.getCallCount() );

        assertNotNull( mailMock.getMailBody() );
        assertTrue( mailMock.getMailBody().indexOf( reservationName ) >= 0 );

       

    }

    public void testRemove() throws Exception
    {
        Allocatable allocatable = facade1.getAllocatables()[0];

        add( allocatable );

        Reservation r = facade1.newReservation();
        String reservationName = "New Reservation";
        r.getClassification().setValue( "name", reservationName );
        Appointment appointment = facade1.newAppointment( new Date(), new Date( new Date().getTime()
                + DateTools.MILLISECONDS_PER_HOUR ) );
        r.addAppointment( appointment );
        r.addAllocatable( allocatable );


        facade1.store( r );
        facade1.remove( r );

        Thread.sleep( 1000 );
        MockMailer mailMock = (MockMailer) raplaServer.getContext().lookup( MailInterface.ROLE );
        assertEquals( 2, mailMock.getCallCount() );
        String body = mailMock.getMailBody();
        assertTrue( "Body doesnt contain delete text\n" + body, body.indexOf( "gel\u00f6scht" ) >= 0 );
     
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -