/** Test of getPassword method, of class DatabaseConnectionInfo. */
 @Test
 public void testGetPassword() {
   System.out.println("getPassword");
   DatabaseConnectionInfo instance = new DatabaseConnectionInfo("url", "username", "password");
   String expResult = "password";
   String result = instance.getPassword();
   assertEquals(expResult, result);
 }
 /** Test of setPassword method, of class DatabaseConnectionInfo. */
 @Test
 public void testSetPassword() {
   System.out.println("setPassword");
   String password = "******";
   DatabaseConnectionInfo instance = new DatabaseConnectionInfo("url", "username", "password");
   instance.setPassword(password);
   String result = instance.getPassword();
   assertEquals(password, result);
 }
 /** Test of setUsername method, of class DatabaseConnectionInfo. */
 @Test
 public void testSetUsername() {
   System.out.println("setUsername");
   String username = "******";
   DatabaseConnectionInfo instance = new DatabaseConnectionInfo("url", "username", "password");
   instance.setUsername(username);
   String result = instance.getUsername();
   assertEquals(username, result);
 }
  /** Test of retrieveLast100 method, of class QuestionRepo. */
  @Test
  public void testRetrieveLast100() throws Exception {
    System.out.println("retrieveLast100");
    QuestionRepo repo = new QuestionRepo(DatabaseConnectionInfo.createDefault());
    List<QuestionEntity> questionList = repo.retrieveLast100();

    assertNotNull(questionList);
    assertTrue(questionList.size() >= 0);
    assertTrue(questionList.size() <= 100);
  }
  /** Test of syncQuestions method, of class SXDatabaseFacade. */
  @Test
  public void testSyncQuestions() {
    System.out.println("syncQuestions");
    List<Question> questionList = new ArrayList<Question>();

    List<String> tags = new ArrayList<String>();
    tags.add(".net");
    tags.add("mysql");

    SXUser u = new SXUser();
    u.setSXid(1);

    Question q = new Question();
    q.setQid(123);
    q.setPostedTimestamp(new Date());
    q.setqText("test question text 1");
    q.setqTitle("test question title 1");
    q.setAnswers(null);
    q.setAskedBy(u);
    // q.setTags(tags);
    questionList.add(q);

    q = new Question();
    q.setQid(456);
    q.setPostedTimestamp(new Date());
    q.setqText("test question text 2");
    q.setqTitle("test question title 2");
    q.setAnswers(null);
    q.setAskedBy(u);
    questionList.add(q);

    try {
      SXDatabaseFacade sxDB = new SXDatabaseFacade();
      int numAdded = sxDB.syncQuestions(questionList);
      assertTrue("not all questions were added", numAdded == questionList.size());

      // Now we need to clean up after ourselves
      QuestionRepo repo = new QuestionRepo(DatabaseConnectionInfo.createDefault());
      for (Question question : questionList) {
        if (repo.exists(question.getQid())) {
          repo.delete(question.getQid());
        }
      }
    } catch (SQLException ex) {
      fail("SQLException thrown");
    }
  }
  /** Test of the add, update, and delete methods of class QuestionRepo. */
  @Test
  public void testAddUpdateDelete() throws Exception {
    QuestionEntity q = new QuestionEntity();
    QuestionRepo repo = new QuestionRepo(DatabaseConnectionInfo.createDefault());

    /** *************** */
    /** ***** add ***** */
    /** *************** */
    System.out.println("add");

    q.setQid(123);
    q.setPostedByUserId(1);
    q.setPostedTimestamp(new Date());
    q.setTitle("DB Test Question Title");
    q.setText("DB Test Question body text");
    boolean rowAdded = repo.add(q);

    assertTrue("add - record was not added", rowAdded);

    /** *************** */
    /** *** update **** */
    /** *************** */
    System.out.println("update");

    q.setPostedByUserId(2);
    q.setPostedTimestamp(new Date());
    q.setTitle("DB Test Question Title 2");
    q.setText("DB Test Question body text 2");
    boolean rowUpdated = repo.update(q);

    assertTrue("update - record was not updated", rowUpdated);

    /** *************** */
    /** *** delete **** */
    /** *************** */
    System.out.println("delete");

    boolean rowDeleted = repo.delete(q);

    assertTrue("delete - no record deleted", rowDeleted);
    assertTrue("delete - qid was not reset", q.getQid() == 0);
  }