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

The following examples show how to use org.apache.solr.SolrTestCaseJ4#assumeWorkingMockito() . 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: ImplicitSnitchTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTags_withAllHostNameRequestedTags_returns_all_Tags() throws Exception {
  SolrTestCaseJ4.assumeWorkingMockito();
  
  String node = "serv01.dc01.london.uk.apache.org:8983_solr";

  SnitchContext context = new ServerSnitchContext(null, node, new HashMap<>(),null);
  //We need mocking here otherwise, we would need proper DNS entry for this test to pass
  ImplicitSnitch mockedSnitch = Mockito.spy(snitch);
  when(mockedSnitch.getHostIp(anyString())).thenReturn("10.11.12.13");

  mockedSnitch.getTags(node, Sets.newHashSet(IP_1, IP_2, IP_3, IP_4), context);

  Map<String, Object> tags = context.getTags();
  assertThat(tags.entrySet().size(), is(4));
  assertThat(tags.get(IP_1), is("13"));
  assertThat(tags.get(IP_2), is("12"));
  assertThat(tags.get(IP_3), is("11"));
  assertThat(tags.get(IP_4), is("10"));
}
 
Example 2
Source File: ImplicitSnitchTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testGetTags_withHostNameRequestedTag_ip3_returns_1_tag() throws Exception {
  SolrTestCaseJ4.assumeWorkingMockito();
  
  String node = "serv01.dc01.london.uk.apache.org:8983_solr";

  SnitchContext context = new ServerSnitchContext(null, node, new HashMap<>(),null);
  //We need mocking here otherwise, we would need proper DNS entry for this test to pass
  ImplicitSnitch mockedSnitch = Mockito.spy(snitch);
  when(mockedSnitch.getHostIp(anyString())).thenReturn("10.11.12.13");
  mockedSnitch.getTags(node, Sets.newHashSet(IP_3), context);

  Map<String, Object> tags = context.getTags();
  assertThat(tags.entrySet().size(), is(1));
  assertThat(tags.get(IP_3), is("11"));
}
 
Example 3
Source File: ImplicitSnitchTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetTags_withHostNameRequestedTag_ip99999_returns_nothing() throws Exception {
  SolrTestCaseJ4.assumeWorkingMockito();
  
  String node = "serv01.dc01.london.uk.apache.org:8983_solr";

  SnitchContext context = new ServerSnitchContext(null, node, new HashMap<>(),null);
  //We need mocking here otherwise, we would need proper DNS entry for this test to pass
  ImplicitSnitch mockedSnitch = Mockito.spy(snitch);
  when(mockedSnitch.getHostIp(anyString())).thenReturn("10.11.12.13");
  mockedSnitch.getTags(node, Sets.newHashSet("ip_99999"), context);

  Map<String, Object> tags = context.getTags();
  assertThat(tags.entrySet().size(), is(0));
}
 
Example 4
Source File: TestHttpServletCarrier.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Test
@SuppressWarnings({"unchecked"})
public void test() {
  SolrTestCaseJ4.assumeWorkingMockito();
  HttpServletRequest req = mock(HttpServletRequest.class);
  Multimap<String, String> headers = HashMultimap.create();
  headers.put("a", "a");
  headers.put("a", "b");
  headers.put("a", "c");
  headers.put("b", "a");
  headers.put("b", "b");
  headers.put("c", "a");

  when(req.getHeaderNames()).thenReturn(IteratorUtils.asEnumeration(headers.keySet().iterator()));
  when(req.getHeaders(anyString())).thenAnswer((Answer<Enumeration<String>>) inv -> {
    String key = inv.getArgument(0);
    return IteratorUtils.asEnumeration(headers.get(key).iterator());
  });

  HttpServletCarrier servletCarrier = new HttpServletCarrier(req);
  Iterator<Map.Entry<String, String>> it = servletCarrier.iterator();
  Multimap<String, String> resultBack = HashMultimap.create();
  while(it.hasNext()) {
    Map.Entry<String, String> entry = it.next();
    resultBack.put(entry.getKey(), entry.getValue());
  }
  assertEquals(headers, resultBack);


}
 
Example 5
Source File: SchemaWatcherTest.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  SolrTestCaseJ4.assumeWorkingMockito();
  
  mockSchemaReader = mock(ZkIndexSchemaReader.class);
  schemaWatcher = new SchemaWatcher(mockSchemaReader);
}
 
Example 6
Source File: CertAuthPluginTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setupMockito() {
    SolrTestCaseJ4.assumeWorkingMockito();
}
 
Example 7
Source File: SkipExistingDocumentsProcessorFactoryTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() {
  SolrTestCaseJ4.assumeWorkingMockito();
}
 
Example 8
Source File: SSLConfigurationsTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private Configuration getMockHadoopConfiguration() {
  SolrTestCaseJ4.assumeWorkingMockito();
  return Mockito.mock(Configuration.class);
}
 
Example 9
Source File: HadoopSSLCredentialProviderTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
private Configuration getMockHadoopConfiguration() {
  SolrTestCaseJ4.assumeWorkingMockito();
  return Mockito.mock(Configuration.class);
}
 
Example 10
Source File: BlobRepositoryMockingTest.java    From lucene-solr with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void beforeClass() {
  SolrTestCaseJ4.assumeWorkingMockito();
}