コード例 #1
0
ファイル: Bootstrap.java プロジェクト: melodyb/OpenBook
 public static void hashPasswords() {
   List<User> users = User.findAll();
   for (User u : users) {
     u.password = Crypto.passwordHash(u.password);
     u.save();
   }
 }
コード例 #2
0
ファイル: BasicTest.java プロジェクト: Tri125/Yade
  @Test
  public void useTheCommentsRelation() {
    // Create a new user and save it
    User bob = new User("*****@*****.**", "secret", "Bob").save();

    // Create a new post
    Post bobPost = new Post(bob, "My first post", "Hello world").save();

    // Post a first comment
    bobPost.addComment("Jeff", "Nice post");
    bobPost.addComment("Tom", "I knew that !");

    // Count things
    assertEquals(1, User.count());
    assertEquals(1, Post.count());
    assertEquals(2, Comment.count());

    // Retrieve Bob's post
    bobPost = Post.find("byAuthor", bob).first();
    assertNotNull(bobPost);

    // Navigate to comments
    assertEquals(2, bobPost.comments.size());
    assertEquals("Jeff", bobPost.comments.get(0).author);

    // Delete the post
    bobPost.delete();

    // Check that all comments have been deleted
    assertEquals(1, User.count());
    assertEquals(0, Post.count());
    assertEquals(0, Post.count());
    assertEquals(0, Comment.count());
  }
コード例 #3
0
 @Test
 public void findRepostByUsers_Entity_複数_00() {
   User usr1 = User.findBySerialCode("usr-goro").first();
   User usr2 = User.findBySerialCode("usr-jiro").first();
   List<RepostBase> lst = RepostBase.findRepostByUsers(usr1, usr2).fetch();
   assertThat(lst.size(), is(9));
   // DBからの取得リストの並び保証なし
 }
コード例 #4
0
 @Test
 public void findRepostByUsers_Entity_複数_投稿者_00() {
   User usr1 = User.findBySerialCode("usr-goro").first();
   User usr2 = User.findBySerialCode("usr-jiro").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst = RepostBase.findRepostByUsers(usr1, usr2).contributor(acnt).fetch();
   assertThat(lst.size(), is(5));
   // DBからの取得リストの並び保証なし
 }
コード例 #5
0
ファイル: BasicTest.java プロジェクト: Tri125/Yade
  @Test
  public void tryConnectAsUser() {
    // Create a new user and save it
    new User("*****@*****.**", "secret", "Bob").save();

    // Test
    assertNotNull(User.connect("*****@*****.**", "secret"));
    assertNull(User.connect("*****@*****.**", "badpassword"));
    assertNull(User.connect("*****@*****.**", "secret"));
  }
コード例 #6
0
ファイル: TopicTest.java プロジェクト: ALT-F4/Expleo
 @Test
 public void newTopic() {
   Forum test = new Forum("Test", "Yop");
   User guillaume = User.find("byName", "Guillaume").first();
   test.newTopic(guillaume, "Hello", "Yop ...");
   assertEquals(2L, (long) guillaume.getTopicsCount());
   assertEquals(1, test.topics.size());
   assertEquals(1, test.getTopicsCount());
   assertEquals(5, Topic.count());
 }
コード例 #7
0
ファイル: TopicTest.java プロジェクト: ALT-F4/Expleo
 @Test
 public void testCascadeDelete() {
   Forum help = Forum.find("byName", "Play help").first();
   assertEquals(4, Topic.count());
   assertEquals(7, Post.count());
   help.delete();
   assertEquals(1, Topic.count());
   assertEquals(1, Post.count());
   User guillaume = User.find("byName", "Guillaume").first();
   assertEquals(0L, (long) guillaume.getTopicsCount());
 }
コード例 #8
0
 @Test
 public void findRepostByUsers_Entity_複数_投稿者_降順_00() {
   User usr1 = User.findBySerialCode("usr-goro").first();
   User usr2 = User.findBySerialCode("usr-jiro").first();
   Account acnt = Account.findByLoginName("goro_san").first();
   List<RepostBase> lst =
       RepostBase.findRepostByUsers(usr1, usr2)
           .contributor(acnt)
           .orderBy(RepostBase.OrderBy.DATE_OF_REPOST_DESC)
           .fetch();
   assertThat(lst.size(), is(5));
   assertThat(lst.get(0).getItem().serialCode, is("usr-jiro"));
 }
コード例 #9
0
ファイル: Bootstrap.java プロジェクト: Tortel/cmsc345
  /** Method to be run at start */
  @SuppressWarnings("unused")
  public void doJob() {
    // Check if the database is empty
    if (User.count() == 0) {
      // The really handy YML file doesnt handle inheritance well
      // Fixtures.loadModels("data.yml");
      Physician bob = new Physician("*****@*****.**", "secret", "Bob", "Doctor").save();
      Physician george = new Physician("*****@*****.**", "secret", "George", "Test").save();
      Patient bill =
          new Patient(
                  "*****@*****.**",
                  "secret",
                  "Bill",
                  "Sick",
                  "123 Main Street",
                  "410-000-0000",
                  'M')
              .save();
      Patient harriet =
          new Patient(
                  "*****@*****.**",
                  "secret",
                  "Harriet",
                  "Blarg",
                  "124 Main Street",
                  "410-000-0001",
                  'F')
              .save();

      Exam exam1 = new Exam(bill, george, "Bill Sucks!", "Bob is awesome!", null).save();
      Exam exam2 = new Exam(harriet, bob, "Harriet is awesome!", "Bob is awesome!", null).save();
    }
  }
コード例 #10
0
 public void doJob() {
   // Check if the database is empty
   if (User.count() == 0) {
     // Initial data of the plateform
     Fixtures.load("initial-data.yml");
   }
 }
コード例 #11
0
ファイル: BasicTest.java プロジェクト: Tri125/Yade
  @Test
  public void createAndRetrieveUser() {
    // Create a new user and save it
    new User("*****@*****.**", "secret", "Bob").save();

    // Retrieve the user with e-mail address [email protected]
    User bob = User.find("byEmail", "*****@*****.**").first();

    // Test
    assertNotNull(bob);
    assertEquals("Bob", bob.fullname);
  }
コード例 #12
0
ファイル: Bootstrap.java プロジェクト: melodyb/OpenBook
  public static void initFriends() {
    List<User> users = User.findAll();
    for (User u : users) {
      u.friends.add(u);
      u.save();
    }
    User bob = User.findById(2L);
    User alice = User.findById(3L);
    User jeff = User.findById(4L);

    bob.friends.add(jeff);
    alice.friends.add(jeff);
    jeff.friends.add(bob);
    jeff.friends.add(alice);
    jeff.save();
  }
コード例 #13
0
ファイル: Bootstrap.java プロジェクト: melodyb/OpenBook
 public void doJob() throws FileNotFoundException, IOException {
   // Check if the database is empty
   if (User.count() == 0) {
     Fixtures.loadModels("default-data.yml"); // Default User
     // load in pictures
     Photo photo;
     String path = new java.io.File(".").getCanonicalPath() + "/public/images/";
     photo =
         Photos.initFileToPhoto(path + "GreenTaijitu.png", "By Chinneeb via Wikimedia Commons");
     peacePhotoID = photo.id;
     photo = Photos.initFileToPhoto(path + "default.png", "Default Profile Photo");
     defaultProfilePhotoID = photo.id;
     photo = Photos.initFileToPhoto(path + "headerBG.png", "Default Header Background Photo");
     defaultHeaderPhotoID = photo.id;
     photo =
         Photos.initFileToPhoto(path + "UT-Austin-Tower.jpg", "UT Austin via Wikimedia Commons");
     Fixtures.loadModels("skinTemplates.yml"); // initial data for skin templates
     Fixtures.loadModels("initial-data.yml"); // rest of the data
     hashPasswords();
     initFriends();
   }
 }
コード例 #14
0
 public void doJob() {
   // Check if the database is empty
   if (User.count() == 0) {
     Fixtures.loadModels("data.yml");
   }
 }