/**
 * Projet myplayapp
 * Entité Game
 */
package models;

import javax.persistence.Entity;

import play.data.validation.Required;
import play.db.jpa.Model;

/**
 * Game Classe modélisant un jeu vidéo de la bibliothèque
 * @author frederic
 * 
 */
@Entity
public class Game extends Model {
@Required
public String title;
@Required
public String platform;
@Required
public String description;
public Boolean publish;
public String testContent;
public String developerStudio;
public String editor;
@Required
public Integer yearOfPublication;
public Integer note;
public String cover;

public Game(String title, String description, Boolean publish,
String testContent, String developerStudio, String editor,
Integer yearOfPublication, Integer note, String cover) {
this.title=title;
this.description=description;
this.publish = publish;
this.testContent=testContent;
this.developerStudio=developerStudio;
this.editor=editor;
this.yearOfPublication = yearOfPublication;
this.note = note;
this.cover = cover;
}

}
Voilà une première étape de faite.

Mais avant de pouvoir tester cette chose, codons justement un test unitaire de la classe de persistance et de sa DAO, géré par le framework.

Créons donc une classe de test dans le répertoire de source test et nommons le EntitiesTest:
Notre petite classe est destinée à tester la persistance de nos entitée:

public class EntitiesTest extends UnitTest {

  @Test
  public void testGame(){
    Game game = new Game("MyGame", 
             "X360", 
             "My Description game", 
             true,
             "Test of the game",
             "My Studio", 
             "My Editor",
             2010,
             8,
             "public/images/x360/my_game/cover/mygame-cover.jpg");
    game.save();

    Long id = game.getId();
    assertNotNull(id);
  }
}

Ok,maintenant, testons notre test ;)  et lançons dans la sessions de commandes précédemment ouverte, la ligne suivante:

play test

nota: depuis Eclipse, via la bar d'icônes de debug, cliquez sur le bouton "Run Configurations...", et dans le groupe "Java applications", lancer "Test myplayapp".

Et ouvrez votre navigateur (Firefox, Chrome, Safari, IE ?) sur l'url http://localhost:9000/@tests !
Vous pouvez alors lancer le ou les tests que vous avez créés.

La page appraissant à l'écran vous propose de lancer les tests souhaités. choisissez EntitiesTest et cliquez sur "Start !".
Capture-06-play_-_tests_runner

figure 6 - Lancement des tests unitaires via l'interface Web de Play!

Le test choisi déroulé, le résultat de celui-ci apparait dans la même page:
Capture-07-play_-_tests_runner

figure 7 - Résultat du test unitaire exécuté

Vous pouvez aussi choisir de lancer l'intégralité des tests unitaires proposés nativement par Play!, ainsi que vos tests "custom".
Pour cela rappelez la page des tests et cliquer sur le lien "select all" puis sur "Start !". Tous les tests natifs sont appelés, y compris un test via Sélénium vérifiant le bon affichage de la page d'accueil de l'application.

Capture-08-play_-_tests_runner

figure 8 - Tous les tests ont été lancés et exécutés avec succès
Conclusion
Nous voilà avec les prémices d'une belle application Play! Nous avons découvert a travars ces premiers pas, la richesse technique et la complétude proposées par ce fabuleux framework Java. Nous découvrirons au prochain épisode notre première page bien à nous et la mis en place des modules CRUD et Security, natif eux aussi à Play! mais non activés par défaut.

Vous trouverez ci-joint, l'archive du code correspondant à cet article.

Click here to download:
myplayapp-part1.zap (262 KB)

  • PHP framework on the go...

    As I have already mention it, I am working on a personal project of a PHP framework.
    Plubished to the world through my Github account, I am building a sample project named "Games", or "Games Request" depends which templates you have selected. This is not a game, but a simple CMS sample. Actually only Font-Side is "runnable".
    A Back-Office side will raise from foundation soon. But some basic module need rework, and evolution, like persistance side.

    Anyway, if anyone want to contribute or comment the current work, please, go to http://github.com/mcgivrer/Games.

    In a near future, i will publish a demo on one of my website.

    have fun.
  • HTML5+CSS3 - start of the first experience !

    Discovering HTML5 and CSS3, I'm on the road of creating a small PHP framework (already seen here) to produce easily some WebSite in a fast and stardard respect way.

    Here is the first flight for my new framework, still buggy and have some weird behaviour, I'm to happy to show you the first visual picture of such piece of code :)

    Demo01

    Yes, the special effects on the mouse hover event are only CSS3 WebKit/Moz implemented version.  But it seems "wavy" ;)

    To be able to watch such demo, you need Last versions of Firefox (3.6.x or minefield version) and Google Chrome (Chromium nightly build or last Chrome)

    Hope to be able to produce soon better code with better effects !
  • My first Hobo application: My Library

    Hello, just as I have published the previous article about Hobo, discovering the full featured rails over layer framework, I can't wait to publish my first test: creating a very simple Web Application to manage a library.

    The first step is just to provide an interface to list all my books
    So please, follow the guide !
    Installation of the framework
    Just run the following command in your prefered terminal (gnome-terminal for example in Ubuntu):
     sudo gem install rails
     sudo gem install hobo
     sudo gem install sqlite3-ruby -v=1.2.3
     sudo apt-get install sqlite3
    First App
    Now we are going to create our first Hobo application
     hobo MyLibrary
    focus in the just create app directory
     cd MyLibrary
    And now create our first datamodel :  a book modelisation
     script/generate hobo_model_resource book title:string author:string year:integer resume:text note:integer
    now, we are going to create this model persistence into the default sqlite3  database
     script/generate hobo_migration 
    (choose the 'm' option)
    Ok, done.  now run the rails server (WebBrick):
     script/server
    browser on http://localhost:3000/
    Look at the title of the application :"My Library" !  Just because we call our project "MyLibrary" (without any space), Hobo kindly titled our welcome page with a beautiful "My Library" in a plain old good english. 
    Identify yourself by creating the first user account which will act as administrator for this new application.
    And now start playing with your books collection !
    1. your first connection to "My Library"
    Hobo_01_first_start
    2. The welcome page (also modifiable 
    Hobo_02_default_welcome_page
    3. Let see our books collection
    Hobo_03_books_page
    4. Go and create our first book in our collection
    Hobo_04_book_default_creation_
    5. Fill all the fields, and "Create Book"
    Hobo_05_first_book
    6. and it's done, the first book is ready to be parsed
    Hobo_06_book_just_created
    Yes I am impressed to discover how the Hobo dev team has been very careful with all details.
    The new Hobo player.
  • A new personal project

    To enhanced my knowledge on PHP5 and the MVC pattern, I've just started a brand new framework project to be able to develop quickly some PHP appliction with the following input requirements:

    • Internationalization (i18n)
    • Themes management
    • Ajax compliant (to respect the Web 2.0 paradigm :)
    • User authentication & authorization
    • Model Driven Development with some code generator
    • Database version and migration management


    My goal is to try to develop some similar functionalities in my PHP framework like in the RAILS framework (yes, some modesty is good sometimes;)

    See you soon for some prototype, a web e-commerce site with all modern technologies.

    Edit: You can find some alpha code on the http://code.google.com/p/os-emarket/ site.