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.BundleLocalizationHeader;
017: import org.eclipse.text.edits.TextEdit;
018: import org.osgi.framework.Constants;
019:
020: public class BundleLocalizationTestCase extends BundleModelTestCase {
021:
022: public static Test suite() {
023: return new TestSuite(BundleLocalizationTestCase.class);
024: }
025:
026: public BundleLocalizationTestCase() {
027: super (Constants.BUNDLE_LOCALIZATION);
028: }
029:
030: public void testGetLocalization() {
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(": plugin\n");
037: fDocument.set(buffer.toString());
038: load();
039:
040: IManifestHeader header = fModel.getBundle().getManifestHeader(
041: fHeaderName);
042: assertNotNull(header);
043: assertEquals(((BundleLocalizationHeader) header)
044: .getLocalization(), "plugin");
045: }
046:
047: public void testSetLocalization() 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, "plugin");
060: TextEdit[] ops = fListener.getTextOperations();
061: assertEquals(ops.length, 1);
062:
063: ops[0].apply(fDocument);
064:
065: assertEquals(5, fDocument.getNumberOfLines());
066: assertEquals(0, fDocument.getLineLength(4));
067:
068: int pos = fDocument.getLineOffset(3);
069: int length = fDocument.getLineLength(3);
070: assertEquals(fHeaderName + ": plugin\n", fDocument.get(pos,
071: length));
072: }
073:
074: public void testChangeExistingLocalization() 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(fHeaderName);
080: buffer.append(": oldLocalization\n");
081: fDocument.set(buffer.toString());
082: load(true);
083:
084: IManifestHeader header = fModel.getBundle().getManifestHeader(
085: fHeaderName);
086: assertNotNull(header);
087:
088: ((BundleLocalizationHeader) header).setLocalization("plugin");
089: TextEdit[] ops = fListener.getTextOperations();
090: assertEquals(ops.length, 1);
091:
092: ops[0].apply(fDocument);
093:
094: assertEquals(5, fDocument.getNumberOfLines());
095: assertEquals(0, fDocument.getLineLength(4));
096:
097: int pos = fDocument.getLineOffset(3);
098: int length = fDocument.getLineLength(3);
099: assertEquals(fHeaderName + ": plugin\n", fDocument.get(pos,
100: length));
101: }
102: }
|