### Question:
SearchContextImpl implements SearchContext { public String getSearchExpression() { String queryStr = (String)message.get(Message.QUERY_STRING); if (queryStr != null) { if (MessageUtils.getContextualBoolean(message, USE_ALL_QUERY_COMPONENT)) { return queryStr; } boolean encoded = PropertyUtils.isTrue(getKeepEncodedProperty()); MultivaluedMap<String, String> params = JAXRSUtils.getStructuredParams(queryStr, "&", !encoded, false); String customQueryParamName = (String)message.getContextualProperty(CUSTOM_SEARCH_QUERY_PARAM_NAME); if (customQueryParamName != null) { return params.getFirst(customQueryParamName); } if (queryStr.contains(SHORT_SEARCH_QUERY) || queryStr.contains(SEARCH_QUERY)) { if (params.containsKey(SHORT_SEARCH_QUERY)) { return params.getFirst(SHORT_SEARCH_QUERY); } return params.getFirst(SEARCH_QUERY); } else if (MessageUtils.getContextualBoolean(message, USE_PLAIN_QUERY_PARAMETERS)) { return convertPlainQueriesToFiqlExp(params); } } return null; } SearchContextImpl(Message message); SearchCondition<T> getCondition(Class<T> cls); SearchCondition<T> getCondition(Class<T> cls, Map<String, String> beanProperties); SearchCondition<T> getCondition(Class<T> cls,
                                               Map<String, String> beanProperties,
                                               Map<String, String> parserProperties); SearchCondition<T> getCondition(String expression, Class<T> cls); SearchCondition<T> getCondition(String expression,
                                               Class<T> cls,
                                               Map<String, String> beanProperties); SearchCondition<T> getCondition(String expression,
                                               Class<T> cls,
                                               Map<String, String> beanProperties,
                                               Map<String, String> parserProperties); String getSearchExpression(); static final String SEARCH_QUERY; static final String SHORT_SEARCH_QUERY; static final String CUSTOM_SEARCH_PARSER_PROPERTY; static final String CUSTOM_SEARCH_PARSER_CLASS_PROPERTY; static final String CUSTOM_SEARCH_QUERY_PARAM_NAME; }### Answer:
@Test public void testPlainQuery1() { Message m = new MessageImpl(); m.put("search.use.plain.queries", true); m.put(Message.QUERY_STRING, "a=b"); String exp = new SearchContextImpl(m).getSearchExpression(); assertEquals("a==b", exp); }
@Test public void testPlainQuery2() { Message m = new MessageImpl(); m.put("search.use.plain.queries", true); m.put(Message.QUERY_STRING, "a=b&a=b1"); String exp = new SearchContextImpl(m).getSearchExpression(); assertEquals("(a==b,a==b1)", exp); }
@Test public void testPlainQuery3() { Message m = new MessageImpl(); m.put("search.use.plain.queries", true); m.put(Message.QUERY_STRING, "a=b&c=d"); String exp = new SearchContextImpl(m).getSearchExpression(); assertEquals("(a==b;c==d)", exp); }
@Test public void testPlainQuery4() { Message m = new MessageImpl(); m.put("search.use.plain.queries", true); m.put(Message.QUERY_STRING, "a=b&a=b2&c=d&f=g"); String exp = new SearchContextImpl(m).getSearchExpression(); assertEquals("((a==b,a==b2);c==d;f==g)", exp); }
@Test public void testPlainQuery5() { Message m = new MessageImpl(); m.put("search.use.plain.queries", true); m.put(Message.QUERY_STRING, "aFrom=1&aTill=3"); String exp = new SearchContextImpl(m).getSearchExpression(); assertEquals("(a=ge=1;a=le=3)", exp); }