Search in sources :

Example 1 with Errors

use of org.springframework.validation.Errors in project OpenClinica by OpenClinica.

the class OdmImportServiceImpl method saveOrUpdateCrfAndFormLayouts.

private void saveOrUpdateCrfAndFormLayouts(String crfOid, List<OCodmComplexTypeDefinitionFormLayoutDef> formLayoutDefs, Form[] fmCrfs, UserAccount userAccount, Study study, String crfName) {
    DataBinder dataBinder = new DataBinder(new FormLayout());
    Errors errors = dataBinder.getBindingResult();
    StudyBean currentStudy = new StudyBean();
    currentStudy.setId(study.getStudyId());
    UserAccountBean ub = new UserAccountBean();
    ub.setId(userAccount.getUserId());
    ub.setActiveStudyId(currentStudy.getId());
    for (Form crf : fmCrfs) {
        if (crf.getOcoid().equals(crfOid)) {
            ExecuteIndividualCrfObject eicObj = new ExecuteIndividualCrfObject(crf, formLayoutDefs, errors, currentStudy, ub, true, null);
            xformService.executeIndividualCrf(eicObj);
        }
    }
}
Also used : FormLayout(org.akaza.openclinica.domain.datamap.FormLayout) Errors(org.springframework.validation.Errors) ExecuteIndividualCrfObject(org.akaza.openclinica.service.crfdata.ExecuteIndividualCrfObject) Form(org.akaza.openclinica.service.dto.Form) StudyBean(org.akaza.openclinica.bean.managestudy.StudyBean) UserAccountBean(org.akaza.openclinica.bean.login.UserAccountBean) DataBinder(org.springframework.validation.DataBinder)

Example 2 with Errors

use of org.springframework.validation.Errors in project opennms by OpenNMS.

the class DefaultDistributedStatusServiceTest method testFindLocationSpecificStatusInvalidLocation.

public void testFindLocationSpecificStatusInvalidLocation() {
    DistributedStatusDetailsCommand command = new DistributedStatusDetailsCommand();
    Errors errors = new BindException(command, "command");
    command.setLocation("invalid location");
    command.setApplication(m_application1.getName());
    expect(m_monitoringLocationDao.get(command.getLocation())).andReturn(null);
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException("Could not find location for location name \"" + command.getLocation() + "\""));
    m_easyMockUtils.replayAll();
    try {
        m_service.findLocationSpecificStatus(command, errors);
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    m_easyMockUtils.verifyAll();
    ta.verifyAnticipated();
}
Also used : Errors(org.springframework.validation.Errors) DistributedStatusDetailsCommand(org.opennms.web.svclayer.model.DistributedStatusDetailsCommand) BindException(org.springframework.validation.BindException) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator)

Example 3 with Errors

use of org.springframework.validation.Errors in project opennms by OpenNMS.

the class DefaultDistributedStatusServiceTest method testCreateStatusPutUnreportedServicesLast.

public void testCreateStatusPutUnreportedServicesLast() {
    DistributedStatusDetailsCommand command = new DistributedStatusDetailsCommand();
    Errors errors = new BindException(command, "command");
    command.setLocation(m_locationDefinition1.getLocationName());
    command.setApplication(m_application1.getName());
    expect(m_applicationDao.findByName("Application 1")).andReturn(m_application1);
    expect(m_monitoringLocationDao.get(m_locationDefinition1.getLocationName())).andReturn(m_locationDefinition1);
    expect(m_locationMonitorDao.findByLocationDefinition(m_locationDefinition1)).andReturn(Collections.singleton(m_locationMonitor1_1));
    OnmsMonitoredService httpService = findMonitoredService(m_services, m_ip, "HTTP");
    OnmsMonitoredService httpsService = findMonitoredService(m_services, m_ip, "HTTPS");
    expect(m_locationMonitorDao.getMostRecentStatusChange(m_locationMonitor1_1, httpService)).andReturn(null);
    expect(m_locationMonitorDao.getMostRecentStatusChange(m_locationMonitor1_1, httpsService)).andReturn(new OnmsLocationSpecificStatus(m_locationMonitor1_1, httpsService, PollStatus.available()));
    expect(m_monitoredServiceDao.findByApplication(m_application1)).andReturn(m_applicationServices1);
    m_easyMockUtils.replayAll();
    SimpleWebTable table = m_service.createStatusTable(command, errors);
    m_easyMockUtils.verifyAll();
    SimpleWebTable expectedTable = new SimpleWebTable();
    expectedTable.setTitle("Distributed status view for Application 1 from Raleigh location");
    expectedTable.addColumn("Node", "");
    expectedTable.addColumn("Monitor", "");
    expectedTable.addColumn("Service", "");
    expectedTable.addColumn("Status", "");
    expectedTable.addColumn("Response", "");
    expectedTable.addColumn("Last Status Change", "");
    expectedTable.addColumn("Last Update", "");
    expectedTable.newRow();
    expectedTable.addCell("Node 1", "Normal", "element/node.jsp?node=1");
    expectedTable.addCell("Raleigh-" + LOCATION_MONITOR_ID_A, "", "distributed/locationMonitorDetails.htm?monitorId=" + LOCATION_MONITOR_ID_A);
    expectedTable.addCell("HTTPS", "", "element/service.jsp?ifserviceid=null");
    expectedTable.addCell("Up", "bright");
    expectedTable.addCell("", "");
    expectedTable.addCell(IGNORE_MATCH, "");
    expectedTable.addCell(IGNORE_MATCH, "");
    expectedTable.newRow();
    expectedTable.addCell("Node 1", "Indeterminate", "element/node.jsp?node=1");
    expectedTable.addCell("Raleigh-" + LOCATION_MONITOR_ID_A, "", "distributed/locationMonitorDetails.htm?monitorId=" + LOCATION_MONITOR_ID_A);
    expectedTable.addCell("HTTP", "", "element/service.jsp?ifserviceid=null");
    expectedTable.addCell("Unknown", "bright");
    expectedTable.addCell("No status recorded for this service from this location", "");
    expectedTable.addCell(IGNORE_MATCH, "");
    expectedTable.addCell(IGNORE_MATCH, "");
    assertTableEquals(expectedTable, table);
}
Also used : Errors(org.springframework.validation.Errors) DistributedStatusDetailsCommand(org.opennms.web.svclayer.model.DistributedStatusDetailsCommand) OnmsLocationSpecificStatus(org.opennms.netmgt.model.OnmsLocationSpecificStatus) BindException(org.springframework.validation.BindException) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable) OnmsMonitoredService(org.opennms.netmgt.model.OnmsMonitoredService)

Example 4 with Errors

use of org.springframework.validation.Errors in project opennms by OpenNMS.

the class DefaultDistributedStatusServiceTest method testCreateStatusNoLocationMonitor.

public void testCreateStatusNoLocationMonitor() {
    DistributedStatusDetailsCommand command = new DistributedStatusDetailsCommand();
    Errors errors = new BindException(command, "command");
    command.setLocation(m_locationDefinition3.getLocationName());
    command.setApplication(m_application2.getName());
    expect(m_applicationDao.findByName("Application 2")).andReturn(m_application2);
    expect(m_monitoringLocationDao.get(m_locationDefinition3.getLocationName())).andReturn(m_locationDefinition3);
    expect(m_locationMonitorDao.findByLocationDefinition(m_locationDefinition3)).andReturn(new HashSet<OnmsLocationMonitor>());
    m_easyMockUtils.replayAll();
    SimpleWebTable table = m_service.createStatusTable(command, errors);
    Errors errorsOut = table.getErrors();
    assertEquals("Number of errors", 1, errorsOut.getErrorCount());
    assertEquals("Number of global errors", 1, errorsOut.getGlobalErrorCount());
    assertEquals("Number of field errors", 0, errorsOut.getFieldErrorCount());
    ObjectError e = (ObjectError) errorsOut.getGlobalErrors().get(0);
    assertEquals("Error code 0", "location.no-monitors", e.getCode());
    assertEquals("Error 0 argument count", 2, e.getArguments().length);
    assertEquals("Error argument 0.0", "Application 2", e.getArguments()[0]);
    assertEquals("Error argument 0.0", "Columbus", e.getArguments()[1]);
    m_easyMockUtils.verifyAll();
}
Also used : Errors(org.springframework.validation.Errors) ObjectError(org.springframework.validation.ObjectError) DistributedStatusDetailsCommand(org.opennms.web.svclayer.model.DistributedStatusDetailsCommand) BindException(org.springframework.validation.BindException) SimpleWebTable(org.opennms.web.svclayer.model.SimpleWebTable) OnmsLocationMonitor(org.opennms.netmgt.model.OnmsLocationMonitor)

Example 5 with Errors

use of org.springframework.validation.Errors in project opennms by OpenNMS.

the class DefaultDistributedStatusServiceTest method testFindLocationSpecificStatusInvalidApplication.

public void testFindLocationSpecificStatusInvalidApplication() {
    DistributedStatusDetailsCommand command = new DistributedStatusDetailsCommand();
    Errors errors = new BindException(command, "command");
    command.setLocation(m_locationDefinition1.getLocationName());
    command.setApplication("invalid application");
    expect(m_monitoringLocationDao.get(m_locationDefinition1.getLocationName())).andReturn(m_locationDefinition1);
    expect(m_applicationDao.findByName(command.getApplication())).andReturn(null);
    ThrowableAnticipator ta = new ThrowableAnticipator();
    ta.anticipate(new IllegalArgumentException("Could not find application for application name \"" + command.getApplication() + "\""));
    m_easyMockUtils.replayAll();
    try {
        m_service.findLocationSpecificStatus(command, errors);
    } catch (Throwable t) {
        ta.throwableReceived(t);
    }
    m_easyMockUtils.verifyAll();
    ta.verifyAnticipated();
}
Also used : Errors(org.springframework.validation.Errors) DistributedStatusDetailsCommand(org.opennms.web.svclayer.model.DistributedStatusDetailsCommand) BindException(org.springframework.validation.BindException) ThrowableAnticipator(org.opennms.test.ThrowableAnticipator)

Aggregations

Errors (org.springframework.validation.Errors)478 BindException (org.springframework.validation.BindException)387 Test (org.junit.Test)376 BaseContextSensitiveTest (org.openmrs.test.BaseContextSensitiveTest)356 OrderUtilTest (org.openmrs.order.OrderUtilTest)58 DrugOrder (org.openmrs.DrugOrder)56 Date (java.util.Date)54 Test (org.junit.jupiter.api.Test)36 Patient (org.openmrs.Patient)36 TestBean (org.springframework.beans.testfixture.beans.TestBean)33 Calendar (java.util.Calendar)28 Concept (org.openmrs.Concept)25 BeanPropertyBindingResult (org.springframework.validation.BeanPropertyBindingResult)24 TestOrder (org.openmrs.TestOrder)23 OrderType (org.openmrs.OrderType)22 Encounter (org.openmrs.Encounter)21 Obs (org.openmrs.Obs)20 Order (org.openmrs.Order)20 ConceptReferenceTerm (org.openmrs.ConceptReferenceTerm)19 PageContext (jakarta.servlet.jsp.PageContext)17