예제 #1
0
 /**
  * Test method for {@link
  * edu.depaul.se491.models.BaseModel#BaseModel(edu.depaul.se491.daos.DAOFactory,
  * edu.depaul.se491.beans.CredentialsBean)}.
  */
 @Test
 public void testBaseModel() {
   BaseModel model = new BaseModel(null, null);
   assertNotNull(model);
   assertNull(model.getResponseStatus());
   assertEquals("", model.getResponseMessage());
 }
예제 #2
0
  @Test
  public void testSetResponseMessageAndStatus() {
    BaseModel model = new BaseModel(null, null);

    model.setResponseMessage("message");
    assertNotNull(model.getResponseMessage());
    assertEquals("message", model.getResponseMessage());

    model.setResponseStatus(Response.Status.OK);
    assertNotNull(model.getResponseStatus());
    assertEquals(Response.Status.OK, model.getResponseStatus());

    model.setResponseAndMeessageForDBError(new SQLException("exception test"));
    assertNotNull(model.getResponseMessage());
    assertEquals(BaseModel.GENERIC_SERVER_ERR_MSG, model.getResponseMessage());
    assertNotNull(model.getResponseStatus());
    assertEquals(Response.Status.INTERNAL_SERVER_ERROR, model.getResponseStatus());
  }
예제 #3
0
 @Test
 public void testExceptions() {
   BaseModel model =
       new BaseModel(
           new TestDAOFactory(new ExceptionConnectionFactory()),
           new CredentialsBean("admin", "password"));
   assertNull(model.getLoggedinAccount());
   assertEquals(Response.Status.INTERNAL_SERVER_ERROR, model.getResponseStatus());
 }
예제 #4
0
  @Test
  public void testGetLoggedinAccount() {
    BaseModel model = new BaseModel(daoFactory, null);
    assertNull(model.getLoggedinAccount());
    assertEquals(Response.Status.BAD_REQUEST, model.getResponseStatus());

    model = new BaseModel(daoFactory, new CredentialsBean());
    assertNull(model.getLoggedinAccount());
    assertEquals(Response.Status.BAD_REQUEST, model.getResponseStatus());

    model = new BaseModel(daoFactory, new CredentialsBean("randomUsername", "password"));
    assertNull(model.getLoggedinAccount());
    assertEquals(Response.Status.NOT_FOUND, model.getResponseStatus());

    for (String username : new String[] {"admin", "manager", "employee1", "customerapp"}) {
      model = new BaseModel(daoFactory, new CredentialsBean(username, "wrongPassword"));
      assertNull(model.getLoggedinAccount());
      assertEquals(Response.Status.NOT_FOUND, model.getResponseStatus());

      model = new BaseModel(daoFactory, new CredentialsBean(username, "password"));
      assertNotNull(model.getLoggedinAccount());
    }
  }