KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > taskdefs > CVSPassTest


1 /*
2  * Copyright 2001,2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.tools.ant.taskdefs;
19
20 import java.io.*;
21 import org.apache.tools.ant.*;
22 import org.apache.tools.ant.BuildFileTest;
23
24 /**
25  * Tests CVSLogin task.
26  *
27  */

28 public class CVSPassTest extends BuildFileTest {
29     private final String JavaDoc EOL = System.getProperty("line.separator");
30     private final String JavaDoc JAKARTA_URL =
31         ":pserver:anoncvs@jakarta.apache.org:/home/cvspublic Ay=0=h<Z";
32     private final String JavaDoc XML_URL =
33         ":pserver:anoncvs@xml.apache.org:/home/cvspublic Ay=0=h<Z";
34     private final String JavaDoc TIGRIS_URL =
35         ":pserver:guest@cvs.tigris.org:/cvs AIbdZ,";
36
37
38     public CVSPassTest(String JavaDoc name) {
39         super(name);
40     }
41
42     public void setUp() {
43         configureProject("src/etc/testcases/taskdefs/cvspass.xml");
44     }
45
46     public void testNoCVSRoot() {
47         try{
48             executeTarget("test1");
49             fail("BuildException not thrown");
50         }catch(BuildException e){
51             assertEquals("cvsroot is required", e.getMessage());
52         }
53     }
54
55     public void testNoPassword() {
56         try{
57             executeTarget("test2");
58             fail("BuildException not thrown");
59         }catch(BuildException e){
60             assertEquals("password is required", e.getMessage());
61         }
62     }
63
64     public void tearDown() {
65         executeTarget("cleanup");
66     }
67
68     public void testPassFile() throws Exception JavaDoc {
69         executeTarget("test3");
70         File f = new File(getProjectDir(), "testpassfile.tmp");
71
72         assertTrue( "Passfile "+f+" not created", f.exists());
73
74         assertEquals(JAKARTA_URL+EOL, readFile(f));
75
76     }
77
78     public void testPassFileDuplicateEntry() throws Exception JavaDoc {
79         executeTarget("test4");
80         File f = new File(getProjectDir(), "testpassfile.tmp");
81
82         assertTrue( "Passfile "+f+" not created", f.exists());
83
84         assertEquals(
85             JAKARTA_URL+ EOL+
86             TIGRIS_URL+ EOL,
87             readFile(f));
88     }
89
90     public void testPassFileMultipleEntry() throws Exception JavaDoc {
91         executeTarget("test5");
92         File f = new File(getProjectDir(), "testpassfile.tmp");
93
94         assertTrue( "Passfile "+f+" not created", f.exists());
95
96         assertEquals(
97             JAKARTA_URL+ EOL+
98             XML_URL+ EOL+
99             TIGRIS_URL+ EOL,
100             readFile(f));
101     }
102
103     private String JavaDoc readFile(File f) throws Exception JavaDoc {
104         BufferedReader reader = null;
105
106         try {
107             reader = new BufferedReader(new FileReader(f));
108
109             StringBuffer JavaDoc buf = new StringBuffer JavaDoc();
110             String JavaDoc line=null;
111             while((line=reader.readLine())!=null){
112                 buf.append(line + EOL);
113             }
114             return buf.toString();
115         } finally {
116             if (reader != null) {
117                 reader.close();
118             }
119         }
120     }
121 }
122
Popular Tags