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.bundle;
011:
012: import junit.framework.Test;
013: import junit.framework.TestSuite;
014:
015: import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
016: import org.eclipse.pde.internal.core.text.bundle.BundleClasspathHeader;
017: import org.eclipse.text.edits.TextEdit;
018: import org.osgi.framework.Constants;
019:
020: public class BundleClasspathTestCase extends MultiLineHeaderTestCase {
021:
022: public static Test suite() {
023: return new TestSuite(BundleClasspathTestCase.class);
024: }
025:
026: public BundleClasspathTestCase() {
027: super (Constants.BUNDLE_CLASSPATH);
028: }
029:
030: public void testAddLibrary() throws Exception {
031: StringBuffer buffer = new StringBuffer();
032: buffer.append("Manifest-Version: 1.0\n");
033: buffer.append("Bundle-ManifestVersion: 2\n");
034: buffer.append("Bundle-SymoblicName: com.example.xyz\n");
035: buffer.append(fHeaderName);
036: buffer.append(": com.example.abc\n");
037: fDocument.set(buffer.toString());
038: load(true);
039:
040: IManifestHeader header = fModel.getBundle().getManifestHeader(
041: fHeaderName);
042: ((BundleClasspathHeader) header).addLibrary("com.example.xyz");
043:
044: TextEdit[] ops = fListener.getTextOperations();
045: assertEquals(1, ops.length);
046:
047: ops[0].apply(fDocument);
048:
049: assertEquals(6, fDocument.getNumberOfLines());
050: assertEquals(0, fDocument.getLineLength(5));
051:
052: int pos = fDocument.getLineOffset(4);
053: int length = fDocument.getLineLength(4);
054: assertEquals(" com.example.xyz\n", fDocument.get(pos, length));
055: }
056:
057: public void testRemoveLibrary() throws Exception {
058: StringBuffer buffer = new StringBuffer();
059: buffer.append("Manifest-Version: 1.0\n");
060: buffer.append("Bundle-ManifestVersion: 2\n");
061: buffer.append("Bundle-SymoblicName: com.example.xyz\n");
062: buffer.append(fHeaderName);
063: buffer.append(": com.example.abc,\n");
064: buffer.append(" com.example.xyz\n");
065: fDocument.set(buffer.toString());
066: load(true);
067:
068: IManifestHeader header = fModel.getBundle().getManifestHeader(
069: fHeaderName);
070: ((BundleClasspathHeader) header)
071: .removeLibrary("com.example.abc");
072:
073: TextEdit[] ops = fListener.getTextOperations();
074: assertEquals(1, ops.length);
075:
076: ops[0].apply(fDocument);
077:
078: assertEquals(5, fDocument.getNumberOfLines());
079: assertEquals(0, fDocument.getLineLength(4));
080:
081: int pos = fDocument.getLineOffset(3);
082: int length = fDocument.getLineLength(3);
083: assertEquals(fHeaderName + ": com.example.xyz\n", fDocument
084: .get(pos, length));
085: }
086:
087: public void testRemoveOnlyLibrary() throws Exception {
088: StringBuffer buffer = new StringBuffer();
089: buffer.append("Manifest-Version: 1.0\n");
090: buffer.append("Bundle-ManifestVersion: 2\n");
091: buffer.append("Bundle-SymoblicName: com.example.xyz\n");
092: buffer.append(fHeaderName);
093: buffer.append(": com.example.abc\n");
094: fDocument.set(buffer.toString());
095: load(true);
096:
097: IManifestHeader header = fModel.getBundle().getManifestHeader(
098: fHeaderName);
099: ((BundleClasspathHeader) header)
100: .removeLibrary("com.example.abc");
101:
102: TextEdit[] ops = fListener.getTextOperations();
103: assertEquals(1, ops.length);
104:
105: ops[0].apply(fDocument);
106:
107: assertEquals(4, fDocument.getNumberOfLines());
108: assertEquals(0, fDocument.getLineLength(3));
109:
110: assertEquals(fDocument.get().indexOf(fHeaderName), -1);
111: }
112: }
|