| <!DOCTYPE html> |
| <!--[if IE 8]> <html lang="en" class="ie8"> <![endif]--> |
| <!--[if IE 9]> <html lang="en" class="ie9"> <![endif]--> |
| <!--[if !IE]><!--> <html lang="en"> <!--<![endif]--> |
| <head> |
| <title>Meecrowave :: the customizable server</title> |
| <!-- Meta --> |
| <meta charset="utf-8"> |
| <meta http-equiv="X-UA-Compatible" content="IE=edge"> |
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> |
| <meta name="description" content=""> |
| <meta name="author" content=""> |
| <link rel="shortcut icon" href="/meecrowave/favicon.ico"> |
| <link href='http://fonts.googleapis.com/css?family=Open+Sans:300italic,400italic,600italic,700italic,800italic,400,300,600,700,800' rel='stylesheet' type='text/css'> |
| <!-- Global CSS --> |
| <link rel="stylesheet" href="/meecrowave/assets/plugins/bootstrap/css/bootstrap.min.css"> |
| <!-- Plugins CSS --> |
| <link rel="stylesheet" href="/meecrowave/assets/plugins/font-awesome/css/font-awesome.min.css"> |
| <link rel="stylesheet" href="/meecrowave/assets/plugins/elegant_font/css/style.css?version=1"> |
| <!-- highlighting --> |
| <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/styles/idea.min.css" integrity="sha256-rYB1c4yTU5UJB//rod7DtBo1JM6HAme/9Vd+VesFG2U=" crossorigin="anonymous" /> |
| |
| <!-- Theme CSS --> |
| <link id="theme-style" rel="stylesheet" href="/meecrowave/assets/css/styles.css"> |
| <!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries --> |
| <!--[if lt IE 9]> |
| <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script> |
| <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script> |
| <![endif]--> |
| </head> |
| |
| <body class="body-blue"> |
| <div class="page-wrapper"> |
| <!-- TODO: google analytics --> |
| <header class="header text-center"> |
| <div class="container"> |
| <div class="branding"> |
| <h1 class="doc-title"> |
| <span aria-hidden="true" class="icon icon_puzzle_alt icon"></span> |
| <a href="/meecrowave/index.html"> |
| Meecrowave |
| </a> |
| </h1> |
| </div> |
| </div><!--//container--> |
| </header><!--//header--> |
| <div class="doc-wrapper"> |
| <div class="container"> |
| <div id="doc-header" class="doc-header text-center"> |
| <h1 class="doc-title"><span aria-hidden="true" class="icon icon icon_puzzle_alt"></span> Meecrowave Testing</h1> |
| </div><!--//doc-header--> |
| |
| <div class="doc-body"> |
| <div class="doc-content"> |
| <div class="content-inner"> |
| |
| |
| |
| |
| <div class='btn-toolbar pull-right' style="z-index: 2000;"> |
| <div class='btn-group'> |
| <a class="btn" href="/meecrowave/testing/index.pdf"><i class="fa fa-file-pdf-o"></i> Download as PDF</a> |
| </div> |
| </div> |
| |
| |
| |
| <section class="doc-section"> |
| <div class="sect1"> |
| <h2 id="_junit">JUnit</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>Coordinates:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs"><dependency> |
| <groupId>org.apache.meecrowave</groupId> |
| <artifactId>meecrowave-junit</artifactId> |
| <version>${meecrowave.version}</version> |
| <scope>test</scope> |
| </dependency></code></pre> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="_rules_and_runners">Rules and Runners</h3> |
| <div class="paragraph"> |
| <p>Meecrowave provides two flavors of JUnit integration: standalone or runners/rules. The standalone one will |
| ensure there is a single container for the whole JVM. It also fits standalone environments where you want to control the lifecycle. |
| The other one will follow the JUnit lifecycle (per class or test rule).</p> |
| </div> |
| <div class="paragraph"> |
| <p>Here how to use the standalone flavor:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@RunWith(MonoMeecrowave.Runner.class) |
| public class MonoMeecrowaveRuleTest { |
| /* or |
| @ClassRule |
| public static final MonoMeecrowave.Rule RULE = new MonoMeecrowave.Rule(); |
| */ |
| |
| @MonoMeecrowave.Runner.ConfigurationInject |
| private Meecrowave.Builder config; |
| |
| @Test |
| public void test() throws IOException { |
| // use "http://localhost:" + config.getHttpPort() |
| } |
| }</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>When using the standalone, <code>@MonoMeecrowave.Runner.ConfigurationInject</code> allows to still |
| access the configuration and random HTTP port.</p> |
| </div> |
| <div class="paragraph"> |
| <p>For the configuration, the standalone runner will use a global configuration shared by all tests. To load it |
| it will use a standard <code>ServiceLoader</code> on type <code>org.apache.meecrowave.Meecrowave$ConfigurationCustomizer</code>.</p> |
| </div> |
| <div class="paragraph"> |
| <p>And here is the one bound to the JUnit lifecycle</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">public class MeecrowaveRuleTest { |
| @ClassRule // started once for the class, @Rule would be per method |
| public static final MeecrowaveRule RULE = new MeecrowaveRule(); |
| |
| @Test |
| public void test() throws IOException { |
| // use "http://localhost:" + RULE.getConfiguration().getHttpPort() |
| } |
| }</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>As usual with JUnit rules, you can decide whereas the Meecrowave instance is bound to the entire test class |
| or a method by using @ClassRule or @Rule.</p> |
| </div> |
| </div> |
| <div class="sect2"> |
| <h3 id="_junit_5">JUnit 5</h3> |
| <div class="paragraph"> |
| <p>JUnit 5 integrates a new <code>Extension</code> system. It is not yet very well supported by IDEs but you can already use it with |
| Gradle and Maven (see <a href="http://junit.org/junit5/docs/current/user-guide/#running-tests" class="bare">http://junit.org/junit5/docs/current/user-guide/#running-tests</a>).</p> |
| </div> |
| <div class="paragraph"> |
| <p>The usage has two annotations: <code>@MeecrowaveConfig</code> which remaps most of the configuration of Meecrowave and <code>@MonoMeecrowaveConfig</code> |
| which is close to <code>MonoMeecrowave.Runner</code> in term of usage.</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@MeecrowaveConfig /*(some config)*/ |
| @TestInstance(PER_CLASS) |
| public class MeecrowaveConfigTest { |
| @ConfigurationInject |
| private Meecrowave.Builder config; |
| |
| @Test |
| public void run() throws MalformedURLException { |
| final String base = "http://localhost:" + config.getHttpPort(); |
| // asserts |
| } |
| }</code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>Or</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code data-lang="java" class="language-java hljs">@MonoMeecrowaveConfig |
| public class MeecrowaveConfigTest { |
| // ... |
| }</code></pre> |
| </div> |
| </div> |
| <div class="admonitionblock tip"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-tip" title="Tip"></i> |
| </td> |
| <td class="content"> |
| JUnit 5 integration provides an <code>@AfterFirstInjection</code> method and <code>@AfterLastTest</code> |
| which can be used to setup/reset some environment using injections once for a set of test methods. |
| The methods must not have any parameter. |
| </td> |
| </tr> |
| </table> |
| </div> |
| <div class="admonitionblock important"> |
| <table> |
| <tr> |
| <td class="icon"> |
| <i class="fa icon-important" title="Important"></i> |
| </td> |
| <td class="content"> |
| when not using <code>@TestInstance(PER_CLASS)</code>, container is started per test method. Generally speaking you should try to align the scope of your container to the scope of validity of your beans. |
| For a library it is generally the class (so <code>@MeecrowaveConfig @TestInstance(PER_CLASS)</code>) and for an application the whole test set (so <code>@MonoMeecrowaveConfig</code>). |
| Note that using an <code>Extension</code> you can adjust mocks or spy beans dynamically without a container restart. |
| Having the longest life time for the container will make your test suite faster to execute. |
| </td> |
| </tr> |
| </table> |
| </div> |
| </div> |
| </div> |
| </div> |
| <div class="sect1"> |
| <h2 id="_arquillian_container">Arquillian Container</h2> |
| <div class="sectionbody"> |
| <div class="paragraph"> |
| <p>Container dependency:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs"><dependency> |
| <groupId>org.apache.meecrowave</groupId> |
| <artifactId>meecrowave-arquillian</artifactId> |
| <version>${meecrowave.version}</version> |
| <scope>test</scope> |
| </dependency></code></pre> |
| </div> |
| </div> |
| <div class="paragraph"> |
| <p>For the configuration check <a href="/meecrowave/meecrowave-core/configuration.html">Core configuration</a>.</p> |
| </div> |
| <div class="paragraph"> |
| <p>Here is a sample:</p> |
| </div> |
| <div class="listingblock"> |
| <div class="content"> |
| <pre class="highlightjs highlight"><code data-lang="xml" class="language-xml hljs"><?xml version="1.0" encoding="UTF-8"?> |
| <arquillian xmlns="http://jboss.org/schema/arquillian" |
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| xsi:schemaLocation="http://jboss.org/schema/arquillian http://jboss.org/schema/arquillian/arquillian_1_0.xsd"> |
| <container qualifier="meecrowave" default="true"> |
| <configuration> |
| <property name="antiResourceLocking">false</property> |
| <property name="arquillianProtocol">Servlet 3.1</property> |
| <property name="cdiConversation">false</property> |
| <property name="clientAuth"></property> |
| <property name="conf"></property> |
| <property name="cxfServletParams"> |
| hide-service-list-page=true |
| </property> |
| <property name="defaultSSLHostConfigName"></property> |
| <property name="deleteBaseOnStartup">true</property> |
| <property name="dir"></property> |
| <property name="host">localhost</property> |
| <property name="http2">false</property> |
| <property name="httpPort">-1</property> |
| <property name="httpsPort">8443</property> |
| <property name="initializeClientBus">true</property> |
| <property name="injectServletContainerInitializer">true</property> |
| <property name="jaxrsAutoActivateBeanValidation">true</property> |
| <property name="jaxrsDefaultProviders"></property> |
| <property name="jaxrsLogProviders">false</property> |
| <property name="jaxrsMapping">/*</property> |
| <property name="jaxrsProviderSetup">true</property> |
| <property name="jaxwsSupportIfAvailable">true</property> |
| <property name="jsonbBinaryStrategy"></property> |
| <property name="jsonbEncoding">UTF-8</property> |
| <property name="jsonbIJson">false</property> |
| <property name="jsonbNamingStrategy"></property> |
| <property name="jsonbNulls">false</property> |
| <property name="jsonbOrderStrategy"></property> |
| <property name="jsonbPrettify">false</property> |
| <property name="jsonpBufferStrategy">QUEUE</property> |
| <property name="jsonpMaxReadBufferLen">65536</property> |
| <property name="jsonpMaxStringLen">10485760</property> |
| <property name="jsonpMaxWriteBufferLen">65536</property> |
| <property name="jsonpPrettify">false</property> |
| <property name="jsonpSupportsComment">false</property> |
| <property name="keepServerXmlAsThis">false</property> |
| <property name="keyAlias"></property> |
| <property name="keystoreFile"></property> |
| <property name="keystorePass"></property> |
| <property name="keystoreType">JKS</property> |
| <property name="loggingGlobalSetup">true</property> |
| <property name="loginConfig">authMethod=BASIC;realmName=app</property> |
| <property name="meecrowaveProperties">meecrowave.properties</property> |
| <property name="properties"> |
| jpa.property.openjpa.RuntimeUnenhancedClasses=supported |
| jpa.property.openjpa.jdbc.SynchronizeMappings=buildSchema |
| </property> |
| <property name="quickSession">true</property> |
| <property name="realm">org.apache.catalina.realm.JAASRealm:configFile=jaas.config;appName=app</property> |
| <property name="roles"> |
| admin=admin |
| limited=admin,other |
| </property> |
| <property name="scanningExcludes"></property> |
| <property name="scanningIncludes"></property> |
| <property name="scanningPackageExcludes"></property> |
| <property name="scanningPackageIncludes"></property> |
| <property name="securityConstraints">collection=sc1:/api/*:POST;authRole=**|collection=sc2:/priv/*:GET;authRole=*</property> |
| <property name="serverXml"></property> |
| <property name="sharedLibraries"></property> |
| <property name="skipHttp">false</property> |
| <property name="ssl">false</property> |
| <property name="sslProtocol"></property> |
| <property name="stopPort">-1</property> |
| <property name="tempDir">/tmp/meecrowave_16133794495335</property> |
| <property name="tomcatAccessLogPattern"></property> |
| <property name="tomcatAutoSetup">true</property> |
| <property name="tomcatFilter"></property> |
| <property name="tomcatJspDevelopment">false</property> |
| <property name="tomcatNoJmx">true</property> |
| <property name="tomcatScanning">true</property> |
| <property name="tomcatWrapLoader">true</property> |
| <property name="useLog4j2JulLogManager">true</property> |
| <property name="useShutdownHook">false</property> |
| <property name="useTomcatDefaults">true</property> |
| <property name="users"> |
| admin=adminpwd |
| other=secret |
| </property> |
| <property name="webResourceCached">true</property> |
| <property name="webSessionCookieConfig"></property> |
| <property name="webSessionTimeout"></property> |
| <property name="webXml"></property> |
| </configuration> |
| </container> |
| </arquillian></code></pre> |
| </div> |
| </div> |
| </div> |
| </div> |
| </section><!--//doc-section--> |
| |
| |
| |
| |
| </div><!--//content-inner--> |
| </div><!--//doc-content--> |
| |
| <div class="doc-sidebar"> |
| <nav id="doc-nav"> |
| <ul id="doc-menu" class="nav doc-menu hidden-xs affix-top" data-spy="affix"> |
| <li><a href="/meecrowave/index.html">Home</a></li> |
| <li><a href="/meecrowave/start.html">Quick Start</a></li> |
| <li><a href="/meecrowave/components.html">Components</a></li> |
| <li><a href="/meecrowave/download.html">Download</a></li> |
| <li><a href="/meecrowave/community.html">Community</a></li> |
| </ul><!--//doc-menu--> |
| </nav> |
| </div> |
| </div> |
| |
| </div><!--//page-wrapper--> |
| |
| <footer class="footer text-center"> |
| <div class="container"> |
| <div class="row"> |
| <p >Copyright © 2016-2020 |
| <a href="http://www.apache.org/">The Apache Software Foundation</a>. All rights reserved. |
| </p> |
| </div> |
| </div> |
| |
| <div class="container"><!-- don't remove it otherwise theme is no more creative common --> |
| <small class="copyright">Designed with <i class="fa fa-heart"></i> by <a href="http://themes.3rdwavemedia.com/" target="_blank">Xiaoying Riley</a> for developers</small> |
| </div><!--//container--> |
| </footer><!--//footer--> |
| |
| |
| <!-- Main Javascript --> |
| <script type="text/javascript" src="/meecrowave/assets/plugins/jquery-1.12.3.min.js"></script> |
| <script type="text/javascript" src="/meecrowave/assets/plugins/bootstrap/js/bootstrap.min.js"></script> |
| <script type="text/javascript" src="/meecrowave/assets/plugins/jquery-match-height/jquery.matchHeight-min.js"></script> |
| <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/highlight.min.js" integrity="sha256-aYTdUrn6Ow1DDgh5JTc3aDGnnju48y/1c8s1dgkYPQ8=" crossorigin="anonymous"></script> |
| <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/languages/java.min.js" integrity="sha256-21Z1xKC/FsaqN9z9jIER9xiX4XbV5buFEVdkZvsfBIc=" crossorigin="anonymous"></script> |
| <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/languages/groovy.min.js" integrity="sha256-0B+Ps1zCncLC5JIOQ+MtIhI/UhbJkYbxWsJowD3c+tk=" crossorigin="anonymous"></script> |
| <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/languages/shell.min.js" integrity="sha256-nwOM3xEc6CFfrPNDN1upX+5ynjWKAXsg+bW63SSzte0=" crossorigin="anonymous"></script> |
| <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.15.6/languages/bash.min.js" integrity="sha256-zXrlim8wsIvcEFjsD3THiAfTvtPZifqx8q0rxegiWQc=" crossorigin="anonymous"></script> |
| <script type="text/javascript" src="/meecrowave/assets/js/main.js?version=1"></script> |
| |
| </body> |
| </html> |
| |
| |