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