Ejemplo n.º 1
0
  @Test
  public void testGet() {
    // invalid request
    Response response = service.get(null);
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.get(new RequestBean<Long>(null, null));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.get(new RequestBean<Long>(null, new Long(1)));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.get(new RequestBean<Long>(new CredentialsBean(), new Long(1)));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.get(new RequestBean<Long>(new CredentialsBean("manager", "password"), null));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // valid request, not found
    response =
        service.get(
            new RequestBean<Long>(new CredentialsBean("manager", "password"), new Long(100)));
    assertNotNull(response);
    assertEquals(Response.Status.NOT_FOUND.getStatusCode(), response.getStatus());

    // valid request, invalid id
    response =
        service.get(new RequestBean<Long>(new CredentialsBean("manager", "password"), new Long(0)));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // valid request
    response =
        service.get(new RequestBean<Long>(new CredentialsBean("manager", "password"), new Long(1)));
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

    MenuItemBean menuItem = (MenuItemBean) response.getEntity();
    assertNotNull(menuItem);
  }
Ejemplo n.º 2
0
  @SuppressWarnings("unchecked")
  @Test
  public void testGetAllHidden() {
    // invalid request
    Response response = service.getAllHidden(null);
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.getAllHidden(new RequestBean<Object>(null, null));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.getAllHidden(new RequestBean<Object>(new CredentialsBean(), null));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // valid request but unauthorized
    response =
        service.getAllHidden(
            new RequestBean<Object>(new CredentialsBean("admin", "password"), null));
    assertNotNull(response);
    assertEquals(Response.Status.UNAUTHORIZED.getStatusCode(), response.getStatus());

    // valid request
    response =
        service.getAllHidden(
            new RequestBean<Object>(new CredentialsBean("manager", "password"), null));
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

    List<MenuItemBean> menuItems = (ArrayList<MenuItemBean>) response.getEntity();
    assertNotNull(menuItems);
    assertEquals(1, menuItems.size());
  }
Ejemplo n.º 3
0
  @Test
  public void testPost() {
    // invalid request
    Response response = service.post(null);
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.post(new RequestBean<MenuItemBean>(null, null));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.post(new RequestBean<MenuItemBean>(null, new MenuItemBean()));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response =
        service.post(new RequestBean<MenuItemBean>(new CredentialsBean(), new MenuItemBean()));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response =
        service.post(
            new RequestBean<MenuItemBean>(new CredentialsBean("manager", "password"), null));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // valid request, bad menu item data
    response =
        service.post(
            new RequestBean<MenuItemBean>(
                new CredentialsBean("manager", "password"), new MenuItemBean()));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // valid request
    MenuItemBean menuItem =
        new MenuItemBean(0L, "name", "description", 12.45, MenuItemCategory.SIDE);
    response =
        service.post(
            new RequestBean<MenuItemBean>(new CredentialsBean("manager", "password"), menuItem));
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

    MenuItemBean createdMenuItem = (MenuItemBean) response.getEntity();
    assertNotNull(createdMenuItem);
  }
Ejemplo n.º 4
0
  @Test
  public void testUnhide() {
    // invalid request
    Response response = service.unhide(null);
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.unhide(new RequestBean<Long>(null, null));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.unhide(new RequestBean<Long>(null, new Long(1)));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.unhide(new RequestBean<Long>(new CredentialsBean(), new Long(1)));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response =
        service.unhide(new RequestBean<Long>(new CredentialsBean("manager", "password"), null));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // valid request, invalid id
    response =
        service.unhide(
            new RequestBean<Long>(new CredentialsBean("manager", "password"), new Long(0)));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // valid request
    response =
        service.unhide(
            new RequestBean<Long>(new CredentialsBean("manager", "password"), new Long(7)));
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

    Boolean updated = (Boolean) response.getEntity();
    assertNotNull(updated);
    assertTrue(updated);
  }
Ejemplo n.º 5
0
 @Test
 public void insertMenus() throws CustomRuntimeException {
   MenuItem menuItem = new MenuItem().setAdmin(false).setName("menu1").setUrl("").setOrder(1);
   MenuItem submenu = new MenuItem().setAdmin(false).setName("submenu1").setUrl("").setOrder(1);
   MenuItem subsubmenu = new MenuItem().setAdmin(false).setName("submenu1").setUrl("").setOrder(1);
   submenu.getMenuItems().add(subsubmenu);
   submenu.getMenuItems().add(subsubmenu);
   submenu.getMenuItems().add(subsubmenu);
   subsubmenu
       .getMenuItems()
       .add(new MenuItem().setAdmin(false).setName("subsubmenu").setUrl("").setOrder(1));
   subsubmenu
       .getMenuItems()
       .add(new MenuItem().setAdmin(false).setName("subsubmenu").setUrl("").setOrder(2));
   subsubmenu
       .getMenuItems()
       .add(new MenuItem().setAdmin(false).setName("subsubmenu").setUrl("").setOrder(3));
   menuItem.getMenuItems().add(submenu.setName("submenu1").setOrder(1));
   menuItem.getMenuItems().add(submenu.setName("submenu2").setOrder(2));
   menuItem.getMenuItems().add(submenu.setName("submenu3").setOrder(3));
   menuItem.getMenuItems().add(submenu.setName("submenu4").setOrder(4));
   menuItem.getMenuItems().add(submenu.setName("submenu5").setOrder(5));
   MenuItem[] menus =
       new MenuItem[] {
         new MenuItem().setAdmin(true).setName("Scaffold").setUrl("/scaffold").setOrder(1),
         new MenuItem().setAdmin(true).setName("Article").setUrl("/article/edit").setOrder(2),
         new MenuItem().setAdmin(true).setName("Themes").setUrl("/themes").setOrder(3),
         new MenuItem()
             .setAdmin(true)
             .setName("Web Services")
             .setUrl("/webservices/admin")
             .setOrder(4),
         new MenuItem().setAdmin(true).setName("Navigation").setUrl("/navigation").setOrder(5),
         menuItem,
         new MenuItem(menuItem).setName("menu1").setOrder(2),
         new MenuItem(menuItem).setName("menu2").setOrder(3),
         new MenuItem(menuItem).setName("menu3").setOrder(4),
         new MenuItem(menuItem).setName("menu4").setOrder(5)
       };
   for (MenuItem menu : menus) {
     menuService.insert(menu);
   }
 }
Ejemplo n.º 6
0
  @Test
  public void testUpdate() {
    // invalid request
    Response response = service.post(null);
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.update(new RequestBean<MenuItemBean>(null, null));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response = service.update(new RequestBean<MenuItemBean>(null, new MenuItemBean()));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response =
        service.update(new RequestBean<MenuItemBean>(new CredentialsBean(), new MenuItemBean()));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // invalid request
    response =
        service.update(
            new RequestBean<MenuItemBean>(new CredentialsBean("manager", "password"), null));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // valid request, bad menu item data
    response =
        service.update(
            new RequestBean<MenuItemBean>(
                new CredentialsBean("manager", "password"), new MenuItemBean()));
    assertNotNull(response);
    assertEquals(Response.Status.BAD_REQUEST.getStatusCode(), response.getStatus());

    // valid request
    MenuItemBean oldMenuItem =
        new MenuItemBean(1L, "updated name", "updated description", 12.45, MenuItemCategory.SIDE);
    response =
        service.update(
            new RequestBean<MenuItemBean>(new CredentialsBean("manager", "password"), oldMenuItem));
    assertNotNull(response);
    assertEquals(Response.Status.OK.getStatusCode(), response.getStatus());

    Boolean updated = (Boolean) response.getEntity();
    assertNotNull(updated);
    assertTrue(updated);

    MenuItemBean updatedMenuItem =
        (MenuItemBean)
            service
                .get(new RequestBean<Long>(new CredentialsBean("manager", "password"), new Long(1)))
                .getEntity();
    assertNotNull(updatedMenuItem);

    assertEquals(oldMenuItem.getId(), updatedMenuItem.getId());
    assertEquals(oldMenuItem.getName(), updatedMenuItem.getName());
    assertEquals(oldMenuItem.getDescription(), updatedMenuItem.getDescription());
    assertEquals(0, Double.compare(oldMenuItem.getPrice(), updatedMenuItem.getPrice()));
    assertEquals(oldMenuItem.getItemCategory(), updatedMenuItem.getItemCategory());
  }
Ejemplo n.º 7
0
 @Override
 public void actionPerformed(ActionEvent e) {
   // TODO Auto-generated method stub
   service.menuAction(MainFrame.this, e.getActionCommand());
 }
Ejemplo n.º 8
0
public class MainFrame extends JFrame {

  private static final long serialVersionUID = 1L;
  static final int WIDTH = 800;
  static final int HEIGHT = 600;

  private ImagePanel panel;
  // private JScrollPane imageSp;
  private StatePanel statePanel;

  public ImagePanel getPanel() {
    return panel;
  }

  public void setPanel(ImagePanel panel) {
    this.panel = panel;
  }

  public StatePanel getStatePanel() {
    return statePanel;
  }

  public void setStatePanel(StatePanel statePanel) {
    this.statePanel = statePanel;
  }

  MenuService service = MenuService.getInstance();

  ActionListener menuListener =
      new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
          // TODO Auto-generated method stub
          service.menuAction(MainFrame.this, e.getActionCommand());
        }
      };

  public MainFrame() {

    super("Image Process");
    this.setSize(800, 600);
    this.setLocation(300, 50);

    this.createMenuBar();

    panel = new ImagePanel();
    // panel.setBorder(BorderFactory.createLineBorder(Color.BLACK));

    statePanel = new StatePanel();

    this.add(panel, BorderLayout.CENTER);
    this.add(statePanel, BorderLayout.SOUTH);

    this.setDefaultCloseOperation(EXIT_ON_CLOSE);
    this.setVisible(true);
  }

  public void createMenuBar() {

    JMenuBar menuBar = new JMenuBar();
    // string for menu
    String[] menuArr = {"File", "View", "Image", "BGRemove", "Neuro network", "Help"};
    // string for menu item
    String[][] menuItemArr = {
      {"Open", "Save", "Save as", "-", "Exit"},
      {"Zoom out", "Zoom in"},
      {"Undo", "Redo", "-", "Grayscale", "Resize", "Gaussian noise", "Extra line"},
      {"KNN setting", "KNN training", "KNN testing"},
      {"Gray thresholding", "Color thresholding"},
      {"Manual", "About"}
    };
    // create menu
    for (int i = 0; i < menuArr.length; i++) {

      JMenu menu = new JMenu(menuArr[i]);
      for (int j = 0; j < menuItemArr[i].length; j++) {
        // seperator
        if (menuItemArr[i][j].equals("-")) {
          menu.addSeparator();
        } else {
          JMenuItem menuItem = new JMenuItem(menuItemArr[i][j]);
          menuItem.addActionListener(menuListener);
          menu.add(menuItem);
        }
      }
      menuBar.add(menu);
    }

    this.setJMenuBar(menuBar);
  }
}