Java Code Examples for org.apache.solr.SolrTestCaseJ4#expectThrows()

The following examples show how to use org.apache.solr.SolrTestCaseJ4#expectThrows() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SolrPortAwareCookieSpecTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testDomainHostPortMatch() throws Exception {
  final BasicClientCookie cookie = new BasicClientCookie("name", "value");
  final CookieOrigin origin = new CookieOrigin("myhost", 80, "/", false);
  final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();

  cookie.setDomain("myhost");
  SolrTestCaseJ4.expectThrows(IllegalArgumentException.class, () -> h.match(cookie, null));

  cookie.setDomain(null);
  Assert.assertFalse(h.match(cookie, origin));

  cookie.setDomain("otherhost");
  Assert.assertFalse(h.match(cookie, origin));

  cookie.setDomain("myhost");
  Assert.assertTrue(h.match(cookie, origin));

  cookie.setDomain("myhost:80");
  Assert.assertTrue(h.match(cookie, origin));

  cookie.setDomain("myhost:8080");
  Assert.assertFalse(h.match(cookie, origin));
}
 
Example 2
Source File: SolrPortAwareCookieSpecTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testDomainHostPortValidate() throws Exception {
  final BasicClientCookie cookie = new BasicClientCookie("name", "value");
  final CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
  final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();

  cookie.setDomain("somehost:80");
  h.validate(cookie, origin);

  cookie.setDomain("somehost:1234");
  SolrTestCaseJ4.expectThrows(MalformedCookieException.class, () -> h.validate(cookie, origin));
}
 
Example 3
Source File: SolrPortAwareCookieSpecTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testDomainValidate1() throws Exception {
  final BasicClientCookie cookie = new BasicClientCookie("name", "value");
  final CookieOrigin origin = new CookieOrigin("somehost", 80, "/", false);
  final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();

  cookie.setDomain("somehost");
  h.validate(cookie, origin);

  cookie.setDomain("otherhost");
  SolrTestCaseJ4.expectThrows(MalformedCookieException.class, () ->  h.validate(cookie, origin));
}
 
Example 4
Source File: SolrPortAwareCookieSpecTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testDomainValidate2() throws Exception {
  final BasicClientCookie cookie = new BasicClientCookie("name", "value");
  final CookieOrigin origin = new CookieOrigin("www.somedomain.com", 80, "/", false);
  final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();

  cookie.setDomain(".somedomain.com");
  h.validate(cookie, origin);

  cookie.setDomain(".otherdomain.com");
  SolrTestCaseJ4.expectThrows(MalformedCookieException.class, () ->  h.validate(cookie, origin));

  cookie.setDomain("www.otherdomain.com");
  SolrTestCaseJ4.expectThrows(MalformedCookieException.class, () ->  h.validate(cookie, origin));
}
 
Example 5
Source File: SolrPortAwareCookieSpecTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testDomainValidate3() throws Exception {
  final BasicClientCookie cookie = new BasicClientCookie("name", "value");
  final CookieOrigin origin = new CookieOrigin("www.a.com", 80, "/", false);
  final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();

  cookie.setDomain(".a.com");
  h.validate(cookie, origin);

  cookie.setDomain(".com");
  SolrTestCaseJ4.expectThrows(MalformedCookieException.class, () ->  h.validate(cookie, origin));
}
 
Example 6
Source File: SolrPortAwareCookieSpecTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testDomainValidate4() throws Exception {
  final BasicClientCookie cookie = new BasicClientCookie("name", "value");
  final CookieOrigin origin = new CookieOrigin("www.a.b.c", 80, "/", false);
  final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();

  cookie.setDomain(".a.b.c");
  h.validate(cookie, origin);

  cookie.setDomain(".b.c");
  SolrTestCaseJ4.expectThrows(MalformedCookieException.class, () ->  h.validate(cookie, origin));
}
 
Example 7
Source File: SolrPortAwareCookieSpecTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testDomainInvalidInput() throws Exception {
  final CookieAttributeHandler h = new SolrPortAwareCookieSpecFactory.PortAwareDomainHandler();
  SolrTestCaseJ4.expectThrows(IllegalArgumentException.class, () -> h.match(null, null));
  SolrTestCaseJ4.expectThrows(IllegalArgumentException.class,
      () -> h.match(new BasicClientCookie("name", "value"), null));
}
 
Example 8
Source File: TestStandardNormalizer.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidSTD() {
  final Map<String,Object> params = new HashMap<String,Object>();
  params.put("std", "0f");
  final NormalizerException expectedException =
      new NormalizerException("Standard Normalizer standard deviation must be positive "
          + "| avg = 0.0,std = 0.0");
  NormalizerException ex = SolrTestCaseJ4.expectThrows(NormalizerException.class,
      () -> implTestStandard(params, 0.0f, 0.0f)
  );
  assertEquals(expectedException.toString(), ex.toString());
}
 
Example 9
Source File: TestStandardNormalizer.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidSTD2() {
  final Map<String,Object> params = new HashMap<String,Object>();
  params.put("std", "-1f");
  final NormalizerException expectedException =
      new NormalizerException("Standard Normalizer standard deviation must be positive "
          + "| avg = 0.0,std = -1.0");

  NormalizerException ex = SolrTestCaseJ4.expectThrows(NormalizerException.class,
      () -> implTestStandard(params, 0.0f, -1f)
  );
  assertEquals(expectedException.toString(), ex.toString());
}
 
Example 10
Source File: TestStandardNormalizer.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testInvalidSTD3() {
  final Map<String,Object> params = new HashMap<String,Object>();
  params.put("avg", "1f");
  params.put("std", "0f");
  final NormalizerException expectedException =
      new NormalizerException("Standard Normalizer standard deviation must be positive "
          + "| avg = 1.0,std = 0.0");

  NormalizerException ex = SolrTestCaseJ4.expectThrows(NormalizerException.class,
      () -> implTestStandard(params, 1f, 0f)
  );
  assertEquals(expectedException.toString(), ex.toString());
}
 
Example 11
Source File: TestMinMaxNormalizer.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testMinMaxNormalizerMinEqualToMax() {
  final Map<String,Object> params = new HashMap<String,Object>();
  params.put("min", "10.0f");
  params.put("max", "10.0f");
  final NormalizerException expectedException =
      new NormalizerException("MinMax Normalizer delta must not be zero "
          + "| min = 10.0,max = 10.0,delta = 0.0");
  NormalizerException ex = SolrTestCaseJ4.expectThrows(NormalizerException.class,
      () -> implTestMinMax(params, 10.0f, 10.0f)
  );
  assertEquals(expectedException.toString(), ex.toString());
}
 
Example 12
Source File: CharBufferTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public void testCreate() {
    CharBuffer cb = new CharBuffer();
    assertEquals(0, cb.length());
    SolrTestCaseJ4.expectThrows(IllegalArgumentException.class, () -> new CharBuffer(0));
    cb = new CharBuffer(128);
    assertEquals(0, cb.length());
}