You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@isis.apache.org by da...@apache.org on 2012/12/08 15:56:02 UTC
[33/53] [partial] ISIS-188: making structure of component viewers
consistent
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/TestToolkit.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/TestToolkit.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/TestToolkit.java
new file mode 100644
index 0000000..a9198e5
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/TestToolkit.java
@@ -0,0 +1,369 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd;
+
+import java.util.Enumeration;
+
+import org.apache.isis.core.commons.debug.DebugBuilder;
+import org.apache.isis.core.commons.debug.DebuggableWithTitle;
+import org.apache.isis.core.commons.exceptions.UnexpectedCallException;
+import org.apache.isis.viewer.dnd.drawing.Background;
+import org.apache.isis.viewer.dnd.drawing.Bounds;
+import org.apache.isis.viewer.dnd.drawing.Color;
+import org.apache.isis.viewer.dnd.drawing.ColorsAndFonts;
+import org.apache.isis.viewer.dnd.drawing.Location;
+import org.apache.isis.viewer.dnd.drawing.Size;
+import org.apache.isis.viewer.dnd.drawing.Text;
+import org.apache.isis.viewer.dnd.view.BackgroundTask;
+import org.apache.isis.viewer.dnd.view.Content;
+import org.apache.isis.viewer.dnd.view.DragEvent;
+import org.apache.isis.viewer.dnd.view.Feedback;
+import org.apache.isis.viewer.dnd.view.GlobalViewFactory;
+import org.apache.isis.viewer.dnd.view.InteractionSpy;
+import org.apache.isis.viewer.dnd.view.Toolkit;
+import org.apache.isis.viewer.dnd.view.UndoStack;
+import org.apache.isis.viewer.dnd.view.View;
+import org.apache.isis.viewer.dnd.view.ViewRequirement;
+import org.apache.isis.viewer.dnd.view.ViewSpecification;
+import org.apache.isis.viewer.dnd.view.Viewer;
+import org.apache.isis.viewer.dnd.viewer.basic.NullColor;
+import org.apache.isis.viewer.dnd.viewer.drawing.DummyText;
+
+public class TestToolkit extends Toolkit {
+
+ public static void createInstance() {
+ if (getInstance() == null) {
+ new TestToolkit();
+ }
+ }
+
+ private TestToolkit() {
+ }
+
+ @Override
+ protected void init() {
+ colorsAndFonts = new ColorsAndFonts() {
+
+ @Override
+ public int defaultBaseline() {
+ return 0;
+ }
+
+ @Override
+ public int defaultFieldHeight() {
+ return 0;
+ }
+
+ @Override
+ public Color getColor(final int rgbColor) {
+ return null;
+ }
+
+ @Override
+ public Color getColor(final String name) {
+ return new NullColor();
+ }
+
+ @Override
+ public Text getText(final String name) {
+ return new DummyText();
+ }
+
+ @Override
+ public void init() {
+ }
+ };
+
+ viewer = new Viewer() {
+
+ @Override
+ public void addToNotificationList(final View view) {
+ }
+
+ @Override
+ public void clearAction() {
+ }
+
+ @Override
+ public void clearOverlayView() {
+ }
+
+ @Override
+ public void clearOverlayView(final View view) {
+ }
+
+ @Override
+ public void disposeUnneededViews() {
+ }
+
+ @Override
+ public Object getClipboard(final Class<?> class1) {
+ return null;
+ }
+
+ @Override
+ public InteractionSpy getSpy() {
+ return null;
+ }
+
+ UndoStack undoStack = new UndoStack();
+
+ @Override
+ public UndoStack getUndoStack() {
+ return undoStack;
+ }
+
+ @Override
+ public boolean hasFocus(final View view) {
+ return false;
+ }
+
+ @Override
+ public boolean isRunningAsExploration() {
+ return false;
+ }
+
+ @Override
+ public boolean isRunningAsPrototype() {
+ return false;
+ }
+
+ @Override
+ public void markDamaged(final Bounds bounds) {
+ }
+
+ @Override
+ public void removeFromNotificationList(final View view) {
+ }
+
+ @Override
+ public void scheduleRepaint() {
+ }
+
+ @Override
+ public void saveCurrentFieldEntry() {
+ }
+
+ @Override
+ public String selectFilePath(final String title, final String directory) {
+ return null;
+ }
+
+ @Override
+ public void setBackground(final Background background) {
+ }
+
+ @Override
+ public void setClipboard(final String clip, final Class<?> class1) {
+ }
+
+ @Override
+ public void setKeyboardFocus(final View view) {
+ }
+
+ @Override
+ public void setOverlayView(final View view) {
+ }
+
+ @Override
+ public void showInOverlay(final Content content, final Location location) {
+ }
+
+ @Override
+ public void showDebugFrame(final DebuggableWithTitle[] info, final Location at) {
+ }
+
+ @Override
+ public Size getOverlaySize() {
+ return null;
+ }
+
+ @Override
+ public void saveOpenObjects() {
+ }
+
+ };
+
+ feedbackManager = new Feedback() {
+
+ @Override
+ public void showArrowCursor() {
+ }
+
+ @Override
+ public void showCrosshairCursor() {
+ }
+
+ @Override
+ public void showDefaultCursor() {
+ }
+
+ @Override
+ public void showException(final Throwable e) {
+ }
+
+ @Override
+ public void showHandCursor() {
+ }
+
+ @Override
+ public void showMoveCursor() {
+ }
+
+ @Override
+ public void showResizeDownCursor() {
+ }
+
+ @Override
+ public void showResizeDownLeftCursor() {
+ }
+
+ @Override
+ public void showResizeDownRightCursor() {
+ }
+
+ @Override
+ public void showResizeLeftCursor() {
+ }
+
+ @Override
+ public void showResizeRightCursor() {
+ }
+
+ @Override
+ public void showResizeUpCursor() {
+ }
+
+ @Override
+ public void showResizeUpLeftCursor() {
+ }
+
+ @Override
+ public void showResizeUpRightCursor() {
+ }
+
+ @Override
+ public void showTextCursor() {
+ }
+
+ @Override
+ public void addMessage(final String string) {
+ }
+
+ @Override
+ public void clearAction() {
+ }
+
+ @Override
+ public void clearBusy(final View view) {
+ }
+
+ @Override
+ public void clearError() {
+ }
+
+ @Override
+ public String getStatusBarOutput() {
+ return null;
+ }
+
+ @Override
+ public boolean isBusy(final View view) {
+ return false;
+ }
+
+ @Override
+ public void setAction(final String string) {
+ }
+
+ @Override
+ public void setBusy(final View view, final BackgroundTask task) {
+ }
+
+ @Override
+ public void setError(final String string) {
+ }
+
+ @Override
+ public void setViewDetail(final String string) {
+ }
+
+ @Override
+ public void showBusyState(final View view) {
+ }
+
+ @Override
+ public void showMessagesAndWarnings() {
+ }
+ };
+
+ viewFactory = new GlobalViewFactory() {
+
+ @Override
+ public Enumeration<ViewSpecification> availableViews(final ViewRequirement viewRequirement) {
+ throw new UnexpectedCallException();
+ }
+
+ @Override
+ public View createDialog(final Content content) {
+ throw new UnexpectedCallException();
+ }
+
+ @Override
+ public DragEvent createDragContentOutline(final View view, final Location location) {
+ throw new UnexpectedCallException();
+ }
+
+ @Override
+ public View createDragViewOutline(final View view) {
+ throw new UnexpectedCallException();
+ }
+
+ @Override
+ public View createMinimizedView(final View view) {
+ throw new UnexpectedCallException();
+ }
+
+ @Override
+ public View createView(final ViewRequirement requirement) {
+ return new DummyView();
+ }
+
+ @Override
+ public void debugData(final DebugBuilder debug) {
+ }
+
+ @Override
+ public String debugTitle() {
+ throw new UnexpectedCallException();
+ }
+
+ @Override
+ public void addSpecification(final ViewSpecification spec) {
+ }
+
+ @Override
+ public Enumeration<ViewSpecification> availableDesigns(final ViewRequirement viewRequirement) {
+ return null;
+ }
+
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/ViewManagerTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/ViewManagerTest.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/ViewManagerTest.java
new file mode 100644
index 0000000..2230da8
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/ViewManagerTest.java
@@ -0,0 +1,79 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd;
+
+import junit.framework.TestCase;
+import junit.textui.TestRunner;
+
+public class ViewManagerTest extends TestCase {
+ // private final static Component COMPONENT = new Component() {
+ // };
+
+ public static void main(final String[] args) {
+ TestRunner.run(ViewManagerTest.class);
+ }
+
+ public void testNone() {
+ }
+
+ /*
+ * public void testMouseClick() { MockWorkspace workspace = new
+ * MockWorkspace(null); MockView view = new MockView();
+ * workspace.setupIdentifyView(view);
+ *
+ * ViewManager manager = new ViewManager(workspace, null);
+ *
+ * view.setupGetAbsoluteLocation(new Location(10, 10));
+ * view.setupIndicatesForView(true); view.setExpectedFirstClickCalls(1);
+ *
+ * manager.mouseClicked(createMouseEvent(10, 20, 1,
+ * MouseEvent.BUTTON1_MASK));
+ *
+ * view.verify(); }
+ *
+ * public void testPopupMouseClick() { MockWorkspace workspace = new
+ * MockWorkspace(null); MockView view = new MockView();
+ * workspace.setupIdentifyView(view);
+ *
+ * MockPopupMenu popup = new MockPopupMenu(); ViewManager manager = new
+ * ViewManager(workspace, popup);
+ *
+ * view.setupGetAbsoluteLocation(new Location(10, 10));
+ * view.setupIndicatesForView(true);
+ *
+ * workspace.addExpectedSetIdentifiedViewValues(view);
+ *
+ * popup.addExpectedInitValues(view, true, true);
+ * view.setupGetAbsoluteLocation(new Location(10, 10));
+ * view.setupIndicatesForView(true); // popup.setupGetParent(null); //
+ * popup.setupIndicatesForView(true);
+ *
+ * manager.mouseClicked(createMouseEvent(10, 20, 1,
+ * MouseEvent.BUTTON3_MASK));
+ *
+ * popup.verify(); view.verify();
+ *
+ * popup.setExpectedFirstClickCalls(1); }
+ *
+ * private MouseEvent createMouseEvent(final int x, final int y, final int
+ * count, final int button) { return new MouseEvent(COMPONENT, 0, 0, button,
+ * x, y, count, false); }
+ */
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/ConfigurableListViewSpecificationTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/ConfigurableListViewSpecificationTest.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/ConfigurableListViewSpecificationTest.java
new file mode 100644
index 0000000..b4e1dea
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/ConfigurableListViewSpecificationTest.java
@@ -0,0 +1,116 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd.configurable;
+
+import static org.junit.Assert.assertTrue;
+
+import java.util.Enumeration;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.viewer.dnd.TestToolkit;
+import org.apache.isis.viewer.dnd.view.Content;
+import org.apache.isis.viewer.dnd.view.ViewRequirement;
+import org.apache.isis.viewer.dnd.view.collection.CollectionContent;
+
+public class ConfigurableListViewSpecificationTest {
+ private GridListSpecification viewSpecification;
+ private CollectionContent collectionContent;
+ private Mockery context;
+
+ @Before
+ public void setup() {
+ Logger.getRootLogger().setLevel(Level.OFF);
+ TestToolkit.createInstance();
+
+ viewSpecification = new GridListSpecification();
+
+ context = new Mockery();
+ collectionContent = context.mock(CollectionContent.class);
+ context.checking(new Expectations() {
+ {
+ one(collectionContent).isCollection();
+ will(returnValue(true));
+ }
+ });
+ }
+
+ @Test
+ public void requiresOpenCollection() throws Exception {
+ final ViewRequirement requirement = new ViewRequirement(collectionContent, ViewRequirement.OPEN);
+ assertTrue(viewSpecification.canDisplay(requirement));
+ }
+
+ @Test
+ public void requiresOpenObject() throws Exception {
+ final ViewRequirement requirement = new ViewRequirement(collectionContent, ViewRequirement.OPEN);
+ assertTrue(viewSpecification.canDisplay(requirement));
+ }
+
+ @Test
+ public void requiresClosedCollection() throws Exception {
+ final Content objectContent = context.mock(Content.class, "object");
+ context.checking(new Expectations() {
+ {
+ one(objectContent).isCollection();
+ will(returnValue(false));
+ }
+ });
+ final ViewRequirement requirement = new ViewRequirement(objectContent, ViewRequirement.CLOSED);
+ assertTrue(!viewSpecification.canDisplay(requirement));
+ }
+
+ // @Test
+ public void testname() throws Exception {
+ context.checking(new Expectations() {
+ {
+ one(collectionContent).allElements();
+ will(returnValue(new Enumeration() {
+ @Override
+ public boolean hasMoreElements() {
+ return false;
+ }
+
+ @Override
+ public Object nextElement() {
+ return null;
+ }
+ }));
+ }
+ });
+
+ /*
+ * TODO Fails trying to load user profile form NO system. View view =
+ * viewSpecification.createView(collectionContent, new Axes(), 0); Axes
+ * axes = view.getViewAxes(); GridLayout axis =
+ * axes.getAxis(GridLayout.class); assertEquals(1, axis.getSize());
+ *
+ *
+ * ConfigurationAxis configurationAxis =
+ * axes.getAxis(ConfigurationAxis.class);
+ * assertNotNull(configurationAxis);
+ */
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/PanelTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/PanelTest.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/PanelTest.java
new file mode 100644
index 0000000..cb82b59
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/PanelTest.java
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd.configurable;
+
+import static junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNull;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.viewer.dnd.DummyView;
+import org.apache.isis.viewer.dnd.TestToolkit;
+import org.apache.isis.viewer.dnd.configurable.PanelView.Position;
+import org.apache.isis.viewer.dnd.drawing.Location;
+import org.apache.isis.viewer.dnd.drawing.Size;
+
+public class PanelTest {
+
+ private Panel panel;
+ private DummyView view2;
+ private DummyView view1;
+ private DummyView view3;
+
+ @Before
+ public void setup() {
+ Logger.getRootLogger().setLevel(Level.OFF);
+ TestToolkit.createInstance();
+
+ view1 = new DummyView();
+ view1.setupRequiredSize(new Size(200, 100));
+ view2 = new DummyView();
+ view2.setupRequiredSize(new Size(150, 120));
+ view3 = new DummyView();
+ view3.setupRequiredSize(new Size(150, 120));
+
+ panel = new Panel();
+ panel.addView(view1, null);
+ panel.addView(view2, Position.East);
+
+ }
+
+ @Test
+ public void firstPanelInTopLeft() throws Exception {
+ panel.layout(Size.createMax());
+ assertEquals(new Location(0, 0), view1.getLocation());
+ }
+
+ @Test
+ public void firstPanelSizeSetToRequiredSize() throws Exception {
+ assertNull(view1.getSize());
+ panel.layout(Size.createMax());
+ assertEquals(new Size(200, 100), view1.getSize());
+ }
+
+ @Test
+ public void totalSizeIsWidthPlusMaxHeigth() throws Exception {
+ assertEquals(new Size(350, 120), panel.getRequiredSize(Size.createMax()));
+ }
+
+ @Test
+ public void addingToSouth() throws Exception {
+ panel = new Panel();
+ panel.addView(view1, Position.East);
+ panel.addView(view2, Position.South);
+ panel.addView(view3, Position.South);
+
+ assertEquals(new Size(200, 340), panel.getRequiredSize(Size.createMax()));
+ }
+
+ @Test
+ public void addingToEast() throws Exception {
+ panel.addView(view3, Position.East);
+
+ assertEquals(new Size(500, 120), panel.getRequiredSize(Size.createMax()));
+ }
+
+ @Test
+ public void secondPanelLocatedToRightOfFirst() throws Exception {
+ panel.layout(Size.createMax());
+ assertEquals(new Location(0, 0), view1.getLocation());
+ assertEquals(new Location(200, 0), view2.getLocation());
+ }
+
+ @Test
+ public void addingThirdPanelToLeftMovesFirstTwoPanels() throws Exception {
+ panel.addView(view3, Position.West);
+ panel.layout(Size.createMax());
+ assertEquals(new Location(150, 0), view1.getLocation());
+ assertEquals(new Location(350, 0), view2.getLocation());
+ assertEquals(new Location(0, 0), view3.getLocation());
+ }
+
+ @Test
+ public void nullPostionAddInSameOrientation() throws Exception {
+ panel.addView(view3, null);
+ assertEquals(new Size(500, 120), panel.getRequiredSize(Size.createMax()));
+ }
+
+ @Test
+ public void addingThirdPanelToBottomIncreasesHeight() throws Exception {
+ panel.addView(view3, Position.South);
+ assertEquals(new Size(350, 240), panel.getRequiredSize(Size.createMax()));
+ }
+
+ @Test
+ public void addingFouthPanelToLeftIncreasesWidth() throws Exception {
+ final DummyView view4 = new DummyView();
+ view4.setupRequiredSize(new Size(50, 100));
+
+ panel.addView(view3, Position.South);
+ panel.addView(view4, Position.East);
+ assertEquals(new Size(400, 240), panel.getRequiredSize(Size.createMax()));
+ }
+
+ @Test
+ public void addingThirdPanelToNorthIncreasesHeight() throws Exception {
+ panel.addView(view3, Position.North);
+ assertEquals(new Size(350, 240), panel.getRequiredSize(Size.createMax()));
+ }
+
+ @Test
+ public void addingThirdPanelToTopPlacesItAboveTheOtherTwo() throws Exception {
+ panel.addView(view3, Position.North);
+ panel.layout(Size.createMax());
+ assertEquals(new Location(0, 120), view1.getLocation());
+ assertEquals(new Location(200, 120), view2.getLocation());
+ assertEquals(new Location(0, 0), view3.getLocation());
+ }
+
+ @Test
+ public void addingThirdPanelToBottomPlacesItBelowTheOtherTwo() throws Exception {
+ panel.addView(view3, Position.South);
+ panel.layout(Size.createMax());
+ assertEquals(new Location(0, 0), view1.getLocation());
+ assertEquals(new Location(200, 0), view2.getLocation());
+ assertEquals(new Location(0, 120), view3.getLocation());
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/PanelViewDropTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/PanelViewDropTest.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/PanelViewDropTest.java
new file mode 100644
index 0000000..d894206
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/PanelViewDropTest.java
@@ -0,0 +1,156 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd.configurable;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jmock.Expectations;
+import org.jmock.auto.Mock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.viewer.dnd.DummyContent;
+import org.apache.isis.viewer.dnd.DummyView;
+import org.apache.isis.viewer.dnd.DummyViewSpecification;
+import org.apache.isis.viewer.dnd.TestToolkit;
+import org.apache.isis.viewer.dnd.configurable.PanelView.Position;
+import org.apache.isis.viewer.dnd.drawing.Location;
+import org.apache.isis.viewer.dnd.drawing.Size;
+import org.apache.isis.viewer.dnd.view.Content;
+import org.apache.isis.viewer.dnd.view.View;
+import org.apache.isis.viewer.dnd.view.ViewDrag;
+
+public class PanelViewDropTest {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_ONLY);
+
+ @Mock
+ private IsisConfiguration mockConfiguration;
+ @Mock
+ private ViewDrag viewDrag;
+
+ private PanelView view;
+ private DummyContent content;
+ private Position position;
+ private final DummyView sourceView = new DummyView();
+
+
+ @Before
+ public void setup() {
+ Logger.getRootLogger().setLevel(Level.OFF);
+
+ TestToolkit.createInstance();
+ IsisContext.setConfiguration(mockConfiguration);
+
+ content = new DummyContent();
+
+ view = new PanelView(content, new DummyViewSpecification()) {
+ @Override
+ public void addView(final Content content, final Position position) {
+ PanelViewDropTest.this.position = position;
+ }
+
+ @Override
+ public synchronized View[] getSubviews() {
+ return new View[] { sourceView };
+ }
+ };
+ view.setSize(new Size(200, 100));
+ view.setLocation(new Location(400, 200));
+ }
+
+ @Test
+ public void dropOnLeft() throws Exception {
+ final ViewDrag drag = dragTo(new Location(405, 250));
+ view.drop(drag);
+ assertEquals(Position.West, position);
+ }
+
+ @Test
+ public void dropOnRight() throws Exception {
+ final ViewDrag drag = dragTo(new Location(595, 250));
+ view.drop(drag);
+ assertEquals(Position.East, position);
+ }
+
+ @Test
+ public void dropOnTop() throws Exception {
+ final ViewDrag drag = dragTo(new Location(500, 205));
+ view.drop(drag);
+ assertEquals(Position.North, position);
+ }
+
+ @Test
+ public void dropOnBottom() throws Exception {
+ final ViewDrag drag = dragTo(new Location(500, 295));
+ view.drop(drag);
+ assertEquals(Position.South, position);
+ }
+
+ @Test
+ public void dropOnTopLeft() throws Exception {
+ final ViewDrag drag = dragTo(new Location(405, 205));
+ view.drop(drag);
+ assertEquals(Position.North, position);
+ }
+
+ @Test
+ public void dropOnTopRight() throws Exception {
+ final ViewDrag drag = dragTo(new Location(595, 205));
+ view.drop(drag);
+ assertEquals(Position.North, position);
+ }
+
+ @Test
+ public void dropOnBottomLeft() throws Exception {
+ final ViewDrag drag = dragTo(new Location(405, 295));
+ view.drop(drag);
+ assertEquals(Position.South, position);
+ }
+
+ @Test
+ public void dropOnBottomRight() throws Exception {
+ final ViewDrag drag = dragTo(new Location(595, 295));
+ view.drop(drag);
+ assertEquals(Position.South, position);
+ }
+
+ private ViewDrag dragTo(final Location location) {
+ context.checking(new Expectations() {
+ {
+ exactly(3).of(viewDrag).getSourceView();
+ will(returnValue(sourceView));
+
+ atLeast(1).of(viewDrag).getLocation();
+ will(returnValue(location));
+ }
+ });
+ return viewDrag;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/PanelViewTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/PanelViewTest.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/PanelViewTest.java
new file mode 100644
index 0000000..4909a43
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/configurable/PanelViewTest.java
@@ -0,0 +1,87 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd.configurable;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jmock.auto.Mock;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.commons.config.IsisConfiguration;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContext;
+import org.apache.isis.viewer.dnd.DummyContent;
+import org.apache.isis.viewer.dnd.DummyViewSpecification;
+import org.apache.isis.viewer.dnd.TestToolkit;
+import org.apache.isis.viewer.dnd.configurable.PanelView.Position;
+import org.apache.isis.viewer.dnd.drawing.Location;
+import org.apache.isis.viewer.dnd.drawing.Size;
+
+public class PanelViewTest {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ @Mock
+ private IsisConfiguration mockConfiguration;
+
+ private PanelView view;
+ private DummyContent content;
+ private DummyViewSpecification specification1;
+ private DummyViewSpecification specification2;
+
+ @Before
+ public void setup() {
+ Logger.getRootLogger().setLevel(Level.OFF);
+ TestToolkit.createInstance();
+ IsisContext.setConfiguration(mockConfiguration);
+
+ specification1 = new DummyViewSpecification();
+ specification1.setupCreatedViewsSize(new Size(200, 100));
+ specification2 = new DummyViewSpecification();
+ specification2.setupCreatedViewsSize(new Size(150, 120));
+
+ content = new DummyContent();
+
+ view = new PanelView(content, new DummyViewSpecification());
+ view.setInitialViewSpecification(specification1);
+ view.getSubviews();
+
+ view.addView(new DummyContent(), specification2, Position.East);
+ }
+
+ @Test
+ public void totalSizeIsWidthPlusMaxHeigth() throws Exception {
+ assertEquals(new Size(350, 120), view.getRequiredSize(Size.createMax()));
+ }
+
+ @Test
+ public void secondPanelLocatedToRightOfFirst() throws Exception {
+ view.layout();
+ assertEquals(new Location(0, 0), view.getSubviews()[0].getLocation());
+ assertEquals(new Location(200, 0), view.getSubviews()[1].getLocation());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/toolbar/ToolbarTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/toolbar/ToolbarTest.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/toolbar/ToolbarTest.java
new file mode 100644
index 0000000..4315e24
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/toolbar/ToolbarTest.java
@@ -0,0 +1,122 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd.toolbar;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
+import org.apache.isis.viewer.dnd.DummyView;
+import org.apache.isis.viewer.dnd.TestToolkit;
+import org.apache.isis.viewer.dnd.drawing.Location;
+import org.apache.isis.viewer.dnd.drawing.Size;
+import org.apache.isis.viewer.dnd.view.ViewConstants;
+import org.apache.isis.viewer.dnd.view.content.NullContent;
+import org.apache.isis.viewer.dnd.view.look.LookFactory;
+
+public class ToolbarTest {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+
+ private ToolbarView toolbar;
+ private DummyView button1;
+ private DummyView button2;
+ private DummyView button3;
+
+
+ @Before
+ public void setupDnd() {
+ Logger.getRootLogger().setLevel(Level.OFF);
+
+ TestToolkit.createInstance();
+ LookFactory.init();
+
+ toolbar = new ToolbarView(new NullContent(), null);
+
+ button1 = new DummyView();
+ button1.setupRequiredSize(new Size(120, 10));
+ toolbar.addView(button1);
+
+ button2 = new DummyView();
+ button2.setupRequiredSize(new Size(100, 10));
+ toolbar.addView(button2);
+
+ button3 = new DummyView();
+ button3.setupRequiredSize(new Size(80, 10));
+ toolbar.addView(button3);
+ }
+
+
+ @Test
+ public void requiredSizeForButtonsLessThanMaximumWidth() throws Exception {
+ final Size size = toolbar.getRequiredSize(Size.createMax());
+ assertEquals(new Size(ViewConstants.HPADDING + (100 + ViewConstants.HPADDING) * 3, 10 + ViewConstants.VPADDING), size);
+ }
+
+ @Test
+ public void requiredSizeForButtonsGreaterThanMaximumWidth() throws Exception {
+ final Size size = toolbar.getRequiredSize(new Size(250, 100));
+ assertEquals(new Size(ViewConstants.HPADDING * 3 + 220, (10 + ViewConstants.VPADDING) * 2), size);
+ }
+
+ @Test
+ public void requiredSizeForButtonsJustGreaterThanMaximumWidth() throws Exception {
+ final int width = ViewConstants.HPADDING + (100 + ViewConstants.HPADDING) * 3;
+ final Size size = toolbar.getRequiredSize(new Size(width + 1, 100));
+ assertEquals(new Size(width, 10 + ViewConstants.VPADDING), size);
+ }
+
+ @Test
+ public void requiredSizeForButtonsSameAsMaximumWidth() throws Exception {
+ final Size size = toolbar.getRequiredSize(new Size(ViewConstants.HPADDING + (100 + ViewConstants.HPADDING) * 3, 100));
+ assertEquals(new Size(ViewConstants.HPADDING * 3 + 220, (10 + ViewConstants.VPADDING) * 2), size);
+ }
+
+ @Test
+ public void layoutSizeForButtonsAsRequired() throws Exception {
+ toolbar.doLayout(Size.createMax());
+ assertEquals(new Size(120, 10), button1.getSize());
+ assertEquals(new Size(100, 10), button2.getSize());
+ assertEquals(new Size(80, 10), button3.getSize());
+ }
+
+ @Test
+ public void layoutLocationForButtonsLessThanMaximumWidth() throws Exception {
+ toolbar.doLayout(Size.createMax());
+ assertEquals(new Location(ViewConstants.HPADDING, 0), button1.getLocation());
+ assertEquals(new Location(ViewConstants.HPADDING * 2 + 120, 0), button2.getLocation());
+ assertEquals(new Location(ViewConstants.HPADDING * 3 + 220, 0), button3.getLocation());
+ }
+
+ @Test
+ public void layoutLocationForButtonsGreaterThanMaximumWidth() throws Exception {
+ toolbar.doLayout(new Size(250, 100));
+ assertEquals(new Location(ViewConstants.HPADDING, 0), button1.getLocation());
+ assertEquals(new Location(ViewConstants.HPADDING * 2 + 120, 0), button2.getLocation());
+ assertEquals(new Location(ViewConstants.HPADDING, 13), button3.getLocation());
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/util/PropertiesTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/util/PropertiesTest.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/util/PropertiesTest.java
new file mode 100644
index 0000000..3b571cc
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/util/PropertiesTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd.util;
+
+import static org.junit.Assert.assertEquals;
+
+import org.junit.Rule;
+import org.junit.Test;
+
+import org.apache.isis.core.runtime.userprofile.Options;
+import org.apache.isis.runtimes.dflt.testsupport.IsisSystemWithFixtures;
+
+public class PropertiesTest {
+
+ @Rule
+ public IsisSystemWithFixtures iswf = IsisSystemWithFixtures.builder().build();
+
+ @Test
+ public void getOptionsCreatesNewOptionsSet() throws Exception {
+
+ final Options options = Properties.getOptions("test");
+ assertEquals(false, options.names().hasNext());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/composite/CompositeViewTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/composite/CompositeViewTest.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/composite/CompositeViewTest.java
new file mode 100644
index 0000000..19e96f3
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/composite/CompositeViewTest.java
@@ -0,0 +1,192 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd.view.composite;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.isis.viewer.dnd.DummyView;
+import org.apache.isis.viewer.dnd.TestToolkit;
+import org.apache.isis.viewer.dnd.drawing.Size;
+import org.apache.isis.viewer.dnd.view.content.NullContent;
+
+public class CompositeViewTest {
+
+ private CompositeView view;
+ private DummyView component1;
+ private int layoutCount;
+ private int newBuildCount;
+ protected int modifiedBuildCount;
+
+ @Before
+ public void createView() {
+ Logger.getRootLogger().setLevel(Level.OFF);
+ TestToolkit.createInstance();
+
+ view = new CompositeView(new NullContent(), null) {
+ @Override
+ protected void buildNewView() {
+ newBuildCount++;
+ }
+
+ @Override
+ protected void buildModifiedView() {
+ modifiedBuildCount++;
+ }
+
+ @Override
+ protected void buildView() {
+ }
+
+ @Override
+ protected void doLayout(final Size maximumSize) {
+ layoutCount++;
+ }
+
+ @Override
+ public Size requiredSize(final Size availableSpace) {
+ return null;
+ }
+ };
+ view.setSize(new Size(100, 200));
+
+ component1 = new DummyView();
+ component1.setupRequiredSize(new Size(100, 20));
+ }
+
+ @Test
+ public void initialLayoutStateIsInvalid() {
+ assertTrue(view.isLayoutInvalid());
+ }
+
+ @Test
+ public void layoutStateIsValidAfterLayout() {
+ view.layout();
+ assertFalse(view.isLayoutInvalid());
+ }
+
+ @Test
+ public void noChangeInSizeLeavesLayoutValid() throws Exception {
+ view.layout();
+ assertEquals(new Size(100, 200), view.getSize());
+ assertFalse(view.isLayoutInvalid());
+ }
+
+ @Test
+ public void changeInSizeInvalidateLayout() throws Exception {
+ view.layout();
+ view.setSize(new Size(120, 200));
+ assertTrue(view.isLayoutInvalid());
+ }
+
+ @Test
+ public void testname() throws Exception {
+ assertEquals(0, layoutCount);
+ view.layout();
+ assertEquals(1, layoutCount);
+ }
+
+ @Test
+ public void testLayoutDoesntGetRepeated() throws Exception {
+ view.layout();
+ view.layout();
+ assertEquals(1, layoutCount);
+ }
+
+ @Test
+ public void testLayoutGetRedoneAfterSizeChanges() throws Exception {
+ view.layout();
+ view.setSize(new Size(120, 200));
+ view.layout();
+ assertEquals(2, layoutCount);
+ }
+
+ @Test
+ public void testLayoutGetRedoneAfterNewComponentAdded() throws Exception {
+ view.layout();
+ view.addView(new DummyView());
+ view.layout();
+ assertEquals(2, layoutCount);
+ }
+
+ @Test
+ public void testLayoutGetRedoneAfterComponentRemoved() throws Exception {
+ view.addView(component1);
+ view.layout();
+ view.removeView(component1);
+ view.layout();
+ assertEquals(2, layoutCount);
+ }
+
+ @Test
+ public void testLayoutGetRedoneAfterComponentReplaced() throws Exception {
+ view.addView(component1);
+ view.layout();
+ view.replaceView(component1, new DummyView());
+ view.layout();
+ assertEquals(2, layoutCount);
+ }
+
+ @Test
+ public void buildNotRepeatedlyCalledWhenNoChangedComponents() throws Exception {
+ assertEquals(0, newBuildCount);
+ view.getSubviews();
+ view.getSubviews();
+ assertEquals(1, newBuildCount);
+ }
+
+ @Test
+ public void changesInSizeDontCauseARebuild() throws Exception {
+ view.getSubviews();
+ view.setSize(new Size(120, 200));
+ component1.setSize(new Size(120, 200));
+ view.getSubviews();
+ assertEquals(1, newBuildCount);
+ }
+
+ @Test
+ public void rebuildAfterContentsInvalidated() throws Exception {
+ view.getSubviews();
+ view.addView(component1);
+ view.invalidateContent();
+ view.getSubviews();
+ assertEquals(1, newBuildCount);
+ assertEquals(1, modifiedBuildCount);
+ }
+
+ @Test
+ public void buildNewWhenNoSubviewsExist() throws Exception {
+ view.getSubviews();
+ assertEquals(1, newBuildCount);
+ }
+
+ @Test
+ public void buildModifiedWhenSubviewsExist() throws Exception {
+ view.addView(component1);
+ view.getSubviews();
+ assertEquals(1, modifiedBuildCount);
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/CursorPositionTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/CursorPositionTest.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/CursorPositionTest.java
new file mode 100644
index 0000000..240b599
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/CursorPositionTest.java
@@ -0,0 +1,229 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd.view.text;
+
+import junit.framework.TestCase;
+
+public class CursorPositionTest extends TestCase {
+
+ public static void main(final String[] args) {
+ junit.textui.TestRunner.run(CursorPositionTest.class);
+ }
+
+ private CursorPosition cursor;
+
+ private void assertPosition(final int line, final int character, final CursorPosition cursor) {
+ assertEquals(line, cursor.getLine());
+ assertEquals(character, cursor.getCharacter());
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ final TextFieldContentStub stub = new TextFieldContentStub();
+ cursor = new CursorPosition(stub, 12, 3);
+ final String text = stub.getText(1);
+ assertEquals(35, text.length());
+ assertEquals("Now ", text.substring(0, 4));
+ assertEquals("is ", text.substring(4, 7));
+ assertEquals("the ", text.substring(7, 11));
+ assertEquals("winter ", text.substring(11, 18));
+ assertEquals("of ", text.substring(18, 21));
+ assertEquals("our ", text.substring(21, 25));
+ assertEquals("discontent", text.substring(25, 35));
+ }
+
+ public void testBottom() {
+ cursor.bottom();
+ assertPosition(15, 35, cursor);
+ }
+
+ public void testCopy() {
+ final CursorPosition copy = new CursorPosition(null, 1, 1);
+ copy.asFor(cursor);
+ assertPosition(12, 3, copy);
+ }
+
+ public void testCreate() {
+ assertPosition(12, 3, cursor);
+ }
+
+ public void testEnd() {
+ cursor.end();
+ assertPosition(12, 35, cursor);
+ }
+
+ public void testHome() {
+ cursor.home();
+ assertPosition(12, 0, cursor);
+ }
+
+ public void testLeft() {
+ cursor.left();
+ assertPosition(12, 2, cursor);
+ cursor.left();
+ assertPosition(12, 1, cursor);
+ cursor.left();
+ assertPosition(12, 0, cursor);
+ cursor.left();
+ assertPosition(11, 35, cursor);
+ }
+
+ public void testLeftPastHome() {
+ cursor.home();
+ cursor.left();
+ assertPosition(11, 35, cursor);
+ }
+
+ public void testLeftPastTop() {
+ cursor.top();
+ cursor.left();
+ assertPosition(0, 0, cursor);
+ }
+
+ public void testLineDown() {
+ cursor.lineDown();
+ assertPosition(13, 3, cursor);
+ }
+
+ public void testLineDownPastBottom() {
+ cursor.bottom();
+ cursor.lineDown();
+ assertPosition(15, 35, cursor);
+ }
+
+ public void testLineUp() {
+ cursor.lineUp();
+ assertPosition(11, 3, cursor);
+ }
+
+ public void testLineUpPastTop() {
+ cursor.top();
+ cursor.lineUp();
+ assertPosition(0, 0, cursor);
+ }
+
+ public void testPageDown() {
+ cursor.pageDown();
+ assertPosition(14, 3, cursor);
+ cursor.pageDown();
+ assertPosition(15, 3, cursor);
+ }
+
+ public void testRight() {
+ cursor.right();
+ assertPosition(12, 4, cursor);
+ cursor.right();
+ assertPosition(12, 5, cursor);
+ }
+
+ public void testRightPastEnd() {
+ cursor.end();
+ cursor.right();
+ assertPosition(13, 1, cursor);
+ cursor.right();
+ assertPosition(13, 2, cursor);
+ }
+
+ public void testRightPastBottom() {
+ cursor.bottom();
+ cursor.right();
+ assertPosition(15, 35, cursor);
+ }
+
+ public void testRightByNumber() {
+ cursor.right(22);
+ assertPosition(12, 25, cursor);
+ cursor.right(100);
+ assertPosition(15, 20, cursor);
+ cursor.right(30); // won't move as it would be past end
+ assertPosition(15, 20, cursor);
+ }
+
+ public void testWordLeft() {
+ cursor.wordLeft();
+ assertPosition(12, 0, cursor);
+ cursor.wordLeft();
+ assertPosition(11, 25, cursor);
+
+ }
+
+ public void testWordRight() {
+ cursor.wordRight();
+ assertPosition(12, 7, cursor);
+ cursor.wordRight();
+ assertPosition(12, 11, cursor);
+ cursor.wordRight();
+ assertPosition(12, 18, cursor);
+ cursor.wordRight();
+ assertPosition(12, 21, cursor);
+ cursor.wordRight();
+ assertPosition(12, 25, cursor);
+ cursor.wordRight();
+ assertPosition(13, 0, cursor);
+ cursor.wordRight();
+ assertPosition(13, 4, cursor);
+ cursor.wordRight();
+ assertPosition(13, 7, cursor);
+ }
+
+ public void testSamePostion() {
+ CursorPosition other = new CursorPosition(null, 12, 15);
+ assertFalse("different character", cursor.samePosition(other));
+
+ other = new CursorPosition(null, 7, 3);
+ assertFalse("different line", cursor.samePosition(other));
+
+ other = new CursorPosition(null, 12, 3);
+ assertTrue(cursor.samePosition(other));
+ }
+
+ public void testPageUp() {
+ cursor.pageUp();
+ assertPosition(10, 3, cursor);
+ cursor.pageUp();
+ assertPosition(8, 3, cursor);
+ cursor.pageUp();
+ assertPosition(6, 3, cursor);
+ cursor.pageUp();
+ assertPosition(4, 3, cursor);
+ cursor.pageUp();
+ assertPosition(2, 3, cursor);
+ cursor.pageUp();
+ assertPosition(0, 3, cursor);
+ cursor.pageUp();
+ assertPosition(0, 3, cursor);
+ }
+
+ public void testIsBeforeWhereAtSamePosition() {
+ final CursorPosition other = new CursorPosition(null, 12, 3);
+ assertFalse(cursor.isBefore(other));
+ }
+
+ public void testIsBeforeWhere2CharacterAfter() {
+ final CursorPosition other = new CursorPosition(null, 12, 5);
+ assertTrue(cursor.isBefore(other));
+ }
+
+ public void testIsBeforeWhere2CharacterBefore() {
+ final CursorPosition other = new CursorPosition(null, 12, 1);
+ assertFalse(cursor.isBefore(other));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/CursorPostionStub.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/CursorPostionStub.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/CursorPostionStub.java
new file mode 100644
index 0000000..e20e716
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/CursorPostionStub.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd.view.text;
+
+public class CursorPostionStub extends CursorPosition {
+ public CursorPostionStub(final TextContent content, final int line, final int afterCharacter) {
+ super(content, line, afterCharacter);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/MultilineTextFieldContentTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/MultilineTextFieldContentTest.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/MultilineTextFieldContentTest.java
new file mode 100644
index 0000000..9317514
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/MultilineTextFieldContentTest.java
@@ -0,0 +1,164 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd.view.text;
+
+import java.util.Collections;
+
+import org.apache.isis.core.commons.config.IsisConfigurationDefault;
+import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.runtime.authentication.AuthenticationManager;
+import org.apache.isis.core.runtime.authorization.AuthorizationManager;
+import org.apache.isis.core.runtime.imageloader.TemplateImageLoader;
+import org.apache.isis.core.runtime.userprofile.UserProfileLoader;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.runtime.system.DeploymentType;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContextStatic;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSessionFactory;
+import org.apache.isis.runtimes.dflt.runtime.system.session.IsisSessionFactoryDefault;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jmock.auto.Mock;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class MultilineTextFieldContentTest {
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ private TextContent content;
+
+ @Mock
+ protected TemplateImageLoader mockTemplateImageLoader;
+ @Mock
+ protected SpecificationLoaderSpi mockSpecificationLoader;
+ @Mock
+ protected PersistenceSessionFactory mockPersistenceSessionFactory;
+ @Mock
+ private UserProfileLoader mockUserProfileLoader;
+ @Mock
+ protected AuthenticationManager mockAuthenticationManager;
+ @Mock
+ protected AuthorizationManager mockAuthorizationManager;
+
+ @Before
+ public void setUp() throws Exception {
+ Logger.getRootLogger().setLevel(Level.OFF);
+
+ context.ignoring(mockTemplateImageLoader, mockSpecificationLoader, mockPersistenceSessionFactory, mockUserProfileLoader, mockAuthenticationManager, mockAuthorizationManager);
+
+ final IsisSessionFactoryDefault sessionFactory = new IsisSessionFactoryDefault(DeploymentType.EXPLORATION, new IsisConfigurationDefault(), mockTemplateImageLoader, mockSpecificationLoader, mockAuthenticationManager, mockAuthorizationManager, mockUserProfileLoader,
+ mockPersistenceSessionFactory, Collections.emptyList(), new OidMarshaller());
+ IsisContextStatic.createRelaxedInstance(sessionFactory);
+ sessionFactory.init();
+
+ final TextBlockTarget target = new TextBlockTargetExample();
+
+ content = new TextContent(target, 4, TextContent.WRAPPING);
+ content.setText("Line one\nLine two\nLine three\nLine four that is long enough that it wraps");
+ }
+
+ @Test
+ public void testDeleteOnSingleLine() {
+ final TextSelection selection = new TextSelection(content);
+ selection.resetTo(new CursorPosition(content, 1, 3));
+ selection.extendTo(new CursorPosition(content, 1, 7));
+ content.delete(selection);
+ Assert.assertEquals("Line one\nLino\nLine three\nLine four that is long enough that it wraps", content.getText());
+ }
+
+ @Test
+ public void testDeleteOnSingleLineWithStartAndEndOutOfOrder() {
+ final TextSelection selection = new TextSelection(content);
+ selection.resetTo(new CursorPosition(content, 1, 7));
+ selection.extendTo(new CursorPosition(content, 1, 3));
+ content.delete(selection);
+ Assert.assertEquals("Line one\nLino\nLine three\nLine four that is long enough that it wraps", content.getText());
+ }
+
+ @Test
+ public void testDeleteAcrossTwoLines() {
+ final TextSelection selection = new TextSelection(content);
+ selection.resetTo(new CursorPosition(content, 0, 6));
+ selection.extendTo(new CursorPosition(content, 1, 6));
+ content.delete(selection);
+ Assert.assertEquals("Line owo\nLine three\nLine four that is long enough that it wraps", content.getText());
+ }
+
+ @Test
+ public void testDeleteAcrossThreeLines() {
+ final TextSelection selection = new TextSelection(content);
+ selection.resetTo(new CursorPosition(content, 0, 6));
+ selection.extendTo(new CursorPosition(content, 2, 6));
+ content.delete(selection);
+ Assert.assertEquals("Line ohree\nLine four that is long enough that it wraps", content.getText());
+ }
+
+ @Test
+ public void testDeleteAcrossThreeLinesIncludingWrappedBlock() {
+ final TextSelection selection = new TextSelection(content);
+ selection.resetTo(new CursorPosition(content, 2, 5));
+ selection.extendTo(new CursorPosition(content, 4, 5));
+ content.delete(selection);
+ Assert.assertEquals("Line one\nLine two\nLine enough that it wraps", content.getText());
+ }
+
+ @Test
+ public void testDeleteWithinWrappedBlock() {
+ final TextSelection selection = new TextSelection(content);
+ selection.resetTo(new CursorPosition(content, 5, 0));
+ selection.extendTo(new CursorPosition(content, 5, 3));
+ content.delete(selection);
+ Assert.assertEquals("Line one\nLine two\nLine three\nLine four that is long enough that wraps", content.getText());
+ }
+
+ @Test
+ public void testDeleteMultipleLinesWithinWrappedBlock() {
+ final TextSelection selection = new TextSelection(content);
+ selection.resetTo(new CursorPosition(content, 3, 5));
+ selection.extendTo(new CursorPosition(content, 5, 3));
+ content.delete(selection);
+ Assert.assertEquals("Line one\nLine two\nLine three\nLine wraps", content.getText());
+ }
+
+ @Test
+ public void testLineBreaks() {
+ Assert.assertEquals(6, content.getNoLinesOfContent());
+
+ content.setNoDisplayLines(8);
+ final String[] lines = content.getDisplayLines();
+
+ Assert.assertEquals(8, lines.length);
+ Assert.assertEquals("Line one", lines[0]);
+ Assert.assertEquals("Line two", lines[1]);
+ Assert.assertEquals("Line three", lines[2]);
+ Assert.assertEquals("Line four that is ", lines[3]);
+ Assert.assertEquals("long enough that ", lines[4]);
+ Assert.assertEquals("it wraps", lines[5]);
+ Assert.assertEquals("", lines[6]);
+ Assert.assertEquals("", lines[7]);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextBlockTargetExample.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextBlockTargetExample.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextBlockTargetExample.java
new file mode 100644
index 0000000..f9975c5
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextBlockTargetExample.java
@@ -0,0 +1,90 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd.view.text;
+
+import org.apache.isis.viewer.dnd.drawing.Text;
+
+final class TextBlockTargetExample implements TextBlockTarget {
+ @Override
+ public int getMaxFieldWidth() {
+ return 200;
+ }
+
+ @Override
+ public Text getText() {
+ return new Text() {
+
+ @Override
+ public int charWidth(final char ch) {
+ return 10;
+ }
+
+ @Override
+ public int stringHeight(final String text, final int width) {
+ return 0;
+ }
+
+ @Override
+ public int stringWidth(final String string) {
+ return 40;
+ }
+
+ @Override
+ public int stringWidth(final String message, final int maxWidth) {
+ return 0;
+ }
+
+ @Override
+ public int getAscent() {
+ return 10;
+ }
+
+ @Override
+ public int getLineHeight() {
+ return 15;
+ }
+
+ @Override
+ public int getMidPoint() {
+ return 7;
+ }
+
+ @Override
+ public int getDescent() {
+ return 0;
+ }
+
+ @Override
+ public int getTextHeight() {
+ return 15;
+ }
+
+ @Override
+ public int getLineSpacing() {
+ return 0;
+ }
+
+ @Override
+ public String getName() {
+ return null;
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextBlockTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextBlockTest.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextBlockTest.java
new file mode 100644
index 0000000..d3d9a59
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextBlockTest.java
@@ -0,0 +1,130 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd.view.text;
+
+import junit.framework.TestCase;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.LogManager;
+
+public class TextBlockTest extends TestCase {
+
+ public static void main(final String[] args) {
+ junit.textui.TestRunner.run(TextBlockTest.class);
+ }
+
+ private TextBlock block;
+
+ @Override
+ protected void setUp() throws Exception {
+ LogManager.getRootLogger().setLevel(Level.OFF);
+
+ final TextBlockTarget user = new TextBlockTargetExample();
+ block = new TextBlock(user, "Now is the winter of our discontent made summer by this glorious sun of York", true);
+ // "Now is the winter "
+ // "of our discontent "
+ // "made summer by "
+ // "this glorious sun "
+ // "of York"
+ }
+
+ public void testBreakBlock() {
+ final TextBlock newBlock = block.splitAt(1, 11);
+ assertEquals("Now is the winter ", block.getLine(0));
+ assertEquals("of our disc", block.getLine(1));
+
+ assertEquals("ontent made summer ", newBlock.getLine(0));
+
+ }
+
+ public void testCantInsertNewline() {
+ try {
+ block.insert(0, 4, "\n");
+ fail();
+ } catch (final IllegalArgumentException expected) {
+ }
+ }
+
+ public void testCountLine() {
+ assertEquals(5, block.noLines());
+ }
+
+ public void testDeletePartOfLine() {
+ block.delete(0, 4, 0, 11);
+ assertEquals("Now winter of our ", block.getLine(0));
+ assertEquals("discontent made ", block.getLine(1));
+
+ block.delete(1, 3, 1, 10);
+ assertEquals("dis made summer by ", block.getLine(1));
+ }
+
+ public void testDeleteLines() {
+ block.delete(0, 4, 2, 12);
+ // assertEquals("Now ", block.getLine(0));
+ assertEquals("Now by this ", block.getLine(0));
+ assertEquals("glorious sun of York", block.getLine(1));
+ }
+
+ public void testDeleteLeft() {
+ block.deleteLeft(0, 3);
+ assertEquals("No is the winter of ", block.getLine(0));
+
+ block.deleteLeft(0, 17);
+ assertEquals("No is the winterof ", block.getLine(0));
+ assertEquals("our discontent ", block.getLine(1));
+
+ block.deleteLeft(1, 9);
+ assertEquals("our discntent ", block.getLine(1));
+ }
+
+ public void testDeleteRight() {
+ block.deleteRight(0, 3);
+ assertEquals("Nowis the winter of ", block.getLine(0));
+
+ block.deleteRight(0, 17);
+ assertEquals("Nowis the winter f ", block.getLine(0));
+ assertEquals("our discontent ", block.getLine(1));
+
+ block.deleteRight(1, 9);
+ assertEquals("our discotent ", block.getLine(1));
+ }
+
+ public void testGetLine() {
+ assertEquals("Now is the winter ", block.getLine(0));
+ assertEquals("of our discontent ", block.getLine(1));
+ assertEquals("made summer by ", block.getLine(2));
+ assertEquals("this glorious sun ", block.getLine(3));
+ assertEquals("of York", block.getLine(4));
+ }
+
+ public void testGetText() {
+ assertEquals("Now is the winter of our discontent made summer by this glorious sun of York", block.getText());
+ }
+
+ public void testInsert() {
+ block.insert(0, 0, "Quote:");
+ assertEquals("Quote:Now is the ", block.getLine(0));
+
+ block.insert(1, 10, "y");
+ assertEquals("Quote:Now is the ", block.getLine(0));
+ assertEquals("winter of your ", block.getLine(1));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextFieldContentStub.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextFieldContentStub.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextFieldContentStub.java
new file mode 100644
index 0000000..fa89742
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextFieldContentStub.java
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd.view.text;
+
+public class TextFieldContentStub extends TextContent {
+
+ public TextFieldContentStub() {
+ super(null, 1, WRAPPING);
+ }
+
+ @Override
+ public void alignDisplay(final int line) {
+ }
+
+ @Override
+ public int getNoLinesOfContent() {
+ return 16;
+ }
+
+ @Override
+ public int getNoDisplayLines() {
+ return 3;
+ }
+
+ @Override
+ public String getText(final int forLine) {
+ // 35 characters
+ // 0 - 3 Now
+ // 4 - 6 is
+ // 7 - 10 the
+ // 11 - 17 winter
+ // 18 - 20 of
+ // 21 - 25 our
+ // 24 - 34 discontent
+ return "Now is the winter of our discontent";
+ }
+}
http://git-wip-us.apache.org/repos/asf/isis/blob/eb613703/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextFieldContentTest.java
----------------------------------------------------------------------
diff --git a/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextFieldContentTest.java b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextFieldContentTest.java
new file mode 100644
index 0000000..6568a8b
--- /dev/null
+++ b/component/viewer/dnd/impl/src/test/java/org/apache/isis/viewer/dnd/view/text/TextFieldContentTest.java
@@ -0,0 +1,272 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you 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.apache.isis.viewer.dnd.view.text;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Collections;
+import java.util.List;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+import org.jmock.Expectations;
+import org.jmock.Mockery;
+import org.jmock.auto.Mock;
+import org.jmock.integration.junit4.JMock;
+import org.jmock.integration.junit4.JUnit4Mockery;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import org.apache.isis.core.commons.config.IsisConfigurationDefault;
+import org.apache.isis.core.metamodel.adapter.oid.OidMarshaller;
+import org.apache.isis.core.metamodel.spec.SpecificationLoaderSpi;
+import org.apache.isis.core.runtime.authentication.AuthenticationManager;
+import org.apache.isis.core.runtime.authorization.AuthorizationManager;
+import org.apache.isis.core.runtime.imageloader.TemplateImageLoader;
+import org.apache.isis.core.runtime.userprofile.UserProfileLoader;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2;
+import org.apache.isis.core.testsupport.jmock.JUnitRuleMockery2.Mode;
+import org.apache.isis.runtimes.dflt.runtime.system.DeploymentType;
+import org.apache.isis.runtimes.dflt.runtime.system.context.IsisContextStatic;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.PersistenceSessionFactory;
+import org.apache.isis.runtimes.dflt.runtime.system.persistence.Persistor;
+import org.apache.isis.runtimes.dflt.runtime.system.session.IsisSessionFactory;
+import org.apache.isis.runtimes.dflt.runtime.system.session.IsisSessionFactoryDefault;
+import org.apache.isis.viewer.dnd.drawing.Location;
+
+public class TextFieldContentTest {
+
+ private TextContent content;
+
+ @Rule
+ public JUnitRuleMockery2 context = JUnitRuleMockery2.createFor(Mode.INTERFACES_AND_CLASSES);
+
+ @Mock
+ protected TemplateImageLoader mockTemplateImageLoader;
+ @Mock
+ protected SpecificationLoaderSpi mockSpecificationLoader;
+ @Mock
+ private UserProfileLoader mockUserProfileLoader;
+ @Mock
+ protected PersistenceSessionFactory mockPersistenceSessionFactory;
+ @Mock
+ protected Persistor mockPersistenceSession;
+ @Mock
+ protected AuthenticationManager mockAuthenticationManager;
+ @Mock
+ protected AuthorizationManager mockAuthorizationManager;
+
+ @Before
+ public void setUp() throws Exception {
+ Logger.getRootLogger().setLevel(Level.OFF);
+
+ context.checking(new Expectations() {
+ {
+ ignoring(mockTemplateImageLoader);
+ ignoring(mockSpecificationLoader);
+ ignoring(mockUserProfileLoader);
+ ignoring(mockPersistenceSessionFactory);
+ ignoring(mockAuthenticationManager);
+ ignoring(mockAuthorizationManager);
+ }
+ });
+
+ final IsisSessionFactory sessionFactory = new IsisSessionFactoryDefault(DeploymentType.EXPLORATION, new IsisConfigurationDefault(), mockTemplateImageLoader, mockSpecificationLoader, mockAuthenticationManager, mockAuthorizationManager, mockUserProfileLoader, mockPersistenceSessionFactory,
+ Collections.emptyList(), new OidMarshaller());
+ sessionFactory.init();
+ IsisContextStatic.createRelaxedInstance(sessionFactory);
+
+ final TextBlockTarget target = new TextBlockTargetExample();
+
+ content = new TextContent(target, 4, TextContent.WRAPPING);
+ }
+
+ @Test
+ public void testCreate() {
+ assertEquals("", content.getText());
+ assertEquals(1, content.getNoLinesOfContent());
+ }
+
+ @Test
+ public void testDeleteLeft() {
+ content.setText("abcdefghijklm");
+ content.deleteLeft(new CursorPosition(content, 0, 2));
+ assertEquals("acdefghijklm", content.getText());
+ }
+
+ @Test
+ public void testDeleteRight() {
+ content.setText("abcdefghijklm");
+ content.deleteRight(new CursorPosition(content, 0, 2));
+ assertEquals("abdefghijklm", content.getText());
+ }
+
+ @Test
+ public void testDisplayLineCount() {
+ assertEquals(4, content.getNoDisplayLines());
+ }
+
+ @Test
+ public void testMinimalTextEqualsOneLine() {
+ content.setText("test");
+ assertEquals(1, content.getNoLinesOfContent());
+ }
+
+
+ @Test
+ public void testNumberOfDisplayLines() {
+ assertEquals(4, content.getNoDisplayLines());
+ assertEquals(4, content.getDisplayLines().length);
+ assertEquals("", content.getDisplayLines()[0]);
+ assertEquals("", content.getDisplayLines()[1]);
+ assertEquals("", content.getDisplayLines()[2]);
+ assertEquals("", content.getDisplayLines()[3]);
+
+ content.setNoDisplayLines(6);
+ assertEquals(6, content.getNoDisplayLines());
+ assertEquals(6, content.getDisplayLines().length);
+ assertEquals("", content.getDisplayLines()[0]);
+ assertEquals("", content.getDisplayLines()[1]);
+ assertEquals("", content.getDisplayLines()[2]);
+ assertEquals("", content.getDisplayLines()[3]);
+ assertEquals("", content.getDisplayLines()[4]);
+ assertEquals("", content.getDisplayLines()[5]);
+ }
+
+ @Test
+ public void testAlignField() {
+
+ // the following text wraps so it takes up 9 line
+ content.setText("Apache Isis - a framework that exposes behaviourally complete business objects directly to the user. Copyright (C) 2012 Apache Software Foundation");
+
+ assertEquals(9, content.getNoLinesOfContent());
+
+ String[] lines = content.getDisplayLines();
+ assertEquals(4, lines.length);
+ assertEquals("Apache Isis - a ", lines[0]);
+ assertEquals("framework that ", lines[1]);
+ assertEquals("exposes behaviourally ", lines[2]);
+ assertEquals("complete business ", lines[3]);
+
+ content.alignDisplay(6);
+ assertEquals(4, content.getNoDisplayLines());
+ lines = content.getDisplayLines();
+ assertEquals(4, lines.length);
+ assertEquals("to the user. ", lines[0]);
+ assertEquals("Copyright (C) 2012 ", lines[1]);
+ assertEquals("Apache Software ", lines[2]);
+ assertEquals("Foundation", lines[3]);
+ }
+
+ @Test
+ public void testInstert() {
+ content.setText("at");
+ final CursorPosition cursor = new CursorPosition(content, 0, 0);
+ content.insert(cursor, "fl");
+
+ assertEquals("flat", content.getText());
+ assertEquals(4, content.getNoDisplayLines());
+ assertEquals(1, content.getNoLinesOfContent());
+ }
+
+ @Test
+ public void testInstertOverTheEndOfLine() {
+ final CursorPosition cursor = new CursorPosition(content, 0, 0);
+ content.insert(cursor, "test insert that is longer than the four lines that were originally allocated for this test");
+
+ assertEquals("test insert that is longer than the four lines that were originally allocated for this test", content.getText());
+ assertEquals(4, content.getNoDisplayLines());
+ assertEquals(6, content.getNoLinesOfContent());
+ }
+
+ @Test
+ public void testCursorPostioningAtCorner() {
+ content.setText("test insert that is longer than a single line");
+ assertEquals(0, content.cursorAtLine(new Location()));
+ assertEquals(0, content.cursorAtCharacter(new Location(), 0));
+ }
+
+ @Test
+ public void testCursorPostioningByLine() {
+ content.setText("test insert that is longer than a single line");
+ assertEquals(0, content.cursorAtLine(new Location(1000, 0)));
+ assertEquals(0, content.cursorAtLine(new Location(1000, 10)));
+ assertEquals(0, content.cursorAtLine(new Location(1000, 14)));
+
+ assertEquals(1, content.cursorAtLine(new Location(1000, 15)));
+
+ assertEquals(1, content.cursorAtLine(new Location(1000, 25)));
+ assertEquals(1, content.cursorAtLine(new Location(1000, 29)));
+
+ assertEquals(2, content.cursorAtLine(new Location(1000, 30)));
+ assertEquals(2, content.cursorAtLine(new Location(1000, 44)));
+
+ assertEquals(3, content.cursorAtLine(new Location(1000, 45)));
+ }
+
+ @Test
+ public void testCursorPostioningByCharacter() {
+ content.setText("test insert that");
+ assertEquals(0, content.cursorAtCharacter(new Location(0, 1000), 0));
+ assertEquals(0, content.cursorAtCharacter(new Location(3, 1000), 0));
+
+ assertEquals(1, content.cursorAtCharacter(new Location(4, 1000), 0));
+ assertEquals(1, content.cursorAtCharacter(new Location(13, 1000), 0));
+
+ assertEquals(2, content.cursorAtCharacter(new Location(14, 1000), 0));
+ assertEquals(2, content.cursorAtCharacter(new Location(23, 1000), 0));
+
+ assertEquals(15, content.cursorAtCharacter(new Location(153, 1000), 0));
+
+ assertEquals(16, content.cursorAtCharacter(new Location(154, 1000), 0));
+
+ assertEquals(16, content.cursorAtCharacter(new Location(199, 1000), 0));
+ }
+
+ @Test
+ public void testCursorPostioningByCharacterPastEnd() {
+ content.setText("test insert that");
+ assertEquals(16, content.cursorAtCharacter(new Location(190, 0), 0));
+ assertEquals(0, content.cursorAtCharacter(new Location(0, 0), 0));
+ assertEquals(16, content.cursorAtCharacter(new Location(35, 0), 2));
+ }
+
+ @Test
+ public void testCursorPostioningByCharacterOnLine2() {
+ content.setNoDisplayLines(4);
+ content.setText("test insert that that spans three lines only");
+ assertEquals(0, content.cursorAtCharacter(new Location(0, 1000), 2));
+ assertEquals(0, content.cursorAtCharacter(new Location(3, 1000), 2));
+
+ assertEquals(1, content.cursorAtCharacter(new Location(4, 1000), 2));
+ assertEquals(1, content.cursorAtCharacter(new Location(13, 1000), 2));
+
+ assertEquals(2, content.cursorAtCharacter(new Location(14, 1000), 2));
+ assertEquals(2, content.cursorAtCharacter(new Location(23, 1000), 2));
+
+ assertEquals(10, content.cursorAtCharacter(new Location(14, 1000), 3));
+ assertEquals(10, content.cursorAtCharacter(new Location(23, 1000), 3));
+
+ }
+
+}