Skip to content

Commit dc95e49

Browse files
committed
[SPR-8240][SPR-8401] formatting and polishing.
1 parent 027c25d commit dc95e49

File tree

1 file changed

+57
-40
lines changed

1 file changed

+57
-40
lines changed

spring-framework-reference/src/testing.xml

Lines changed: 57 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,7 +1283,7 @@ public class OrderServiceTest {
12831283
production configuration you will define either a set of XML
12841284
resource locations or a set of
12851285
<interfacename>@Configuration</interfacename> classes that your
1286-
production <interfacename>ApplicationContext</interfacename> will
1286+
production <interfacename>ApplicationContext</interfacename> will be
12871287
loaded from, but you still have the freedom to include or import the
12881288
other type of configuration.</para>
12891289
</section>
@@ -1362,22 +1362,26 @@ public class ExtendedTest extends BaseTest {
13621362
<title>Context configuration with environment profiles</title>
13631363

13641364
<para>Spring 3.1 introduces first-class support in the framework for
1365-
the notion of environments and profiles (a.k.a., bean definition
1366-
profiles), and integration tests can now be configured to activate
1367-
particular bean definition profiles for various testing scenarios.
1368-
This is achieved by annotating a test class with the new
1369-
@ActiveProfiles annotation and supplying a list of profiles that
1370-
should be activated when loading the ApplicationContext for the
1371-
test.</para>
1365+
the notion of environments and profiles (a.k.a., <emphasis>bean
1366+
definition profiles</emphasis>), and integration tests can now be
1367+
configured to activate particular bean definition profiles for
1368+
various testing scenarios. This is achieved by annotating a test
1369+
class with the new <interfacename>@ActiveProfiles</interfacename>
1370+
annotation and supplying a list of profiles that should be activated
1371+
when loading the <interfacename>ApplicationContext</interfacename>
1372+
for the test.</para>
13721373

13731374
<note>
1374-
<para>@ActiveProfiles may be used with any implementation of the
1375-
new SmartContextLoader SPI, but @ActiveProfiles is not supported
1376-
with implementations of the older ContextLoader SPI.</para>
1375+
<para><interfacename>@ActiveProfiles</interfacename> may be used
1376+
with any implementation of the new
1377+
<interfacename>SmartContextLoader</interfacename> SPI, but
1378+
<interfacename>@ActiveProfiles</interfacename> is not supported
1379+
with implementations of the older
1380+
<interfacename>ContextLoader</interfacename> SPI.</para>
13771381
</note>
13781382

13791383
<para>Let's take a look at some examples with XML configuration and
1380-
@Configuration classes.</para>
1384+
<interfacename>@Configuration</interfacename> classes.</para>
13811385

13821386
<programlisting language="xml">&lt;!-- app-config.xml --&gt;
13831387
&lt;beans xmlns="http://www.springframework.org/schema/beans"
@@ -1433,25 +1437,33 @@ public class TransferServiceTest {
14331437
}
14341438
}</programlisting>
14351439

1436-
<para>When TransferServiceTest is run, its ApplicationContext will
1437-
be loaded from the app-config.xml configuration file in the root of
1438-
the classpath. If you inspect app-config.xml you'll notice that the
1439-
accountRepository bean has a dependency on a dataSource bean;
1440-
however, dataSource is not defined as a top-level bean. Instead,
1441-
dataSource is defined twice: once in the production profile and once
1442-
in the dev profile.</para>
1443-
1444-
<para>By annotating TransferServiceTest with @ActiveProfiles("dev")
1445-
we instruct the Spring TestContext Framework to load the
1446-
ApplicationContext with the active profiles set to {"dev"}. As a
1447-
result, an embedded database will be created, and the
1448-
accountRepository bean will be wired with a reference to the
1449-
development DataSource. And that's likely what we want in an
1450-
integration test.</para>
1440+
<para>When <classname>TransferServiceTest</classname> is run, its
1441+
<interfacename>ApplicationContext</interfacename> will be loaded
1442+
from the <filename>app-config.xml</filename> configuration file in
1443+
the root of the classpath. If you inspect
1444+
<filename>app-config.xml</filename> you'll notice that the
1445+
<varname>accountRepository</varname> bean has a dependency on a
1446+
<varname>dataSource</varname> bean; however,
1447+
<varname>dataSource</varname> is not defined as a top-level bean.
1448+
Instead, <varname>dataSource</varname> is defined twice: once in the
1449+
<emphasis>production</emphasis> profile and once in the
1450+
<emphasis>dev</emphasis> profile.</para>
1451+
1452+
<para>By annotating <classname>TransferServiceTest</classname> with
1453+
<interfacename>@ActiveProfiles("dev")</interfacename> we instruct
1454+
the Spring TestContext Framework to load the
1455+
<interfacename>ApplicationContext</interfacename> with the active
1456+
profiles set to <literal>{"dev"}</literal>. As a result, an embedded
1457+
database will be created, and the
1458+
<varname>accountRepository</varname> bean will be wired with a
1459+
reference to the development
1460+
<interfacename>DataSource</interfacename>. And that's likely what we
1461+
want in an integration test.</para>
14511462

14521463
<para>The following code listings demonstrate how to implement the
1453-
same configuration and integration test but using @Configuration
1454-
classes instead of XML.</para>
1464+
same configuration and integration test but using
1465+
<interfacename>@Configuration</interfacename> classes instead of
1466+
XML.</para>
14551467

14561468
<programlisting language="java">@Configuration
14571469
@Profile("dev")
@@ -1510,30 +1522,35 @@ public class TransferServiceTest {
15101522
}</programlisting>
15111523

15121524
<para>In this variation, we have split the XML configuration into
1513-
three independent @Configuration classes:</para>
1525+
three independent <interfacename>@Configuration</interfacename>
1526+
classes:</para>
15141527

15151528
<itemizedlist>
15161529
<listitem>
1517-
<para>TransferServiceConfig: acquires a dataSource via
1518-
dependency injection using @Autowired</para>
1530+
<para><classname>TransferServiceConfig</classname>: acquires a
1531+
<varname>dataSource</varname> via dependency injection using
1532+
<interfacename>@Autowired</interfacename></para>
15191533
</listitem>
15201534

15211535
<listitem>
1522-
<para>StandaloneDataConfig: defines a dataSource for an embedded
1523-
database suitable for developer tests</para>
1536+
<para><classname>StandaloneDataConfig</classname>: defines a
1537+
<varname>dataSource</varname> for an embedded database suitable
1538+
for developer tests</para>
15241539
</listitem>
15251540

15261541
<listitem>
1527-
<para>JndiDataConfig: defines a dataSource that is retrieved
1528-
from JNDI in a production environment</para>
1542+
<para><classname>JndiDataConfig</classname>: defines a
1543+
<varname>dataSource</varname> that is retrieved from JNDI in a
1544+
production environment</para>
15291545
</listitem>
15301546
</itemizedlist>
15311547

15321548
<para>As with the XML-based configuration example, we still annotate
1533-
TransferServiceTest with @ActiveProfiles("dev"), but this time we
1534-
specify all three configuration classes via the
1535-
@ContextConfiguration annotation. The body of the test class itself
1536-
remains completely unchanged.</para>
1549+
<classname>TransferServiceTest</classname> with
1550+
<interfacename>@ActiveProfiles("dev")</interfacename>, but this time
1551+
we specify all three configuration classes via the
1552+
<interfacename>@ContextConfiguration </interfacename>annotation. The
1553+
body of the test class itself remains completely unchanged.</para>
15371554
</section>
15381555

15391556
<section id="testcontext-ctx-management-caching">

0 commit comments

Comments
 (0)