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.ExternalResource
A JUnit
Rule for 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
Modifier and TypeMethodDescriptionprotected voidafter()protected voidbefore()getCreatedItems(Class<T> type) Retrieves items created by the test<T extends ItemModel>
booleanChecks whether item specified by the condition was created during the test execution.static ItemTrackerCreates this rule by specifying types of the items to be tracked.Methods inherited from class org.junit.rules.ExternalResource
apply
-
Method Details
-
track
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
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:
IllegalArgumentException- if the specified type is not tracked
-
getCreatedItems
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:
IllegalArgumentException- if the specified type is not tracked
-