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.ICoreConstants;
016: import org.eclipse.pde.internal.core.ibundle.IManifestHeader;
017: import org.eclipse.pde.internal.core.text.bundle.LazyStartHeader;
018: import org.eclipse.text.edits.TextEdit;
019:
020: public class LazyStartTestCase extends BundleModelTestCase {
021:
022: public LazyStartTestCase(String headerName) {
023: super (ICoreConstants.ECLIPSE_AUTOSTART);
024: }
025:
026: public static Test suite() {
027: return new TestSuite(BundleLocalizationTestCase.class);
028: }
029:
030: public void testGetAutoStart() {
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(": true\n");
037: fDocument.set(buffer.toString());
038: load();
039:
040: IManifestHeader header = fModel.getBundle().getManifestHeader(
041: fHeaderName);
042: assertNotNull(header);
043: assertTrue(((LazyStartHeader) header).isLazyStart());
044: }
045:
046: public void testGetAutoStart2() {
047: StringBuffer buffer = new StringBuffer();
048: buffer.append("Manifest-Version: 1.0\n");
049: buffer.append("Bundle-ManifestVersion: 2\n");
050: buffer.append("Bundle-SymoblicName: com.example.xyz\n");
051: buffer.append(fHeaderName);
052: buffer.append(": false\n");
053: fDocument.set(buffer.toString());
054: load();
055:
056: IManifestHeader header = fModel.getBundle().getManifestHeader(
057: fHeaderName);
058: assertNotNull(header);
059: assertTrue(!((LazyStartHeader) header).isLazyStart());
060: }
061:
062: public void testSetLazyStart() throws Exception {
063: StringBuffer buffer = new StringBuffer();
064: buffer.append("Manifest-Version: 1.0\n");
065: buffer.append("Bundle-ManifestVersion: 2\n");
066: buffer.append("Bundle-SymoblicName: com.example.xyz\n");
067: fDocument.set(buffer.toString());
068: load(true);
069:
070: IManifestHeader header = fModel.getBundle().getManifestHeader(
071: fHeaderName);
072: assertNull(header);
073:
074: fModel.getBundle().setHeader(fHeaderName, "plugin");
075: TextEdit[] ops = fListener.getTextOperations();
076: assertEquals(ops.length, 1);
077:
078: ops[0].apply(fDocument);
079:
080: assertEquals(5, fDocument.getNumberOfLines());
081: assertEquals(0, fDocument.getLineLength(4));
082:
083: int pos = fDocument.getLineOffset(3);
084: int length = fDocument.getLineLength(3);
085: assertEquals(fHeaderName + ": plugin\n", fDocument.get(pos,
086: length));
087: }
088:
089: public void testChangeExistingLazyStart() throws Exception {
090: StringBuffer buffer = new StringBuffer();
091: buffer.append("Manifest-Version: 1.0\n");
092: buffer.append("Bundle-ManifestVersion: 2\n");
093: buffer.append("Bundle-SymoblicName: com.example.xyz\n");
094: buffer.append(fHeaderName);
095: buffer.append(": false\n");
096: fDocument.set(buffer.toString());
097: load(true);
098:
099: IManifestHeader header = fModel.getBundle().getManifestHeader(
100: fHeaderName);
101: assertNotNull(header);
102:
103: ((LazyStartHeader) header).setLazyStart(true);
104: TextEdit[] ops = fListener.getTextOperations();
105: assertEquals(ops.length, 1);
106:
107: ops[0].apply(fDocument);
108:
109: assertEquals(5, fDocument.getNumberOfLines());
110: assertEquals(0, fDocument.getLineLength(4));
111:
112: int pos = fDocument.getLineOffset(3);
113: int length = fDocument.getLineLength(3);
114: assertEquals(fHeaderName + ": true\n", fDocument.get(pos,
115: length));
116: }
117: }
|