Class CockpitTestUtil
- java.lang.Object
-
- com.hybris.cockpitng.testing.util.CockpitTestUtil
-
public final class CockpitTestUtil extends java.lang.ObjectUtility methods for testing.
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description protected static org.mockito.stubbing.Answer<java.lang.Object>createAttributesAnswer(java.util.Set<java.lang.String> keys, java.util.function.BiFunction<java.lang.String,java.lang.Object,java.lang.Object> mock)static AuResponseProcessor<org.zkoss.zk.au.out.AuEcho>createEchoProcessor()Creates a processor forAuEchorequests.static voidexecuteWithLabels(java.util.Map<java.lang.String,java.lang.String> labels, java.lang.Runnable runnable)Allows to mock ZK labels that are fetched by static methods likeLabels.getLabel(String).static <C extends org.zkoss.zk.ui.Component>
java.util.Optional<C>find(org.zkoss.zk.ui.Component parent, java.lang.Class<? extends C> childClass)Looks for a component of provided type (incl.static <C extends org.zkoss.zk.ui.Component>
java.util.Optional<C>find(org.zkoss.zk.ui.Component parent, java.util.function.Predicate<org.zkoss.zk.ui.Component> test)Looks for a component that meets of provided requirement (incl.static <C extends org.zkoss.zk.ui.Component>
java.util.stream.Stream<C>findAll(org.zkoss.zk.ui.Component parent, java.lang.Class<? extends C> childClass)Looks for a all components of provided type (incl.static <C extends org.zkoss.zk.ui.Component>
java.util.stream.Stream<C>findAll(org.zkoss.zk.ui.Component parent, java.util.function.Predicate<org.zkoss.zk.ui.Component> test)Looks for a all components that meets of provided requirement (incl.static <C extends org.zkoss.zk.ui.Component>
java.util.stream.Stream<C>findAllChildren(org.zkoss.zk.ui.Component parent, java.lang.Class<? extends C> childClass)Looks for all children of provided type.static <C extends org.zkoss.zk.ui.Component>
java.util.stream.Stream<C>findAllChildren(org.zkoss.zk.ui.Component parent, java.util.function.Predicate<org.zkoss.zk.ui.Component> test)Looks for all children that meets of provided requirement.static <C extends org.zkoss.zk.ui.Component>
java.util.Optional<C>findChild(org.zkoss.zk.ui.Component parent, java.lang.Class<? extends C> childClass)Looks for a child of provided type.static <C extends org.zkoss.zk.ui.Component>
java.util.Optional<C>findChild(org.zkoss.zk.ui.Component parent, java.util.function.Predicate<org.zkoss.zk.ui.Component> test)Looks for a child that meets of provided requirement.static java.lang.String[]getSClasses(java.lang.String sclass)Retrieves all CSS classes from provided sclass attribute of componentstatic java.lang.String[]getSClasses(org.zkoss.zk.ui.HtmlBasedComponent component)Retrieves all CSS classes currently set on provided componentstatic booleanisSClassSet(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String... expectedClasses)Checks if provided component has all specified CSS classes setstatic booleanisSClassUnset(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String... unexpectedClasses)Checks if provided component none of specified CSS classes set.protected static org.mockito.stubbing.StubbermockAttributes(java.util.function.BiFunction<java.lang.String,java.lang.Object,java.lang.Object> mock, java.util.function.Supplier<java.util.Enumeration<java.lang.String>> keysSupplier)static voidmockAuResponseProcessing(AuResponseProcessorRegistry processors)Informs zkExecutionon how to deal withAuResponsestatic voidmockBeanLookup(BeanLookup lookup)Mocks beans that are accessible bySpringUtil.static voidmockBeanLookup(BeanLookupFactory lookup)Mocks beans that are accessible bySpringUtil.static voidmockHttpRequestAttributes()Mocks http request, response and session.static voidmockLabelLookup(LabelLookup lookup)Mocks labels that are accessible byLabels.static voidmockLabelLookup(LabelLookupFactory lookup)Mocks labels that are accessible byLabels.static WidgetInstanceManagermockWidgetInstanceManager()static WidgetInstanceManagermockWidgetInstanceManager(TypedSettingsMap widgetSettings)static DefaultWidgetModelmockWidgetModel()static voidmockZkEnvironment()Mocks all necessaryThreadLocalvariables necessary to deal with zk components, e.g.static voidsimulateEvent(org.zkoss.zk.ui.Component component, java.lang.String eventName, java.lang.Object eventData)static voidsimulateEvent(org.zkoss.zk.ui.Component component, org.zkoss.zk.ui.event.Event event)Simulates anEventat the specifiedComponent.static voidtestSClassSet(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String... expectedClasses)Checks if provided component has all specified CSS classes set.static voidtestSClassUnset(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String... unexpectedClasses)Checks if provided component none of specified CSS classes set.
-
-
-
Method Detail
-
mockLabelLookup
public static void mockLabelLookup(LabelLookupFactory lookup)
Mocks labels that are accessible byLabels.- Parameters:
lookup- labels mock factory
-
mockLabelLookup
public static void mockLabelLookup(LabelLookup lookup)
Mocks labels that are accessible byLabels.- Parameters:
lookup- labels mock
-
executeWithLabels
public static void executeWithLabels(java.util.Map<java.lang.String,java.lang.String> labels, java.lang.Runnable runnable)Allows to mock ZK labels that are fetched by static methods likeLabels.getLabel(String). It sets the labels for the time of test, then reverts them after finishing.- Parameters:
labels- map of labels to userunnable- code to run that will see the labels
-
mockBeanLookup
public static void mockBeanLookup(BeanLookupFactory lookup)
Mocks beans that are accessible bySpringUtil.Notice that only one bean mock may be done for single
mockZkEnvironment()call- Parameters:
lookup- beans mock factory
-
mockBeanLookup
public static void mockBeanLookup(BeanLookup lookup)
Mocks beans that are accessible bySpringUtil.Notice that only one bean mock may be done for single
mockZkEnvironment()call- Parameters:
lookup- beans mock
-
mockHttpRequestAttributes
public static void mockHttpRequestAttributes()
Mocks http request, response and session. Then it is stored inRequestContextHolder.
-
mockAttributes
protected static org.mockito.stubbing.Stubber mockAttributes(java.util.function.BiFunction<java.lang.String,java.lang.Object,java.lang.Object> mock, java.util.function.Supplier<java.util.Enumeration<java.lang.String>> keysSupplier)
-
createAttributesAnswer
protected static org.mockito.stubbing.Answer<java.lang.Object> createAttributesAnswer(java.util.Set<java.lang.String> keys, java.util.function.BiFunction<java.lang.String,java.lang.Object,java.lang.Object> mock)
-
mockZkEnvironment
public static void mockZkEnvironment()
Mocks all necessaryThreadLocalvariables necessary to deal with zk components, e.g.Execution,Desktop,WebApp,WebApplicationContext, etc.
-
mockAuResponseProcessing
public static void mockAuResponseProcessing(AuResponseProcessorRegistry processors)
Informs zkExecutionon how to deal withAuResponse- Parameters:
processors- registry of processors forAuResponse
-
createEchoProcessor
public static AuResponseProcessor<org.zkoss.zk.au.out.AuEcho> createEchoProcessor()
Creates a processor forAuEchorequests. This processor notifies all listeners for this event type immediately.- Returns:
- processor to be registered in
AuResponseProcessorRegistry
-
find
public static <C extends org.zkoss.zk.ui.Component> java.util.Optional<C> find(org.zkoss.zk.ui.Component parent, java.lang.Class<? extends C> childClass)Looks for a component of provided type (incl. parent). Method performs a deep-search in whole DOM tree of provided parent.- Type Parameters:
C- type of component- Parameters:
parent- component which child is to be foundchildClass- class of a child to be found- Returns:
- result of search
-
find
public static <C extends org.zkoss.zk.ui.Component> java.util.Optional<C> find(org.zkoss.zk.ui.Component parent, java.util.function.Predicate<org.zkoss.zk.ui.Component> test)Looks for a component that meets of provided requirement (incl. parent). Method performs a deep-search in whole DOM tree of provided parent.- Type Parameters:
C- expected type of component- Parameters:
parent- component which child is to be foundtest- requirement for component- Returns:
- result of search
-
findAll
public static <C extends org.zkoss.zk.ui.Component> java.util.stream.Stream<C> findAll(org.zkoss.zk.ui.Component parent, java.lang.Class<? extends C> childClass)Looks for a all components of provided type (incl. parent). Method performs a deep-search in whole DOM tree of provided parent.- Type Parameters:
C- type of component- Parameters:
parent- component which child is to be foundchildClass- class of a child to be found- Returns:
- result of search
-
findAll
public static <C extends org.zkoss.zk.ui.Component> java.util.stream.Stream<C> findAll(org.zkoss.zk.ui.Component parent, java.util.function.Predicate<org.zkoss.zk.ui.Component> test)Looks for a all components that meets of provided requirement (incl. parent). Method performs a deep-search in whole DOM tree of provided parent.- Type Parameters:
C- expected type of component- Parameters:
parent- component which child is to be foundtest- requirement for component- Returns:
- result of search
-
findChild
public static <C extends org.zkoss.zk.ui.Component> java.util.Optional<C> findChild(org.zkoss.zk.ui.Component parent, java.lang.Class<? extends C> childClass)Looks for a child of provided type. Method performs a deep-search in whole DOM tree of provided parent.- Type Parameters:
C- type of component- Parameters:
parent- component which child is to be foundchildClass- class of a child to be found- Returns:
- result of search
-
findChild
public static <C extends org.zkoss.zk.ui.Component> java.util.Optional<C> findChild(org.zkoss.zk.ui.Component parent, java.util.function.Predicate<org.zkoss.zk.ui.Component> test)Looks for a child that meets of provided requirement. Method performs a deep-search in whole DOM tree of provided parent.- Type Parameters:
C- expected type of child- Parameters:
parent- component which child is to be foundtest- requirement for child- Returns:
- result of search
-
findAllChildren
public static <C extends org.zkoss.zk.ui.Component> java.util.stream.Stream<C> findAllChildren(org.zkoss.zk.ui.Component parent, java.lang.Class<? extends C> childClass)Looks for all children of provided type. Method performs a deep-search in whole DOM tree of provided parent.- Type Parameters:
C- type of component- Parameters:
parent- component which child is to be foundchildClass- class of a child to be found- Returns:
- result of search
-
findAllChildren
public static <C extends org.zkoss.zk.ui.Component> java.util.stream.Stream<C> findAllChildren(org.zkoss.zk.ui.Component parent, java.util.function.Predicate<org.zkoss.zk.ui.Component> test)Looks for all children that meets of provided requirement. Method performs a deep-search in whole DOM tree of provided parent.- Type Parameters:
C- type of component- Parameters:
parent- component which child is to be foundtest- requirement for child- Returns:
- result of search
-
getSClasses
public static java.lang.String[] getSClasses(org.zkoss.zk.ui.HtmlBasedComponent component)
Retrieves all CSS classes currently set on provided component- Parameters:
component- component, which CSS classes are to be retrieved- Returns:
trueif all classes are set
-
getSClasses
public static java.lang.String[] getSClasses(java.lang.String sclass)
Retrieves all CSS classes from provided sclass attribute of component- Parameters:
sclass- component's sclass attribute value- Returns:
- arrays of separate CSS classes included in provieded sclass attribute
-
isSClassSet
public static boolean isSClassSet(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String... expectedClasses)Checks if provided component has all specified CSS classes set- Parameters:
component- component, which CSS classes are to be testedexpectedClasses- names of required classes- Returns:
trueif all classes are set
-
testSClassSet
public static void testSClassSet(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String... expectedClasses)Checks if provided component has all specified CSS classes set. If not - assertion fails.- Parameters:
component- component, which CSS classes are to be testedexpectedClasses- names of required classes
-
testSClassUnset
public static void testSClassUnset(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String... unexpectedClasses)Checks if provided component none of specified CSS classes set. If not - assertion fails.- Parameters:
component- component, which CSS classes are to be testedunexpectedClasses- names of classes that should not appear
-
isSClassUnset
public static boolean isSClassUnset(org.zkoss.zk.ui.HtmlBasedComponent component, java.lang.String... unexpectedClasses)Checks if provided component none of specified CSS classes set.- Parameters:
component- component, which CSS classes are to be testedunexpectedClasses- names of classes that should not appear- Returns:
trueif none of provided classes are set
-
simulateEvent
public static void simulateEvent(org.zkoss.zk.ui.Component component, java.lang.String eventName, java.lang.Object eventData)
-
simulateEvent
public static void simulateEvent(org.zkoss.zk.ui.Component component, org.zkoss.zk.ui.event.Event event)Simulates anEventat the specifiedComponent. Note that it only calls theEventListeners registered for the given event name and does NOT do zk internal state changes. That means, if you want to test the correct execution of anEventListener, you have do make these state changes manually before calling this method, e.g. if you simulate an onSelect event on a combobox, its selectedItem field is NOT being updated.
-
mockWidgetModel
public static DefaultWidgetModel mockWidgetModel()
-
mockWidgetInstanceManager
public static WidgetInstanceManager mockWidgetInstanceManager()
-
mockWidgetInstanceManager
public static WidgetInstanceManager mockWidgetInstanceManager(TypedSettingsMap widgetSettings)
-
-