001: /*******************************************************************************
002: * Copyright (c) 2006 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.pde.ui.tests.model.xml;
011:
012: import junit.framework.Test;
013: import junit.framework.TestSuite;
014:
015: import org.eclipse.pde.core.plugin.IPluginElement;
016: import org.eclipse.pde.core.plugin.IPluginExtension;
017: import org.eclipse.pde.core.plugin.IPluginObject;
018:
019: public class SwapXMLModelTestCase extends XMLModelTestCase {
020:
021: public static Test suite() {
022: return new TestSuite(SwapXMLModelTestCase.class);
023: }
024:
025: // all one one line
026: public void testSwapTwoChildren() throws Exception {
027: StringBuffer sb = new StringBuffer();
028: sb.append("<extension id=\"org.eclipse.pde.ui.samples\">");
029: sb.append("<child id=\"a\" /><child id=\"b\" />");
030: sb.append("</extension>");
031: setXMLContents(sb, LF);
032: twoChildSwap();
033: }
034:
035: // all on diff line
036: public void testSwapTwoChildren2() throws Exception {
037: StringBuffer sb = new StringBuffer();
038: sb.append("<extension id=\"org.eclipse.pde.ui.samples\">");
039: sb.append(LF);
040: sb.append("<child id=\"a\" />");
041: sb.append(LF);
042: sb.append("<child id=\"b\" />");
043: sb.append(LF);
044: sb.append("</extension>");
045: setXMLContents(sb, LF);
046: twoChildSwap();
047: }
048:
049: // all on diff line with tabs
050: public void testSwapTwoChildren3() throws Exception {
051: StringBuffer sb = new StringBuffer();
052: sb.append("<extension id=\"org.eclipse.pde.ui.samples\">");
053: sb.append(LF);
054: sb.append("\t<child id=\"a\" />");
055: sb.append(LF);
056: sb.append("\t<child id=\"b\" />");
057: sb.append(LF);
058: sb.append("</extension>");
059: setXMLContents(sb, LF);
060: twoChildSwap();
061: }
062:
063: // some on diff lines with no spacing
064: public void testSwapTwoChildren4() throws Exception {
065: StringBuffer sb = new StringBuffer();
066: sb.append("<extension id=\"org.eclipse.pde.ui.samples\">");
067: sb.append("<child id=\"a\" />");
068: sb.append(LF);
069: sb.append("<child id=\"b\" />");
070: sb.append("</extension>");
071: setXMLContents(sb, LF);
072: twoChildSwap();
073: }
074:
075: // some on diff lines with spacing
076: public void testSwapTwoChildren5() throws Exception {
077: StringBuffer sb = new StringBuffer();
078: sb.append("<extension id=\"org.eclipse.pde.ui.samples\">");
079: sb.append("\t<child id=\"a\" />");
080: sb.append(LF);
081: sb.append("\t<child id=\"b\" />");
082: sb.append(LF);
083: sb.append("</extension>");
084: setXMLContents(sb, LF);
085: twoChildSwap();
086: }
087:
088: private void twoChildSwap() throws Exception {
089: load(true);
090:
091: IPluginExtension[] extensions = fModel.getPluginBase()
092: .getExtensions();
093: assertEquals(1, extensions.length);
094:
095: IPluginObject[] children = extensions[0].getChildren();
096:
097: assertEquals(2, children.length);
098: assertTrue(children[0] instanceof IPluginElement);
099: assertTrue(children[1] instanceof IPluginElement);
100: assertEquals("a", ((IPluginElement) children[0]).getAttribute(
101: "id").getValue());
102: assertEquals("b", ((IPluginElement) children[1]).getAttribute(
103: "id").getValue());
104:
105: extensions[0].swap(children[0], children[1]);
106:
107: // move source edit - only one op
108: reload();
109:
110: extensions = fModel.getPluginBase().getExtensions();
111: assertEquals(1, extensions.length);
112:
113: children = extensions[0].getChildren();
114:
115: assertEquals(2, children.length);
116: assertTrue(children[0] instanceof IPluginElement);
117: assertTrue(children[1] instanceof IPluginElement);
118: assertEquals("b", ((IPluginElement) children[0]).getAttribute(
119: "id").getValue());
120: assertEquals("a", ((IPluginElement) children[1]).getAttribute(
121: "id").getValue());
122: }
123: }
|