Class ItemTracker
- java.lang.Object
-
- org.junit.rules.ExternalResource
-
- de.hybris.platform.integrationservices.util.ItemTracker
-
- All Implemented Interfaces:
org.junit.rules.TestRule
public class ItemTracker extends org.junit.rules.ExternalResourceA JUnitRulefor tracking items created in the course of an integration test execution. The rule must be created with a set of item types to keep track of. Before the tests run, this rule will capture pre-existing items for each of the types specified; after the tests it cleans all items that were created by the test, ie. they are not pre-existent to the test.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafter()protected voidbefore()<T extends ItemModel>
java.util.List<T>getCreatedItems(java.lang.Class<T> type)Retrieves items created by the test<T extends ItemModel>
booleanisCreated(java.lang.Class<T> type, java.util.function.Predicate<T> condition)Checks whether item specified by the condition was created during the test execution.static ItemTrackertrack(java.lang.Class<? extends ItemModel>... types)Creates this rule by specifying types of the items to be tracked.
-
-
-
Method Detail
-
track
@SafeVarargs public static ItemTracker track(java.lang.Class<? extends ItemModel>... types)
Creates this rule by specifying types of the items to be tracked. Be mindful of the number of types included because this rules keeps all items pre-existing for each of the types in memory.- Parameters:
types- types, for which items should be tracked by this rule. Sometimes, items of one type cannot be deleted while items of other types exist. In this case make sure the dependent items are cleaned last, e.g."Product", "CatalogVersion", "Catalog"- Returns:
- a rule initialized with the item types.
-
before
protected void before()
- Overrides:
beforein classorg.junit.rules.ExternalResource
-
after
protected void after()
- Overrides:
afterin classorg.junit.rules.ExternalResource
-
isCreated
public <T extends ItemModel> boolean isCreated(java.lang.Class<T> type, java.util.function.Predicate<T> condition)
Checks whether item specified by the condition was created during the test execution.- Type Parameters:
T-ItemModelsubclass.- Parameters:
type- type of the item to check.condition- a condition the created item should match, e.g. a unique field match, etc.- Returns:
true, if there is at least one item that did not exist before the test but exists at the time of this method call;falseotherwise.- Throws:
java.lang.IllegalArgumentException- if the specified type is not tracked
-
getCreatedItems
public <T extends ItemModel> java.util.List<T> getCreatedItems(java.lang.Class<T> type)
Retrieves items created by the test- Parameters:
type- type of the items to retrieve- Returns:
- a list of all items of the specified time created by the test or an empty list, if no items created.
- Throws:
java.lang.IllegalArgumentException- if the specified type is not tracked
-
-