svnno****@sourc*****
svnno****@sourc*****
2009年 2月 14日 (土) 21:59:29 JST
Revision: 2670 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2670 Author: shin1 Date: 2009-02-14 21:59:29 +0900 (Sat, 14 Feb 2009) Log Message: ----------- 親子関係の探索に、collectionではなくiterableを使用する。 testクラスのクラス名変更、デバッグ用ログをtraceに。 Modified Paths: -------------- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/ReferenceResolverImpl.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ReferenceResolverImplTest.java Added Paths: ----------- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerImplTest.java Removed Paths: ------------- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerTest.java -------------- next part -------------- Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/ReferenceResolverImpl.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/ReferenceResolverImpl.java 2009-02-14 02:21:18 UTC (rev 2669) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/ReferenceResolverImpl.java 2009-02-14 12:59:29 UTC (rev 2670) @@ -19,7 +19,6 @@ package org.jiemamy; import java.lang.reflect.InvocationTargetException; -import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Map; @@ -28,6 +27,7 @@ import org.apache.commons.beanutils.PropertyUtils; import org.apache.commons.lang.Validate; +import org.apache.commons.lang.builder.ToStringBuilder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -77,7 +77,12 @@ while (i.hasNext()) { Entry<String, Object> next = i.next(); Object value = next.getValue(); - logger.debug(" field:name=" + next.getKey() + ", value=" + value); + logger.trace(String.format(" %s@%s.%s=%s", new Object[] { + element.getClass().getSimpleName(), + Integer.toHexString(element.hashCode()), + next.getKey(), + next.getValue() + })); if (isDescendFromFieldValue(value, uuid)) { return true; } @@ -86,7 +91,11 @@ Iterator<Object> adapters = element.getAdapters().iterator(); while (adapters.hasNext()) { Object value = adapters.next(); - logger.debug(" adapter=" + value); + logger.trace(String.format(" %s@%s.adapter=%s", new Object[] { + element.getClass().getSimpleName(), + Integer.toHexString(element.hashCode()), + ToStringBuilder.reflectionToString(value) + })); if (isDescendFromFieldValue(value, uuid)) { return true; } @@ -127,10 +136,10 @@ if (uuid.equals(((ElementReference<JiemamyElement>) fieldValue).getReferenceId())) { return true; } - } else if (fieldValue instanceof Collection) { - // Collectionだった場合は要素に対して再起して調査する。 - Collection<? extends Object> collection = (Collection) fieldValue; - for (Object element : collection) { + } else if (fieldValue instanceof Iterable) { + // Iterableだった場合は要素に対して再起して調査する。 + Iterable<? extends Object> iterable = (Iterable) fieldValue; + for (Object element : iterable) { if (isDescendFromFieldValue(element, uuid)) { return true; } Copied: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerImplTest.java (from rev 2666, artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerTest.java) =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerImplTest.java (rev 0) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerImplTest.java 2009-02-14 12:59:29 UTC (rev 2670) @@ -0,0 +1,324 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/01/18 + * + * 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; + +import static org.hamcrest.CoreMatchers.instanceOf; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.jiemamy.editcommand.Command; +import org.jiemamy.editcommand.CommandListener; +import org.jiemamy.editcommand.CommandProcessorImpl; +import org.jiemamy.editcommand.impl.AddColumnCommand; +import org.jiemamy.editcommand.impl.AddColumnToColumnRefListCommand; +import org.jiemamy.editcommand.impl.AddPrimaryKeyCommand; +import org.jiemamy.editcommand.impl.AddTableCommand; +import org.jiemamy.editcommand.impl.DeleteColumnCommand; +import org.jiemamy.editcommand.impl.DeleteColumnFromColumnRefListCommand; +import org.jiemamy.editcommand.impl.ModifyModelPropertyCommand; +import org.jiemamy.model.JiemamyElement; +import org.jiemamy.model.RootModel; +import org.jiemamy.model.attribute.ColumnModel; +import org.jiemamy.model.attribute.constraint.ConstraintModel; +import org.jiemamy.model.attribute.constraint.PrimaryKeyModel; +import org.jiemamy.model.entity.TableModel; + +/** + * {@link EventBrokerImpl}の試験クラス。 + * + * @author shin1ogawa + */ +public class EventBrokerImplTest { + + static final Logger LOGGER = LoggerFactory.getLogger(EventBrokerImplTest.class); + + private JiemamyFactory factory; + + private Jiemamy jiemamy; + + private EventBroker eventBroker; + + private CommandProcessorImpl commandProcessor; + + private Stack<Command> commandStack; + + private RootModel rootModel; + + + /** + * テストの準備 + */ + @Before + public void setUp() { + jiemamy = Jiemamy.newInstance(); + factory = jiemamy.getFactory(); + rootModel = factory.newModel(RootModel.class); + eventBroker = jiemamy.getEventBroker(); + commandProcessor = new CommandProcessorImpl(eventBroker); + commandStack = new Stack<Command>(); + } + + /** + * Tableが保持している{@link ConstraintModel}が参照する{@link ColumnModel}に対する変更も通知される。 + * @throws Exception + */ + @Test + public void testReferenceで保持した要素からのバブリング() throws Exception { + TableModel table = factory.newModel(TableModel.class); + ColumnModel column1 = factory.newModel(ColumnModel.class); + new AddColumnCommand(table, column1).execute(commandProcessor, commandStack); + ColumnModel column2 = factory.newModel(ColumnModel.class); + new AddColumnCommand(table, column2).execute(commandProcessor, commandStack); + + PrimaryKeyModel primaryKey = factory.newModel(PrimaryKeyModel.class); + new AddColumnToColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), column2).execute(commandProcessor, + commandStack); + new AddColumnToColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), column1, 0).execute( + commandProcessor, commandStack); + new AddPrimaryKeyCommand(table, primaryKey).execute(commandProcessor, commandStack); + + // ここまでで以下の構造を構築した事になる。 + // table + // +attributes + // -column1 + // -column2 + // +primaryKey + // -[ref]column1 + // -[ref]column2 + + DefaultCommandListener tableListener = new DefaultCommandListener(table); + eventBroker.addListener(tableListener); + DefaultCommandListener columnListener1 = new DefaultCommandListener(column1); + eventBroker.addListener(columnListener1); + DefaultCommandListener columnListener2 = new DefaultCommandListener(column2); + eventBroker.addListener(columnListener2); + DefaultCommandListener pkeyListener = new DefaultCommandListener(primaryKey); + eventBroker.addListener(pkeyListener); + + assertThat(columnListener1.commandList.size(), is(0)); + assertThat(columnListener2.commandList.size(), is(0)); + assertThat(pkeyListener.commandList.size(), is(0)); + assertThat(tableListener.commandList.size(), is(0)); + assertThat(table.getAttributes().size(), is(3)); // column1,column2,pkey + assertThat(primaryKey.getKeyColumns().size(), is(2)); // [ref]column1, [ref]column2。 + assertThat(primaryKey.getKeyColumns().get(0).getReferenceId(), is(column1.getId())); + assertThat(primaryKey.getKeyColumns().get(1).getReferenceId(), is(column2.getId())); + + new ModifyModelPropertyCommand(column1, "name", "column1").execute(commandProcessor, commandStack); + + assertThat(columnListener1.commandList.size(), is(1)); // 変更があったcolumn自身。 + assertThat(columnListener2.commandList.size(), is(0)); + assertThat(pkeyListener.commandList.size(), is(1)); // 変更があったcolumnのreferenceを保持しているから通知を受ける。 + assertThat(tableListener.commandList.size(), is(1)); // 変更があったcolumnを保持しているから通知を受ける。 + assertThat(table.getAttributes().size(), is(3)); // column1,column2,pkey + assertThat(primaryKey.getKeyColumns().size(), is(2)); // [ref]column1, [ref]column2。 + assertThat(primaryKey.getKeyColumns().get(0).getReferenceId(), is(column1.getId())); + assertThat(primaryKey.getKeyColumns().get(1).getReferenceId(), is(column2.getId())); + + columnListener1.commandList.clear(); + columnListener2.commandList.clear(); + pkeyListener.commandList.clear(); + tableListener.commandList.clear(); + // columnをprimaryKeyから削除する。 + new DeleteColumnFromColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), column1).execute( + commandProcessor, commandStack); + + assertThat(columnListener1.commandList.size(), is(0)); // column自身は何も変更されていない。 + assertThat(columnListener2.commandList.size(), is(0)); + assertThat(pkeyListener.commandList.size(), is(1)); // 変更があったcolumnのreferenceを保持しているから通知を受ける。 + assertThat(tableListener.commandList.size(), is(1)); // 変更があったcolumnのreferenceを保持しているprumaruKeyを保持しているから通知を受ける。 + assertThat(table.getAttributes().size(), is(3)); // column1,column2,pkey + assertThat(primaryKey.getKeyColumns().size(), is(1)); // [ref]column2。 + + columnListener1.commandList.clear(); + columnListener2.commandList.clear(); + pkeyListener.commandList.clear(); + tableListener.commandList.clear(); + // columnをtableから削除する。 + new DeleteColumnCommand(table, column1).execute(commandProcessor); + + assertThat(columnListener1.commandList.size(), is(0)); // column自身は何も変更されていない。 + assertThat(columnListener2.commandList.size(), is(0)); + assertThat(pkeyListener.commandList.size(), is(0)); + assertThat(tableListener.commandList.size(), is(1)); + assertThat(table.getAttributes().size(), is(2)); // column2,pkey + assertThat(primaryKey.getKeyColumns().size(), is(1)); // [ref]column2。 + } + + /** + * バブリングの動作確認。 + * + * @throws Exception + */ + @Test + public void testバブリング() throws Exception { + TableModel table = factory.newModel(TableModel.class); + new AddTableCommand(rootModel, table).execute(commandProcessor, commandStack); + ColumnModel column = factory.newModel(ColumnModel.class); + new AddColumnCommand(table, column).execute(commandProcessor, commandStack); + + // ここまでで以下の構造を構築した事になる。 + // table + // +attributes + // -column + assertThat(table.getAttributes().size(), is(1)); + assertThat(rootModel.getEntities().size(), is(1)); + + DefaultCommandListener rootListener = new DefaultCommandListener(rootModel); + eventBroker.addListener(rootListener); + DefaultCommandListener tableListener = new DefaultCommandListener(table); + eventBroker.addListener(tableListener); + DefaultCommandListener columnListener = new DefaultCommandListener(column); + eventBroker.addListener(columnListener); + + new ModifyModelPropertyCommand(table, "name", "T_EMP"). // tableを変更する。 + execute(commandProcessor, commandStack); // tableListener, rootListenerへ通知されるはず。 + new ModifyModelPropertyCommand(column, "name", "ID") // columnを変更する。 + .execute(commandProcessor, commandStack); // columnListener,tableListener,rootListenerへ通知される + new AddColumnCommand(table, factory.newModel(ColumnModel.class)) // 新たに作成したcolumnを追加する。 + .execute(commandProcessor, commandStack); // tableListener, rootListenerへ通知されるはず。 + new AddTableCommand(rootModel, factory.newModel(TableModel.class)) // 新たに作成したtableを追加する。 + .execute(commandProcessor, commandStack); // rootListenerへ通知されるはず。 + + assertThat(table.getAttributes().size(), is(2)); + assertThat(rootModel.getEntities().size(), is(2)); + + assertThat(columnListener.commandList.size(), is(1)); + assertThat(columnListener.commandList.get(0), instanceOf(ModifyModelPropertyCommand.class)); + assertThat(tableListener.commandList.size(), is(3)); + assertThat(tableListener.commandList.get(0), instanceOf(ModifyModelPropertyCommand.class)); + assertThat(tableListener.commandList.get(1), instanceOf(ModifyModelPropertyCommand.class)); + assertThat(tableListener.commandList.get(2), instanceOf(AddColumnCommand.class)); + assertThat(rootListener.commandList.size(), is(4)); + assertThat(rootListener.commandList.get(0), instanceOf(ModifyModelPropertyCommand.class)); + assertThat(rootListener.commandList.get(1), instanceOf(ModifyModelPropertyCommand.class)); + assertThat(rootListener.commandList.get(2), instanceOf(AddColumnCommand.class)); + assertThat(rootListener.commandList.get(3), instanceOf(AddTableCommand.class)); + + columnListener.commandList.clear(); + tableListener.commandList.clear(); + rootListener.commandList.clear(); + + // RootModelに追加しないColumnModelを作ったり、属性を変更したり。 + ColumnModel column2 = factory.newModel(ColumnModel.class); + new ModifyModelPropertyCommand(column2, "name", "NAME").execute(commandProcessor, commandStack); + // RootModelに追加しないColumnModelを作ったり、属性を変更したり。 + TableModel table2 = factory.newModel(TableModel.class); + new ModifyModelPropertyCommand(table2, "name", "Y_DEPT").execute(commandProcessor, commandStack); + // RootModelに追加していないTableModelにColumnModelを追加してみたり。 + new AddColumnCommand(table2, column2).execute(commandProcessor, commandStack); + + assertThat(columnListener.commandList.size(), is(0)); + assertThat(tableListener.commandList.size(), is(0)); + assertThat(rootListener.commandList.size(), is(0)); + } + + /** + * シンプルなイベント通知の動作確認。 + * + * @throws Exception + */ + @Test + public void testバブリングとか無しでの通知() throws Exception { + TableModel emp = factory.newModel(TableModel.class); + TableModel dept = factory.newModel(TableModel.class); + new ModifyModelPropertyCommand(emp, "name", "T_EMP").execute(commandProcessor, commandStack); + new ModifyModelPropertyCommand(dept, "name", "T_DEPT").execute(commandProcessor, commandStack); + new AddTableCommand(rootModel, emp).execute(commandProcessor, commandStack); + new AddTableCommand(rootModel, dept).execute(commandProcessor, commandStack); + + // Listenerを作成、追加する。 + DefaultCommandListener empListener = new DefaultCommandListener(emp); + eventBroker.addListener(empListener); + DefaultCommandListener deptListener = new DefaultCommandListener(dept); + eventBroker.addListener(deptListener); + + // EMPに対して変更Commandを適用する。 + new ModifyModelPropertyCommand(emp, "name", "newEmp").execute(commandProcessor, commandStack); + assertThat(empListener.commandList.size(), is(1)); + assertThat(deptListener.commandList.size(), is(0)); + assertThat(emp.getName(), is("newEmp")); + // Undoしてみる。 + Command undoCommand1 = commandStack.pop(); + undoCommand1.execute(commandProcessor, commandStack); + assertThat(empListener.commandList.size(), is(2)); + assertThat(deptListener.commandList.size(), is(0)); + assertThat(emp.getName(), is("T_EMP")); + + // DEPTに対して変更Commandを適用する。 + empListener.commandList.clear(); + deptListener.commandList.clear(); + new ModifyModelPropertyCommand(dept, "name", "newDept").execute(commandProcessor, commandStack); + assertThat(empListener.commandList.size(), is(0)); + assertThat(deptListener.commandList.size(), is(1)); + assertThat(dept.getName(), is("newDept")); + // Undoしてみる。 + Command undoCommand2 = commandStack.pop(); + undoCommand2.execute(commandProcessor, commandStack); + assertThat(empListener.commandList.size(), is(0)); + assertThat(deptListener.commandList.size(), is(2)); + assertThat(dept.getName(), is("T_DEPT")); + } + + + /** + * TODO for shin1ogawa + * + * @author shin1ogawa + */ + public static class DefaultCommandListener implements CommandListener { + + JiemamyElement target; + + List<Command> commandList = new ArrayList<Command>(); + + + /** + * インスタンスを生成する。 + * + * @param target + */ + public DefaultCommandListener(JiemamyElement target) { + this.target = target; + } + + /** + * {@inheritDoc} + */ + public void commandProcess(Command command) { + commandList.add(command); + } + + /** + * {@inheritDoc} + */ + public JiemamyElement getTargetModel() { + return target; + } + } +} Property changes on: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerImplTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Deleted: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerTest.java 2009-02-14 02:21:18 UTC (rev 2669) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerTest.java 2009-02-14 12:59:29 UTC (rev 2670) @@ -1,324 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2009/01/18 - * - * 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; - -import static org.hamcrest.CoreMatchers.instanceOf; -import static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.ArrayList; -import java.util.List; -import java.util.Stack; - -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.jiemamy.editcommand.Command; -import org.jiemamy.editcommand.CommandListener; -import org.jiemamy.editcommand.CommandProcessorImpl; -import org.jiemamy.editcommand.impl.AddColumnCommand; -import org.jiemamy.editcommand.impl.AddColumnToColumnRefListCommand; -import org.jiemamy.editcommand.impl.AddPrimaryKeyCommand; -import org.jiemamy.editcommand.impl.AddTableCommand; -import org.jiemamy.editcommand.impl.DeleteColumnCommand; -import org.jiemamy.editcommand.impl.DeleteColumnFromColumnRefListCommand; -import org.jiemamy.editcommand.impl.ModifyModelPropertyCommand; -import org.jiemamy.model.JiemamyElement; -import org.jiemamy.model.RootModel; -import org.jiemamy.model.attribute.ColumnModel; -import org.jiemamy.model.attribute.constraint.ConstraintModel; -import org.jiemamy.model.attribute.constraint.PrimaryKeyModel; -import org.jiemamy.model.entity.TableModel; - -/** - * {@link EventBrokerImpl}の試験クラス。 - * - * @author shin1ogawa - */ -public class EventBrokerTest { - - static final Logger LOGGER = LoggerFactory.getLogger(EventBrokerTest.class); - - private JiemamyFactory factory; - - private Jiemamy jiemamy; - - private EventBroker eventBroker; - - private CommandProcessorImpl commandProcessor; - - private Stack<Command> commandStack; - - private RootModel rootModel; - - - /** - * テストの準備 - */ - @Before - public void setUp() { - jiemamy = Jiemamy.newInstance(); - factory = jiemamy.getFactory(); - rootModel = factory.newModel(RootModel.class); - eventBroker = jiemamy.getEventBroker(); - commandProcessor = new CommandProcessorImpl(eventBroker); - commandStack = new Stack<Command>(); - } - - /** - * Tableが保持している{@link ConstraintModel}が参照する{@link ColumnModel}に対する変更も通知される。 - * @throws Exception - */ - @Test - public void testReferenceで保持した要素からのバブリング() throws Exception { - TableModel table = factory.newModel(TableModel.class); - ColumnModel column1 = factory.newModel(ColumnModel.class); - new AddColumnCommand(table, column1).execute(commandProcessor, commandStack); - ColumnModel column2 = factory.newModel(ColumnModel.class); - new AddColumnCommand(table, column2).execute(commandProcessor, commandStack); - - PrimaryKeyModel primaryKey = factory.newModel(PrimaryKeyModel.class); - new AddColumnToColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), column2).execute(commandProcessor, - commandStack); - new AddColumnToColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), column1, 0).execute( - commandProcessor, commandStack); - new AddPrimaryKeyCommand(table, primaryKey).execute(commandProcessor, commandStack); - - // ここまでで以下の構造を構築した事になる。 - // table - // +attributes - // -column1 - // -column2 - // +primaryKey - // -[ref]column1 - // -[ref]column2 - - DefaultCommandListener tableListener = new DefaultCommandListener(table); - eventBroker.addListener(tableListener); - DefaultCommandListener columnListener1 = new DefaultCommandListener(column1); - eventBroker.addListener(columnListener1); - DefaultCommandListener columnListener2 = new DefaultCommandListener(column2); - eventBroker.addListener(columnListener2); - DefaultCommandListener pkeyListener = new DefaultCommandListener(primaryKey); - eventBroker.addListener(pkeyListener); - - assertThat(columnListener1.commandList.size(), is(0)); - assertThat(columnListener2.commandList.size(), is(0)); - assertThat(pkeyListener.commandList.size(), is(0)); - assertThat(tableListener.commandList.size(), is(0)); - assertThat(table.getAttributes().size(), is(3)); // column1,column2,pkey - assertThat(primaryKey.getKeyColumns().size(), is(2)); // [ref]column1, [ref]column2。 - assertThat(primaryKey.getKeyColumns().get(0).getReferenceId(), is(column1.getId())); - assertThat(primaryKey.getKeyColumns().get(1).getReferenceId(), is(column2.getId())); - - new ModifyModelPropertyCommand(column1, "name", "column1").execute(commandProcessor, commandStack); - - assertThat(columnListener1.commandList.size(), is(1)); // 変更があったcolumn自身。 - assertThat(columnListener2.commandList.size(), is(0)); - assertThat(pkeyListener.commandList.size(), is(1)); // 変更があったcolumnのreferenceを保持しているから通知を受ける。 - assertThat(tableListener.commandList.size(), is(1)); // 変更があったcolumnを保持しているから通知を受ける。 - assertThat(table.getAttributes().size(), is(3)); // column1,column2,pkey - assertThat(primaryKey.getKeyColumns().size(), is(2)); // [ref]column1, [ref]column2。 - assertThat(primaryKey.getKeyColumns().get(0).getReferenceId(), is(column1.getId())); - assertThat(primaryKey.getKeyColumns().get(1).getReferenceId(), is(column2.getId())); - - columnListener1.commandList.clear(); - columnListener2.commandList.clear(); - pkeyListener.commandList.clear(); - tableListener.commandList.clear(); - // columnをprimaryKeyから削除する。 - new DeleteColumnFromColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), column1).execute( - commandProcessor, commandStack); - - assertThat(columnListener1.commandList.size(), is(0)); // column自身は何も変更されていない。 - assertThat(columnListener2.commandList.size(), is(0)); - assertThat(pkeyListener.commandList.size(), is(1)); // 変更があったcolumnのreferenceを保持しているから通知を受ける。 - assertThat(tableListener.commandList.size(), is(1)); // 変更があったcolumnのreferenceを保持しているprumaruKeyを保持しているから通知を受ける。 - assertThat(table.getAttributes().size(), is(3)); // column1,column2,pkey - assertThat(primaryKey.getKeyColumns().size(), is(1)); // [ref]column2。 - - columnListener1.commandList.clear(); - columnListener2.commandList.clear(); - pkeyListener.commandList.clear(); - tableListener.commandList.clear(); - // columnをtableから削除する。 - new DeleteColumnCommand(table, column1).execute(commandProcessor); - - assertThat(columnListener1.commandList.size(), is(0)); // column自身は何も変更されていない。 - assertThat(columnListener2.commandList.size(), is(0)); - assertThat(pkeyListener.commandList.size(), is(0)); - assertThat(tableListener.commandList.size(), is(1)); - assertThat(table.getAttributes().size(), is(2)); // column2,pkey - assertThat(primaryKey.getKeyColumns().size(), is(1)); // [ref]column2。 - } - - /** - * バブリングの動作確認。 - * - * @throws Exception - */ - @Test - public void testバブリング() throws Exception { - TableModel table = factory.newModel(TableModel.class); - new AddTableCommand(rootModel, table).execute(commandProcessor, commandStack); - ColumnModel column = factory.newModel(ColumnModel.class); - new AddColumnCommand(table, column).execute(commandProcessor, commandStack); - - // ここまでで以下の構造を構築した事になる。 - // table - // +attributes - // -column - assertThat(table.getAttributes().size(), is(1)); - assertThat(rootModel.getEntities().size(), is(1)); - - DefaultCommandListener rootListener = new DefaultCommandListener(rootModel); - eventBroker.addListener(rootListener); - DefaultCommandListener tableListener = new DefaultCommandListener(table); - eventBroker.addListener(tableListener); - DefaultCommandListener columnListener = new DefaultCommandListener(column); - eventBroker.addListener(columnListener); - - new ModifyModelPropertyCommand(table, "name", "T_EMP"). // tableを変更する。 - execute(commandProcessor, commandStack); // tableListener, rootListenerへ通知されるはず。 - new ModifyModelPropertyCommand(column, "name", "ID") // columnを変更する。 - .execute(commandProcessor, commandStack); // columnListener,tableListener,rootListenerへ通知される - new AddColumnCommand(table, factory.newModel(ColumnModel.class)) // 新たに作成したcolumnを追加する。 - .execute(commandProcessor, commandStack); // tableListener, rootListenerへ通知されるはず。 - new AddTableCommand(rootModel, factory.newModel(TableModel.class)) // 新たに作成したtableを追加する。 - .execute(commandProcessor, commandStack); // rootListenerへ通知されるはず。 - - assertThat(table.getAttributes().size(), is(2)); - assertThat(rootModel.getEntities().size(), is(2)); - - assertThat(columnListener.commandList.size(), is(1)); - assertThat(columnListener.commandList.get(0), instanceOf(ModifyModelPropertyCommand.class)); - assertThat(tableListener.commandList.size(), is(3)); - assertThat(tableListener.commandList.get(0), instanceOf(ModifyModelPropertyCommand.class)); - assertThat(tableListener.commandList.get(1), instanceOf(ModifyModelPropertyCommand.class)); - assertThat(tableListener.commandList.get(2), instanceOf(AddColumnCommand.class)); - assertThat(rootListener.commandList.size(), is(4)); - assertThat(rootListener.commandList.get(0), instanceOf(ModifyModelPropertyCommand.class)); - assertThat(rootListener.commandList.get(1), instanceOf(ModifyModelPropertyCommand.class)); - assertThat(rootListener.commandList.get(2), instanceOf(AddColumnCommand.class)); - assertThat(rootListener.commandList.get(3), instanceOf(AddTableCommand.class)); - - columnListener.commandList.clear(); - tableListener.commandList.clear(); - rootListener.commandList.clear(); - - // RootModelに追加しないColumnModelを作ったり、属性を変更したり。 - ColumnModel column2 = factory.newModel(ColumnModel.class); - new ModifyModelPropertyCommand(column2, "name", "NAME").execute(commandProcessor, commandStack); - // RootModelに追加しないColumnModelを作ったり、属性を変更したり。 - TableModel table2 = factory.newModel(TableModel.class); - new ModifyModelPropertyCommand(table2, "name", "Y_DEPT").execute(commandProcessor, commandStack); - // RootModelに追加していないTableModelにColumnModelを追加してみたり。 - new AddColumnCommand(table2, column2).execute(commandProcessor, commandStack); - - assertThat(columnListener.commandList.size(), is(0)); - assertThat(tableListener.commandList.size(), is(0)); - assertThat(rootListener.commandList.size(), is(0)); - } - - /** - * シンプルなイベント通知の動作確認。 - * - * @throws Exception - */ - @Test - public void testバブリングとか無しでの通知() throws Exception { - TableModel emp = factory.newModel(TableModel.class); - TableModel dept = factory.newModel(TableModel.class); - new ModifyModelPropertyCommand(emp, "name", "T_EMP").execute(commandProcessor, commandStack); - new ModifyModelPropertyCommand(dept, "name", "T_DEPT").execute(commandProcessor, commandStack); - new AddTableCommand(rootModel, emp).execute(commandProcessor, commandStack); - new AddTableCommand(rootModel, dept).execute(commandProcessor, commandStack); - - // Listenerを作成、追加する。 - DefaultCommandListener empListener = new DefaultCommandListener(emp); - eventBroker.addListener(empListener); - DefaultCommandListener deptListener = new DefaultCommandListener(dept); - eventBroker.addListener(deptListener); - - // EMPに対して変更Commandを適用する。 - new ModifyModelPropertyCommand(emp, "name", "newEmp").execute(commandProcessor, commandStack); - assertThat(empListener.commandList.size(), is(1)); - assertThat(deptListener.commandList.size(), is(0)); - assertThat(emp.getName(), is("newEmp")); - // Undoしてみる。 - Command undoCommand1 = commandStack.pop(); - undoCommand1.execute(commandProcessor, commandStack); - assertThat(empListener.commandList.size(), is(2)); - assertThat(deptListener.commandList.size(), is(0)); - assertThat(emp.getName(), is("T_EMP")); - - // DEPTに対して変更Commandを適用する。 - empListener.commandList.clear(); - deptListener.commandList.clear(); - new ModifyModelPropertyCommand(dept, "name", "newDept").execute(commandProcessor, commandStack); - assertThat(empListener.commandList.size(), is(0)); - assertThat(deptListener.commandList.size(), is(1)); - assertThat(dept.getName(), is("newDept")); - // Undoしてみる。 - Command undoCommand2 = commandStack.pop(); - undoCommand2.execute(commandProcessor, commandStack); - assertThat(empListener.commandList.size(), is(0)); - assertThat(deptListener.commandList.size(), is(2)); - assertThat(dept.getName(), is("T_DEPT")); - } - - - /** - * TODO for shin1ogawa - * - * @author shin1ogawa - */ - public static class DefaultCommandListener implements CommandListener { - - JiemamyElement target; - - List<Command> commandList = new ArrayList<Command>(); - - - /** - * インスタンスを生成する。 - * - * @param target - */ - public DefaultCommandListener(JiemamyElement target) { - this.target = target; - } - - /** - * {@inheritDoc} - */ - public void commandProcess(Command command) { - commandList.add(command); - } - - /** - * {@inheritDoc} - */ - public JiemamyElement getTargetModel() { - return target; - } - } -} Modified: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ReferenceResolverImplTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ReferenceResolverImplTest.java 2009-02-14 02:21:18 UTC (rev 2669) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ReferenceResolverImplTest.java 2009-02-14 12:59:29 UTC (rev 2670) @@ -51,7 +51,7 @@ */ public class ReferenceResolverImplTest { - static final Logger LOGGER = LoggerFactory.getLogger(EventBrokerTest.class); + static final Logger LOGGER = LoggerFactory.getLogger(ReferenceResolverImplTest.class); private JiemamyFactory factory;