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 Details

    • track

      @SafeVarargs public static ItemTracker track(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:
      before in class org.junit.rules.ExternalResource
    • after

      protected void after()
      Overrides:
      after in class org.junit.rules.ExternalResource
    • isCreated

      public <T extends ItemModel> boolean isCreated(Class<T> type, Predicate<T> condition)
      Checks whether item specified by the condition was created during the test execution.
      Type Parameters:
      T - ItemModel subclass.
      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; false otherwise.
      Throws:
      IllegalArgumentException - if the specified type is not tracked
    • getCreatedItems

      public <T extends ItemModel> List<T> getCreatedItems(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:
      IllegalArgumentException - if the specified type is not tracked