Search in sources :

Example 16 with ServerModelStore

use of com.canoo.dp.impl.server.legacy.ServerModelStore in project dolphin-platform by canoo.

the class TestObservableListSync method deletingMultipleElementAtEndAsUser_shouldAddElements.

// TODO: Enable once ObservableArrayList.sublist() was implemented completely
@Test(enabled = false)
public void deletingMultipleElementAtEndAsUser_shouldAddElements() {
    // given :
    final ServerModelStore serverModelStore = createServerModelStore();
    final BeanManager manager = createBeanManager(serverModelStore);
    final ListReferenceModel model = manager.create(ListReferenceModel.class);
    final PresentationModel sourceModel = serverModelStore.findAllPresentationModelsByType(ListReferenceModel.class.getName()).get(0);
    model.getPrimitiveList().addAll(Arrays.asList("1", "2", "3", "4", "5", "6"));
    removeAllPresentationModelsOfType(serverModelStore, PlatformRemotingConstants.LIST_SPLICE);
    // when :
    model.getPrimitiveList().subList(3, 6).clear();
    // then :
    final List<ServerPresentationModel> changes = serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.LIST_SPLICE);
    assertThat(changes, hasSize(1));
    final PresentationModel change = changes.get(0);
    assertThat(change.getAttribute("source").getValue(), allOf(instanceOf(String.class), is((Object) sourceModel.getId())));
    assertThat(change.getAttribute("attribute").getValue(), allOf(instanceOf(String.class), is((Object) "primitiveList")));
    assertThat(change.getAttribute("from").getValue(), allOf(instanceOf(Integer.class), is((Object) 3)));
    assertThat(change.getAttribute("to").getValue(), allOf(instanceOf(Integer.class), is((Object) 6)));
    assertThat(change.getAttribute("count").getValue(), allOf(instanceOf(Integer.class), is((Object) 0)));
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) ServerPresentationModel(com.canoo.dp.impl.server.legacy.ServerPresentationModel) ServerPresentationModel(com.canoo.dp.impl.server.legacy.ServerPresentationModel) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) ListReferenceModel(com.canoo.impl.server.util.ListReferenceModel) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Example 17 with ServerModelStore

use of com.canoo.dp.impl.server.legacy.ServerModelStore in project dolphin-platform by canoo.

the class TestObservableListSync method addingObjectElementAsUser_shouldAddElement.

// ////////////////////////////////////////////////////////////
// Adding, removing, and replacing all element types as user
// ////////////////////////////////////////////////////////////
@Test
public void addingObjectElementAsUser_shouldAddElement() {
    // given :
    final ServerModelStore serverModelStore = createServerModelStore();
    final BeanManager manager = createBeanManager(serverModelStore);
    final ListReferenceModel model = manager.create(ListReferenceModel.class);
    final PresentationModel sourceModel = serverModelStore.findAllPresentationModelsByType(ListReferenceModel.class.getName()).get(0);
    final SimpleTestModel object = manager.create(SimpleTestModel.class);
    final PresentationModel objectModel = serverModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName()).get(0);
    // when :
    model.getObjectList().add(object);
    // then :
    final List<ServerPresentationModel> changes = serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.LIST_SPLICE);
    assertThat(changes, hasSize(1));
    final PresentationModel change = changes.get(0);
    assertThat(change.getAttribute("source").getValue(), allOf(instanceOf(String.class), is((Object) sourceModel.getId())));
    assertThat(change.getAttribute("attribute").getValue(), allOf(instanceOf(String.class), is((Object) "objectList")));
    assertThat(change.getAttribute("from").getValue(), allOf(instanceOf(Integer.class), is((Object) 0)));
    assertThat(change.getAttribute("to").getValue(), allOf(instanceOf(Integer.class), is((Object) 0)));
    assertThat(change.getAttribute("count").getValue(), allOf(instanceOf(Integer.class), is((Object) 1)));
    assertThat(change.getAttribute("0").getValue(), allOf(instanceOf(String.class), is((Object) objectModel.getId())));
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) ServerPresentationModel(com.canoo.dp.impl.server.legacy.ServerPresentationModel) ServerPresentationModel(com.canoo.dp.impl.server.legacy.ServerPresentationModel) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) SimpleTestModel(com.canoo.impl.server.util.SimpleTestModel) ListReferenceModel(com.canoo.impl.server.util.ListReferenceModel) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Example 18 with ServerModelStore

use of com.canoo.dp.impl.server.legacy.ServerModelStore in project dolphin-platform by canoo.

the class TestPropertyChange method testWithAnnotatedSimpleModel.

@Test
public void testWithAnnotatedSimpleModel() {
    ServerModelStore serverModelStore = createServerModelStore();
    final BeanManager manager = createBeanManager(serverModelStore);
    final SimpleAnnotatedTestModel model = manager.create(SimpleAnnotatedTestModel.class);
    final ListerResults<String> results = new ListerResults<>();
    ValueChangeListener<String> myListener = new ValueChangeListener<String>() {

        @SuppressWarnings("unchecked")
        @Override
        public void valueChanged(ValueChangeEvent<? extends String> evt) {
            assertThat((Property<String>) evt.getSource(), is(model.getMyProperty()));
            results.newValue = evt.getNewValue();
            results.oldValue = evt.getOldValue();
            results.listenerCalls++;
        }
    };
    final Subscription subscription = model.getMyProperty().onChanged(myListener);
    assertThat(results.listenerCalls, is(0));
    assertThat(results.newValue, nullValue());
    assertThat(results.oldValue, nullValue());
    model.getMyProperty().set("Hallo Property");
    assertThat(results.listenerCalls, is(1));
    assertThat(results.newValue, is("Hallo Property"));
    assertThat(results.oldValue, nullValue());
    results.listenerCalls = 0;
    model.getMyProperty().set("Hallo Property2");
    assertThat(results.listenerCalls, is(1));
    assertThat(results.newValue, is("Hallo Property2"));
    assertThat(results.oldValue, is("Hallo Property"));
    results.listenerCalls = 0;
    subscription.unsubscribe();
    model.getMyProperty().set("Hallo Property3");
    assertThat(results.listenerCalls, is(0));
    assertThat(results.newValue, is("Hallo Property2"));
    assertThat(results.oldValue, is("Hallo Property"));
}
Also used : ValueChangeEvent(com.canoo.platform.remoting.ValueChangeEvent) ValueChangeListener(com.canoo.platform.remoting.ValueChangeListener) SimpleAnnotatedTestModel(com.canoo.impl.server.util.SimpleAnnotatedTestModel) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) Subscription(com.canoo.platform.core.functional.Subscription) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Example 19 with ServerModelStore

use of com.canoo.dp.impl.server.legacy.ServerModelStore in project dolphin-platform by canoo.

the class TestPropertyChange method testWithSingleReferenceModel.

@Test
public void testWithSingleReferenceModel() {
    ServerModelStore serverModelStore = createServerModelStore();
    final BeanManager manager = createBeanManager(serverModelStore);
    final SimpleTestModel ref1 = manager.create(SimpleTestModel.class);
    final SimpleTestModel ref2 = manager.create(SimpleTestModel.class);
    final SimpleTestModel ref3 = manager.create(SimpleTestModel.class);
    final SingleReferenceModel model = manager.create(SingleReferenceModel.class);
    final ListerResults<SimpleTestModel> results = new ListerResults<>();
    final ValueChangeListener<SimpleTestModel> myListener = new ValueChangeListener<SimpleTestModel>() {

        @SuppressWarnings("unchecked")
        @Override
        public void valueChanged(ValueChangeEvent<? extends SimpleTestModel> evt) {
            assertThat((Property<SimpleTestModel>) evt.getSource(), is(model.getReferenceProperty()));
            results.newValue = evt.getNewValue();
            results.oldValue = evt.getOldValue();
            results.listenerCalls++;
        }
    };
    final Subscription subscription = model.getReferenceProperty().onChanged(myListener);
    assertThat(results.listenerCalls, is(0));
    assertThat(results.newValue, nullValue());
    assertThat(results.oldValue, nullValue());
    model.getReferenceProperty().set(ref1);
    assertThat(results.listenerCalls, is(1));
    assertThat(results.newValue, is(ref1));
    assertThat(results.oldValue, nullValue());
    results.listenerCalls = 0;
    model.getReferenceProperty().set(ref2);
    assertThat(results.listenerCalls, is(1));
    assertThat(results.newValue, is(ref2));
    assertThat(results.oldValue, is(ref1));
    results.listenerCalls = 0;
    subscription.unsubscribe();
    model.getReferenceProperty().set(ref3);
    assertThat(results.listenerCalls, is(0));
    assertThat(results.newValue, is(ref2));
    assertThat(results.oldValue, is(ref1));
}
Also used : SingleReferenceModel(com.canoo.impl.server.util.SingleReferenceModel) ValueChangeEvent(com.canoo.platform.remoting.ValueChangeEvent) ValueChangeListener(com.canoo.platform.remoting.ValueChangeListener) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) SimpleTestModel(com.canoo.impl.server.util.SimpleTestModel) Subscription(com.canoo.platform.core.functional.Subscription) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Example 20 with ServerModelStore

use of com.canoo.dp.impl.server.legacy.ServerModelStore in project dolphin-platform by canoo.

the class TestPropertyChange method testWithInheritedModel.

@Test
public void testWithInheritedModel() {
    ServerModelStore serverModelStore = createServerModelStore();
    final BeanManager manager = createBeanManager(serverModelStore);
    final ChildModel model = manager.create(ChildModel.class);
    final ListerResults<String> childResults = new ListerResults<>();
    ValueChangeListener<String> childListener = new ValueChangeListener<String>() {

        @SuppressWarnings("unchecked")
        @Override
        public void valueChanged(ValueChangeEvent<? extends String> evt) {
            assertThat((Property<String>) evt.getSource(), is(model.getChildProperty()));
            childResults.newValue = evt.getNewValue();
            childResults.oldValue = evt.getOldValue();
            childResults.listenerCalls++;
        }
    };
    final ListerResults<String> parentResults = new ListerResults<>();
    ValueChangeListener<String> parentListener = new ValueChangeListener<String>() {

        @SuppressWarnings("unchecked")
        @Override
        public void valueChanged(ValueChangeEvent<? extends String> evt) {
            assertThat((Property<String>) evt.getSource(), is(model.getParentProperty()));
            parentResults.newValue = evt.getNewValue();
            parentResults.oldValue = evt.getOldValue();
            parentResults.listenerCalls++;
        }
    };
    model.getChildProperty().onChanged(childListener);
    model.getParentProperty().onChanged(parentListener);
    assertThat(childResults.listenerCalls, is(0));
    assertThat(childResults.newValue, nullValue());
    assertThat(childResults.oldValue, nullValue());
    assertThat(parentResults.listenerCalls, is(0));
    assertThat(parentResults.newValue, nullValue());
    assertThat(parentResults.oldValue, nullValue());
    model.getChildProperty().set("Hallo Property");
    assertThat(childResults.listenerCalls, is(1));
    assertThat(childResults.newValue, is("Hallo Property"));
    assertThat(childResults.oldValue, nullValue());
    assertThat(parentResults.listenerCalls, is(0));
    assertThat(parentResults.newValue, nullValue());
    assertThat(parentResults.oldValue, nullValue());
    childResults.listenerCalls = 0;
    childResults.newValue = null;
    childResults.oldValue = null;
    model.getParentProperty().set("Hallo Property2");
    assertThat(childResults.listenerCalls, is(0));
    assertThat(childResults.newValue, nullValue());
    assertThat(childResults.oldValue, nullValue());
    assertThat(parentResults.listenerCalls, is(1));
    assertThat(parentResults.newValue, is("Hallo Property2"));
    assertThat(parentResults.oldValue, nullValue());
}
Also used : ValueChangeEvent(com.canoo.platform.remoting.ValueChangeEvent) ValueChangeListener(com.canoo.platform.remoting.ValueChangeListener) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) ChildModel(com.canoo.impl.server.util.ChildModel) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Aggregations

ServerModelStore (com.canoo.dp.impl.server.legacy.ServerModelStore)103 Test (org.testng.annotations.Test)100 AbstractDolphinBasedTest (com.canoo.impl.server.util.AbstractDolphinBasedTest)97 BeanManager (com.canoo.platform.remoting.BeanManager)91 ServerPresentationModel (com.canoo.dp.impl.server.legacy.ServerPresentationModel)88 PresentationModel (com.canoo.dp.impl.remoting.legacy.core.PresentationModel)66 ListReferenceModel (com.canoo.impl.server.util.ListReferenceModel)65 SimpleTestModel (com.canoo.impl.server.util.SimpleTestModel)18 BeanRepository (com.canoo.dp.impl.remoting.BeanRepository)14 EventDispatcher (com.canoo.dp.impl.remoting.EventDispatcher)14 Attribute (com.canoo.dp.impl.remoting.legacy.core.Attribute)8 ServerAttribute (com.canoo.dp.impl.server.legacy.ServerAttribute)7 ServerPresentationModelBuilder (com.canoo.dp.impl.server.model.ServerPresentationModelBuilder)5 SimpleAnnotatedTestModel (com.canoo.impl.server.util.SimpleAnnotatedTestModel)5 Command (com.canoo.dp.impl.remoting.legacy.communication.Command)4 ChildModel (com.canoo.impl.server.util.ChildModel)4 SingleReferenceModel (com.canoo.impl.server.util.SingleReferenceModel)4 ValueChangeEvent (com.canoo.platform.remoting.ValueChangeEvent)4 ValueChangeListener (com.canoo.platform.remoting.ValueChangeListener)4 Subscription (com.canoo.platform.core.functional.Subscription)3