Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: f1c66018a021758431aab4e37eadcd4ab4e0b4f3 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/*******************************************************************************
 * Copyright (c) 2011, 2012 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/

package org.eclipse.ua.tests.help.webapp;

import java.io.BufferedInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;

import junit.framework.TestCase;

import org.eclipse.help.internal.base.BaseHelpSystem;
import org.eclipse.help.internal.server.WebappManager;

/**
 * Tests for reading from toc.zip
 */
public class TocZipTest extends TestCase {

	protected void setUp() throws Exception {
		BaseHelpSystem.ensureWebappRunning();
	}

	public void testDocInZipOnly() throws IOException {
		final String path= "/org.eclipse.ua.tests/data/help/manual/dz1.html";
		String contents= readPage(path);
		assertTrue(contents.indexOf("dz1 from doc.zip") > -1);
	}

	/**
	 * Verify that loose files override those in doc.zip
	 * @throws IOException
	 */
	public void testDocInZipAndBundle() throws IOException {
		final String path = "/org.eclipse.ua.tests/data/help/manual/dz2.html";
		 String contents  = readPage(path);
		 assertFalse(contents.indexOf("dz2 from doc.zip") > -1);
		 assertTrue(contents.indexOf("dz2 from bundle") > -1);
	}

	private String readPage(final String path) throws MalformedURLException,
			IOException {
		int port = WebappManager.getPort();
		URL url = new URL("http", "localhost", port, "/help/topic" + path);
		InputStream is = url.openStream();
		BufferedInputStream buffered = new BufferedInputStream(is);
	    ByteArrayOutputStream os = new ByteArrayOutputStream();
	    int result = buffered.read();
	    while(result != -1) {
	      os.write(result);
	      result = buffered.read();
	    }   
	    buffered.close();
	    os.close();
	    return  os.toString();
	}
	
}

Back to the top