Author: norman
Date: Mon Nov 13 04:35:50 2006
New Revision: 474281
URL: http://svn.apache.org/viewvc?view=rev&rev=474281
Log:
Create more junit tests for JunkScorehandler, create JunkScoreConfigUtil and
fix some bugs. Second part for JAMES-614
Added:
james/server/trunk/src/java/org/apache/james/util/junkscore/JunkScoreConfigUtil.java
(with props)
james/server/trunk/src/test/org/apache/james/util/junkscore/
james/server/trunk/src/test/org/apache/james/util/junkscore/ComposedJunkScoreTest.java
(with props)
james/server/trunk/src/test/org/apache/james/util/junkscore/JunkScoreConfigUtilTest.java
(with props)
james/server/trunk/src/test/org/apache/james/util/junkscore/JunkScoreImplTest.java
(with props)
Modified:
james/server/trunk/src/java/org/apache/james/util/junkscore/ComposedJunkScore.java
james/server/trunk/src/java/org/apache/james/util/junkscore/JunkScoreImpl.java
Modified:
james/server/trunk/src/java/org/apache/james/util/junkscore/ComposedJunkScore.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/util/junkscore/ComposedJunkScore.java?view=diff&rev=474281&r1=474280&r2=474281
==============================================================================
---
james/server/trunk/src/java/org/apache/james/util/junkscore/ComposedJunkScore.java
(original)
+++
james/server/trunk/src/java/org/apache/james/util/junkscore/ComposedJunkScore.java
Mon Nov 13 04:35:50 2006
@@ -79,11 +79,12 @@
}
/**
- * Return only 0
+ * Throws an UnsuportedOperationException cause its not supported here
+ *
+ * @throws UnsupportedOperationException
*/
public double setStoredScore(String key, double score) {
- // just do nothing here and return 0
- return 0;
+ throw new UnsupportedOperationException("Unimplemented Method");
}
}
Added:
james/server/trunk/src/java/org/apache/james/util/junkscore/JunkScoreConfigUtil.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/util/junkscore/JunkScoreConfigUtil.java?view=auto&rev=474281
==============================================================================
---
james/server/trunk/src/java/org/apache/james/util/junkscore/JunkScoreConfigUtil.java
(added)
+++
james/server/trunk/src/java/org/apache/james/util/junkscore/JunkScoreConfigUtil.java
Mon Nov 13 04:35:50 2006
@@ -0,0 +1,70 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+
+
+
+package org.apache.james.util.junkscore;
+
+/**
+ * Utility class for providing static method for JunkScore configuration
+ */
+public class JunkScoreConfigUtil {
+
+ public static final String JUNKSCORE = "junkscore";
+ public static final String JUNKSCORE_DELIMITER = ":";
+
+ /**
+ * Return the junkscore which was supplied as raw config String
+ *
+ * @param raw configuration String
+ * @return junkScore
+ * @throws IllegalArgumentException get thrown on invalid config
+ */
+ public static double getJunkScoreConfig(String raw) throws
IllegalArgumentException {
+ double score = 0;
+ raw = raw.toLowerCase();
+ if (raw.indexOf(JUNKSCORE_DELIMITER) > 0 && raw.startsWith(JUNKSCORE))
{
+ try {
+ score =
Double.parseDouble(raw.trim().split(JUNKSCORE_DELIMITER)[1]);
+ } catch (NumberFormatException e) {
+ throw new IllegalArgumentException("Invalid input: " + raw);
+ }
+ } else {
+ throw new IllegalArgumentException("Invalid input: " + raw);
+ }
+ return score;
+ }
+
+
+ /**
+ * Return true if the given raw config is a valid JunkScore configuration
String
+ *
+ * @param raw configuration String
+ * @return true of false
+ */
+ public static boolean isValidJunkScoreConfig(String raw) {
+ try {
+ getJunkScoreConfig(raw);
+ } catch (IllegalArgumentException e){
+ return false;
+ }
+ return true;
+ }
+}
Propchange:
james/server/trunk/src/java/org/apache/james/util/junkscore/JunkScoreConfigUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified:
james/server/trunk/src/java/org/apache/james/util/junkscore/JunkScoreImpl.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/util/junkscore/JunkScoreImpl.java?view=diff&rev=474281&r1=474280&r2=474281
==============================================================================
---
james/server/trunk/src/java/org/apache/james/util/junkscore/JunkScoreImpl.java
(original)
+++
james/server/trunk/src/java/org/apache/james/util/junkscore/JunkScoreImpl.java
Mon Nov 13 04:35:50 2006
@@ -43,7 +43,7 @@
Iterator s = scoreMap.keySet().iterator();
while (s.hasNext()) {
- count =+ Double.parseDouble(scoreMap.get(s.next()).toString());
+ count = count + getStoredScore(s.next().toString());
}
return count;
}
@@ -76,7 +76,7 @@
*/
public double setStoredScore(String key, double score) {
Object s = null;
- scoreMap.put(key, String.valueOf(score));
+ s = scoreMap.put(key, String.valueOf(score));
if (s == null) {
return 0;
Added:
james/server/trunk/src/test/org/apache/james/util/junkscore/ComposedJunkScoreTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/util/junkscore/ComposedJunkScoreTest.java?view=auto&rev=474281
==============================================================================
---
james/server/trunk/src/test/org/apache/james/util/junkscore/ComposedJunkScoreTest.java
(added)
+++
james/server/trunk/src/test/org/apache/james/util/junkscore/ComposedJunkScoreTest.java
Mon Nov 13 04:35:50 2006
@@ -0,0 +1,99 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+
+
+package org.apache.james.util.junkscore;
+
+import junit.framework.TestCase;
+
+public class ComposedJunkScoreTest extends TestCase {
+
+ private final static String KEY1 = "KEY1";
+ private final static double SCORE1 = 20.0;
+ private final static String KEY2 = "KEY2";
+ private final static double SCORE2 = 2.0;
+
+ private JunkScore getJunkScore(String key, double score) {
+ JunkScore junk = new JunkScoreImpl();
+ if (key != null) {
+ junk.setStoredScore(key, score);
+ }
+ return junk;
+ }
+
+ public void testIllegalArguments() {
+ boolean exception1 = false;
+ boolean exception2 = false;
+ boolean exception3 = false;
+
+ try {
+ JunkScore junk = new ComposedJunkScore(null,null);
+ } catch (IllegalArgumentException e) {
+ exception1 = true;
+ }
+ assertTrue("Exception thrown", exception1);
+
+ try {
+ JunkScore junk = new ComposedJunkScore(null,getJunkScore(null,0));
+ } catch (IllegalArgumentException e) {
+ exception2 = true;
+ }
+ assertTrue("Exception thrown", exception2);
+
+ try {
+ JunkScore junk = new ComposedJunkScore(getJunkScore(null,0),null);
+ } catch (IllegalArgumentException e) {
+ exception3 = true;
+ }
+ assertTrue("Exception thrown", exception3);
+
+ }
+
+ public void testComposedJunkScore() {
+ JunkScore junk = new ComposedJunkScore(getJunkScore(KEY1, SCORE1),
getJunkScore(KEY2, SCORE2));
+
+ assertEquals("Summarize score", junk.getCompleteStoredScores(),SCORE1
+ SCORE2);
+
+ assertEquals("Get stored score", junk.getStoredScore(KEY1), SCORE1);
+ assertEquals("Get stored score", junk.getStoredScore(KEY2), SCORE2);
+
+ assertEquals("Get Map", junk.getStoredScores().size(), 2);
+
+ assertEquals("Reset Score", junk.resetStoredScores(), SCORE1 + SCORE2);
+
+ assertEquals("No Score", junk.getCompleteStoredScores(), 0.0);
+ assertEquals("Empty Map", junk.getStoredScores().size(), 0);
+
+ }
+
+ public void testUnsuportedOperation() {
+ boolean exception1 = false;
+
+ JunkScore junk = new ComposedJunkScore(getJunkScore(KEY1, SCORE1),
getJunkScore(KEY2, SCORE2));
+ try {
+ junk.setStoredScore(KEY1, SCORE1);
+ } catch (UnsupportedOperationException e) {
+ exception1 = true;
+ }
+
+ assertTrue("Unsupported operation", exception1);
+
+ }
+}
Propchange:
james/server/trunk/src/test/org/apache/james/util/junkscore/ComposedJunkScoreTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
james/server/trunk/src/test/org/apache/james/util/junkscore/JunkScoreConfigUtilTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/util/junkscore/JunkScoreConfigUtilTest.java?view=auto&rev=474281
==============================================================================
---
james/server/trunk/src/test/org/apache/james/util/junkscore/JunkScoreConfigUtilTest.java
(added)
+++
james/server/trunk/src/test/org/apache/james/util/junkscore/JunkScoreConfigUtilTest.java
Mon Nov 13 04:35:50 2006
@@ -0,0 +1,62 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+
+
+
+package org.apache.james.util.junkscore;
+
+import junit.framework.TestCase;
+
+public class JunkScoreConfigUtilTest extends TestCase {
+
+ private final static String INVALID_CONFIG1 = "junkscore: invalid";
+ private final static String INVALID_CONFIG2 = "junk: 21";
+ private final static String VALID_CONFIG = "junkscore: 21";
+
+ public void testgetJunkScoreConfig() {
+ boolean exception1 = false;
+ boolean exception2 = false;
+
+ try {
+ JunkScoreConfigUtil.getJunkScoreConfig(INVALID_CONFIG1);
+ } catch (IllegalArgumentException e) {
+ exception1 = true;
+ }
+
+ assertTrue("Exception thrown", exception1);
+
+ try {
+ JunkScoreConfigUtil.getJunkScoreConfig(INVALID_CONFIG2);
+ } catch (IllegalArgumentException e) {
+ exception2 = true;
+ }
+
+ assertTrue("Exception thrown", exception2);
+
+ assertEquals("JunkScore extracted",
JunkScoreConfigUtil.getJunkScoreConfig(VALID_CONFIG),21.0);
+
+ }
+
+ public void testIsValidJunkScoreConfig() {
+ assertFalse("Invalid Config",
JunkScoreConfigUtil.isValidJunkScoreConfig(INVALID_CONFIG1));
+ assertFalse("Invalid Config",
JunkScoreConfigUtil.isValidJunkScoreConfig(INVALID_CONFIG2));
+ assertTrue("Valid Config",
JunkScoreConfigUtil.isValidJunkScoreConfig(VALID_CONFIG));
+ }
+}
Propchange:
james/server/trunk/src/test/org/apache/james/util/junkscore/JunkScoreConfigUtilTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
james/server/trunk/src/test/org/apache/james/util/junkscore/JunkScoreImplTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/util/junkscore/JunkScoreImplTest.java?view=auto&rev=474281
==============================================================================
---
james/server/trunk/src/test/org/apache/james/util/junkscore/JunkScoreImplTest.java
(added)
+++
james/server/trunk/src/test/org/apache/james/util/junkscore/JunkScoreImplTest.java
Mon Nov 13 04:35:50 2006
@@ -0,0 +1,56 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ****************************************************************/
+
+
+
+package org.apache.james.util.junkscore;
+
+import junit.framework.TestCase;
+
+public class JunkScoreImplTest extends TestCase {
+
+ private final static String KEY1 = "KEY1";
+ private final static double SCORE1 = 20.0;
+ private final static String KEY2 = "KEY2";
+ private final static double SCORE2 = 2.0;
+
+ public void testJunkScoreImpl() {
+ JunkScore junk = new JunkScoreImpl();
+
+ assertEquals("Empty", junk.getCompleteStoredScores(),0.0);
+
+ assertEquals("No previous stored score", junk.setStoredScore(KEY1,
SCORE1), 0.0);
+ assertEquals("No previous stored score", junk.setStoredScore(KEY2,
SCORE1), 0.0);
+
+ assertEquals("Return the previous stored score",
junk.setStoredScore(KEY2, SCORE2), SCORE1);
+
+ assertEquals("Summarize score", junk.getCompleteStoredScores(), SCORE1
+ SCORE2);
+
+ assertEquals("Get stored score", junk.getStoredScore(KEY1), SCORE1);
+ assertEquals("Get stored score", junk.getStoredScore(KEY2), SCORE2);
+
+ assertEquals("Get Map", junk.getStoredScores().size(), 2);
+
+ assertEquals("Reset Score", junk.resetStoredScores(), SCORE1 + SCORE2);
+
+ assertEquals("No Score", junk.getCompleteStoredScores(), 0.0);
+ assertEquals("Empty Map", junk.getStoredScores().size(), 0);
+ }
+
+}
Propchange:
james/server/trunk/src/test/org/apache/james/util/junkscore/JunkScoreImplTest.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]