Package org.plugtree.training.model

Examples of org.plugtree.training.model.Playlist


        return ksession;
    }
    @Test
    public void noLoop() throws Exception {

        Playlist pl = this.createFullPlaylist();

        StatefulKnowledgeSession ksession = this.createKSession("/rules/NoLoopRules.drl", null);

        ksession.setGlobal("index", new AtomicInteger(1));

        for (Song song : pl.getSongs()) {
            System.out.println(song.getName());
            ksession.insert(song);
        }


        ksession.fireAllRules();

        for (Song song : pl.getSongs()) {
            System.out.println(song.getName());
        }

        ksession.dispose();
View Full Code Here


    }
    @Test
    public void lockOnActive() throws Exception {

        Playlist pl = this.createFullPlaylist();

        StatefulKnowledgeSession ksession = this.createKSession("/rules/LockOnActiveRules.drl", null);

        ksession.setGlobal("index", new AtomicInteger(1));

        for (Song song : pl.getSongs()) {
            System.out.println(song.getName());
            ksession.insert(song);
        }


        ksession.fireAllRules();

        for (Song song : pl.getSongs()) {
            System.out.println(song.getName());
        }

        ksession.dispose();
View Full Code Here

        List<String> firedRules = new ArrayList<String>();

        StatefulKnowledgeSession ksession = this.createKSession("/rules/AgendaGroupRules.drl", firedRules);

        Playlist playlist = new Playlist("Good playlist");
        ksession.setGlobal("index", new AtomicInteger(1));

        ksession.insert(playlist);
        ksession.insert(createThrillerSong());
        ksession.insert(createAdagioSong());
        ksession.insert(createTheFinalCountdownSong());

        ksession.fireAllRules();

        //No rules were fired because the MAIN agenda-group is empty. We
        //need to manually set the focus in an agenda-group.
        Assert.assertTrue(firedRules.isEmpty());

        Assert.assertTrue(playlist.isEmpty());
        Assert.assertFalse(playlist.isPlaying());

        //This way we set the focus in an agenda-group
        ksession.getAgenda().getAgendaGroup("Create Playlist").setFocus();
        ksession.fireAllRules();

        //3 rules x 3 songs = 9 + "Playlist ready" + "Play playlist" = 11
        Assert.assertEquals(11,firedRules.size());
        //The salience of the rules guarantees the excecution order
        Assert.assertTrue(firedRules.get(0).equals("Classify Songs"));
        Assert.assertTrue(firedRules.get(1).equals("Classify Songs"));
        Assert.assertTrue(firedRules.get(2).equals("Classify Songs"));
        Assert.assertTrue(firedRules.get(3).equals("Number Songs"));
        Assert.assertTrue(firedRules.get(4).equals("Number Songs"));
        Assert.assertTrue(firedRules.get(5).equals("Number Songs"));
        Assert.assertTrue(firedRules.get(6).equals("Fill playlist"));
        Assert.assertTrue(firedRules.get(7).equals("Fill playlist"));
        Assert.assertTrue(firedRules.get(8).equals("Fill playlist"));
        Assert.assertTrue(firedRules.get(9).equals("Playlist ready"));
        Assert.assertTrue(firedRules.get(10).equals("Play playlist"));

        Assert.assertEquals(3, playlist.getSongs().size());
        Assert.assertTrue(playlist.isPlaying());


        ksession.dispose();

    }
View Full Code Here

    /**
     * Creates a new playlist with 2 songs.
     * @return the created playlist
     */
    private Playlist createPlaylist() {
        Playlist playlist = new Playlist();
        playlist.setName("My favorite songs");
       
        playlist.addSong(createThriller());
        playlist.addSong(createAdagio());

        return playlist;
    }
View Full Code Here

    /**
     * Creates a new playlist with 3 songs.
     * @return the created playlist
     */
    private Playlist createFullPlaylist() {
        Playlist playlist = new Playlist();
        playlist.setName("My favorite songs");

        playlist.addSong(createThrillerSong());
        playlist.addSong(createAdagioSong());
        playlist.addSong(createTheFinalCountdownSong());

        return playlist;
    }
View Full Code Here

    /**
     * Creates a new playlist with 2 songs.
     * @return the created playlist
     */
    private Playlist createLongPlaylist() {
        Playlist playlist = new Playlist();
        playlist.setName("My favorite songs");


        Song song = new Song("Thriller", Song.Genre.POP, 6540, 1982);
        song.addArtist(new Artist("Michael", "Jackson"));
        playlist.addSong(song);

        song = new Song("Adagio", Song.Genre.CLASSICAL, 2561, 1708);
        song.addArtist(new Artist("Johann Sebastian", "Bach"));
        playlist.addSong(song);

        song = new Song("The final countdown", Song.Genre.ROCK, 300, 1985);
        song.addArtist(new Artist("Joey", "Tempest"));
        song.addArtist(new Artist("John", "Norum"));
        playlist.addSong(song);

        return playlist;
    }
View Full Code Here

        return playlist;
    }

    private Playlist createShortPlaylist() {
        Playlist playlist = new Playlist();
        playlist.setName("Rock songs");

        Song song = new Song("The final countdown", Song.Genre.ROCK, 300, 1985);
        song.addArtist(new Artist("Joey", "Tempest"));
        song.addArtist(new Artist("John", "Norum"));
        playlist.addSong(song);

        song = new Song("Thriller", Song.Genre.POP, 6540, 1982);
        song.addArtist(new Artist("Michael", "Jackson"));
        playlist.addSong(song);

        return playlist;
    }
View Full Code Here

        });
    }
    @Test
    public void rulesActivation() {

        Playlist playlist = this.createFullPlaylist();

        ksession.insert(playlist);
        ksession.fireAllRules();

        Assert.assertEquals(2,firedRules.size());
View Full Code Here

    /**
     * Creates a new playlist with 3 songs.
     * @return the created playlist
     */
    private Playlist createFullPlaylist() {
        Playlist playlist = new Playlist();
        playlist.setName("My favorite songs");
       
        playlist.addSong(createThrillerSong());
        playlist.addSong(createAdagioSong());
        playlist.addSong(createTheFinalCountdownSong());

        return playlist;
    }
View Full Code Here

    /**
     * Creates a new playlist containing just one song: "The final countdown"
     * @return a new playlist containing just one song: "The final countdown"
     */
    private Playlist createPlaylistWithOneSong() {
        Playlist playlist = new Playlist();
        playlist.setName("Single song playlist");
       
        playlist.addSong(createTheFinalCountdownSong());

        return playlist;
    }
View Full Code Here

TOP

Related Classes of org.plugtree.training.model.Playlist

Copyright © 2018 www.massapicom. 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.