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.BundleActivatorHeader;
017: import org.eclipse.text.edits.TextEdit;
018: import org.osgi.framework.Constants;
019:
020: public class BundleActivatorTestCase extends BundleModelTestCase {
021:
022: public static Test suite() {
023: return new TestSuite(BundleActivatorTestCase.class);
024: }
025:
026: public BundleActivatorTestCase() {
027: super (Constants.BUNDLE_ACTIVATOR);
028: }
029:
030: public void testGetActivator() {
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.package.Activator\n");
037: fDocument.set(buffer.toString());
038: load();
039:
040: IManifestHeader header = fModel.getBundle().getManifestHeader(
041: fHeaderName);
042: assertNotNull(header);
043: assertEquals(((BundleActivatorHeader) header).getClassName(),
044: "com.package.Activator");
045: }
046:
047: public void testSetActivator() throws Exception {
048: StringBuffer buffer = new StringBuffer();
049: buffer.append("Manifest-Version: 1.0\n");
050: buffer.append("Bundle-ManifestVersion: 2\n");
051: buffer.append("Bundle-SymoblicName: com.example.xyz\n");
052: fDocument.set(buffer.toString());
053: load(true);
054:
055: IManifestHeader header = fModel.getBundle().getManifestHeader(
056: fHeaderName);
057: assertNull(header);
058:
059: fModel.getBundle().setHeader(fHeaderName,
060: "com.package.Activator");
061: TextEdit[] ops = fListener.getTextOperations();
062: assertEquals(ops.length, 1);
063:
064: ops[0].apply(fDocument);
065:
066: assertEquals(5, fDocument.getNumberOfLines());
067: assertEquals(0, fDocument.getLineLength(4));
068:
069: int pos = fDocument.getLineOffset(3);
070: int length = fDocument.getLineLength(3);
071: assertEquals(fHeaderName + ": com.package.Activator\n",
072: fDocument.get(pos, length));
073: }
074:
075: public void testChangeExistingActivator() throws Exception {
076: StringBuffer buffer = new StringBuffer();
077: buffer.append("Manifest-Version: 1.0\n");
078: buffer.append("Bundle-ManifestVersion: 2\n");
079: buffer.append("Bundle-SymoblicName: com.example.xyz\n");
080: buffer.append(fHeaderName);
081: buffer.append(": com.package.Activator\n");
082: fDocument.set(buffer.toString());
083: load(true);
084:
085: IManifestHeader header = fModel.getBundle().getManifestHeader(
086: fHeaderName);
087: assertNotNull(header);
088:
089: ((BundleActivatorHeader) header)
090: .setClassName("com.package.BundleActivator");
091: TextEdit[] ops = fListener.getTextOperations();
092: assertEquals(ops.length, 1);
093:
094: ops[0].apply(fDocument);
095:
096: assertEquals(5, fDocument.getNumberOfLines());
097: assertEquals(0, fDocument.getLineLength(4));
098:
099: int pos = fDocument.getLineOffset(3);
100: int length = fDocument.getLineLength(3);
101: assertEquals(fHeaderName + ": com.package.BundleActivator\n",
102: fDocument.get(pos, length));
103: }
104: }
|