Search in sources :

Example 1 with SingleReferenceModel

use of com.canoo.dolphin.client.util.SingleReferenceModel in project dolphin-platform by canoo.

the class TestModelCreation method testWithSingleReferenceModel.

@Test
public void testWithSingleReferenceModel(@Mocked AbstractClientConnector connector) {
    final ClientModelStore clientModelStore = createClientModelStore(connector);
    final EventDispatcher dispatcher = createEventDispatcher(clientModelStore);
    final BeanRepository repository = createBeanRepository(clientModelStore, dispatcher);
    final BeanManager manager = createBeanManager(clientModelStore, repository, dispatcher);
    SingleReferenceModel model = manager.create(SingleReferenceModel.class);
    assertThat(model, notNullValue());
    assertThat(model.getReferenceProperty(), notNullValue());
    assertThat(model.getReferenceProperty().get(), nullValue());
    assertThat(repository.isManaged(model), is(true));
    List<ClientPresentationModel> dolphinModels = clientModelStore.findAllPresentationModelsByType(SingleReferenceModel.class.getName());
    assertThat(dolphinModels, hasSize(1));
    PresentationModel dolphinModel = dolphinModels.get(0);
    List<Attribute> attributes = dolphinModel.getAttributes();
    assertThat(attributes, containsInAnyOrder(allOf(hasProperty("propertyName", is("referenceProperty")), hasProperty("value", nullValue()), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_CLIENT)), hasProperty("qualifier", nullValue()))));
    List<ClientPresentationModel> classModels = clientModelStore.findAllPresentationModelsByType(PlatformRemotingConstants.DOLPHIN_BEAN);
    assertThat(classModels, contains(hasProperty("attributes", containsInAnyOrder(allOf(hasProperty("propertyName", is(PlatformRemotingConstants.JAVA_CLASS)), hasProperty("value", is(SingleReferenceModel.class.getName())), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is("referenceProperty")), hasProperty("value", is(DolphinBeanConverterFactory.FIELD_TYPE_DOLPHIN_BEAN)), hasProperty("qualifier", nullValue())), allOf(hasProperty("propertyName", is(RemotingConstants.SOURCE_SYSTEM)), hasProperty("value", is(RemotingConstants.SOURCE_SYSTEM_CLIENT)), hasProperty("qualifier", nullValue()))))));
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) SingleReferenceModel(com.canoo.dolphin.client.util.SingleReferenceModel) EventDispatcher(com.canoo.dp.impl.remoting.EventDispatcher) Attribute(com.canoo.dp.impl.remoting.legacy.core.Attribute) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) ClientModelStore(com.canoo.dp.impl.client.legacy.ClientModelStore) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.dolphin.client.util.AbstractDolphinBasedTest)

Example 2 with SingleReferenceModel

use of com.canoo.dolphin.client.util.SingleReferenceModel in project dolphin-platform by canoo.

the class TestModelDeletion method testWithSingleReferenceModel.

@Test
public void testWithSingleReferenceModel(@Mocked AbstractClientConnector connector) {
    final ClientModelStore clientModelStore = createClientModelStore(connector);
    final EventDispatcher dispatcher = createEventDispatcher(clientModelStore);
    final BeanRepository repository = createBeanRepository(clientModelStore, dispatcher);
    final BeanManager manager = createBeanManager(clientModelStore, repository, dispatcher);
    SingleReferenceModel model = manager.create(SingleReferenceModel.class);
    repository.delete(model);
    List<ClientPresentationModel> dolphinModels = clientModelStore.findAllPresentationModelsByType(SingleReferenceModel.class.getName());
    assertThat(dolphinModels, empty());
    Collection<ClientPresentationModel> allDolphinModels = clientModelStore.listPresentationModels();
    assertThat(allDolphinModels, hasSize(1));
    assertThat(repository.isManaged(model), is(false));
}
Also used : SingleReferenceModel(com.canoo.dolphin.client.util.SingleReferenceModel) EventDispatcher(com.canoo.dp.impl.remoting.EventDispatcher) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) ClientModelStore(com.canoo.dp.impl.client.legacy.ClientModelStore) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.dolphin.client.util.AbstractDolphinBasedTest)

Example 3 with SingleReferenceModel

use of com.canoo.dolphin.client.util.SingleReferenceModel in project dolphin-platform by canoo.

the class TestPropertyChange method testWithSingleReferenceModel.

@Test
public void testWithSingleReferenceModel(@Mocked AbstractClientConnector connector) {
    final ClientModelStore clientModelStore = createClientModelStore(connector);
    final EventDispatcher dispatcher = createEventDispatcher(clientModelStore);
    final BeanRepository repository = createBeanRepository(clientModelStore, dispatcher);
    final BeanManager manager = createBeanManager(clientModelStore, repository, dispatcher);
    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>() {

        @Override
        public void valueChanged(ValueChangeEvent<? extends SimpleTestModel> evt) {
            Assert.assertEquals(evt.getSource(), 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;
    model.getReferenceProperty().set(null);
    assertThat(results.listenerCalls, is(1));
    assertThat(results.newValue, nullValue());
    assertThat(results.oldValue, is(ref2));
    results.listenerCalls = 0;
    subscription.unsubscribe();
    model.getReferenceProperty().set(ref3);
    assertThat(results.listenerCalls, is(0));
    assertThat(results.newValue, nullValue());
    assertThat(results.oldValue, is(ref2));
}
Also used : SingleReferenceModel(com.canoo.dolphin.client.util.SingleReferenceModel) ValueChangeEvent(com.canoo.platform.remoting.ValueChangeEvent) EventDispatcher(com.canoo.dp.impl.remoting.EventDispatcher) ValueChangeListener(com.canoo.platform.remoting.ValueChangeListener) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) SimpleTestModel(com.canoo.dolphin.client.util.SimpleTestModel) Subscription(com.canoo.platform.core.functional.Subscription) ClientModelStore(com.canoo.dp.impl.client.legacy.ClientModelStore) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.dolphin.client.util.AbstractDolphinBasedTest)

Example 4 with SingleReferenceModel

use of com.canoo.dolphin.client.util.SingleReferenceModel in project dolphin-platform by canoo.

the class TestPropertyValue method testWithSingleReferenceModel.

@Test
public void testWithSingleReferenceModel(@Mocked AbstractClientConnector connector) {
    final ClientModelStore clientModelStore = createClientModelStore(connector);
    final EventDispatcher dispatcher = createEventDispatcher(clientModelStore);
    final BeanRepository repository = createBeanRepository(clientModelStore, dispatcher);
    final BeanManager manager = createBeanManager(clientModelStore, repository, dispatcher);
    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<ClientPresentationModel> refPMs = clientModelStore.findAllPresentationModelsByType(SimpleTestModel.class.getName());
    final PresentationModel ref1PM = "ref1_text".equals(refPMs.get(0).getAttribute("text").getValue()) ? refPMs.get(0) : refPMs.get(1);
    final PresentationModel ref2PM = "ref2_text".equals(refPMs.get(0).getAttribute("text").getValue()) ? refPMs.get(0) : refPMs.get(1);
    final SingleReferenceModel model = manager.create(SingleReferenceModel.class);
    final PresentationModel dolphinModel = clientModelStore.findAllPresentationModelsByType(SingleReferenceModel.class.getName()).get(0);
    final Attribute referenceAttribute = dolphinModel.getAttribute("referenceProperty");
    assertThat(referenceAttribute.getValue(), nullValue());
    model.getReferenceProperty().set(ref1);
    assertThat(referenceAttribute.getValue(), is((Object) ref1PM.getId()));
    assertThat(model.getReferenceProperty().get(), is(ref1));
    referenceAttribute.setValue(ref2PM.getId());
    assertThat(referenceAttribute.getValue(), is((Object) ref2PM.getId()));
    assertThat(model.getReferenceProperty().get(), is(ref2));
}
Also used : PresentationModel(com.canoo.dp.impl.remoting.legacy.core.PresentationModel) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) SingleReferenceModel(com.canoo.dolphin.client.util.SingleReferenceModel) EventDispatcher(com.canoo.dp.impl.remoting.EventDispatcher) Attribute(com.canoo.dp.impl.remoting.legacy.core.Attribute) BeanRepository(com.canoo.dp.impl.remoting.BeanRepository) SimpleTestModel(com.canoo.dolphin.client.util.SimpleTestModel) ClientPresentationModel(com.canoo.dp.impl.client.legacy.ClientPresentationModel) ClientModelStore(com.canoo.dp.impl.client.legacy.ClientModelStore) BeanManager(com.canoo.platform.remoting.BeanManager) Test(org.testng.annotations.Test) AbstractDolphinBasedTest(com.canoo.dolphin.client.util.AbstractDolphinBasedTest)

Aggregations

AbstractDolphinBasedTest (com.canoo.dolphin.client.util.AbstractDolphinBasedTest)4 SingleReferenceModel (com.canoo.dolphin.client.util.SingleReferenceModel)4 ClientModelStore (com.canoo.dp.impl.client.legacy.ClientModelStore)4 BeanRepository (com.canoo.dp.impl.remoting.BeanRepository)4 EventDispatcher (com.canoo.dp.impl.remoting.EventDispatcher)4 BeanManager (com.canoo.platform.remoting.BeanManager)4 Test (org.testng.annotations.Test)4 ClientPresentationModel (com.canoo.dp.impl.client.legacy.ClientPresentationModel)3 SimpleTestModel (com.canoo.dolphin.client.util.SimpleTestModel)2 Attribute (com.canoo.dp.impl.remoting.legacy.core.Attribute)2 PresentationModel (com.canoo.dp.impl.remoting.legacy.core.PresentationModel)2 Subscription (com.canoo.platform.core.functional.Subscription)1 ValueChangeEvent (com.canoo.platform.remoting.ValueChangeEvent)1 ValueChangeListener (com.canoo.platform.remoting.ValueChangeListener)1