Package com.avanza.astrix.test
Class AstrixTestContext
- java.lang.Object
-
- com.avanza.astrix.test.AstrixTestContext
-
- All Implemented Interfaces:
com.avanza.astrix.context.Astrix,com.avanza.astrix.context.AstrixContext,AutoCloseable
public class AstrixTestContext extends Object implements com.avanza.astrix.context.AstrixContext
-
-
Constructor Summary
Constructors Constructor Description AstrixTestContext(com.avanza.astrix.config.MapConfigSource configSource, Class<? extends TestApi>... testApis)AstrixTestContext(Class<? extends TestApi>... testApis)Deprecated.Please useAstrixTestContext(MapConfigSource, Class[])
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()voiddestroy()com.avanza.astrix.context.AstrixContextgetAstrixContext()<T> TgetBean(Class<T> serviceBean)<T> TgetBean(Class<T> serviceBean, String qualifier)com.avanza.astrix.config.MapConfigSourcegetConfigSource()StringgetConfigSourceId()The configSourceId might be used to retrieve the ConfigSource instance usingGlobalConfigSourceRegistry.getConfigSource(String)StringgetServiceRegistryUri()<T extends TestApi>
TgetTestApi(Class<T> testApi)<T> voidregisterProxy(Class<T> service)<T> voidregisterProxy(Class<T> service, String qualifier)voidresetProxies()voidresetTestApis()voidsetConfigurationProperty(String settingName, String value)<T> voidsetProxyState(Class<T> type, String qualifier, T mock)Sets the proxy state for a given proxy in the service registry.<T> voidsetProxyState(Class<T> type, T mock)Sets the proxy state for a given proxy in the service registry.<T> TwaitForBean(Class<T> type, long timeoutMillis)<T> TwaitForBean(Class<T> type, String qualifier, long timeoutMillis)
-
-
-
Constructor Detail
-
AstrixTestContext
@Deprecated @SafeVarargs public AstrixTestContext(Class<? extends TestApi>... testApis)
Deprecated.Please useAstrixTestContext(MapConfigSource, Class[])
-
AstrixTestContext
@SafeVarargs public AstrixTestContext(com.avanza.astrix.config.MapConfigSource configSource, Class<? extends TestApi>... testApis)
-
-
Method Detail
-
getConfigSourceId
public String getConfigSourceId()
The configSourceId might be used to retrieve the ConfigSource instance usingGlobalConfigSourceRegistry.getConfigSource(String)- Returns:
- the configSourceId for the associated ConfigSource.
-
getConfigSource
public com.avanza.astrix.config.MapConfigSource getConfigSource()
-
getServiceRegistryUri
public String getServiceRegistryUri()
- Returns:
- the serviceUri for the associated service-registry.
-
waitForBean
public <T> T waitForBean(Class<T> type, long timeoutMillis) throws InterruptedException
- Specified by:
waitForBeanin interfacecom.avanza.astrix.context.Astrix- Throws:
InterruptedException
-
waitForBean
public <T> T waitForBean(Class<T> type, String qualifier, long timeoutMillis) throws InterruptedException
- Specified by:
waitForBeanin interfacecom.avanza.astrix.context.Astrix- Throws:
InterruptedException
-
getBean
public <T> T getBean(Class<T> serviceBean)
- Specified by:
getBeanin interfacecom.avanza.astrix.context.Astrix
-
getBean
public <T> T getBean(Class<T> serviceBean, String qualifier)
- Specified by:
getBeanin interfacecom.avanza.astrix.context.Astrix
-
destroy
public void destroy()
- Specified by:
destroyin interfacecom.avanza.astrix.context.AstrixContext
-
close
public void close() throws Exception- Specified by:
closein interfaceAutoCloseable- Throws:
Exception
-
registerProxy
public <T> void registerProxy(Class<T> service)
- Parameters:
service- - The qualified bean type to register a proxy for- See Also:
AstrixRuleContext.registerProxy(Class)
-
registerProxy
public <T> void registerProxy(Class<T> service, String qualifier)
- Parameters:
service- - The qualified bean type to register a proxy forqualifier- - The qualifier of the bean type to register a proxy for- See Also:
AstrixRuleContext.registerProxy(Class)
-
setProxyState
public <T> void setProxyState(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, seeAstrixRuleContext.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(Class<T> type, 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, seeAstrixRuleContext.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 formock- - 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()
-
resetTestApis
public void resetTestApis()
-
-