1 /****************************************************************
2 * Licensed to the Apache Software Foundation (ASF) under one *
3 * or more contributor license agreements. See the NOTICE file *
4 * distributed with this work for additional information *
5 * regarding copyright ownership. The ASF licenses this file *
6 * to you under the Apache License, Version 2.0 (the *
7 * "License"); you may not use this file except in compliance *
8 * with the License. You may obtain a copy of the License at *
10 * http://www.apache.org/licenses/LICENSE-2.0 *
12 * Unless required by applicable law or agreed to in writing, *
13 * software distributed under the License is distributed on an *
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
15 * KIND, either express or implied. See the License for the *
16 * specific language governing permissions and limitations *
17 * under the License. *
18 ****************************************************************/
20 package org
.apache
.james
.mime4j
;
22 import java
.io
.ByteArrayInputStream
;
24 import junit
.framework
.TestCase
;
26 public class StrictMimeTokenStreamTest
extends TestCase
{
28 private static final String HEADER_ONLY
= "From: foo@abr.com\r\nSubject: A subject\r\n";
29 private static final String CORRECT_HEADERS
= HEADER_ONLY
+ "\r\n";
31 public void testUnexpectedEndOfHeaders() throws Exception
{
33 MimeTokenStream parser
= MimeTokenStream
.createStrictValidationStream();
35 parser
.parse(new ByteArrayInputStream(HEADER_ONLY
.getBytes()));
37 assertEquals("Headers start", MimeTokenStream
.T_START_HEADER
, parser
.next());
38 assertEquals("Field", MimeTokenStream
.T_FIELD
, parser
.next());
41 fail("Expected exception to be thrown");
42 } catch (MimeParseEventException e
) {
43 assertEquals("Premature end of headers", Event
.HEADERS_PREMATURE_END
, e
.getEvent());
47 public void testCorrectEndOfHeaders() throws Exception
{
49 MimeTokenStream parser
= MimeTokenStream
.createStrictValidationStream();
51 parser
.parse(new ByteArrayInputStream(CORRECT_HEADERS
.getBytes()));
53 assertEquals("Headers start", MimeTokenStream
.T_START_HEADER
, parser
.next());
54 assertEquals("From header", MimeTokenStream
.T_FIELD
, parser
.next());
55 assertEquals("Subject header", MimeTokenStream
.T_FIELD
, parser
.next());
56 assertEquals("End message", MimeTokenStream
.T_END_HEADER
, parser
.next());