Class AstrixTestContext

  • All Implemented Interfaces:
    com.avanza.astrix.context.Astrix, com.avanza.astrix.context.AstrixContext, java.lang.AutoCloseable

    public class AstrixTestContext
    extends java.lang.Object
    implements com.avanza.astrix.context.AstrixContext
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void close()  
      void destroy()  
      com.avanza.astrix.context.AstrixContext getAstrixContext()  
      <T> T getBean​(java.lang.Class<T> serviceBean)  
      <T> T getBean​(java.lang.Class<T> serviceBean, java.lang.String qualifier)  
      com.avanza.astrix.config.MapConfigSource getConfigSource()  
      java.lang.String getConfigSourceId()
      The configSourceId might be used to retrieve the ConfigSource instance using GlobalConfigSourceRegistry.getConfigSource(String)
      java.lang.String getServiceRegistryUri()  
      <T extends TestApi>
      T
      getTestApi​(java.lang.Class<T> testApi)  
      <T> void registerProxy​(java.lang.Class<T> service)  
      <T> void registerProxy​(java.lang.Class<T> service, java.lang.String qualifier)  
      void resetProxies()  
      void resetTestApis()  
      void setConfigurationProperty​(java.lang.String settingName, java.lang.String value)  
      <T> void setProxyState​(java.lang.Class<T> type, java.lang.String qualifier, T mock)
      Sets the proxy state for a given proxy in the service registry.
      <T> void setProxyState​(java.lang.Class<T> type, T mock)
      Sets the proxy state for a given proxy in the service registry.
      <T> T waitForBean​(java.lang.Class<T> type, long timeoutMillis)  
      <T> T waitForBean​(java.lang.Class<T> type, java.lang.String qualifier, long timeoutMillis)  
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • AstrixTestContext

        @SafeVarargs
        public AstrixTestContext​(com.avanza.astrix.config.MapConfigSource configSource,
                                 java.lang.Class<? extends TestApi>... testApis)
    • Method Detail

      • getConfigSourceId

        public java.lang.String getConfigSourceId()
        The configSourceId might be used to retrieve the ConfigSource instance using GlobalConfigSourceRegistry.getConfigSource(String)
        Returns:
        the configSourceId for the associated ConfigSource.
      • getConfigSource

        public com.avanza.astrix.config.MapConfigSource getConfigSource()
      • getServiceRegistryUri

        public java.lang.String getServiceRegistryUri()
        Returns:
        the serviceUri for the associated service-registry.
      • waitForBean

        public <T> T waitForBean​(java.lang.Class<T> type,
                                 long timeoutMillis)
                          throws java.lang.InterruptedException
        Specified by:
        waitForBean in interface com.avanza.astrix.context.Astrix
        Throws:
        java.lang.InterruptedException
      • waitForBean

        public <T> T waitForBean​(java.lang.Class<T> type,
                                 java.lang.String qualifier,
                                 long timeoutMillis)
                          throws java.lang.InterruptedException
        Specified by:
        waitForBean in interface com.avanza.astrix.context.Astrix
        Throws:
        java.lang.InterruptedException
      • getBean

        public <T> T getBean​(java.lang.Class<T> serviceBean)
        Specified by:
        getBean in interface com.avanza.astrix.context.Astrix
      • getBean

        public <T> T getBean​(java.lang.Class<T> serviceBean,
                             java.lang.String qualifier)
        Specified by:
        getBean in interface com.avanza.astrix.context.Astrix
      • destroy

        public void destroy()
        Specified by:
        destroy in interface com.avanza.astrix.context.AstrixContext
      • close

        public void close()
                   throws java.lang.Exception
        Specified by:
        close in interface java.lang.AutoCloseable
        Throws:
        java.lang.Exception
      • registerProxy

        public <T> void registerProxy​(java.lang.Class<T> service)
        Parameters:
        service - - The qualified bean type to register a proxy for
        See Also:
        AstrixRuleContext.registerProxy(Class)
      • registerProxy

        public <T> void registerProxy​(java.lang.Class<T> service,
                                      java.lang.String qualifier)
        Parameters:
        service - - The qualified bean type to register a proxy for
        qualifier - - The qualifier of the bean type to register a proxy for
        See Also:
        AstrixRuleContext.registerProxy(Class)
      • setProxyState

        public <T> void setProxyState​(java.lang.Class<T> type,
                                      T mock)
        Sets the proxy state for a given proxy in the service registry. If no proxy has bean registered before it will be created with the given initial state, see AstrixRuleContext.registerProxy(Class) for more details. When a service-provider is proxied it allows fast switching of the given provider between different test-runs, without restarting the entire test environment.
        Parameters:
        type - - The api to register a provider for.
        mock - - The instance to delegate all invocations to the given api to. Might be null in which case a ServiceUnavailableException will be thrown when the service is invoked.
      • setProxyState

        public <T> void setProxyState​(java.lang.Class<T> type,
                                      java.lang.String qualifier,
                                      T mock)
        Sets the proxy state for a given proxy in the service registry. If no proxy has bean registered before it will be created with the given initial state, see AstrixRuleContext.registerProxy(Class) for more details. When a service-provider is proxied it allows fast switching of the given provider between different test-runs, without restarting the entire test environment.
        Parameters:
        type - - The api to register a provider for.
        qualifier - - The qualifier for the service bean to register a provider for
        mock - - The instance to delegate all invocations to the given api to. Might be null in which case a ServiceUnavailableException will be thrown when the service is invoked.
      • resetProxies

        public void resetProxies()
      • getAstrixContext

        public com.avanza.astrix.context.AstrixContext getAstrixContext()
      • getTestApi

        public <T extends TestApi> T getTestApi​(java.lang.Class<T> testApi)
      • resetTestApis

        public void resetTestApis()
      • setConfigurationProperty

        public void setConfigurationProperty​(java.lang.String settingName,
                                             java.lang.String value)