How to use SolrSearchEngine class of com.example package

Best Testcontainers-java code snippet using com.example.SolrSearchEngine

Source:SolrQueryTest.java Github

copy

Full Screen

...11import java.io.IOException;12import java.util.Collections;13import java.util.HashMap;14import java.util.Map;15import static com.example.SolrSearchEngine.COLLECTION_NAME;16import static org.rnorth.visibleassertions.VisibleAssertions.assertEquals;17public class SolrQueryTest {18 private static final DockerImageName SOLR_IMAGE = DockerImageName.parse("solr:8.3.0");19 public static final SolrContainer solrContainer = new SolrContainer(SOLR_IMAGE)20 .withCollection(COLLECTION_NAME);21 private static SolrClient solrClient;22 @BeforeClass23 public static void setUp() throws IOException, SolrServerException {24 solrContainer.start();25 solrClient = new Http2SolrClient.Builder("http://" + solrContainer.getContainerIpAddress() + ":" + solrContainer.getSolrPort() + "/solr").build();26 // Add Sample Data27 solrClient.add(COLLECTION_NAME, Collections.singletonList(28 new SolrInputDocument(createMap(29 "id", createInputField("id", "1"),30 "title", createInputField("title", "old skool - trainers - shoes")31 ))32 ));33 solrClient.add(COLLECTION_NAME, Collections.singletonList(34 new SolrInputDocument(createMap(35 "id", createInputField("id", "2"),36 "title", createInputField("title", "print t-shirt")37 ))38 ));39 solrClient.commit(COLLECTION_NAME);40 }41 @Test42 public void testQueryForShoes() {43 SolrSearchEngine searchEngine = new SolrSearchEngine(solrClient);44 SearchResult result = searchEngine.search("shoes");45 assertEquals("When searching for shoes we expect one result", 1L, result.getTotalHits());46 assertEquals("The result should have the id 1", "1", result.getResults().get(0).get("id"));47 }48 @Test49 public void testQueryForTShirt() {50 SolrSearchEngine searchEngine = new SolrSearchEngine(solrClient);51 SearchResult result = searchEngine.search("t-shirt");52 assertEquals("When searching for t-shirt we expect one result", 1L, result.getTotalHits());53 assertEquals("The result should have the id 2", "2", result.getResults().get(0).get("id"));54 }55 @Test56 public void testQueryForAsterisk() {57 SolrSearchEngine searchEngine = new SolrSearchEngine(solrClient);58 SearchResult result = searchEngine.search("*");59 assertEquals("When searching for * we expect no results", 0L, result.getTotalHits());60 }61 private static SolrInputField createInputField(String key, String value) {62 SolrInputField inputField = new SolrInputField(key);63 inputField.setValue(value);64 return inputField;65 }66 private static Map<String, SolrInputField> createMap(String k0, SolrInputField v0, String k1, SolrInputField v1) {67 Map<String, SolrInputField> result = new HashMap<>();68 result.put(k0, v0);69 result.put(k1, v1);70 return result;71 }...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Testcontainers-java automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Most used methods in SolrSearchEngine

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful