1 package org.kuali.student.enrollment.class1.hold.service.impl;
2
3 import org.junit.Test;
4 import org.junit.runner.RunWith;
5 import org.kuali.rice.core.api.criteria.PredicateFactory;
6 import org.kuali.rice.core.api.criteria.QueryByCriteria;
7 import org.kuali.student.common.test.util.AttributeTester;
8 import org.kuali.student.r2.common.exceptions.DataValidationErrorException;
9 import org.kuali.student.r2.common.exceptions.InvalidParameterException;
10 import org.kuali.student.r2.common.exceptions.MissingParameterException;
11 import org.kuali.student.r2.common.exceptions.OperationFailedException;
12 import org.kuali.student.r2.common.exceptions.PermissionDeniedException;
13 import org.kuali.student.r2.common.exceptions.ReadOnlyException;
14 import org.kuali.student.r2.common.util.RichTextHelper;
15 import org.kuali.student.r2.core.constants.HoldServiceConstants;
16 import org.kuali.student.r2.core.hold.dto.AppliedHoldInfo;
17 import org.kuali.student.r2.core.hold.dto.HoldIssueInfo;
18 import org.springframework.test.context.ContextConfiguration;
19 import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
20 import org.springframework.test.context.transaction.TransactionConfiguration;
21 import org.springframework.transaction.annotation.Transactional;
22
23 import java.util.Date;
24 import java.util.List;
25
26 import static org.junit.Assert.assertEquals;
27 import static org.junit.Assert.assertNotNull;
28 import static org.junit.Assert.assertTrue;
29
30
31 @RunWith(SpringJUnit4ClassRunner.class)
32 @ContextConfiguration(locations = {"classpath:hold-test-context.xml"})
33 @TransactionConfiguration(transactionManager = "JtaTxManager", defaultRollback = true)
34 @Transactional
35 public class TestHoldServiceJpaPersistenceImpl extends TestHoldServiceMockImpl {
36
37
38 @Test
39 public void testSearchForAppliedHoldIds() throws InvalidParameterException, DataValidationErrorException, MissingParameterException, ReadOnlyException, PermissionDeniedException, OperationFailedException {
40
41 HoldIssueInfo myIssue = new HoldIssueInfo();
42 myIssue.setName("name of issue");
43 myIssue.setDescr(new RichTextHelper().fromPlain("description of issue"));
44 myIssue.setOrganizationId("org1");
45 myIssue.setTypeKey(HoldServiceConstants.ACADEMIC_PROGRESS_ISSUE_TYPE_KEY);
46 myIssue.setStateKey(HoldServiceConstants.ISSUE_INACTIVE_STATE_KEY);
47 new AttributeTester().add2ForCreate(myIssue.getAttributes());
48 HoldIssueInfo actualIssue = getHoldService().createHoldIssue(myIssue.getTypeKey(), myIssue, callContext);
49
50 AppliedHoldInfo expected = new AppliedHoldInfo();
51 expected.setPersonId("student1");
52 expected.setHoldIssueId(actualIssue.getId());
53 expected.setName("name of hold");
54 expected.setDescr(new RichTextHelper().fromPlain("description of hold"));
55 expected.setEffectiveDate(new Date());
56 expected.setReleasedDate(new Date());
57 expected.setTypeKey(HoldServiceConstants.STUDENT_HOLD_TYPE_KEY);
58 expected.setStateKey(HoldServiceConstants.HOLD_ACTIVE_STATE_KEY);
59 new AttributeTester().add2ForCreate(expected.getAttributes());
60 AppliedHoldInfo actual = getHoldService().createAppliedHold(expected.getPersonId(), expected.getHoldIssueId(), expected.getTypeKey(), expected,
61 callContext);
62 assertNotNull(actual.getId());
63
64 QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
65 qbcBuilder.setPredicates(PredicateFactory.equal("id", actual.getId()));
66 QueryByCriteria qbc = qbcBuilder.build();
67 List<String> results = getHoldService().searchForAppliedHoldIds(qbc, callContext);
68
69 assertTrue(results.size() == 1);
70 String myResult = results.get(0);
71 assertEquals(actual.getId(), myResult);
72 }
73
74 @Test
75 public void testSearchForAppliedHolds() throws InvalidParameterException, MissingParameterException, PermissionDeniedException, OperationFailedException, DataValidationErrorException, ReadOnlyException {
76
77 HoldIssueInfo myIssue = new HoldIssueInfo();
78 myIssue.setName("name of issue");
79 myIssue.setDescr(new RichTextHelper().fromPlain("description of issue"));
80 myIssue.setOrganizationId("org1");
81 myIssue.setTypeKey(HoldServiceConstants.ACADEMIC_PROGRESS_ISSUE_TYPE_KEY);
82 myIssue.setStateKey(HoldServiceConstants.ISSUE_INACTIVE_STATE_KEY);
83 new AttributeTester().add2ForCreate(myIssue.getAttributes());
84 HoldIssueInfo actualIssue = getHoldService().createHoldIssue(myIssue.getTypeKey(), myIssue, callContext);
85
86 AppliedHoldInfo expected = new AppliedHoldInfo();
87 expected.setPersonId("student1");
88 expected.setHoldIssueId(actualIssue.getId());
89 expected.setName("name of hold");
90 expected.setDescr(new RichTextHelper().fromPlain("description of hold"));
91 expected.setEffectiveDate(new Date());
92 expected.setReleasedDate(new Date());
93 expected.setTypeKey(HoldServiceConstants.STUDENT_HOLD_TYPE_KEY);
94 expected.setStateKey(HoldServiceConstants.HOLD_ACTIVE_STATE_KEY);
95 new AttributeTester().add2ForCreate(expected.getAttributes());
96 AppliedHoldInfo actual = getHoldService().createAppliedHold(expected.getPersonId(), expected.getHoldIssueId(), expected.getTypeKey(), expected,
97 callContext);
98 assertNotNull(actual.getId());
99
100 QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
101 qbcBuilder.setPredicates(PredicateFactory.equal("id", actual.getId()),
102 PredicateFactory.equal("attributes[attribute.key1]", "attribute value1"));
103 QueryByCriteria qbc = qbcBuilder.build();
104 List<AppliedHoldInfo> results = getHoldService().searchForAppliedHolds(qbc, callContext);
105
106 assertTrue(results.size() == 1);
107 AppliedHoldInfo myResult = results.get(0);
108 assertEquals(actual.getId(), myResult.getId());
109 new AttributeTester().check(actual.getAttributes(), myResult.getAttributes());
110 }
111
112 @Test
113 public void testSearchForHoldIssueIds() throws InvalidParameterException, DataValidationErrorException, MissingParameterException, ReadOnlyException, PermissionDeniedException, OperationFailedException {
114
115 HoldIssueInfo myIssue = new HoldIssueInfo();
116 myIssue.setName("name of issue");
117 myIssue.setDescr(new RichTextHelper().fromPlain("description of issue"));
118 myIssue.setOrganizationId("org1");
119 myIssue.setTypeKey(HoldServiceConstants.ACADEMIC_PROGRESS_ISSUE_TYPE_KEY);
120 myIssue.setStateKey(HoldServiceConstants.ISSUE_INACTIVE_STATE_KEY);
121 new AttributeTester().add2ForCreate(myIssue.getAttributes());
122 HoldIssueInfo actualIssue = getHoldService().createHoldIssue(myIssue.getTypeKey(), myIssue, callContext);
123 assertNotNull(actualIssue.getId());
124
125 QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
126 qbcBuilder.setPredicates(PredicateFactory.equal("id", actualIssue.getId()));
127 QueryByCriteria qbc = qbcBuilder.build();
128 List<String> results = getHoldService().searchForHoldIssueIds(qbc, callContext);
129
130 assertTrue(results.size() == 1);
131 String myResult = results.get(0);
132 assertEquals(actualIssue.getId(), myResult);
133 }
134
135 @Test
136 public void testSearchForHoldIssues() throws InvalidParameterException, DataValidationErrorException, MissingParameterException, ReadOnlyException, PermissionDeniedException, OperationFailedException {
137
138 HoldIssueInfo myIssue = new HoldIssueInfo();
139 myIssue.setName("name of issue");
140 myIssue.setDescr(new RichTextHelper().fromPlain("description of issue"));
141 myIssue.setOrganizationId("org1");
142 myIssue.setTypeKey(HoldServiceConstants.ACADEMIC_PROGRESS_ISSUE_TYPE_KEY);
143 myIssue.setStateKey(HoldServiceConstants.ISSUE_INACTIVE_STATE_KEY);
144 new AttributeTester().add2ForCreate(myIssue.getAttributes());
145 HoldIssueInfo actualIssue = getHoldService().createHoldIssue(myIssue.getTypeKey(), myIssue, callContext);
146 assertNotNull(actualIssue.getId());
147
148 QueryByCriteria.Builder qbcBuilder = QueryByCriteria.Builder.create();
149 qbcBuilder.setPredicates(PredicateFactory.equal("id", actualIssue.getId()));
150 QueryByCriteria qbc = qbcBuilder.build();
151 List<HoldIssueInfo> results = getHoldService().searchForHoldIssues(qbc, callContext);
152
153 assertTrue(results.size() == 1);
154 HoldIssueInfo myResult = results.get(0);
155 assertEquals(actualIssue.getId(), myResult.getId());
156 new AttributeTester().check(actualIssue.getAttributes(), myResult.getAttributes());
157 }
158 }