Search in sources :

Example 1 with SimpleTestModel

use of com.canoo.impl.server.util.SimpleTestModel in project dolphin-platform by canoo.

the class TestObservableListSync method addingObjectElementFromserverModelStore_shouldAddElement.

// /////////////////////////////////////////////////////////////////
// Adding, removing, and replacing all element types from dolphin
// /////////////////////////////////////////////////////////////////
@Test
public void addingObjectElementFromserverModelStore_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 PresentationModel classDescription = serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.DOLPHIN_BEAN).get(0);
    classDescription.getAttribute("objectList").setValue(DolphinBeanConverterFactory.FIELD_TYPE_DOLPHIN_BEAN);
    final SimpleTestModel object = manager.create(SimpleTestModel.class);
    final PresentationModel objectModel = serverModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName()).get(0);
    // when :
    new PresentationModelBuilder(serverModelStore, PlatformRemotingConstants.LIST_SPLICE).withAttribute("source", sourceModel.getId()).withAttribute("attribute", "objectList").withAttribute("from", 0).withAttribute("to", 0).withAttribute("count", 1).withAttribute("0", objectModel.getId()).create();
    // then :
    assertThat(model.getObjectList(), is(Collections.singletonList(object)));
    assertThat(serverModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.LIST_SPLICE), empty());
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) 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 2 with SimpleTestModel

use of com.canoo.impl.server.util.SimpleTestModel 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 3 with SimpleTestModel

use of com.canoo.impl.server.util.SimpleTestModel 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 4 with SimpleTestModel

use of com.canoo.impl.server.util.SimpleTestModel in project dolphin-platform by canoo.

the class TestPropertyValue method testWithSingleReferenceModel.

@Test
public void testWithSingleReferenceModel() {
    final ServerModelStore serverModelStore = createServerModelStore();
    final BeanManager manager = createBeanManager(serverModelStore);
    final SimpleTestModel ref1 = manager.create(SimpleTestModel.class);
    ref1.getTextProperty().set("ref1_text");
    final SimpleTestModel ref2 = manager.create(SimpleTestModel.class);
    ref2.getTextProperty().set("ref2_text");
    final List<ServerPresentationModel> refPMs = serverModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName());
    final ServerPresentationModel ref1PM = "ref1_text".equals(refPMs.get(0).getAttribute("text").getValue()) ? refPMs.get(0) : refPMs.get(1);
    final ServerPresentationModel ref2PM = "ref2_text".equals(refPMs.get(0).getAttribute("text").getValue()) ? refPMs.get(0) : refPMs.get(1);
    final SingleReferenceModel model = manager.create(SingleReferenceModel.class);
    final ServerPresentationModel dolphinModel = serverModelStore.findAllPresentationModelsByType(SingleReferenceModel.class.getName()).get(0);
    final Attribute referenceAttribute = dolphinModel.getAttribute("referenceProperty");
    assertThat(referenceAttribute.getValue(), nullValue());
    model.getReferenceProperty().set(ref1);
    assertThat((String) referenceAttribute.getValue(), is(ref1PM.getId()));
    assertThat(model.getReferenceProperty().get(), is(ref1));
    referenceAttribute.setValue(ref2PM.getId());
    assertThat((String) referenceAttribute.getValue(), is(ref2PM.getId()));
    assertThat(model.getReferenceProperty().get(), is(ref2));
}
Also used : ServerPresentationModel(com.canoo.dp.impl.server.legacy.ServerPresentationModel) SingleReferenceModel(com.canoo.impl.server.util.SingleReferenceModel) Attribute(com.canoo.dp.impl.remoting.legacy.core.Attribute) ServerModelStore(com.canoo.dp.impl.server.legacy.ServerModelStore) SimpleTestModel(com.canoo.impl.server.util.SimpleTestModel) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.impl.server.util.AbstractDolphinBasedTest)

Example 5 with SimpleTestModel

use of com.canoo.impl.server.util.SimpleTestModel in project dolphin-platform by canoo.

the class TestObservableListSync method deletingObjectElementAsUser_shouldDeleteElement.

@Test
public void deletingObjectElementAsUser_shouldDeleteElement() {
    // 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);
    model.getObjectList().add(object);
    removeAllPresentationModelsOfType(serverModelStore, PlatformRemotingConstants.LIST_SPLICE);
    // when :
    model.getObjectList().remove(0);
    // 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) 1)));
    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) 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)

Aggregations

ServerModelStore (com.canoo.dp.impl.server.legacy.ServerModelStore)18 AbstractDolphinBasedTest (com.canoo.impl.server.util.AbstractDolphinBasedTest)18 SimpleTestModel (com.canoo.impl.server.util.SimpleTestModel)18 BeanManager (com.canoo.platform.remoting.BeanManager)18 Test (org.testng.annotations.Test)18 ServerPresentationModel (com.canoo.dp.impl.server.legacy.ServerPresentationModel)15 PresentationModel (com.canoo.dp.impl.remoting.legacy.core.PresentationModel)10 ListReferenceModel (com.canoo.impl.server.util.ListReferenceModel)10 BeanRepository (com.canoo.dp.impl.remoting.BeanRepository)3 EventDispatcher (com.canoo.dp.impl.remoting.EventDispatcher)3 Attribute (com.canoo.dp.impl.remoting.legacy.core.Attribute)2 SingleReferenceModel (com.canoo.impl.server.util.SingleReferenceModel)2 Subscription (com.canoo.platform.core.functional.Subscription)2 ValueChangeEvent (com.canoo.platform.remoting.ValueChangeEvent)2 ValueChangeListener (com.canoo.platform.remoting.ValueChangeListener)2 ServerAttribute (com.canoo.dp.impl.server.legacy.ServerAttribute)1 SimpleAnnotatedTestModel (com.canoo.impl.server.util.SimpleAnnotatedTestModel)1