Beispiel #1
0
  @Test
  public void testHasPermission() {
    BaseModel model = new BaseModel(daoFactory, new CredentialsBean("admin", "password"));
    assertNotNull(model.getLoggedinAccount());

    for (String username : new String[] {"admin", "manager", "employee1", "customerapp"}) {
      model = new BaseModel(daoFactory, new CredentialsBean(username, "password"));
      assertNotNull(model.getLoggedinAccount());

      assertFalse(model.hasPermission(new AccountRole[] {}));

      assertTrue(model.hasPermission(new AccountRole[] {model.getLoggedinAccount().getRole()}));
    }
  }
Beispiel #2
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());
 }
Beispiel #3
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());
    }
  }