dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24778
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12197: more tests for eventService (single, no reg)
------------------------------------------------------------
revno: 12197
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-09-23 09:28:36 +0200
message:
more tests for eventService (single, no reg)
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultInputValidationService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/InputValidationService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java
dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java
dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java
dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java 2013-09-20 15:12:37 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/program/ProgramStageInstance.java 2013-09-23 07:28:36 +0000
@@ -344,4 +344,24 @@
return ProgramStageInstance.FUTURE_VISIT_STATUS;
}
}
+
+ @Override
+ public String toString()
+ {
+ return "ProgramStageInstance{" +
+ "programInstance=" + programInstance +
+ ", programStage=" + programStage +
+ ", dueDate=" + dueDate +
+ ", executionDate=" + executionDate +
+ ", organisationUnit=" + organisationUnit +
+ ", completed=" + completed +
+ ", outboundSms=" + outboundSms +
+ ", messageConversations=" + messageConversations +
+ ", patientComment=" + patientComment +
+ ", status=" + status +
+ ", coordinates='" + coordinates + '\'' +
+ ", completedUser='" + completedUser + '\'' +
+ ", completedDate=" + completedDate +
+ '}';
+ }
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultInputValidationService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultInputValidationService.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/DefaultInputValidationService.java 2013-09-23 07:28:36 +0000
@@ -46,10 +46,36 @@
// -------------------------------------------------------------------------
@Autowired
+ private UserService userService;
+
+ @Autowired
private I18nManager i18nManager;
- @Autowired
- private UserService userService;
+ private I18nFormat _format;
+
+ @Override
+ public void setFormat( I18nFormat format )
+ {
+ this._format = format;
+ }
+
+ public I18nFormat getFormat()
+ {
+ if ( _format != null )
+ {
+ return _format;
+ }
+
+ try
+ {
+ _format = i18nManager.getI18nFormat();
+ }
+ catch ( I18nManagerException ignored )
+ {
+ }
+
+ return _format;
+ }
// -------------------------------------------------------------------------
// InputValidationService Implementation
@@ -58,17 +84,12 @@
@Override
public Status validateDataElement( DataElement dataElement, String value )
{
- I18nFormat format;
-
- try
- {
- format = i18nManager.getI18nFormat();
- }
- catch ( I18nManagerException ex )
- {
- return new Status( false, ex.getMessage() );
- }
-
+ return validateDataElement( dataElement, value, getFormat() );
+ }
+
+ @Override
+ public Status validateDataElement( DataElement dataElement, String value, I18nFormat format )
+ {
value = value.trim();
if ( value.length() >= 255 )
@@ -92,7 +113,7 @@
}
else if ( dataElement.getType().equals( DataElement.VALUE_TYPE_DATE ) )
{
- boolean dateIsValidated = format.parseDate( value ) != null;
+ boolean dateIsValidated = getFormat().parseDate( value ) != null;
if ( !dateIsValidated )
{
@@ -118,7 +139,7 @@
else if ( dataElement.getTextType().equals( DataElement.VALUE_TYPE_TEXT ) ||
dataElement.getTextType().equals( DataElement.VALUE_TYPE_LONG_TEXT ) )
{
- // no validation for this right now, we already to length validation
+ // no validation for this right now, we already have length validation
}
}
else if ( dataElement.getType().equals( DataElement.VALUE_TYPE_NUMBER ) )
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/InputValidationService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/InputValidationService.java 2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/InputValidationService.java 2013-09-23 07:28:36 +0000
@@ -29,12 +29,15 @@
*/
import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.i18n.I18nFormat;
/**
* @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
*/
public interface InputValidationService
{
+ public void setFormat( I18nFormat format );
+
final class Status
{
private boolean success = true;
@@ -63,4 +66,6 @@
}
Status validateDataElement( DataElement dataElement, String value );
+
+ Status validateDataElement( DataElement dataElement, String value, I18nFormat format );
}
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2013-09-20 15:12:37 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/AbstractEventService.java 2013-09-23 07:28:36 +0000
@@ -56,7 +56,6 @@
import org.hisp.dhis.program.ProgramStageService;
import org.hisp.dhis.user.CurrentUserService;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;
import java.util.ArrayList;
@@ -497,7 +496,7 @@
private boolean validateDataElement( DataElement dataElement, String value, ImportSummary importSummary )
{
- InputValidationService.Status status = inputValidationService.validateDataElement( dataElement, value );
+ InputValidationService.Status status = inputValidationService.validateDataElement( dataElement, value, getFormat() );
if ( !status.isSuccess() )
{
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java 2013-09-20 15:12:37 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/event/EventService.java 2013-09-23 07:28:36 +0000
@@ -48,7 +48,7 @@
*/
public interface EventService
{
- public void setFormat(I18nFormat format);
+ public void setFormat( I18nFormat format );
// -------------------------------------------------------------------------
// READ
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java 2013-09-20 15:12:37 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/main/java/org/hisp/dhis/dxf2/events/person/AbstractPersonService.java 2013-09-23 07:28:36 +0000
@@ -121,7 +121,6 @@
return _format;
}
-
// -------------------------------------------------------------------------
// READ
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java'
--- dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java 2013-09-20 15:12:37 +0000
+++ dhis-2/dhis-services/dhis-service-dxf2/src/test/java/org/hisp/dhis/dxf2/events/NoRegistrationSingleEventServiceTest.java 2013-09-23 07:28:36 +0000
@@ -31,6 +31,7 @@
import org.hisp.dhis.DhisTest;
import org.hisp.dhis.common.IdentifiableObjectManager;
import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dxf2.events.enrollment.EnrollmentService;
import org.hisp.dhis.dxf2.events.event.DataValue;
import org.hisp.dhis.dxf2.events.event.Event;
import org.hisp.dhis.dxf2.events.event.EventService;
@@ -44,23 +45,14 @@
import org.hisp.dhis.program.ProgramStage;
import org.hisp.dhis.program.ProgramStageDataElement;
import org.hisp.dhis.program.ProgramStageDataElementService;
-import org.hisp.dhis.user.User;
-import org.hisp.dhis.user.UserAuthorityGroup;
+import org.hisp.dhis.program.ProgramStageInstance;
+import org.hisp.dhis.program.ProgramStageInstanceService;
import org.hisp.dhis.user.UserService;
-import org.junit.Ignore;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
-import org.springframework.security.core.Authentication;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.authority.SimpleGrantedAuthority;
-import org.springframework.security.core.context.SecurityContextHolder;
-import org.springframework.security.core.userdetails.UserDetails;
-import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
-import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
@@ -81,9 +73,15 @@
private ProgramStageDataElementService programStageDataElementService;
@Autowired
+ private EnrollmentService enrollmentService;
+
+ @Autowired
private ProgramInstanceService programInstanceService;
@Autowired
+ private ProgramStageInstanceService programStageInstanceService;
+
+ @Autowired
private IdentifiableObjectManager manager;
@Autowired
@@ -147,9 +145,114 @@
}
@Test
+ public void testGetPersonsByProgramOrgUnit()
+ {
+ for ( int i = 0; i < 10; i++ )
+ {
+ Event event = createEvent( programA.getUid(), organisationUnitA.getUid() );
+
+ ImportSummary importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+ assertNotNull( importSummary.getReference() );
+ }
+
+ assertEquals( 10, eventService.getEvents( programA, organisationUnitA ).getEvents().size() );
+ }
+
+ @Test
+ public void testGetPersonsByProgramStageOrgUnit()
+ {
+ for ( int i = 0; i < 10; i++ )
+ {
+ Event event = createEvent( programA.getUid(), organisationUnitA.getUid() );
+
+ ImportSummary importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+ assertNotNull( importSummary.getReference() );
+ }
+
+ assertEquals( 10, eventService.getEvents( programStageA, organisationUnitA ).getEvents().size() );
+ }
+
+ @Test
+ public void testGetPersonsByProgramProgramStageOrgUnit()
+ {
+ for ( int i = 0; i < 10; i++ )
+ {
+ Event event = createEvent( programA.getUid(), organisationUnitA.getUid() );
+
+ ImportSummary importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+ assertNotNull( importSummary.getReference() );
+ }
+
+ assertEquals( 10, eventService.getEvents( programA, programStageA, organisationUnitA ).getEvents().size() );
+ }
+
+ @Test
+ public void testGetPersonsByProgramStageInstance()
+ {
+ Event event = createEvent( programA.getUid(), organisationUnitA.getUid() );
+
+ ImportSummary importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+ assertNotNull( importSummary.getReference() );
+
+ ProgramStageInstance programStageInstance = programStageInstanceService.getProgramStageInstance( importSummary.getReference() );
+
+ assertNotNull( programStageInstance );
+ assertNotNull( eventService.getEvent( programStageInstance ) );
+ }
+
+ @Test
+ public void testGetEventByUid()
+ {
+ Event event = createEvent( programA.getUid(), organisationUnitA.getUid() );
+
+ ImportSummary importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+ assertNotNull( importSummary.getReference() );
+
+ assertNotNull( eventService.getEvent( importSummary.getReference() ) );
+ }
+
+ @Test
public void testSaveEvent()
{
Event event = createEvent( programA.getUid(), organisationUnitA.getUid() );
+ ImportSummary importSummary = eventService.saveEvent( event );
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+ assertEquals( 0, importSummary.getConflicts().size() );
+ assertNotNull( importSummary.getReference() );
+
+ event = eventService.getEvent( importSummary.getReference() );
+ assertNotNull( event );
+ assertEquals( "10", event.getDataValues().get( 0 ).getValue() );
+ }
+
+ @Test
+ public void testUpdateEvent()
+ {
+ Event event = createEvent( programA.getUid(), organisationUnitA.getUid() );
+
+ ImportSummary importSummary = eventService.saveEvent( event );
+
+ assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
+ assertNotNull( importSummary.getReference() );
+ assertEquals( "10", event.getDataValues().get( 0 ).getValue() );
+
+ event = eventService.getEvent( importSummary.getReference() );
+ event.getDataValues().get( 0 ).setValue( "254" );
+ eventService.updateEvent( event );
+
+ event = eventService.getEvent( importSummary.getReference() );
+ assertEquals( "254", event.getDataValues().get( 0 ).getValue() );
+ }
+
+ @Test
+ public void testDeleteEvent()
+ {
+ Event event = createEvent( programA.getUid(), organisationUnitA.getUid() );
ImportSummary importSummary = eventService.saveEvent( event );
assertEquals( ImportStatus.SUCCESS, importSummary.getStatus() );
=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java 2013-09-20 15:12:37 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/dbms/HibernateDbmsManager.java 2013-09-23 07:28:36 +0000
@@ -125,6 +125,7 @@
emptyTable( "datasetoperands" );
emptyTable( "dataset" );
+ emptyTable( "patientdatavalue" );
emptyTable( "programstageinstance" );
emptyTable( "programinstance" );
emptyTable( "programstage_dataelements" );