blob: e9e571210d4a932f0fc902a702364fd0f09371a5 [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2004 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.jst.jsp.core.tests.contenttypeidentifier.contentspecific;
import java.io.IOException;
import junit.framework.TestCase;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.content.IContentDescription;
import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.core.runtime.content.IContentTypeManager;
import org.eclipse.wst.common.encoding.content.IContentTypeIdentifier;
/**
* This class is to test very basics of content type handlers.
*
* It tests that
*
* BVT: content registry can be / is created 5 expected contentTypeIdentifiers
* can be created/found based on id. there is one and only one default content
* type handler.
*
*
*
*
*/
public class TestContentTypeHandlers extends TestCase {
private static final boolean DEBUG = false;
public TestContentTypeHandlers(String name) {
super(name);
}
private static IContentTypeManager getContentTypeRegistry() {
IContentTypeManager registry = Platform.getContentTypeManager();
return registry;
}
public void testCreation() {
IContentTypeManager registry = getContentTypeRegistry();
assertTrue("content type identifer registry must exist", registry != null);
if (DEBUG) {
IContentType[] allTypes = registry.getAllContentTypes();
for (int i = 0; i < allTypes.length; i++) {
System.out.println(allTypes[i]);
}
}
}
public void testXMLExists() {
String id = IContentTypeIdentifier.ContentTypeID_SSEXML;
IContentTypeManager registry = getContentTypeRegistry();
IContentType identifier = registry.getContentType(id);
assertTrue("content type identifier registry does not have XML type ", identifier != null);
}
public void testHTMLExists() {
String id = IContentTypeIdentifier.ContentTypeID_HTML;
IContentTypeManager registry = getContentTypeRegistry();
IContentType identifier = registry.getContentType(id);
assertTrue("content type identifier registry does not have HTML type ", identifier != null);
}
public void testJSPExists() {
String id = IContentTypeIdentifier.ContentTypeID_JSP;
IContentTypeManager registry = getContentTypeRegistry();
IContentType identifier = registry.getContentType(id);
assertTrue("content type identifier registry does not have JSP type ", identifier != null);
}
public void testCSSExists() {
String id = IContentTypeIdentifier.ContentTypeID_CSS;
IContentTypeManager registry = getContentTypeRegistry();
IContentType identifier = registry.getContentType(id);
assertTrue("content type identifier registry does not have CSS type ", identifier != null);
}
public void testDTDExists() {
String id = IContentTypeIdentifier.ContentTypeID_DTD;
IContentTypeManager registry = getContentTypeRegistry();
IContentType identifier = registry.getContentType(id);
assertTrue("content type identifier registry does not have DTD type ", identifier != null);
}
public void testXMLExistsByFileExtension() throws IOException {
String filename = "test.xml";
IContentTypeManager registry = getContentTypeRegistry();
IContentType identifier = registry.getDescriptionFor(new NullStream(), filename, IContentDescription.ALL).getContentType();
assertTrue("content type identifier registry does not have XML type ", identifier != null);
}
public void testHTMLExistsByFileExtension() throws IOException {
String filename = "test.html";
IContentTypeManager registry = getContentTypeRegistry();
IContentType identifier = registry.getDescriptionFor(new NullStream(), filename, IContentDescription.ALL).getContentType();
assertTrue("content type identifier registry does not have HTML type ", identifier != null);
}
public void testJSPExistsByFileExtension() throws IOException {
String filename = "test.jsp";
IContentTypeManager registry = getContentTypeRegistry();
IContentType identifier = registry.getDescriptionFor(new NullStream(), filename, IContentDescription.ALL).getContentType();
assertTrue("content type identifier registry does not have JSP type ", identifier != null);
}
public void testCSSExistsByFileExtension() throws IOException {
String filename = "test.css";
IContentTypeManager registry = getContentTypeRegistry();
IContentType identifier = registry.getDescriptionFor(new NullStream(), filename, IContentDescription.ALL).getContentType();
assertTrue("content type identifier registry does not have CSS type ", identifier != null);
}
public void testDTDExistsByFileExtension() throws IOException {
String filename = "test.dtd";
IContentTypeManager registry = getContentTypeRegistry();
IContentType identifier = registry.getDescriptionFor(new NullStream(), filename, IContentDescription.ALL).getContentType();
assertTrue("content type identifier registry does not have DTD type ", identifier != null);
}
public void testMultipleDefinitions() throws IOException {
String id = IContentTypeIdentifier.ContentTypeID_CSS;
String filename = "test.css";
IContentTypeManager registry = getContentTypeRegistry();
IContentType identifier1 = registry.getContentType(id);
IContentType identifier2 = registry.getDescriptionFor(new NullStream(), filename, IContentDescription.ALL).getContentType();
assertTrue("mulitple content type identifiers need to map to same instance ", identifier1 == identifier2);
}
}