...
Code Block |
---|
@Resource
public void setMaxLineItems(int maxLineItems) {
this.maxLineItems = maxLineItems;
}
|
env-entry in ejb-jar.xml
Code Block |
---|
|
<env-entry>
<description>The maximum number of line items per invoice.</description>
<env-entry-name>org.apache.openejb.examples.injection.InvoiceBean/maxLineItems</env-entry-name>
<env-entry-type>java.lang.Integer</env-entry-type>
<env-entry-value>15</env-entry-value>
</env-entry>
|
Using @Resource annotated env-entry
Tip |
---|
title | Using @Resource annotated env-entry |
---|
|
maxLineItems variable is injected by the setMaxLine method above. See also how env-entry is defined in ejb-jar.xml |
Code Block |
---|
public void addLineItem(LineItem item) throws TooManyItemsException {
if (item == null) {
throw new IllegalArgumentException("Line item must not be null");
}
if (itemCount <= maxLineItems) {
items.add(item);
itemCount++;
} else {
throw new TooManyItemsException("Number of items exceeded the maximum limit");
}
}
|
JUnit Test
Writing an JUnit test for this example is quite simple. We need just to write a setup method to create and initialize the InitialContext, and then write our test methods.
...