svnno****@sourc*****
svnno****@sourc*****
2009年 2月 14日 (土) 22:01:21 JST
Revision: 2671 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2671 Author: shin1 Date: 2009-02-14 22:01:20 +0900 (Sat, 14 Feb 2009) Log Message: ----------- j-viewをj-coreにadaptした時のイベントの通知を確認するテストを追加。 Added Paths: ----------- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/EventBrokerImplTest.java -------------- next part -------------- Added: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/EventBrokerImplTest.java =================================================================== --- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/EventBrokerImplTest.java (rev 0) +++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/EventBrokerImplTest.java 2009-02-14 13:01:20 UTC (rev 2671) @@ -0,0 +1,140 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/02/14 + * + * 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 java.util.ArrayList; +import java.util.List; +import java.util.Stack; + +import org.hamcrest.Matchers; +import org.junit.Assert; +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.AddTableCommand; +import org.jiemamy.editcommand.impl.ModifyModelPropertyCommand; +import org.jiemamy.model.DiagramPresentationModel; +import org.jiemamy.model.DiagramPresentations; +import org.jiemamy.model.JiemamyElement; +import org.jiemamy.model.RootModel; +import org.jiemamy.model.attribute.ColumnModel; +import org.jiemamy.model.entity.TableModel; + +/** + * j-core, j-viewを使った{@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; + + + /** + * テストの準備 + */ + @Before + public void setUp() { + jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView())); + factory = jiemamy.getFactory(); + eventBroker = jiemamy.getEventBroker(); + commandProcessor = new CommandProcessorImpl(eventBroker); + } + + /** + * j-coreの{@link RootModel}に対してj-viewの{@link DiagramPresentationModel}をAdaptし、 + * AdaptされたModelに対して変更コマンドを実行したときにj-coreの{@link EventBroker}が通知できるか。 + * @throws Exception + */ + @Test + public void test01_AdaptされたDiaglramPresentationModelに対する変更が通知される() throws Exception { + RootModel rootModel = factory.newModel(RootModel.class); + + Stack<Command> commandStack = new Stack<Command>(); + TableModel table = factory.newModel(TableModel.class); + new AddTableCommand(rootModel, table).execute(commandProcessor, commandStack); + 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); + + DiagramPresentationModel presentation = factory.newModel(DiagramPresentationModel.class); + presentation.setName("testPresentation"); + rootModel.getAdapter(DiagramPresentations.class).add(presentation); + + // RootModelを監視対象とするリスナを作成し、EventBrokerへ登録する。 + DefaultCommandListener rootModelListener = new DefaultCommandListener(rootModel); + eventBroker.addListener(rootModelListener); + + // DiagramPresentationModelを変更する。 + new ModifyModelPropertyCommand(presentation, "name", "newName").execute(commandProcessor, commandStack); + Assert.assertThat(rootModelListener.commandList.size(), Matchers.is(1)); + } + + + /** + * 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-artemis-test/src/test/java/org/jiemamy/EventBrokerImplTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain