-
Notifications
You must be signed in to change notification settings - Fork 519
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RESTWS-904 Support custom representation for Map objects #602
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,7 @@ | |
package org.openmrs.module.webservices.rest.web; | ||
|
||
import static org.hamcrest.core.Is.is; | ||
import org.junit.Assert; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertThat; | ||
|
||
import java.lang.reflect.Method; | ||
|
@@ -25,8 +25,11 @@ | |
import java.util.TimeZone; | ||
|
||
import org.apache.commons.beanutils.PropertyUtils; | ||
import org.junit.Assert; | ||
import org.junit.Test; | ||
import org.openmrs.api.ConceptNameType; | ||
import org.openmrs.module.webservices.rest.SimpleObject; | ||
import org.openmrs.module.webservices.rest.web.representation.CustomRepresentation; | ||
import org.openmrs.module.webservices.rest.web.representation.Representation; | ||
import org.openmrs.web.test.BaseModuleWebContextSensitiveTest; | ||
|
||
|
@@ -145,6 +148,26 @@ public void convert_shouldConvertToAClass() throws Exception { | |
Assert.assertTrue(converted.isAssignableFrom(String.class)); | ||
} | ||
|
||
@Test | ||
public void convert_shouldConvertSimpleObjectToCustomRepresentation() throws Exception { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The method name does not seem to reflect the work being done by the ticket? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The ticket is about not being able to get custom representations with audit info. So bassically it's enough to assert that it can properly convert simple objects to a given custom representation. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dkayiwa Can we merge this fix? |
||
|
||
SimpleObject child = new SimpleObject(); | ||
child.put("child_key_1", "child_val_1"); | ||
child.put("child_key_2", "child_val_2"); | ||
SimpleObject parent = new SimpleObject(); | ||
parent.put("parent_key_1", child); | ||
parent.put("parent_key_2", "parent_val_2"); | ||
|
||
Object o = ConversionUtil.convertToRepresentation(parent, new CustomRepresentation("parent_key_1:(child_key_1)")); | ||
|
||
SimpleObject expectedChild = new SimpleObject(); | ||
expectedChild.put("child_key_1", "child_val_1"); | ||
SimpleObject expectedParent = new SimpleObject(); | ||
expectedParent.put("parent_key_1", expectedChild); | ||
|
||
assertEquals(expectedParent, o); | ||
} | ||
|
||
public void convert_shouldConvertIntToDouble() throws Exception { | ||
assertThat((Double) ConversionUtil.convert(5, Double.class), is(5d)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't this be in
ConversionUtilTest
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PatientIdentifierTypeController1_8Test
also include a test namedshouldReturnTheAuditInfoForTheFullRepresentation
. So it's nice to have a matching E2E test for converting to a custom representation.The new method that we introuduced in
ConversionUtil
isprivate
. So I think it makes sense to have it here instead.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you directly calling this private method from the test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, the private method is not called directly in the test. The test makes a GET call to the resource with custom representation as the
v
param.openmrs-module-webservices.rest/omod-1.8/src/test/java/org/openmrs/module/webservices/rest/web/v1_0/controller/openmrs1_8/PatientIdentifierTypeController1_8Test.java
Lines 174 to 176 in 9eb0e4d
Assertions in this test should be enough to prevent someone from breaking things again :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And the private method is fully covered by this test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the test is for a change in ConversionUtil, is there a reason why you do not put the test in ConversionUtilTest?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gayanW did you see the above comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry for the late reply. I've been busy with work.
I don't think it would be good to put Mock Http test in ConversionUtil.
Additionally I could write a new unit test for
ConversionUtil#convertToRepresentation
inConversionUtilTest
. Let me check that on the weekend.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I added a new unit test to
ConversionUtilTest
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dkayiwa Can you check :)