Пример #1
0
  @Test
  public void testThatChangeToCoreObjectChangesHash() throws Exception {
    // Get starting Hash
    StateService svc = StateService.getInstance();
    String hash = svc.getCurrentHash(CoreObjectType.ITEM);

    // Create a new item, with same attributes.
    SalesItem initialItem = CoreObjectService.getInstance().getAllItems().get(0);
    SalesItem item = new SalesItem();
    item.token = initialItem.token;
    item.name = "Cheezbureger";
    item.category = 1;
    item.clazz = "com.openpos.salesitem";
    item.unitPrice = new BigDecimal(19.99);
    item.category = 1;
    item.setId(1);
    List<SalesItem> items = new ArrayList<>();
    items.add(item);

    // update the state with same object, make sure hash doesn't change
    EventService.getInstance().postEvent(new NewProgramState(CoreObjectType.ITEM, items));
    Thread.sleep(150);
    assertEquals(hash, svc.getCurrentHash(CoreObjectType.ITEM));

    // Change one attribute, and make sure hash changes.
    items.clear();
    item.name = "Burger";

    // update the state with same object, make sure hash doesn't change
    EventService.getInstance().postEvent(new NewProgramState(CoreObjectType.ITEM, items));
    Thread.sleep(150);
    assertNotEquals(hash, svc.getCurrentHash(CoreObjectType.ITEM));

    // Test that changing a non-serialized field doesn't cause update.
    // Change one attribute, and make sure hash changes.
    items.clear();
    item.name = "Cheezbureger";
    item.client = 33;
    items.add(item);
    // update the state with same object, make sure hash doesn't change
    EventService.getInstance().postEvent(new NewProgramState(CoreObjectType.ITEM, items));
    Thread.sleep(190);
    assertEquals(hash, svc.getCurrentHash(CoreObjectType.ITEM));
  }