1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.location.web;
17
18 import org.junit.Assert;
19 import org.junit.Before;
20 import org.junit.Test;
21 import org.kuali.rice.kew.api.document.Document;
22 import org.kuali.rice.kew.api.exception.WorkflowException;
23 import org.kuali.rice.kns.service.KNSServiceLocator;
24 import org.kuali.rice.krad.exception.ValidationException;
25 import org.kuali.rice.krad.maintenance.MaintenanceDocument;
26 import org.kuali.rice.krad.service.KRADServiceLocator;
27 import org.kuali.rice.krad.service.KRADServiceLocatorWeb;
28 import org.kuali.rice.krad.util.KRADConstants;
29 import org.kuali.rice.location.api.services.LocationApiServiceLocator;
30 import org.kuali.rice.location.impl.country.CountryBo;
31 import org.kuali.rice.location.impl.county.CountyBo;
32 import org.kuali.rice.location.impl.state.StateBo;
33 import org.kuali.rice.krad.test.BaseMaintenanceDocumentTest;
34
35 import static org.junit.Assert.assertNotNull;
36
37
38
39
40 public class CountyMaintenanceDocumentTest extends BaseMaintenanceDocumentTest {
41
42
43
44 @Before
45 public void insertTestCountryAndState() {
46 CountryBo country = new CountryBo();
47 country.setCode("CC");
48 country.setName("New Country");
49 country.setActive(true);
50 KNSServiceLocator.getBusinessObjectService().save(country);
51
52 StateBo state = new StateBo();
53 state.setCode("SS");
54 state.setCountryCode("CC");
55 state.setName("New State");
56 state.setActive(true);
57 KNSServiceLocator.getBusinessObjectService().save(state);
58 }
59
60 @Override
61 protected Object getNewMaintainableObject() {
62 CountyBo county = new CountyBo();
63 county.setName("Tompkins");
64 county.setCode("TOMPKINS");
65 county.setCountryCode("US");
66 county.setStateCode("CA");
67 return county;
68 }
69
70 @Override
71 protected String getDocumentTypeName() {
72 return "CountyMaintenanceDocument";
73 }
74
75 @Override
76 protected String getInitiatorPrincipalName() {
77 return "quickstart";
78 }
79
80 @Override
81 protected Object getOldMaintainableObject() {
82 return getNewMaintainableObject();
83 }
84
85 @Test(expected = ValidationException.class)
86
87
88
89 public void test_MismatchedStateCountry() throws WorkflowException {
90 assertNotNull(LocationApiServiceLocator.getCountryService().getCountry("CC"));
91 assertNotNull(LocationApiServiceLocator.getStateService().getState("CC", "SS"));
92
93 CountyBo county = new CountyBo();
94 county.setName("Tompkins");
95 county.setCode("TOMPKINS");
96 county.setCountryCode("US");
97
98
99
100
101 county.setStateCode("SS");
102
103 MaintenanceDocument document = getDocument();
104 document.getOldMaintainableObject().setDataObject(null);
105 document.getOldMaintainableObject().setDataObjectClass(county.getClass());
106 document.getNewMaintainableObject().setDataObject(county);
107 document.getNewMaintainableObject().setDataObjectClass(county.getClass());
108
109 document.getNewMaintainableObject().setMaintenanceAction(KRADConstants.MAINTENANCE_NEW_ACTION);
110
111 KRADServiceLocatorWeb.getDocumentService().routeDocument(getDocument(), "submit", null);
112 Assert.assertTrue("ValidationException should have been thrown instead of this assertion failure", getDocument().getDocumentHeader().getWorkflowDocument().isEnroute());
113 }
114 }