001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.tools.ant.taskdefs;
020:
021: import java.io.*;
022: import org.apache.tools.ant.*;
023: import org.apache.tools.ant.BuildFileTest;
024:
025: /**
026: * Tests CVSLogin task.
027: *
028: */
029: public class CVSPassTest extends BuildFileTest {
030: private final String EOL = System.getProperty("line.separator");
031: private static final String JAKARTA_URL = ":pserver:anoncvs@jakarta.apache.org:/home/cvspublic Ay=0=h<Z";
032: private static final String XML_URL = ":pserver:anoncvs@xml.apache.org:/home/cvspublic Ay=0=h<Z";
033: private static final String TIGRIS_URL = ":pserver:guest@cvs.tigris.org:/cvs AIbdZ,";
034:
035: public CVSPassTest(String name) {
036: super (name);
037: }
038:
039: public void setUp() {
040: configureProject("src/etc/testcases/taskdefs/cvspass.xml");
041: }
042:
043: public void testNoCVSRoot() {
044: try {
045: executeTarget("test1");
046: fail("BuildException not thrown");
047: } catch (BuildException e) {
048: assertEquals("cvsroot is required", e.getMessage());
049: }
050: }
051:
052: public void testNoPassword() {
053: try {
054: executeTarget("test2");
055: fail("BuildException not thrown");
056: } catch (BuildException e) {
057: assertEquals("password is required", e.getMessage());
058: }
059: }
060:
061: public void tearDown() {
062: executeTarget("cleanup");
063: }
064:
065: public void testPassFile() throws Exception {
066: executeTarget("test3");
067: File f = new File(getProjectDir(), "testpassfile.tmp");
068:
069: assertTrue("Passfile " + f + " not created", f.exists());
070:
071: assertEquals(JAKARTA_URL + EOL, readFile(f));
072:
073: }
074:
075: public void testPassFileDuplicateEntry() throws Exception {
076: executeTarget("test4");
077: File f = new File(getProjectDir(), "testpassfile.tmp");
078:
079: assertTrue("Passfile " + f + " not created", f.exists());
080:
081: assertEquals(JAKARTA_URL + EOL + TIGRIS_URL + EOL, readFile(f));
082: }
083:
084: public void testPassFileMultipleEntry() throws Exception {
085: executeTarget("test5");
086: File f = new File(getProjectDir(), "testpassfile.tmp");
087:
088: assertTrue("Passfile " + f + " not created", f.exists());
089:
090: assertEquals(JAKARTA_URL + EOL + XML_URL + EOL + TIGRIS_URL
091: + EOL, readFile(f));
092: }
093:
094: private String readFile(File f) throws Exception {
095: BufferedReader reader = null;
096:
097: try {
098: reader = new BufferedReader(new FileReader(f));
099:
100: StringBuffer buf = new StringBuffer();
101: String line = null;
102: while ((line = reader.readLine()) != null) {
103: buf.append(line + EOL);
104: }
105: return buf.toString();
106: } finally {
107: if (reader != null) {
108: reader.close();
109: }
110: }
111: }
112: }
|