svnno****@sourc*****
svnno****@sourc*****
2009年 3月 22日 (日) 12:06:42 JST
Revision: 2976 http://svn.sourceforge.jp/view?root=jiemamy&view=rev&rev=2976 Author: daisuke_m Date: 2009-03-22 12:06:42 +0900 (Sun, 22 Mar 2009) Log Message: ----------- testクラスもパケ移動。 Modified Paths: -------------- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/JiemamySerializerTest.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/generic/GenericDialect.java artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/ReferenceResolverImpl.java artemis/trunk/jiemamy-dialect-mysql/src/main/java/org/jiemamy/dialect/mysql/MySqlDialect.java artemis/trunk/jiemamy-dialect-postgresql/src/main/java/org/jiemamy/dialect/postgresql/PostgresqlDialect.java artemis/trunk/jiemamy-dialect-sql99/src/main/java/org/jiemamy/dialect/sql99/Sql99Dialect.java Added Paths: ----------- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/EventBrokerImplTest.java artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/JiemamyDomSerializerTest.java artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/SerializationTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/ArtemisJiemamyFactoryTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/EventBrokerImplTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/JiemamyFacadeImplTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/JiemamyPropertyTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/ReferenceResolverImplTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/EmptyProxyModel.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/RootModelImplTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/constraint/ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/datatype/ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/datatype/BuiltinDataTypeImplTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/node/ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/node/TableModelImplTest.java artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/JiemamyViewFacadeImplTest.java artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/JiemamyViewPropertyTest.java artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/DiagramPresentationModelImplTest.java artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/connection/ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/connection/ConnectionModelImplTest.java artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/node/ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/node/NodeModelImplTest.java Removed Paths: ------------- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/EventBrokerImplTest.java artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/JiemamyDomSerializerTest.java artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/SerializationTest.java artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/editcommand/ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ArtemisJiemamyFactoryTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerImplTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/JiemamyPropertyTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ReferenceResolverImplTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/facade/ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/datatype/BuiltinDataTypeImplTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/node/TableModelImplTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/EmptyProxyModel.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/RootModelImplTest.java artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/constraint/ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/datatype/ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/node/ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/serializer/ artemis/trunk/jiemamy-view/src/main/java/org/jiemamy/model/ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/JiemamyViewPropertyTest.java artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/facade/ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/connection/ConnectionModelImplTest.java artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/node/NodeModelImplTest.java artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/model/DiagramPresentationModelImplTest.java artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/model/connection/ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/model/node/ -------------- next part -------------- Deleted: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/EventBrokerImplTest.java =================================================================== --- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/EventBrokerImplTest.java 2009-03-21 04:23:00 UTC (rev 2975) +++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/EventBrokerImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,156 +0,0 @@ -/* - * 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 static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.List; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.jiemamy.JiemamyViewProperty.DiagramPresentationProperty; -import org.jiemamy.editcommand.Command; -import org.jiemamy.editcommand.CommandListener; -import org.jiemamy.editcommand.CommandProcessor; -import org.jiemamy.internal.CommandProcessorImpl; -import org.jiemamy.internal.EventBrokerImpl; -import org.jiemamy.internal.editcommand.AddAttributeCommand; -import org.jiemamy.internal.editcommand.AddEntityToRootCommand; -import org.jiemamy.internal.editcommand.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; -import org.jiemamy.utils.CollectionsUtil; - -/** - * 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 CommandProcessor commandProcessor; - - - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView())); - factory = jiemamy.getFactory(); - eventBroker = jiemamy.getEventBroker(); - commandProcessor = new CommandProcessorImpl(eventBroker); - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - jiemamy = null; - factory = null; - eventBroker = null; - commandProcessor = null; - } - - /** - * 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.getRootModel(); - - TableModel tableModel = factory.newModel(TableModel.class); - new AddEntityToRootCommand(rootModel, tableModel).execute(commandProcessor); - ColumnModel columnModel1 = factory.newModel(ColumnModel.class); - new AddAttributeCommand(tableModel, columnModel1).execute(commandProcessor); - ColumnModel columnModel2 = factory.newModel(ColumnModel.class); - new AddAttributeCommand(tableModel, columnModel2).execute(commandProcessor); - - DiagramPresentationModel presentation = factory.newModel(DiagramPresentationModel.class); - presentation.setName("testPresentation"); - rootModel.getAdapter(DiagramPresentations.class).add(presentation); - - // RootModelを監視対象とするリスナを作成し、EventBrokerへ登録する。 - CommandListenerMock rootModelListener = new CommandListenerMock(rootModel); - eventBroker.addListener(rootModelListener); - - // DiagramPresentationModelを変更する。 - - new ModifyModelPropertyCommand<DiagramPresentationModel>(presentation, DiagramPresentationProperty.name, - "newName").execute(commandProcessor); - assertThat(rootModelListener.commandList.size(), is(1)); - } - - - /** - * {@link CommandListener}のテスト用モッククラス。 - * - * @author shin1ogawa - */ - public static class CommandListenerMock implements CommandListener { - - /** 監視対象モデル */ - JiemamyElement target; - - /** リスナのリスト */ - List<Command> commandList = CollectionsUtil.newArrayList(); - - - /** - * インスタンスを生成する。 - * - * @param target 監視対象モデル - */ - public CommandListenerMock(JiemamyElement target) { - this.target = target; - } - - public void commandExecuted(Command command) { - commandList.add(command); - } - - public JiemamyElement getTargetModel() { - return target; - } - } -} Copied: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/EventBrokerImplTest.java (from rev 2972, artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/EventBrokerImplTest.java) =================================================================== --- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/EventBrokerImplTest.java (rev 0) +++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/EventBrokerImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,159 @@ +/* + * 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.internal; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.List; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.jiemamy.Artemis; +import org.jiemamy.ArtemisView; +import org.jiemamy.EventBroker; +import org.jiemamy.Jiemamy; +import org.jiemamy.JiemamyFactory; +import org.jiemamy.JiemamyViewProperty.DiagramPresentationProperty; +import org.jiemamy.editcommand.Command; +import org.jiemamy.editcommand.CommandListener; +import org.jiemamy.editcommand.CommandProcessor; +import org.jiemamy.internal.editcommand.AddAttributeCommand; +import org.jiemamy.internal.editcommand.AddEntityToRootCommand; +import org.jiemamy.internal.editcommand.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; +import org.jiemamy.utils.CollectionsUtil; + +/** + * 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 CommandProcessor commandProcessor; + + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView())); + factory = jiemamy.getFactory(); + eventBroker = jiemamy.getEventBroker(); + commandProcessor = new CommandProcessorImpl(eventBroker); + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + jiemamy = null; + factory = null; + eventBroker = null; + commandProcessor = null; + } + + /** + * 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.getRootModel(); + + TableModel tableModel = factory.newModel(TableModel.class); + new AddEntityToRootCommand(rootModel, tableModel).execute(commandProcessor); + ColumnModel columnModel1 = factory.newModel(ColumnModel.class); + new AddAttributeCommand(tableModel, columnModel1).execute(commandProcessor); + ColumnModel columnModel2 = factory.newModel(ColumnModel.class); + new AddAttributeCommand(tableModel, columnModel2).execute(commandProcessor); + + DiagramPresentationModel presentation = factory.newModel(DiagramPresentationModel.class); + presentation.setName("testPresentation"); + rootModel.getAdapter(DiagramPresentations.class).add(presentation); + + // RootModelを監視対象とするリスナを作成し、EventBrokerへ登録する。 + CommandListenerMock rootModelListener = new CommandListenerMock(rootModel); + eventBroker.addListener(rootModelListener); + + // DiagramPresentationModelを変更する。 + + new ModifyModelPropertyCommand<DiagramPresentationModel>(presentation, DiagramPresentationProperty.name, + "newName").execute(commandProcessor); + assertThat(rootModelListener.commandList.size(), is(1)); + } + + + /** + * {@link CommandListener}のテスト用モッククラス。 + * + * @author shin1ogawa + */ + public static class CommandListenerMock implements CommandListener { + + /** 監視対象モデル */ + JiemamyElement target; + + /** リスナのリスト */ + List<Command> commandList = CollectionsUtil.newArrayList(); + + + /** + * インスタンスを生成する。 + * + * @param target 監視対象モデル + */ + public CommandListenerMock(JiemamyElement target) { + this.target = target; + } + + public void commandExecuted(Command command) { + commandList.add(command); + } + + public JiemamyElement getTargetModel() { + return target; + } + } +} Property changes on: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/EventBrokerImplTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Deleted: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/JiemamyDomSerializerTest.java =================================================================== --- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/JiemamyDomSerializerTest.java 2009-03-20 15:22:38 UTC (rev 2971) +++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/JiemamyDomSerializerTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,57 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2009/01/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.serializer; - -import org.junit.After; -import org.junit.Before; - -import org.jiemamy.Artemis; -import org.jiemamy.ArtemisView; -import org.jiemamy.Jiemamy; - -/** - * {@link JiemamyDomSerializer}のテストクラス。 - * - * @author daisuke - */ -public class JiemamyDomSerializerTest extends JiemamySerializerTest { - - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView())); - serializer = jiemamy.getSerializer(); - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - serializer = null; - jiemamy = null; - } - -} Copied: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/JiemamyDomSerializerTest.java (from rev 2975, artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/JiemamyDomSerializerTest.java) =================================================================== --- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/JiemamyDomSerializerTest.java (rev 0) +++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/JiemamyDomSerializerTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,57 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/01/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.internal.serializer; + +import org.junit.After; +import org.junit.Before; + +import org.jiemamy.Artemis; +import org.jiemamy.ArtemisView; +import org.jiemamy.Jiemamy; + +/** + * {@link JiemamyDomSerializer}のテストクラス。 + * + * @author daisuke + */ +public class JiemamyDomSerializerTest extends JiemamySerializerTest { + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView())); + serializer = jiemamy.getSerializer(); + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + serializer = null; + jiemamy = null; + } + +} Modified: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/JiemamySerializerTest.java =================================================================== --- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/JiemamySerializerTest.java 2009-03-20 15:22:38 UTC (rev 2971) +++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/JiemamySerializerTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -16,7 +16,7 @@ * either express or implied. See the License for the specific language * governing permissions and limitations under the License. */ -package org.jiemamy.serializer; +package org.jiemamy.internal.serializer; import static org.hamcrest.CoreMatchers.instanceOf; import static org.hamcrest.CoreMatchers.is; @@ -51,6 +51,7 @@ import org.jiemamy.model.entity.ViewModel; import org.jiemamy.model.node.NodeAdapter; import org.jiemamy.model.node.StickyModel; +import org.jiemamy.serializer.JiemamySerializer; import org.jiemamy.utils.XpathUtil; /** Deleted: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/SerializationTest.java =================================================================== --- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/SerializationTest.java 2009-03-20 15:22:38 UTC (rev 2971) +++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/SerializationTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,345 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2008/06/09 - * - * 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.serializer; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertThat; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.InputStream; -import java.io.UnsupportedEncodingException; -import java.util.Collection; -import java.util.List; -import java.util.Map; - -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; -import org.apache.commons.jxpath.JXPathContext; -import org.apache.commons.lang.CharEncoding; -import org.apache.commons.lang.ClassUtils; -import org.custommonkey.xmlunit.DetailedDiff; -import org.custommonkey.xmlunit.Diff; -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.jiemamy.AllValidator; -import org.jiemamy.Artemis; -import org.jiemamy.ArtemisView; -import org.jiemamy.Jiemamy; -import org.jiemamy.JiemamyFactory; -import org.jiemamy.internal.test.TestModelBuilder; -import org.jiemamy.internal.test.ViewTestModelBuilder; -import org.jiemamy.model.RootModel; -import org.jiemamy.model.attribute.AttributeModel; -import org.jiemamy.model.attribute.ColumnRef; -import org.jiemamy.model.dataset.DataSetModel; -import org.jiemamy.model.dataset.RecordModel; -import org.jiemamy.model.datatype.DomainModel; -import org.jiemamy.model.entity.TableModel; -import org.jiemamy.model.entity.TableRef; -import org.jiemamy.model.entity.ViewModel; -import org.jiemamy.utils.model.EqualsUtil; -import org.jiemamy.utils.model.RootModelUtil; -import org.jiemamy.validator.Problem; -import org.jiemamy.validator.Validator; - -/** - * モデルのシリアライズ全体のテスト。 - * コードで作ったモデル -(serialize)-> XML -(deserialize-> 復元モデルを比較して同一性をチェックする。 - * @author daisuke - */ -public class SerializationTest { - - private static Logger logger = LoggerFactory.getLogger(SerializationTest.class); - - - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - } - - /** - * とりあえずXMLに書き込んでみる。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test01_とりあえずXMLに書き込んでみる() throws Exception { - Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView())); - TestModelBuilder mb = new ViewTestModelBuilder(jiemamy); - mb.build(); - JiemamyFactory factory = jiemamy.getFactory(); - JiemamySerializer serializer = jiemamy.getSerializer(); - - ByteArrayOutputStream out = null; - RootModel rootModel = factory.getRootModel(); - - try { - out = new ByteArrayOutputStream(); - serializer.serialize(rootModel, out); - } finally { - IOUtils.closeQuietly(out); - } - - String xml = out.toString(CharEncoding.UTF_8); - - assertThat(xml, is(notNullValue())); - } - - /** - * とりあえずXMLから読み込んでみる。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test02_とりあえずXMLから読み込んでみる() throws Exception { - Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView())); - JiemamySerializer serializer = jiemamy.getSerializer(); - - InputStream in = null; - RootModel rootModel; - try { - in = SerializationTest.class.getResourceAsStream("/sample.xml"); - rootModel = serializer.deserialize(in); - } finally { - IOUtils.closeQuietly(in); - } - - assertThat(rootModel, is(notNullValue())); - - JXPathContext jxpath = JXPathContext.newContext(rootModel); - - logger.info("RootModel(Id):" + rootModel.getId()); - assertThat(jxpath.getValue("id").toString(), is("d5a96af3-b1e9-4285-a8ef-c491ce5ae308")); - - logger.info("RootModel(Dialect):" + rootModel.getDialectClassName()); - assertThat((String) jxpath.getValue("dialectClassName"), is("org.jiemamy.dialect.mysql.MySqlDialect")); - - logger.info("RootModel(BeginScript):" + rootModel.getBeginScript()); - assertThat((String) jxpath.getValue("beginScript"), is("BEGIN;")); - - logger.info("RootModel(EndScript):" + rootModel.getEndScript()); - assertThat((String) jxpath.getValue("endScript"), is("COMMIT;")); - - logger.info("RootModel(Description):" + rootModel.getDescription()); - assertThat((String) jxpath.getValue("description"), is("Jiemamyテストモデル1")); - - logger.info("RootModel(SchemaName):" + rootModel.getSchemaName()); - assertThat((String) jxpath.getValue("schemaName"), is("FOO")); - - logger.info("***Domains"); - List<DomainModel> domains = rootModel.getDomains(); - for (DomainModel domainModel : domains) { - logger.info(" " + domainModel); - } - assertThat(domains.size(), is(2)); - assertThat((String) jxpath.getValue("domains[1]/name"), is("ID")); - assertThat(jxpath.getValue("domains[1]/logicalName"), is(nullValue())); - assertThat((String) jxpath.getValue("domains[2]/name"), is("NAME")); - assertThat(jxpath.getValue("domains[2]/logicalName"), is(nullValue())); - - logger.info("***Entities"); - Collection<TableModel> tables = RootModelUtil.getEntities(rootModel, TableModel.class); - for (TableModel tableModel : tables) { - logger.info(" Table:" + tableModel.getId() + "," + tableModel.getName() + "," - + tableModel.getLogicalName() + "," + tableModel.getDescription()); - - for (AttributeModel attribute : tableModel.getAttributes()) { - logger.info(" " + attribute); - } - } - assertThat(tables.size(), is(2)); - - Collection<ViewModel> views = RootModelUtil.getEntities(rootModel, ViewModel.class); - for (ViewModel view : views) { - logger.info(" View:" + view); - } - assertThat(views.size(), is(1)); - - logger.info("***DataSets"); - List<DataSetModel> dataSets = rootModel.getDataSets(); - for (DataSetModel dataSet : dataSets) { - logger.info(" DataSet:" + dataSet.getId() + "," + dataSet.getName()); - for (Map.Entry<TableRef, List<RecordModel>> entry : dataSet.getRecords().entrySet()) { - logger.info(" TableRef:" + entry.getKey()); - for (RecordModel recordModel : entry.getValue()) { - for (Map.Entry<ColumnRef, String> e2 : recordModel.getValues().entrySet()) { - logger.info(" " + e2.getKey() + ":" + e2.getValue()); - } - } - } - } - assertThat(dataSets.size(), is(2)); - } - - /** - * 往復テスト1(RXRX)。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test03_往復テスト1_RXRX() throws Exception { - Jiemamy jiemamy1 = Jiemamy.newInstance(new Artemis(new ArtemisView())); - Jiemamy jiemamy2 = Jiemamy.newInstance(new Artemis(new ArtemisView())); - JiemamySerializer serializer1 = jiemamy1.getSerializer(); - JiemamySerializer serializer2 = jiemamy2.getSerializer(); - Validator validator = new AllValidator(); - - new ViewTestModelBuilder(jiemamy1).build(); - RootModel rootModel1 = jiemamy1.getFactory().getRootModel(); - Collection<Problem> problems1 = validator.validate(rootModel1); - for (Problem problem : problems1) { - logger.error(problem.getMessage()); - } - - // rootModel1 -> xml1 - String xml1 = convertRootModelToXml(serializer1, rootModel1); - - // xml1 -> rootModel2 - RootModel rootModel2 = convertXmlToRootModel(xml1, serializer2); - Collection<Problem> problems2 = validator.validate(rootModel2); - for (Problem problem : problems2) { - logger.warn(problem.getMessage()); - } - - // rootModel2 -> xml2 - String xml2 = convertRootModelToXml(serializer2, rootModel2); - - // 参考のため、targetディレクトリに出力XMLを記録 - FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) - + "_test1_xml1.xml"), xml1, CharEncoding.UTF_8); - - FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) - + "_test1_xml2.xml"), xml2, CharEncoding.UTF_8); - - EqualsUtil.equals(rootModel2, rootModel1); - - FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) - + "_test1_gtree1.txt"), EqualsUtil.rightGTree, CharEncoding.UTF_8); - - FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) - + "_test1_gtree2.txt"), EqualsUtil.leftGTree, CharEncoding.UTF_8); - - DetailedDiff diff = new DetailedDiff(new Diff(xml1, xml2)); - assertThat(diff.getAllDifferences().toString(), diff.similar(), is(true)); - assertEquals(EqualsUtil.rightGTree, EqualsUtil.leftGTree); - assertThat(problems1.size(), is(0)); // 一応バリデーションを行っておく - assertThat(problems2.size(), is(0)); // 一応バリデーションを行っておく - } - - /** - * 往復テスト2(XRXR)。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test04_往復テスト2_XRXR() throws Exception { - Jiemamy jiemamy1 = Jiemamy.newInstance(new Artemis(new ArtemisView())); - Jiemamy jiemamy2 = Jiemamy.newInstance(new Artemis(new ArtemisView())); - JiemamySerializer serializer1 = jiemamy1.getSerializer(); - JiemamySerializer serializer2 = jiemamy2.getSerializer(); - Validator validator = new AllValidator(); - - String xml1 = IOUtils.toString(SerializationTest.class.getResourceAsStream("/sample.xml"), CharEncoding.UTF_8); - - // xml1 -> rootModel1 - RootModel rootModel1 = convertXmlToRootModel(xml1, serializer1); - Collection<Problem> problem1 = validator.validate(rootModel1); - for (Problem problem : problem1) { - logger.error(problem.getMessage()); - } - - // rootModel1 -> xml2 - String xml2 = convertRootModelToXml(serializer2, rootModel1); - - // xml1 -> rootModel2 - RootModel rootModel2 = convertXmlToRootModel(xml2, serializer2); - Collection<Problem> problem2 = validator.validate(rootModel2); - - // 参考のため、targetディレクトリに出力XMLを記録 - FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) - + "_test2_xml1.xml"), xml1, CharEncoding.UTF_8); - - FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) - + "_test2_xml2.xml"), xml2, CharEncoding.UTF_8); - - EqualsUtil.equals(rootModel2, rootModel1); - - FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) - + "_test2_gtree1.txt"), EqualsUtil.rightGTree, CharEncoding.UTF_8); - - FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) - + "_test2_gtree2.txt"), EqualsUtil.leftGTree, CharEncoding.UTF_8); - - DetailedDiff diff = new DetailedDiff(new Diff(xml1, xml2)); - assertThat(diff.getAllDifferences().toString(), diff.similar(), is(true)); - assertEquals(EqualsUtil.rightGTree, EqualsUtil.leftGTree); - assertThat(problem1.size(), is(0)); // 一応バリデーションを行っておく - assertThat(problem2.size(), is(0)); // 一応バリデーションを行っておく - } - - private String convertRootModelToXml(JiemamySerializer serializer, RootModel rootModel) - throws UnsupportedEncodingException, SerializationException { - String xml; - ByteArrayOutputStream out = null; - - try { - out = new ByteArrayOutputStream(); - serializer.serialize(rootModel, out); - xml = out.toString(CharEncoding.UTF_8); - } finally { - IOUtils.closeQuietly(out); - } - return xml; - } - - private RootModel convertXmlToRootModel(String xml, JiemamySerializer serializer) - throws UnsupportedEncodingException, SerializationException { - RootModel rootModel; - InputStream in = null; - try { - in = new ByteArrayInputStream(xml.getBytes(CharEncoding.UTF_8)); - rootModel = serializer.deserialize(in); - } finally { - IOUtils.closeQuietly(in); - } - return rootModel; - } -} Copied: artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/SerializationTest.java (from rev 2975, artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/serializer/SerializationTest.java) =================================================================== --- artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/SerializationTest.java (rev 0) +++ artemis/trunk/jiemamy-artemis-test/src/test/java/org/jiemamy/internal/serializer/SerializationTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,347 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2008/06/09 + * + * 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.internal.serializer; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertThat; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.InputStream; +import java.io.UnsupportedEncodingException; +import java.util.Collection; +import java.util.List; +import java.util.Map; + +import org.apache.commons.io.FileUtils; +import org.apache.commons.io.IOUtils; +import org.apache.commons.jxpath.JXPathContext; +import org.apache.commons.lang.CharEncoding; +import org.apache.commons.lang.ClassUtils; +import org.custommonkey.xmlunit.DetailedDiff; +import org.custommonkey.xmlunit.Diff; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.jiemamy.Artemis; +import org.jiemamy.ArtemisView; +import org.jiemamy.Jiemamy; +import org.jiemamy.JiemamyFactory; +import org.jiemamy.internal.test.TestModelBuilder; +import org.jiemamy.internal.test.ViewTestModelBuilder; +import org.jiemamy.model.RootModel; +import org.jiemamy.model.attribute.AttributeModel; +import org.jiemamy.model.attribute.ColumnRef; +import org.jiemamy.model.dataset.DataSetModel; +import org.jiemamy.model.dataset.RecordModel; +import org.jiemamy.model.datatype.DomainModel; +import org.jiemamy.model.entity.TableModel; +import org.jiemamy.model.entity.TableRef; +import org.jiemamy.model.entity.ViewModel; +import org.jiemamy.serializer.JiemamySerializer; +import org.jiemamy.serializer.SerializationException; +import org.jiemamy.utils.model.EqualsUtil; +import org.jiemamy.utils.model.RootModelUtil; +import org.jiemamy.validator.AllValidator; +import org.jiemamy.validator.Problem; +import org.jiemamy.validator.Validator; + +/** + * モデルのシリアライズ全体のテスト。 + * コードで作ったモデル -(serialize)-> XML -(deserialize-> 復元モデルを比較して同一性をチェックする。 + * @author daisuke + */ +public class SerializationTest { + + private static Logger logger = LoggerFactory.getLogger(SerializationTest.class); + + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + } + + /** + * とりあえずXMLに書き込んでみる。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test01_とりあえずXMLに書き込んでみる() throws Exception { + Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView())); + TestModelBuilder mb = new ViewTestModelBuilder(jiemamy); + mb.build(); + JiemamyFactory factory = jiemamy.getFactory(); + JiemamySerializer serializer = jiemamy.getSerializer(); + + ByteArrayOutputStream out = null; + RootModel rootModel = factory.getRootModel(); + + try { + out = new ByteArrayOutputStream(); + serializer.serialize(rootModel, out); + } finally { + IOUtils.closeQuietly(out); + } + + String xml = out.toString(CharEncoding.UTF_8); + + assertThat(xml, is(notNullValue())); + } + + /** + * とりあえずXMLから読み込んでみる。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test02_とりあえずXMLから読み込んでみる() throws Exception { + Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView())); + JiemamySerializer serializer = jiemamy.getSerializer(); + + InputStream in = null; + RootModel rootModel; + try { + in = SerializationTest.class.getResourceAsStream("/sample.xml"); + rootModel = serializer.deserialize(in); + } finally { + IOUtils.closeQuietly(in); + } + + assertThat(rootModel, is(notNullValue())); + + JXPathContext jxpath = JXPathContext.newContext(rootModel); + + logger.info("RootModel(Id):" + rootModel.getId()); + assertThat(jxpath.getValue("id").toString(), is("d5a96af3-b1e9-4285-a8ef-c491ce5ae308")); + + logger.info("RootModel(Dialect):" + rootModel.getDialectClassName()); + assertThat((String) jxpath.getValue("dialectClassName"), is("org.jiemamy.dialect.mysql.MySqlDialect")); + + logger.info("RootModel(BeginScript):" + rootModel.getBeginScript()); + assertThat((String) jxpath.getValue("beginScript"), is("BEGIN;")); + + logger.info("RootModel(EndScript):" + rootModel.getEndScript()); + assertThat((String) jxpath.getValue("endScript"), is("COMMIT;")); + + logger.info("RootModel(Description):" + rootModel.getDescription()); + assertThat((String) jxpath.getValue("description"), is("Jiemamyテストモデル1")); + + logger.info("RootModel(SchemaName):" + rootModel.getSchemaName()); + assertThat((String) jxpath.getValue("schemaName"), is("FOO")); + + logger.info("***Domains"); + List<DomainModel> domains = rootModel.getDomains(); + for (DomainModel domainModel : domains) { + logger.info(" " + domainModel); + } + assertThat(domains.size(), is(2)); + assertThat((String) jxpath.getValue("domains[1]/name"), is("ID")); + assertThat(jxpath.getValue("domains[1]/logicalName"), is(nullValue())); + assertThat((String) jxpath.getValue("domains[2]/name"), is("NAME")); + assertThat(jxpath.getValue("domains[2]/logicalName"), is(nullValue())); + + logger.info("***Entities"); + Collection<TableModel> tables = RootModelUtil.getEntities(rootModel, TableModel.class); + for (TableModel tableModel : tables) { + logger.info(" Table:" + tableModel.getId() + "," + tableModel.getName() + "," + + tableModel.getLogicalName() + "," + tableModel.getDescription()); + + for (AttributeModel attribute : tableModel.getAttributes()) { + logger.info(" " + attribute); + } + } + assertThat(tables.size(), is(2)); + + Collection<ViewModel> views = RootModelUtil.getEntities(rootModel, ViewModel.class); + for (ViewModel view : views) { + logger.info(" View:" + view); + } + assertThat(views.size(), is(1)); + + logger.info("***DataSets"); + List<DataSetModel> dataSets = rootModel.getDataSets(); + for (DataSetModel dataSet : dataSets) { + logger.info(" DataSet:" + dataSet.getId() + "," + dataSet.getName()); + for (Map.Entry<TableRef, List<RecordModel>> entry : dataSet.getRecords().entrySet()) { + logger.info(" TableRef:" + entry.getKey()); + for (RecordModel recordModel : entry.getValue()) { + for (Map.Entry<ColumnRef, String> e2 : recordModel.getValues().entrySet()) { + logger.info(" " + e2.getKey() + ":" + e2.getValue()); + } + } + } + } + assertThat(dataSets.size(), is(2)); + } + + /** + * 往復テスト1(RXRX)。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test03_往復テスト1_RXRX() throws Exception { + Jiemamy jiemamy1 = Jiemamy.newInstance(new Artemis(new ArtemisView())); + Jiemamy jiemamy2 = Jiemamy.newInstance(new Artemis(new ArtemisView())); + JiemamySerializer serializer1 = jiemamy1.getSerializer(); + JiemamySerializer serializer2 = jiemamy2.getSerializer(); + Validator validator = new AllValidator(); + + new ViewTestModelBuilder(jiemamy1).build(); + RootModel rootModel1 = jiemamy1.getFactory().getRootModel(); + Collection<Problem> problems1 = validator.validate(rootModel1); + for (Problem problem : problems1) { + logger.error(problem.getMessage()); + } + + // rootModel1 -> xml1 + String xml1 = convertRootModelToXml(serializer1, rootModel1); + + // xml1 -> rootModel2 + RootModel rootModel2 = convertXmlToRootModel(xml1, serializer2); + Collection<Problem> problems2 = validator.validate(rootModel2); + for (Problem problem : problems2) { + logger.warn(problem.getMessage()); + } + + // rootModel2 -> xml2 + String xml2 = convertRootModelToXml(serializer2, rootModel2); + + // 参考のため、targetディレクトリに出力XMLを記録 + FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) + + "_test1_xml1.xml"), xml1, CharEncoding.UTF_8); + + FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) + + "_test1_xml2.xml"), xml2, CharEncoding.UTF_8); + + EqualsUtil.equals(rootModel2, rootModel1); + + FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) + + "_test1_gtree1.txt"), EqualsUtil.rightGTree, CharEncoding.UTF_8); + + FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) + + "_test1_gtree2.txt"), EqualsUtil.leftGTree, CharEncoding.UTF_8); + + DetailedDiff diff = new DetailedDiff(new Diff(xml1, xml2)); + assertThat(diff.getAllDifferences().toString(), diff.similar(), is(true)); + assertEquals(EqualsUtil.rightGTree, EqualsUtil.leftGTree); + assertThat(problems1.size(), is(0)); // 一応バリデーションを行っておく + assertThat(problems2.size(), is(0)); // 一応バリデーションを行っておく + } + + /** + * 往復テスト2(XRXR)。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test04_往復テスト2_XRXR() throws Exception { + Jiemamy jiemamy1 = Jiemamy.newInstance(new Artemis(new ArtemisView())); + Jiemamy jiemamy2 = Jiemamy.newInstance(new Artemis(new ArtemisView())); + JiemamySerializer serializer1 = jiemamy1.getSerializer(); + JiemamySerializer serializer2 = jiemamy2.getSerializer(); + Validator validator = new AllValidator(); + + String xml1 = IOUtils.toString(SerializationTest.class.getResourceAsStream("/sample.xml"), CharEncoding.UTF_8); + + // xml1 -> rootModel1 + RootModel rootModel1 = convertXmlToRootModel(xml1, serializer1); + Collection<Problem> problem1 = validator.validate(rootModel1); + for (Problem problem : problem1) { + logger.error(problem.getMessage()); + } + + // rootModel1 -> xml2 + String xml2 = convertRootModelToXml(serializer2, rootModel1); + + // xml1 -> rootModel2 + RootModel rootModel2 = convertXmlToRootModel(xml2, serializer2); + Collection<Problem> problem2 = validator.validate(rootModel2); + + // 参考のため、targetディレクトリに出力XMLを記録 + FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) + + "_test2_xml1.xml"), xml1, CharEncoding.UTF_8); + + FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) + + "_test2_xml2.xml"), xml2, CharEncoding.UTF_8); + + EqualsUtil.equals(rootModel2, rootModel1); + + FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) + + "_test2_gtree1.txt"), EqualsUtil.rightGTree, CharEncoding.UTF_8); + + FileUtils.writeStringToFile(new File("./target/" + ClassUtils.getShortClassName(this.getClass()) + + "_test2_gtree2.txt"), EqualsUtil.leftGTree, CharEncoding.UTF_8); + + DetailedDiff diff = new DetailedDiff(new Diff(xml1, xml2)); + assertThat(diff.getAllDifferences().toString(), diff.similar(), is(true)); + assertEquals(EqualsUtil.rightGTree, EqualsUtil.leftGTree); + assertThat(problem1.size(), is(0)); // 一応バリデーションを行っておく + assertThat(problem2.size(), is(0)); // 一応バリデーションを行っておく + } + + private String convertRootModelToXml(JiemamySerializer serializer, RootModel rootModel) + throws UnsupportedEncodingException, SerializationException { + String xml; + ByteArrayOutputStream out = null; + + try { + out = new ByteArrayOutputStream(); + serializer.serialize(rootModel, out); + xml = out.toString(CharEncoding.UTF_8); + } finally { + IOUtils.closeQuietly(out); + } + return xml; + } + + private RootModel convertXmlToRootModel(String xml, JiemamySerializer serializer) + throws UnsupportedEncodingException, SerializationException { + RootModel rootModel; + InputStream in = null; + try { + in = new ByteArrayInputStream(xml.getBytes(CharEncoding.UTF_8)); + rootModel = serializer.deserialize(in); + } finally { + IOUtils.closeQuietly(in); + } + return rootModel; + } +} Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/generic/GenericDialect.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/generic/GenericDialect.java 2009-03-21 04:23:00 UTC (rev 2975) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/dialect/generic/GenericDialect.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -59,20 +59,20 @@ static { List<BuiltinDataTypeMold> list = CollectionsUtil.newArrayList(); // FIXME 適当 - list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.CHARACTER, SizedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.VARCHAR, SizedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.CLOB, SizedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BLOB, SizedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BIT, SizedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.VARBIT, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.INTEGER)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.SMALLINT)); list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.NUMERIC, PrecisionedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DECIMAL, PrecisionedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.INTEGER)); - list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.SMALLINT)); list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.FLOAT, PrecisionedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.REAL, PrecisionedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DOUBLE, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BIT, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.VARBIT, SizedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BOOLEAN)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.CHARACTER, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.VARCHAR, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.CLOB, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.BLOB, SizedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.DATE)); list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.TIME, TimezonedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(DataTypeCategory.TIMESTAMP, TimezonedDataTypeAdapter.class)); Modified: artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/ReferenceResolverImpl.java =================================================================== --- artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/ReferenceResolverImpl.java 2009-03-21 04:23:00 UTC (rev 2975) +++ artemis/trunk/jiemamy-core/src/main/java/org/jiemamy/internal/ReferenceResolverImpl.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -32,7 +32,6 @@ import org.slf4j.LoggerFactory; import org.jiemamy.ReferenceResolver; -import org.jiemamy.ReferenceResolverImplTest; import org.jiemamy.model.ElementReference; import org.jiemamy.model.JiemamyElement; import org.jiemamy.model.RootModel; Deleted: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ArtemisJiemamyFactoryTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ArtemisJiemamyFactoryTest.java 2009-03-21 04:23:00 UTC (rev 2975) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ArtemisJiemamyFactoryTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,314 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2009/01/08 - * - * 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.equalTo; -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.sameInstance; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import java.util.List; -import java.util.UUID; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.jiemamy.model.JiemamyElement; -import org.jiemamy.model.RootModel; -import org.jiemamy.model.attribute.ColumnModel; -import org.jiemamy.model.attribute.ColumnRef; -import org.jiemamy.model.attribute.constraint.ColumnCheckConstraint; -import org.jiemamy.model.attribute.constraint.ForeignKey; -import org.jiemamy.model.attribute.constraint.NotNullConstraint; -import org.jiemamy.model.attribute.constraint.PrimaryKey; -import org.jiemamy.model.attribute.constraint.TableCheckConstraint; -import org.jiemamy.model.attribute.constraint.UniqueKey; -import org.jiemamy.model.dataset.DataSetModel; -import org.jiemamy.model.dataset.RecordModel; -import org.jiemamy.model.datatype.DomainModel; -import org.jiemamy.model.datatype.DomainRef; -import org.jiemamy.model.entity.TableModel; -import org.jiemamy.model.entity.TableRef; -import org.jiemamy.model.entity.ViewModel; -import org.jiemamy.model.index.IndexColumnModel; -import org.jiemamy.model.index.IndexModel; - -/** - * {@link ArtemisJiemamyFactoryTest}のテストクラス。 - * - * @author daisuke - */ -public class ArtemisJiemamyFactoryTest { - - private static Logger logger = LoggerFactory.getLogger(ArtemisJiemamyFactoryTest.class); - - private JiemamyFactory factory; - - private Jiemamy jiemamy; - - - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - jiemamy = Jiemamy.newInstance(); - factory = jiemamy.getFactory(); - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - factory = null; - jiemamy = null; - } - - /** - * 各取得メソッドはnullを返さない。 - * - * @throws Exception 例外が発生した場合Xt - */ - @Test - public void test01_各取得メソッドはnullを返さない() throws Exception { - assertThat(factory.getImplementation(), is(notNullValue())); - assertThat(factory.getSerializer(), is(notNullValue())); - assertThat(factory.getSupportedSpecs(), is(notNullValue())); - } - - /** - * {@link JiemamyFactory#hasRootModel()}が正常に機能する。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test02_hasRootModelが正常に機能する() throws Exception { - assertThat(factory.hasRootModel(), is(false)); - factory.getRootModel(); - assertThat(factory.hasRootModel(), is(true)); - } - - /** - * setImplementation, setJiemamyは呼び出せない。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test03_setImplementation_setJiemamyは呼び出せない() throws Exception { - try { - factory.setImplementation(new Artemis()); - fail(); - } catch (IllegalStateException e) { - } - try { - factory.setJiemamy(jiemamy); - fail(); - } catch (IllegalStateException e) { - } - } - - /** - * Jiemamyクラスは生成でき_その他クラスは生成できない。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test04_Jiemamyクラスは生成でき_その他クラスは生成できない() throws Exception { - RootModel rootModel = factory.newModel(RootModel.class); - assertThat(rootModel, is(notNullValue())); - - try { - factory.newModel(JiemamyElementMock.class); - fail(); - } catch (IllegalArgumentException e) { - // success - } - } - - /** - * 各種COREモデルが問題なく生成できる。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test05_各種COREモデルが問題なく生成できる() throws Exception { - assertThat(factory.newModel(TableModel.class), is(notNullValue())); - assertThat(factory.newModel(ViewModel.class), is(notNullValue())); - assertThat(factory.newModel(ColumnModel.class), is(notNullValue())); - assertThat(factory.newModel(PrimaryKey.class), is(notNullValue())); - assertThat(factory.newModel(UniqueKey.class), is(notNullValue())); - assertThat(factory.newModel(ForeignKey.class), is(notNullValue())); - assertThat(factory.newModel(TableCheckConstraint.class), is(notNullValue())); - assertThat(factory.newModel(ColumnCheckConstraint.class), is(notNullValue())); - assertThat(factory.newModel(NotNullConstraint.class), is(notNullValue())); - assertThat(factory.newModel(DomainModel.class), is(notNullValue())); - assertThat(factory.newModel(DataSetModel.class), is(notNullValue())); - assertThat(factory.newModel(RecordModel.class), is(notNullValue())); - assertThat(factory.newModel(IndexModel.class), is(notNullValue())); - assertThat(factory.newModel(IndexColumnModel.class), is(notNullValue())); - - TableModel tableModel = factory.newModel(TableModel.class); - TableRef tableRef = factory.newReference(tableModel); - ColumnModel columnModel = factory.newModel(ColumnModel.class); - ColumnRef columnRef = factory.newReference(columnModel); - DomainModel domainModel = factory.newModel(DomainModel.class); - DomainRef domainRef = factory.newReference(domainModel); - assertThat(tableRef, is(notNullValue())); - assertThat(tableRef.getReferenceId(), is(equalTo(tableModel.getId()))); - assertThat(columnRef, is(notNullValue())); - assertThat(columnRef.getReferenceId(), is(equalTo(columnModel.getId()))); - assertThat(domainRef, is(notNullValue())); - assertThat(domainRef.getReferenceId(), is(equalTo(domainModel.getId()))); - } - - /** - * IDを指定することにより、そのIDを持つモデルが生成できる。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test06_IDを指定することにより_そのIDを持つモデルが生成できる() throws Exception { - UUID id = UUID.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff"); - - ColumnModel[] c = new ColumnModel[] { - factory.newModel(ColumnModel.class), - factory.newModel(ColumnModel.class), - factory.newModel(ColumnModel.class, id), - factory.newModel(ColumnModel.class, id), - factory.newModel(ColumnModel.class), - factory.newModel(ColumnModel.class) - }; - - for (int i = 0; i < c.length; i++) { - logger.info(i + " = " + c[i].getId()); - } - - assertThat(c[0].getId(), not(id)); - assertThat(c[1].getId(), not(id)); - assertThat(c[2].getId(), is(id)); - assertThat(c[3].getId(), is(id)); - assertThat(c[4].getId(), not(id)); - assertThat(c[5].getId(), not(id)); - - for (int i = 0; i < c.length; i++) { - for (int j = i; j < c.length; j++) { - boolean sameCondition = (i == j || (i == 2 && j == 3) || (i == 3 && j == 2)); - if (c[i].getId().equals(c[j].getId())) { - assertThat(sameCondition, is(true)); - } else { - assertThat(sameCondition, is(false)); - } - } - } - } - - /** - * リファレンスを生成し、解決してみる。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test07_リファレンスを生成し_解決してみる() throws Exception { - ColumnModel columnModel = factory.newModel(ColumnModel.class); - ColumnRef columnRef = factory.newReference(columnModel); - - assertThat(columnRef, is(notNullValue())); - assertThat(columnRef.getReferenceId(), is(columnModel.getId())); - logger.debug("Element = " + columnModel.getId()); - logger.debug("Referebce = " + columnRef.getReferenceId()); - - ColumnModel resolved = jiemamy.getReferenceResolver().resolve(columnRef); - assertThat(resolved, is(sameInstance(columnModel))); - } - - /** - * ファクトリは複数のRootModelを生成できない。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test08_ファクトリは複数のRootModelを生成できない() throws Exception { - // RootModelを1つ生成する。 - RootModel rootModel1 = - factory.newModel(RootModel.class, UUID.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff")); - - // もう一つ生成しようと試みる。 - try { - factory.newModel(RootModel.class); - fail(); - } catch (IllegalStateException e) { - // success - } - - // ID指定で、別のIDを持つRootModelの取得を試みる。 - try { - factory.getRootModel(UUID.fromString("00000000-0000-0000-0000-000000000000")); - fail(); - } catch (IllegalStateException e) { - // success - } - - // 最初に指定したIDで取得を試みる。 - RootModel rootModel2 = factory.getRootModel(UUID.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff")); - RootModel rootModel3 = factory.getRootModel(); - - // 取れるRootModelのインスタンスは同一である。 - assertThat(rootModel2, is(sameInstance(rootModel1))); - assertThat(rootModel3, is(sameInstance(rootModel1))); - } - - - private static class JiemamyElementMock implements JiemamyElement { - - public <T>T getAdapter(Class<T> adapterClass) { - return null; - } - - public List<Object> getAdapters() { - return null; - } - - public UUID getId() { - return null; - } - - public Jiemamy getJiemamy() { - return null; - } - - public boolean hasAdapter(Class<?> adapterClass) { - return false; - } - - public void registerAdapter(Object adapter) { - } - - } -} Deleted: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerImplTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerImplTest.java 2009-03-21 04:23:00 UTC (rev 2975) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,366 +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.After; -import org.junit.Before; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.jiemamy.JiemamyProperty.AttributeProperty; -import org.jiemamy.JiemamyProperty.EntityProperty; -import org.jiemamy.editcommand.Command; -import org.jiemamy.editcommand.CommandListener; -import org.jiemamy.internal.CommandProcessorImpl; -import org.jiemamy.internal.EventBrokerImpl; -import org.jiemamy.internal.editcommand.AddAttributeCommand; -import org.jiemamy.internal.editcommand.AddColumnToColumnRefListCommand; -import org.jiemamy.internal.editcommand.AddEntityToRootCommand; -import org.jiemamy.internal.editcommand.ModifyModelPropertyCommand; -import org.jiemamy.internal.editcommand.RemoveAttributeCommand; -import org.jiemamy.internal.editcommand.RemoveColumnFromColumnRefListCommand; -import org.jiemamy.model.JiemamyElement; -import org.jiemamy.model.RootModel; -import org.jiemamy.model.attribute.AttributeModel; -import org.jiemamy.model.attribute.ColumnModel; -import org.jiemamy.model.attribute.constraint.ConstraintModel; -import org.jiemamy.model.attribute.constraint.PrimaryKey; -import org.jiemamy.model.entity.EntityModel; -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 RootModel rootModel; - - - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - jiemamy = Jiemamy.newInstance(); - factory = jiemamy.getFactory(); - rootModel = factory.newModel(RootModel.class); - eventBroker = jiemamy.getEventBroker(); - commandProcessor = new CommandProcessorImpl(eventBroker); - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - jiemamy = null; - factory = null; - rootModel = null; - eventBroker = null; - commandProcessor = null; - } - - /** - * シンプルなイベント通知の動作確認。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test01_バブリングとか無しでの通知() throws Exception { - Stack<Command> commandStack = new Stack<Command>(); - - TableModel emp = factory.newModel(TableModel.class); - TableModel dept = factory.newModel(TableModel.class); - - Command command = new ModifyModelPropertyCommand<EntityModel>(emp, EntityProperty.name, "T_EMP"); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - command = new ModifyModelPropertyCommand<EntityModel>(dept, EntityProperty.name, "T_DEPT"); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - command = new AddEntityToRootCommand(rootModel, emp); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - command = new AddEntityToRootCommand(rootModel, dept); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - // Listenerを作成、追加する。 - CommandListenerMock empListener = new CommandListenerMock(emp); - eventBroker.addListener(empListener); - CommandListenerMock deptListener = new CommandListenerMock(dept); - eventBroker.addListener(deptListener); - - // EMPに対して変更Commandを適用する。 - command = new ModifyModelPropertyCommand<EntityModel>(emp, EntityProperty.name, "newEmp"); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - assertThat(empListener.commandList.size(), is(1)); - assertThat(deptListener.commandList.size(), is(0)); - assertThat(emp.getName(), is("newEmp")); - - // Undoしてみる。 - command = commandStack.pop(); - command.execute(commandProcessor); - - 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(); - command = new ModifyModelPropertyCommand<EntityModel>(dept, EntityProperty.name, "newDept"); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - assertThat(empListener.commandList.size(), is(0)); - assertThat(deptListener.commandList.size(), is(1)); - assertThat(dept.getName(), is("newDept")); - - // Undoしてみる。 - command = commandStack.pop(); - command.execute(commandProcessor); - - assertThat(empListener.commandList.size(), is(0)); - assertThat(deptListener.commandList.size(), is(2)); - assertThat(dept.getName(), is("T_DEPT")); - } - - /** - * バブリングの動作確認。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test02_バブリング() throws Exception { - TableModel tableModel = factory.newModel(TableModel.class); - new AddEntityToRootCommand(rootModel, tableModel).execute(commandProcessor); - ColumnModel columnModel = factory.newModel(ColumnModel.class); - new AddAttributeCommand(tableModel, columnModel).execute(commandProcessor); - - // ここまでで以下の構造を構築した事になる。 - // table - // +attributes - // -columnModel - assertThat(tableModel.getAttributes().size(), is(1)); - assertThat(rootModel.getEntities().size(), is(1)); - - CommandListenerMock rootListener = new CommandListenerMock(rootModel); - eventBroker.addListener(rootListener); - CommandListenerMock tableListener = new CommandListenerMock(tableModel); - eventBroker.addListener(tableListener); - CommandListenerMock columnListener = new CommandListenerMock(columnModel); - eventBroker.addListener(columnListener); - - new ModifyModelPropertyCommand<EntityModel>(tableModel, EntityProperty.name, "T_EMP"). // tableを変更する。 - execute(commandProcessor); // tableListener, rootListenerへ通知されるはず。 - new ModifyModelPropertyCommand<AttributeModel>(columnModel, AttributeProperty.name, "ID") // columnModelを変更する。 - .execute(commandProcessor); // columnListener,tableListener,rootListenerへ通知される - new AddAttributeCommand(tableModel, factory.newModel(ColumnModel.class)) // 新たに作成したcolumnModelを追加する。 - .execute(commandProcessor); // tableListener, rootListenerへ通知されるはず。 - new AddEntityToRootCommand(rootModel, factory.newModel(TableModel.class)) // 新たに作成したtableを追加する。 - .execute(commandProcessor); // rootListenerへ通知されるはず。 - - assertThat(tableModel.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(AddAttributeCommand.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(AddAttributeCommand.class)); - assertThat(rootListener.commandList.get(3), instanceOf(AddEntityToRootCommand.class)); - - columnListener.commandList.clear(); - tableListener.commandList.clear(); - rootListener.commandList.clear(); - - // RootModelに追加しないColumnModelを作ったり、属性を変更したり。 - ColumnModel columnModel2 = factory.newModel(ColumnModel.class); - new ModifyModelPropertyCommand<AttributeModel>(columnModel2, AttributeProperty.name, "NAME") - .execute(commandProcessor); - // RootModelに追加しないColumnModelを作ったり、属性を変更したり。 - TableModel tableModel2 = factory.newModel(TableModel.class); - new ModifyModelPropertyCommand<EntityModel>(tableModel2, EntityProperty.name, "Y_DEPT") - .execute(commandProcessor); - // RootModelに追加していないTableModelにColumnModelを追加してみたり。 - new AddAttributeCommand(tableModel2, columnModel2).execute(commandProcessor); - - assertThat(columnListener.commandList.size(), is(0)); - assertThat(tableListener.commandList.size(), is(0)); - assertThat(rootListener.commandList.size(), is(0)); - } - - /** - * Tableが保持している{@link ConstraintModel}が参照する{@link ColumnModel}に対する変更も通知される。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test03_Referenceで保持した要素からのバブリング() throws Exception { - TableModel tableModel = factory.newModel(TableModel.class); - ColumnModel columnModel1 = factory.newModel(ColumnModel.class); - new AddAttributeCommand(tableModel, columnModel1).execute(commandProcessor); - ColumnModel columnModel2 = factory.newModel(ColumnModel.class); - new AddAttributeCommand(tableModel, columnModel2).execute(commandProcessor); - - PrimaryKey primaryKey = factory.newModel(PrimaryKey.class); - new AddColumnToColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), columnModel2) - .execute(commandProcessor); - new AddColumnToColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), columnModel1, 0) - .execute(commandProcessor); - new AddAttributeCommand(tableModel, primaryKey).execute(commandProcessor); - - // ここまでで以下の構造を構築した事になる。 - // table - // +attributes - // -column1 - // -column2 - // +primaryKey - // -[ref]column1 - // -[ref]column2 - - CommandListenerMock tableListener = new CommandListenerMock(tableModel); - eventBroker.addListener(tableListener); - CommandListenerMock columnListener1 = new CommandListenerMock(columnModel1); - eventBroker.addListener(columnListener1); - CommandListenerMock columnListener2 = new CommandListenerMock(columnModel2); - eventBroker.addListener(columnListener2); - CommandListenerMock pkeyListener = new CommandListenerMock(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(tableModel.getAttributes().size(), is(3)); // column1,column2,pkey - assertThat(primaryKey.getKeyColumns().size(), is(2)); // [ref]column1, [ref]column2。 - assertThat(primaryKey.getKeyColumns().get(0).getReferenceId(), is(columnModel1.getId())); - assertThat(primaryKey.getKeyColumns().get(1).getReferenceId(), is(columnModel2.getId())); - - new ModifyModelPropertyCommand<AttributeModel>(columnModel1, AttributeProperty.name, "column1") - .execute(commandProcessor); - - 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(tableModel.getAttributes().size(), is(3)); // column1,column2,pkey - assertThat(primaryKey.getKeyColumns().size(), is(2)); // [ref]column1, [ref]column2。 - assertThat(primaryKey.getKeyColumns().get(0).getReferenceId(), is(columnModel1.getId())); - assertThat(primaryKey.getKeyColumns().get(1).getReferenceId(), is(columnModel2.getId())); - - columnListener1.commandList.clear(); - columnListener2.commandList.clear(); - pkeyListener.commandList.clear(); - tableListener.commandList.clear(); - // columnをprimaryKeyから削除する。 - new RemoveColumnFromColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), columnModel1) - .execute(commandProcessor); - - 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(tableModel.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 RemoveAttributeCommand(tableModel, columnModel1).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(tableModel.getAttributes().size(), is(2)); // column2,pkey - assertThat(primaryKey.getKeyColumns().size(), is(1)); // [ref]column2。 - } - - - /** - * {@link CommandListener}のテスト用モッククラス。 - * - * @author shin1ogawa - */ - public static class CommandListenerMock implements CommandListener { - - /** 監視対象 */ - JiemamyElement target; - - /** リスナのリスト */ - List<Command> commandList = new ArrayList<Command>(); - - - /** - * インスタンスを生成する。 - * - * @param target 監視対象 - */ - public CommandListenerMock(JiemamyElement target) { - this.target = target; - } - - public void commandExecuted(Command command) { - commandList.add(command); - } - - public JiemamyElement getTargetModel() { - return target; - } - } -} Deleted: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/JiemamyPropertyTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/JiemamyPropertyTest.java 2009-03-21 04:23:00 UTC (rev 2975) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/JiemamyPropertyTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,155 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2009/01/29 - * - * 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.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Arrays; - -import org.apache.commons.lang.ClassUtils; -import org.junit.Test; - -import org.jiemamy.internal.model.attribute.constraint.AbstractConstraintModel; -import org.jiemamy.utils.ReflectionUtil; - -/** - * {@link JiemamyProperty}のテストクラス。 - * - * @author daisuke - */ -public class JiemamyPropertyTest { - - /** - * 各モデルのインターフェイスは、{@link JiemamyProperty}で示されるgetterを持つべきである。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test01_ModelHasGetter() throws Exception { - for (Class<?> enumClass : JiemamyProperty.class.getClasses()) { - if (Enum.class.isAssignableFrom(enumClass) == false) { - continue; - } - - TargetModel annot = enumClass.getAnnotation(TargetModel.class); - assertThat("JiemamyPropertyの内部列挙型はTargetModelアノテーションを持たなければならない", annot, is(notNullValue())); - - Class<?> targetModelClass = annot.value(); - for (Field field : enumClass.getFields()) { - String iserName = ReflectionUtil.convertFieldToAccessorName(field, "is"); - String getterName = ReflectionUtil.convertFieldToAccessorName(field, "get"); - try { - targetModelClass.getMethod(getterName); - } catch (NoSuchMethodException e) { - Method iserMethod; - try { - iserMethod = targetModelClass.getMethod(iserName); - if (iserMethod.getReturnType() != Boolean.class && iserMethod.getReturnType() != boolean.class) { - fail(targetModelClass.getName() + " is not have " + getterName); - } - } catch (NoSuchMethodException e2) { - fail(targetModelClass.getName() + " is not have " + getterName + " or " + iserName); - } - } - } - } - } - - /** - * 各モデルの実装クラスは、{@link JiemamyProperty}で示されるフィールドを持つべきである。 - * - * <p>Artemis特有。仕様ではない。</p> - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test02_ModelHasField() throws Exception { - for (Class<?> enumClass : JiemamyProperty.class.getClasses()) { - if (Enum.class.isAssignableFrom(enumClass) == false) { - continue; - } - - TargetModel annot = enumClass.getAnnotation(TargetModel.class); - assertThat("JiemamyPropertyの内部列挙型はTargetModelアノテーションを持たなければならない", annot, is(notNullValue())); - - Class<?> interfaceClass = annot.value(); - String implClassName = interfaceClass.getName() + "Impl"; - - Class<?> targetModelClass; - try { - targetModelClass = Class.forName(implClassName); - } catch (ClassNotFoundException e) { - String packageName = ClassUtils.getPackageName(interfaceClass); - String shortClassName = ClassUtils.getShortClassName(interfaceClass); - - implClassName = packageName + ".Abstract" + shortClassName; - targetModelClass = Class.forName(implClassName); - } - - Field[] enumFields = enumClass.getFields(); - for (Field enumField : enumFields) { - try { - targetModelClass.getDeclaredField(enumField.getName()); - } catch (NoSuchFieldException e) { - if (targetModelClass == AbstractConstraintModel.class && enumField.getName() == "name") { - // 例外 success - } else { - fail(targetModelClass.getName() + " is not have " + enumField.getName()); - } - } - } - } - } - - /** - * {@link JiemamyProperty}は、各モデルのインターフェイスのgetterで示されるプロパティを網羅すべきである。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test03_PropertyHasFieldName() throws Exception { - for (Class<?> clazz : JiemamyProperty.class.getClasses()) { - if (Enum.class.isAssignableFrom(clazz) == false) { - continue; - } - TargetModel annot = clazz.getAnnotation(TargetModel.class); - Class<?> targetModelClass = annot.value(); - Method[] methods = targetModelClass.getDeclaredMethods(); - for (Method method : methods) { - if (ReflectionUtil.isGetter(method) == false) { - continue; - } - String fieldName = ReflectionUtil.convertAccessorToFieldName(method); - try { - clazz.getField(fieldName); - } catch (NoSuchFieldException e) { - if (Arrays.asList("adapter", "adapters").contains(fieldName) == false) { - fail(clazz.getName() + " is not have " + fieldName); - } - } - } - } - - } -} Deleted: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ReferenceResolverImplTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ReferenceResolverImplTest.java 2009-03-21 04:23:00 UTC (rev 2975) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ReferenceResolverImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,237 +0,0 @@ -/* - * 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 static org.hamcrest.CoreMatchers.is; -import static org.junit.Assert.assertThat; - -import java.util.Stack; - -import org.apache.commons.lang.RandomStringUtils; -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.jiemamy.editcommand.Command; -import org.jiemamy.internal.CommandProcessorImpl; -import org.jiemamy.internal.ReferenceResolverImpl; -import org.jiemamy.internal.editcommand.AddAttributeCommand; -import org.jiemamy.internal.editcommand.AddColumnToColumnRefListCommand; -import org.jiemamy.internal.editcommand.AddEntityToRootCommand; -import org.jiemamy.internal.editcommand.RemoveAttributeCommand; -import org.jiemamy.internal.editcommand.RemoveColumnFromColumnRefListCommand; -import org.jiemamy.internal.editcommand.RemoveEntityFromRootCommand; -import org.jiemamy.model.RootModel; -import org.jiemamy.model.attribute.ColumnModel; -import org.jiemamy.model.attribute.constraint.PrimaryKey; -import org.jiemamy.model.entity.TableModel; - -/** - * {@link ReferenceResolverImpl}のテストクラス。 - * - * @author shin1ogawa - */ -public class ReferenceResolverImplTest { - - static final Logger LOGGER = LoggerFactory.getLogger(ReferenceResolverImplTest.class); - - private JiemamyFactory factory; - - private Jiemamy jiemamy; - - private EventBroker eventBroker; - - private CommandProcessorImpl commandProcessor; - - private Stack<Stack<Command>> commandStackStack; - - private RootModel rootModel; - - - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - jiemamy = Jiemamy.newInstance(); - factory = jiemamy.getFactory(); - rootModel = factory.newModel(RootModel.class); - eventBroker = jiemamy.getEventBroker(); - commandProcessor = new CommandProcessorImpl(eventBroker); - commandStackStack = new Stack<Stack<Command>>(); - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - jiemamy = null; - factory = null; - rootModel = null; - eventBroker = null; - commandProcessor = null; - commandStackStack = null; - } - - /** - * メモリリークテスト。 - * - * <p>RootModelからたどる事のないインスタンスを大量生成する。ここで{@link OutOfMemoryError}を起こしてはならない。</p> - * - * @throws Exception 例外が発生した場合 - */ - @Test - @Ignore - public void test00_メモリリークテスト() throws Exception { - for (int i = 0; i < 100000; i++) { - TableModel tableModel = factory.newModel(TableModel.class); - tableModel.setName(RandomStringUtils.randomAlphabetic(10)); - ColumnModel columnModel = factory.newModel(ColumnModel.class); - columnModel.setName(RandomStringUtils.randomAlphabetic(10)); - tableModel.getAttributes().add(columnModel); - } - } - - /** - * {@link ReferenceResolverImpl#isDescendFromElement(org.jiemamy.internal.model.JiemamyElement, java.util.UUID)} - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test01親子関係の判断() throws Exception { - Stack<Command> commandStack = new Stack<Command>(); - - TableModel tableModel = factory.newModel(TableModel.class); - Command command = new AddEntityToRootCommand(rootModel, tableModel); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - ColumnModel columnModel1 = factory.newModel(ColumnModel.class); - command = new AddAttributeCommand(tableModel, columnModel1); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - ColumnModel columnModel2 = factory.newModel(ColumnModel.class); - command = new AddAttributeCommand(tableModel, columnModel2); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - PrimaryKey primaryKey = factory.newModel(PrimaryKey.class); - command = new AddColumnToColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), columnModel2); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - command = new AddColumnToColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), columnModel1, 0); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - command = new AddAttributeCommand(tableModel, primaryKey); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - commandStackStack.push(commandStack); // 構築操作を行ったCommandStackをpushする。 - - assertThat(tableModel.getAttributes().size(), is(3)); // column1,column2,pkey - assertThat(primaryKey.getKeyColumns().size(), is(2)); // [ref]column1, [ref]column2。 - assertThat(primaryKey.getKeyColumns().get(0).getReferenceId(), is(columnModel1.getId())); - assertThat(primaryKey.getKeyColumns().get(1).getReferenceId(), is(columnModel2.getId())); - - // ここまでで以下の構造を構築した事になる。 - // table - // +attributes - // -column1 - // -column2 - // +primaryKey - // -[ref]column1 - // -[ref]column2 - - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, columnModel1.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, primaryKey.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, tableModel.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, columnModel1.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, primaryKey.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(primaryKey, columnModel1.getId()), is(true)); - - // 新たなStackを用意する。 - commandStack = new Stack<Command>(); - - // columnをprimaryKeyから削除する。 - command = new RemoveColumnFromColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), columnModel1); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, columnModel1.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, primaryKey.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, tableModel.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, columnModel1.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, primaryKey.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(primaryKey, columnModel1.getId()), is(false)); - - // columnをtableから削除する。 - command = new RemoveAttributeCommand(tableModel, columnModel1); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, columnModel1.getId()), is(false)); - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, primaryKey.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, tableModel.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, columnModel1.getId()), is(false)); - assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, primaryKey.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(primaryKey, columnModel1.getId()), is(false)); - - // tableをRootModelから削除する。 - command = new RemoveEntityFromRootCommand(rootModel, tableModel); - command.execute(commandProcessor); - commandStack.push(command.getNegateCommand()); - - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, columnModel1.getId()), is(false)); - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, primaryKey.getId()), is(false)); - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, tableModel.getId()), is(false)); - assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, columnModel1.getId()), is(false)); - assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, primaryKey.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(primaryKey, columnModel1.getId()), is(false)); - commandStackStack.push(commandStack); // 削除操作を行ったCommandStackをpushする。 - - // 一連の削除操作を全て取り消す。 - Stack<Command> deleteCommands = commandStackStack.pop(); - while (deleteCommands.isEmpty() == false) { - command = deleteCommands.pop(); - command.execute(commandProcessor); - } - - assertThat(tableModel.getAttributes().size(), is(3)); // column1,column2,pkey - assertThat(primaryKey.getKeyColumns().size(), is(2)); // [ref]column1, [ref]column2。 - assertThat(primaryKey.getKeyColumns().get(0).getReferenceId(), is(columnModel1.getId())); - assertThat(primaryKey.getKeyColumns().get(1).getReferenceId(), is(columnModel2.getId())); - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, columnModel1.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, primaryKey.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, tableModel.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, columnModel1.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, primaryKey.getId()), is(true)); - assertThat(ReferenceResolverImpl.isDescendFromElement(primaryKey, columnModel1.getId()), is(true)); - } -} Copied: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/ArtemisJiemamyFactoryTest.java (from rev 2971, artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ArtemisJiemamyFactoryTest.java) =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/ArtemisJiemamyFactoryTest.java (rev 0) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/ArtemisJiemamyFactoryTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,317 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/01/08 + * + * 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.internal; + +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.sameInstance; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.util.List; +import java.util.UUID; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.jiemamy.Artemis; +import org.jiemamy.Jiemamy; +import org.jiemamy.JiemamyFactory; +import org.jiemamy.model.JiemamyElement; +import org.jiemamy.model.RootModel; +import org.jiemamy.model.attribute.ColumnModel; +import org.jiemamy.model.attribute.ColumnRef; +import org.jiemamy.model.attribute.constraint.ColumnCheckConstraint; +import org.jiemamy.model.attribute.constraint.ForeignKey; +import org.jiemamy.model.attribute.constraint.NotNullConstraint; +import org.jiemamy.model.attribute.constraint.PrimaryKey; +import org.jiemamy.model.attribute.constraint.TableCheckConstraint; +import org.jiemamy.model.attribute.constraint.UniqueKey; +import org.jiemamy.model.dataset.DataSetModel; +import org.jiemamy.model.dataset.RecordModel; +import org.jiemamy.model.datatype.DomainModel; +import org.jiemamy.model.datatype.DomainRef; +import org.jiemamy.model.entity.TableModel; +import org.jiemamy.model.entity.TableRef; +import org.jiemamy.model.entity.ViewModel; +import org.jiemamy.model.index.IndexColumnModel; +import org.jiemamy.model.index.IndexModel; + +/** + * {@link ArtemisJiemamyFactoryTest}のテストクラス。 + * + * @author daisuke + */ +public class ArtemisJiemamyFactoryTest { + + private static Logger logger = LoggerFactory.getLogger(ArtemisJiemamyFactoryTest.class); + + private JiemamyFactory factory; + + private Jiemamy jiemamy; + + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + jiemamy = Jiemamy.newInstance(); + factory = jiemamy.getFactory(); + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + factory = null; + jiemamy = null; + } + + /** + * 各取得メソッドはnullを返さない。 + * + * @throws Exception 例外が発生した場合Xt + */ + @Test + public void test01_各取得メソッドはnullを返さない() throws Exception { + assertThat(factory.getImplementation(), is(notNullValue())); + assertThat(factory.getSerializer(), is(notNullValue())); + assertThat(factory.getSupportedSpecs(), is(notNullValue())); + } + + /** + * {@link JiemamyFactory#hasRootModel()}が正常に機能する。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test02_hasRootModelが正常に機能する() throws Exception { + assertThat(factory.hasRootModel(), is(false)); + factory.getRootModel(); + assertThat(factory.hasRootModel(), is(true)); + } + + /** + * setImplementation, setJiemamyは呼び出せない。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test03_setImplementation_setJiemamyは呼び出せない() throws Exception { + try { + factory.setImplementation(new Artemis()); + fail(); + } catch (IllegalStateException e) { + } + try { + factory.setJiemamy(jiemamy); + fail(); + } catch (IllegalStateException e) { + } + } + + /** + * Jiemamyクラスは生成でき_その他クラスは生成できない。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test04_Jiemamyクラスは生成でき_その他クラスは生成できない() throws Exception { + RootModel rootModel = factory.newModel(RootModel.class); + assertThat(rootModel, is(notNullValue())); + + try { + factory.newModel(JiemamyElementMock.class); + fail(); + } catch (IllegalArgumentException e) { + // success + } + } + + /** + * 各種COREモデルが問題なく生成できる。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test05_各種COREモデルが問題なく生成できる() throws Exception { + assertThat(factory.newModel(TableModel.class), is(notNullValue())); + assertThat(factory.newModel(ViewModel.class), is(notNullValue())); + assertThat(factory.newModel(ColumnModel.class), is(notNullValue())); + assertThat(factory.newModel(PrimaryKey.class), is(notNullValue())); + assertThat(factory.newModel(UniqueKey.class), is(notNullValue())); + assertThat(factory.newModel(ForeignKey.class), is(notNullValue())); + assertThat(factory.newModel(TableCheckConstraint.class), is(notNullValue())); + assertThat(factory.newModel(ColumnCheckConstraint.class), is(notNullValue())); + assertThat(factory.newModel(NotNullConstraint.class), is(notNullValue())); + assertThat(factory.newModel(DomainModel.class), is(notNullValue())); + assertThat(factory.newModel(DataSetModel.class), is(notNullValue())); + assertThat(factory.newModel(RecordModel.class), is(notNullValue())); + assertThat(factory.newModel(IndexModel.class), is(notNullValue())); + assertThat(factory.newModel(IndexColumnModel.class), is(notNullValue())); + + TableModel tableModel = factory.newModel(TableModel.class); + TableRef tableRef = factory.newReference(tableModel); + ColumnModel columnModel = factory.newModel(ColumnModel.class); + ColumnRef columnRef = factory.newReference(columnModel); + DomainModel domainModel = factory.newModel(DomainModel.class); + DomainRef domainRef = factory.newReference(domainModel); + assertThat(tableRef, is(notNullValue())); + assertThat(tableRef.getReferenceId(), is(equalTo(tableModel.getId()))); + assertThat(columnRef, is(notNullValue())); + assertThat(columnRef.getReferenceId(), is(equalTo(columnModel.getId()))); + assertThat(domainRef, is(notNullValue())); + assertThat(domainRef.getReferenceId(), is(equalTo(domainModel.getId()))); + } + + /** + * IDを指定することにより、そのIDを持つモデルが生成できる。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test06_IDを指定することにより_そのIDを持つモデルが生成できる() throws Exception { + UUID id = UUID.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff"); + + ColumnModel[] c = new ColumnModel[] { + factory.newModel(ColumnModel.class), + factory.newModel(ColumnModel.class), + factory.newModel(ColumnModel.class, id), + factory.newModel(ColumnModel.class, id), + factory.newModel(ColumnModel.class), + factory.newModel(ColumnModel.class) + }; + + for (int i = 0; i < c.length; i++) { + logger.info(i + " = " + c[i].getId()); + } + + assertThat(c[0].getId(), not(id)); + assertThat(c[1].getId(), not(id)); + assertThat(c[2].getId(), is(id)); + assertThat(c[3].getId(), is(id)); + assertThat(c[4].getId(), not(id)); + assertThat(c[5].getId(), not(id)); + + for (int i = 0; i < c.length; i++) { + for (int j = i; j < c.length; j++) { + boolean sameCondition = (i == j || (i == 2 && j == 3) || (i == 3 && j == 2)); + if (c[i].getId().equals(c[j].getId())) { + assertThat(sameCondition, is(true)); + } else { + assertThat(sameCondition, is(false)); + } + } + } + } + + /** + * リファレンスを生成し、解決してみる。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test07_リファレンスを生成し_解決してみる() throws Exception { + ColumnModel columnModel = factory.newModel(ColumnModel.class); + ColumnRef columnRef = factory.newReference(columnModel); + + assertThat(columnRef, is(notNullValue())); + assertThat(columnRef.getReferenceId(), is(columnModel.getId())); + logger.debug("Element = " + columnModel.getId()); + logger.debug("Referebce = " + columnRef.getReferenceId()); + + ColumnModel resolved = jiemamy.getReferenceResolver().resolve(columnRef); + assertThat(resolved, is(sameInstance(columnModel))); + } + + /** + * ファクトリは複数のRootModelを生成できない。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test08_ファクトリは複数のRootModelを生成できない() throws Exception { + // RootModelを1つ生成する。 + RootModel rootModel1 = + factory.newModel(RootModel.class, UUID.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff")); + + // もう一つ生成しようと試みる。 + try { + factory.newModel(RootModel.class); + fail(); + } catch (IllegalStateException e) { + // success + } + + // ID指定で、別のIDを持つRootModelの取得を試みる。 + try { + factory.getRootModel(UUID.fromString("00000000-0000-0000-0000-000000000000")); + fail(); + } catch (IllegalStateException e) { + // success + } + + // 最初に指定したIDで取得を試みる。 + RootModel rootModel2 = factory.getRootModel(UUID.fromString("ffffffff-ffff-ffff-ffff-ffffffffffff")); + RootModel rootModel3 = factory.getRootModel(); + + // 取れるRootModelのインスタンスは同一である。 + assertThat(rootModel2, is(sameInstance(rootModel1))); + assertThat(rootModel3, is(sameInstance(rootModel1))); + } + + + private static class JiemamyElementMock implements JiemamyElement { + + public <T>T getAdapter(Class<T> adapterClass) { + return null; + } + + public List<Object> getAdapters() { + return null; + } + + public UUID getId() { + return null; + } + + public Jiemamy getJiemamy() { + return null; + } + + public boolean hasAdapter(Class<?> adapterClass) { + return false; + } + + public void registerAdapter(Object adapter) { + } + + } +} Property changes on: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/ArtemisJiemamyFactoryTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Copied: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/EventBrokerImplTest.java (from rev 2972, artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/EventBrokerImplTest.java) =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/EventBrokerImplTest.java (rev 0) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/EventBrokerImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,367 @@ +/* + * 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.internal; + +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.After; +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.jiemamy.EventBroker; +import org.jiemamy.Jiemamy; +import org.jiemamy.JiemamyFactory; +import org.jiemamy.JiemamyProperty.AttributeProperty; +import org.jiemamy.JiemamyProperty.EntityProperty; +import org.jiemamy.editcommand.Command; +import org.jiemamy.editcommand.CommandListener; +import org.jiemamy.internal.editcommand.AddAttributeCommand; +import org.jiemamy.internal.editcommand.AddColumnToColumnRefListCommand; +import org.jiemamy.internal.editcommand.AddEntityToRootCommand; +import org.jiemamy.internal.editcommand.ModifyModelPropertyCommand; +import org.jiemamy.internal.editcommand.RemoveAttributeCommand; +import org.jiemamy.internal.editcommand.RemoveColumnFromColumnRefListCommand; +import org.jiemamy.model.JiemamyElement; +import org.jiemamy.model.RootModel; +import org.jiemamy.model.attribute.AttributeModel; +import org.jiemamy.model.attribute.ColumnModel; +import org.jiemamy.model.attribute.constraint.ConstraintModel; +import org.jiemamy.model.attribute.constraint.PrimaryKey; +import org.jiemamy.model.entity.EntityModel; +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 RootModel rootModel; + + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + jiemamy = Jiemamy.newInstance(); + factory = jiemamy.getFactory(); + rootModel = factory.newModel(RootModel.class); + eventBroker = jiemamy.getEventBroker(); + commandProcessor = new CommandProcessorImpl(eventBroker); + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + jiemamy = null; + factory = null; + rootModel = null; + eventBroker = null; + commandProcessor = null; + } + + /** + * シンプルなイベント通知の動作確認。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test01_バブリングとか無しでの通知() throws Exception { + Stack<Command> commandStack = new Stack<Command>(); + + TableModel emp = factory.newModel(TableModel.class); + TableModel dept = factory.newModel(TableModel.class); + + Command command = new ModifyModelPropertyCommand<EntityModel>(emp, EntityProperty.name, "T_EMP"); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + command = new ModifyModelPropertyCommand<EntityModel>(dept, EntityProperty.name, "T_DEPT"); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + command = new AddEntityToRootCommand(rootModel, emp); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + command = new AddEntityToRootCommand(rootModel, dept); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + // Listenerを作成、追加する。 + CommandListenerMock empListener = new CommandListenerMock(emp); + eventBroker.addListener(empListener); + CommandListenerMock deptListener = new CommandListenerMock(dept); + eventBroker.addListener(deptListener); + + // EMPに対して変更Commandを適用する。 + command = new ModifyModelPropertyCommand<EntityModel>(emp, EntityProperty.name, "newEmp"); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + assertThat(empListener.commandList.size(), is(1)); + assertThat(deptListener.commandList.size(), is(0)); + assertThat(emp.getName(), is("newEmp")); + + // Undoしてみる。 + command = commandStack.pop(); + command.execute(commandProcessor); + + 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(); + command = new ModifyModelPropertyCommand<EntityModel>(dept, EntityProperty.name, "newDept"); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + assertThat(empListener.commandList.size(), is(0)); + assertThat(deptListener.commandList.size(), is(1)); + assertThat(dept.getName(), is("newDept")); + + // Undoしてみる。 + command = commandStack.pop(); + command.execute(commandProcessor); + + assertThat(empListener.commandList.size(), is(0)); + assertThat(deptListener.commandList.size(), is(2)); + assertThat(dept.getName(), is("T_DEPT")); + } + + /** + * バブリングの動作確認。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test02_バブリング() throws Exception { + TableModel tableModel = factory.newModel(TableModel.class); + new AddEntityToRootCommand(rootModel, tableModel).execute(commandProcessor); + ColumnModel columnModel = factory.newModel(ColumnModel.class); + new AddAttributeCommand(tableModel, columnModel).execute(commandProcessor); + + // ここまでで以下の構造を構築した事になる。 + // table + // +attributes + // -columnModel + assertThat(tableModel.getAttributes().size(), is(1)); + assertThat(rootModel.getEntities().size(), is(1)); + + CommandListenerMock rootListener = new CommandListenerMock(rootModel); + eventBroker.addListener(rootListener); + CommandListenerMock tableListener = new CommandListenerMock(tableModel); + eventBroker.addListener(tableListener); + CommandListenerMock columnListener = new CommandListenerMock(columnModel); + eventBroker.addListener(columnListener); + + new ModifyModelPropertyCommand<EntityModel>(tableModel, EntityProperty.name, "T_EMP"). // tableを変更する。 + execute(commandProcessor); // tableListener, rootListenerへ通知されるはず。 + new ModifyModelPropertyCommand<AttributeModel>(columnModel, AttributeProperty.name, "ID") // columnModelを変更する。 + .execute(commandProcessor); // columnListener,tableListener,rootListenerへ通知される + new AddAttributeCommand(tableModel, factory.newModel(ColumnModel.class)) // 新たに作成したcolumnModelを追加する。 + .execute(commandProcessor); // tableListener, rootListenerへ通知されるはず。 + new AddEntityToRootCommand(rootModel, factory.newModel(TableModel.class)) // 新たに作成したtableを追加する。 + .execute(commandProcessor); // rootListenerへ通知されるはず。 + + assertThat(tableModel.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(AddAttributeCommand.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(AddAttributeCommand.class)); + assertThat(rootListener.commandList.get(3), instanceOf(AddEntityToRootCommand.class)); + + columnListener.commandList.clear(); + tableListener.commandList.clear(); + rootListener.commandList.clear(); + + // RootModelに追加しないColumnModelを作ったり、属性を変更したり。 + ColumnModel columnModel2 = factory.newModel(ColumnModel.class); + new ModifyModelPropertyCommand<AttributeModel>(columnModel2, AttributeProperty.name, "NAME") + .execute(commandProcessor); + // RootModelに追加しないColumnModelを作ったり、属性を変更したり。 + TableModel tableModel2 = factory.newModel(TableModel.class); + new ModifyModelPropertyCommand<EntityModel>(tableModel2, EntityProperty.name, "Y_DEPT") + .execute(commandProcessor); + // RootModelに追加していないTableModelにColumnModelを追加してみたり。 + new AddAttributeCommand(tableModel2, columnModel2).execute(commandProcessor); + + assertThat(columnListener.commandList.size(), is(0)); + assertThat(tableListener.commandList.size(), is(0)); + assertThat(rootListener.commandList.size(), is(0)); + } + + /** + * Tableが保持している{@link ConstraintModel}が参照する{@link ColumnModel}に対する変更も通知される。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test03_Referenceで保持した要素からのバブリング() throws Exception { + TableModel tableModel = factory.newModel(TableModel.class); + ColumnModel columnModel1 = factory.newModel(ColumnModel.class); + new AddAttributeCommand(tableModel, columnModel1).execute(commandProcessor); + ColumnModel columnModel2 = factory.newModel(ColumnModel.class); + new AddAttributeCommand(tableModel, columnModel2).execute(commandProcessor); + + PrimaryKey primaryKey = factory.newModel(PrimaryKey.class); + new AddColumnToColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), columnModel2) + .execute(commandProcessor); + new AddColumnToColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), columnModel1, 0) + .execute(commandProcessor); + new AddAttributeCommand(tableModel, primaryKey).execute(commandProcessor); + + // ここまでで以下の構造を構築した事になる。 + // table + // +attributes + // -column1 + // -column2 + // +primaryKey + // -[ref]column1 + // -[ref]column2 + + CommandListenerMock tableListener = new CommandListenerMock(tableModel); + eventBroker.addListener(tableListener); + CommandListenerMock columnListener1 = new CommandListenerMock(columnModel1); + eventBroker.addListener(columnListener1); + CommandListenerMock columnListener2 = new CommandListenerMock(columnModel2); + eventBroker.addListener(columnListener2); + CommandListenerMock pkeyListener = new CommandListenerMock(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(tableModel.getAttributes().size(), is(3)); // column1,column2,pkey + assertThat(primaryKey.getKeyColumns().size(), is(2)); // [ref]column1, [ref]column2。 + assertThat(primaryKey.getKeyColumns().get(0).getReferenceId(), is(columnModel1.getId())); + assertThat(primaryKey.getKeyColumns().get(1).getReferenceId(), is(columnModel2.getId())); + + new ModifyModelPropertyCommand<AttributeModel>(columnModel1, AttributeProperty.name, "column1") + .execute(commandProcessor); + + 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(tableModel.getAttributes().size(), is(3)); // column1,column2,pkey + assertThat(primaryKey.getKeyColumns().size(), is(2)); // [ref]column1, [ref]column2。 + assertThat(primaryKey.getKeyColumns().get(0).getReferenceId(), is(columnModel1.getId())); + assertThat(primaryKey.getKeyColumns().get(1).getReferenceId(), is(columnModel2.getId())); + + columnListener1.commandList.clear(); + columnListener2.commandList.clear(); + pkeyListener.commandList.clear(); + tableListener.commandList.clear(); + // columnをprimaryKeyから削除する。 + new RemoveColumnFromColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), columnModel1) + .execute(commandProcessor); + + 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(tableModel.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 RemoveAttributeCommand(tableModel, columnModel1).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(tableModel.getAttributes().size(), is(2)); // column2,pkey + assertThat(primaryKey.getKeyColumns().size(), is(1)); // [ref]column2。 + } + + + /** + * {@link CommandListener}のテスト用モッククラス。 + * + * @author shin1ogawa + */ + public static class CommandListenerMock implements CommandListener { + + /** 監視対象 */ + JiemamyElement target; + + /** リスナのリスト */ + List<Command> commandList = new ArrayList<Command>(); + + + /** + * インスタンスを生成する。 + * + * @param target 監視対象 + */ + public CommandListenerMock(JiemamyElement target) { + this.target = target; + } + + public void commandExecuted(Command command) { + commandList.add(command); + } + + public JiemamyElement getTargetModel() { + return target; + } + } +} Copied: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/JiemamyFacadeImplTest.java (from rev 2972, artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/facade/JiemamyFacadeImplTest.java) =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/JiemamyFacadeImplTest.java (rev 0) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/JiemamyFacadeImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,349 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/03/02 + * + * 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.internal; + +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.CoreMatchers.sameInstance; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertThat; + +import java.util.List; + +import org.apache.commons.collections15.CollectionUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import org.jiemamy.Jiemamy; +import org.jiemamy.JiemamyFactory; +import org.jiemamy.ReferenceResolver; +import org.jiemamy.JiemamyProperty.EntityProperty; +import org.jiemamy.facade.JiemamyFacade; +import org.jiemamy.facade.SavePoint; +import org.jiemamy.model.RootModel; +import org.jiemamy.model.attribute.ColumnModel; +import org.jiemamy.model.attribute.ColumnRef; +import org.jiemamy.model.attribute.constraint.PrimaryKey; +import org.jiemamy.model.entity.TableModel; +import org.jiemamy.utils.model.TableUtil; + +/** + * {@link JiemamyFacadeImpl}のテストクラス。 + * + * @author shin1ogawa + */ +public class JiemamyFacadeImplTest { + + private Jiemamy jiemamy; + + private JiemamyFacade coreFacade; + + private JiemamyFactory factory; + + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + jiemamy = Jiemamy.newInstance(); + coreFacade = new JiemamyFacadeImpl(jiemamy); + factory = jiemamy.getFactory(); + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + jiemamy = null; + coreFacade = null; + factory = null; + } + + /** + * {@link JiemamyFacadeImpl#addAttribute(TableModel, org.jiemamy.internal.model.attribute.AttributeModel)}のテスト。 + */ + @Test + public void test_addAttribute() { + SavePoint save1 = coreFacade.save(); + TableModel tableModel = factory.newModel(TableModel.class); + coreFacade.addEntity(tableModel); + ColumnModel columnModel1 = factory.newModel(ColumnModel.class); + ColumnModel columnModel2 = factory.newModel(ColumnModel.class); + ColumnModel columnModel3 = factory.newModel(ColumnModel.class); + assertThat(TableUtil.getColumns(tableModel).size(), is(0)); + + SavePoint save2 = coreFacade.save(); + coreFacade.addAttribute(tableModel, columnModel1); + assertThat(TableUtil.getColumns(tableModel).size(), is(1)); + assertThat(TableUtil.getColumns(tableModel).get(0), is(columnModel1)); + + SavePoint save3 = coreFacade.save(); + coreFacade.addAttribute(tableModel, columnModel2); + assertThat(TableUtil.getColumns(tableModel).size(), is(2)); + assertThat(TableUtil.getColumns(tableModel).get(0), is(columnModel1)); + assertThat(TableUtil.getColumns(tableModel).get(1), is(columnModel2)); + + coreFacade.rollback(save3); + assertThat(TableUtil.getColumns(tableModel).size(), is(1)); + assertThat(TableUtil.getColumns(tableModel).get(0), is(columnModel1)); + + coreFacade.addAttribute(tableModel, columnModel2); + coreFacade.addAttribute(tableModel, columnModel3); + assertThat(TableUtil.getColumns(tableModel).size(), is(3)); + assertThat(TableUtil.getColumns(tableModel).get(0), is(columnModel1)); + assertThat(TableUtil.getColumns(tableModel).get(1), is(columnModel2)); + assertThat(TableUtil.getColumns(tableModel).get(2), is(columnModel3)); + + coreFacade.rollback(save2); + assertThat(TableUtil.getColumns(tableModel).size(), is(0)); + assertThat(factory.getRootModel().getEntities().size(), is(1)); + coreFacade.rollback(save1); + assertThat(factory.getRootModel().getEntities().isEmpty(), is(true)); + } + + /** + * {@link JiemamyFacadeImpl#addEntity(org.jiemamy.internal.model.entity.EntityModel)}のテスト。 + */ + @Test + public void test_addEntity() { + RootModel rootModel = factory.getRootModel(); + TableModel tableModel = factory.newModel(TableModel.class); + + SavePoint save = coreFacade.save(); + // tableはまだrootModelに追加されていない。 + assertThat(rootModel.getEntities().contains(tableModel), is(false)); + + coreFacade.addEntity(tableModel); + + assertThat(rootModel.getEntities().contains(tableModel), is(true)); + + coreFacade.rollback(save); + + assertThat(rootModel.getEntities().contains(tableModel), is(false)); + + } + + /** + * {@link JiemamyFacadeImpl#addKeyColumn(org.jiemamy.internal.model.attribute.constraint.KeyConstraint, ColumnModel)}のテスト。 + */ + @Test + public void test_addKeyColumn() { + TableModel tableModel = factory.newModel(TableModel.class); + coreFacade.addEntity(tableModel); + ColumnModel columnModel1 = factory.newModel(ColumnModel.class); + ColumnModel columnModel2 = factory.newModel(ColumnModel.class); + ColumnModel columnModel3 = factory.newModel(ColumnModel.class); + + coreFacade.addAttribute(tableModel, columnModel1); + coreFacade.addAttribute(tableModel, columnModel2); + coreFacade.addAttribute(tableModel, columnModel3); + + ReferenceResolver resolver = jiemamy.getReferenceResolver(); + SavePoint save1 = coreFacade.save(); + + PrimaryKey primaryKey = factory.newModel(PrimaryKey.class); + coreFacade.addKeyColumn(primaryKey, columnModel1); + coreFacade.addAttribute(tableModel, primaryKey); + + List<ColumnRef> keyColumns = primaryKey.getKeyColumns(); + assertThat(keyColumns, notNullValue()); + assertThat(keyColumns.size(), is(1)); + assertThat(resolver.resolve(keyColumns.get(0)), is(columnModel1)); + + SavePoint save2 = coreFacade.save(); + coreFacade.addKeyColumn(primaryKey, columnModel2); + keyColumns = primaryKey.getKeyColumns(); + assertThat(keyColumns, notNullValue()); + assertThat(keyColumns.size(), is(2)); + assertThat(resolver.resolve(keyColumns.get(0)), is(columnModel1)); + assertThat(resolver.resolve(keyColumns.get(1)), is(columnModel2)); + + coreFacade.rollback(save2); + keyColumns = primaryKey.getKeyColumns(); + assertThat(keyColumns, notNullValue()); + assertThat(keyColumns.size(), is(1)); + assertThat(resolver.resolve(keyColumns.get(0)), is(columnModel1)); + + coreFacade.rollback(save1); + keyColumns = primaryKey.getKeyColumns(); + assertThat(keyColumns, notNullValue()); + assertThat(keyColumns.size(), is(0)); + } + + /** + * {@link JiemamyFacadeImpl#removeKeyColumn(org.jiemamy.internal.model.attribute.constraint.KeyConstraint, ColumnModel)}の例外テスト。 + */ + @Test(expected = IllegalArgumentException.class) + @Ignore + public void test_addPrimaryKey_tableに含まれていないColumnを指定するとException() { + TableModel tableModel = factory.newModel(TableModel.class); + coreFacade.addEntity(tableModel); + ColumnModel columnModel1 = factory.newModel(ColumnModel.class); + ColumnModel columnModel2 = factory.newModel(ColumnModel.class); + ColumnModel columnModel3 = factory.newModel(ColumnModel.class); + + // coreFacade.addAttribute(tableModel, columnModel1); // 追加しない。 + coreFacade.addAttribute(tableModel, columnModel2); + coreFacade.addAttribute(tableModel, columnModel3); + + // tableが保持していないcolumnを指定して主キーを設定する。 + PrimaryKey primaryKey = factory.newModel(PrimaryKey.class); + coreFacade.addKeyColumn(primaryKey, columnModel1); + coreFacade.addAttribute(tableModel, primaryKey); + } + + /** + * save/rollbackのテスト。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test01_save_rollbackのテスト_縦横無尽() throws Exception { + RootModel rootModel = factory.getRootModel(); + assertThat(rootModel.getEntities().size(), is(0)); + + SavePoint sp1 = coreFacade.save(); + + TableModel tableModel1 = factory.newModel(TableModel.class); + assertThat(tableModel1.getName(), is(nullValue())); + + coreFacade.changeModelProperty(tableModel1, EntityProperty.name, "foo"); + coreFacade.addEntity(tableModel1); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(tableModel1.getName(), is("foo")); + + SavePoint sp2 = coreFacade.save(); + + coreFacade.changeModelProperty(tableModel1, EntityProperty.name, "bar"); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(tableModel1.getName(), is("bar")); + + SavePoint sp3 = coreFacade.save(); + + // 隣り合わせの単純遷移 3→2→1→2→3 + coreFacade.rollback(sp2); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(tableModel1.getName(), is("foo")); + + coreFacade.rollback(sp1); + assertThat(rootModel.getEntities().size(), is(0)); + assertThat(tableModel1.getName(), is(nullValue())); + + coreFacade.rollback(sp2); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(tableModel1.getName(), is("foo")); + + coreFacade.rollback(sp3); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(tableModel1.getName(), is("bar")); + + // コマ飛ばし遷移 3→1→3 + coreFacade.rollback(sp1); + assertThat(rootModel.getEntities().size(), is(0)); + assertThat(tableModel1.getName(), is(nullValue())); + + coreFacade.rollback(sp3); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(tableModel1.getName(), is("bar")); + + // sp1に戻し、ここから派生するsp4を作る。 + coreFacade.rollback(sp1); + assertThat(rootModel.getEntities().size(), is(0)); + assertThat(tableModel1.getName(), is(nullValue())); + + TableModel tableModel2 = factory.newModel(TableModel.class); + coreFacade.changeModelProperty(tableModel2, EntityProperty.name, "baz"); + coreFacade.addEntity(tableModel2); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(tableModel2.getName(), is("baz")); + + SavePoint sp4 = coreFacade.save(); + + // sp1 → sp2 → sp3 + // ↓ + // sp4 + // という状態になった。 + + // 双方向への隣り合わせの単純遷移 1→4→1→2 + coreFacade.rollback(sp1); + assertThat(rootModel.getEntities().size(), is(0)); + assertThat(tableModel1.getName(), is(nullValue())); + assertThat(tableModel2.getName(), is(nullValue())); + + coreFacade.rollback(sp4); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(CollectionUtils.get(rootModel.getEntities(), 0), is(sameInstance((Object) tableModel2))); + assertThat(tableModel2.getName(), is("baz")); + + coreFacade.rollback(sp1); + assertThat(rootModel.getEntities().size(), is(0)); + assertThat(tableModel1.getName(), is(nullValue())); + assertThat(tableModel2.getName(), is(nullValue())); + + coreFacade.rollback(sp2); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(CollectionUtils.get(rootModel.getEntities(), 0), is(sameInstance((Object) tableModel1))); + assertThat(tableModel1.getName(), is("foo")); + + // 系列横断遷移 2→4→3→4 + coreFacade.rollback(sp4); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(CollectionUtils.get(rootModel.getEntities(), 0), is(sameInstance((Object) tableModel2))); + assertThat(tableModel2.getName(), is("baz")); + + coreFacade.rollback(sp3); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(CollectionUtils.get(rootModel.getEntities(), 0), is(sameInstance((Object) tableModel1))); + assertThat(tableModel1.getName(), is("bar")); + + coreFacade.rollback(sp4); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(CollectionUtils.get(rootModel.getEntities(), 0), is(sameInstance((Object) tableModel2))); + assertThat(tableModel2.getName(), is("baz")); + + // 最後にもう一度、全てのspをテスト + coreFacade.rollback(sp1); + assertThat(rootModel.getEntities().size(), is(0)); + assertThat(tableModel1.getName(), is(nullValue())); + assertThat(tableModel2.getName(), is(nullValue())); + + coreFacade.rollback(sp2); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(CollectionUtils.get(rootModel.getEntities(), 0), is(sameInstance((Object) tableModel1))); + assertThat(tableModel1.getName(), is("foo")); + + coreFacade.rollback(sp3); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(CollectionUtils.get(rootModel.getEntities(), 0), is(sameInstance((Object) tableModel1))); + assertThat(tableModel1.getName(), is("bar")); + + coreFacade.rollback(sp4); + assertThat(rootModel.getEntities().size(), is(1)); + assertThat(CollectionUtils.get(rootModel.getEntities(), 0), is(sameInstance((Object) tableModel2))); + assertThat(tableModel2.getName(), is("baz")); + } +} Property changes on: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/JiemamyFacadeImplTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Copied: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/JiemamyPropertyTest.java (from rev 2972, artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/JiemamyPropertyTest.java) =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/JiemamyPropertyTest.java (rev 0) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/JiemamyPropertyTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,157 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/01/29 + * + * 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.internal; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.util.Arrays; + +import org.apache.commons.lang.ClassUtils; +import org.junit.Test; + +import org.jiemamy.JiemamyProperty; +import org.jiemamy.TargetModel; +import org.jiemamy.internal.model.attribute.constraint.AbstractConstraintModel; +import org.jiemamy.utils.ReflectionUtil; + +/** + * {@link JiemamyProperty}のテストクラス。 + * + * @author daisuke + */ +public class JiemamyPropertyTest { + + /** + * 各モデルのインターフェイスは、{@link JiemamyProperty}で示されるgetterを持つべきである。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test01_ModelHasGetter() throws Exception { + for (Class<?> enumClass : JiemamyProperty.class.getClasses()) { + if (Enum.class.isAssignableFrom(enumClass) == false) { + continue; + } + + TargetModel annot = enumClass.getAnnotation(TargetModel.class); + assertThat("JiemamyPropertyの内部列挙型はTargetModelアノテーションを持たなければならない", annot, is(notNullValue())); + + Class<?> targetModelClass = annot.value(); + for (Field field : enumClass.getFields()) { + String iserName = ReflectionUtil.convertFieldToAccessorName(field, "is"); + String getterName = ReflectionUtil.convertFieldToAccessorName(field, "get"); + try { + targetModelClass.getMethod(getterName); + } catch (NoSuchMethodException e) { + Method iserMethod; + try { + iserMethod = targetModelClass.getMethod(iserName); + if (iserMethod.getReturnType() != Boolean.class && iserMethod.getReturnType() != boolean.class) { + fail(targetModelClass.getName() + " is not have " + getterName); + } + } catch (NoSuchMethodException e2) { + fail(targetModelClass.getName() + " is not have " + getterName + " or " + iserName); + } + } + } + } + } + + /** + * 各モデルの実装クラスは、{@link JiemamyProperty}で示されるフィールドを持つべきである。 + * + * <p>Artemis特有。仕様ではない。</p> + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test02_ModelHasField() throws Exception { + for (Class<?> enumClass : JiemamyProperty.class.getClasses()) { + if (Enum.class.isAssignableFrom(enumClass) == false) { + continue; + } + + TargetModel annot = enumClass.getAnnotation(TargetModel.class); + assertThat("JiemamyPropertyの内部列挙型はTargetModelアノテーションを持たなければならない", annot, is(notNullValue())); + + Class<?> interfaceClass = annot.value(); + String implClassName = interfaceClass.getName() + "Impl"; + + Class<?> targetModelClass; + try { + targetModelClass = Class.forName(implClassName); + } catch (ClassNotFoundException e) { + String packageName = ClassUtils.getPackageName(interfaceClass); + String shortClassName = ClassUtils.getShortClassName(interfaceClass); + + implClassName = packageName + ".Abstract" + shortClassName; + targetModelClass = Class.forName(implClassName); + } + + Field[] enumFields = enumClass.getFields(); + for (Field enumField : enumFields) { + try { + targetModelClass.getDeclaredField(enumField.getName()); + } catch (NoSuchFieldException e) { + if (targetModelClass == AbstractConstraintModel.class && enumField.getName() == "name") { + // 例外 success + } else { + fail(targetModelClass.getName() + " is not have " + enumField.getName()); + } + } + } + } + } + + /** + * {@link JiemamyProperty}は、各モデルのインターフェイスのgetterで示されるプロパティを網羅すべきである。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test03_PropertyHasFieldName() throws Exception { + for (Class<?> clazz : JiemamyProperty.class.getClasses()) { + if (Enum.class.isAssignableFrom(clazz) == false) { + continue; + } + TargetModel annot = clazz.getAnnotation(TargetModel.class); + Class<?> targetModelClass = annot.value(); + Method[] methods = targetModelClass.getDeclaredMethods(); + for (Method method : methods) { + if (ReflectionUtil.isGetter(method) == false) { + continue; + } + String fieldName = ReflectionUtil.convertAccessorToFieldName(method); + try { + clazz.getField(fieldName); + } catch (NoSuchFieldException e) { + if (Arrays.asList("adapter", "adapters").contains(fieldName) == false) { + fail(clazz.getName() + " is not have " + fieldName); + } + } + } + } + + } +} Property changes on: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/JiemamyPropertyTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Copied: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/ReferenceResolverImplTest.java (from rev 2972, artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/ReferenceResolverImplTest.java) =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/ReferenceResolverImplTest.java (rev 0) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/ReferenceResolverImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,238 @@ +/* + * 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.internal; + +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; + +import java.util.Stack; + +import org.apache.commons.lang.RandomStringUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.jiemamy.EventBroker; +import org.jiemamy.Jiemamy; +import org.jiemamy.JiemamyFactory; +import org.jiemamy.editcommand.Command; +import org.jiemamy.internal.editcommand.AddAttributeCommand; +import org.jiemamy.internal.editcommand.AddColumnToColumnRefListCommand; +import org.jiemamy.internal.editcommand.AddEntityToRootCommand; +import org.jiemamy.internal.editcommand.RemoveAttributeCommand; +import org.jiemamy.internal.editcommand.RemoveColumnFromColumnRefListCommand; +import org.jiemamy.internal.editcommand.RemoveEntityFromRootCommand; +import org.jiemamy.model.RootModel; +import org.jiemamy.model.attribute.ColumnModel; +import org.jiemamy.model.attribute.constraint.PrimaryKey; +import org.jiemamy.model.entity.TableModel; + +/** + * {@link ReferenceResolverImpl}のテストクラス。 + * + * @author shin1ogawa + */ +public class ReferenceResolverImplTest { + + static final Logger LOGGER = LoggerFactory.getLogger(ReferenceResolverImplTest.class); + + private JiemamyFactory factory; + + private Jiemamy jiemamy; + + private EventBroker eventBroker; + + private CommandProcessorImpl commandProcessor; + + private Stack<Stack<Command>> commandStackStack; + + private RootModel rootModel; + + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + jiemamy = Jiemamy.newInstance(); + factory = jiemamy.getFactory(); + rootModel = factory.newModel(RootModel.class); + eventBroker = jiemamy.getEventBroker(); + commandProcessor = new CommandProcessorImpl(eventBroker); + commandStackStack = new Stack<Stack<Command>>(); + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + jiemamy = null; + factory = null; + rootModel = null; + eventBroker = null; + commandProcessor = null; + commandStackStack = null; + } + + /** + * メモリリークテスト。 + * + * <p>RootModelからたどる事のないインスタンスを大量生成する。ここで{@link OutOfMemoryError}を起こしてはならない。</p> + * + * @throws Exception 例外が発生した場合 + */ + @Test + @Ignore + public void test00_メモリリークテスト() throws Exception { + for (int i = 0; i < 100000; i++) { + TableModel tableModel = factory.newModel(TableModel.class); + tableModel.setName(RandomStringUtils.randomAlphabetic(10)); + ColumnModel columnModel = factory.newModel(ColumnModel.class); + columnModel.setName(RandomStringUtils.randomAlphabetic(10)); + tableModel.getAttributes().add(columnModel); + } + } + + /** + * {@link ReferenceResolverImpl#isDescendFromElement(org.jiemamy.internal.model.JiemamyElement, java.util.UUID)} + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test01親子関係の判断() throws Exception { + Stack<Command> commandStack = new Stack<Command>(); + + TableModel tableModel = factory.newModel(TableModel.class); + Command command = new AddEntityToRootCommand(rootModel, tableModel); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + ColumnModel columnModel1 = factory.newModel(ColumnModel.class); + command = new AddAttributeCommand(tableModel, columnModel1); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + ColumnModel columnModel2 = factory.newModel(ColumnModel.class); + command = new AddAttributeCommand(tableModel, columnModel2); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + PrimaryKey primaryKey = factory.newModel(PrimaryKey.class); + command = new AddColumnToColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), columnModel2); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + command = new AddColumnToColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), columnModel1, 0); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + command = new AddAttributeCommand(tableModel, primaryKey); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + commandStackStack.push(commandStack); // 構築操作を行ったCommandStackをpushする。 + + assertThat(tableModel.getAttributes().size(), is(3)); // column1,column2,pkey + assertThat(primaryKey.getKeyColumns().size(), is(2)); // [ref]column1, [ref]column2。 + assertThat(primaryKey.getKeyColumns().get(0).getReferenceId(), is(columnModel1.getId())); + assertThat(primaryKey.getKeyColumns().get(1).getReferenceId(), is(columnModel2.getId())); + + // ここまでで以下の構造を構築した事になる。 + // table + // +attributes + // -column1 + // -column2 + // +primaryKey + // -[ref]column1 + // -[ref]column2 + + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, columnModel1.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, primaryKey.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, tableModel.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, columnModel1.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, primaryKey.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(primaryKey, columnModel1.getId()), is(true)); + + // 新たなStackを用意する。 + commandStack = new Stack<Command>(); + + // columnをprimaryKeyから削除する。 + command = new RemoveColumnFromColumnRefListCommand(primaryKey, primaryKey.getKeyColumns(), columnModel1); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, columnModel1.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, primaryKey.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, tableModel.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, columnModel1.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, primaryKey.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(primaryKey, columnModel1.getId()), is(false)); + + // columnをtableから削除する。 + command = new RemoveAttributeCommand(tableModel, columnModel1); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, columnModel1.getId()), is(false)); + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, primaryKey.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, tableModel.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, columnModel1.getId()), is(false)); + assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, primaryKey.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(primaryKey, columnModel1.getId()), is(false)); + + // tableをRootModelから削除する。 + command = new RemoveEntityFromRootCommand(rootModel, tableModel); + command.execute(commandProcessor); + commandStack.push(command.getNegateCommand()); + + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, columnModel1.getId()), is(false)); + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, primaryKey.getId()), is(false)); + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, tableModel.getId()), is(false)); + assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, columnModel1.getId()), is(false)); + assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, primaryKey.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(primaryKey, columnModel1.getId()), is(false)); + commandStackStack.push(commandStack); // 削除操作を行ったCommandStackをpushする。 + + // 一連の削除操作を全て取り消す。 + Stack<Command> deleteCommands = commandStackStack.pop(); + while (deleteCommands.isEmpty() == false) { + command = deleteCommands.pop(); + command.execute(commandProcessor); + } + + assertThat(tableModel.getAttributes().size(), is(3)); // column1,column2,pkey + assertThat(primaryKey.getKeyColumns().size(), is(2)); // [ref]column1, [ref]column2。 + assertThat(primaryKey.getKeyColumns().get(0).getReferenceId(), is(columnModel1.getId())); + assertThat(primaryKey.getKeyColumns().get(1).getReferenceId(), is(columnModel2.getId())); + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, columnModel1.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, primaryKey.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(rootModel, tableModel.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, columnModel1.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(tableModel, primaryKey.getId()), is(true)); + assertThat(ReferenceResolverImpl.isDescendFromElement(primaryKey, columnModel1.getId()), is(true)); + } +} Copied: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/EmptyProxyModel.java (from rev 2971, artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/EmptyProxyModel.java) =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/EmptyProxyModel.java (rev 0) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/EmptyProxyModel.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,57 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2008/11/13 + * + * 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.internal.model; + +import mockit.Mockit; + +import org.jiemamy.model.attribute.ColumnModel; +import org.jiemamy.model.attribute.constraint.CheckConstraint; +import org.jiemamy.model.dataset.DataSetModel; +import org.jiemamy.model.datatype.DataType; +import org.jiemamy.model.datatype.DomainModel; +import org.jiemamy.model.entity.EntityModel; +import org.jiemamy.model.index.IndexModel; + +/** + * テスト用の、インターフェイスの空実装を保持する定数クラス。 + * @author daisuke + */ +public final class EmptyProxyModel { + + /** {@link DataType}の空実装 */ + public static final DataType DATA_TYPE_DESC = Mockit.newEmptyProxy(DataType.class); + + /** {@link DomainModel}の空実装 */ + public static final DomainModel DOMAIN = Mockit.newEmptyProxy(DomainModel.class); + + /** {@link ColumnModel}の空実装 */ + public static final ColumnModel COLUMN = Mockit.newEmptyProxy(ColumnModel.class); + + /** {@link EntityModel}の空実装 */ + public static final EntityModel ENTITY = Mockit.newEmptyProxy(EntityModel.class); + + /** {@link DataSetModel}の空実装 */ + public static final DataSetModel INSERT_DATA_SET = Mockit.newEmptyProxy(DataSetModel.class); + + /** {@link CheckConstraint}の空実装 */ + public static final CheckConstraint CHECK = Mockit.newEmptyProxy(CheckConstraint.class); + + /** {@link IndexModel}の空実装 */ + public static final IndexModel INDEX = Mockit.newEmptyProxy(IndexModel.class); +} Property changes on: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/EmptyProxyModel.java ___________________________________________________________________ Added: svn:mime-type + text/plain Copied: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/RootModelImplTest.java (from rev 2972, artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/RootModelImplTest.java) =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/RootModelImplTest.java (rev 0) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/RootModelImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,200 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2008/09/29 + * + * 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.internal.model; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.CoreMatchers.sameInstance; +import static org.junit.Assert.assertThat; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import org.jiemamy.Jiemamy; +import org.jiemamy.JiemamyFactory; +import org.jiemamy.model.RootModel; +import org.jiemamy.model.attribute.constraint.ForeignKey; +import org.jiemamy.model.datatype.DataTypeCategory; +import org.jiemamy.model.datatype.DomainModel; +import org.jiemamy.model.entity.TableModel; +import org.jiemamy.utils.builder.DataTypeBuilderImpl; +import org.jiemamy.utils.model.AttributeUtil; + +/** + * {@link RootModelImpl}のテストクラス。 + * + * @author daisuke + */ +public class RootModelImplTest { + + private Jiemamy jiemamy; + + private JiemamyFactory factory; + + private RootModel rootModel; + + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + jiemamy = Jiemamy.newInstance(); + factory = jiemamy.getFactory(); + rootModel = factory.getRootModel(); + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + rootModel = null; + factory = null; + jiemamy = null; + } + + /** + * 各プロパティが正常に初期化されていること。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test01_各プロパティが正常に初期化されていること() throws Exception { + assertThat(rootModel.getBeginScript(), is(nullValue())); + assertThat(rootModel.getEndScript(), is(nullValue())); + assertThat(rootModel.getDescription(), is(nullValue())); + assertThat(rootModel.getSchemaName(), is(nullValue())); + + assertThat(rootModel.getId(), is(notNullValue())); + assertThat(rootModel.getAdapters(), is(notNullValue())); + assertThat(rootModel.getDomains(), is(notNullValue())); + assertThat(rootModel.getEntities(), is(notNullValue())); + assertThat(rootModel.getDataSets(), is(notNullValue())); + assertThat(rootModel.getDialectClassName(), is(notNullValue())); + + assertThat(rootModel.getDomains().size(), is(0)); + assertThat(rootModel.getEntities().size(), is(0)); + assertThat(rootModel.getAdapters().size(), is(0)); + assertThat(rootModel.getDataSets().size(), is(0)); + } + + /** + * RootModelからのクローニングが適切に行われること。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + @Ignore("not implemented") + public void test07_RootModelからのクローニングが適切に行われること() throws Exception { + // モデル構築 + DomainModel domainModel1 = factory.newModel(DomainModel.class); + domainModel1.setName("domain1"); + domainModel1.setDataType(new DataTypeBuilderImpl(factory, DataTypeCategory.INTEGER).build()); + DomainModel domainModel2 = factory.newModel(DomainModel.class); + domainModel2.setName("domain2"); + domainModel2.setDataType(new DataTypeBuilderImpl(factory, DataTypeCategory.INTEGER).build()); + + rootModel.getDomains().add(domainModel1); + + // オリジナルに2つのモデルがセットされている + assertThat(rootModel.getDomains().get(0), is(sameInstance(domainModel1))); + + // RootModelをクローニングする +// RootModel clone = rootModel.clone(); +// +// // 各RootModelのIDは同一、インスタンスは別 +// assertThat(rootModel.getId(), is(clone.getId())); +// assertThat(clone, is(not(sameInstance(rootModel)))); +// +// // オリジナルとクローンで、domain数は同じ +// assertThat(rootModel.getDomains().size(), is(1)); +// assertThat(clone.getDomains().size(), is(1)); +// +// // 各DomainModelのIDは同一、インスタンスは別 +// assertThat(rootModel.getDomains().get(0).getId(), is(clone.getDomains().get(0).getId())); +// assertThat(rootModel.getDomains().get(1).getId(), is(clone.getDomains().get(1).getId())); +// assertThat(rootModel.getDomains().get(0), is(not(sameInstance(clone.getDomains().get(0))))); +// assertThat(rootModel.getDomains().get(1), is(not(sameInstance(clone.getDomains().get(1))))); +// +// // ここでオリジナルにドメインを追加する +// rootModel.getDomains().add(domain2); +// +// assertThat(rootModel.getDomains().get(1), is(sameInstance(domain2))); +// +// // 追加分はクローンに影響しない +// assertThat(rootModel.getDomains().size(), is(2)); +// assertThat(clone.getDomains().size(), is(1)); + } + + /** + * 外部キーのクローニングが適切に行われること。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + @Ignore("not implemented") + public void test09_外部キーのクローニングが適切に行われること() throws Exception { + // モデル構築 + TableModel tableModel1 = factory.newModel(TableModel.class); + tableModel1.setName("table1"); + TableModel tableModel2 = factory.newModel(TableModel.class); + tableModel2.setName("table2"); + rootModel.getEntities().add(tableModel1); + rootModel.getEntities().add(tableModel2); + + ForeignKey foreignKey = factory.newModel(ForeignKey.class); + AttributeUtil.autoDenominate(foreignKey, rootModel); + tableModel1.getAttributes().add(foreignKey); + + // RootModelをクローニングする +// RootModel cloneRoot = rootModel.clone(); +// TableModel cloneTable1 = RootModelUtil.getEntity(cloneRoot, TableModel.class, "table1"); +// TableModel cloneTable2 = RootModelUtil.getEntity(cloneRoot, TableModel.class, "table2"); +// ForeignKey cloneFk = RootModelUtil.getAllForeignKeys(cloneRoot).iterator().next(); +// +// // RootModelのIDは同一、インスタンスは別 +// assertThat(cloneRoot.getId(), is(rootModel.getId())); +// assertThat(cloneRoot, is(not(sameInstance(rootModel)))); +// +// // オリジナルとクローンで、node, connectionの数は同じ +// assertThat(rootModel.getEntities().size(), is(2)); +// assertThat(cloneRoot.getEntities().size(), is(2)); +// assertThat(RootModelUtil.getAllForeignKeys(rootModel).size(), is(1)); +// assertThat(RootModelUtil.getAllForeignKeys(cloneRoot).size(), is(1)); +// +// // node, connectionのIDは同一 +// assertThat(table1.getId(), is(cloneTable1.getId())); +// assertThat(table2.getId(), is(cloneTable1.getId())); +// assertThat(cloneFk.getId(), is(fk.getId())); +// +// // node, connectionのインスタンスは別 +// assertThat(table1, is(not(sameInstance(cloneTable1)))); +// assertThat(table2, is(not(sameInstance(cloneTable2)))); +// assertThat(cloneFk, is(not(sameInstance(fk)))); + } + +} Property changes on: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/RootModelImplTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Deleted: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/datatype/BuiltinDataTypeImplTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/datatype/BuiltinDataTypeImplTest.java 2009-03-20 15:22:38 UTC (rev 2971) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/datatype/BuiltinDataTypeImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,86 +0,0 @@ -/* - * Copyright 2007-2009 MIYAMOTO Daisuke, jiemamy.org and the Others. - * Created on 2009/01/02 - * - * 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.model.datatype; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.not; -import static org.hamcrest.CoreMatchers.sameInstance; -import static org.junit.Assert.assertThat; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import org.jiemamy.Jiemamy; -import org.jiemamy.JiemamyFactory; -import org.jiemamy.dialect.BuiltinDataTypeMold; -import org.jiemamy.dialect.BuiltinDataTypeMoldImpl; -import org.jiemamy.model.datatype.adapter.SizedDataTypeAdapter; - -/** - * {@link BuiltinDataType}のテストクラス。 - * - * @author daisuke - */ -public class BuiltinDataTypeImplTest { - - private Jiemamy jiemamy; - - private JiemamyFactory factory; - - - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - jiemamy = Jiemamy.newInstance(); - factory = jiemamy.getFactory(); - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - factory = null; - jiemamy = null; - } - - /** - * インスタンス毎にアダプタは異なったインスタンスが設定されている。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test01_インスタンス毎にアダプタは異なったインスタンスが設定されている() throws Exception { - BuiltinDataTypeMold mold = new BuiltinDataTypeMoldImpl(DataTypeCategory.VARCHAR, SizedDataTypeAdapter.class); - BuiltinDataType dataType1 = factory.newDataType(mold); - BuiltinDataType dataType2 = factory.newDataType(mold); - - SizedDataTypeAdapter sized1 = dataType1.getAdapter(SizedDataTypeAdapter.class); - SizedDataTypeAdapter sized2 = dataType2.getAdapter(SizedDataTypeAdapter.class); - assertThat(dataType1, is(not(sameInstance(dataType2)))); - assertThat(sized1, is(not(sameInstance(sized2)))); - } -} Copied: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/datatype/BuiltinDataTypeImplTest.java (from rev 2975, artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/datatype/BuiltinDataTypeImplTest.java) =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/datatype/BuiltinDataTypeImplTest.java (rev 0) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/datatype/BuiltinDataTypeImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,88 @@ +/* + * Copyright 2007-2009 MIYAMOTO Daisuke, jiemamy.org and the Others. + * Created on 2009/01/02 + * + * 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.internal.model.datatype; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.sameInstance; +import static org.junit.Assert.assertThat; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.jiemamy.Jiemamy; +import org.jiemamy.JiemamyFactory; +import org.jiemamy.dialect.BuiltinDataTypeMold; +import org.jiemamy.dialect.BuiltinDataTypeMoldImpl; +import org.jiemamy.internal.model.datatype.adapter.SizedDataTypeAdapter; +import org.jiemamy.model.datatype.BuiltinDataType; +import org.jiemamy.model.datatype.DataTypeCategory; + +/** + * {@link BuiltinDataType}のテストクラス。 + * + * @author daisuke + */ +public class BuiltinDataTypeImplTest { + + private Jiemamy jiemamy; + + private JiemamyFactory factory; + + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + jiemamy = Jiemamy.newInstance(); + factory = jiemamy.getFactory(); + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + factory = null; + jiemamy = null; + } + + /** + * インスタンス毎にアダプタは異なったインスタンスが設定されている。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test01_インスタンス毎にアダプタは異なったインスタンスが設定されている() throws Exception { + BuiltinDataTypeMold mold = new BuiltinDataTypeMoldImpl(DataTypeCategory.VARCHAR, SizedDataTypeAdapter.class); + BuiltinDataType dataType1 = factory.newDataType(mold); + BuiltinDataType dataType2 = factory.newDataType(mold); + + SizedDataTypeAdapter sized1 = dataType1.getAdapter(SizedDataTypeAdapter.class); + SizedDataTypeAdapter sized2 = dataType2.getAdapter(SizedDataTypeAdapter.class); + assertThat(dataType1, is(not(sameInstance(dataType2)))); + assertThat(sized1, is(not(sameInstance(sized2)))); + } +} Deleted: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/node/TableModelImplTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/node/TableModelImplTest.java 2009-03-20 15:22:38 UTC (rev 2971) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/node/TableModelImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,154 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2008/11/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.model.node; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.CoreMatchers.sameInstance; -import static org.junit.Assert.assertThat; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import org.jiemamy.Jiemamy; -import org.jiemamy.JiemamyFactory; -import org.jiemamy.model.RootModel; -import org.jiemamy.model.attribute.ColumnModel; -import org.jiemamy.model.datatype.DataTypeCategory; -import org.jiemamy.model.entity.TableModel; -import org.jiemamy.model.entity.TableModelImpl; -import org.jiemamy.utils.builder.DataTypeBuilderImpl; -import org.jiemamy.utils.model.TableUtil; - -/** - * {@link TableModelImpl}のテストクラス。 - * - * @author daisuke - */ -public class TableModelImplTest { - - private RootModel rootModel; - - private JiemamyFactory factory; - - private Jiemamy jiemamy; - - private TableModel tableModel; - - - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - jiemamy = Jiemamy.newInstance(); - factory = jiemamy.getFactory(); - rootModel = factory.getRootModel(); - tableModel = factory.newModel(TableModel.class); - tableModel.setName("table"); - rootModel.getEntities().add(tableModel); - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - tableModel = null; - rootModel = null; - factory = null; - jiemamy = null; - } - - /** - * 各プロパティが正常に初期化されていること。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test01_各プロパティが正常に初期化されていること() throws Exception { - assertThat(tableModel.getName(), is("table")); - assertThat(tableModel.getLogicalName(), is(nullValue())); - assertThat(tableModel.getBeginScript(), is(nullValue())); - assertThat(tableModel.getEndScript(), is(nullValue())); - assertThat(tableModel.getDescription(), is(nullValue())); - - assertThat(tableModel.getId(), is(notNullValue())); - assertThat(tableModel.getAdapters(), is(notNullValue())); - assertThat(tableModel.getAttributes(), is(notNullValue())); - assertThat(tableModel.getIndexes(), is(notNullValue())); - - assertThat(tableModel.getAdapters().size(), is(1)); // disablable - assertThat(tableModel.getAttributes().size(), is(0)); - assertThat(tableModel.getIndexes().size(), is(0)); - } - - /** - * RootModelからのクローニングが適切に行われること。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - @Ignore("not implemented") - public void test08_RootModelからのクローニングが適切に行われること() throws Exception { - ColumnModel columnModel1 = factory.newModel(ColumnModel.class); - columnModel1.setName("column1"); - columnModel1.setDataType(new DataTypeBuilderImpl(factory, DataTypeCategory.INTEGER).build()); - ColumnModel columnModel2 = factory.newModel(ColumnModel.class); - columnModel2.setName("column2"); - columnModel2.setDataType(new DataTypeBuilderImpl(factory, DataTypeCategory.INTEGER).build()); - - tableModel.getAttributes().add(columnModel1); - - // オリジナルにモデルがセットされている - assertThat(TableUtil.getColumns(tableModel).get(0), is(sameInstance(columnModel1))); - - // RootModelをクローニングする -// RootModel cloneRoot = rootModel.clone(); -// TableModel cloneTable = RootModelUtil.getEntity(cloneRoot, TableModel.class, "table"); -// -// // IDは同一、インスタンスは別 -// assertThat(cloneTable.getId(), is(tableModel.getId())); -// assertThat(cloneTable, is(sameInstance(tableModel))); -// -// // オリジナルとクローンで、カラム数は同じ -// assertThat(tableModel.getAttributes().size(), is(1)); -// assertThat(cloneTable.getAttributes().size(), is(1)); -// -// // カラムのIDは同一、インスタンスは別 -// assertThat(cloneTable.getAttributes().get(0).getId(), is(tableModel.getAttributes().get(0).getId())); -// assertThat(cloneTable.getAttributes().get(0), is(sameInstance(tableModel.getAttributes().get(0)))); -// -// tableModel.getAttributes().add(column2); -// -// // オリジナルにモデルがセットされている -// assertThat(TableUtil.getColumns(tableModel).get(1), is(sameInstance(column2))); -// -// // 追加分はクローンに影響しない -// assertThat(tableModel.getAttributes().size(), is(2)); -// assertThat(cloneTable.getAttributes().size(), is(1)); - } -} Copied: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/node/TableModelImplTest.java (from rev 2975, artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/node/TableModelImplTest.java) =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/node/TableModelImplTest.java (rev 0) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/internal/model/node/TableModelImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,154 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2008/11/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.internal.model.node; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.nullValue; +import static org.hamcrest.CoreMatchers.sameInstance; +import static org.junit.Assert.assertThat; + +import org.junit.After; +import org.junit.Before; +import org.junit.Ignore; +import org.junit.Test; + +import org.jiemamy.Jiemamy; +import org.jiemamy.JiemamyFactory; +import org.jiemamy.internal.model.entity.TableModelImpl; +import org.jiemamy.model.RootModel; +import org.jiemamy.model.attribute.ColumnModel; +import org.jiemamy.model.datatype.DataTypeCategory; +import org.jiemamy.model.entity.TableModel; +import org.jiemamy.utils.builder.DataTypeBuilderImpl; +import org.jiemamy.utils.model.TableUtil; + +/** + * {@link TableModelImpl}のテストクラス。 + * + * @author daisuke + */ +public class TableModelImplTest { + + private RootModel rootModel; + + private JiemamyFactory factory; + + private Jiemamy jiemamy; + + private TableModel tableModel; + + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + jiemamy = Jiemamy.newInstance(); + factory = jiemamy.getFactory(); + rootModel = factory.getRootModel(); + tableModel = factory.newModel(TableModel.class); + tableModel.setName("table"); + rootModel.getEntities().add(tableModel); + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + tableModel = null; + rootModel = null; + factory = null; + jiemamy = null; + } + + /** + * 各プロパティが正常に初期化されていること。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test01_各プロパティが正常に初期化されていること() throws Exception { + assertThat(tableModel.getName(), is("table")); + assertThat(tableModel.getLogicalName(), is(nullValue())); + assertThat(tableModel.getBeginScript(), is(nullValue())); + assertThat(tableModel.getEndScript(), is(nullValue())); + assertThat(tableModel.getDescription(), is(nullValue())); + + assertThat(tableModel.getId(), is(notNullValue())); + assertThat(tableModel.getAdapters(), is(notNullValue())); + assertThat(tableModel.getAttributes(), is(notNullValue())); + assertThat(tableModel.getIndexes(), is(notNullValue())); + + assertThat(tableModel.getAdapters().size(), is(1)); // disablable + assertThat(tableModel.getAttributes().size(), is(0)); + assertThat(tableModel.getIndexes().size(), is(0)); + } + + /** + * RootModelからのクローニングが適切に行われること。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + @Ignore("not implemented") + public void test08_RootModelからのクローニングが適切に行われること() throws Exception { + ColumnModel columnModel1 = factory.newModel(ColumnModel.class); + columnModel1.setName("column1"); + columnModel1.setDataType(new DataTypeBuilderImpl(factory, DataTypeCategory.INTEGER).build()); + ColumnModel columnModel2 = factory.newModel(ColumnModel.class); + columnModel2.setName("column2"); + columnModel2.setDataType(new DataTypeBuilderImpl(factory, DataTypeCategory.INTEGER).build()); + + tableModel.getAttributes().add(columnModel1); + + // オリジナルにモデルがセットされている + assertThat(TableUtil.getColumns(tableModel).get(0), is(sameInstance(columnModel1))); + + // RootModelをクローニングする +// RootModel cloneRoot = rootModel.clone(); +// TableModel cloneTable = RootModelUtil.getEntity(cloneRoot, TableModel.class, "table"); +// +// // IDは同一、インスタンスは別 +// assertThat(cloneTable.getId(), is(tableModel.getId())); +// assertThat(cloneTable, is(sameInstance(tableModel))); +// +// // オリジナルとクローンで、カラム数は同じ +// assertThat(tableModel.getAttributes().size(), is(1)); +// assertThat(cloneTable.getAttributes().size(), is(1)); +// +// // カラムのIDは同一、インスタンスは別 +// assertThat(cloneTable.getAttributes().get(0).getId(), is(tableModel.getAttributes().get(0).getId())); +// assertThat(cloneTable.getAttributes().get(0), is(sameInstance(tableModel.getAttributes().get(0)))); +// +// tableModel.getAttributes().add(column2); +// +// // オリジナルにモデルがセットされている +// assertThat(TableUtil.getColumns(tableModel).get(1), is(sameInstance(column2))); +// +// // 追加分はクローンに影響しない +// assertThat(tableModel.getAttributes().size(), is(2)); +// assertThat(cloneTable.getAttributes().size(), is(1)); + } +} Deleted: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/EmptyProxyModel.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/EmptyProxyModel.java 2009-03-21 04:23:00 UTC (rev 2975) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/EmptyProxyModel.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,57 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2008/11/13 - * - * 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.model; - -import mockit.Mockit; - -import org.jiemamy.model.attribute.ColumnModel; -import org.jiemamy.model.attribute.constraint.CheckConstraint; -import org.jiemamy.model.dataset.DataSetModel; -import org.jiemamy.model.datatype.DataType; -import org.jiemamy.model.datatype.DomainModel; -import org.jiemamy.model.entity.EntityModel; -import org.jiemamy.model.index.IndexModel; - -/** - * テスト用の、インターフェイスの空実装を保持する定数クラス。 - * @author daisuke - */ -public final class EmptyProxyModel { - - /** {@link DataType}の空実装 */ - public static final DataType DATA_TYPE_DESC = Mockit.newEmptyProxy(DataType.class); - - /** {@link DomainModel}の空実装 */ - public static final DomainModel DOMAIN = Mockit.newEmptyProxy(DomainModel.class); - - /** {@link ColumnModel}の空実装 */ - public static final ColumnModel COLUMN = Mockit.newEmptyProxy(ColumnModel.class); - - /** {@link EntityModel}の空実装 */ - public static final EntityModel ENTITY = Mockit.newEmptyProxy(EntityModel.class); - - /** {@link DataSetModel}の空実装 */ - public static final DataSetModel INSERT_DATA_SET = Mockit.newEmptyProxy(DataSetModel.class); - - /** {@link CheckConstraint}の空実装 */ - public static final CheckConstraint CHECK = Mockit.newEmptyProxy(CheckConstraint.class); - - /** {@link IndexModel}の空実装 */ - public static final IndexModel INDEX = Mockit.newEmptyProxy(IndexModel.class); -} Deleted: artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/RootModelImplTest.java =================================================================== --- artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/RootModelImplTest.java 2009-03-21 04:23:00 UTC (rev 2975) +++ artemis/trunk/jiemamy-core/src/test/java/org/jiemamy/model/RootModelImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,200 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2008/09/29 - * - * 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.model; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.nullValue; -import static org.hamcrest.CoreMatchers.sameInstance; -import static org.junit.Assert.assertThat; - -import org.junit.After; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -import org.jiemamy.Jiemamy; -import org.jiemamy.JiemamyFactory; -import org.jiemamy.internal.model.RootModelImpl; -import org.jiemamy.model.attribute.constraint.ForeignKey; -import org.jiemamy.model.datatype.DataTypeCategory; -import org.jiemamy.model.datatype.DomainModel; -import org.jiemamy.model.entity.TableModel; -import org.jiemamy.utils.builder.DataTypeBuilderImpl; -import org.jiemamy.utils.model.AttributeUtil; - -/** - * {@link RootModelImpl}のテストクラス。 - * - * @author daisuke - */ -public class RootModelImplTest { - - private Jiemamy jiemamy; - - private JiemamyFactory factory; - - private RootModel rootModel; - - - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - jiemamy = Jiemamy.newInstance(); - factory = jiemamy.getFactory(); - rootModel = factory.getRootModel(); - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - rootModel = null; - factory = null; - jiemamy = null; - } - - /** - * 各プロパティが正常に初期化されていること。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test01_各プロパティが正常に初期化されていること() throws Exception { - assertThat(rootModel.getBeginScript(), is(nullValue())); - assertThat(rootModel.getEndScript(), is(nullValue())); - assertThat(rootModel.getDescription(), is(nullValue())); - assertThat(rootModel.getSchemaName(), is(nullValue())); - - assertThat(rootModel.getId(), is(notNullValue())); - assertThat(rootModel.getAdapters(), is(notNullValue())); - assertThat(rootModel.getDomains(), is(notNullValue())); - assertThat(rootModel.getEntities(), is(notNullValue())); - assertThat(rootModel.getDataSets(), is(notNullValue())); - assertThat(rootModel.getDialectClassName(), is(notNullValue())); - - assertThat(rootModel.getDomains().size(), is(0)); - assertThat(rootModel.getEntities().size(), is(0)); - assertThat(rootModel.getAdapters().size(), is(0)); - assertThat(rootModel.getDataSets().size(), is(0)); - } - - /** - * RootModelからのクローニングが適切に行われること。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - @Ignore("not implemented") - public void test07_RootModelからのクローニングが適切に行われること() throws Exception { - // モデル構築 - DomainModel domainModel1 = factory.newModel(DomainModel.class); - domainModel1.setName("domain1"); - domainModel1.setDataType(new DataTypeBuilderImpl(factory, DataTypeCategory.INTEGER).build()); - DomainModel domainModel2 = factory.newModel(DomainModel.class); - domainModel2.setName("domain2"); - domainModel2.setDataType(new DataTypeBuilderImpl(factory, DataTypeCategory.INTEGER).build()); - - rootModel.getDomains().add(domainModel1); - - // オリジナルに2つのモデルがセットされている - assertThat(rootModel.getDomains().get(0), is(sameInstance(domainModel1))); - - // RootModelをクローニングする -// RootModel clone = rootModel.clone(); -// -// // 各RootModelのIDは同一、インスタンスは別 -// assertThat(rootModel.getId(), is(clone.getId())); -// assertThat(clone, is(not(sameInstance(rootModel)))); -// -// // オリジナルとクローンで、domain数は同じ -// assertThat(rootModel.getDomains().size(), is(1)); -// assertThat(clone.getDomains().size(), is(1)); -// -// // 各DomainModelのIDは同一、インスタンスは別 -// assertThat(rootModel.getDomains().get(0).getId(), is(clone.getDomains().get(0).getId())); -// assertThat(rootModel.getDomains().get(1).getId(), is(clone.getDomains().get(1).getId())); -// assertThat(rootModel.getDomains().get(0), is(not(sameInstance(clone.getDomains().get(0))))); -// assertThat(rootModel.getDomains().get(1), is(not(sameInstance(clone.getDomains().get(1))))); -// -// // ここでオリジナルにドメインを追加する -// rootModel.getDomains().add(domain2); -// -// assertThat(rootModel.getDomains().get(1), is(sameInstance(domain2))); -// -// // 追加分はクローンに影響しない -// assertThat(rootModel.getDomains().size(), is(2)); -// assertThat(clone.getDomains().size(), is(1)); - } - - /** - * 外部キーのクローニングが適切に行われること。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - @Ignore("not implemented") - public void test09_外部キーのクローニングが適切に行われること() throws Exception { - // モデル構築 - TableModel tableModel1 = factory.newModel(TableModel.class); - tableModel1.setName("table1"); - TableModel tableModel2 = factory.newModel(TableModel.class); - tableModel2.setName("table2"); - rootModel.getEntities().add(tableModel1); - rootModel.getEntities().add(tableModel2); - - ForeignKey foreignKey = factory.newModel(ForeignKey.class); - AttributeUtil.autoDenominate(foreignKey, rootModel); - tableModel1.getAttributes().add(foreignKey); - - // RootModelをクローニングする -// RootModel cloneRoot = rootModel.clone(); -// TableModel cloneTable1 = RootModelUtil.getEntity(cloneRoot, TableModel.class, "table1"); -// TableModel cloneTable2 = RootModelUtil.getEntity(cloneRoot, TableModel.class, "table2"); -// ForeignKey cloneFk = RootModelUtil.getAllForeignKeys(cloneRoot).iterator().next(); -// -// // RootModelのIDは同一、インスタンスは別 -// assertThat(cloneRoot.getId(), is(rootModel.getId())); -// assertThat(cloneRoot, is(not(sameInstance(rootModel)))); -// -// // オリジナルとクローンで、node, connectionの数は同じ -// assertThat(rootModel.getEntities().size(), is(2)); -// assertThat(cloneRoot.getEntities().size(), is(2)); -// assertThat(RootModelUtil.getAllForeignKeys(rootModel).size(), is(1)); -// assertThat(RootModelUtil.getAllForeignKeys(cloneRoot).size(), is(1)); -// -// // node, connectionのIDは同一 -// assertThat(table1.getId(), is(cloneTable1.getId())); -// assertThat(table2.getId(), is(cloneTable1.getId())); -// assertThat(cloneFk.getId(), is(fk.getId())); -// -// // node, connectionのインスタンスは別 -// assertThat(table1, is(not(sameInstance(cloneTable1)))); -// assertThat(table2, is(not(sameInstance(cloneTable2)))); -// assertThat(cloneFk, is(not(sameInstance(fk)))); - } - -} Modified: artemis/trunk/jiemamy-dialect-mysql/src/main/java/org/jiemamy/dialect/mysql/MySqlDialect.java =================================================================== --- artemis/trunk/jiemamy-dialect-mysql/src/main/java/org/jiemamy/dialect/mysql/MySqlDialect.java 2009-03-21 04:23:00 UTC (rev 2975) +++ artemis/trunk/jiemamy-dialect-mysql/src/main/java/org/jiemamy/dialect/mysql/MySqlDialect.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -61,19 +61,6 @@ static { List<BuiltinDataTypeMold> list = CollectionsUtil.newArrayList(); - list.add(new BuiltinDataTypeMoldImpl(CHARACTER, SizedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(VARCHAR, SizedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(CLOB, "TEXT")); - list.add(new BuiltinDataTypeMoldImpl(CLOB, "TINYTEXT")); - list.add(new BuiltinDataTypeMoldImpl(CLOB, "MEDIUMTEXT")); - list.add(new BuiltinDataTypeMoldImpl(CLOB, "LONGTEXT")); - list.add(new BuiltinDataTypeMoldImpl(BLOB)); - list.add(new BuiltinDataTypeMoldImpl(BLOB, "TINYBLOB")); - list.add(new BuiltinDataTypeMoldImpl(BLOB, "MEDIUMBLOB")); - list.add(new BuiltinDataTypeMoldImpl(BLOB, "LONGBLOB")); - list.add(new BuiltinDataTypeMoldImpl(BIT, SizedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(NUMERIC, PrecisionedDataTypeAdapter.class, Unsigned.class)); - list.add(new BuiltinDataTypeMoldImpl(DECIMAL, PrecisionedDataTypeAdapter.class, Unsigned.class)); list.add(new BuiltinDataTypeMoldImpl(INTEGER, new Class[] { SizedDataTypeAdapter.class, SerialDataTypeAdapter.class, @@ -99,9 +86,22 @@ SerialDataTypeAdapter.class, Unsigned.class })); + list.add(new BuiltinDataTypeMoldImpl(NUMERIC, PrecisionedDataTypeAdapter.class, Unsigned.class)); + list.add(new BuiltinDataTypeMoldImpl(DECIMAL, PrecisionedDataTypeAdapter.class, Unsigned.class)); list.add(new BuiltinDataTypeMoldImpl(FLOAT, PrecisionedDataTypeAdapter.class, Unsigned.class)); list.add(new BuiltinDataTypeMoldImpl(REAL, PrecisionedDataTypeAdapter.class, Unsigned.class)); list.add(new BuiltinDataTypeMoldImpl(DOUBLE, PrecisionedDataTypeAdapter.class, Unsigned.class)); + list.add(new BuiltinDataTypeMoldImpl(BIT, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(CHARACTER, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(VARCHAR, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(CLOB, "TEXT")); + list.add(new BuiltinDataTypeMoldImpl(CLOB, "TINYTEXT")); + list.add(new BuiltinDataTypeMoldImpl(CLOB, "MEDIUMTEXT")); + list.add(new BuiltinDataTypeMoldImpl(CLOB, "LONGTEXT")); + list.add(new BuiltinDataTypeMoldImpl(BLOB)); + list.add(new BuiltinDataTypeMoldImpl(BLOB, "TINYBLOB")); + list.add(new BuiltinDataTypeMoldImpl(BLOB, "MEDIUMBLOB")); + list.add(new BuiltinDataTypeMoldImpl(BLOB, "LONGBLOB")); list.add(new BuiltinDataTypeMoldImpl(DATE)); list.add(new BuiltinDataTypeMoldImpl(TIME)); list.add(new BuiltinDataTypeMoldImpl(TIMESTAMP)); Modified: artemis/trunk/jiemamy-dialect-postgresql/src/main/java/org/jiemamy/dialect/postgresql/PostgresqlDialect.java =================================================================== --- artemis/trunk/jiemamy-dialect-postgresql/src/main/java/org/jiemamy/dialect/postgresql/PostgresqlDialect.java 2009-03-21 04:23:00 UTC (rev 2975) +++ artemis/trunk/jiemamy-dialect-postgresql/src/main/java/org/jiemamy/dialect/postgresql/PostgresqlDialect.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -69,11 +69,11 @@ list.add(new BuiltinDataTypeMoldImpl(FLOAT, "REAL")); list.add(new BuiltinDataTypeMoldImpl(REAL)); list.add(new BuiltinDataTypeMoldImpl(DOUBLE, "DOUBLE PRECISION")); + list.add(new BuiltinDataTypeMoldImpl(BIT, SizedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(CHARACTER, SizedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(VARCHAR, SizedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(CLOB, "TEXT")); list.add(new BuiltinDataTypeMoldImpl(BLOB, "BYTEA")); - list.add(new BuiltinDataTypeMoldImpl(BIT, SizedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(VARBIT, SizedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(BOOLEAN)); list.add(new BuiltinDataTypeMoldImpl(DATE)); Modified: artemis/trunk/jiemamy-dialect-sql99/src/main/java/org/jiemamy/dialect/sql99/Sql99Dialect.java =================================================================== --- artemis/trunk/jiemamy-dialect-sql99/src/main/java/org/jiemamy/dialect/sql99/Sql99Dialect.java 2009-03-21 04:23:00 UTC (rev 2975) +++ artemis/trunk/jiemamy-dialect-sql99/src/main/java/org/jiemamy/dialect/sql99/Sql99Dialect.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -62,20 +62,20 @@ static { List<BuiltinDataTypeMold> list = CollectionsUtil.newArrayList(); - list.add(new BuiltinDataTypeMoldImpl(CHARACTER, SizedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(VARCHAR, SizedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(CLOB, SizedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(BLOB, SizedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(BIT, SizedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(VARBIT, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(INTEGER)); + list.add(new BuiltinDataTypeMoldImpl(SMALLINT)); list.add(new BuiltinDataTypeMoldImpl(NUMERIC, PrecisionedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(DECIMAL, PrecisionedDataTypeAdapter.class)); - list.add(new BuiltinDataTypeMoldImpl(INTEGER)); - list.add(new BuiltinDataTypeMoldImpl(SMALLINT)); list.add(new BuiltinDataTypeMoldImpl(FLOAT, PrecisionedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(REAL, PrecisionedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(DOUBLE, PrecisionedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(BIT, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(VARBIT, SizedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(BOOLEAN)); + list.add(new BuiltinDataTypeMoldImpl(CHARACTER, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(VARCHAR, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(CLOB, SizedDataTypeAdapter.class)); + list.add(new BuiltinDataTypeMoldImpl(BLOB, SizedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(DATE)); list.add(new BuiltinDataTypeMoldImpl(TIME, TimezonedDataTypeAdapter.class)); list.add(new BuiltinDataTypeMoldImpl(TIMESTAMP, TimezonedDataTypeAdapter.class)); Deleted: artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/JiemamyViewPropertyTest.java =================================================================== --- artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/JiemamyViewPropertyTest.java 2009-03-21 04:23:00 UTC (rev 2975) +++ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/JiemamyViewPropertyTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,165 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2009/03/01 - * - * 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.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; -import static org.junit.Assert.fail; - -import java.lang.reflect.Field; -import java.lang.reflect.Method; - -import org.apache.commons.lang.ClassUtils; -import org.junit.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import org.jiemamy.internal.model.attribute.constraint.AbstractConstraintModel; -import org.jiemamy.utils.ReflectionUtil; - -/** - * {@link JiemamyViewProperty}のテストクラス。 - * <p>j-core内のJiemamyPropertyテストクラスのコピー。</p> - * - * @author shin1ogawa - */ -public class JiemamyViewPropertyTest { - - private static final Logger LOGGER = LoggerFactory.getLogger(JiemamyViewProperty.class); - - - /** - * 各モデルのインターフェイスは、{@link JiemamyProperty}で示されるgetterを持つべきである。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test01_ModelHasGetter() throws Exception { - for (Class<?> enumClass : JiemamyViewProperty.class.getClasses()) { - if (Enum.class.isAssignableFrom(enumClass) == false) { - continue; - } - LOGGER.debug("target enumClass: " + enumClass.getSimpleName()); - TargetModel annot = enumClass.getAnnotation(TargetModel.class); - assertThat("JiemamyPropertyの内部列挙型はTargetModelアノテーションを持たなければならない", annot, is(notNullValue())); - - Class<?> targetModelClass = annot.value(); - for (Field field : enumClass.getFields()) { - String iserName = ReflectionUtil.convertFieldToAccessorName(field, "is"); - String getterName = ReflectionUtil.convertFieldToAccessorName(field, "get"); - try { - targetModelClass.getMethod(getterName); - } catch (NoSuchMethodException e) { - Method iserMethod; - try { - iserMethod = targetModelClass.getMethod(iserName); - if (iserMethod.getReturnType() != Boolean.class && iserMethod.getReturnType() != boolean.class) { - fail(targetModelClass.getName() + " is not have " + getterName); - } - } catch (NoSuchMethodException e2) { - fail(targetModelClass.getName() + " is not have " + getterName + " or " + iserName); - } - } - } - } - } - - /** - * 各モデルの実装クラスは、{@link JiemamyProperty}で示されるフィールドを持つべきである。 - * - * <p>Artemis特有。仕様ではない。</p> - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test02_ModelHasField() throws Exception { - for (Class<?> enumClass : JiemamyViewProperty.class.getClasses()) { - if (Enum.class.isAssignableFrom(enumClass) == false) { - continue; - } - - LOGGER.debug("target enumClass: " + enumClass.getSimpleName()); - TargetModel annot = enumClass.getAnnotation(TargetModel.class); - assertThat("JiemamyPropertyの内部列挙型はTargetModelアノテーションを持たなければならない", annot, is(notNullValue())); - - Class<?> interfaceClass = annot.value(); - String implClassName = interfaceClass.getName() + "Impl"; - - Class<?> targetModelClass; - try { - targetModelClass = Class.forName(implClassName); - } catch (ClassNotFoundException e) { - String packageName = ClassUtils.getPackageName(interfaceClass); - String shortClassName = ClassUtils.getShortClassName(interfaceClass); - - implClassName = packageName + ".Abstract" + shortClassName; - try { - targetModelClass = Class.forName(implClassName); - } catch (ClassNotFoundException e2) { - e2.printStackTrace(); - continue; - } - } - - Field[] enumFields = enumClass.getFields(); - for (Field enumField : enumFields) { - try { - targetModelClass.getDeclaredField(enumField.getName()); - } catch (NoSuchFieldException e) { - if (targetModelClass == AbstractConstraintModel.class && enumField.getName() == "name") { - // 例外 success - } else { - fail(targetModelClass.getName() + " is not have " + enumField.getName()); - } - } - } - } - } - - /** - * {@link JiemamyProperty}は、各モデルのインターフェイスのgetterで示されるプロパティを網羅すべきである。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test03_PropertyHasFieldName() throws Exception { - for (Class<?> clazz : JiemamyViewProperty.class.getClasses()) { - if (Enum.class.isAssignableFrom(clazz) == false) { - continue; - } - LOGGER.debug("target enumClass: " + clazz.getSimpleName()); - TargetModel annot = clazz.getAnnotation(TargetModel.class); - Class<?> targetModelClass = annot.value(); - Method[] methods = targetModelClass.getDeclaredMethods(); - for (Method method : methods) { - if (ReflectionUtil.isGetter(method) == false) { - continue; - } - String fieldName = ReflectionUtil.convertAccessorToFieldName(method); - try { - clazz.getField(fieldName); - } catch (NoSuchFieldException e) { - fail(clazz.getName() + " is not have " + fieldName); - } - } - } - - } -} Copied: artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/JiemamyViewFacadeImplTest.java (from rev 2972, artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/facade/JiemamyViewFacadeImplTest.java) =================================================================== --- artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/JiemamyViewFacadeImplTest.java (rev 0) +++ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/JiemamyViewFacadeImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,314 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/03/01 + * + * 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.internal; + +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; +import static org.junit.Assert.assertThat; + +import java.util.List; + +import org.junit.Before; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.jiemamy.Artemis; +import org.jiemamy.ArtemisView; +import org.jiemamy.Jiemamy; +import org.jiemamy.JiemamyFactory; +import org.jiemamy.Migration; +import org.jiemamy.ReferenceResolver; +import org.jiemamy.facade.JiemamyViewFacade; +import org.jiemamy.facade.SavePoint; +import org.jiemamy.model.DiagramPresentationModel; +import org.jiemamy.model.DiagramPresentations; +import org.jiemamy.model.NodeProfile; +import org.jiemamy.model.RootModel; +import org.jiemamy.model.attribute.ColumnModel; +import org.jiemamy.model.attribute.constraint.ForeignKey; +import org.jiemamy.model.attribute.constraint.PrimaryKey; +import org.jiemamy.model.connection.ConnectionAdapter; +import org.jiemamy.model.entity.EntityModel; +import org.jiemamy.model.entity.TableModel; +import org.jiemamy.model.geometory.JmRectangle; +import org.jiemamy.model.node.NodeAdapter; +import org.jiemamy.utils.model.TableUtil; + +/** + * {@link JiemamyViewFacadeImpl}のテストクラス。 + * + * @author shin1ogawa + */ +public class JiemamyViewFacadeImplTest { + + private Jiemamy jiemamyWithView; + + private JiemamyViewFacade viewFacade; + + private JiemamyFactory factory; + + private RootModel rootModel; + + private DiagramPresentationModel diagramPresentationModel; + + private ReferenceResolver referenceResolver; + + private static Logger logger = LoggerFactory.getLogger(JiemamyViewFacadeImplTest.class); + + + /** + * + */ + @Before + public void setUp() { + jiemamyWithView = Jiemamy.newInstance(new Artemis(new ArtemisView())); + viewFacade = new JiemamyViewFacadeImpl(jiemamyWithView); + factory = jiemamyWithView.getFactory(); + rootModel = factory.getRootModel(); + referenceResolver = jiemamyWithView.getReferenceResolver(); + diagramPresentationModel = factory.newModel(DiagramPresentationModel.class); + rootModel.getAdapter(DiagramPresentations.class).add(diagramPresentationModel); + } + + /** + * {@link JiemamyViewFacadeImpl#addNodeProfile(int, NodeAdapter, NodeProfile)}のテスト + */ + @Test + public void test_addNodeProfile() { + TableModel tableModel = factory.newModel(TableModel.class); + NodeAdapter nodeAdapter = tableModel.getAdapter(NodeAdapter.class); + NodeProfile nodeProfile = factory.newModel(NodeProfile.class); + + SavePoint save = viewFacade.save(); + viewFacade.addNodeProfile(0, nodeAdapter, nodeProfile); + + assertThat(rootModel.getAdapter(DiagramPresentations.class).get(0).getNodeProfiles().get(nodeAdapter), + is(nodeProfile)); + + viewFacade.rollback(save); + + assertThat(rootModel.getAdapter(DiagramPresentations.class).get(0).getNodeProfiles().get(nodeAdapter), + nullValue()); + } + + /** + * {@link JiemamyViewFacadeImpl#createConnection(int, ConnectionAdapter, TableModel, TableModel)}のテスト。 + */ + @Test + public void test_createConnection() { + TableModel[] tables = setUpForConnectionTest(); + ForeignKey foreignKey = factory.newModel(ForeignKey.class); + ConnectionAdapter connectionAdapter = foreignKey.getAdapter(ConnectionAdapter.class); + List<ForeignKey> foreignKeys = TableUtil.getForeignKeys(tables[1]); + assertThat(foreignKeys.size(), is(0)); + + SavePoint save = viewFacade.save(); + viewFacade.createConnection(Migration.DIAGRAM_INDEX, connectionAdapter, tables[1], tables[0]); + logger.info(connectionAdapter.getSource().unwrap().toString()); + assertThat(connectionAdapter.getSource().unwrap(), is((EntityModel) tables[1])); + assertThat(connectionAdapter.getTarget().unwrap(), is((EntityModel) tables[0])); + foreignKeys = TableUtil.getForeignKeys(tables[1]); + assertThat(foreignKeys.size(), is(1)); + assertThat(foreignKeys.get(0), is(foreignKey)); + assertThat(foreignKey.getKeyColumns().size(), is(1)); + assertThat(foreignKey.getReferenceColumns().size(), is(1)); + assertThat(referenceResolver.resolve(foreignKey.getKeyColumns().get(0)), is(TableUtil.getColumns(tables[1]) + .get(0))); + + viewFacade.rollback(save); + foreignKeys = TableUtil.getForeignKeys(tables[1]); + assertThat(foreignKeys.size(), is(0)); + assertThat(foreignKey.getKeyColumns().size(), is(0)); + assertThat(foreignKey.getReferenceColumns().size(), is(0)); + } + + /** + * {@link JiemamyViewFacadeImpl#addNode(int, NodeAdapter, JmRectangle)}のテスト。 + */ + @Test + public void test_createNodeCommand() { + final TableModel tableModel = factory.newModel(TableModel.class); + final NodeAdapter nodeAdapter = tableModel.getAdapter(NodeAdapter.class); + final JmRectangle rectangle = new JmRectangle(0, 0); + + /** test_createNodeCommandのテストのためのヘルパークラス */ + class TestCreateNodeCommandHelper { + + NodeProfile nodeProfile; + + + void assertAfter() { + assertThat(rootModel.getEntities().contains(tableModel), is(true)); + assertThat(diagramPresentationModel.getNodeProfiles().get(nodeAdapter), is(notNullValue())); + nodeProfile = diagramPresentationModel.getNodeProfiles().get(nodeAdapter); + assertThat(nodeProfile.getBoundary(), is(rectangle)); + } + + void assertBefore() { + assertThat(rootModel.getEntities().contains(tableModel), is(false)); + assertThat(diagramPresentationModel.getNodeProfiles().get(nodeAdapter), is(nullValue())); + nodeProfile = diagramPresentationModel.getNodeProfiles().get(nodeAdapter); + assertThat(nodeProfile, is(nullValue())); + } + } + TestCreateNodeCommandHelper testHelper = new TestCreateNodeCommandHelper(); + + testHelper.assertBefore(); + + // 処理 + SavePoint before = viewFacade.save(); + viewFacade.addNode(Migration.DIAGRAM_INDEX, nodeAdapter, rectangle); + SavePoint after = viewFacade.save(); + + testHelper.assertAfter(); + + viewFacade.rollback(before); // undo + testHelper.assertBefore(); + + viewFacade.rollback(after); // redo + testHelper.assertAfter(); + } + + /** + * {@link JiemamyViewFacadeImpl#removeNode(int, NodeAdapter)}のテスト。 + * + */ + @Test + public void test_removeNode() { + // 動作が怪しいとの報告があったので試験を書いて安心したい。 + // GEF側のCreateConnectionCommandの中をFacadeに展開してから書いた方が良いと気づいた。 + TableModel[] tables = setUpForConnectionTest(); + + ForeignKey foreignKey1to0 = factory.newModel(ForeignKey.class); + ConnectionAdapter connection1 = foreignKey1to0.getAdapter(ConnectionAdapter.class); + viewFacade.createConnection(Migration.DIAGRAM_INDEX, connection1, tables[1], tables[0]); + + ForeignKey foreignKey2to0 = factory.newModel(ForeignKey.class); + ConnectionAdapter connection2 = foreignKey2to0.getAdapter(ConnectionAdapter.class); + viewFacade.createConnection(Migration.DIAGRAM_INDEX, connection2, tables[2], tables[0]); + + assertThat(TableUtil.getForeignKeys(tables[1]).size(), is(1)); + assertThat(TableUtil.getForeignKeys(tables[2]).size(), is(1)); + assertThat(foreignKey1to0.getKeyColumns().size(), is(1)); + assertThat(foreignKey1to0.getReferenceColumns().size(), is(1)); + assertThat(foreignKey2to0.getKeyColumns().size(), is(1)); + assertThat(foreignKey2to0.getReferenceColumns().size(), is(1)); + + SavePoint save = viewFacade.save(); + // do + viewFacade.removeNode(Migration.DIAGRAM_INDEX, tables[1].getAdapter(NodeAdapter.class)); + SavePoint save2 = viewFacade.save(); + + assertThat(TableUtil.getForeignKeys(tables[1]).size(), is(0)); // 切れる + assertThat(TableUtil.getForeignKeys(tables[2]).size(), is(1)); // 影響を受けない + // THINK 以下も満たされるべきか?と思ったが、 + // RootModelから完全に切り離されたモデルはどーでもいい、という結論になった。 + // つまり、createConnection()とremoveConnection()の間の対称性が崩れた状態となっているが気にしない。 +// assertThat(foreignKey1to0.getKeyColumns().size(), is(0)); +// assertThat(foreignKey1to0.getReferenceColumns().size(), is(0)); +// assertThat(foreignKey2to0.getKeyColumns().size(), is(0)); +// assertThat(foreignKey2to0.getReferenceColumns().size(), is(0)); + + viewFacade.rollback(save); // undo + assertThat(TableUtil.getForeignKeys(tables[1]).size(), is(1)); + assertThat(TableUtil.getForeignKeys(tables[2]).size(), is(1)); + assertThat(foreignKey1to0.getKeyColumns().size(), is(1)); + assertThat(foreignKey1to0.getReferenceColumns().size(), is(1)); + assertThat(foreignKey2to0.getKeyColumns().size(), is(1)); + assertThat(foreignKey2to0.getReferenceColumns().size(), is(1)); + + viewFacade.rollback(save2); // redo + assertThat(TableUtil.getForeignKeys(tables[1]).size(), is(0)); // 切れる + assertThat(TableUtil.getForeignKeys(tables[2]).size(), is(1)); // 影響を受けない + } + + private TableModel[] setUpForConnectionTest() { + TableModel tableModel1 = factory.newModel(TableModel.class); + viewFacade.addEntity(tableModel1); + ColumnModel columnModel1a = factory.newModel(ColumnModel.class); + ColumnModel columnModel1b = factory.newModel(ColumnModel.class); + ColumnModel columnModel1c = factory.newModel(ColumnModel.class); + NodeAdapter nodeAdapter1 = tableModel1.getAdapter(NodeAdapter.class); + NodeProfile nodeProfile1 = factory.newModel(NodeProfile.class); + JmRectangle rectangle1 = new JmRectangle(0, 0); + viewFacade.addEntity(tableModel1); + viewFacade.addNodeProfile(Migration.DIAGRAM_INDEX, nodeAdapter1, nodeProfile1); + viewFacade.changeNodeBoundary(Migration.DIAGRAM_INDEX, nodeAdapter1, rectangle1); + viewFacade.addAttribute(tableModel1, columnModel1a); + viewFacade.addAttribute(tableModel1, columnModel1b); + viewFacade.addAttribute(tableModel1, columnModel1c); + PrimaryKey primaryKey1 = factory.newModel(PrimaryKey.class); + viewFacade.addAttribute(tableModel1, primaryKey1); + viewFacade.addKeyColumn(primaryKey1, columnModel1a); + assertThat(rootModel.getEntities().contains(tableModel1), is(true)); + assertThat(diagramPresentationModel.getNodeProfiles().get(nodeAdapter1), is(nodeProfile1)); + assertThat(nodeProfile1.getBoundary(), is(rectangle1)); + assertThat(TableUtil.getColumns(tableModel1).size(), is(3)); + + TableModel tableModel2 = factory.newModel(TableModel.class); + viewFacade.addEntity(tableModel2); + ColumnModel columnModel2a = factory.newModel(ColumnModel.class); + ColumnModel columnModel2b = factory.newModel(ColumnModel.class); + NodeAdapter nodeAdapter2 = tableModel2.getAdapter(NodeAdapter.class); + NodeProfile nodeProfile2 = rootModel.getJiemamy().getFactory().newModel(NodeProfile.class); + JmRectangle rectangle2 = new JmRectangle(0, 0); + viewFacade.addEntity(tableModel2); + viewFacade.addNodeProfile(Migration.DIAGRAM_INDEX, nodeAdapter2, nodeProfile2); + viewFacade.changeNodeBoundary(Migration.DIAGRAM_INDEX, nodeAdapter2, rectangle2); + viewFacade.addAttribute(tableModel2, columnModel2a); + viewFacade.addAttribute(tableModel2, columnModel2b); + PrimaryKey primaryKey2 = factory.newModel(PrimaryKey.class); + viewFacade.addAttribute(tableModel2, primaryKey2); + viewFacade.addKeyColumn(primaryKey2, columnModel2a); + viewFacade.addKeyColumn(primaryKey2, columnModel2b); + assertThat(rootModel.getEntities().contains(tableModel1), is(true)); + assertThat(diagramPresentationModel.getNodeProfiles().get(nodeAdapter1), is(nodeProfile1)); + assertThat(nodeProfile1.getBoundary(), is(rectangle1)); + assertThat(TableUtil.getColumns(tableModel2).size(), is(2)); + + TableModel tableModel3 = factory.newModel(TableModel.class); + viewFacade.addEntity(tableModel3); + ColumnModel columnModel3a = factory.newModel(ColumnModel.class); + ColumnModel columnModel3b = factory.newModel(ColumnModel.class); + NodeAdapter nodeAdapter3 = tableModel3.getAdapter(NodeAdapter.class); + NodeProfile nodeProfile3 = rootModel.getJiemamy().getFactory().newModel(NodeProfile.class); + JmRectangle rectangle3 = new JmRectangle(0, 0); + viewFacade.addEntity(tableModel3); + viewFacade.addNodeProfile(Migration.DIAGRAM_INDEX, nodeAdapter3, nodeProfile3); + viewFacade.changeNodeBoundary(Migration.DIAGRAM_INDEX, nodeAdapter3, rectangle3); + viewFacade.addAttribute(tableModel3, columnModel3a); + viewFacade.addAttribute(tableModel3, columnModel3b); + PrimaryKey primaryKey3 = factory.newModel(PrimaryKey.class); + viewFacade.addAttribute(tableModel3, primaryKey3); + viewFacade.addKeyColumn(primaryKey3, columnModel3a); + viewFacade.addKeyColumn(primaryKey3, columnModel3b); + assertThat(rootModel.getEntities().contains(tableModel1), is(true)); + assertThat(diagramPresentationModel.getNodeProfiles().get(nodeAdapter1), is(nodeProfile1)); + assertThat(nodeProfile1.getBoundary(), is(rectangle1)); + assertThat(TableUtil.getColumns(tableModel3).size(), is(2)); + + return new TableModel[] { + tableModel1, + tableModel2, + tableModel3 + }; + } +} Property changes on: artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/JiemamyViewFacadeImplTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Copied: artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/JiemamyViewPropertyTest.java (from rev 2972, artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/JiemamyViewPropertyTest.java) =================================================================== --- artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/JiemamyViewPropertyTest.java (rev 0) +++ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/JiemamyViewPropertyTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,168 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/03/01 + * + * 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.internal; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; +import static org.junit.Assert.fail; + +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +import org.apache.commons.lang.ClassUtils; +import org.junit.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.jiemamy.JiemamyProperty; +import org.jiemamy.JiemamyViewProperty; +import org.jiemamy.TargetModel; +import org.jiemamy.internal.model.attribute.constraint.AbstractConstraintModel; +import org.jiemamy.utils.ReflectionUtil; + +/** + * {@link JiemamyViewProperty}のテストクラス。 + * <p>j-core内のJiemamyPropertyテストクラスのコピー。</p> + * + * @author shin1ogawa + */ +public class JiemamyViewPropertyTest { + + private static final Logger LOGGER = LoggerFactory.getLogger(JiemamyViewProperty.class); + + + /** + * 各モデルのインターフェイスは、{@link JiemamyProperty}で示されるgetterを持つべきである。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test01_ModelHasGetter() throws Exception { + for (Class<?> enumClass : JiemamyViewProperty.class.getClasses()) { + if (Enum.class.isAssignableFrom(enumClass) == false) { + continue; + } + LOGGER.debug("target enumClass: " + enumClass.getSimpleName()); + TargetModel annot = enumClass.getAnnotation(TargetModel.class); + assertThat("JiemamyPropertyの内部列挙型はTargetModelアノテーションを持たなければならない", annot, is(notNullValue())); + + Class<?> targetModelClass = annot.value(); + for (Field field : enumClass.getFields()) { + String iserName = ReflectionUtil.convertFieldToAccessorName(field, "is"); + String getterName = ReflectionUtil.convertFieldToAccessorName(field, "get"); + try { + targetModelClass.getMethod(getterName); + } catch (NoSuchMethodException e) { + Method iserMethod; + try { + iserMethod = targetModelClass.getMethod(iserName); + if (iserMethod.getReturnType() != Boolean.class && iserMethod.getReturnType() != boolean.class) { + fail(targetModelClass.getName() + " is not have " + getterName); + } + } catch (NoSuchMethodException e2) { + fail(targetModelClass.getName() + " is not have " + getterName + " or " + iserName); + } + } + } + } + } + + /** + * 各モデルの実装クラスは、{@link JiemamyProperty}で示されるフィールドを持つべきである。 + * + * <p>Artemis特有。仕様ではない。</p> + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test02_ModelHasField() throws Exception { + for (Class<?> enumClass : JiemamyViewProperty.class.getClasses()) { + if (Enum.class.isAssignableFrom(enumClass) == false) { + continue; + } + + LOGGER.debug("target enumClass: " + enumClass.getSimpleName()); + TargetModel annot = enumClass.getAnnotation(TargetModel.class); + assertThat("JiemamyPropertyの内部列挙型はTargetModelアノテーションを持たなければならない", annot, is(notNullValue())); + + Class<?> interfaceClass = annot.value(); + String implClassName = interfaceClass.getName() + "Impl"; + + Class<?> targetModelClass; + try { + targetModelClass = Class.forName(implClassName); + } catch (ClassNotFoundException e) { + String packageName = ClassUtils.getPackageName(interfaceClass); + String shortClassName = ClassUtils.getShortClassName(interfaceClass); + + implClassName = packageName + ".Abstract" + shortClassName; + try { + targetModelClass = Class.forName(implClassName); + } catch (ClassNotFoundException e2) { + e2.printStackTrace(); + continue; + } + } + + Field[] enumFields = enumClass.getFields(); + for (Field enumField : enumFields) { + try { + targetModelClass.getDeclaredField(enumField.getName()); + } catch (NoSuchFieldException e) { + if (targetModelClass == AbstractConstraintModel.class && enumField.getName() == "name") { + // 例外 success + } else { + fail(targetModelClass.getName() + " is not have " + enumField.getName()); + } + } + } + } + } + + /** + * {@link JiemamyProperty}は、各モデルのインターフェイスのgetterで示されるプロパティを網羅すべきである。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test03_PropertyHasFieldName() throws Exception { + for (Class<?> clazz : JiemamyViewProperty.class.getClasses()) { + if (Enum.class.isAssignableFrom(clazz) == false) { + continue; + } + LOGGER.debug("target enumClass: " + clazz.getSimpleName()); + TargetModel annot = clazz.getAnnotation(TargetModel.class); + Class<?> targetModelClass = annot.value(); + Method[] methods = targetModelClass.getDeclaredMethods(); + for (Method method : methods) { + if (ReflectionUtil.isGetter(method) == false) { + continue; + } + String fieldName = ReflectionUtil.convertAccessorToFieldName(method); + try { + clazz.getField(fieldName); + } catch (NoSuchFieldException e) { + fail(clazz.getName() + " is not have " + fieldName); + } + } + } + + } +} Property changes on: artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/JiemamyViewPropertyTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Copied: artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/DiagramPresentationModelImplTest.java (from rev 2972, artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/model/DiagramPresentationModelImplTest.java) =================================================================== --- artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/DiagramPresentationModelImplTest.java (rev 0) +++ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/DiagramPresentationModelImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,96 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2008/11/13 + * + * 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.internal.model; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.junit.Assert.assertThat; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.jiemamy.Artemis; +import org.jiemamy.ArtemisView; +import org.jiemamy.Jiemamy; +import org.jiemamy.JiemamyFactory; +import org.jiemamy.model.DiagramPresentationModel; +import org.jiemamy.model.DiagramPresentations; +import org.jiemamy.model.RootModel; + +/** + * {@link DiagramPresentationModelImpl}のテストクラス。 + * + * @author daisuke + */ +public class DiagramPresentationModelImplTest { + + private RootModel rootModel; + + private DiagramPresentationModel presentation; + + private JiemamyFactory factory; + + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView())); + factory = jiemamy.getFactory(); + rootModel = factory.getRootModel(); + presentation = factory.newModel(DiagramPresentationModel.class); + presentation.setName("testPresentation"); + DiagramPresentations diagramPresentations = rootModel.getAdapter(DiagramPresentations.class); + diagramPresentations.add(presentation); + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + DiagramPresentations diagramPresentations = rootModel.getAdapter(DiagramPresentations.class); + diagramPresentations.remove(presentation); + presentation = null; + rootModel = null; + factory = null; + } + + /** + * 各プロパティが正常に初期化されていること。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test01_各プロパティが正常に初期化されていること() throws Exception { + assertThat(presentation.getNodeProfiles(), is(notNullValue())); + assertThat(presentation.getConnectionProfiles(), is(notNullValue())); + assertThat(presentation.getMode(), is(notNullValue())); + assertThat(presentation.getLevel(), is(notNullValue())); + assertThat(presentation.getName(), is("testPresentation")); + + assertThat(presentation.getNodeProfiles().size(), is(0)); + } +} Property changes on: artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/DiagramPresentationModelImplTest.java ___________________________________________________________________ Added: svn:mime-type + text/plain Deleted: artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/connection/ConnectionModelImplTest.java =================================================================== --- artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/model/connection/ConnectionModelImplTest.java 2009-03-20 15:22:38 UTC (rev 2971) +++ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/connection/ConnectionModelImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,129 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2009/01/23 - * - * 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.model.connection; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.sameInstance; -import static org.junit.Assert.assertThat; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import org.jiemamy.Artemis; -import org.jiemamy.ArtemisView; -import org.jiemamy.Jiemamy; -import org.jiemamy.internal.test.ReflectionDialectProvider; -import org.jiemamy.internal.test.TestModelBuilder; -import org.jiemamy.internal.test.TestModelBuilder2; -import org.jiemamy.model.node.NodeAdapter; - -/** - * {@link ConnectionAdapterImpl}のテストクラス。 - * - * @author daisuke - */ -public class ConnectionModelImplTest { - - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - } - - /** - * FKからコネクションが取得でき、そのソースとターゲットが正常に取得できる。empDept版。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test01_FKからコネクションが取得でき_そのソースとターゲットが正常に取得できる_empDept() throws Exception { - Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView()), new ReflectionDialectProvider()); - TestModelBuilder mb = new TestModelBuilder(jiemamy); - mb.build(); - - ConnectionAdapter empDeptConnection = mb.fkEmpDept.getAdapter(ConnectionAdapter.class); - assertThat(empDeptConnection, is(notNullValue())); - assertThat(empDeptConnection.unwrap(), is(sameInstance(mb.fkEmpDept))); - - ConnectionAdapter empEmpConnection = mb.fkEmpEmp.getAdapter(ConnectionAdapter.class); - assertThat(empEmpConnection, is(notNullValue())); - assertThat(empEmpConnection.unwrap(), is(sameInstance(mb.fkEmpEmp))); - - NodeAdapter empNode = mb.tableEmp.getAdapter(NodeAdapter.class); - NodeAdapter deptNode = mb.tableDept.getAdapter(NodeAdapter.class); - - assertThat(empDeptConnection.getSource(), is(sameInstance(empNode))); - assertThat(empDeptConnection.getTarget(), is(sameInstance(deptNode))); - - assertThat(empEmpConnection.getSource(), is(sameInstance(empNode))); - assertThat(empEmpConnection.getTarget(), is(sameInstance(empNode))); - } - - /** - * FKからコネクションが取得でき、そのソースとターゲットが正常に取得できる。order版。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test02_FKからコネクションが取得でき_そのソースとターゲットが正常に取得できる_order() throws Exception { - Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView()), new ReflectionDialectProvider()); - TestModelBuilder2 mb = new TestModelBuilder2(jiemamy); - mb.build(); - - ConnectionAdapter detailItemConnection = mb.fkDetailItem.getAdapter(ConnectionAdapter.class); - assertThat(detailItemConnection, is(notNullValue())); - assertThat(detailItemConnection.unwrap(), is(sameInstance(mb.fkDetailItem))); - - ConnectionAdapter detailOrderConnection = mb.fkDetailOrder.getAdapter(ConnectionAdapter.class); - assertThat(detailOrderConnection, is(notNullValue())); - assertThat(detailOrderConnection.unwrap(), is(sameInstance(mb.fkDetailOrder))); - - ConnectionAdapter orderUserConnection = mb.fkOrderUser.getAdapter(ConnectionAdapter.class); - assertThat(orderUserConnection, is(notNullValue())); - assertThat(orderUserConnection.unwrap(), is(sameInstance(mb.fkOrderUser))); - - NodeAdapter detailNode = mb.tableDetail.getAdapter(NodeAdapter.class); - NodeAdapter itemNode = mb.tableItem.getAdapter(NodeAdapter.class); - NodeAdapter orderNode = mb.tableOrder.getAdapter(NodeAdapter.class); - NodeAdapter userNode = mb.tableUser.getAdapter(NodeAdapter.class); - - assertThat(detailItemConnection.getSource(), is(sameInstance(detailNode))); - assertThat(detailItemConnection.getTarget(), is(sameInstance(itemNode))); - - assertThat(detailOrderConnection.getSource(), is(sameInstance(detailNode))); - assertThat(detailOrderConnection.getTarget(), is(sameInstance(orderNode))); - - assertThat(orderUserConnection.getSource(), is(sameInstance(orderNode))); - assertThat(orderUserConnection.getTarget(), is(sameInstance(userNode))); - } -} Copied: artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/connection/ConnectionModelImplTest.java (from rev 2975, artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/model/connection/ConnectionModelImplTest.java) =================================================================== --- artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/connection/ConnectionModelImplTest.java (rev 0) +++ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/connection/ConnectionModelImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,130 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/01/23 + * + * 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.internal.model.connection; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.sameInstance; +import static org.junit.Assert.assertThat; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.jiemamy.Artemis; +import org.jiemamy.ArtemisView; +import org.jiemamy.Jiemamy; +import org.jiemamy.internal.test.ReflectionDialectProvider; +import org.jiemamy.internal.test.TestModelBuilder; +import org.jiemamy.internal.test.TestModelBuilder2; +import org.jiemamy.model.connection.ConnectionAdapter; +import org.jiemamy.model.node.NodeAdapter; + +/** + * {@link ConnectionAdapterImpl}のテストクラス。 + * + * @author daisuke + */ +public class ConnectionModelImplTest { + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + } + + /** + * FKからコネクションが取得でき、そのソースとターゲットが正常に取得できる。empDept版。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test01_FKからコネクションが取得でき_そのソースとターゲットが正常に取得できる_empDept() throws Exception { + Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView()), new ReflectionDialectProvider()); + TestModelBuilder mb = new TestModelBuilder(jiemamy); + mb.build(); + + ConnectionAdapter empDeptConnection = mb.fkEmpDept.getAdapter(ConnectionAdapter.class); + assertThat(empDeptConnection, is(notNullValue())); + assertThat(empDeptConnection.unwrap(), is(sameInstance(mb.fkEmpDept))); + + ConnectionAdapter empEmpConnection = mb.fkEmpEmp.getAdapter(ConnectionAdapter.class); + assertThat(empEmpConnection, is(notNullValue())); + assertThat(empEmpConnection.unwrap(), is(sameInstance(mb.fkEmpEmp))); + + NodeAdapter empNode = mb.tableEmp.getAdapter(NodeAdapter.class); + NodeAdapter deptNode = mb.tableDept.getAdapter(NodeAdapter.class); + + assertThat(empDeptConnection.getSource(), is(sameInstance(empNode))); + assertThat(empDeptConnection.getTarget(), is(sameInstance(deptNode))); + + assertThat(empEmpConnection.getSource(), is(sameInstance(empNode))); + assertThat(empEmpConnection.getTarget(), is(sameInstance(empNode))); + } + + /** + * FKからコネクションが取得でき、そのソースとターゲットが正常に取得できる。order版。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test02_FKからコネクションが取得でき_そのソースとターゲットが正常に取得できる_order() throws Exception { + Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView()), new ReflectionDialectProvider()); + TestModelBuilder2 mb = new TestModelBuilder2(jiemamy); + mb.build(); + + ConnectionAdapter detailItemConnection = mb.fkDetailItem.getAdapter(ConnectionAdapter.class); + assertThat(detailItemConnection, is(notNullValue())); + assertThat(detailItemConnection.unwrap(), is(sameInstance(mb.fkDetailItem))); + + ConnectionAdapter detailOrderConnection = mb.fkDetailOrder.getAdapter(ConnectionAdapter.class); + assertThat(detailOrderConnection, is(notNullValue())); + assertThat(detailOrderConnection.unwrap(), is(sameInstance(mb.fkDetailOrder))); + + ConnectionAdapter orderUserConnection = mb.fkOrderUser.getAdapter(ConnectionAdapter.class); + assertThat(orderUserConnection, is(notNullValue())); + assertThat(orderUserConnection.unwrap(), is(sameInstance(mb.fkOrderUser))); + + NodeAdapter detailNode = mb.tableDetail.getAdapter(NodeAdapter.class); + NodeAdapter itemNode = mb.tableItem.getAdapter(NodeAdapter.class); + NodeAdapter orderNode = mb.tableOrder.getAdapter(NodeAdapter.class); + NodeAdapter userNode = mb.tableUser.getAdapter(NodeAdapter.class); + + assertThat(detailItemConnection.getSource(), is(sameInstance(detailNode))); + assertThat(detailItemConnection.getTarget(), is(sameInstance(itemNode))); + + assertThat(detailOrderConnection.getSource(), is(sameInstance(detailNode))); + assertThat(detailOrderConnection.getTarget(), is(sameInstance(orderNode))); + + assertThat(orderUserConnection.getSource(), is(sameInstance(orderNode))); + assertThat(orderUserConnection.getTarget(), is(sameInstance(userNode))); + } +} Deleted: artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/node/NodeModelImplTest.java =================================================================== --- artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/model/node/NodeModelImplTest.java 2009-03-20 15:22:38 UTC (rev 2971) +++ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/node/NodeModelImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,146 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2009/01/23 - * - * 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.model.node; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.hamcrest.CoreMatchers.sameInstance; -import static org.hamcrest.Matchers.hasItem; -import static org.hamcrest.Matchers.hasItems; -import static org.junit.Assert.assertThat; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import org.jiemamy.Artemis; -import org.jiemamy.ArtemisView; -import org.jiemamy.Jiemamy; -import org.jiemamy.internal.test.ReflectionDialectProvider; -import org.jiemamy.internal.test.TestModelBuilder; -import org.jiemamy.internal.test.TestModelBuilder2; -import org.jiemamy.model.connection.ConnectionAdapter; -import org.jiemamy.model.entity.EntityModel; - -/** - * {@link NodeAdapterImpl}のテストクラス。 - * - * @author daisuke - */ -public class NodeModelImplTest { - - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - } - - /** - * エンティティからノードが取得でき、そのソースConsとターゲットConsが正常に取得できる。empDept版。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test01_エンティティからノードが取得でき_そのソースConsとターゲットConsが正常に取得できる_empDept() throws Exception { - Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView()), new ReflectionDialectProvider()); - TestModelBuilder mb = new TestModelBuilder(jiemamy); - mb.build(); - - NodeAdapter empNode = mb.tableEmp.getAdapter(NodeAdapter.class); - assertThat(empNode, is(notNullValue())); - assertThat(empNode.unwrap(), is(sameInstance((EntityModel) mb.tableEmp))); - - NodeAdapter deptNode = mb.tableDept.getAdapter(NodeAdapter.class); - assertThat(deptNode, is(notNullValue())); - assertThat(deptNode.unwrap(), is(sameInstance((EntityModel) mb.tableDept))); - - ConnectionAdapter empDeptConnection = mb.fkEmpDept.getAdapter(ConnectionAdapter.class); - ConnectionAdapter empEmpConnection = mb.fkEmpEmp.getAdapter(ConnectionAdapter.class); - - assertThat(empNode.getSourceConnections(), hasItems(empEmpConnection, empDeptConnection)); - assertThat(empNode.getTargetConnections(), hasItems(empEmpConnection)); - assertThat(empNode.getSourceConnections().size(), is(2)); - assertThat(empNode.getTargetConnections().size(), is(1)); - - assertThat(deptNode.getTargetConnections(), hasItems(empDeptConnection)); - assertThat(deptNode.getSourceConnections().size(), is(0)); - assertThat(deptNode.getTargetConnections().size(), is(1)); - } - - /** - * エンティティからノードが取得でき、そのソースConsとターゲットConsが正常に取得できる。order版。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test02_エンティティからノードが取得でき_そのソースConsとターゲットConsが正常に取得できる_order() throws Exception { - Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView()), new ReflectionDialectProvider()); - TestModelBuilder2 mb = new TestModelBuilder2(jiemamy); - mb.build(); - - NodeAdapter itemNode = mb.tableItem.getAdapter(NodeAdapter.class); - assertThat(itemNode, is(notNullValue())); - assertThat(itemNode.unwrap(), is(sameInstance((EntityModel) mb.tableItem))); - - NodeAdapter userNode = mb.tableUser.getAdapter(NodeAdapter.class); - assertThat(userNode, is(notNullValue())); - assertThat(userNode.unwrap(), is(sameInstance((EntityModel) mb.tableUser))); - - NodeAdapter orderNode = mb.tableOrder.getAdapter(NodeAdapter.class); - assertThat(orderNode, is(notNullValue())); - assertThat(orderNode.unwrap(), is(sameInstance((EntityModel) mb.tableOrder))); - - NodeAdapter deailNode = mb.tableDetail.getAdapter(NodeAdapter.class); - assertThat(deailNode, is(notNullValue())); - assertThat(deailNode.unwrap(), is(sameInstance((EntityModel) mb.tableDetail))); - - ConnectionAdapter detailItemConnection = mb.fkDetailItem.getAdapter(ConnectionAdapter.class); - ConnectionAdapter detailOrderConnection = mb.fkDetailOrder.getAdapter(ConnectionAdapter.class); - ConnectionAdapter orderUserConnection = mb.fkOrderUser.getAdapter(ConnectionAdapter.class); - - assertThat(itemNode.getTargetConnections(), hasItem(detailItemConnection)); - assertThat(itemNode.getSourceConnections().size(), is(0)); - assertThat(itemNode.getTargetConnections().size(), is(1)); - - assertThat(userNode.getTargetConnections(), hasItem(orderUserConnection)); - assertThat(userNode.getSourceConnections().size(), is(0)); - assertThat(userNode.getTargetConnections().size(), is(1)); - - assertThat(orderNode.getSourceConnections(), hasItem(orderUserConnection)); - assertThat(orderNode.getTargetConnections(), hasItem(detailOrderConnection)); - assertThat(orderNode.getSourceConnections().size(), is(1)); - assertThat(orderNode.getTargetConnections().size(), is(1)); - - assertThat(deailNode.getSourceConnections(), hasItems(detailItemConnection, detailOrderConnection)); - assertThat(deailNode.getSourceConnections().size(), is(2)); - assertThat(deailNode.getTargetConnections().size(), is(0)); - } -} Copied: artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/node/NodeModelImplTest.java (from rev 2975, artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/model/node/NodeModelImplTest.java) =================================================================== --- artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/node/NodeModelImplTest.java (rev 0) +++ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/internal/model/node/NodeModelImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -0,0 +1,147 @@ +/* + * Copyright 2007-2009 Jiemamy Project and the Others. + * Created on 2009/01/23 + * + * 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.internal.model.node; + +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.notNullValue; +import static org.hamcrest.CoreMatchers.sameInstance; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.Matchers.hasItems; +import static org.junit.Assert.assertThat; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import org.jiemamy.Artemis; +import org.jiemamy.ArtemisView; +import org.jiemamy.Jiemamy; +import org.jiemamy.internal.test.ReflectionDialectProvider; +import org.jiemamy.internal.test.TestModelBuilder; +import org.jiemamy.internal.test.TestModelBuilder2; +import org.jiemamy.model.connection.ConnectionAdapter; +import org.jiemamy.model.entity.EntityModel; +import org.jiemamy.model.node.NodeAdapter; + +/** + * {@link NodeAdapterImpl}のテストクラス。 + * + * @author daisuke + */ +public class NodeModelImplTest { + + /** + * テストを初期化する。 + * + * @throws Exception 例外が発生した場合 + */ + @Before + public void setUp() throws Exception { + } + + /** + * テストの情報を破棄する。 + * + * @throws Exception 例外が発生した場合 + */ + @After + public void tearDown() throws Exception { + } + + /** + * エンティティからノードが取得でき、そのソースConsとターゲットConsが正常に取得できる。empDept版。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test01_エンティティからノードが取得でき_そのソースConsとターゲットConsが正常に取得できる_empDept() throws Exception { + Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView()), new ReflectionDialectProvider()); + TestModelBuilder mb = new TestModelBuilder(jiemamy); + mb.build(); + + NodeAdapter empNode = mb.tableEmp.getAdapter(NodeAdapter.class); + assertThat(empNode, is(notNullValue())); + assertThat(empNode.unwrap(), is(sameInstance((EntityModel) mb.tableEmp))); + + NodeAdapter deptNode = mb.tableDept.getAdapter(NodeAdapter.class); + assertThat(deptNode, is(notNullValue())); + assertThat(deptNode.unwrap(), is(sameInstance((EntityModel) mb.tableDept))); + + ConnectionAdapter empDeptConnection = mb.fkEmpDept.getAdapter(ConnectionAdapter.class); + ConnectionAdapter empEmpConnection = mb.fkEmpEmp.getAdapter(ConnectionAdapter.class); + + assertThat(empNode.getSourceConnections(), hasItems(empEmpConnection, empDeptConnection)); + assertThat(empNode.getTargetConnections(), hasItems(empEmpConnection)); + assertThat(empNode.getSourceConnections().size(), is(2)); + assertThat(empNode.getTargetConnections().size(), is(1)); + + assertThat(deptNode.getTargetConnections(), hasItems(empDeptConnection)); + assertThat(deptNode.getSourceConnections().size(), is(0)); + assertThat(deptNode.getTargetConnections().size(), is(1)); + } + + /** + * エンティティからノードが取得でき、そのソースConsとターゲットConsが正常に取得できる。order版。 + * + * @throws Exception 例外が発生した場合 + */ + @Test + public void test02_エンティティからノードが取得でき_そのソースConsとターゲットConsが正常に取得できる_order() throws Exception { + Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView()), new ReflectionDialectProvider()); + TestModelBuilder2 mb = new TestModelBuilder2(jiemamy); + mb.build(); + + NodeAdapter itemNode = mb.tableItem.getAdapter(NodeAdapter.class); + assertThat(itemNode, is(notNullValue())); + assertThat(itemNode.unwrap(), is(sameInstance((EntityModel) mb.tableItem))); + + NodeAdapter userNode = mb.tableUser.getAdapter(NodeAdapter.class); + assertThat(userNode, is(notNullValue())); + assertThat(userNode.unwrap(), is(sameInstance((EntityModel) mb.tableUser))); + + NodeAdapter orderNode = mb.tableOrder.getAdapter(NodeAdapter.class); + assertThat(orderNode, is(notNullValue())); + assertThat(orderNode.unwrap(), is(sameInstance((EntityModel) mb.tableOrder))); + + NodeAdapter deailNode = mb.tableDetail.getAdapter(NodeAdapter.class); + assertThat(deailNode, is(notNullValue())); + assertThat(deailNode.unwrap(), is(sameInstance((EntityModel) mb.tableDetail))); + + ConnectionAdapter detailItemConnection = mb.fkDetailItem.getAdapter(ConnectionAdapter.class); + ConnectionAdapter detailOrderConnection = mb.fkDetailOrder.getAdapter(ConnectionAdapter.class); + ConnectionAdapter orderUserConnection = mb.fkOrderUser.getAdapter(ConnectionAdapter.class); + + assertThat(itemNode.getTargetConnections(), hasItem(detailItemConnection)); + assertThat(itemNode.getSourceConnections().size(), is(0)); + assertThat(itemNode.getTargetConnections().size(), is(1)); + + assertThat(userNode.getTargetConnections(), hasItem(orderUserConnection)); + assertThat(userNode.getSourceConnections().size(), is(0)); + assertThat(userNode.getTargetConnections().size(), is(1)); + + assertThat(orderNode.getSourceConnections(), hasItem(orderUserConnection)); + assertThat(orderNode.getTargetConnections(), hasItem(detailOrderConnection)); + assertThat(orderNode.getSourceConnections().size(), is(1)); + assertThat(orderNode.getTargetConnections().size(), is(1)); + + assertThat(deailNode.getSourceConnections(), hasItems(detailItemConnection, detailOrderConnection)); + assertThat(deailNode.getSourceConnections().size(), is(2)); + assertThat(deailNode.getTargetConnections().size(), is(0)); + } +} Deleted: artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/model/DiagramPresentationModelImplTest.java =================================================================== --- artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/model/DiagramPresentationModelImplTest.java 2009-03-21 04:23:00 UTC (rev 2975) +++ artemis/trunk/jiemamy-view/src/test/java/org/jiemamy/model/DiagramPresentationModelImplTest.java 2009-03-22 03:06:42 UTC (rev 2976) @@ -1,94 +0,0 @@ -/* - * Copyright 2007-2009 Jiemamy Project and the Others. - * Created on 2008/11/13 - * - * 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.model; - -import static org.hamcrest.CoreMatchers.is; -import static org.hamcrest.CoreMatchers.notNullValue; -import static org.junit.Assert.assertThat; - -import org.junit.After; -import org.junit.Before; -import org.junit.Test; - -import org.jiemamy.Artemis; -import org.jiemamy.ArtemisView; -import org.jiemamy.Jiemamy; -import org.jiemamy.JiemamyFactory; -import org.jiemamy.internal.model.DiagramPresentationModelImpl; - -/** - * {@link DiagramPresentationModelImpl}のテストクラス。 - * - * @author daisuke - */ -public class DiagramPresentationModelImplTest { - - private RootModel rootModel; - - private DiagramPresentationModel presentation; - - private JiemamyFactory factory; - - - /** - * テストを初期化する。 - * - * @throws Exception 例外が発生した場合 - */ - @Before - public void setUp() throws Exception { - Jiemamy jiemamy = Jiemamy.newInstance(new Artemis(new ArtemisView())); - factory = jiemamy.getFactory(); - rootModel = factory.getRootModel(); - presentation = factory.newModel(DiagramPresentationModel.class); - presentation.setName("testPresentation"); - DiagramPresentations diagramPresentations = rootModel.getAdapter(DiagramPresentations.class); - diagramPresentations.add(presentation); - } - - /** - * テストの情報を破棄する。 - * - * @throws Exception 例外が発生した場合 - */ - @After - public void tearDown() throws Exception { - DiagramPresentations diagramPresentations = rootModel.getAdapter(DiagramPresentations.class); - diagramPresentations.remove(presentation); - presentation = null; - rootModel = null; - factory = null; - } - - /** - * 各プロパティが正常に初期化されていること。 - * - * @throws Exception 例外が発生した場合 - */ - @Test - public void test01_各プロパティが正常に初期化されていること() throws Exception { - assertThat(presentation.getNodeProfiles(), is(notNullValue())); - assertThat(presentation.getConnectionProfiles(), is(notNullValue())); - assertThat(presentation.getMode(), is(notNullValue())); - assertThat(presentation.getLevel(), is(notNullValue())); - assertThat(presentation.getName(), is("testPresentation")); - - assertThat(presentation.getNodeProfiles().size(), is(0)); - } -}