Hi I am very new to
unit testing. I am using Spring framework +
struts 2.0
I am trying to test a serice. I have two Context files. When I run this class as a
junit test, it gave me an error like could not find local.config.properties file. ApplicationContext.xml file has property configurer.
I like to know if I am running in a proper way or should I create a build file so that applicationContext can find all the properties file or how should I load the properties file.
Here is what I am trying to do--
package myproject.service;
import java.util.List;
import org.springframework.test.AbstractDependencyInjectionSpringContextTests;
import myproject.model.Shipment;
import myproject.model.ShipmentBeanForListing;
import myproject.model.ShipmentSelectionCriteria;
public class ShipmentServiceTest extends
AbstractDependencyInjectionSpringContextTests {
public ShipmentServiceTest(
String name) {
super(name);
}
protected String[] getConfigLocations(){
return new String[] {
"file:///C://web_servers//apache-tomcat-6.0.14//webapps//myproject//WEB-INF//applicationContext.xml",
"file:///C://web_servers//apache-tomcat-6.0.14//webapps//vms//WEB-INF//dataAccessContext.xml"};
}
public void testSaveShipment() throws Exception {
ShipmentService service = (ShipmentService) applicationContext.getBean("shipmentService");
Shipment shipment = new Shipment();
shipment.setShipmentId(new Integer(999999));
shipment.setShippingMethod("Courier");
shipment.setShippingCarrier("SKPS");
service.saveShipment(shipment);
System.out.println("Shipment Added");
ShipmentSelectionCriteria selectionCriteria = new ShipmentSelectionCriteria();
selectionCriteria.setShipmentIds("999999");
List<ShipmentBeanForListing> shipments = service.getShipments(selectionCriteria);
assertTrue(shipments.contains(shipment));
}
}
--------------------------------------------------------------------------
Part of applicationContext.xml file
<!-- Configurer that replaces ${...} placeholders with values from properties files -->
<bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<list>
<value>WEB-INF/${HOST_NAME}.config.properties</value>
<value>WEB-INF/${HOST_NAME}.jdbc.properties</value>
</list>
</property>
<property name="systemPropertiesModeName">
<value>SYSTEM_PROPERTIES_MODE_OVERRIDE</value>
</property>
</bean>