Author: bfoster
Date: Mon Mar 26 22:49:10 2012
New Revision: 1305648

URL: http://svn.apache.org/viewvc?rev=1305648&view=rev
Log:
- CrawlerBeansPropHandler doesn't set list properties for Spring 
PropertyOverrideConfigurer correctly

------------
OODT-428

Added:
    oodt/trunk/crawler/src/test/org/apache/oodt/cas/crawl/cli/
    oodt/trunk/crawler/src/test/org/apache/oodt/cas/crawl/cli/option/
    oodt/trunk/crawler/src/test/org/apache/oodt/cas/crawl/cli/option/handler/
    
oodt/trunk/crawler/src/test/org/apache/oodt/cas/crawl/cli/option/handler/TestCrawlerBeansPropHandler.java
   (with props)
Modified:
    
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/cli/option/handler/CrawlerBeansPropHandler.java

Modified: 
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/cli/option/handler/CrawlerBeansPropHandler.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/cli/option/handler/CrawlerBeansPropHandler.java?rev=1305648&r1=1305647&r2=1305648&view=diff
==============================================================================
--- 
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/cli/option/handler/CrawlerBeansPropHandler.java
 (original)
+++ 
oodt/trunk/crawler/src/main/java/org/apache/oodt/cas/crawl/cli/option/handler/CrawlerBeansPropHandler.java
 Mon Mar 26 22:49:10 2012
@@ -19,9 +19,6 @@ package org.apache.oodt.cas.crawl.cli.op
 //JDK imports 
 import java.util.List;
 
-//Apache imports 
-import org.apache.commons.lang.StringUtils;
-
 //OODT imports 
 import org.apache.oodt.cas.cli.action.CmdLineAction;
 import org.apache.oodt.cas.cli.option.CmdLineOption;
@@ -50,8 +47,20 @@ public class CrawlerBeansPropHandler imp
    public void handleOption(CmdLineAction selectedAction,
          CmdLineOptionInstance optionInstance) {
       for (String beanProperty : properties) {
-         ActionBeanProperties.setProperty(beanProperty,
-               StringUtils.join(optionInstance.getValues().iterator(), ","));
+         if (optionInstance.getValues().size() > 1) {
+            for (int i = 0; i < optionInstance.getValues().size(); i++) {
+               ActionBeanProperties.setProperty(beanProperty + "[" + i + "]",
+                     optionInstance.getValues().get(i));
+            }
+         } else if (!optionInstance.getValues().isEmpty()) {
+            ActionBeanProperties.setProperty(beanProperty,
+                  optionInstance.getValues().get(0));
+         } else {
+            throw new RuntimeException(
+                  CrawlerBeansPropHandler.class.getCanonicalName()
+                        + " can't apply option '" + optionInstance.getOption()
+                        + "' since it has no value");
+         }
       }
    }
 

Added: 
oodt/trunk/crawler/src/test/org/apache/oodt/cas/crawl/cli/option/handler/TestCrawlerBeansPropHandler.java
URL: 
http://svn.apache.org/viewvc/oodt/trunk/crawler/src/test/org/apache/oodt/cas/crawl/cli/option/handler/TestCrawlerBeansPropHandler.java?rev=1305648&view=auto
==============================================================================
--- 
oodt/trunk/crawler/src/test/org/apache/oodt/cas/crawl/cli/option/handler/TestCrawlerBeansPropHandler.java
 (added)
+++ 
oodt/trunk/crawler/src/test/org/apache/oodt/cas/crawl/cli/option/handler/TestCrawlerBeansPropHandler.java
 Mon Mar 26 22:49:10 2012
@@ -0,0 +1,82 @@
+/*
+ * 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.oodt.cas.crawl.cli.option.handler;
+
+//OODT static imports
+import static 
org.apache.oodt.cas.crawl.util.ActionBeanProperties.getProperties;
+
+//JDK imports
+import java.util.Collections;
+
+//OODT imports
+import org.apache.oodt.cas.cli.option.AdvancedCmdLineOption;
+import org.apache.oodt.cas.cli.option.CmdLineOptionInstance;
+
+//Google imports
+import com.google.common.collect.Lists;
+
+//JUnit imports
+import junit.framework.TestCase;
+
+/**
+ * Test class for {@link CrawlerBeansPropHandler}.
+ *
+ * @author bfoster (Brian Foster)
+ */
+public class TestCrawlerBeansPropHandler extends TestCase {
+
+   public void testHandleOption() {
+      AdvancedCmdLineOption option = new AdvancedCmdLineOption();
+      option.setShortOption("t");
+      option.setLongOption("test");
+      option.setHasArgs(true);
+
+      // Test 1 value specified.
+      CmdLineOptionInstance instance = new CmdLineOptionInstance(
+            option, Lists.newArrayList("value"));
+      CrawlerBeansPropHandler handler = new CrawlerBeansPropHandler();
+      handler.initialize(option);
+      handler.setProperties(Lists.newArrayList("TestBean.prop"));
+      handler.handleOption(null, instance);
+      assertEquals(1, getProperties().size());
+      assertEquals("value", getProperties().getProperty("TestBean.prop"));
+      getProperties().clear();
+
+      // Test multiple values specified.
+      instance = new CmdLineOptionInstance(
+            option, Lists.newArrayList("value1", "value2"));
+      handler = new CrawlerBeansPropHandler();
+      handler.initialize(option);
+      handler.setProperties(Lists.newArrayList("TestBean.prop"));
+      handler.handleOption(null, instance);
+      assertEquals(2, getProperties().size());
+      assertEquals("value1", getProperties().getProperty("TestBean.prop[0]"));
+      assertEquals("value2", getProperties().getProperty("TestBean.prop[1]"));
+      getProperties().clear();
+
+      // Test no values specified.
+      try {
+         instance = new CmdLineOptionInstance(
+               option, Collections.<String>emptyList());
+         handler = new CrawlerBeansPropHandler();
+         handler.initialize(option);
+         handler.setProperties(Lists.newArrayList("TestBean.prop"));
+         handler.handleOption(null, instance);
+         fail("Should have thrown RuntimeException");
+      } catch (RuntimeException e) { /* expect throw */ }
+   }
+}

Propchange: 
oodt/trunk/crawler/src/test/org/apache/oodt/cas/crawl/cli/option/handler/TestCrawlerBeansPropHandler.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain


Reply via email to