{"id":1570,"date":"2012-07-06T22:00:00","date_gmt":"2012-07-06T22:00:00","guid":{"rendered":"http:\/\/www.javacodegeeks.com\/2012\/10\/tomcat-context-junit-rule.html"},"modified":"2012-10-22T06:08:03","modified_gmt":"2012-10-22T06:08:03","slug":"tomcat-context-junit-rule","status":"publish","type":"post","link":"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html","title":{"rendered":"Tomcat Context JUnit @Rule"},"content":{"rendered":"<div dir=\"ltr\" style=\"text-align: left\"><span style=\"background-color: white\">A first draft of a JUnit @Rule that create the test context. This can be used with the Spring context rule for <\/span><a href=\"http:\/\/www.blogger.com\/?q=content\/tutorial-junit-rule\">this post<\/a><span style=\"background-color: white\"> to create a complete Spring context for integration tests.<\/span><\/p>\n<pre class=\"brush:java\">import org.apache.commons.dbcp.BasicDataSource;\r\nimport org.apache.log4j.Logger;\r\nimport org.junit.rules.TestRule;\r\nimport org.junit.runner.Description;\r\nimport org.junit.runners.model.Statement;\r\nimport org.w3c.dom.Document;\r\nimport org.w3c.dom.Element;\r\nimport org.w3c.dom.NodeList;\r\n \r\nimport javax.naming.Context;\r\nimport javax.naming.InitialContext;\r\nimport javax.naming.NamingException;\r\nimport javax.sql.DataSource;\r\nimport javax.xml.parsers.DocumentBuilder;\r\nimport javax.xml.parsers.DocumentBuilderFactory;\r\nimport java.io.*;\r\nimport java.lang.reflect.Method;\r\nimport java.sql.Driver;\r\nimport java.sql.DriverManager;\r\n \r\n \r\n\/**\r\n * Creates an context for tests using an Apache Tomcat server.xml.\r\n *\r\n * https:\/\/blogs.oracle.com\/randystuph\/entry\/injecting_jndi_datasources_for_junit\r\n *\r\n * @author alex.collins\r\n *\/\r\npublic class TomcatContextRule implements TestRule {\r\n \r\n    public static final Logger LOGGER = Logger.getLogger(CatalinaContextRule.class);\r\n \r\n    \/**\r\n     * Creates all the sub-contexts for a name.\r\n     *\/\r\n    public static void createSubContexts(Context ctx, String name) {\r\n        String subContext = '';\r\n        for (String x : name.substring(0, name.lastIndexOf('\/')).split('\/')) {\r\n            subContext += x;\r\n            try {\r\n                ctx.createSubcontext(subContext);\r\n            } catch (NamingException e) {\r\n                \/\/ nop\r\n            }\r\n            subContext += '\/';\r\n        }\r\n    }\r\n \r\n    private final File serverXml;\r\n \r\n    public TomcatContextRule(File serverXml, Object target) {\r\n        if (serverXml == null || !serverXml.isFile()) {throw new IllegalArgumentException();}\r\n        if (target == null) {throw new IllegalArgumentException();}\r\n        this.serverXml = serverXml;\r\n    }\r\n \r\n    public Statement apply(final Statement statement, Description description) {\r\n        return new Statement() {\r\n            @Override\r\n            public void evaluate() throws Throwable {\r\n                createInitialContext();\r\n                try {\r\n                    statement.evaluate();\r\n                } finally {\r\n                    destroyInitialContext();\r\n                }\r\n            }\r\n        };\r\n    }\r\n \r\n    private void createInitialContext() throws Exception {\r\n \r\n        LOGGER.info('creating context');\r\n \r\n        System.setProperty(Context.INITIAL_CONTEXT_FACTORY, org.apache.naming.java.javaURLContextFactory.class.getName());\r\n        System.setProperty(Context.URL_PKG_PREFIXES, 'org.apache.naming');\r\n \r\n        final InitialContext ic = new InitialContext();\r\n \r\n        createSubContexts(ic, 'java:\/comp\/env');\r\n \r\n        final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();\r\n        final DocumentBuilder builder = factory.newDocumentBuilder();\r\n        final Document document = builder.parse(serverXml);\r\n \r\n        \/\/ create Environment\r\n        {\r\n            final NodeList envs = document.getElementsByTagName('Environment');\r\n            for (int i = 0; i &lt; envs.getLength(); i++) {\r\n                final Element env = (Element)envs.item(i); \/\/ must be Element\r\n                final String name = 'java:comp\/env\/' + env.getAttribute('name');\r\n                final Object instance = Class.forName(env.getAttribute('type')).getConstructor(String.class)\r\n                        .newInstance(env.getAttribute('value'));\r\n \r\n                LOGGER.info('binding ' + name + ' &lt;' + instance + '&gt;');\r\n \r\n                createSubContexts(ic, name);\r\n \r\n                ic.bind(name, instance);\r\n            }\r\n        }\r\n \r\n        \/\/ Resource\r\n        {\r\n            final NodeList resources = document.getElementsByTagName('Resource');\r\n            for (int i = 0; i &lt; resources.getLength(); i++) {\r\n                final Element resource = (Element)resources.item(i); \/\/ must be Element\r\n                final String name = 'java:comp\/env\/' + resource.getAttribute('name');\r\n                final Class&lt;?&gt; type = Class.forName(resource.getAttribute('type'));\r\n \r\n                final Object instance;\r\n                if (type.equals(DataSource.class)) {\r\n                    {\r\n                        @SuppressWarnings('unchecked') \/\/ this mus be driver?\r\n                        final Class&lt;? extends Driver&gt; driverClass = (Class&lt;? extends Driver&gt;) Class.forName(resource.getAttribute('driverClassName'));\r\n \r\n                        DriverManager.registerDriver(driverClass.newInstance());\r\n                    }\r\n \r\n                    final BasicDataSource dataSource = new BasicDataSource();\r\n                    \/\/ find all the bean attributes and set them use some reflection\r\n                    for (Method method : dataSource.getClass().getMethods()) {\r\n \r\n                        if (!method.getName().matches('^set.*')) {continue;}\r\n \r\n                        final String x = method.getName().substring(3, 4).toLowerCase() + method.getName().substring(4);\r\n \r\n                        if (!resource.hasAttribute(x)) {continue;}\r\n                        Class&lt;?&gt; y = method.getParameterTypes()[0]; \/\/ might be primitive\r\n \r\n                        if (y.isPrimitive()) {\r\n                            if (y.getName().equals('boolean')) y = Boolean.class;\r\n                            if (y.getName().equals('byte')) y = Byte.class;\r\n                            if (y.getName().equals('char')) y = Character.class;\r\n                            if (y.getName().equals('double')) y = Double.class;\r\n                            if (y.getName().equals('float')) y = Float.class;\r\n                            if (y.getName().equals('int')) y = Integer.class;\r\n                            if (y.getName().equals('long')) y = Long.class;\r\n                            if (y.getName().equals('short')) y = Short.class;\r\n                            if (y.getName().equals('void')) y = Void.class;\r\n                        }\r\n \r\n                        method.invoke(dataSource, y.getConstructor(String.class).newInstance(resource.getAttribute(x)));\r\n                    }\r\n \r\n                    instance = dataSource;\r\n                } else {\r\n                    \/\/ not supported, yet...\r\n                    throw new AssertionError('type ' + type + ' not supported');\r\n                }\r\n \r\n                LOGGER.info('binding ' + name + ' &lt;' + instance + '&gt;');\r\n \r\n                createSubContexts(ic, name);\r\n \r\n                ic.bind(name, instance);\r\n            }\r\n        }\r\n    }\r\n \r\n    private void destroyInitialContext() {\r\n        System.clearProperty(Context.INITIAL_CONTEXT_FACTORY);\r\n        System.clearProperty(Context.URL_PKG_PREFIXES);\r\n \r\n        LOGGER.info('context destroyed');\r\n    }\r\n \r\n}<\/pre>\n<p>For example:<div style=\"display:inline-block; margin: 15px 0;\"> <div id=\"adngin-JavaCodeGeeks_incontent_video-0\" style=\"display:inline-block;\"><\/div> <\/div><\/p>\n<pre class=\"brush:java\"> @Rule\r\n    public TestRule rules = RuleChain.outerRule(new CatalinaContextRule(new File(getClass().getResource('\/server.xml').getFile()), this))\r\n            .around(new ContextRule(new String[] {'\/applicationContext.xml'}, this));<\/pre>\n<p>This code is on <a href=\"https:\/\/github.com\/alexec\/test-support\">Github<\/a>.<\/p>\n<p><strong><i>Reference: <\/i><\/strong><a href=\"http:\/\/www.alexecollins.com\/?q=content\/tomcat-context-junit-rule\">Tomcat Context JUnit @Rule<\/a> from our <a href=\"http:\/\/www.javacodegeeks.com\/p\/jcg.html\">JCG partner<\/a> Alex Collins  at the <a href=\"http:\/\/www.alexecollins.com\/\">Alex Collins &#8216;s blog<\/a> blog.<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>A first draft of a JUnit @Rule that create the test context. This can be used with the Spring context rule for this post to create a complete Spring context for integration tests. import org.apache.commons.dbcp.BasicDataSource; import org.apache.log4j.Logger; import org.junit.rules.TestRule; import org.junit.runner.Description; import org.junit.runners.model.Statement; import org.w3c.dom.Document; import org.w3c.dom.Element; import org.w3c.dom.NodeList; import javax.naming.Context; import javax.naming.InitialContext; import javax.naming.NamingException; &hellip;<\/p>\n","protected":false},"author":202,"featured_media":176,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[32,274,273],"class_list":["post-1570","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-enterprise-java","tag-apache-tomcat","tag-junit","tag-testing"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Tomcat Context JUnit @Rule - Java Code Geeks<\/title>\n<meta name=\"description\" content=\"A first draft of a JUnit @Rule that create the test context. This can be used with the Spring context rule for this post to create a complete Spring\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Tomcat Context JUnit @Rule - Java Code Geeks\" \/>\n<meta property=\"og:description\" content=\"A first draft of a JUnit @Rule that create the test context. This can be used with the Spring context rule for this post to create a complete Spring\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html\" \/>\n<meta property=\"og:site_name\" content=\"Java Code Geeks\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/javacodegeeks\" \/>\n<meta property=\"article:published_time\" content=\"2012-07-06T22:00:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2012-10-22T06:08:03+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"150\" \/>\n\t<meta property=\"og:image:height\" content=\"150\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Alex Collins\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:site\" content=\"@javacodegeeks\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Alex Collins\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/07\\\/tomcat-context-junit-rule.html#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/07\\\/tomcat-context-junit-rule.html\"},\"author\":{\"name\":\"Alex Collins\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/d8297de25c5373886136a5d9bd8e3f02\"},\"headline\":\"Tomcat Context JUnit @Rule\",\"datePublished\":\"2012-07-06T22:00:00+00:00\",\"dateModified\":\"2012-10-22T06:08:03+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/07\\\/tomcat-context-junit-rule.html\"},\"wordCount\":62,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/07\\\/tomcat-context-junit-rule.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"keywords\":[\"Apache Tomcat\",\"JUnit\",\"Testing\"],\"articleSection\":[\"Enterprise Java\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/07\\\/tomcat-context-junit-rule.html#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/07\\\/tomcat-context-junit-rule.html\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/07\\\/tomcat-context-junit-rule.html\",\"name\":\"Tomcat Context JUnit @Rule - Java Code Geeks\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/07\\\/tomcat-context-junit-rule.html#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/07\\\/tomcat-context-junit-rule.html#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"datePublished\":\"2012-07-06T22:00:00+00:00\",\"dateModified\":\"2012-10-22T06:08:03+00:00\",\"description\":\"A first draft of a JUnit @Rule that create the test context. This can be used with the Spring context rule for this post to create a complete Spring\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/07\\\/tomcat-context-junit-rule.html#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/07\\\/tomcat-context-junit-rule.html\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/07\\\/tomcat-context-junit-rule.html#primaryimage\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2012\\\/10\\\/junit-logo-e1426444701180.jpg\",\"width\":150,\"height\":150},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/2012\\\/07\\\/tomcat-context-junit-rule.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"Enterprise Java\",\"item\":\"https:\\\/\\\/www.javacodegeeks.com\\\/category\\\/java\\\/enterprise-java\"},{\"@type\":\"ListItem\",\"position\":4,\"name\":\"Tomcat Context JUnit @Rule\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#website\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"name\":\"Java Code Geeks\",\"description\":\"Java Developers Resource Center\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\"},\"alternateName\":\"JCG\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.javacodegeeks.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#organization\",\"name\":\"Exelixis Media P.C.\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"contentUrl\":\"https:\\\/\\\/www.javacodegeeks.com\\\/wp-content\\\/uploads\\\/2022\\\/06\\\/exelixis-logo.png\",\"width\":864,\"height\":246,\"caption\":\"Exelixis Media P.C.\"},\"image\":{\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/javacodegeeks\",\"https:\\\/\\\/x.com\\\/javacodegeeks\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.javacodegeeks.com\\\/#\\\/schema\\\/person\\\/d8297de25c5373886136a5d9bd8e3f02\",\"name\":\"Alex Collins\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/51ce4c7aceacb45e0ca4ae9d90c010b8b72f7aeaca8bba26b7828d5cfe36622c?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/51ce4c7aceacb45e0ca4ae9d90c010b8b72f7aeaca8bba26b7828d5cfe36622c?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/51ce4c7aceacb45e0ca4ae9d90c010b8b72f7aeaca8bba26b7828d5cfe36622c?s=96&d=mm&r=g\",\"caption\":\"Alex Collins\"},\"sameAs\":[\"http:\\\/\\\/www.alexecollins.com\\\/\"],\"url\":\"https:\\\/\\\/www.javacodegeeks.com\\\/author\\\/Alex-Collins\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Tomcat Context JUnit @Rule - Java Code Geeks","description":"A first draft of a JUnit @Rule that create the test context. This can be used with the Spring context rule for this post to create a complete Spring","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html","og_locale":"en_US","og_type":"article","og_title":"Tomcat Context JUnit @Rule - Java Code Geeks","og_description":"A first draft of a JUnit @Rule that create the test context. This can be used with the Spring context rule for this post to create a complete Spring","og_url":"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html","og_site_name":"Java Code Geeks","article_publisher":"https:\/\/www.facebook.com\/javacodegeeks","article_published_time":"2012-07-06T22:00:00+00:00","article_modified_time":"2012-10-22T06:08:03+00:00","og_image":[{"width":150,"height":150,"url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","type":"image\/jpeg"}],"author":"Alex Collins","twitter_card":"summary_large_image","twitter_creator":"@javacodegeeks","twitter_site":"@javacodegeeks","twitter_misc":{"Written by":"Alex Collins","Est. reading time":"4 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html#article","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html"},"author":{"name":"Alex Collins","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/d8297de25c5373886136a5d9bd8e3f02"},"headline":"Tomcat Context JUnit @Rule","datePublished":"2012-07-06T22:00:00+00:00","dateModified":"2012-10-22T06:08:03+00:00","mainEntityOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html"},"wordCount":62,"commentCount":0,"publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","keywords":["Apache Tomcat","JUnit","Testing"],"articleSection":["Enterprise Java"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html","url":"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html","name":"Tomcat Context JUnit @Rule - Java Code Geeks","isPartOf":{"@id":"https:\/\/www.javacodegeeks.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html#primaryimage"},"image":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html#primaryimage"},"thumbnailUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","datePublished":"2012-07-06T22:00:00+00:00","dateModified":"2012-10-22T06:08:03+00:00","description":"A first draft of a JUnit @Rule that create the test context. This can be used with the Spring context rule for this post to create a complete Spring","breadcrumb":{"@id":"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html#primaryimage","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2012\/10\/junit-logo-e1426444701180.jpg","width":150,"height":150},{"@type":"BreadcrumbList","@id":"https:\/\/www.javacodegeeks.com\/2012\/07\/tomcat-context-junit-rule.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.javacodegeeks.com\/"},{"@type":"ListItem","position":2,"name":"Java","item":"https:\/\/www.javacodegeeks.com\/category\/java"},{"@type":"ListItem","position":3,"name":"Enterprise Java","item":"https:\/\/www.javacodegeeks.com\/category\/java\/enterprise-java"},{"@type":"ListItem","position":4,"name":"Tomcat Context JUnit @Rule"}]},{"@type":"WebSite","@id":"https:\/\/www.javacodegeeks.com\/#website","url":"https:\/\/www.javacodegeeks.com\/","name":"Java Code Geeks","description":"Java Developers Resource Center","publisher":{"@id":"https:\/\/www.javacodegeeks.com\/#organization"},"alternateName":"JCG","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.javacodegeeks.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.javacodegeeks.com\/#organization","name":"Exelixis Media P.C.","url":"https:\/\/www.javacodegeeks.com\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/","url":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","contentUrl":"https:\/\/www.javacodegeeks.com\/wp-content\/uploads\/2022\/06\/exelixis-logo.png","width":864,"height":246,"caption":"Exelixis Media P.C."},"image":{"@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/javacodegeeks","https:\/\/x.com\/javacodegeeks"]},{"@type":"Person","@id":"https:\/\/www.javacodegeeks.com\/#\/schema\/person\/d8297de25c5373886136a5d9bd8e3f02","name":"Alex Collins","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/51ce4c7aceacb45e0ca4ae9d90c010b8b72f7aeaca8bba26b7828d5cfe36622c?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/51ce4c7aceacb45e0ca4ae9d90c010b8b72f7aeaca8bba26b7828d5cfe36622c?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/51ce4c7aceacb45e0ca4ae9d90c010b8b72f7aeaca8bba26b7828d5cfe36622c?s=96&d=mm&r=g","caption":"Alex Collins"},"sameAs":["http:\/\/www.alexecollins.com\/"],"url":"https:\/\/www.javacodegeeks.com\/author\/Alex-Collins"}]}},"_links":{"self":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/1570","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/users\/202"}],"replies":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/comments?post=1570"}],"version-history":[{"count":0,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/posts\/1570\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media\/176"}],"wp:attachment":[{"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/media?parent=1570"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/categories?post=1570"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.javacodegeeks.com\/wp-json\/wp\/v2\/tags?post=1570"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}