Order Resource Param Spec

What is the minimum spec for parameters of a GET MockHttpServletRequest for an Order resource ? Would i be right if i left out params like caresetting ,orderer ,encounter.

and concentrated on status and patient uuid ?

SimpleObject obj = deserialize(handle(newGetRequest(getURI(), new Parameter("status", "active"), new Parameter(
		        "careSetting", RestTestConstants1_10.CARE_SETTING_UUID), new Parameter("includeAll", "true"))));

versus

MockHttpServletRequest request = request(RequestMethod.GET, getURI());
		SimpleObject results;
		String status = "active";
		request.setParameter("status", status);
		results = deserialize(handle(request));

ref https://issues.openmrs.org/browse/RESTWS-716

thoughts @mogoodrich , @dkayiwa

@tendomart , are these lines of any help
OrderResource1_10.java L208-L216 ?

Just in case this is helpful, am thinking the fix to the referenced issue may definitely need to be here

@ruhanga thanks alot.Actually that’s the very method that i refactored , The snippets above are from OrderController1_10Test

so the actual refactoring looks like this

@Override
	protected PageableResult doSearch(RequestContext context) throws ObjectNotFoundException {
		String patientUuid = context.getRequest().getParameter("patient");
		String stat = context.getRequest().getParameter("status");
		if (StringUtils.equals(stat, "active") && StringUtils.isBlank(patientUuid)) {
			//throw new org.databene.commons.ObjectNotFoundException("Sorry You did not Specify a Patient UUID");
			throw new ObjectNotFoundException();
			//return new EmptySearchResult();
		}
		
		if (patientUuid != null) {
			Patient patient = ((PatientResource1_8) Context.getService(RestService.class).getResourceBySupportedClass(
			    Patient.class)).getByUniqueId(patientUuid);
			if (patient == null) {
				//return new EmptySearchResult();
				throw new ObjectNotFoundException();
			}
			
			// if the user indicated a specific type, try to delegate to the appropriate subclass handler
			if (context.getType() != null) {
				PageableResult ret = (PageableResult) findAndInvokeSubclassHandlerMethod(context.getType(),
				    "getActiveOrders", patient, context);
				if (ret != null) {
					return ret;
				}
			}
			
			String careSettingUuid = context.getRequest().getParameter("careSetting");
			String asOfDateString = context.getRequest().getParameter("asOfDate");
			CareSetting careSetting = null;
			Date asOfDate = null;
			if (StringUtils.isNotBlank(asOfDateString)) {
				asOfDate = (Date) ConversionUtil.convert(asOfDateString, Date.class);
			}
			if (StringUtils.isNotBlank(careSettingUuid)) {
				careSetting = ((CareSettingResource1_10) Context.getService(RestService.class).getResourceBySupportedClass(
				    CareSetting.class)).getByUniqueId(careSettingUuid);
			}
			
			String status = context.getRequest().getParameter("status");
			List<Order> orders = OrderUtil.getOrders(patient, careSetting, null, status, asOfDate, context.getIncludeAll());
			// if the user indicated a specific type, and we couldn't delegate to a subclass handler above, filter here
			if (context.getType() != null) {
				filterByType(orders, context.getType());
			}
			
			return new NeedsPaging<Order>(orders, context);
		}
		throw new ObjectNotFoundException();
		//return new EmptySearchResult();
		//throw new NoResultException("Sorry You Did not Specify a Patient UUID");
	}

And either of the two should pass if only order status is passed as param.

We don’t expect a null or "empty result "

The actual methods look like

//@Test
	public void doSearch_ReturnExceptionIfNoPatientUuidIsSpecified() throws Exception {
		MockHttpServletRequest request = request(RequestMethod.GET, getURI());
		SimpleObject results;
		String status = "active";
		request.setParameter("status", status);
		//request.setParameter("patient", PATIENT_UUID);
		results = deserialize(handle(request));
		Object obj = results.getClass();
		
		assertEquals(obj, new ObjectNotFoundException());
		
	}
	
	@Test
	public void doSearch_ReturnExceptionIfNoPatientUuidIsSpecifiedAtAll() throws Exception {
		SimpleObject obj = deserialize(handle(newGetRequest(getURI(), new Parameter("status", "active"), new Parameter(
		        "careSetting", RestTestConstants1_10.CARE_SETTING_UUID), new Parameter("includeAll", "true"))));
		assertEquals(new ObjectNotFoundException(), Util.getResultsList(obj));
	}

is this neccessary ?

    if (StringUtils.equals(stat, "active") && StringUtils.isBlank(patientUuid)) {
		//throw new org.databene.commons.ObjectNotFoundException("Sorry You did not Specify a Patient UUID");
		throw new ObjectNotFoundException();
		//return new EmptySearchResult();
    }

This is because this as mentioned in issue description would fail

/order?status=active&patient=a7bc3378-f769-460c-be02-ef2d15b441a8

What is it that am not seeing here ? Did the issue really say

`/order?status=active&patient=a7bc3378-f769-460c-be02-ef2d15b441a8`  would fail ?

Okay @tendomart, I got the matter , but my simple thought is the block I referred to could be sort of a potential duplicate to the last throw new ObjectNotFoundException(); statement in the code snippet.

@ruhanga alright thanks, i was just waiting to see how you would throw that exception.