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 MimeTokenStreamTest extends TestCase { |
---|
29 | |
---|
30 | MimeTokenStream stream; |
---|
31 | |
---|
32 | @Override |
---|
33 | public void setUp() throws Exception { |
---|
34 | stream = new MimeTokenStream(); |
---|
35 | } |
---|
36 | |
---|
37 | public void testSetRecursionModeBeforeParse() throws Exception { |
---|
38 | stream.setRecursionMode(RecursionMode.M_NO_RECURSE); |
---|
39 | stream.parse(new ByteArrayInputStream(ExampleMail.MAIL_WITH_RFC822_PART_BYTES)); |
---|
40 | checkNextIs(EntityState.T_START_HEADER); |
---|
41 | checkNextIs(EntityState.T_FIELD); |
---|
42 | checkNextIs(EntityState.T_FIELD); |
---|
43 | checkNextIs(EntityState.T_FIELD); |
---|
44 | checkNextIs(EntityState.T_FIELD); |
---|
45 | checkNextIs(EntityState.T_FIELD); |
---|
46 | checkNextIs(EntityState.T_FIELD); |
---|
47 | checkNextIs(EntityState.T_END_HEADER); |
---|
48 | checkNextIs(EntityState.T_START_MULTIPART); |
---|
49 | checkNextIs(EntityState.T_PREAMBLE); |
---|
50 | checkNextIs(EntityState.T_START_BODYPART); |
---|
51 | checkNextIs(EntityState.T_START_HEADER); |
---|
52 | checkNextIs(EntityState.T_END_HEADER); |
---|
53 | checkNextIs(EntityState.T_BODY); |
---|
54 | checkNextIs(EntityState.T_END_BODYPART); |
---|
55 | checkNextIs(EntityState.T_START_BODYPART); |
---|
56 | checkNextIs(EntityState.T_START_HEADER); |
---|
57 | checkNextIs(EntityState.T_FIELD); |
---|
58 | checkNextIs(EntityState.T_END_HEADER); |
---|
59 | checkNextIs(EntityState.T_BODY); |
---|
60 | checkNextIs(EntityState.T_END_BODYPART); |
---|
61 | checkNextIs(EntityState.T_START_BODYPART); |
---|
62 | checkNextIs(EntityState.T_START_HEADER); |
---|
63 | checkNextIs(EntityState.T_FIELD); |
---|
64 | checkNextIs(EntityState.T_END_HEADER); |
---|
65 | checkNextIs(EntityState.T_BODY); |
---|
66 | checkNextIs(EntityState.T_END_BODYPART); |
---|
67 | checkNextIs(EntityState.T_START_BODYPART); |
---|
68 | checkNextIs(EntityState.T_START_HEADER); |
---|
69 | checkNextIs(EntityState.T_FIELD); |
---|
70 | checkNextIs(EntityState.T_END_HEADER); |
---|
71 | checkNextIs(EntityState.T_BODY); |
---|
72 | checkNextIs(EntityState.T_END_BODYPART); |
---|
73 | checkNextIs(EntityState.T_EPILOGUE); |
---|
74 | checkNextIs(EntityState.T_END_MULTIPART); |
---|
75 | checkNextIs(EntityState.T_END_MESSAGE); |
---|
76 | checkNextIs(EntityState.T_END_OF_STREAM); |
---|
77 | } |
---|
78 | |
---|
79 | private void checkNextIs(EntityState expected) throws Exception { |
---|
80 | assertEquals(MimeTokenStream.stateToString(expected), MimeTokenStream.stateToString(stream.next())); |
---|
81 | } |
---|
82 | } |
---|