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 * |
---|
9 | * * |
---|
10 | * http://www.apache.org/licenses/LICENSE-2.0 * |
---|
11 | * * |
---|
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 | ****************************************************************/ |
---|
19 | |
---|
20 | package org.apache.james.mime4j.stream; |
---|
21 | |
---|
22 | import java.io.ByteArrayInputStream; |
---|
23 | |
---|
24 | import junit.framework.TestCase; |
---|
25 | |
---|
26 | import org.apache.james.mime4j.ExampleMail; |
---|
27 | |
---|
28 | public class MimeStreamTokenMessageRfc822Test extends TestCase { |
---|
29 | |
---|
30 | MimeTokenStream stream; |
---|
31 | |
---|
32 | @Override |
---|
33 | protected void setUp() throws Exception { |
---|
34 | super.setUp(); |
---|
35 | stream = new MimeTokenStream(); |
---|
36 | stream.parse(new ByteArrayInputStream(ExampleMail.MIME_RFC822_SIMPLE_BYTES)); |
---|
37 | } |
---|
38 | |
---|
39 | @Override |
---|
40 | protected void tearDown() throws Exception { |
---|
41 | super.tearDown(); |
---|
42 | } |
---|
43 | |
---|
44 | public void testShouldParseMessageRFC822CorrectWithDefaultConfiguration() throws Exception { |
---|
45 | nextIs(EntityState.T_START_HEADER); |
---|
46 | nextIs(EntityState.T_FIELD); |
---|
47 | nextIs(EntityState.T_FIELD); |
---|
48 | nextIs(EntityState.T_FIELD); |
---|
49 | nextIs(EntityState.T_FIELD); |
---|
50 | nextIs(EntityState.T_FIELD); |
---|
51 | nextIs(EntityState.T_FIELD); |
---|
52 | nextIs(EntityState.T_END_HEADER); |
---|
53 | nextIs(EntityState.T_START_MESSAGE); |
---|
54 | nextIs(EntityState.T_START_HEADER); |
---|
55 | nextIs(EntityState.T_FIELD); |
---|
56 | nextIs(EntityState.T_FIELD); |
---|
57 | nextIs(EntityState.T_FIELD); |
---|
58 | nextIs(EntityState.T_FIELD); |
---|
59 | nextIs(EntityState.T_END_HEADER); |
---|
60 | nextIs(EntityState.T_BODY); |
---|
61 | nextIs(EntityState.T_END_MESSAGE); |
---|
62 | nextIs(EntityState.T_END_MESSAGE); |
---|
63 | nextIs(EntityState.T_END_OF_STREAM); |
---|
64 | } |
---|
65 | |
---|
66 | public void testShouldParseMessageRFC822CorrectWithNoRecurse() throws Exception { |
---|
67 | stream.setRecursionMode(RecursionMode.M_NO_RECURSE); |
---|
68 | nextIs(EntityState.T_START_HEADER); |
---|
69 | nextIs(EntityState.T_FIELD); |
---|
70 | nextIs(EntityState.T_FIELD); |
---|
71 | nextIs(EntityState.T_FIELD); |
---|
72 | nextIs(EntityState.T_FIELD); |
---|
73 | nextIs(EntityState.T_FIELD); |
---|
74 | nextIs(EntityState.T_FIELD); |
---|
75 | nextIs(EntityState.T_END_HEADER); |
---|
76 | nextIs(EntityState.T_BODY); |
---|
77 | nextIs(EntityState.T_END_MESSAGE); |
---|
78 | nextIs(EntityState.T_END_OF_STREAM); |
---|
79 | } |
---|
80 | |
---|
81 | public void testShouldParseMessageRFC822CorrectWithFlat() throws Exception { |
---|
82 | stream.setRecursionMode(RecursionMode.M_FLAT); |
---|
83 | nextIs(EntityState.T_START_HEADER); |
---|
84 | nextIs(EntityState.T_FIELD); |
---|
85 | nextIs(EntityState.T_FIELD); |
---|
86 | nextIs(EntityState.T_FIELD); |
---|
87 | nextIs(EntityState.T_FIELD); |
---|
88 | nextIs(EntityState.T_FIELD); |
---|
89 | nextIs(EntityState.T_FIELD); |
---|
90 | nextIs(EntityState.T_END_HEADER); |
---|
91 | nextIs(EntityState.T_BODY); |
---|
92 | nextIs(EntityState.T_END_MESSAGE); |
---|
93 | nextIs(EntityState.T_END_OF_STREAM); |
---|
94 | } |
---|
95 | |
---|
96 | private void nextIs(EntityState state) throws Exception { |
---|
97 | assertEquals(MimeTokenStream.stateToString(state), MimeTokenStream.stateToString(stream.next())); |
---|
98 | } |
---|
99 | } |
---|