[infinispan-commits] Infinispan SVN: r1917 - in trunk/core/src: test/java/org/infinispan/config/parsing and 1 other directory.

infinispan-commits at lists.jboss.org infinispan-commits at lists.jboss.org
Wed Jun 16 12:24:31 EDT 2010


Author: manik.surtani at jboss.com
Date: 2010-06-16 12:24:31 -0400 (Wed, 16 Jun 2010)
New Revision: 1917

Modified:
   trunk/core/src/main/java/org/infinispan/config/parsing/ConfigFilesConvertor.java
   trunk/core/src/test/java/org/infinispan/config/parsing/Coherence2InfinispanTransformerTest.java
   trunk/core/src/test/java/org/infinispan/config/parsing/EHCache2InfinispanTransformerTest.java
Log:
[ISPN-485] (Coherence migration pointing to wrong .xslt file) Fixed bug, refactored converter, improved tests

Modified: trunk/core/src/main/java/org/infinispan/config/parsing/ConfigFilesConvertor.java
===================================================================
--- trunk/core/src/main/java/org/infinispan/config/parsing/ConfigFilesConvertor.java	2010-06-16 12:29:39 UTC (rev 1916)
+++ trunk/core/src/main/java/org/infinispan/config/parsing/ConfigFilesConvertor.java	2010-06-16 16:24:31 UTC (rev 1917)
@@ -44,8 +44,16 @@
 import java.io.InputStream;
 import java.io.OutputStream;
 import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.LinkedList;
 import java.util.List;
+import java.util.Map;
+import java.util.Set;
 
+import static java.util.Collections.sort;
+
 /**
  * Class used for converting different configuration files to INFINISPAN format.
  *
@@ -57,8 +65,15 @@
    static final String JBOSS_CACHE3X = "JBossCache3x";
    static final String EHCACHE_CACHE1X = "Ehcache1x";
    static final String COHERENCE_35X = "Coherence35x";
-   static final String[] SUPPORTED_FORMATS = {JBOSS_CACHE3X, EHCACHE_CACHE1X, COHERENCE_35X};
 
+   static final Map<String, String> TRANSFORMATIONS = new HashMap<String, String>(4);
+
+   static {
+      TRANSFORMATIONS.put(JBOSS_CACHE3X, "xslt/jbc3x2infinispan4.xslt");
+      TRANSFORMATIONS.put(EHCACHE_CACHE1X, "xslt/ehcache1x2infinispan4x.xslt");
+      TRANSFORMATIONS.put(COHERENCE_35X, "xslt/coherence35x2infinispan4x.xslt");
+   }
+
    public void parse(InputStream is, OutputStream os, String xsltFile) throws Exception {
       InputStream xsltInStream = new FileLookup().lookupFile(xsltFile);
       if (xsltInStream == null) {
@@ -101,7 +116,7 @@
 
    private static void help() {
       System.out.println("Usage:");
-      System.out.println("importConfig [-source <the file to be transformed>] [-destination <where to store resulting XML>] [-type <the type of the source, possible values being: " + Arrays.asList(SUPPORTED_FORMATS) + " >]");
+      System.out.println("importConfig [-source <the file to be transformed>] [-destination <where to store resulting XML>] [-type <the type of the source, possible values being: " + getSupportedFormats() + " >]");
    }
 
 
@@ -131,17 +146,14 @@
       mustExist(destinationName, "destination");
       mustExist(type, "type");
 
-      List<String> stringList = Arrays.asList(SUPPORTED_FORMATS);
-      if (!stringList.contains(type)) {
-         System.err.println("Unsupported transformation type: " + type + ". Supported formats are: " + stringList);
+      if (!TRANSFORMATIONS.containsKey(type)) {
+         System.err.println("Unsupported transformation type: " + type + ". Supported formats are: " + getSupportedFormats());
       }
 
       if (type.equals(JBOSS_CACHE3X)) {
          transformFromJbossCache3x(sourceName, destinationName);
-      } else if (type.equals(EHCACHE_CACHE1X)) {
-         transformFromEhcache1x(sourceName, destinationName);
-      } else if (type.equals(COHERENCE_35X)) {
-         transformFromCoherence35x(sourceName, destinationName);
+      } else {
+         transformFromNonJBoss(sourceName, destinationName, TRANSFORMATIONS.get(type));
       }
 
       System.out.println("---");
@@ -149,7 +161,13 @@
       System.out.println("---");
    }
 
-   private static void transformFromCoherence35x(String sourceName, String destinationName) throws Exception {
+   private static String getSupportedFormats() {
+      List<String> supported = new LinkedList<String>(TRANSFORMATIONS.keySet());
+      sort(supported);
+      return supported.toString();
+   }
+
+   private static void transformFromNonJBoss(String sourceName, String destinationName, String xslt) throws Exception {
       File oldConfig = new File(sourceName);
       if (!oldConfig.exists()) {
          System.err.println("File specified as input ('" + sourceName + ") does not exist.");
@@ -170,14 +188,13 @@
          }
 
          fos = new FileOutputStream(destinationName);
-         convertor.parse(is, fos, "xslt/ehcache1x2infinispan4x.xslt");
+         convertor.parse(is, fos, xslt);
       } finally {
          Util.flushAndCloseStream(fos);
          Util.close(is);
       }
    }
 
-
    private static void mustExist(String sourceName, String what) {
       if (sourceName == null) {
          System.err.println("Missing '" + what + "', cannot proceed");
@@ -232,34 +249,6 @@
       }
    }
 
-   private static void transformFromEhcache1x(String sourceName, String destinationName) throws Exception {
-      File oldConfig = new File(sourceName);
-      if (!oldConfig.exists()) {
-         System.err.println("File specified as input ('" + sourceName + ") does not exist.");
-         System.exit(1);
-      }
-      ConfigFilesConvertor converter = new ConfigFilesConvertor();
-      FileInputStream is = null;
-      FileOutputStream fos = null;
-
-      try {
-
-         is = new FileInputStream(oldConfig);
-         File destination = new File(destinationName);
-         if (!destination.exists()) {
-            if (!destination.createNewFile()) {
-               System.err.println("Warn! Could not create file " + destination);
-            }
-         }
-
-         fos = new FileOutputStream(destinationName);
-         converter.parse(is, fos, "xslt/ehcache1x2infinispan4x.xslt");
-      } finally {
-         Util.flushAndCloseStream(fos);
-         Util.close(is);
-      }
-   }
-
    private Transformer getTransformer(InputStream xsltInStream) throws TransformerConfigurationException {
       TransformerFactory tFactory = TransformerFactory.newInstance();
       StreamSource stylesource = new StreamSource(xsltInStream);

Modified: trunk/core/src/test/java/org/infinispan/config/parsing/Coherence2InfinispanTransformerTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/config/parsing/Coherence2InfinispanTransformerTest.java	2010-06-16 12:29:39 UTC (rev 1916)
+++ trunk/core/src/test/java/org/infinispan/config/parsing/Coherence2InfinispanTransformerTest.java	2010-06-16 16:24:31 UTC (rev 1917)
@@ -19,7 +19,6 @@
 @Test(groups = "functional", testName = "config.parsing.Coherence2InfinispanTransformerTest", enabled = false)
 public class Coherence2InfinispanTransformerTest extends AbstractInfinispanTest {
 
-   public static final String XSLT_FILE = "xslt/coherence35x2infinispan4x.xslt";
    private static final String BASE_DIR = "configs/coherence";
 
 
@@ -41,7 +40,7 @@
          Thread.currentThread().setContextClassLoader(delegatingCl);
          String fileName = getFileName(coherenceFileName);
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
-         convertor.parse(fileName, baos, XSLT_FILE);
+         convertor.parse(fileName, baos, ConfigFilesConvertor.TRANSFORMATIONS.get(ConfigFilesConvertor.COHERENCE_35X));
          dcm = TestCacheManagerFactory.fromStream(new ByteArrayInputStream(baos.toByteArray()), true);
          Cache<Object,Object> defaultCache = dcm.getCache();
          defaultCache.put("key", "value");

Modified: trunk/core/src/test/java/org/infinispan/config/parsing/EHCache2InfinispanTransformerTest.java
===================================================================
--- trunk/core/src/test/java/org/infinispan/config/parsing/EHCache2InfinispanTransformerTest.java	2010-06-16 12:29:39 UTC (rev 1916)
+++ trunk/core/src/test/java/org/infinispan/config/parsing/EHCache2InfinispanTransformerTest.java	2010-06-16 16:24:31 UTC (rev 1917)
@@ -24,7 +24,6 @@
 @Test(groups = "functional", testName = "config.parsing.EHCache2InfinispanTransformerTest")
 public class EHCache2InfinispanTransformerTest extends AbstractInfinispanTest {
 
-   public static final String XSLT_FILE = "xslt/ehcache1x2infinispan4x.xslt";
    private static final String BASE_DIR = "configs/ehcache";
    ConfigFilesConvertor convertor = new ConfigFilesConvertor();
 
@@ -49,7 +48,7 @@
          currentThread().setContextClassLoader(delegatingCl);
          String fileName = getFileName(ehCacheFile);
          ByteArrayOutputStream baos = new ByteArrayOutputStream();
-         convertor.parse(fileName, baos, XSLT_FILE);
+         convertor.parse(fileName, baos, ConfigFilesConvertor.TRANSFORMATIONS.get(ConfigFilesConvertor.EHCACHE_CACHE1X));
          dcm = (DefaultCacheManager) TestCacheManagerFactory.fromStream(new ByteArrayInputStream(baos.toByteArray()), true);
          Cache<Object,Object> defaultCache = dcm.getCache();
          defaultCache.put("key", "value");



More information about the infinispan-commits mailing list