Ejemplo n.º 1
0
  public void testResponse() throws Exception {
    QueryRequest qr = queryRequestFactory.createNonFirewalledQuery("badger", (byte) 1);
    testUP[0].send(qr);
    testUP[0].flush();
    Thread.sleep(1000);
    QueryReply r = BlockingConnectionUtils.getFirstQueryReply(testUP[0]);
    assertNotNull(r);
    QueryReply expected = staticMessages.getLimeReply();
    assertTrue(expected.getResultsAsList().containsAll(r.getResultsAsList()));
    assertTrue(r.getResultsAsList().containsAll(expected.getResultsAsList()));

    // change the words to something else
    SearchSettings.LIME_SEARCH_TERMS.set(new String[] {"mushroom"});
    qr = queryRequestFactory.createNonFirewalledQuery("badger", (byte) 1);
    testUP[0].send(qr);
    testUP[0].flush();
    Thread.sleep(1000);
    r = BlockingConnectionUtils.getFirstQueryReply(testUP[0]);
    assertNull(r);

    qr = queryRequestFactory.createNonFirewalledQuery("mushroom", (byte) 1);
    testUP[0].send(qr);
    testUP[0].flush();
    Thread.sleep(1000);
    r = BlockingConnectionUtils.getFirstQueryReply(testUP[0]);
    assertNotNull(r);
    assertTrue(expected.getResultsAsList().containsAll(r.getResultsAsList()));
    assertTrue(r.getResultsAsList().containsAll(expected.getResultsAsList()));

    // turn off responding completely
    SearchSettings.SEND_LIME_RESPONSES.setValue(0);
    qr = queryRequestFactory.createNonFirewalledQuery("mushroom", (byte) 1);
    testUP[0].send(qr);
    testUP[0].flush();
    Thread.sleep(1000);
    r = BlockingConnectionUtils.getFirstQueryReply(testUP[0]);
    assertNull(r);
  }
  public void testXMLReturned1() throws Exception {
    drainAll();

    // send a query
    QueryRequest query = queryRequestFactory.createQuery("ID3V24");
    ULTRAPEER[0].send(query);
    ULTRAPEER[0].flush();

    // wait for processing
    Thread.sleep(750);

    // confirm that result has heXML.
    QueryReply reply = BlockingConnectionUtils.getFirstQueryReply(ULTRAPEER[0]);
    assertNotNull(reply);
    assertNotNull(reply.getXMLBytes());
    assertTrue("xml length = " + reply.getXMLBytes().length, reply.getXMLBytes().length > 10);
  }
  public void testXMLReturned2() throws Exception {
    drainAll();

    String richQuery =
        "<?xml version=\"1.0\"?><audios xsi:noNamespaceSchemaLocation=\"http://www.limewire.com/schemas/audio.xsd\"><audio genre=\"Bass\"></audio></audios>";

    // send a query
    QueryRequest query = queryRequestFactory.createQuery("Bass", richQuery);
    ULTRAPEER[0].send(query);
    ULTRAPEER[0].flush();

    // wait for processing
    Thread.sleep(750);

    // confirm that result has heXML.
    QueryReply reply = BlockingConnectionUtils.getFirstQueryReply(ULTRAPEER[0]);
    assertNotNull(reply);
    assertNotNull(reply.getXMLBytes());
    assertTrue("xml length = " + reply.getXMLBytes().length, reply.getXMLBytes().length > 10);
  }
  public void testBitrateExclusion() throws Exception {
    // test that a mismatching artist name doesn't return a result
    {
      drainAll();

      String richQuery =
          "<?xml version=\"1.0\"?><audios xsi:noNamespaceSchemaLocation=\"http://www.limewire.com/schemas/audio.xsd\"><audio bitrate=\"64\" artist=\"junk\"></audio></audios>";

      // send a query
      QueryRequest query = queryRequestFactory.createQuery("junk 64", richQuery);
      ULTRAPEER[0].send(query);
      ULTRAPEER[0].flush();

      // wait for processing
      Thread.sleep(750);

      // confirm that we don't get a result
      QueryReply reply = BlockingConnectionUtils.getFirstQueryReply(ULTRAPEER[0]);
      assertNull(reply);
    }

    // test that a matching artist name does return a result
    {
      drainAll();

      String richQuery =
          "<?xml version=\"1.0\"?><audios xsi:noNamespaceSchemaLocation=\"http://www.limewire.com/schemas/audio.xsd\"><audio bitrate=\"64\" artist=\"artist test\"></audio></audios>";

      // send a query
      QueryRequest query = queryRequestFactory.createQuery("title 16", richQuery);
      ULTRAPEER[0].send(query);
      ULTRAPEER[0].flush();

      // wait for processing
      Thread.sleep(750);

      // confirm that we do get a result
      QueryReply reply = BlockingConnectionUtils.getFirstQueryReply(ULTRAPEER[0]);
      assertNotNull(reply);
      assertNotNull(reply.getXMLBytes());
      assertTrue("xml length = " + reply.getXMLBytes().length, reply.getXMLBytes().length > 10);
    }

    // test that a null price value doesn't return a result
    {
      drainAll();

      String richQuery =
          "<?xml version=\"1.0\"?><audios xsi:noNamespaceSchemaLocation=\"http://www.limewire.com/schemas/audio.xsd\"><audio bitrate=\"64\" price=\"$19.99\"></audio></audios>";

      // send a query
      QueryRequest query = queryRequestFactory.createQuery("$19.99 16", richQuery);
      ULTRAPEER[0].send(query);
      ULTRAPEER[0].flush();

      // wait for processing
      Thread.sleep(750);

      // confirm that we don't get a result
      QueryReply reply = BlockingConnectionUtils.getFirstQueryReply(ULTRAPEER[0]);
      assertNull(reply);
    }

    // 3 fields - bitrate matches, but only one other, so no return
    {
      drainAll();

      String richQuery =
          "<?xml version=\"1.0\"?><audios xsi:noNamespaceSchemaLocation=\"http://www.limewire.com/schemas/audio.xsd\"><audio bitrate=\"64\" artist=\"artist test\" title=\"junk\"></audio></audios>";

      // send a query
      QueryRequest query = queryRequestFactory.createQuery("Test junk 16", richQuery);
      ULTRAPEER[0].send(query);
      ULTRAPEER[0].flush();

      // wait for processing
      Thread.sleep(750);

      // confirm that we don't get a result
      QueryReply reply = BlockingConnectionUtils.getFirstQueryReply(ULTRAPEER[0]);
      assertNull(reply);
    }

    // 3 fields - all match, should return
    {
      drainAll();

      String richQuery =
          "<?xml version=\"1.0\"?><audios xsi:noNamespaceSchemaLocation=\"http://www.limewire.com/schemas/audio.xsd\"><audio bitrate=\"64\" artist=\"artist test\" title=\"title test\"></audio></audios>";

      // send a query
      QueryRequest query = queryRequestFactory.createQuery("Test mpg 16", richQuery);
      ULTRAPEER[0].send(query);
      ULTRAPEER[0].flush();

      // wait for processing
      Thread.sleep(750);

      // confirm that we do get a result
      QueryReply reply = BlockingConnectionUtils.getFirstQueryReply(ULTRAPEER[0]);
      assertNotNull(reply);
      assertNotNull(reply.getXMLBytes());
      assertTrue("xml length = " + reply.getXMLBytes().length, reply.getXMLBytes().length > 10);
    }

    // 3 fields - 1 match, 1 null, should return
    {
      drainAll();

      String richQuery =
          "<?xml version=\"1.0\"?><audios xsi:noNamespaceSchemaLocation=\"http://www.limewire.com/schemas/audio.xsd\"><audio bitrate=\"64\" artist=\"artist test\" type=\"Audiobook\"></audio></audios>";

      // send a query
      QueryRequest query = queryRequestFactory.createQuery("Test Audiobook 16", richQuery);
      ULTRAPEER[0].send(query);
      ULTRAPEER[0].flush();

      // wait for processing
      Thread.sleep(750);

      // confirm that we do get a result
      QueryReply reply = BlockingConnectionUtils.getFirstQueryReply(ULTRAPEER[0]);
      assertNotNull(reply);
      assertNotNull(reply.getXMLBytes());
      assertTrue("xml length = " + reply.getXMLBytes().length, reply.getXMLBytes().length > 10);
    }

    // 3 fields - 2 null, should not return
    {
      drainAll();

      String richQuery =
          "<?xml version=\"1.0\"?><audios xsi:noNamespaceSchemaLocation=\"http://www.limewire.com/schemas/audio.xsd\"><audio bitrate=\"64\" price=\"$19.99\" type=\"Audiobook\"></audio></audios>";

      // send a query
      QueryRequest query = queryRequestFactory.createQuery("$19.99 Audiobook 16", richQuery);
      ULTRAPEER[0].send(query);
      ULTRAPEER[0].flush();

      // wait for processing
      Thread.sleep(750);

      // confirm that we don't get a result
      QueryReply reply = BlockingConnectionUtils.getFirstQueryReply(ULTRAPEER[0]);
      assertNull(reply);
    }

    // 3 fields - 1 null, 1 mismatch, should not return
    {
      drainAll();

      String richQuery =
          "<?xml version=\"1.0\"?><audios xsi:noNamespaceSchemaLocation=\"http://www.limewire.com/schemas/audio.xsd\"><audio bitrate=\"64\" price=\"$19.99\" artist=\"Tester\"></audio></audios>";

      // send a query
      QueryRequest query = queryRequestFactory.createQuery("$19.99 Tester 16", richQuery);
      ULTRAPEER[0].send(query);
      ULTRAPEER[0].flush();

      // wait for processing
      Thread.sleep(750);

      // confirm that we don't get a result
      QueryReply reply = BlockingConnectionUtils.getFirstQueryReply(ULTRAPEER[0]);
      assertNull(reply);
    }
  }