|
18 | 18 | import static org.hamcrest.Matchers.hasKey;
|
19 | 19 | import static org.hamcrest.Matchers.hasSize;
|
20 | 20 |
|
| 21 | +import java.util.ArrayList; |
| 22 | +import java.util.List; |
21 | 23 | import java.util.Map;
|
22 | 24 |
|
23 | 25 | import org.junit.Before;
|
24 | 26 | import org.junit.Test;
|
25 | 27 | import org.openmrs.Patient;
|
| 28 | +import org.openmrs.PatientIdentifier; |
26 | 29 | import org.openmrs.Person;
|
27 | 30 | import org.openmrs.module.webservices.rest.web.RequestContext;
|
| 31 | +import org.openmrs.module.webservices.rest.web.annotation.PropertyGetter; |
| 32 | +import org.openmrs.module.webservices.rest.web.annotation.PropertySetter; |
28 | 33 | import org.openmrs.module.webservices.rest.web.resource.api.Resource;
|
29 | 34 | import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingCrudResource;
|
30 | 35 | import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription;
|
@@ -152,6 +157,29 @@ public void discoverResourceProperties_shouldCombineGetDelegateTypeAndDiscoverAv
|
152 | 157 | assertThat(properties, hasKey("birthdate"));
|
153 | 158 | }
|
154 | 159 |
|
| 160 | + /** |
| 161 | + * @see SchemaIntrospectionServiceImpl#discoverResourceProperties(Resource) |
| 162 | + */ |
| 163 | + @Test |
| 164 | + public void discoverResourceProperties_shouldIncludePropertiesFromAnnotations() { |
| 165 | + TestPatientResourceWithAnnotations resource = new TestPatientResourceWithAnnotations(); |
| 166 | + Map<String, String> properties = service.discoverResourceProperties(resource); |
| 167 | + |
| 168 | + // Verify standard properties from the delegate type |
| 169 | + assertThat(properties, hasKey("uuid")); |
| 170 | + assertThat(properties, hasKey("patientId")); |
| 171 | + |
| 172 | + // Verify properties defined by @PropertyGetter annotations |
| 173 | + assertThat(properties, hasKey("activeIdentifiers")); |
| 174 | + assertThat(properties, hasKey("displayName")); |
| 175 | + assertThat(properties, hasEntry("activeIdentifiers", "List<PatientIdentifier>")); |
| 176 | + assertThat(properties, hasEntry("displayName", "String")); |
| 177 | + |
| 178 | + // Verify properties defined by @PropertySetter annotations |
| 179 | + assertThat(properties, hasKey("preferredName")); |
| 180 | + assertThat(properties, hasEntry("preferredName", "String")); |
| 181 | + } |
| 182 | + |
155 | 183 | /**
|
156 | 184 | * Mock DelegatingCrudResource for testing
|
157 | 185 | */
|
@@ -187,6 +215,58 @@ public void delete(Patient delegate, String reason, RequestContext context) thro
|
187 | 215 | }
|
188 | 216 | }
|
189 | 217 |
|
| 218 | + /** |
| 219 | + * Mock DelegatingCrudResource for testing PropertyGetter and PropertySetter annotations |
| 220 | + */ |
| 221 | + private class TestPatientResourceWithAnnotations extends DelegatingCrudResource<Patient> { |
| 222 | + |
| 223 | + @PropertyGetter("activeIdentifiers") |
| 224 | + public List<PatientIdentifier> getActiveIdentifiers(Patient patient) { |
| 225 | + return new ArrayList<PatientIdentifier>(); |
| 226 | + } |
| 227 | + |
| 228 | + @PropertyGetter("displayName") |
| 229 | + public String getDisplayName(Patient patient) { |
| 230 | + return patient.getPersonName().getFullName(); |
| 231 | + } |
| 232 | + |
| 233 | + @PropertySetter("preferredName") |
| 234 | + public void setPreferredName(Patient patient, String name) { |
| 235 | + // Implementation not needed for test |
| 236 | + } |
| 237 | + |
| 238 | + // Standard resource methods |
| 239 | + |
| 240 | + @Override |
| 241 | + public Patient newDelegate() { |
| 242 | + return new Patient(); |
| 243 | + } |
| 244 | + |
| 245 | + @Override |
| 246 | + public Patient save(Patient delegate) { |
| 247 | + return delegate; |
| 248 | + } |
| 249 | + |
| 250 | + @Override |
| 251 | + public Patient getByUniqueId(String uniqueId) { |
| 252 | + return new Patient(); |
| 253 | + } |
| 254 | + |
| 255 | + @Override |
| 256 | + public void purge(Patient delegate, RequestContext context) { |
| 257 | + } |
| 258 | + |
| 259 | + @Override |
| 260 | + public DelegatingResourceDescription getRepresentationDescription(Representation rep) { |
| 261 | + return null; |
| 262 | + } |
| 263 | + |
| 264 | + @Override |
| 265 | + public void delete(Patient delegate, String reason, RequestContext context) throws ResourceDoesNotSupportOperationException { |
| 266 | + throw new ResourceDoesNotSupportOperationException(); |
| 267 | + } |
| 268 | + } |
| 269 | + |
190 | 270 | /**
|
191 | 271 | * Mock DelegatingSubResource for testing
|
192 | 272 | */
|
|
0 commit comments