No Such Table Exception on Test

Hi all, I am currently developing an openmrs module. But the only issue i currently have is when running my test. I receive this error: org.dbunit.dataset.NoSuchTableException: managepricing_drugpricing This is a snapshot of my current project structure:

These are some of the relevant source code: TestingApplicationContext.xml:

<bean id="sessionFactory" class="org.openmrs.api.db.hibernate.HibernateSessionFactoryBean">
    <property name="configLocations">
        <list>
            <value>classpath:hibernate.cfg.xml</value>
            <value>classpath:managepricing-hibernate.cfg.xml</value>
        </list>
    </property>
    <property name="mappingJarLocations">
        <ref bean="mappingJarResources" />
    </property>
    <!--  default properties must be set in the hibernate.default.properties -->
</bean>

managepricing-hibernate.cfg.xml

<hibernate-configuration>
<session-factory>
	<mapping resource="DrugPricing.hbm.xml"/>
</session-factory>

DrugPricing.hbm.xml

<class name="DrugPricing" table="${project.parent.artifactId}_DrugPricing">
	<id name="id" type="int" column="id" unsaved-value="0"><generator class="native" />	</id>
	<discriminator column="id" insert="false" />
	<!--<property name="uuid" type="java.lang.String" column="uuid" length="38" unique="true" />
	-->
	<property name="type" column="type" type="java.lang.String" length="20" />
	<property name="hmoName" column="hmo_name" type="java.lang.String" length="150" />
	<property name="hmoId" column="hmo_id" type="java.lang.Integer"/>
	<property name="drugName" column="drug_name" type="java.lang.String" length="150" />
	<property name="drugId" column="drug_id" type="java.lang.Integer" />
	<property name="dispenseUnit" column="dispense_unit" type="java.lang.String" length="50" />
	<property name="unitPrice" column="unit_price" type="java.math.BigDecimal" />
	<property name="retired" column="retired" type="java.lang.Integer" />
	<property name="creator" column="creator" type="java.lang.Integer" />
</class>
1 Like

In your DrugPricing.hbm.xml try replacing _DrugPricing with _drugpricing

Hello @dkayiwa, I am still having thesame issue, even after trying the replacement.

How about replacing table="${project.parent.artifactId}_DrugPricing" with table=“managepricing_drugpricing”

1 Like

Thanks. This works okay. But I now have another error:

getDrugPricingByType_shouldReturnListOfDrugpricingForAType(org.openmrs.module.mangepricing.api.DrugPricingServiceTest)  Time elapsed: 0.38 sec  <<< ERROR!
java.lang.NullPointerException
at org.dbunit.dataset.datatype.IntegerDataType.setSqlValue(IntegerDataType.java:106)
at org.dbunit.database.statement.SimplePreparedStatement.addValue(SimplePreparedStatement.java:73)
at org.dbunit.operation.RefreshOperation$RowOperation.execute(RefreshOperation.java:180)
at org.dbunit.operation.RefreshOperation.execute(RefreshOperation.java:110)
at org.openmrs.test.BaseContextSensitiveTest.executeDataSet(BaseContextSensitiveTest.java:572)
at org.openmrs.test.BaseContextSensitiveTest.executeDataSet(BaseContextSensitiveTest.java:484)
at org.openmrs.module.mangepricing.api.DrugPricingServiceTest.getDrugPricingByType_shouldReturnListOfDrugpricingForAType(DrugPricingServiceTest.java:45)

This is the function where the error emanates from:

public void getDrugPricingByType_shouldReturnListOfDrugpricingForAType() throws Exception {
	initializeInMemoryDatabase();
	executeDataSet("testDataSet.xml");
	authenticate();

	DrugPricingService drugPricingService = Context.getService(DrugPricingService.class);
	System.out.println("\n GET HMO BY TYPE");
	List<DrugPricing> facilityTypeList = drugPricingService.getDrugPricingByType("Facility", false);

	Assert.assertTrue(facilityTypeList.size() >= 1); // assert that it returns more than a single list


}//getDrugPricingByType

How does testDataSet.xml look like?

<?xml version='1.0' encoding='UTF-8'?>
    <dataset>
<managepricing_drugpricing id="2" type="Facility" hmo_name="" hmo_id="" drug_name="Paracetamol" drug_id="1" dispense_unit="sachet" unit_price="20" creator="1" retired="1" />
<managepricing_drugpricing id="3" type="Facility" hmo_name="" hmo_id="" drug_name="Paracetamol" drug_id="1" dispense_unit="15cl bottle" unit_price="100" creator="1" retired="1" />
<managepricing_drugpricing id="4" type="HMO" hmo_name="Atilia" hmo_id="1" drug_name="Paracetamol" drug_id="1" dispense_unit="sachet" unit_price="50" creator="1" retired="1" />
<managepricing_drugpricing id="5" type="HMO" hmo_name="B-HMO" hmo_id="2" drug_name="Panadol" drug_id="2" dispense_unit="sachet" unit_price="25" creator="1" retired="0" />
<managepricing_drugpricing id="6" type="HMO" hmo_name="Atilia" hmo_id="1" drug_name="Vitamin C" drug_id="3" dispense_unit="20cl bottle" unit_price="80" creator="1" retired="1" />
<managepricing_drugpricing id="7" type="HMO" hmo_name="B-HMO" hmo_id="2" drug_name="Vitamin C" drug_id="3" dispense_unit="20cl bottle" unit_price="90" creator="1" retired="1" />
<managepricing_drugpricing id="8" type="Facility" hmo_name="" hmo_id="" drug_name="Panadol" drug_id="2" dispense_unit="10cl Bottle" unit_price="120" creator="1" retired="1" />
</dataset>

How should this convert to an integer? hmo_id=" "

2 Likes

@dkayiwa Thanks a lot for your time. Everything is now perfect. What I did was to enter a value of 0 for any hmo_id that has no value.

It works! Once again, thanks.

2 Likes