Search in sources :

Example 21 with InternalIEntity

use of org.whole.lang.model.InternalIEntity in project whole by wholeplatform.

the class HistoryInvariantsTest method testModelCommands.

@Test
public void testModelCommands() {
    IEntityIterator<IEntity> i = IteratorFactory.descendantOrSelfIterator();
    i.reset(model);
    for (IEntity e : i) {
        ICommand cmd = ((InternalIEntity) e).wGetBindingCommand();
        Assert.assertTrue(cmd.getKind() == CommandKind.NULL);
        cmd = ((InternalIEntity) e).wGetLastCommand();
        Assert.assertTrue(cmd.getKind() == CommandKind.NULL);
    }
    performChanges(model);
    List<ICommand> changes = history.getUndoCommands();
    i = IteratorFactory.descendantOrSelfIterator();
    i.reset(model);
    for (IEntity e : i) {
        ICommand cmd = ((InternalIEntity) e).wGetBindingCommand();
        if (cmd.getKind() != CommandKind.NULL)
            Assert.assertTrue(changes.contains(cmd));
        cmd = ((InternalIEntity) e).wGetLastCommand();
        if (cmd.getKind() != CommandKind.NULL)
            Assert.assertTrue(changes.contains(cmd));
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) InternalIEntity(org.whole.lang.model.InternalIEntity) InternalIEntity(org.whole.lang.model.InternalIEntity) Test(org.junit.Test)

Example 22 with InternalIEntity

use of org.whole.lang.model.InternalIEntity in project whole by wholeplatform.

the class HistoryInvariantsTest method testClearHistory.

@Test
public void testClearHistory() {
    performChanges(model);
    IEntity model2 = EntityUtils.clone(model);
    history.clearHistory();
    Assert.assertTrue(history.getUndoCommands().isEmpty());
    IEntityIterator<IEntity> i = IteratorFactory.descendantOrSelfIterator();
    i.reset(model);
    for (IEntity e : i) {
        ICommand cmd = ((InternalIEntity) e).wGetBindingCommand();
        Assert.assertTrue(cmd.getKind() == CommandKind.NULL);
        cmd = ((InternalIEntity) e).wGetLastCommand();
        Assert.assertTrue(cmd.getKind() == CommandKind.NULL);
    }
    Assert.assertTrue(Matcher.match(model2, model));
}
Also used : IEntity(org.whole.lang.model.IEntity) InternalIEntity(org.whole.lang.model.InternalIEntity) InternalIEntity(org.whole.lang.model.InternalIEntity) Test(org.junit.Test)

Example 23 with InternalIEntity

use of org.whole.lang.model.InternalIEntity in project whole by wholeplatform.

the class HistoryInvariantsTest method testModelNullCommands.

@Test
public void testModelNullCommands() {
    IEntityIterator<IEntity> i = IteratorFactory.descendantOrSelfIterator();
    i.reset(model);
    for (IEntity e : i) {
        Assert.assertEquals(NullCommand.instance, ((InternalIEntity) e).wGetBindingCommand());
        Assert.assertEquals(NullCommand.instance, ((InternalIEntity) e).wGetLastCommand());
    }
}
Also used : IEntity(org.whole.lang.model.IEntity) InternalIEntity(org.whole.lang.model.InternalIEntity) Test(org.junit.Test)

Example 24 with InternalIEntity

use of org.whole.lang.model.InternalIEntity in project whole by wholeplatform.

the class HistoryInvariantsTest method testChangeOrder.

@Test
public void testChangeOrder() {
    IEntity e1 = model.getName();
    IEntity e2 = model.getNamespace();
    e1.wSetValue("newLangName");
    e2.wSetValue("newNamespace");
    Assert.assertTrue(((InternalIEntity) e1).wGetLastCommand().getExecutionTime() <= ((InternalIEntity) e2).wGetLastCommand().getExecutionTime());
}
Also used : IEntity(org.whole.lang.model.IEntity) InternalIEntity(org.whole.lang.model.InternalIEntity) Test(org.junit.Test)

Example 25 with InternalIEntity

use of org.whole.lang.model.InternalIEntity in project whole by wholeplatform.

the class LifecycleAPITest method testCommit.

@Test
public void testCommit() {
    ITransaction transaction = ReflectionFactory.getTransaction(model);
    IEntity e1 = model.wGet(0);
    IEntity e2 = model.wGet(3);
    transaction.begin();
    e1.wSetValue("newLangName");
    ICommand c1 = ((InternalIEntity) e1).wGetLastCommand();
    e2.wSetValue("newNamespace");
    ICommand c2 = ((InternalIEntity) e2).wGetLastCommand();
    String langName = e1.wStringValue();
    int size = history.getUndoSize();
    assertTrue(c1.getExecutionTime() <= c2.getExecutionTime());
    transaction.commit();
    assertEquals(e1.wStringValue(), langName);
    assertTrue(history.getUndoSize() < size);
    assertEquals(c1.getExecutionTime(), c2.getExecutionTime());
}
Also used : IEntity(org.whole.lang.model.IEntity) InternalIEntity(org.whole.lang.model.InternalIEntity) ICommand(org.whole.lang.commands.ICommand) InternalIEntity(org.whole.lang.model.InternalIEntity) Test(org.junit.Test)

Aggregations

InternalIEntity (org.whole.lang.model.InternalIEntity)25 IEntity (org.whole.lang.model.IEntity)19 Test (org.junit.Test)13 ICommand (org.whole.lang.commands.ICommand)6 IFragmentModel (org.whole.lang.model.IFragmentModel)2 FeatureDescriptor (org.whole.lang.reflect.FeatureDescriptor)2 Serializable (java.io.Serializable)1 Category (org.junit.experimental.categories.Category)1 ITransactionScope (org.whole.lang.bindings.ITransactionScope)1 QuantifierEnum (org.whole.lang.commons.model.QuantifierEnum)1 Variable (org.whole.lang.commons.model.Variable)1 SubstituteException (org.whole.lang.matchers.SubstituteException)1