Coverage Report - org.webslinger.modules.tests.TestStandardModuleState
 
Classes in this File Line Coverage Branch Coverage Complexity
TestStandardModuleState
100%
52/52
100%
1/1
1.143
 
 1  
 package org.webslinger.modules.tests;
 2  
 
 3  
 import org.webslinger.httpunit.WebslingerTestCase;
 4  
 
 5  
 import java.io.File;
 6  
 import java.io.IOException;
 7  
 
 8  
 import org.apache.commons.vfs.CacheStrategy;
 9  
 import org.apache.commons.vfs.FileObject;
 10  
 import org.apache.commons.vfs.Selectors;
 11  
 import org.apache.commons.vfs.impl.StandardFileSystemManager;
 12  
 
 13  
 import org.webslinger.containers.TestContainer;
 14  
 import org.webslinger.commons.vfs.VFSUtil;
 15  
 import org.webslinger.io.IOUtil;
 16  
 import org.webslinger.modules.StandardModuleState;
 17  
 
 18  
 public class TestStandardModuleState extends TestContainer.TestContainerTestCase {
 19  
     protected StandardFileSystemManager sfsm;
 20  
     protected FileObject root;
 21  
     protected FileObject modules;
 22  
     protected FileObject bases;
 23  
     protected FileObject real;
 24  
 
 25  
     public TestStandardModuleState(String name) {
 26  1
         super(name);
 27  1
     }
 28  
 
 29  
     protected void setUp() throws Exception {
 30  1
         super.setUp();
 31  1
         sfsm = new StandardFileSystemManager();
 32  1
         sfsm.setCacheStrategy(CacheStrategy.MANUAL);
 33  
         //sfsm.setCacheStrategy(CacheStrategy.ON_CALL);
 34  1
         sfsm.init();
 35  1
         sfsm.setBaseFile(new File(getTestLocation(), getName()));
 36  1
         root = sfsm.resolveFile(".");
 37  1
         root.delete(Selectors.SELECT_ALL);
 38  1
         modules = root.resolveFile("modules");
 39  1
         bases = root.resolveFile("bases");
 40  1
         real = root.resolveFile("real");
 41  
 
 42  1
         VFSUtil.setString(modules, "defaults/www/WEB-INF/web.xml", "<web-xml/>\n");
 43  1
         VFSUtil.setString(modules, "defaults/www/Theme/Default/Wrappers/Main.vm", "<body>#TemplateContent()</body>");
 44  1
         VFSUtil.setString(modules, "edit/www/Edit/index.jn", "return null;\n");
 45  1
         VFSUtil.setString(modules, "jquery.js", "\n");
 46  
 
 47  1
         VFSUtil.setString(real, "www/index.vm", "The front page.");
 48  1
         VFSUtil.setString(real, "www/Theme/Default/Wrappers/Main.vm", "#TemplateContent()");
 49  1
     }
 50  
 
 51  
     protected void tearDown() throws Exception {
 52  1
         root.delete(Selectors.SELECT_ALL);
 53  1
         super.tearDown();
 54  1
     }
 55  
 
 56  
     protected void checkRealFile(FileObject top, boolean inReal, String name) throws Exception {
 57  1
         assertTrue("view:" + name + " exists", top.resolveFile(name).exists());
 58  1
         assertTrue("real:" + name + " exists", real.resolveFile(name).exists());
 59  1
         assertEquals("content:" + name, VFSUtil.getString(top, name), VFSUtil.getString(real, name));
 60  1
     }
 61  
 
 62  
     protected void checkModuleFile(FileObject top, boolean inReal, String name, String path) throws Exception {
 63  3
         checkModuleFile(top, inReal, name, name + "/" + path, path);
 64  3
     }
 65  
 
 66  
     protected void checkModuleFile(FileObject top, boolean inReal, String name, String src, String dest) throws Exception {
 67  4
         assertTrue("view(" + name + "):" + dest + " does not exist", top.resolveFile(dest).exists());
 68  4
         if (inReal) {
 69  1
             assertTrue("real(" + name + "):" + dest + " does not exist", real.resolveFile(dest).exists());
 70  1
             assertEquals("content(" + name + "):" + dest, VFSUtil.getString(real, dest), VFSUtil.getString(top, dest));
 71  
         } else {
 72  3
             assertFalse("real(" + name + "):" + dest + " exists", real.resolveFile(dest).exists());
 73  3
             assertEquals("content(" + name + "):" + dest, VFSUtil.getString(modules, src), VFSUtil.getString(top, dest));
 74  
         }
 75  4
     }
 76  
 
 77  
     public void testStandardModuleState() throws Exception {
 78  1
         StandardModuleState sms = new StandardModuleState(real);
 79  
 
 80  1
         sms.addModule("defaults", modules.resolveFile("defaults").getURL().toString());
 81  1
         sms.addModule("edit", modules.resolveFile("edit").getURL().toString());
 82  1
         sms.addModule("jquery", modules.resolveFile("jquery.js").getURL().toString());
 83  1
         sms.addModuleMount("defaults", "", "");
 84  1
         sms.addModuleMount("edit", "", "");
 85  1
         sms.addModuleMount("jquery", "", "www/jscripts/jquery.js");
 86  1
         sms.enableModule("defaults");
 87  1
         sms.enableModule("edit");
 88  1
         sms.enableModule("jquery");
 89  
 
 90  1
         FileObject top = sms.getRoot();
 91  1
         checkModuleFile(top, false, "defaults", "www/WEB-INF/web.xml");
 92  1
         checkModuleFile(top, true, "defaults", "www/Theme/Default/Wrappers/Main.vm");
 93  1
         checkModuleFile(top, false, "edit", "www/Edit/index.jn");
 94  1
         checkModuleFile(top, false, "jquery", "jquery.js", "www/jscripts/jquery.js");
 95  1
         checkRealFile(top, true, "www/index.vm");
 96  1
     }
 97  
 }