### Question:
SearchContextImpl implements SearchContext { public <T> SearchCondition<T> getCondition(Class<T> cls) { return getCondition(null, cls); } 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 testWrongQueryNoException() { Message m = new MessageImpl(); m.put("search.block.search.exception", true); m.put(Message.QUERY_STRING, "_s=ab"); assertNull(new SearchContextImpl(m).getCondition(Book.class)); }
@Test(expected = SearchParseException.class) public void testWrongQueryException() { Message m = new MessageImpl(); m.put(Message.QUERY_STRING, "_s=ab"); new SearchContextImpl(m).getCondition(Book.class); }
@Test(expected = IllegalArgumentException.class) public void testIllegalConditionType() { SearchContext context = new SearchContextImpl(new MessageImpl()); context.getCondition(String.class); }
@Test public void testPrimitiveStatementSearchBean() { Message m = new MessageImpl(); m.put(Message.QUERY_STRING, "_s=name==CXF"); SearchContext context = new SearchContextImpl(m); SearchCondition<SearchBean> sc = context.getCondition(SearchBean.class); assertNotNull(sc); PrimitiveStatement ps = sc.getStatement(); assertNotNull(ps); assertEquals("name", ps.getProperty()); assertEquals("CXF", ps.getValue()); assertEquals(ConditionType.EQUALS, ps.getCondition()); assertEquals(String.class, ps.getValueType()); }
@Test public void testPrimitiveStatementSearchBeanComlexName() { Message m = new MessageImpl(); m.put(Message.QUERY_STRING, "_s=complex.name==CXF"); SearchContext context = new SearchContextImpl(m); SearchCondition<SearchBean> sc = context.getCondition(SearchBean.class); assertNotNull(sc); PrimitiveStatement ps = sc.getStatement(); assertNotNull(ps); assertEquals("complex.name", ps.getProperty()); assertEquals("CXF", ps.getValue()); assertEquals(ConditionType.EQUALS, ps.getCondition()); assertEquals(String.class, ps.getValueType()); }
@Test public void testSingleEquals() { Message m = new MessageImpl(); m.put(Message.QUERY_STRING, "_s=name=CXF"); m.put("fiql.support.single.equals.operator", "true"); SearchContext context = new SearchContextImpl(m); SearchCondition<SearchBean> sc = context.getCondition(SearchBean.class); assertNotNull(sc); PrimitiveStatement ps = sc.getStatement(); assertNotNull(ps); assertEquals("name", ps.getProperty()); assertEquals("CXF", ps.getValue()); assertEquals(ConditionType.EQUALS, ps.getCondition()); assertEquals(String.class, ps.getValueType()); }