/*
* Copyright 2007 T-Rank AS
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package no.trank.openpipe.step;
import java.util.HashMap;
import java.util.Map;
import junit.framework.TestCase;
import no.trank.openpipe.api.document.Document;
/**
* @version $Revision$
*/
public class StripHtmlTest extends TestCase {
private StripHtml stripHtml;
@Override
protected void setUp() throws Exception {
stripHtml = new StripHtml();
Map<String, String> fieldNameMap = new HashMap<String, String>();
fieldNameMap.put("in", "out");
stripHtml.setFieldNameMap(fieldNameMap);
}
public void testComments() throws Exception {
Document doc = new Document();
doc.setFieldValue("in", "<!-- html comment -->tralala<!--");
stripHtml.execute(doc);
assertEquals("tralala<!--", doc.getFieldValue("out"));
doc.setFieldValue("in","a<!--");
stripHtml.execute(doc);
assertEquals("a<!--", doc.getFieldValue("out"));
}
public void testTags() throws Exception {
Document doc = new Document();
doc.setFieldValue("in", "<div huff='jj>\\''>tralala");
stripHtml.execute(doc);
assertEquals("tralala", doc.getFieldValue("out"));
doc.setFieldValue("in", "<");
stripHtml.execute(doc);
assertEquals("<", doc.getFieldValue("out"));
}
public void testEntities() throws Exception {
Document doc = new Document();
doc.setFieldValue("in", "trala la");
stripHtml.execute(doc);
assertEquals("trala la", doc.getFieldValue("out"));
doc.setFieldValue("in", "trala&;la");
stripHtml.execute(doc);
assertEquals("tralala", doc.getFieldValue("out"));
doc.setFieldValue("in", "tralala");
stripHtml.execute(doc);
assertEquals("tralala", doc.getFieldValue("out"));
doc.setFieldValue("in", "trala la");
stripHtml.execute(doc);
assertEquals("trala la", doc.getFieldValue("out"));
doc.setFieldValue("in", "&l;");
stripHtml.execute(doc);
assertEquals("", doc.getFieldValue("out"));
}
}