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.FragmentHostHeader;
017: import org.eclipse.text.edits.TextEdit;
018: import org.osgi.framework.Constants;
019:
020: public class FragmentHostTestCase extends BundleModelTestCase {
021:
022: public FragmentHostTestCase() {
023: super (Constants.FRAGMENT_HOST);
024: }
025:
026: public static Test suite() {
027: return new TestSuite(FragmentHostTestCase.class);
028: }
029:
030: public void testAddFragmentHost() 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.FRAGMENT_HOST,
038: "org.eclipse.pde");
039:
040: IManifestHeader header = fModel.getBundle().getManifestHeader(
041: Constants.FRAGMENT_HOST);
042: assertNotNull(header);
043: assertEquals("Fragment-Host: org.eclipse.pde\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 testRemoveFragmentHost() 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("Fragment-Host: org.eclipse.pde\n");
059: fDocument.set(buffer.toString());
060: load(true);
061:
062: IManifestHeader header = fModel.getBundle().getManifestHeader(
063: Constants.FRAGMENT_HOST);
064: assertNotNull(header);
065: ((FragmentHostHeader) header).setHostId("");
066:
067: TextEdit[] ops = fListener.getTextOperations();
068: assertEquals(1, ops.length);
069:
070: ops[0].apply(fDocument);
071: assertEquals(4, fDocument.getNumberOfLines());
072: assertEquals(0, fDocument.getLineLength(3));
073: }
074:
075: public void testChangeFragmentHost() 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("Fragment-Host: org.eclipse.pde\n");
081: fDocument.set(buffer.toString());
082: load(true);
083:
084: IManifestHeader header = fModel.getBundle().getManifestHeader(
085: Constants.FRAGMENT_HOST);
086: assertNotNull(header);
087: ((FragmentHostHeader) header).setHostId("org.eclipse.jdt");
088:
089: TextEdit[] ops = fListener.getTextOperations();
090: assertEquals(1, ops.length);
091:
092: ops[0].apply(fDocument);
093: assertEquals(5, fDocument.getNumberOfLines());
094: assertEquals(0, fDocument.getLineLength(4));
095:
096: int pos = fDocument.getLineOffset(3);
097: int length = fDocument.getLineLength(3);
098:
099: StringBuffer expected = new StringBuffer(
100: "Fragment-Host: org.eclipse.jdt\n");
101: assertEquals(expected.toString(), fDocument.get(pos, length));
102: }
103:
104: }
|