You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm-commits@maven.apache.org by ev...@apache.org on 2003/12/08 19:08:18 UTC
cvs commit: maven-scm/generic-scm-api/src/test/org/apache/maven/genericscm/repository RepositoryTest.java TestRepository.java
evenisse 2003/12/08 10:08:18
Modified: generic-scm-api/src/java/org/apache/maven/genericscm/command
AbstractCommand.java Command.java
generic-scm-api/src/java/org/apache/maven/genericscm/repository
AbstractRepository.java
generic-scm-api/src/java/org/apache/maven/genericscm/util
EnhancedStringTokenizer.java
generic-scm-api/src/test/org/apache/maven/genericscm/command
AbstractCommandTest.java TestCommand.java
generic-scm-api/src/test/org/apache/maven/genericscm/util
CommandlineTest.java
generic-scm-providers/cvslib/src/java/org/apache/maven/genericscm/provider/cvslib/repository
CvsRepository.java
Added: generic-scm-api/src/test/org/apache/maven/genericscm/util
EnhancedStringTokenizerTest.java
generic-scm-api/src/test/org/apache/maven/genericscm/command/changelog
ChangeLogEntryTest.java ChangeLogFileTest.java
generic-scm-api/src/test/org/apache/maven/genericscm/repository
RepositoryTest.java TestRepository.java
Log:
Add more and more tests
Revision Changes Path
1.2 +1 -3 maven-scm/generic-scm-api/src/java/org/apache/maven/genericscm/command/AbstractCommand.java
Index: AbstractCommand.java
===================================================================
RCS file: /home/cvs/maven-scm/generic-scm-api/src/java/org/apache/maven/genericscm/command/AbstractCommand.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractCommand.java 2 Dec 2003 20:12:43 -0000 1.1
+++ AbstractCommand.java 8 Dec 2003 18:08:17 -0000 1.2
@@ -126,6 +126,4 @@
{
return consumer;
}
-
- public abstract Commandline getCommandLine() throws ScmException;
}
1.2 +4 -1 maven-scm/generic-scm-api/src/java/org/apache/maven/genericscm/command/Command.java
Index: Command.java
===================================================================
RCS file: /home/cvs/maven-scm/generic-scm-api/src/java/org/apache/maven/genericscm/command/Command.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- Command.java 2 Dec 2003 20:12:43 -0000 1.1
+++ Command.java 8 Dec 2003 18:08:17 -0000 1.2
@@ -57,6 +57,7 @@
*/
import org.apache.maven.genericscm.ScmException;
+import org.apache.maven.genericscm.util.Commandline;
import org.apache.maven.genericscm.repository.Repository;
import org.apache.maven.genericscm.util.StreamConsumer;
@@ -97,4 +98,6 @@
void setConsumer(StreamConsumer consumer) throws ScmException;
StreamConsumer getConsumer();
+
+ Commandline getCommandLine() throws ScmException;
}
1.2 +1 -52 maven-scm/generic-scm-api/src/java/org/apache/maven/genericscm/repository/AbstractRepository.java
Index: AbstractRepository.java
===================================================================
RCS file: /home/cvs/maven-scm/generic-scm-api/src/java/org/apache/maven/genericscm/repository/AbstractRepository.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractRepository.java 2 Dec 2003 20:12:44 -0000 1.1
+++ AbstractRepository.java 8 Dec 2003 18:08:17 -0000 1.2
@@ -56,11 +56,7 @@
* ====================================================================
*/
-import java.util.ArrayList;
-import java.util.List;
-
import org.apache.maven.genericscm.ScmException;
-import org.apache.maven.genericscm.util.EnhancedStringTokenizer;
/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
@@ -109,51 +105,4 @@
{
return delimiter;
}
-
- /**
- * Splits an connection string into parts
- * @param connection
- * @return
- */
- public String[] splitConnection() throws ScmException
- {
- if (getConnection() == null)
- {
- throw new ScmException("connection must be defined");
- }
- if (getDelimiter() == null)
- {
- throw new ScmException("delimiter must be defined");
- }
-
- EnhancedStringTokenizer tok = new EnhancedStringTokenizer(getConnection(), getDelimiter());
-
- String[] tokens = tokenizerToArray(tok);
-
- if (tokens.length < 4)
- {
- throw new IllegalArgumentException("repository connection string contains less than four tokens");
- }
-
- if (tokens.length > 4)
- {
- throw new IllegalArgumentException("repository connection string contains more than four tokens");
- }
- return tokens;
- }
-
- /**
- * Converts a tokenizer to an array of strings
- * @param tok
- * @return String[]
- */
- private static String[] tokenizerToArray(EnhancedStringTokenizer tok)
- {
- List l = new ArrayList();
- while (tok.hasMoreTokens())
- {
- l.add(tok.nextToken());
- }
- return (String[]) l.toArray(new String[l.size()]);
- }
}
1.2 +98 -77 maven-scm/generic-scm-api/src/java/org/apache/maven/genericscm/util/EnhancedStringTokenizer.java
Index: EnhancedStringTokenizer.java
===================================================================
RCS file: /home/cvs/maven-scm/generic-scm-api/src/java/org/apache/maven/genericscm/util/EnhancedStringTokenizer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EnhancedStringTokenizer.java 2 Dec 2003 20:12:44 -0000 1.1
+++ EnhancedStringTokenizer.java 8 Dec 2003 18:08:17 -0000 1.2
@@ -64,81 +64,102 @@
* It will return 1,3,4
* Which is clearly wrong - 1,EMPTY,EMPTY,3,EMPTY,4 is what it should return
*/
-public final class EnhancedStringTokenizer {
- private StringTokenizer cst = null;
- String cdelim;
- final boolean cdelimSingleChar;
- final char cdelimChar;
- boolean creturnDelims;
-
- public EnhancedStringTokenizer(String str) {
- this(str, " \t\n\r\f", false);
- }
-
- public EnhancedStringTokenizer(String str, String delim) {
- this(str, delim, false);
- }
-
- public EnhancedStringTokenizer(String str, String delim, boolean returnDelims) {
- cst = new StringTokenizer(str, delim, true);
- cdelim = delim;
- creturnDelims = returnDelims;
- cdelimSingleChar = (delim.length() == 1);
- cdelimChar = delim.charAt(0);
- }
-
- public boolean hasMoreTokens() {
- return cst.hasMoreTokens();
- }
-
- String lastToken = null;
- boolean delimLast = true;
- private String internalNextToken() {
- if (lastToken != null) {
- String last = lastToken;
- lastToken = null;
- return last;
- }
-
- String token = cst.nextToken();
- if (isDelim(token)) {
- if (delimLast) {
- lastToken = token;
- return "";
- } else {
- delimLast = true;
- return token;
- }
- } else {
- delimLast = false;
- return token;
- }
- }
-
- public String nextToken() {
- String token = internalNextToken();
- if (creturnDelims)
- return token;
- if (isDelim(token))
- return hasMoreTokens() ? internalNextToken() : "";
- else
- return token;
- }
-
- private boolean isDelim(String str) {
- if (str.length() == 1) {
- char ch = str.charAt(0);
- if (cdelimSingleChar) {
- if (cdelimChar == ch) {
- return true;
- }
- } else {
- if (cdelim.indexOf(ch) >= 0) {
- return true;
- }
- }
- }
- return false;
+public final class EnhancedStringTokenizer
+{
+ private StringTokenizer cst = null;
+ String cdelim;
+ final boolean cdelimSingleChar;
+ final char cdelimChar;
+ boolean creturnDelims;
+ String lastToken = null;
+ boolean delimLast = true;
+
+ public EnhancedStringTokenizer(String str)
+ {
+ this(str, " \t\n\r\f", false);
+ }
+
+ public EnhancedStringTokenizer(String str, String delim)
+ {
+ this(str, delim, false);
+ }
+
+ public EnhancedStringTokenizer(String str, String delim, boolean returnDelims)
+ {
+ cst = new StringTokenizer(str, delim, true);
+ cdelim = delim;
+ creturnDelims = returnDelims;
+ cdelimSingleChar = (delim.length() == 1);
+ cdelimChar = delim.charAt(0);
+ }
+
+ public boolean hasMoreTokens()
+ {
+ return cst.hasMoreTokens();
+ }
+
+ private String internalNextToken()
+ {
+ if (lastToken != null)
+ {
+ String last = lastToken;
+ lastToken = null;
+ return last;
+ }
+
+ String token = cst.nextToken();
+ if (isDelim(token))
+ {
+ if (delimLast)
+ {
+ lastToken = token;
+ return "";
+ }
+ else
+ {
+ delimLast = true;
+ return token;
+ }
+ }
+ else
+ {
+ delimLast = false;
+ return token;
+ }
+ }
+
+ public String nextToken()
+ {
+ String token = internalNextToken();
+ if (creturnDelims)
+ return token;
+ if (isDelim(token))
+ return hasMoreTokens() ? internalNextToken() : "";
+ else
+ return token;
+ }
+
+ private boolean isDelim(String str)
+ {
+ if (str.length() == 1)
+ {
+ char ch = str.charAt(0);
+ if (cdelimSingleChar)
+ {
+ if (cdelimChar == ch)
+ {
+ return true;
+ }
+ }
+ else
+ {
+ if (cdelim.indexOf(ch) >= 0)
+ {
+ return true;
+ }
+ }
+ }
+ return false;
- }
-}
\ No newline at end of file
+ }
+}
1.3 +40 -3 maven-scm/generic-scm-api/src/test/org/apache/maven/genericscm/command/AbstractCommandTest.java
Index: AbstractCommandTest.java
===================================================================
RCS file: /home/cvs/maven-scm/generic-scm-api/src/test/org/apache/maven/genericscm/command/AbstractCommandTest.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- AbstractCommandTest.java 3 Dec 2003 17:53:04 -0000 1.2
+++ AbstractCommandTest.java 8 Dec 2003 18:08:17 -0000 1.3
@@ -60,6 +60,9 @@
import junit.framework.TestCase;
+import org.apache.maven.genericscm.util.DefaultConsumer;
+import org.apache.maven.genericscm.util.StreamConsumer;
+
/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @version $Id$
@@ -73,8 +76,6 @@
public AbstractCommandTest(String testName)
{
super(testName);
- baseDir = System.getProperty("basedir");
- assertNotNull("The system property basedir was not defined.", baseDir);
}
/* (non-Javadoc)
@@ -83,6 +84,8 @@
protected void setUp() throws Exception
{
super.setUp();
+ baseDir = System.getProperty("basedir");
+ assertNotNull("The system property basedir was not defined.", baseDir);
}
public void testWorkingDirectory()
@@ -93,5 +96,39 @@
File workDir = new File(wd);
assertTrue(workDir.exists());
workDir.delete();
+ }
+
+ public void testCommandExecutionWithWorkingDir()
+ {
+ try
+ {
+ TestCommand cmd = new TestCommand();
+ cmd.setWorkingDirectory(baseDir);
+ StreamConsumer cons = new DefaultConsumer();
+ cmd.setConsumer(cons);
+ assertEquals(cons, cmd.getConsumer());
+ cmd.execute();
+ }
+ catch(Exception e)
+ {
+ fail(e.getMessage());
+ }
+ }
+
+ public void testCommandExecutionWithoutWorkingDir()
+ {
+ try
+ {
+ TestCommand cmd = new TestCommand();
+ //cmd.setWorkingDirectory(baseDir);
+ StreamConsumer cons = new DefaultConsumer();
+ cmd.setConsumer(cons);
+ assertEquals(cons, cmd.getConsumer());
+ cmd.execute();
+ }
+ catch(Exception e)
+ {
+ fail(e.getMessage());
+ }
}
}
1.2 +6 -17 maven-scm/generic-scm-api/src/test/org/apache/maven/genericscm/command/TestCommand.java
Index: TestCommand.java
===================================================================
RCS file: /home/cvs/maven-scm/generic-scm-api/src/test/org/apache/maven/genericscm/command/TestCommand.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestCommand.java 2 Dec 2003 20:12:44 -0000 1.1
+++ TestCommand.java 8 Dec 2003 18:08:17 -0000 1.2
@@ -69,26 +69,15 @@
{
/* (non-Javadoc)
- * @see org.apache.maven.genericscm.command.Command#setConsumer(org.apache.maven.genericscm.util.StreamConsumer)
- */
- public void setConsumer(StreamConsumer consumer) throws ScmException
- {
- }
-
- /* (non-Javadoc)
- * @see org.apache.maven.genericscm.command.Command#getConsumer()
- */
- public StreamConsumer getConsumer()
- {
- return null;
- }
-
- /* (non-Javadoc)
* @see org.apache.maven.genericscm.command.AbstractCommand#getCommandLine()
*/
public Commandline getCommandLine() throws ScmException
{
- return null;
+ Commandline cmd = new Commandline();
+ //cmd.setWorkingDirectory(getWorkingDirectory());
+ cmd.setExecutable("echo");
+ cmd.createArgument().setValue("Hello");
+ return cmd;
}
/* (non-Javadoc)
1.2 +1 -0 maven-scm/generic-scm-api/src/test/org/apache/maven/genericscm/util/CommandlineTest.java
Index: CommandlineTest.java
===================================================================
RCS file: /home/cvs/maven-scm/generic-scm-api/src/test/org/apache/maven/genericscm/util/CommandlineTest.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CommandlineTest.java 7 Dec 2003 20:03:42 -0000 1.1
+++ CommandlineTest.java 8 Dec 2003 18:08:18 -0000 1.2
@@ -63,6 +63,7 @@
public class CommandlineTest extends TestCase
{
private String baseDir;
+
/**
* @param testName
*/
1.1 maven-scm/generic-scm-api/src/test/org/apache/maven/genericscm/util/EnhancedStringTokenizerTest.java
Index: EnhancedStringTokenizerTest.java
===================================================================
package org.apache.maven.genericscm.util;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import junit.framework.TestCase;
public class EnhancedStringTokenizerTest extends TestCase
{
/**
* @param testName
*/
public EnhancedStringTokenizerTest(final String testName)
{
super(testName);
}
/*
* @see TestCase#setUp()
*/
public void setUp() throws Exception
{
super.setUp();
}
public void test1()
{
EnhancedStringTokenizer est = new EnhancedStringTokenizer("this is a test string");
StringBuffer sb = new StringBuffer();
while(est.hasMoreTokens())
{
sb.append(est.nextToken());
sb.append(" ");
}
assertEquals("this is a test string ", sb.toString());
}
public void test2()
{
EnhancedStringTokenizer est = new EnhancedStringTokenizer("1,,,3,,4", ",");
assertEquals("Token 1", "1", est.nextToken());
assertEquals("Token 2", "", est.nextToken());
assertEquals("Token 3", "", est.nextToken());
assertEquals("Token 4", "3", est.nextToken());
assertEquals("Token 5", "", est.nextToken());
assertEquals("Token 6", "4", est.nextToken());
}
public void test3()
{
EnhancedStringTokenizer est = new EnhancedStringTokenizer("1,,,3,,4", ",", true);
assertEquals("Token 1", "1", est.nextToken());
assertEquals("Token 2", ",", est.nextToken());
assertEquals("Token 3", "", est.nextToken());
assertEquals("Token 4", ",", est.nextToken());
assertEquals("Token 5", "", est.nextToken());
assertEquals("Token 6", ",", est.nextToken());
assertEquals("Token 7", "3", est.nextToken());
assertEquals("Token 8", ",", est.nextToken());
assertEquals("Token 9", "", est.nextToken());
assertEquals("Token 10", ",", est.nextToken());
assertEquals("Token 11", "4", est.nextToken());
}
public void testMultipleDelim()
{
EnhancedStringTokenizer est = new EnhancedStringTokenizer("1 2|3|4", " |", true);
assertEquals("Token 1", "1", est.nextToken());
assertEquals("Token 2", " ", est.nextToken());
assertEquals("Token 3", "2", est.nextToken());
assertEquals("Token 4", "|", est.nextToken());
assertEquals("Token 5", "3", est.nextToken());
assertEquals("Token 6", "|", est.nextToken());
assertEquals("Token 7", "4", est.nextToken());
assertEquals("est.hasMoreTokens()", false, est.hasMoreTokens());
}
public void testEmptyString()
{
EnhancedStringTokenizer est = new EnhancedStringTokenizer("");
assertEquals("est.hasMoreTokens()", false, est.hasMoreTokens());
try
{
est.nextToken();
fail();
}
catch(Exception e)
{
}
}
public void testSimpleString()
{
EnhancedStringTokenizer est = new EnhancedStringTokenizer("a ");
assertEquals("Token 1", "a", est.nextToken());
assertEquals("Token 2", "", est.nextToken());
assertEquals("est.hasMoreTokens()", false, est.hasMoreTokens());
}
}
1.2 +52 -2 maven-scm/generic-scm-providers/cvslib/src/java/org/apache/maven/genericscm/provider/cvslib/repository/CvsRepository.java
Index: CvsRepository.java
===================================================================
RCS file: /home/cvs/maven-scm/generic-scm-providers/cvslib/src/java/org/apache/maven/genericscm/provider/cvslib/repository/CvsRepository.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- CvsRepository.java 2 Dec 2003 20:13:32 -0000 1.1
+++ CvsRepository.java 8 Dec 2003 18:08:18 -0000 1.2
@@ -56,8 +56,12 @@
* ====================================================================
*/
+import java.util.ArrayList;
+import java.util.List;
+
import org.apache.maven.genericscm.ScmException;
import org.apache.maven.genericscm.repository.AbstractRepository;
+import org.apache.maven.genericscm.util.EnhancedStringTokenizer;
/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
@@ -202,5 +206,51 @@
{
this.password = password;
}
-
+
+ /**
+ * Splits an connection string into parts
+ * @param connection
+ * @return
+ */
+ public String[] splitConnection() throws ScmException
+ {
+ if (getConnection() == null)
+ {
+ throw new ScmException("connection must be defined");
+ }
+ if (getDelimiter() == null)
+ {
+ throw new ScmException("delimiter must be defined");
+ }
+
+ EnhancedStringTokenizer tok = new EnhancedStringTokenizer(getConnection(), getDelimiter());
+
+ String[] tokens = tokenizerToArray(tok);
+
+ if (tokens.length < 4)
+ {
+ throw new IllegalArgumentException("repository connection string contains less than four tokens");
+ }
+
+ if (tokens.length > 4)
+ {
+ throw new IllegalArgumentException("repository connection string contains more than four tokens");
+ }
+ return tokens;
+ }
+
+ /**
+ * Converts a tokenizer to an array of strings
+ * @param tok
+ * @return String[]
+ */
+ private static String[] tokenizerToArray(EnhancedStringTokenizer tok)
+ {
+ List l = new ArrayList();
+ while (tok.hasMoreTokens())
+ {
+ l.add(tok.nextToken());
+ }
+ return (String[]) l.toArray(new String[l.size()]);
+ }
}
1.1 maven-scm/generic-scm-api/src/test/org/apache/maven/genericscm/command/changelog/ChangeLogEntryTest.java
Index: ChangeLogEntryTest.java
===================================================================
package org.apache.maven.genericscm.command.changelog;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
import java.util.Calendar;
import java.util.Date;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import junit.textui.TestRunner;
/**
* Tests for the {@link ChangeLogEntry} class
*
* @author dion
* @version $Id: ChangeLogEntryTest.java,v 1.1 2003/12/08 18:08:18 evenisse Exp $
*/
public class ChangeLogEntryTest extends TestCase
{
/** the {@link ChangeLogEntry} used for testing */
private ChangeLogEntry instance;
/**
* Create a test with the given name
* @param testName the name of the test
*/
public ChangeLogEntryTest(String testName)
{
super(testName);
}
/**
* Run the test using the {@link TestRunner}
* @param args command line provided arguments
*/
public static void main(String[] args)
{
TestRunner.run(suite());
}
/**
* Create a test suite for this class
* @return a {@link TestSuite} for all tests in this class
*/
public static Test suite()
{
return new TestSuite(ChangeLogEntryTest.class);
}
/**
* Initialize per test data
*/
public void setUp()
{
instance = new ChangeLogEntry();
instance.setAuthor("dion");
instance.setComment("comment");
instance.setDate("2002/04/01 00:00:00");
}
/**
* Test of addFile methods: using ChangeLogFile
*/
public void testAddFileWithFile()
{
ChangeLogFile file = new ChangeLogFile("maven:dummy");
instance.addFile(file);
assertTrue("File name not found in list",
instance.toString().indexOf("maven:dummy") != -1 );
}
/**
* Test of addFile methods: using file & revision
*/
public void testAddFileWithFileAndRevision()
{
instance.addFile("maven:dummy", "x.y");
assertTrue("File name not found in list",
instance.toString().indexOf("maven:dummy") != -1);
assertTrue("Revision not found in list",
instance.toString().indexOf("x.y") != -1);
}
/**
* Test of toString method
*/
public void testToString()
{
//dion, Mon Apr 01 00:00:00 EST 2002, [], comment
String value = instance.toString();
assertTrue("author not found in string", value.indexOf("dion") != -1);
assertTrue("comment not found in string",
value.indexOf("comment") != -1);
assertTrue("date not found in string",
value.indexOf("Mon Apr 01") != -1);
assertTrue("empty file list not found in string",
value.indexOf("[]") != -1);
}
/**
* Test of toXML method
*/
public void testToXML()
{
String value = instance.toXML();
String trimmedValue = value.trim();
assertTrue("XML doesn't start with changelog-entry",
trimmedValue.startsWith("<changelog-entry>"));
assertTrue("XML doesn't contain date",
value.indexOf("<date>2002-04-01</date>") != -1);
assertTrue("XML doesn't contain author CDATA",
value.indexOf("<author><![CDATA[dion]]></author>") != -1);
assertTrue("XML doesn't contain comment CDATA",
value.indexOf("<msg><![CDATA[comment]]></msg>") != -1);
}
/**
* Test of getAuthor method
*/
public void testGetAuthor()
{
assertEquals("Author value not retrieved correctly", "dion",
instance.getAuthor());
}
/**
* Test of setAuthor method
*/
public void testSetAuthor()
{
instance.setAuthor("maven:dion");
assertEquals("Author not set correctly", "maven:dion",
instance.getAuthor());
}
/**
* Test of getComment method
*/
public void testGetComment()
{
assertEquals("Comment value not retrieved correctly", "comment",
instance.getComment());
}
/**
* Test of setComment method
*/
public void testSetComment()
{
instance.setComment("maven:comment");
assertEquals("Comment not set correctly", "maven:comment",
instance.getComment());
}
/**
* Test of getDate method
*/
public void testGetDate()
{
Calendar cal = Calendar.getInstance();
cal.set(2002, 3, 1, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
assertEquals("Date value not retrieved correctly", cal.getTime(),
instance.getDate());
}
/**
* Test of setDate method with Date object
*/
public void testSetDate()
{
Calendar cal = Calendar.getInstance();
Date date = cal.getTime();
instance.setDate(date);
assertEquals("Date value not set correctly", date, instance.getDate());
}
/**
* Test of setDate method with String
*/
public void testSetDateFromString()
{
instance.setDate("2002/03/04 00:00:00");
Calendar cal = Calendar.getInstance();
cal.set(2002, 2, 4, 0, 0, 0);
cal.set(Calendar.MILLISECOND, 0);
assertEquals("Date value not set correctly from a string",
cal.getTime(), instance.getDate());
}
/**
* Test of getDateFormatted method
*/
public void testGetDateFormatted()
{
assertEquals("Date not formatted correctly", "2002-04-01",
instance.getDateFormatted());
}
/**
* Test of getDateFormatted method
*/
public void testGetTimeFormatted()
{
assertEquals("Time not formatted correctly", "00:00:00",
instance.getTimeFormatted());
}
// Add test methods here, they have to start with 'test' name.
// for example:
// public void testHello() {}
}
1.1 maven-scm/generic-scm-api/src/test/org/apache/maven/genericscm/command/changelog/ChangeLogFileTest.java
Index: ChangeLogFileTest.java
===================================================================
package org.apache.maven.genericscm.command.changelog;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-userName documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import junit.framework.TestCase;
/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @version $Id: ChangeLogFileTest.java,v 1.1 2003/12/08 18:08:18 evenisse Exp $
*/
public class ChangeLogFileTest extends TestCase
{
private String baseDir;
/**
* @param testName
*/
public ChangeLogFileTest(String testName)
{
super(testName);
}
/* (non-Javadoc)
* @see junit.framework.TestCase#setUp()
*/
protected void setUp() throws Exception
{
super.setUp();
baseDir = System.getProperty("basedir");
assertNotNull("The system property basedir was not defined.", baseDir);
}
public void testNewFile()
{
ChangeLogFile f = new ChangeLogFile("test.java");
assertEquals("test.java", f.getName());
assertEquals(null, f.getRevision());
assertEquals("test.java", f.toString());
}
public void testNewRevisionFile()
{
ChangeLogFile f = new ChangeLogFile("test.java", "revision1");
assertEquals("test.java", f.getName());
assertEquals("revision1", f.getRevision());
assertEquals("test.java, revision1", f.toString());
}
}
1.1 maven-scm/generic-scm-api/src/test/org/apache/maven/genericscm/repository/RepositoryTest.java
Index: RepositoryTest.java
===================================================================
package org.apache.maven.genericscm.repository;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-userName documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import junit.framework.TestCase;
public class RepositoryTest extends TestCase
{
private TestRepository repo;
/**
* @param testName
*/
public RepositoryTest(final String testName)
{
super(testName);
}
/*
* @see TestCase#setUp()
*/
public void setUp() throws Exception
{
super.setUp();
repo = new TestRepository();
}
public void testSetConnectionWithoutDelimiter()
{
try
{
repo.setConnection("myConnection");
fail();
}
catch(Exception e)
{
}
}
public void testSetConnectionWithDelimiter()
{
try
{
repo.setDelimiter(":");
assertEquals(":", repo.getDelimiter());
repo.setConnection("my:connection");
assertEquals("my:connection", repo.getConnection());
}
catch(Exception e)
{
fail(e.getMessage());
}
}
}
1.1 maven-scm/generic-scm-api/src/test/org/apache/maven/genericscm/repository/TestRepository.java
Index: TestRepository.java
===================================================================
package org.apache.maven.genericscm.repository;
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Maven" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Maven", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
import org.apache.maven.genericscm.ScmException;
public class TestRepository extends AbstractRepository
{
private String password;
public void setPassword(String password)
{
this.password = password;
}
public String getPassword()
{
return password;
}
public void parseConnection() throws ScmException
{
//return getConnection();
}
}