Class TestableSearchTransaction
- java.lang.Object
-
- com.funnelback.publicui.search.model.transaction.SearchTransaction
-
- com.funnelback.publicui.search.model.transaction.testutils.TestableSearchTransaction
-
public class TestableSearchTransaction extends SearchTransaction
A search transaction that makes testing easier. for example:SearchTransaction transaction = new TestableSearchTransaction() .withResult(Result.builder().title("hello").liveUrl("http://example/com/").build()) // Add a profile setting will be returned by transaction.getQuestion().getCurrentProfileConfig() .withProfileSetting("a", "b") // Add a facet to the result packet. .withFacetAndValues(new Facet("authors"), CategoryValue.builder().label("Bob").count(12).selected(false).build(), CategoryValue.builder().label("Alice").count(12).selected(true).build()) // Use the modifier to set the form name in a single line. .withModification(t -> t.getQuestion().setForm("super")) // Use the modifier to add some custom data to the transaction. .withModification(t -> { if(t.getCustomData().isEmpty()) { t.getCustomData().put("a", "b"); t.getCustomData().put("b", "c"); } });
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.funnelback.publicui.search.model.transaction.SearchTransaction
SearchTransaction.ExtraSearches
-
-
Constructor Summary
Constructors Constructor Description TestableSearchTransaction()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description TestableSearchTransaction
withFacetAndValues(Facet facetToAdd, Facet.CategoryValue... values)
Adds the given facet to the search transaction, and adds all category values to the facet.TestableSearchTransaction
withFacetAndValues(Facet facetToAdd, List<Facet.CategoryValue> values)
Adds the given facet to the search transaction, and adds all category values to the facet.TestableSearchTransaction
withModification(Consumer<TestableSearchTransaction> modify)
Allows for easy chaining of modifications to this SearchTransaction For example:TestableSearchTransaction
withProfileSetting(String key, String value)
Sets profile settings on to the SearchTransaction, these settings will be returned bySearchQuestion.getCurrentProfileConfig()
.TestableSearchTransaction
withResult(Result resultToAdd)
Adds a result to the list of results in the search transaction.TestableSearchTransaction
withResultPacket(ResultPacket resultPacket)
Adds the given result packet to the search transaction.TestableSearchTransaction
withResultPacketIfNotSet()
Ensures the SearchTransaction has a result packet, if none is set it will set one.-
Methods inherited from class com.funnelback.publicui.search.model.transaction.SearchTransaction
addExtraSearch, getCustomData, getEffectiveExtraSearchName, getError, getExtraSearches, getExtraSearchesAproxTimeSpent, getExtraSearchesQuestions, getExtraSearchesTasks, getExtraSearchName, getParentTransaction, getQuestion, getResponse, getSession, isAnyExtraSearchesIncomplete, setAnyExtraSearchesIncomplete, setError, setExtraSearchNameAndParentTransaction, setSession
-
-
-
-
Method Detail
-
withResult
public TestableSearchTransaction withResult(Result resultToAdd)
Adds a result to the list of results in the search transaction..withResult(Result.builder().title("hello").liveUrl("http://example/com/1").build()) .withResult(Result.builder().title("hi").liveUrl("http://example/com/2").build())
- Parameters:
resultToAdd
- the result to add to theResultPacket
, a result packet will be created if it does not already exist.- Returns:
- this
-
withProfileSetting
public TestableSearchTransaction withProfileSetting(String key, String value)
Sets profile settings on to the SearchTransaction, these settings will be returned bySearchQuestion.getCurrentProfileConfig()
.- Parameters:
key
- The profile setting key.value
- The value to set the key to, when null the setting will be removed.
-
withResultPacketIfNotSet
public TestableSearchTransaction withResultPacketIfNotSet()
Ensures the SearchTransaction has a result packet, if none is set it will set one.
-
withResultPacket
public TestableSearchTransaction withResultPacket(ResultPacket resultPacket)
Adds the given result packet to the search transaction.- Parameters:
resultPacket
- the result packet to set on the search transaction- Returns:
- this
-
withFacetAndValues
public TestableSearchTransaction withFacetAndValues(Facet facetToAdd, Facet.CategoryValue... values)
Adds the given facet to the search transaction, and adds all category values to the facet..withFacetAndValues(new Facet("authors"), CategoryValue.builder().label("Bob").count(12).selected(false).build(), CategoryValue.builder().label("Alice").count(12).selected(true).build())
- Parameters:
facetToAdd
- the facet to add to the search transaction, will replace any existing facet with the same name.values
- these are the values from the facet for example for a facet over metadata author this might contain all authors e.g. "Bob".- Returns:
- this
-
withFacetAndValues
public TestableSearchTransaction withFacetAndValues(Facet facetToAdd, List<Facet.CategoryValue> values)
Adds the given facet to the search transaction, and adds all category values to the facet.- Parameters:
facetToAdd
- the facet to add to the search transaction, will replace any existing facet with the same name.values
- these are the values from the facet for example for a facet over metadata author this might contain all authors e.g. "Bob".- Returns:
- this
-
withModification
public TestableSearchTransaction withModification(Consumer<TestableSearchTransaction> modify)
Allows for easy chaining of modifications to this SearchTransaction For example:// Use the modifier to set the form name in a single line. .withModification(t -> t.getQuestion().setForm("super")) // Use the modifier to add some custom data to the transaction. .withModification(t -> { if(t.getCustomData().isEmpty()) { t.getCustomData().put("a", "b"); t.getCustomData().put("b", "c"); } }); .with...() // chain more here
-
-