-
Notifications
You must be signed in to change notification settings - Fork 545
RESTWS-760: changed the way the drug property was accessed to represe… #650
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
Open
Kalanzifrank1
wants to merge
1
commit into
openmrs:master
Choose a base branch
from
Kalanzifrank1:RESTWS-760
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,12 +13,23 @@ | |
import org.openmrs.Drug; | ||
import org.openmrs.DrugOrder; | ||
import org.openmrs.Order; | ||
import org.openmrs.api.OrderService; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.webservices.rest.web.ConversionUtil; | ||
import org.openmrs.module.webservices.rest.web.representation.DefaultRepresentation; | ||
import org.openmrs.module.webservices.rest.web.representation.Representation; | ||
import org.openmrs.module.webservices.rest.web.resource.impl.DelegatingResourceDescription; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.junit.Before; | ||
import static org.junit.Assert.*; | ||
import static org.hamcrest.CoreMatchers.is; | ||
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. |
||
|
||
|
||
import static org.hamcrest.core.Is.is; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class DrugOrderSubclassHandler1_10Test { | ||
|
||
|
||
|
||
@Test | ||
public void getDisplayString_shouldNotFailForDcOrder() throws Exception { | ||
Drug drug = new Drug(); | ||
|
@@ -31,4 +42,6 @@ public void getDisplayString_shouldNotFailForDcOrder() throws Exception { | |
String actual = DrugOrderSubclassHandler1_10.getDisplay(order); | ||
assertThat(actual, is("(DISCONTINUE) Aspirin")); | ||
} | ||
|
||
|
||
} |
55 changes: 55 additions & 0 deletions
55
...ule/webservices/rest/web/v1_0/resource/openmrs1_10/DrugOrderSubclassHandler1_10Test2.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.webservices.rest.web.v1_0.resource.openmrs1_10; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openmrs.Drug; | ||
import org.openmrs.DrugOrder; | ||
import org.openmrs.Order; | ||
import org.openmrs.OrderType; | ||
|
||
import static org.junit.Assert.*; | ||
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. We generally dont recommend wildcards. Have a look at the conventions at https://openmrs.atlassian.net/wiki/x/tL_EAQ |
||
|
||
public class DrugOrderSubclassHandler1_10Test2 { | ||
|
||
private DrugOrderSubclassHandler1_10 handler; | ||
|
||
@Before | ||
public void setup() { | ||
handler = new DrugOrderSubclassHandler1_10(); | ||
} | ||
|
||
@Test | ||
public void shouldIncludeDrugStrengthInDisplay() { | ||
// Create test drug | ||
Drug drug = new Drug(); | ||
drug.setName("Aspirin"); | ||
drug.setStrength("325 mg"); | ||
|
||
// Create test order type | ||
OrderType drugOrderType = new OrderType(); | ||
drugOrderType.setName("Drug order"); | ||
|
||
// Create test order | ||
DrugOrder order = new DrugOrder(); | ||
order.setDrug(drug); | ||
order.setOrderType(drugOrderType); | ||
order.setAction(Order.Action.NEW); | ||
|
||
// Test the display string | ||
String display = DrugOrderSubclassHandler1_10.getDisplay(order); | ||
|
||
// Verify results | ||
assertNotNull("Display should not be null", display); | ||
assertTrue("Display should contain drug name: " + display, display.contains("Aspirin")); | ||
assertTrue("Display should contain strength: " + display, display.contains("325 mg")); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
117 changes: 117 additions & 0 deletions
117
...mrs/module/webservices/rest/web/v1_0/controller/openmrs1_12/OrderController1_12Test2.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
/** | ||
* This Source Code Form is subject to the terms of the Mozilla Public License, | ||
* v. 2.0. If a copy of the MPL was not distributed with this file, You can | ||
* obtain one at http://mozilla.org/MPL/2.0/. OpenMRS is also distributed under | ||
* the terms of the Healthcare Disclaimer located at http://openmrs.org/license. | ||
* | ||
* Copyright (C) OpenMRS Inc. OpenMRS is a registered trademark and the OpenMRS | ||
* graphic logo is a trademark of OpenMRS Inc. | ||
*/ | ||
package org.openmrs.module.webservices.rest.web.v1_0.controller.openmrs1_12; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.openmrs.Drug; | ||
import org.openmrs.DrugOrder; | ||
import org.openmrs.Order; | ||
import org.openmrs.OrderType; | ||
import org.openmrs.api.OrderService; | ||
import org.openmrs.api.context.Context; | ||
import org.openmrs.module.webservices.rest.web.RestConstants; | ||
import org.openmrs.module.webservices.rest.web.response.ResponseException; | ||
import org.springframework.mock.web.MockHttpServletRequest; | ||
import org.springframework.mock.web.MockHttpServletResponse; | ||
|
||
import java.util.Map; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotNull; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class OrderController1_12Test2 { | ||
|
||
private OrderService orderService; | ||
private static final String ORDER_URI = "/rest/v1/order"; | ||
|
||
@Before | ||
public void init() throws Exception { | ||
orderService = Context.getOrderService(); | ||
|
||
// Setup minimal test data | ||
OrderType drugOrderType = new OrderType(); | ||
drugOrderType.setName("Drug order"); | ||
orderService.saveOrderType(drugOrderType); | ||
} | ||
|
||
@Test | ||
public void getOrder_shouldIncludeDrugStrength() throws Exception { | ||
// Given | ||
Drug drug = new Drug(); | ||
drug.setName("Aspirin"); | ||
drug.setStrength("325 mg"); | ||
DrugOrder order = createAndSaveDrugOrder(drug); | ||
|
||
// When | ||
MockHttpServletRequest request = newGetRequest(ORDER_URI + "/" + order.getUuid(), | ||
new Parameter(RestConstants.REQUEST_PROPERTY_FOR_REPRESENTATION, RestConstants.REPRESENTATION_FULL)); | ||
|
||
MockHttpServletResponse response = new MockHttpServletResponse(); | ||
handle(request, response); | ||
|
||
// Then | ||
Map<String, Object> result = readResponse(response); | ||
Map<String, Object> drugRep = (Map<String, Object>) result.get("drug"); | ||
assertNotNull("Drug representation should not be null", drugRep); | ||
assertEquals("325 mg", drugRep.get("strength")); | ||
} | ||
|
||
private DrugOrder createAndSaveDrugOrder(Drug drug) throws ResponseException { | ||
OrderType drugOrderType = orderService.getOrderTypeByName("Drug order"); | ||
|
||
DrugOrder order = new DrugOrder(); | ||
order.setDrug(drug); | ||
order.setOrderType(drugOrderType); | ||
order.setAction(Order.Action.NEW); | ||
|
||
// Cast to DrugOrder is safe here since we're creating a DrugOrder | ||
return (DrugOrder) orderService.saveOrder(order, null); | ||
} | ||
|
||
// Helper methods to replace BaseCrudControllerTest functionality | ||
private MockHttpServletRequest newGetRequest(String uri, Parameter... parameters) { | ||
MockHttpServletRequest request = new MockHttpServletRequest("GET", uri); | ||
for (Parameter parameter : parameters) { | ||
request.addParameter(parameter.getName(), parameter.getValue()); | ||
} | ||
return request; | ||
} | ||
|
||
private void handle(MockHttpServletRequest request, MockHttpServletResponse response) throws Exception { | ||
// Implementation would depend on your controller setup | ||
// This is a placeholder for actual request handling | ||
} | ||
|
||
private Map<String, Object> readResponse(MockHttpServletResponse response) throws Exception { | ||
// Implementation would parse the JSON response | ||
// This is a placeholder for actual response parsing | ||
return null; | ||
} | ||
|
||
public static class Parameter { | ||
private final String name; | ||
private final String value; | ||
|
||
public Parameter(String name, String value) { | ||
this.name = name; | ||
this.value = value; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public String getValue() { | ||
return value; | ||
} | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.