1 package info.magnolia.cms.bean.config; 2 3 import info.magnolia.cms.beans.config.ConfigLoader; 4 import info.magnolia.cms.beans.config.ContentRepository; 5 import info.magnolia.cms.beans.config.Server; 6 import info.magnolia.cms.core.HierarchyManager; 7 import info.magnolia.cms.core.SystemProperty; 8 import info.magnolia.cms.security.AccessDeniedException; 9 import info.magnolia.test.MagnoliaTestUtils; 10 11 import java.util.HashMap ; 12 import java.util.Map ; 13 14 import javax.jcr.PathNotFoundException; 15 import javax.jcr.RepositoryException; 16 17 import junit.framework.TestCase; 18 19 import org.apache.commons.lang.StringUtils; 20 import org.slf4j.Logger; import org.slf4j.LoggerFactory; 21 22 import com.mockrunner.mock.web.MockServletContext; 23 24 25 29 public class BootstrapTest extends TestCase { 30 31 34 private static Logger log = LoggerFactory.getLogger(BootstrapTest.class); 35 36 40 public void testBootstrap() { 41 42 String testResourcesDir = MagnoliaTestUtils.getTestResourcesDir(); 43 String baseTestDir = testResourcesDir + "/bootstrap-test"; 44 45 MockServletContext context = new MockServletContext(); 46 47 Map config = new HashMap (); 48 context.setRealPath(StringUtils.EMPTY, baseTestDir); 49 50 config.put(SystemProperty.MAGNOLIA_REPOSITORIES_CONFIG, baseTestDir + "/WEB-INF/config/repositories.xml"); 51 52 config.put(SystemProperty.MAGNOLIA_BOOTSTRAP_ROOTDIR, MagnoliaTestUtils.getProjectRoot() 53 + "/src/webapp/WEB-INF/bootstrap"); 54 55 SystemProperty.setProperty(SystemProperty.MAGNOLIA_CACHE_STARTDIR, MagnoliaTestUtils.getProjectRoot() 57 + "/src/webapp/cache"); 58 59 new ConfigLoader(context, config); 60 61 HierarchyManager hm = ContentRepository.getHierarchyManager(ContentRepository.CONFIG); 62 assertNotNull("Config repository not properly configured.", hm); 63 64 try { 65 hm.getContent(Server.CONFIG_PAGE); 66 } 67 catch (AccessDeniedException e) { 68 fail("Access denied to [" + Server.CONFIG_PAGE + "]"); 69 } 70 catch (PathNotFoundException e) { 71 fail("Config repository not correctly initialized, missing [" + Server.CONFIG_PAGE + "]"); 72 } 73 catch (RepositoryException e) { 74 log.error(e.getMessage(), e); 75 fail("Exception caught: " + e.getMessage()); 76 } 77 78 hm = ContentRepository.getHierarchyManager(ContentRepository.WEBSITE); 79 assertNotNull("Website repository not properly configured.", hm); 80 81 try { 82 hm.getContent("features"); 83 } 84 catch (AccessDeniedException e) { 85 fail("Access denied to [features] page"); 86 } 87 catch (PathNotFoundException e) { 88 fail("Website repository not correctly initialized, missing [features] page"); 89 } 90 catch (RepositoryException e) { 91 log.error(e.getMessage(), e); 92 fail("Exception caught: " + e.getMessage()); 93 } 94 95 try { 96 hm.getContent("thispagedoesntexist"); 97 fail("Test doesn't get a PathNotFoundException while it should."); 98 } 99 catch (PathNotFoundException e) { 100 log.debug("PathNotFoundException caught as expected"); 102 } 103 catch (RepositoryException e) { 104 log.error(e.getMessage(), e); 105 fail("Exception caught: " + e.getMessage()); 106 } 107 108 } 109 } 110
| Popular Tags
|