// Path: h2hell-core/src/main/java/com/highway2urhell/transformer/Struts1Transformer.java
// public class Struts1Transformer extends AbstractLeechTransformer {
// 
//     public Struts1Transformer() {
//         super("org/apache/struts/action/ActionServlet");
//         addImportPackage(collectPackages());
//     }
// 
//     public static String[] collectPackages() {
//         return new String[]{
//                 "com.highway2urhell",
//                 "com.highway2urhell.domain",
//                 "java.lang.reflect",
//                 "java.util",
//                 "org.apache.commons.digester",
//                 "org.apache.struts.action",
//                 "org.apache.struts.config.impl"
//         };
//     }
// 
//     @Override
//     protected void doTransform(CtClass cc) throws Exception {
//         CtMethod m = cc.getMethod("destroyConfigDigester", "()V");
//         m.insertBefore(collectBody());
//     }
// 
//     public static String collectBody() {
//         return "{\n" +
//                 "    ModuleConfigImpl m = (ModuleConfigImpl) configDigester.getRoot();\n" +
//                 "    Field f;\n" +
//                 "    List listEntryPath = new ArrayList();\n" +
//                 "    try {\n" +
//                 "        f = m.getClass().getDeclaredField(\"actionConfigList\");\n" +
//                 "        f.setAccessible(true);\n" +
//                 "        List res = (ArrayList) f.get(m);\n" +
//                 "        if (res != null) {\n" +
//                 "            Iterator iter = res.iterator();\n" +
//                 "            while (iter.hasNext()) {\n" +
//                 "                ActionMapping action = (ActionMapping) iter.next();\n" +
//                 "                if (action.getType() != null && !\"\".equals(action.getType())) {\n" +
//                 "                    try {\n" +
//                 "                        Class c = Class.forName(action.getType());\n" +
//                 "                        Method[] tabMet = c.getDeclaredMethods();\n" +
//                 "                        for (int i = 0; i < tabMet.length; i++) {\n" +
//                 "                            EntryPathData entry = new EntryPathData();\n" +
//                 "                            entry.setClassName(action.getType());\n" +
//                 "                            entry.setMethodName(tabMet[i].getName());\n" +
//                 "                            if (action.getPrefix() != null && !\"null\".equals(action.getPrefix())) {\n" +
//                 "                                entry.setUri(action.getPrefix() + action.getPath());\n" +
//                 "                            } else {\n" +
//                 "                                entry.setUri(action.getPath());\n" +
//                 "                            }\n" +
//                 "                            entry.setTypePath(TypePath.DYNAMIC);\n" +
//                 "                            List listEntryPathData = new ArrayList();\n" +
//                 "                            for (int j = 0; j < tabMet[i].getParameterTypes().length; j++) {\n" +
//                 "                                EntryPathParam param = new EntryPathParam();\n" +
//                 "                                param.setKey(\"\");\n" +
//                 "                                param.setTypeParam(TypeParam.PARAM_DATA);\n" +
//                 "                                param.setValue(tabMet[i].getParameterTypes()[j].getName());\n" +
//                 "                                listEntryPathData.add(param);\n" +
//                 "                            }\n" +
//                 "                            entry.setListEntryPathData(listEntryPathData);\n" +
//                 "                            entry.setSignatureName(org.objectweb.asm.Type.getMethodDescriptor(tabMet[i]));\n" +
//                 "                            listEntryPath.add(entry);\n" +
//                 "                        }\n" +
//                 "                    } catch (ClassNotFoundException e) {\n" +
//                 "                        e.printStackTrace();\n" +
//                 "                    }\n" +
//                 "                }\n" +
//                 "            }\n" +
//                 "        }\n" +
//                 "    } catch (Exception e) {\n" +
//                 "        e.printStackTrace();\n" +
//                 "    }\n" +
//                 "    CoreEngine.getInstance().getFramework(\"STRUTS_1\").receiveData(listEntryPath);\n" +
//                 "}";
//     }
// }
// 
// Path: h2hell-core/src/test/java/com/highway2urhell/utils/ParsingUtil.java
// public static String extractBody(String in, String methodName) throws ParseException, FileNotFoundException {
//     return extractMethod(JavaParser.parse(new FileInputStream(in)), methodName);
// }
// 
// Path: h2hell-core/src/test/java/com/highway2urhell/utils/ParsingUtil.java
// public static String[] extractPackages(String in) throws ParseException, FileNotFoundException {
//     List<String> classes = extractImports(in);
//     Set<String> ret = new TreeSet<String>();
//     for (String aClass : classes) {
//         ret.add(aClass.substring(0, aClass.lastIndexOf(".")));
//     }
// 
//     return ret.toArray(new String[]{});
// }


import com.github.javaparser.ParseException;
import com.highway2urhell.transformer.Struts1Transformer;
import org.junit.Test;
import java.io.FileNotFoundException;
import static com.highway2urhell.utils.ParsingUtil.extractBody;
import static com.highway2urhell.utils.ParsingUtil.extractPackages;
import static org.fest.assertions.Assertions.assertThat;
package com.highway2urhell.collector;




public class Struts1CollectorTest {
    @Test
    public void checkScript() throws FileNotFoundException, ParseException {
        assertThat(Struts1Transformer.collectBody())
                .isEqualTo(extractBody("./src/test/java/com/highway2urhell/collector/Struts1Collector.java", "collectBody"));
        assertThat(Struts1Transformer.collectPackages())
// Path: h2hell-core/src/main/java/com/highway2urhell/transformer/Struts1Transformer.java
// public class Struts1Transformer extends AbstractLeechTransformer {
// 
//     public Struts1Transformer() {
//         super("org/apache/struts/action/ActionServlet");
//         addImportPackage(collectPackages());
//     }
// 
//     public static String[] collectPackages() {
//         return new String[]{
//                 "com.highway2urhell",
//                 "com.highway2urhell.domain",
//                 "java.lang.reflect",
//                 "java.util",
//                 "org.apache.commons.digester",
//                 "org.apache.struts.action",
//                 "org.apache.struts.config.impl"
//         };
//     }
// 
//     @Override
//     protected void doTransform(CtClass cc) throws Exception {
//         CtMethod m = cc.getMethod("destroyConfigDigester", "()V");
//         m.insertBefore(collectBody());
//     }
// 
//     public static String collectBody() {
//         return "{\n" +
//                 "    ModuleConfigImpl m = (ModuleConfigImpl) configDigester.getRoot();\n" +
//                 "    Field f;\n" +
//                 "    List listEntryPath = new ArrayList();\n" +
//                 "    try {\n" +
//                 "        f = m.getClass().getDeclaredField(\"actionConfigList\");\n" +
//                 "        f.setAccessible(true);\n" +
//                 "        List res = (ArrayList) f.get(m);\n" +
//                 "        if (res != null) {\n" +
//                 "            Iterator iter = res.iterator();\n" +
//                 "            while (iter.hasNext()) {\n" +
//                 "                ActionMapping action = (ActionMapping) iter.next();\n" +
//                 "                if (action.getType() != null && !\"\".equals(action.getType())) {\n" +
//                 "                    try {\n" +
//                 "                        Class c = Class.forName(action.getType());\n" +
//                 "                        Method[] tabMet = c.getDeclaredMethods();\n" +
//                 "                        for (int i = 0; i < tabMet.length; i++) {\n" +
//                 "                            EntryPathData entry = new EntryPathData();\n" +
//                 "                            entry.setClassName(action.getType());\n" +
//                 "                            entry.setMethodName(tabMet[i].getName());\n" +
//                 "                            if (action.getPrefix() != null && !\"null\".equals(action.getPrefix())) {\n" +
//                 "                                entry.setUri(action.getPrefix() + action.getPath());\n" +
//                 "                            } else {\n" +
//                 "                                entry.setUri(action.getPath());\n" +
//                 "                            }\n" +
//                 "                            entry.setTypePath(TypePath.DYNAMIC);\n" +
//                 "                            List listEntryPathData = new ArrayList();\n" +
//                 "                            for (int j = 0; j < tabMet[i].getParameterTypes().length; j++) {\n" +
//                 "                                EntryPathParam param = new EntryPathParam();\n" +
//                 "                                param.setKey(\"\");\n" +
//                 "                                param.setTypeParam(TypeParam.PARAM_DATA);\n" +
//                 "                                param.setValue(tabMet[i].getParameterTypes()[j].getName());\n" +
//                 "                                listEntryPathData.add(param);\n" +
//                 "                            }\n" +
//                 "                            entry.setListEntryPathData(listEntryPathData);\n" +
//                 "                            entry.setSignatureName(org.objectweb.asm.Type.getMethodDescriptor(tabMet[i]));\n" +
//                 "                            listEntryPath.add(entry);\n" +
//                 "                        }\n" +
//                 "                    } catch (ClassNotFoundException e) {\n" +
//                 "                        e.printStackTrace();\n" +
//                 "                    }\n" +
//                 "                }\n" +
//                 "            }\n" +
//                 "        }\n" +
//                 "    } catch (Exception e) {\n" +
//                 "        e.printStackTrace();\n" +
//                 "    }\n" +
//                 "    CoreEngine.getInstance().getFramework(\"STRUTS_1\").receiveData(listEntryPath);\n" +
//                 "}";
//     }
// }
// 
// Path: h2hell-core/src/test/java/com/highway2urhell/utils/ParsingUtil.java
// public static String extractBody(String in, String methodName) throws ParseException, FileNotFoundException {
//     return extractMethod(JavaParser.parse(new FileInputStream(in)), methodName);
// }
// 
// Path: h2hell-core/src/test/java/com/highway2urhell/utils/ParsingUtil.java
// public static String[] extractPackages(String in) throws ParseException, FileNotFoundException {
//     List<String> classes = extractImports(in);
//     Set<String> ret = new TreeSet<String>();
//     for (String aClass : classes) {
//         ret.add(aClass.substring(0, aClass.lastIndexOf(".")));
//     }
// 
//     return ret.toArray(new String[]{});
// }


// Path: h2hell-core/src/test/java/com/highway2urhell/collector/Struts1CollectorTest.java
import com.github.javaparser.ParseException;
import com.highway2urhell.transformer.Struts1Transformer;
import org.junit.Test;
import java.io.FileNotFoundException;
import static com.highway2urhell.utils.ParsingUtil.extractBody;
import static com.highway2urhell.utils.ParsingUtil.extractPackages;
import static org.fest.assertions.Assertions.assertThat;

package com.highway2urhell.collector;




public class Struts1CollectorTest {
    @Test
    public void checkScript() throws FileNotFoundException, ParseException {
        assertThat(Struts1Transformer.collectBody())
                .isEqualTo(extractBody("./src/test/java/com/highway2urhell/collector/Struts1Collector.java", "collectBody"));
        assertThat(Struts1Transformer.collectPackages())
                .isEqualTo(extractPackages("./src/test/java/com/highway2urhell/collector/Struts1Collector.java"));