Example usage for org.apache.solr.common.params CommonParams ID

List of usage examples for org.apache.solr.common.params CommonParams ID

Introduction

In this page you can find the example usage for org.apache.solr.common.params CommonParams ID.

Prototype

String ID

To view the source code for org.apache.solr.common.params CommonParams ID.

Click Source Link

Usage

From source file:org.alfresco.solr.SolrInformationServer.java

License:Open Source License

SolrDocument getState(SolrCore core, SolrQueryRequest request, String id) {
    ModifiableSolrParams newParams = new ModifiableSolrParams(request.getParams()).set(CommonParams.ID, id);
    request.setParams(newParams);//from  w  ww . ja va2  s.  c  om

    SolrQueryResponse response = newSolrQueryResponse();
    core.getRequestHandler(REQUEST_HANDLER_GET).handleRequest(request, response);

    NamedList values = response.getValues();
    return (SolrDocument) values.get(RESPONSE_DEFAULT_ID);
}

From source file:org.alfresco.solr.SolrInformationServerTest.java

License:Open Source License

@Test
public void testGetStateOk() {
    String id = String.valueOf(System.currentTimeMillis());

    SolrDocument state = new SolrDocument();

    SimpleOrderedMap responseContent = new SimpleOrderedMap<>();
    responseContent.add(SolrInformationServer.RESPONSE_DEFAULT_ID, state);

    when(response.getValues()).thenReturn(responseContent);
    when(core.getRequestHandler(SolrInformationServer.REQUEST_HANDLER_GET)).thenReturn(handler);

    SolrDocument document = infoServer.getState(core, request, id);

    assertEquals(id, request.getParams().get(CommonParams.ID));
    verify(core).getRequestHandler(SolrInformationServer.REQUEST_HANDLER_GET);
    verify(response).getValues();/*from w  ww. jav  a  2  s  .co m*/

    assertSame(state, document);
}

From source file:org.alfresco.solr.SolrInformationServerTest.java

License:Open Source License

/**
 * GetState returns null in case the given id doesn't correspond to an existing state document.
 *//*from  w  ww.  j  av a2 s  . c  om*/
@Test
public void testGetStateWithStateNotFound_returnsNull() {
    String id = String.valueOf(System.currentTimeMillis());

    SimpleOrderedMap responseContent = new SimpleOrderedMap<>();
    responseContent.add(SolrInformationServer.RESPONSE_DEFAULT_ID, null);

    when(response.getValues()).thenReturn(responseContent);
    when(core.getRequestHandler(SolrInformationServer.REQUEST_HANDLER_GET)).thenReturn(handler);

    SolrDocument document = infoServer.getState(core, request, id);

    assertEquals(id, request.getParams().get(CommonParams.ID));
    verify(core).getRequestHandler(SolrInformationServer.REQUEST_HANDLER_GET);
    verify(response).getValues();

    assertNull(document);
}