Package com.rila.chat.dao.mongo

Examples of com.rila.chat.dao.mongo.MessagesHistoryMongo


 
  private static ApplicationContext context;
 
  @Bean
  public IMessagesHistoryMongo iMessagesHistoryMongo(){
    return new MessagesHistoryMongo();
  }
View Full Code Here


        .getCollection("historymessages");
    messagesCollection.drop();
  }

  public void insert10Messages() {
    MessagesHistoryMongo conect = new MessagesHistoryMongo();
    Statut statut = Statut.EN_LIGNE;
    Message message1 = new Message();
    message1.setMessage("comment vas-tu?");
    message1.setUserFrom(new User("benoit", statut, "192.168.1.1"));
    message1.setUserTo("florian");
    message1.setEvent(Event.ALL_CLIENTS);
    message1.setDate(new Date(1394743482).toString());

    conect.saveMessage(message1);

    Statut statut2 = Statut.ABSENT;
    Message message2 = new Message();
    message2.setMessage("bien et toi");
    message2.setUserFrom(new User("florian", statut2, "192.168.1.2"));
    message2.setUserTo("Benoit");
    message2.setEvent(Event.ONE_CLIENT);
    message2.setDate(new Date(1394829882).toString());
 

    conect.saveMessage(message2);

    Message message3 = new Message();
    message3.setMessage("cool raoul");
    message3.setUserFrom(new User("antho", statut, "192.168.1.3"));
    message3.setUserTo("All");
    message3.setEvent(Event.ALL_CLIENTS);
    message3.setDate(new Date(1394916282).toString());

    conect.saveMessage(message3);

    Message message4 = new Message();
    message4.setMessage("on se fait un mac DO");
    message4.setUserFrom(new User("benoit", statut, "192.168.1.1"));
    message4.setUserTo("florian");
    message4.setEvent(Event.ALL_CLIENTS);
    message4.setDate(new Date(1395002682).toString());

    conect.saveMessage(message4);

    Message message5 = new Message();
    message5.setMessage("ou un kebab");
    message5.setUserFrom(new User("florian", statut, "192.168.1.2"));
    message5.setUserTo("all");
    message5.setEvent(Event.ALL_CLIENTS);
    message5.setDate(new Date(1395089082).toString());

    conect.saveMessage(message5);

    Message message6 = new Message();
    message6.setMessage("pour moi mc do c'est cool!");
    message6.setUserFrom(new User("antho", statut, "192.168.1.3"));
    message6.setUserTo("all");
    message6.setEvent(Event.ALL_CLIENTS);
    message6.setDate(new Date(1395175482).toString());

    conect.saveMessage(message6);

    Message message7 = new Message();
    message7.setMessage("bon ben mc do");
    message7.setUserFrom(new User("florian", statut, "192.168.1.2"));
    message7.setUserTo("all");
    message7.setEvent(Event.ALL_CLIENTS);
    message7.setDate(new Date(1395261882).toString());

    conect.saveMessage(message7);

    Message message8 = new Message();
    message8.setMessage("on prend quelle voiture?");
    message8.setUserFrom(new User("florian", statut, "192.168.1.2"));
    message8.setUserTo("all");
    message8.setEvent(Event.ALL_CLIENTS);
    message8.setDate(new Date(1395348282).toString());

    conect.saveMessage(message8);

    Message message9 = new Message();
    message9.setMessage("la mienne c'est bon");
    message9.setUserFrom(new User("benoit", statut, "192.168.1.1"));
    message9.setUserTo("all");
    message9.setEvent(Event.ALL_CLIENTS);
    message9.setDate(new Date(1395434682).toString());
   
    conect.saveMessage(message9);

    Message message10 = new Message();
    message10.setMessage("allez go en B! on va les avoir");
    message10.setUserFrom(new User("florian", statut, "192.168.1.2"));
    message10.setUserTo("all");
    message10.setEvent(Event.ALL_CLIENTS);
    message10.setDate(new Date(1395521082).toString());
   
    conect.saveMessage(message10);
  }
View Full Code Here

    message1.setMessage("comment vas-tu?");
    message1.setUserFrom(new User("benoit", statut, "192.168.1.1"));
    message1.setUserTo("florian");
    message1.setEvent(Event.ALL_CLIENTS);
    message1.setDate(new Date().toString());
    MessagesHistoryMongo conect;
    conect = new MessagesHistoryMongo();
    conect.saveMessage(message1);

    // on test si on a bien le message ins�r�
    DBObject messageReturn = messagesCollection.findOne();
    Assert.assertNotNull(messageReturn)
  }
View Full Code Here

  public void testOnlyTenMessages() {
    this.dropCollection();
    // insertion de 10 messages
    this.insert10Messages();

    MessagesHistoryMongo conect = new MessagesHistoryMongo();

    DBCollection messagesCollection = chatDatabase.getCollection("historymessages");
   
    Long numberOfMessages = messagesCollection.count();
    DBCursor curs = messagesCollection.find();
    List<Message> messages = new ArrayList<>();
    while (curs.hasNext()) {
      DBObject o = curs.next();
      String test=o.get("message").toString();
      Gson gson = new Gson();
      Message message = gson.fromJson(test, Message.class);     
      messages.add(message);
    }
 
    Assert.assertEquals(new Long(10), numberOfMessages);
    Assert.assertEquals(new Date(1394743482).toString(),messages.get(0).getDate());
   
    Message message11 = new Message();
    message11.setMessage("un best OF!");
    message11.setUserFrom(new User("antho", Statut.EN_LIGNE, "192.168.1.3"));
    message11.setUserTo("all");
    message11.setEvent(Event.ALL_CLIENTS);
    message11.setDate(new Date(1395621082).toString());

    conect.saveMessage(message11);
    Long numberOfMessagesNew = messagesCollection.count();
    Assert.assertEquals(new Long(10), numberOfMessagesNew);
   
    DBCursor cursNew = messagesCollection.find();
    List<Message> messagesNew = new ArrayList<>();
View Full Code Here

  @Test
  public void getLastMessages() {
    this.dropCollection();
    // insertion de 10 messages
    this.insert10Messages();
    MessagesHistoryMongo conect = new MessagesHistoryMongo();
    Object messages = conect.getLastMessages();
    Assert.assertTrue(messages instanceof List<?>);
    @SuppressWarnings("unchecked")
    List<Message> messagesList = (List<Message>) messages;
    Assert.assertEquals(10, messagesList.size());
    Assert.assertTrue(messagesList.get(0) instanceof Message);
View Full Code Here

TOP

Related Classes of com.rila.chat.dao.mongo.MessagesHistoryMongo

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.