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

📄 servertest.java

📁 Rapla是一个灵活的多用户资源管理系统。它提供的一些功能有:日历GUI
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        assertEquals( 5, facade2.getAllocatables().length);
        
        ClassificationFilter filter = facade2.getDynamicType("room").newClassificationFilter();
        filter.addIsRule( "name", "erwin");
        {
            Allocatable rAfter = facade2.getAllocatables( filter.toArray())[0];
            assertEquals(2, rAfter.getClassification().getAttributes().length);
        }
        //facade2.getUser("test-user");
        // Wait for the update
        facade2.refresh();
        facade2.logout();
    }
    
    private Reservation findReservation(ClientFacade facade,String typeKey,String name) throws RaplaException {
        DynamicType reservationType = facade.getDynamicType( typeKey );
        ClassificationFilter filter = reservationType.newClassificationFilter();
        filter.addRule("name", new Object[][] {{"contains","test-reservation"}});
        Reservation[] reservations = facade.getReservations( null, null, null, new ClassificationFilter[] {filter});
        if (reservations.length >0 )
            return reservations[0];
        else
            return null;
    }


    public void testChangeDynamicType2() throws Exception {
        DynamicType type = (DynamicType) facade1.getDynamicTypes(DynamicTypeAnnotations.VALUE_RESOURCE_CLASSIFICATION)[0];
        DynamicType typeEdit3 = (DynamicType) facade1.edit(type);
        typeEdit3.removeAttribute( typeEdit3.getAttribute("belongsto"));

        Allocatable resource1 = (Allocatable) facade1.getAllocatables()[0];
        assertEquals("erwin", resource1.getName( locale ) );
        facade1.store( typeEdit3 );
        assertEquals(2, resource1.getClassification().getAttributes().length);
    }

    public void testRemoveCategory() throws Exception {
        Category superCategoryClone = (Category) facade1.edit(facade1.getSuperCategory());
        Category department = superCategoryClone.getCategory("department");
        Category powerplant = department.getCategory("springfield-powerplant");
        powerplant.getParent().removeCategory(powerplant);
        try {
            facade1.store(superCategoryClone);
        } catch (DependencyException ex) {
            return;
        }
        assertTrue("Dependency Exception should have been thrown", false);
    }

    public void testStoreFilter() throws Exception {
        // select from event where name contains 'planting' or name contains 'test';
        DynamicType dynamicType = facade1.getDynamicType("room");
        ClassificationFilter classificationFilter = dynamicType.newClassificationFilter();
        Category channel6 = facade1.getSuperCategory().getCategory("department").getCategory("channel-6");
        Category testdepartment = facade1.getSuperCategory().getCategory("department").getCategory("testdepartment");
        classificationFilter.setRule(0
                                     ,dynamicType.getAttribute("belongsto")
                                     ,new Object[][] {
                                         {"is",channel6}
                                         ,{"is",testdepartment}
                                     }
                                     );
        boolean thrown = false;
        ClassificationFilter[] filter = new ClassificationFilter[] { classificationFilter};
    	RaplaMap selected = facade1.newRaplaMap( Collections.EMPTY_MAP );
    	CalendarModelConfiguration conf = facade1.newRaplaCalendarModel(selected, filter,null,null, null, facade1.today(), "week", null );
        Preferences prefs = (Preferences) facade1.edit( facade1.getPreferences());
    	prefs.putEntry( "org.rapla.TestEntry", conf);
    	facade1.store( prefs );
    	User user = raplaServer.getFacade().getUser("homer");
        Preferences storedPrefs = raplaServer.getFacade().getPreferences(user);
        assertNotNull( storedPrefs );
        CalendarModelConfiguration storedConf =   (CalendarModelConfiguration )storedPrefs.getEntry("org.rapla.TestEntry");
        assertNotNull( storedConf );
        
        ClassificationFilter[] storedFilter = storedConf.getFilter();
        assertEquals( 1, storedFilter.length);
        ClassificationFilter storedClassFilter = storedFilter[0];

        assertEquals( 1, storedClassFilter.ruleSize());

        try {
            Category parent = (Category) facade1.edit( testdepartment.getParent() );
            parent.removeCategory( testdepartment );
            facade1.store( parent );
        } catch (DependencyException ex) {
            assertTrue(ex.getDependencies().contains(prefs.getName(locale)));
            thrown = true;
        }
        assertTrue("Dependency Exception should have been thrown!",thrown);

    }
    
    public void testReservationInTheFutureStoredInCalendar() throws Exception{
        Date futureDate = new Date(facade1.today().getTime() + DateTools.MILLISECONDS_PER_WEEK * 10);
        Reservation r = facade1.newReservation();
        r.addAppointment( facade1.newAppointment( futureDate, futureDate));
        r.getClassification().setValue("name","Test");

        facade1.store( r );

        RaplaMap map = facade1.newRaplaMap( Collections.singletonList( r ));
        CalendarModelConfiguration conf = facade1.newRaplaCalendarModel( map, null,"test", null, null,facade1.today(), WeekViewFactory.WEEK_VIEW, null);

        Preferences prefs = ( Preferences ) facade1.edit( facade1.getPreferences() );
        prefs.putEntry( "org.rapla.test", conf);

        try {
            facade1.store( prefs );
            fail("Should throw an exception in the current version, because we can't store references to reservations");
        } catch (RaplaException ex) {
        }
        /*
        Thread.sleep( 1000);

        ClientFacade facade2 = (ClientFacade)
        getContext().lookup(ClientFacade.ROLE + "/remote-facade-2");
        facade2.login("homer","duffs".toCharArray());*/


    }


    public void testReservationWithExceptionDoesntShow() throws Exception {
        {
            facade1.removeObjects( facade1.getReservations( null, null, null, null));
        }
        Date start =  new Date();
        Date end = new Date( start.getTime() + DateTools.MILLISECONDS_PER_HOUR * 2);
        {
	        Reservation r = facade1.newReservation(  );
	        r.getClassification().setValue("name","test-reservation");
	        Appointment a = facade1.newAppointment( start, end);
	        a.setRepeatingEnabled( true );
	        a.getRepeating().setType( Repeating.WEEKLY);
	        a.getRepeating().setInterval( 2 );
	        a.getRepeating().setNumber( 10 );
	        r.addAllocatable( facade1.getAllocatables()[0]);
	        r.addAppointment( a );
	        a.getRepeating().addException( start );
	        a.getRepeating().addException( new Date(start.getTime() + DateTools.MILLISECONDS_PER_WEEK));
	        facade1.store(  r  );
	        facade1.logout();
        }
        {
            ClientFacade facade2 = (ClientFacade) getContext().lookup(ClientFacade.ROLE + "/remote-facade-2");
	        facade2.login("homer","duffs".toCharArray());

	        Reservation[] res = facade2.getReservations( null,start, new Date( start.getTime()+ 8* DateTools.MILLISECONDS_PER_WEEK  ), null );
	        assertEquals( 1, res.length);
            Thread.sleep( 100);
	        facade2.logout();
        }


    }

    public void testChangeGroup() throws Exception {
        User user = (User)facade1.edit( facade1.getUser("monty"));
        Category[] groups = user.getGroups();
        assertTrue("No groups found!", groups.length>0);
        Category myGroup = facade1.getUserGroupsCategory().getCategory("my-group");
        assertTrue( Arrays.asList(groups).contains(myGroup));
        user.removeGroup( myGroup );
        ClientFacade facade2 = (ClientFacade)
        getContext().lookup(ClientFacade.ROLE + "/remote-facade-2");
        facade2.login("homer","duffs".toCharArray());
        Allocatable testResource = (Allocatable) facade2.edit( facade2.getAllocatables()[0]);
        assertTrue( testResource.canAllocate( facade2.getUser("monty") ,null, null,null));
        testResource.removePermission( testResource.getPermissions()[0]);
        Permission newPermission = testResource.newPermission();
        newPermission.setGroup( facade1.getUserGroupsCategory().getCategory("my-group") );
        newPermission.setAccessLevel( Permission.READ );
        testResource.addPermission( newPermission );
        assertFalse( testResource.canAllocate( facade2.getUser("monty") ,null, null,null));
        assertTrue( testResource.canRead( facade2.getUser("monty")));
        facade1.store( user );
        facade2.refresh();
        assertFalse( testResource.canRead( facade2.getUser("monty") ));
    }

    public void testRemoveAppointment() throws Exception {
        Date start = getRaplaLocale().toDate( 2005, 10, 10);
        Date end = getRaplaLocale().toDate( 2005, 10, 15);
        Reservation r = facade1.newReservation();
        r.getClassification().setValue("name", "newReservation");
        r.addAppointment( facade1.newAppointment( start, end ));
        r.addAllocatable( facade1.getAllocatables()[0]);
        ClassificationFilter f = r.getClassification().getType().newClassificationFilter();
        f.addEqualsRule("name","newReservation");
        facade1.store( r );
        r = (Reservation) facade1.getPersistant( r );
        facade1.remove( r );
        Reservation[] allRes =  facade1.getReservations( null, null, null,new ClassificationFilter[] {f} );
        assertEquals( 0 , allRes.length);

    }

}





⌨️ 快捷键说明

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