AMQCLI-3 - tests and cleanup
diff --git a/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/Exporter.java b/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/Exporter.java
index 5a9c9d6..9d7ba93 100644
--- a/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/Exporter.java
+++ b/activemq-kahadb-exporter/src/main/java/org/apache/activemq/cli/kahadb/exporter/Exporter.java
@@ -79,7 +79,7 @@
         @Option(name = {"--qp", "--queuePattern"}, type = OptionType.COMMAND, description = "Queue Export Pattern")
         public String queuePattern;
 
-        @Option(name = {"--tp", "--queuePattern"}, type = OptionType.COMMAND, description = "Topic Export Pattern")
+        @Option(name = {"--tp", "--topicPattern"}, type = OptionType.COMMAND, description = "Topic Export Pattern")
         public String topicPattern;
 
         @Option(name = "-c", type = OptionType.COMMAND, description = "Compress output xml file using gzip")
@@ -93,7 +93,7 @@
          */
         @Override
         public void run() {
-            LOG.info("Starting store export");
+            LOG.info("Starting KahaDB store export");
             try {
                 Exporter.exportStore(ExportConfigurationBuilder.newBuilder()
                         .setSource(new File(source))
@@ -101,9 +101,11 @@
                         .setQueuePattern(queuePattern)
                         .setTopicPattern(topicPattern)
                         .setCompress(compress)
+                        .setOverwrite(overwrite)
                         .build());
             } catch (Exception e) {
                 LOG.error(e.getMessage(), e);
+                throw new IllegalStateException(e.getMessage(), e);
             }
 
         }
@@ -118,7 +120,7 @@
          */
         @Override
         public void run() {
-            LOG.info("Exporting");
+            LOG.info("Starting MultiKahaDB store export");
             try {
                 Exporter.exportStore(ExportConfigurationBuilder.newBuilder()
                         .setMultiKaha(true)
@@ -127,9 +129,11 @@
                         .setQueuePattern(queuePattern)
                         .setTopicPattern(topicPattern)
                         .setCompress(compress)
+                        .setOverwrite(overwrite)
                         .build());
             } catch (Exception e) {
                 LOG.error(e.getMessage(), e);
+                throw new IllegalStateException(e.getMessage(), e);
             }
 
         }
@@ -137,7 +141,7 @@
 
     public static void exportStore(final ExportConfiguration config) throws Exception {
 
-        if (config.getTarget().exists()) {
+        if (!config.isOverwrite() && config.getTarget().exists()) {
             throw new IllegalStateException("File: " + config.getTarget() + " already exists");
         }
 
diff --git a/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterCLITest.java b/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterCLITest.java
new file mode 100644
index 0000000..1200c0c
--- /dev/null
+++ b/activemq-kahadb-exporter/src/test/java/org/apache/activemq/cli/kahadb/exporter/ExporterCLITest.java
@@ -0,0 +1,79 @@
+/**
+ * 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.activemq.cli.kahadb.exporter;
+
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.rules.TemporaryFolder;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.junit.runners.Parameterized.Parameters;
+
+import io.airlift.airline.ParseOptionMissingException;
+
+@RunWith(Parameterized.class)
+public class ExporterCLITest {
+
+    @Rule
+    public TemporaryFolder temp = new TemporaryFolder();
+    private String type;
+
+    @Parameters(name = "type={0}")
+    public static Collection<Object[]> data() {
+        return Arrays.asList(new Object[][] {
+                {"kahadb"},
+                {"mkahadb"}
+        });
+    }
+
+    public ExporterCLITest(String type) {
+        super();
+        this.type = type;
+    }
+
+    @Test(expected = ParseOptionMissingException.class)
+    public void testMissingsArgs() {
+        Exporter.main(new String[]{type});
+    }
+
+    @Test(expected = ParseOptionMissingException.class)
+    public void testMissingTarget() {
+        Exporter.main(new String[]{type, "-s", "file"});
+    }
+
+    @Test(expected = ParseOptionMissingException.class)
+    public void testMissingSource() {
+        Exporter.main(new String[]{type, "-t", "file"});
+    }
+
+    @Test(expected = IllegalStateException.class)
+    public void testFileExists() throws IOException {
+        Exporter.main(new String[]{type, "-s", temp.newFolder().getAbsolutePath(),
+                "-t", temp.newFile().getAbsolutePath()});
+    }
+
+    @Test
+    public void testFileOverwrite() throws IOException {
+        Exporter.main(new String[]{type, "-s", temp.newFolder().getAbsolutePath(),
+                "-t", temp.newFile().getAbsolutePath(), "-f"});
+        //should be no exceptions
+    }
+}
diff --git a/pom.xml b/pom.xml
index 651d6a3..183a172 100644
--- a/pom.xml
+++ b/pom.xml
@@ -167,6 +167,7 @@
 
   <modules>
     <module>activemq-kahadb-exporter</module>
+    <module>assembly</module>
   </modules>
 
   <profiles>