1 | | package org.sophie2.main.layout.mydoggy; |
2 | | |
3 | | import org.junit.After; |
4 | | import org.junit.Before; |
5 | | import org.junit.Test; |
6 | | import org.sophie2.base.layout.BaseLayoutModule; |
7 | | import org.sophie2.base.layout.impl.DefaultDocumentsDesktop; |
8 | | import org.sophie2.base.layout.testing.DummyFlap; |
9 | | import org.sophie2.base.layout.testing.DummyMainWindow; |
10 | | import org.sophie2.base.layout.testing.DummyPalette; |
11 | | import org.sophie2.base.layout.testing.DummyTab; |
12 | | import org.sophie2.base.menus.testing.DummyMenuBar; |
13 | | import org.sophie2.base.model.book.BaseModelBookModule; |
14 | | import org.sophie2.base.skins.BaseSkinsModule; |
15 | | import org.sophie2.base.visual.BaseVisualModule; |
16 | | import org.sophie2.core.modularity.FakeModuleRegistry; |
17 | | import org.sophie2.core.mvc.CoreMvcModule; |
18 | | import org.sophie2.core.prolib.list.ProList; |
19 | | import org.sophie2.core.testing.UnitTestBase; |
20 | | import org.sophie2.main.app.commons.MainAppModule; |
21 | | import org.sophie2.main.scene.simple.MainSceneSimpleModule; |
22 | | |
23 | | /** |
24 | | * Tests MyDoggy implementation of the main layout. |
25 | | * |
26 | | * @author nvasilev, kyli |
27 | | */ |
28 | | public class MyDoggyLayoutDemo extends UnitTestBase { |
29 | | |
30 | | // --- Instance Variables -------------------------------------------------- |
31 | | |
32 | | /** |
33 | | * MainWindow structure used for creation of MyDoggy components. |
34 | | */ |
35 | | private DummyMainWindow mainWindow; |
36 | | |
37 | | /** |
38 | | * MyDoggy main window used for visualization of the model. |
39 | | */ |
40 | | private MDMainWindow mdMainWindow; |
41 | | |
42 | | // --- Methods (inherited) ------------------------------------------------- |
43 | | |
44 | | @SuppressWarnings("unchecked") |
45 | | @Override |
46 | | @Before |
47 | | protected void setUp() throws Exception { |
48 | | super.setUp(); |
49 | | FakeModuleRegistry.start(CoreMvcModule.class, |
50 | | BaseModelBookModule.class, MainAppModule.class, |
51 | | BaseVisualModule.class, BaseSkinsModule.class, |
52 | | MainSceneSimpleModule.class, LayoutMyDoggyModule.class, |
53 | | BaseLayoutModule.class); |
54 | | |
55 | | this.mainWindow = new DummyMainWindow(); |
56 | | this.mainWindow.title().set("Sophie2"); |
57 | | |
58 | | DummyFlap leftFlap = new DummyFlap("lfName", "lfTooltip"); |
59 | | DummyFlap rightFlap = new DummyFlap("rfName", "rfTooltip"); |
60 | | |
61 | | this.mainWindow.menuBar().set(new DummyMenuBar()); |
62 | | this.mainWindow.booksDesktop().set(new DefaultDocumentsDesktop()); |
63 | | |
64 | | this.mainWindow.leftFlap().set(leftFlap); |
65 | | this.mainWindow.rightFlap().set(rightFlap); |
66 | | DummyTab leftFlapsTab = new DummyTab(leftFlap, "lfTabName", |
67 | | "lfTabTooltip"); |
68 | | new DummyPalette(leftFlapsTab, "lfTabNameP", "lfTabPTooltip"); |
69 | | this.mdMainWindow = new MDMainWindow(this.mainWindow); |
70 | | } |
71 | | |
72 | | @Override |
73 | | @After |
74 | | protected void tearDown() throws Exception { |
75 | | // this.mdMainWindow.globalContainer().get().dispose(); |
76 | | // this.mdMainWindow.getBean().destroy(); |
77 | | // this.mainWindow = null; |
78 | | FakeModuleRegistry.stop(); |
79 | | super.tearDown(); |
80 | | } |
81 | | |
82 | | // --- Methods (test) ------------------------------------------------------ |
83 | | |
84 | | /** |
85 | | * Tests creation of the main window. |
86 | | */ |
87 | | @Test |
88 | | public void testMainWindowCreation() { |
89 | | assertSame(this.mdMainWindow.mainWindow().get(), this.mainWindow); |
90 | | assertSame(this.mdMainWindow.mdLeftFlap().get().model().get(), |
91 | | this.mainWindow.leftFlap().get()); |
92 | | assertSame(this.mdMainWindow.mdRightFlap().get().model().get(), |
93 | | this.mainWindow.rightFlap().get()); |
94 | | } |
95 | | |
96 | | /** |
97 | | * Tests tabs creation. |
98 | | */ |
99 | | @Test |
100 | | public void testTabsCreation() { |
101 | | ProList<MDTab> mdTabListRightFlap = this.mdMainWindow.mdRightFlap() |
102 | | .get().tabViews().get(); |
103 | | assertEquals(0, mdTabListRightFlap.size()); |
104 | | ProList<MDTab> mdTabListLeftFlap = this.mdMainWindow.mdLeftFlap().get() |
105 | | .tabViews().get(); |
106 | | assertEquals(1, mdTabListLeftFlap.size()); |
107 | | assertSame(mdTabListLeftFlap.get(0).model().get(), this.mainWindow |
108 | | .leftFlap().get().tabs().get().get(0)); |
109 | | } |
110 | | |
111 | | /** |
112 | | * Tests palettes creation. |
113 | | */ |
114 | | @Test |
115 | | public void testPalettesCreation() { |
116 | | ProList<MDTab> mdTabListLeftFlap = this.mdMainWindow.mdLeftFlap().get() |
117 | | .tabViews().get(); |
118 | | assertSame(mdTabListLeftFlap.get(0).paletteViews().get().get(0).model() |
119 | | .get(), this.mainWindow.leftFlap().get().tabs().get().get(0) |
120 | | .palettes().get().get(0)); |
121 | | } |
122 | | |
123 | | /** |
124 | | * Tests flap updating (replacing). |
125 | | */ |
126 | | @Test |
127 | | public void testFlapUpdating() { |
128 | | DummyFlap leftFlap = new DummyFlap("LeftFlapsName2", |
129 | | "LeftFlapsTooltip2"); |
130 | | System.out.println(leftFlap.title().get()); |
131 | | this.mainWindow.leftFlap().set(leftFlap); |
132 | | assertSame(this.mdMainWindow.mdLeftFlap().get().model().get(), |
133 | | this.mainWindow.leftFlap().get()); |
134 | | |
135 | | DummyFlap rightFlap = new DummyFlap("RightFlapsName2", |
136 | | "RightFlapsTooltip2"); |
137 | | this.mainWindow.rightFlap().set(rightFlap); |
138 | | assertSame(this.mdMainWindow.mdRightFlap().get().model().get(), |
139 | | this.mainWindow.rightFlap().get()); |
140 | | } |
141 | | |
142 | | /** |
143 | | * Tests palette updating (adding). |
144 | | */ |
145 | | @Test |
146 | | public void testPaletteUpdating() { |
147 | | DummyFlap leftFlap = new DummyFlap("LeftFlapsName3", |
148 | | "LeftFlapsTooltip3"); |
149 | | this.mainWindow.leftFlap().set(leftFlap); |
150 | | |
151 | | DummyTab leftFlapTab = new DummyTab(leftFlap, "LeftFlapsTabName1", |
152 | | "LeftFlapsTabTooltip1"); |
153 | | DummyPalette leftFlapFirstTabPallete = new DummyPalette(leftFlapTab, |
154 | | "LeftFlapsTabName2", "LeftFlapsTabTooltip2"); |
155 | | assertSame(this.mdMainWindow.mdLeftFlap().get().tabViews().get().get(0) |
156 | | .paletteViews().get(0).model().get(), leftFlapFirstTabPallete); |
157 | | } |
158 | | |
159 | | /** |
160 | | * Tests showing / hiding of MyDoggy components |
161 | | */ |
162 | | @Test |
163 | | public void testShowing() { |
164 | | MDEngine mdEngine = new MDEngine(); |
165 | | MDMainWindow res = mdEngine.show(this.mainWindow); |
166 | | assertTrue(res.globalContainer().get().isVisible()); |
167 | | |
168 | | mdEngine.hide(this.mainWindow, res); |
169 | | assertFalse(res.globalContainer().get().isVisible()); |
170 | | } |
171 | | } |
| 1 | package org.sophie2.main.layout.mydoggy; |
| 2 | |
| 3 | import java.awt.Dimension; |
| 4 | import java.awt.Point; |
| 5 | import java.awt.Toolkit; |
| 6 | |
| 7 | import javax.swing.JFrame; |
| 8 | |
| 9 | import org.junit.After; |
| 10 | import org.junit.Before; |
| 11 | import org.junit.Test; |
| 12 | import org.noos.xing.mydoggy.plaf.MyDoggyToolWindowManager; |
| 13 | import org.sophie2.base.layout.model.ScreenMode; |
| 14 | import org.sophie2.base.layout.testing.DummyDocumentView; |
| 15 | import org.sophie2.base.layout.testing.DummyDocumentsDesktop; |
| 16 | import org.sophie2.base.layout.BaseLayoutModule; |
| 17 | import org.sophie2.base.layout.testing.DummyFlap; |
| 18 | import org.sophie2.base.layout.testing.DummyMainWindow; |
| 19 | import org.sophie2.base.layout.testing.DummyPalette; |
| 20 | import org.sophie2.base.layout.testing.DummyTab; |
| 21 | import org.sophie2.base.layout.testing.DummyTabBar; |
| 22 | import org.sophie2.base.menus.testing.DummyMenuBar; |
| 23 | import org.sophie2.base.model.book.BaseModelBookModule; |
| 24 | import org.sophie2.base.skins.BaseSkinsModule; |
| 25 | import org.sophie2.base.visual.BaseVisualModule; |
| 26 | import org.sophie2.core.modularity.FakeModuleRegistry; |
| 27 | import org.sophie2.core.mvc.CoreMvcModule; |
| 28 | import org.sophie2.core.prolib.list.ProList; |
| 29 | import org.sophie2.core.testing.UnitTestBase; |
| 30 | import org.sophie2.main.app.commons.MainAppModule; |
| 31 | import org.sophie2.main.scene.simple.MainSceneSimpleModule; |
| 32 | |
| 33 | /** |
| 34 | * Tests MyDoggy implementation of the main layout. |
| 35 | * |
| 36 | * @author nvasilev, kyli |
| 37 | */ |
| 38 | public class MyDoggyLayoutDemo extends UnitTestBase { |
| 39 | |
| 40 | // --- Instance Variables -------------------------------------------------- |
| 41 | |
| 42 | /** |
| 43 | * MainWindow structure used for creation of MyDoggy components. |
| 44 | */ |
| 45 | private DummyMainWindow mainWindow; |
| 46 | |
| 47 | /** |
| 48 | * MyDoggy main window used for visualization of the model. |
| 49 | */ |
| 50 | private MDMainWindow mdMainWindow; |
| 51 | |
| 52 | // --- Methods (inherited) ------------------------------------------------- |
| 53 | |
| 54 | @SuppressWarnings("unchecked") |
| 55 | @Override |
| 56 | @Before |
| 57 | protected void setUp() throws Exception { |
| 58 | super.setUp(); |
| 59 | FakeModuleRegistry.start(CoreMvcModule.class, |
| 60 | BaseModelBookModule.class, MainAppModule.class, |
| 61 | BaseVisualModule.class, BaseSkinsModule.class, |
| 62 | MainSceneSimpleModule.class, LayoutMyDoggyModule.class, |
| 63 | BaseLayoutModule.class); |
| 64 | |
| 65 | this.mainWindow = new DummyMainWindow(); |
| 66 | this.mainWindow.title().set("Sophie2"); |
| 67 | |
| 68 | DummyFlap leftFlap = new DummyFlap("lfName", "lfTooltip"); |
| 69 | DummyFlap rightFlap = new DummyFlap("rfName", "rfTooltip"); |
| 70 | |
| 71 | this.mainWindow.menuBar().set(new DummyMenuBar()); |
| 72 | |
| 73 | DummyDocumentsDesktop desktop = new DummyDocumentsDesktop(); |
| 74 | desktop.tabBar().set(new DummyTabBar()); |
| 75 | desktop.desktopView().set(new DummyDocumentView()); |
| 76 | this.mainWindow.booksDesktop().set(desktop); |
| 77 | |
| 78 | this.mainWindow.leftFlap().set(leftFlap); |
| 79 | this.mainWindow.rightFlap().set(rightFlap); |
| 80 | DummyTab leftFlapsTab = new DummyTab(leftFlap, "lfTabName", |
| 81 | "lfTabTooltip"); |
| 82 | new DummyPalette(leftFlapsTab, "lfTabNameP", "lfTabPTooltip"); |
| 83 | this.mdMainWindow = new MDMainWindow(this.mainWindow); |
| 84 | } |
| 85 | |
| 86 | @Override |
| 87 | @After |
| 88 | protected void tearDown() throws Exception { |
| 89 | FakeModuleRegistry.stop(); |
| 90 | // this.mdMainWindow.globalContainer().get().dispose(); |
| 91 | // this.mdMainWindow.getBean().destroy(); |
| 92 | // this.mainWindow = null; |
| 93 | super.tearDown(); |
| 94 | } |
| 95 | |
| 96 | // --- Methods (test) ------------------------------------------------------ |
| 97 | |
| 98 | /** |
| 99 | * Tests creation of the main window. |
| 100 | */ |
| 101 | @Test |
| 102 | public void testMainWindowCreation() { |
| 103 | assertSame(this.mdMainWindow.mainWindow().get(), this.mainWindow); |
| 104 | assertSame(this.mdMainWindow.mdLeftFlap().get().model().get(), |
| 105 | this.mainWindow.leftFlap().get()); |
| 106 | assertSame(this.mdMainWindow.mdRightFlap().get().model().get(), |
| 107 | this.mainWindow.rightFlap().get()); |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Tests tabs creation. |
| 112 | */ |
| 113 | @Test |
| 114 | public void testTabsCreation() { |
| 115 | ProList<MDTab> mdTabListRightFlap = this.mdMainWindow.mdRightFlap() |
| 116 | .get().tabViews().get(); |
| 117 | assertEquals(0, mdTabListRightFlap.size()); |
| 118 | ProList<MDTab> mdTabListLeftFlap = this.mdMainWindow.mdLeftFlap().get() |
| 119 | .tabViews().get(); |
| 120 | assertEquals(1, mdTabListLeftFlap.size()); |
| 121 | assertSame(mdTabListLeftFlap.get(0).model().get(), this.mainWindow |
| 122 | .leftFlap().get().tabs().get().get(0)); |
| 123 | } |
| 124 | |
| 125 | /** |
| 126 | * Tests palettes creation. |
| 127 | */ |
| 128 | @Test |
| 129 | public void testPalettesCreation() { |
| 130 | ProList<MDTab> mdTabListLeftFlap = this.mdMainWindow.mdLeftFlap().get() |
| 131 | .tabViews().get(); |
| 132 | assertSame(mdTabListLeftFlap.get(0).paletteViews().get().get(0).model() |
| 133 | .get(), this.mainWindow.leftFlap().get().tabs().get().get(0) |
| 134 | .palettes().get().get(0)); |
| 135 | } |
| 136 | |
| 137 | /** |
| 138 | * Tests flap updating (replacing). |
| 139 | */ |
| 140 | @Test |
| 141 | public void testFlapUpdating() { |
| 142 | DummyFlap leftFlap = new DummyFlap("LeftFlapsName2", |
| 143 | "LeftFlapsTooltip2"); |
| 144 | System.out.println(leftFlap.title().get()); |
| 145 | this.mainWindow.leftFlap().set(leftFlap); |
| 146 | assertSame(this.mdMainWindow.mdLeftFlap().get().model().get(), |
| 147 | this.mainWindow.leftFlap().get()); |
| 148 | |
| 149 | DummyFlap rightFlap = new DummyFlap("RightFlapsName2", |
| 150 | "RightFlapsTooltip2"); |
| 151 | this.mainWindow.rightFlap().set(rightFlap); |
| 152 | assertSame(this.mdMainWindow.mdRightFlap().get().model().get(), |
| 153 | this.mainWindow.rightFlap().get()); |
| 154 | } |
| 155 | |
| 156 | /** |
| 157 | * Tests palette updating (adding). |
| 158 | */ |
| 159 | @Test |
| 160 | public void testPaletteUpdating() { |
| 161 | DummyFlap leftFlap = new DummyFlap("LeftFlapsName3", |
| 162 | "LeftFlapsTooltip3"); |
| 163 | this.mainWindow.leftFlap().set(leftFlap); |
| 164 | |
| 165 | DummyTab leftFlapTab = new DummyTab(leftFlap, "LeftFlapsTabName1", |
| 166 | "LeftFlapsTabTooltip1"); |
| 167 | DummyPalette leftFlapFirstTabPallete = new DummyPalette(leftFlapTab, |
| 168 | "LeftFlapsTabName2", "LeftFlapsTabTooltip2"); |
| 169 | assertSame(this.mdMainWindow.mdLeftFlap().get().tabViews().get().get(0) |
| 170 | .paletteViews().get(0).model().get(), leftFlapFirstTabPallete); |
| 171 | } |
| 172 | |
| 173 | /** |
| 174 | * Tests entering and leaving full screen mode. |
| 175 | * Properties being tested include JFrame settings, flaps visibility, etc. |
| 176 | */ |
| 177 | @Test |
| 178 | public void testFullScreenMode() { |
| 179 | |
| 180 | //Entering Full Screen mode |
| 181 | this.mainWindow.screenMode().set(ScreenMode.FULL_SCREEN); |
| 182 | MyDoggyToolWindowManager manager = this.mdMainWindow.toolWindowManager().get(); |
| 183 | |
| 184 | assertEquals(true, manager.getToolWindow("Left Flap").isAutoHide()); |
| 185 | assertEquals(true, manager.getToolWindow("Right Flap").isAutoHide()); |
| 186 | |
| 187 | JFrame globalFrame = this.mdMainWindow.globalContainer().get(); |
| 188 | assertEquals(true, globalFrame.isUndecorated()); |
| 189 | assertEquals(new Point(0, 0), globalFrame.getLocation()); |
| 190 | |
| 191 | Toolkit toolkit = Toolkit.getDefaultToolkit(); |
| 192 | Dimension dimension = toolkit.getScreenSize(); |
| 193 | assertEquals(dimension, globalFrame.getSize()); |
| 194 | |
| 195 | //Leaving Full Screen mode |
| 196 | this.mainWindow.screenMode().set(ScreenMode.NORMAL); |
| 197 | manager = this.mdMainWindow.toolWindowManager().get(); |
| 198 | |
| 199 | assertEquals(false, manager.getToolWindow("Left Flap").isAutoHide()); |
| 200 | assertEquals(false, manager.getToolWindow("Right Flap").isAutoHide()); |
| 201 | |
| 202 | globalFrame = this.mdMainWindow.globalContainer().get(); |
| 203 | assertEquals(false, globalFrame.isUndecorated()); |
| 204 | |
| 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Tests entering and leaving presentation mode. |
| 209 | * Properties being tested include JFrame settings, flaps visibility, etc. |
| 210 | */ |
| 211 | @Test |
| 212 | public void testPresentationMode() { |
| 213 | |
| 214 | //Entering Presentation mode |
| 215 | this.mainWindow.screenMode().set(ScreenMode.PRESENTATION); |
| 216 | |
| 217 | ((DummyDocumentsDesktop) this.mainWindow.booksDesktop().get()) |
| 218 | .currentWindow().set(new DummyDocumentView()); |
| 219 | |
| 220 | JFrame globalFrame = this.mdMainWindow.globalContainer().get(); |
| 221 | assertEquals(true, globalFrame.isUndecorated()); |
| 222 | assertEquals(new Point(0, 0), globalFrame.getLocation()); |
| 223 | |
| 224 | Toolkit toolkit = Toolkit.getDefaultToolkit(); |
| 225 | Dimension dimension = toolkit.getScreenSize(); |
| 226 | assertEquals(dimension, globalFrame.getSize()); |
| 227 | |
| 228 | //Leaving Presentation mode |
| 229 | this.mainWindow.screenMode().set(ScreenMode.NORMAL); |
| 230 | |
| 231 | globalFrame = this.mdMainWindow.globalContainer().get(); |
| 232 | assertEquals(false, globalFrame.isUndecorated()); |
| 233 | |
| 234 | } |
| 235 | |
| 236 | /** |
| 237 | * Tests showing / hiding of MyDoggy components |
| 238 | */ |
| 239 | @Test |
| 240 | public void testShowing() { |
| 241 | MDEngine mdEngine = new MDEngine(); |
| 242 | MDMainWindow res = mdEngine.show(this.mainWindow); |
| 243 | assertTrue(res.globalContainer().get().isVisible()); |
| 244 | |
| 245 | mdEngine.hide(this.mainWindow, res); |
| 246 | assertFalse(res.globalContainer().get().isVisible()); |
| 247 | } |
| 248 | } |