### Question:
SenchaParseRequestStage extends ParseRequestStage { @Override protected <T> void doExecute(SelectContext<T> context) { super.doExecute(context); Map<String, List<String>> protocolParameters = context.getProtocolParameters(); SenchaRequest.Builder builder = SenchaRequest.builder() .filters(filterParser.fromString(ParameterExtractor.string(protocolParameters, FILTER))); SenchaRequest.set(context, builder.build()); } SenchaParseRequestStage(
            @Inject IAgRequestBuilderFactory requestBuilderFactory,
            @Inject ISenchaFilterParser filterParser);   }### Answer:
@Test public void testSelectRequest_Filter() { @SuppressWarnings("unchecked") MultivaluedMap<String, String> params = mock(MultivaluedMap.class); when(params.get(SenchaParseRequestStage.FILTER)).thenReturn(Collections.singletonList("[{\"property\":\"name\",\"value\":\"xyz\"}]")); SelectContext<E2> context = prepareContext(params, E2.class); parseStage.doExecute(context); SenchaRequest senchaRequest = SenchaRequest.get(context); assertNotNull(senchaRequest); assertFalse(senchaRequest.getFilters().isEmpty()); assertEquals("name", senchaRequest.getFilters().get(0).getProperty()); assertEquals("xyz", senchaRequest.getFilters().get(0).getValue()); assertEquals("like", senchaRequest.getFilters().get(0).getOperator()); }
@Test public void testSelectRequest_Filter_CayenneExp() { @SuppressWarnings("unchecked") MultivaluedMap<String, String> params = mock(MultivaluedMap.class); when(params.get("cayenneExp")).thenReturn(Collections.singletonList("{\"exp\" : \"address = '1 Main Street'\"}")); when(params.get(SenchaParseRequestStage.FILTER)).thenReturn(Collections.singletonList("[{\"property\":\"name\",\"value\":\"xyz\"}]")); SelectContext<E2> context = prepareContext(params, E2.class); parseStage.doExecute(context); SenchaRequest senchaRequest = SenchaRequest.get(context); assertNotNull(senchaRequest); assertFalse(senchaRequest.getFilters().isEmpty()); assertEquals("name", senchaRequest.getFilters().get(0).getProperty()); assertEquals("xyz", senchaRequest.getFilters().get(0).getValue()); assertEquals("like", senchaRequest.getFilters().get(0).getOperator()); AgRequest request = context.getMergedRequest(); assertNotNull(request.getCayenneExp()); assertEquals("address = '1 Main Street'", request.getCayenneExp().getExp()); }
@Test public void testSelectRequest_Sort_Group() { @SuppressWarnings("unchecked") MultivaluedMap<String, String> params = mock(MultivaluedMap.class); when(params.get("sort")).thenReturn( Collections.singletonList("[{\"property\":\"name\",\"direction\":\"DESC\"},{\"property\":\"address\",\"direction\":\"ASC\"}]")); when(params.get(SenchaParseRequestStage.GROUP)).thenReturn( Collections.singletonList("[{\"property\":\"id\",\"direction\":\"DESC\"},{\"property\":\"address\",\"direction\":\"ASC\"}]")); SelectContext<E2> context = prepareContext(params, E2.class); parseStage.doExecute(context); List<Sort> orderings = context.getMergedRequest().getOrderings(); assertEquals(4, orderings.size()); assertEquals("id", orderings.get(0).getProperty()); assertEquals(Dir.DESC, orderings.get(0).getDirection()); assertEquals("address", orderings.get(1).getProperty()); assertEquals(Dir.ASC, orderings.get(1).getDirection()); assertEquals("name", orderings.get(2).getProperty()); assertEquals(Dir.DESC, orderings.get(2).getDirection()); assertEquals("address", orderings.get(3).getProperty()); assertEquals(Dir.ASC, orderings.get(3).getDirection()); }