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  package org.apache.jsieve.commands.optional;
20  
21  import java.util.ArrayList;
22  import java.util.Collections;
23  import java.util.List;
24  
25  import junit.framework.TestCase;
26  
27  import org.apache.commons.logging.LogFactory;
28  import org.apache.jsieve.Argument;
29  import org.apache.jsieve.Arguments;
30  import org.apache.jsieve.BaseSieveContext;
31  import org.apache.jsieve.ConfigurationManager;
32  import org.apache.jsieve.ScriptCoordinate;
33  import org.apache.jsieve.SieveContext;
34  import org.apache.jsieve.StringListArgument;
35  import org.apache.jsieve.TestList;
36  import org.apache.jsieve.mail.ActionFileInto;
37  import org.apache.jsieve.util.check.ScriptCheckMailAdapter;
38  
39  public class FileIntoTest extends TestCase {
40  
41      FileInto subject;
42      
43      ScriptCheckMailAdapter mockAdapter;
44      Arguments dummyArguments;
45      SieveContext dummyContext;
46      
47      @SuppressWarnings("unchecked")
48      protected void setUp() throws Exception {
49          super.setUp();
50          mockAdapter = new ScriptCheckMailAdapter();
51          List<String> stringList = new ArrayList<String>();
52          stringList.add("Whatever");
53          List<Argument> argumentList = new ArrayList<Argument>();
54          argumentList.add(new StringListArgument(stringList));
55          dummyArguments = new Arguments(argumentList, new TestList(Collections.EMPTY_LIST));
56          ConfigurationManager configurationManager = new ConfigurationManager();
57          dummyContext = new BaseSieveContext(
58                  configurationManager.getCommandManager(), configurationManager
59                          .getComparatorManager(), configurationManager
60                          .getTestManager(), LogFactory
61                          .getLog(this.getClass()));
62          dummyContext.setCoordinate(new ScriptCoordinate(0, 0, 0, 0));
63          subject = new FileInto();
64      }
65  
66      protected void tearDown() throws Exception {
67          super.tearDown();
68      }
69  
70      public void testFileIntoShouldNotAllowMultipleFileIntoActions() throws Exception {
71          subject.execute(mockAdapter, dummyArguments, null, dummyContext);
72          assertEquals(1, mockAdapter.getActions().size());
73          assertTrue(mockAdapter.getActions().get(0) instanceof ActionFileInto);
74          
75          subject.execute(mockAdapter, dummyArguments, null, dummyContext);
76          assertEquals(1, mockAdapter.getActions().size());
77          assertTrue(mockAdapter.getActions().get(0) instanceof ActionFileInto);
78      }
79  }