svnno****@sourc*****
svnno****@sourc*****
2008年 10月 10日 (金) 02:12:21 JST
Revision: 2014 http://svn.sourceforge.jp/cgi-bin/viewcvs.cgi?root=jiemamy&view=rev&rev=2014 Author: shin1 Date: 2008-10-10 02:12:21 +0900 (Fri, 10 Oct 2008) Log Message: ----------- バブリングの動作確認用のTestCase。…だったはずなんだけど、動作していない事が確認されてしまったたので、とりあえずFIXMEをつけてコミットさせて頂く。 Added Paths: ----------- artemis/trunk/org.jiemamy.event/src/test/java/org/jiemamy/core/model/RootModelTest.java -------------- next part -------------- Added: artemis/trunk/org.jiemamy.event/src/test/java/org/jiemamy/core/model/RootModelTest.java =================================================================== --- artemis/trunk/org.jiemamy.event/src/test/java/org/jiemamy/core/model/RootModelTest.java (rev 0) +++ artemis/trunk/org.jiemamy.event/src/test/java/org/jiemamy/core/model/RootModelTest.java 2008-10-09 17:12:21 UTC (rev 2014) @@ -0,0 +1,203 @@ +/* + * Copyright 2007-2008 MIYAMOTO Daisuke, jiemamy.org and the Others. + * Created on 2008/10/07 + * + * This file is part of Jiemamy. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, + * either express or implied. See the License for the specific language + * governing permissions and limitations under the License. + */ +package org.jiemamy.core.model; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.util.ArrayList; +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.jiemamy.core.S2FactoryStrategy; +import org.jiemamy.creator.JiemamyModelFactory; +import org.jiemamy.spec.event.ModelChangeEvent; +import org.jiemamy.spec.event.ObservableCollectionChangeEvent; +import org.jiemamy.spec.event.model.RootModelChangeListener; +import org.jiemamy.spec.event.model.RootModelChangeSupport; +import org.jiemamy.spec.event.model.node.TableModelChangeListener; +import org.jiemamy.spec.event.model.node.TableModelChangeSupport; +import org.jiemamy.spec.exception.TooManyElementsException; +import org.jiemamy.spec.model.ColumnModel; +import org.jiemamy.spec.model.DomainModel; +import org.jiemamy.spec.model.RootModel; +import org.jiemamy.spec.model.connection.AbstractConnectionModel; +import org.jiemamy.spec.model.constraint.CheckConstraintModel; +import org.jiemamy.spec.model.dataset.InsertDataSetModel; +import org.jiemamy.spec.model.index.IndexModel; +import org.jiemamy.spec.model.node.AbstractNodeModel; +import org.jiemamy.spec.model.node.TableModel; + +/** + * RootModel用のイベント系テスト + * @author shin1 + */ +public class RootModelTest { + + private RootModel rootModel; + + private RootModelChangeListenerImpl listener; + + + /** + * Test用のRootModelを作成し、さらにListenerの作成と追加をする。 + */ + @Before + public void setUp() { + JiemamyModelFactory.init(new S2FactoryStrategy("jiemamy-event.dicon")); + rootModel = JiemamyModelFactory.createRoot().init(); + listener = new RootModelChangeListenerImpl(); + rootModel.getAdapter(RootModelChangeSupport.class).addRootModelChangeListener(listener); + } + + /** + * Test用のRootModelとそのListenerの破棄。 + */ + @After + public void tearDown() { + rootModel.getAdapter(RootModelChangeSupport.class).removeRootModelChangeListener(listener); + rootModel = null; + listener = null; + } + + /** + * バブリングの動作確認。 + * @throws TooManyElementsException + */ + @Test + public void test_バブリングが正しく動作するか() throws TooManyElementsException { + rootModel.appendModel(rootModel.createJiemamyModel(TableModel.class).init("T_USER01")); + rootModel.appendModel(rootModel.createJiemamyModel(TableModel.class).init("T_USER02")); + + TableModel tableModel = rootModel.getEntity(TableModel.class, "T_USER01"); + assertNotNull(tableModel); + tableModel.getAdapter(TableModelChangeSupport.class).addTableModelChangeListener( + new TableModelChangeListenerImpl()); + + ColumnModel columnModel = rootModel.createJiemamyModel(ColumnModel.class); + assertNotNull(columnModel); + + // 通常のRootModelが直接保持するCollection<TableModel>を操作する。 + listener.nodeEvents.clear(); + tableModel.setName("T_USER01a"); + assertEquals(1, listener.nodeEvents.size()); + + // FIXME shin1: 動いてない!! +// // RootModelが保持するCollection<TableModel>が保持するCollection<ColumnModel>を操作する。 +// listener.nodeEvents.clear(); +// tableModel.getColumns().add(columnModel); +// assertEquals(1, listener.nodeEvents.size()); // バブリングの確認 + } + + + public class TableModelChangeListenerImpl implements TableModelChangeListener { + + /** + * {@inheritDoc} + */ + public void checkCollectionChange( + ObservableCollectionChangeEvent<List<CheckConstraintModel>, CheckConstraintModel> event) { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void columnCollectionChange(ObservableCollectionChangeEvent<List<ColumnModel>, ColumnModel> event) { + System.out.println("columnCollectionChange"); + + } + + /** + * {@inheritDoc} + */ + public void indexCollectionChange(ObservableCollectionChangeEvent<List<IndexModel>, IndexModel> event) { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void modelChanged(ModelChangeEvent e) { + // TODO Auto-generated method stub + + } + + /** + * {@inheritDoc} + */ + public void primaryKeyColumnCollectionChange( + ObservableCollectionChangeEvent<List<ColumnModel>, ColumnModel> event) { + // TODO Auto-generated method stub + + } + + } + + private class RootModelChangeListenerImpl implements RootModelChangeListener { + + List<ObservableCollectionChangeEvent<List<AbstractNodeModel>, AbstractNodeModel>> nodeEvents = + new ArrayList<ObservableCollectionChangeEvent<List<AbstractNodeModel>, AbstractNodeModel>>(); + + + /** + * {@inheritDoc} + */ + public void connectionCollectionChange( + ObservableCollectionChangeEvent<List<AbstractConnectionModel>, AbstractConnectionModel> event) { + System.out.println("connectionCollectionChange"); + } + + /** + * {@inheritDoc} + */ + public void domainCollectionChange(ObservableCollectionChangeEvent<List<DomainModel>, DomainModel> event) { + System.out.println("connectionCollectionChange"); + } + + /** + * {@inheritDoc} + */ + public void insertDataSetCollectionChange( + ObservableCollectionChangeEvent<List<InsertDataSetModel>, InsertDataSetModel> event) { + System.out.println("insertDataSetCollectionChange"); + } + + /** + * {@inheritDoc} + */ + public void modelChanged(ModelChangeEvent e) { + System.out.println("modelChanged"); + } + + /** + * {@inheritDoc} + */ + public void nodCollectionChange( + ObservableCollectionChangeEvent<List<AbstractNodeModel>, AbstractNodeModel> event) { + nodeEvents.add(event); + System.out.println("nodeCollectionChange event=" + event); + } + } +} Property changes on: artemis/trunk/org.jiemamy.event/src/test/java/org/jiemamy/core/model/RootModelTest.java ___________________________________________________________________ Name: svn:mime-type + text/plain