<commit_before>package edu.cmu.sv.ws.ssnoc.data.dao;

import edu.cmu.sv.ws.ssnoc.common.utils.ConverterUtils;
import edu.cmu.sv.ws.ssnoc.data.util.DBUtils;
import edu.cmu.sv.ws.ssnoc.dto.Message;
import edu.cmu.sv.ws.ssnoc.dto.User;
import edu.cmu.sv.ws.ssnoc.rest.MessagesService;
import edu.cmu.sv.ws.ssnoc.rest.UserService;
import junit.framework.TestCase;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class MessageDAOImplTest extends TestCase {

    public void setUp() throws Exception {
        super.setUp();
        File file = new File(System.getProperty("user.home") + "/h2db.mv.db");
        File file2 = new File(System.getProperty("user.home") + "/h2db.mv.db.backup");

        if (!file2.exists()) {
            file.renameTo(file2);
        } else {
            file2.delete();
            file.renameTo(file2);
        }
    }

    public void tearDown() throws Exception {
        File file = new File(System.getProperty("user.home") + "/h2db.mv.db");
        File file2 = new File(System.getProperty("user.home") + "/h2db.mv.db.backup");

        file.delete();
        file2.renameTo(file);
    }

    public void testCanSavePubicMessage() throws Exception {
        DBUtils.initializeDatabase();

        UserService us = new UserService();
        User u = new User();
        u.setUserName("demo");
        u.setPassword("<PASSWORD>");
        us.addUser(u);

        Message message = new Message();
        message.setContent("test");
        message.setAuthor("demo");
        message.setPublic(true);
        message.setTimestamp("1970-01-01 12:00:00");

        DAOFactory.getInstance().getMessageDAO().save(ConverterUtils.convert(message));

        MessagesService mss = new MessagesService();
        List<Message> ret = mss.getWallPosts();
        List<String> contents = new ArrayList<String>();
        for (Message m : ret) {
            contents.add(m.getContent());
        }
        boolean passed = false;
        for (String content : contents) {
            if (content.equals("test")) {
                passed = true;
                break;
            }<commit_msg>added test case for null wall messages<commit_after>package edu.cmu.sv.ws.ssnoc.data.dao;

import edu.cmu.sv.ws.ssnoc.common.utils.ConverterUtils;
import edu.cmu.sv.ws.ssnoc.data.util.DBUtils;
import edu.cmu.sv.ws.ssnoc.dto.Message;
import edu.cmu.sv.ws.ssnoc.dto.User;
import edu.cmu.sv.ws.ssnoc.rest.MessagesService;
import edu.cmu.sv.ws.ssnoc.rest.UserService;
import junit.framework.TestCase;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class MessageDAOImplTest extends TestCase {

    public void setUp() throws Exception {
        super.setUp();
        File file = new File(System.getProperty("user.home") + "/h2db.mv.db");
        File file2 = new File(System.getProperty("user.home") + "/h2db.mv.db.backup");

        if (!file2.exists()) {
            file.renameTo(file2);
        } else {
            file2.delete();
            file.renameTo(file2);
        }
    }

    public void tearDown() throws Exception {
        File file = new File(System.getProperty("user.home") + "/h2db.mv.db");
        File file2 = new File(System.getProperty("user.home") + "/h2db.mv.db.backup");

        file.delete();
        file2.renameTo(file);
    }

    public void testCantSaveNullWallPost() throws Exception {
        DBUtils.initializeDatabase();

        UserService us = new UserService();
        User u = new User();
        u.setUserName("demo");
        u.setPassword("<PASSWORD>");
        us.addUser(u);

        DAOFactory.getInstance().getMessageDAO().save(null);

        MessagesService mss = new MessagesService();
        List<Message> ret = mss.getWallPosts();

        assertEquals(ret.size(), 0);
    }

    public void testCanSavePubicMessage() throws Exception {
        DBUtils.initializeDatabase();

        UserService us = new UserService();
        User u = new User();
        u.setUserName("demo");
        u.setPassword("<PASSWORD>");
        us.addUser(u);

        Message message = new Message();
        message.setContent("test");
        message.setAuthor("demo");
        message.setPublic(true);
        message.setTimestamp("1970-01-01 12:00:00");

        DAOFactory.getInstance().getMessageDAO().save(ConverterUtils.convert(message));

        MessagesService mss = new MessagesService();
        List<Message> ret = mss.getWallPosts();
        List<String> contents = new ArrayList<String>();
        for (Message m : ret) {
            contents.add(m.getContent());
        }
        boolean passed = false;
        for (String content : contents) {
            if (content.equals("test")) {
                passed = true;
                break;
            }
{'fraction_non_alphanumeric': 0.13834900731452457, 'fraction_numerical': 0.010658307210031349, 'mean_word_length': 2.463096960926194, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5451205', 'n_tokens_mistral': 1498, 'n_tokens_neox': 1477, 'n_words': 275}