コード例 #1
0
  @Test
  public void testStreamURL() throws Exception {
    boolean ok = false;
    String url = "http://www.apache.org/dist/lucene/solr/";
    String txt = null;
    try {
      URLConnection connection = new URL(url).openConnection();
      connection.setConnectTimeout(5000);
      connection.setReadTimeout(5000);
      connection.connect();
      txt = IOUtils.toString(connection.getInputStream());
    } catch (Exception ex) {
      // TODO - should it fail/skip?
      fail("this test only works if you have a network connection.");
      return;
    }

    SolrCore core = h.getCore();

    Map<String, String[]> args = new HashMap<String, String[]>();
    args.put(CommonParams.STREAM_URL, new String[] {url});

    // Make sure it got a single stream in and out ok
    List<ContentStream> streams = new ArrayList<ContentStream>();
    parser.buildRequestFrom(core, new MultiMapSolrParams(args), streams);
    assertEquals(1, streams.size());
    assertEquals(txt, IOUtils.toString(streams.get(0).getStream()));
  }
コード例 #2
0
  @Test
  public void testStreamBody() throws Exception {
    String body1 = "AMANAPLANPANAMA";
    String body2 = "qwertasdfgzxcvb";
    String body3 = "1234567890";

    SolrCore core = h.getCore();

    Map<String, String[]> args = new HashMap<String, String[]>();
    args.put(CommonParams.STREAM_BODY, new String[] {body1});

    // Make sure it got a single stream in and out ok
    List<ContentStream> streams = new ArrayList<ContentStream>();
    parser.buildRequestFrom(core, new MultiMapSolrParams(args), streams);
    assertEquals(1, streams.size());
    assertEquals(body1, IOUtils.toString(streams.get(0).getStream()));

    // Now add three and make sure they come out ok
    streams = new ArrayList<ContentStream>();
    args.put(CommonParams.STREAM_BODY, new String[] {body1, body2, body3});
    parser.buildRequestFrom(core, new MultiMapSolrParams(args), streams);
    assertEquals(3, streams.size());
    ArrayList<String> input = new ArrayList<String>();
    ArrayList<String> output = new ArrayList<String>();
    input.add(body1);
    input.add(body2);
    input.add(body3);
    output.add(IOUtils.toString(streams.get(0).getStream()));
    output.add(IOUtils.toString(streams.get(1).getStream()));
    output.add(IOUtils.toString(streams.get(2).getStream()));
    // sort them so the output is consistent
    Collections.sort(input);
    Collections.sort(output);
    assertEquals(input.toString(), output.toString());

    // set the contentType and make sure tat gets set
    String ctype = "text/xxx";
    streams = new ArrayList<ContentStream>();
    args.put(CommonParams.STREAM_CONTENTTYPE, new String[] {ctype});
    parser.buildRequestFrom(core, new MultiMapSolrParams(args), streams);
    for (ContentStream s : streams) {
      assertEquals(ctype, s.getContentType());
    }
  }
コード例 #3
0
  @Test
  public void testUrlParamParsing() {
    String[][] teststr =
        new String[][] {
          {"this is simple", "this%20is%20simple"},
          {"this is simple", "this+is+simple"},
          {"\u00FC", "%C3%BC"}, // lower-case "u" with diaeresis/umlaut
          {"\u0026", "%26"}, // &
          {"\u20AC", "%E2%82%AC"} // euro
        };

    for (String[] tst : teststr) {
      MultiMapSolrParams params = SolrRequestParsers.parseQueryString("val=" + tst[1]);
      assertEquals(tst[0], params.get("val"));
    }
  }