public class MockUtil extends Object
Caution: This class is not thread-safe.
Upon construction, this class automatically loads test systems and credentials from resource files
TEST_SYSTEMS_RESOURCE_FILE and CREDENTIALS_RESOURCE_FILE (appending the file extensions defined by
CONFIG_FILE_EXTENSIONS). For examples of such files, refer to loadTestSystems(File) and
loadCredentials(File).
In addition, test systems and credentials are read from Java system properties PROPERTY_TEST_SYSTEMS and
PROPERTY_CREDENTIALS. Both properties can be used to specify either the path to or the direct content of a
configuration file. For example, these can be specified via
mvn clean install -Dtest.systems="..." -Dtest.credentials="..." where "..." corresponds to
either the path to a configuration file or the content of such a file.
When specifying paths to test systems and credentials files, the file extension can be omitted (e.g.,
test/resources/systems). In this case, this class will scan for the existence of the following files:
test/resources/systems.jsontest/resources/systems.yamltest/resources/systems.ymlNote that the order is arbitrary here since, if more than one matching file is found, an exception is thrown demanding to specify exactly one file. If test systems or credentials are specified as Java system properties while configuration files exist simultaneously within the the test resources folder, only Java system properties are loaded, thereby overriding configuration from files in the test resources folder.
| Constructor and Description |
|---|
MockUtil()
Instantiates a new instance of
MockUtil, invalidates caches, and resets Hystrix. |
| Modifier and Type | Method and Description |
|---|---|
void |
addCredentials(String systemAlias,
Credentials credentials)
Registers the given
Credentials to enable retrieval by its alias. |
void |
addDefaultErpSystem(ErpSystem erpSystem)
Adds and sets the default ERP system.
|
void |
addTestSystem(TestSystem<?> testSystem)
Registers the given
TestSystem to enable retrieval by its alias. |
void |
clearCredentials()
Clears all
Credentials. |
void |
clearDestinations()
Clears all previously mocked
Destinations. |
void |
clearKeyStores()
Clears all previously mocked
KeyStores. |
void |
clearSecretStores()
Clears all previously mocked
SecretStores. |
void |
clearTenants()
Clears all previously mocked
Tenants. |
void |
clearTestSystems()
Clears all
TestSystems. |
void |
clearUsers()
Clears all previously mocked
Users. |
Credentials |
getCredentials(String systemAlias)
Returns the credentials for the given alias.
|
Credentials |
getCredentials(TestSystem<?> testSystem) |
ErpSystem |
getErpSystem() |
ErpSystem |
getErpSystem(String systemAlias) |
TestSystem<?> |
getTestSystem(String systemAlias)
Returns the
TestSystem for the given alias. |
void |
loadCredentials(File file)
Loads credential configuration from the resource file with the given name.
|
void |
loadCredentials(String resourceFileName)
Delegates to
loadCredentials(File) and loads credential configuration from the resource file with the
given name. |
void |
loadTestSystems(File file)
Loads test system configuration from the given file.
|
void |
loadTestSystems(String resourceFileName)
Delegates to
loadTestSystems(File) and loads test system configuration from the resource file with the
given name. |
AuditLog |
mockAuditLog()
Mocks the
AuditLog, redirecting to DefaultLoggerAuditLog within tests. |
AuditLog |
mockAuditLog(AuditLog delegate)
|
CloudPlatform |
mockCurrentCloudPlatform()
Mocks the current
CloudPlatform using application name MOCKED_CLOUD_APP_NAME. |
CloudPlatform |
mockCurrentCloudPlatform(String applicationName)
Mocks the current
CloudPlatform using the given application name. |
void |
mockCurrentLocales()
|
void |
mockCurrentLocales(Locale locale,
Locale... additionalLocales)
Mocks the current
Locales with the given values. |
Tenant |
mockCurrentTenant()
Mocks the current
Tenant with tenant identifier MOCKED_TENANT. |
Tenant |
mockCurrentTenant(String tenantId)
Mocks a
Tenant with the given identifier. |
User |
mockCurrentUser()
Mocks the current
User with user name MOCKED_USER. |
User |
mockCurrentUser(String userName)
Mocks the current
User with the given name. |
User |
mockCurrentUser(String userName,
Locale locale,
Collection<Authorization> authorizations,
Map<String,UserAttribute> attributes)
Mocks the current
User. |
void |
mockDefaults()
Mocks common defaults for testing, in particular:
facades that are used to realize Cloud platform abstractions,
the current
CloudPlatform,
the current Locale,
the current Tenant,
the current User
This method should be called as the first method of MockUtil in the test setup method annotated with
@BeforeClass. |
Destination |
mockDestination(MockDestination destination)
Mocks a destination based on the given
MockDestination. |
Destination |
mockDestination(String name,
String systemAlias)
Mocks a destination with a given name to the given system with the registered credentials.
|
Destination |
mockDestination(String name,
TestSystem<?> testSystem)
Mocks a destination with a given name to the given
TestSystem with the registered credentials. |
Destination |
mockDestination(String name,
URI uri)
Mocks a destination with a given name to redirect to the given
URI with no authentication. |
Destination |
mockDestination(String name,
URI uri,
AuthenticationType authenticationType,
ProxyType proxyType,
ProxyConfiguration proxyConfiguration,
List<Header> headers,
KeyStore trustStore,
String trustStorePassword,
Boolean isTrustingAllCertificates,
KeyStore keyStore,
String keyStorePassword,
Map<String,String> propertiesByName)
Mocks a destination based on the given parameters.
|
Destination |
mockDestination(String name,
URI uri,
Credentials credentials)
Mocks a destination with a given name to redirect to the given
URI with the given Credentials. |
Destination |
mockDestination(String name,
URI uri,
Credentials credentials,
ProxyConfiguration proxyConfiguration)
Mocks a destination with a given name to redirect to the given
URI with the given Credentials. |
Destination |
mockErpDestination()
Mocks an ERP
Destination by redirecting to an actual ERP system for destination name "ErpQueryEndpoint". |
Destination |
mockErpDestination(ErpSystem erpSystem)
Mocks an ERP
Destination by redirecting to an actual ERP system for destination name "ErpQueryEndpoint". |
Destination |
mockErpDestination(ErpSystem erpSystem,
Credentials credentials)
Mocks an ERP
Destination for the given ErpSystem and Credentials for destination name
"ErpQueryEndpoint". |
Destination |
mockErpDestination(MockErpDestination destination)
Mocks an ERP
Destination for the given MockErpDestination. |
Destination |
mockErpDestination(String systemAlias)
Mocks an ERP
Destination by redirecting to an actual ERP system for destination name "ErpQueryEndpoint". |
Destination |
mockErpDestination(String destinationName,
ErpSystem erpSystem)
Mocks an ERP
Destination by redirecting to an actual ERP system for the given destination name. |
Destination |
mockErpDestination(String destinationName,
ErpSystem erpSystem,
Credentials credentials)
|
Destination |
mockErpDestination(String destinationName,
ErpSystem erpSystem,
Credentials credentials,
AuthenticationType authenticationType,
ProxyType proxyType,
ProxyConfiguration proxyConfiguration,
List<Header> headers,
KeyStore trustStore,
String trustStorePassword,
Boolean isTrustingAllCertificates,
KeyStore keyStore,
String keyStorePassword,
Map<String,String> propertiesByName)
Mocks an ERP
Destination for the given parameters. |
Destination |
mockErpDestination(String destinationName,
String systemAlias)
Mocks an ERP
Destination by redirecting to an actual ERP system for the given destination name. |
com.github.tomakehurst.wiremock.junit.WireMockRule |
mockErpServer()
Mocks an ERP
Destination with name ErpDestination.getDefaultName() and starts a mock server
pointing all calls against the ERP destination towards the mock server instance. |
com.github.tomakehurst.wiremock.junit.WireMockRule |
mockErpServer(SapClient sapClient)
Mocks an ERP
Destination with name ErpDestination.getDefaultName() and starts a mock server
pointing all calls against the ERP destination towards the mock server instance. |
com.github.tomakehurst.wiremock.junit.WireMockRule |
mockErpServer(SapClient sapClient,
String relativePath)
Mocks an ERP
Destination with name ErpDestination.getDefaultName() and starts a mock server
pointing all calls against the ERP destination towards the mock server instance. |
com.github.tomakehurst.wiremock.junit.WireMockRule |
mockErpServer(String destinationName,
SapClient sapClient,
String relativePath)
Mocks an ERP
Destination and starts a mock server pointing all calls against the ERP destination towards
the mock server instance. |
com.github.tomakehurst.wiremock.junit.WireMockRule |
mockErpServer(String destinationName,
SapClient sapClient,
String relativePath,
com.github.tomakehurst.wiremock.core.WireMockConfiguration configuration)
Mocks an ERP
Destination and starts a mock server pointing all calls against the ERP destination towards
the mock server instance. |
GenericDestination |
mockGenericDestination(DestinationType destinationType,
String destinationName,
Map<String,String> propertiesByName)
Mocks an
GenericDestination for the given parameters. |
GenericDestination |
mockGenericDestination(MockGenericDestination destination)
Mocks an
GenericDestination for the given MockGenericDestination. |
<T> T |
mockJndiLookup(Class<T> cls,
String name)
Mocks a JNDI lookup.
|
void |
mockJndiLookup(Object obj,
String name)
Mocks a JNDI lookup.
|
void |
mockKeyStore(String name,
SecretStore password,
KeyStore keyStore)
Mocks a
KeyStore for a given instance. |
KeyStore |
mockKeyStore(String name,
SecretStore password,
String keyStoreFileName,
String keyStoreType)
Mocks a
KeyStore from a key store resource file. |
void |
mockKeyStore(String name,
String password,
KeyStore keyStore)
Mocks a
KeyStore for a given instance. |
KeyStore |
mockKeyStore(String name,
String password,
String keyStoreFileName,
String keyStoreType)
Mocks a
KeyStore from a key store resource file. |
RfcDestination |
mockRfcDestination()
Mocks an
RfcDestination by redirecting to an actual ERP system for destination name "ErpQueryEndpoint". |
RfcDestination |
mockRfcDestination(ErpSystem erpSystem)
Mocks an
RfcDestination by redirecting to an actual ERP system for destination name "ErpQueryEndpoint". |
RfcDestination |
mockRfcDestination(ErpSystem erpSystem,
Credentials credentials)
Mocks an
RfcDestination for the given ErpSystem and Credentials for destination name
"ErpQueryEndpoint". |
RfcDestination |
mockRfcDestination(MockRfcDestination destination)
Mocks an
RfcDestination for the given MockRfcDestination. |
RfcDestination |
mockRfcDestination(String systemAlias)
Mocks an
RfcDestination by redirecting to an actual ERP system for destination name "ErpQueryEndpoint". |
RfcDestination |
mockRfcDestination(String destinationName,
ErpSystem erpSystem)
Mocks an
RfcDestination by redirecting to an actual ERP system for the given destination name. |
RfcDestination |
mockRfcDestination(String destinationName,
ErpSystem erpSystem,
Credentials credentials)
|
RfcDestination |
mockRfcDestination(String destinationName,
ErpSystem erpSystem,
Credentials credentials,
Map<String,String> propertiesByName)
Mocks an
RfcDestination for the given parameters. |
RfcDestination |
mockRfcDestination(String destinationName,
String systemAlias)
Mocks an
RfcDestination by redirecting to an actual ERP system for the given destination name. |
void |
mockSecretStore(String name,
SecretStore secretStore)
Mocks a
SecretStore for a given instance. |
SecretStore |
mockSecretStore(String name,
String password)
Mocks a
SecretStore for a given password. |
com.github.tomakehurst.wiremock.junit.WireMockRule |
mockServer(String destinationName)
Mocks a
Destination and starts a mock server pointing all calls against the destination towards the mock
server instance. |
com.github.tomakehurst.wiremock.junit.WireMockRule |
mockServer(String destinationName,
String relativePath)
Mocks a
Destination and starts a mock server pointing all calls against the destination towards the mock
server instance. |
com.github.tomakehurst.wiremock.junit.WireMockRule |
mockServer(String destinationName,
String relativePath,
com.github.tomakehurst.wiremock.core.WireMockConfiguration configuration)
Mocks a
Destination and starts a mock server pointing all calls against the destination towards the mock
server instance. |
Tenant |
mockTenant(String tenantId)
Mocks a
Tenant with the given identifier. |
User |
mockUser(String userName)
Mocks a
User with the given name. |
User |
mockUser(String userName,
Locale locale,
Collection<Authorization> authorizations,
Map<String,UserAttribute> attributes)
Mocks a
User. |
void |
removeCredentials(String systemAlias)
Unregisters the
Credentials for the given alias. |
void |
removeTestSystem(String systemAlias)
Unregisters the
TestSystem for the given alias. |
void |
removeTestSystem(TestSystem<?> testSystem)
Unregisters the given
TestSystem. |
void |
setCurrentTenant(String tenantId)
Sets the current
Tenant. |
void |
setCurrentUser(String userName)
Sets the current
User. |
MockUtil |
withProxy(ProxyConfiguration proxyConfiguration) |
public MockUtil()
MockUtil, invalidates caches, and resets Hystrix.
Note: To avoid potential side effects, only one instance of MockUtil should exist within a test class. It is
therefore recommended to maintain an instance of this class as a static member of the test class. Example usage:
private static final MockUtil mockUtil = new MockUtil();
@BeforeClass
public static void beforeClass()
{
mockUtil.mockDefaults();
}
@Nonnull public MockUtil withProxy(@Nullable ProxyConfiguration proxyConfiguration)
public void mockDefaults()
CloudPlatform,Locale,Tenant,UserMockUtil in the test setup method annotated with
@BeforeClass.public void mockJndiLookup(@Nonnull Object obj, @Nonnull String name)
obj - Object to be returned by the lookup.name - Name that is used for the lookup.@Nonnull public <T> T mockJndiLookup(@Nonnull Class<T> cls, @Nonnull String name)
cls - Class to be mocked.name - Name that is used for the lookup.public void mockCurrentLocales()
public void mockCurrentLocales(@Nonnull Locale locale, @Nonnull Locale... additionalLocales)
Locales with the given values.@Nonnull public AuditLog mockAuditLog()
AuditLog, redirecting to DefaultLoggerAuditLog within tests.AuditLog.@Nonnull public CloudPlatform mockCurrentCloudPlatform()
CloudPlatform using application name MOCKED_CLOUD_APP_NAME.@Nonnull public CloudPlatform mockCurrentCloudPlatform(@Nonnull String applicationName)
CloudPlatform using the given application name.@Nonnull public TestSystem<?> getTestSystem(@Nonnull String systemAlias)
TestSystem for the given alias. By default, TestSystems are loaded from the system
property PROPERTY_TEST_SYSTEMS and the test resource file
TEST_SYSTEMS_RESOURCE_FILE (with extension .json/.yml for JSON/YAML format). For registering
additional TestSystems, use loadTestSystems(String) or addTestSystem(TestSystem).@Nonnull public ErpSystem getErpSystem(@Nonnull String systemAlias)
ErpSystem for the given alias. Delegates to getTestSystem(String).public void loadTestSystems(@Nonnull String resourceFileName)
loadTestSystems(File) and loads test system configuration from the resource file with the
given name. The file is assumed to be in JSON format and expected to be located in src/test/resources/.resourceFileName - The name of the file to be loaded from the resources folder.public void loadTestSystems(@Nullable File file)
"alias" field must be unique.
Note: Configuration specified as Java system properties always overrides configuration loaded from files.
Example (YAML):
---
systems:
- alias: "ANY_SYSTEM"
uri: "https://any-system.com"
proxy: "http://my-proxy:8080"
erp:
default: "ERP_001"
systems:
- alias: "ERP_001"
uri: "https://my-erp.com"
systemId: "ERP" # optional, defaults to ""
sapClient: "001" # optional, defaults to default SAP client
locale: "en" # optional, defaults to English (US)
erpEdition: "cloud" # optional, defaults to "cloud"
proxy: "http://my-proxy:8080" # optional
applicationServer: "my-erp.com" # optional, defaults to URI host
instanceNumber: "00" # optional, defaults to "00"
Example (JSON):
{
"systems": [
{
"alias": "ANY_SYSTEM",
"uri": "https://any-system.com",
"proxy": "http://my-proxy:8080"
}
],
"erp": {
"default": "ERP_001",
"systems": [
{
"alias": "ERP_001",
"systemId": "ERP",
"sapClient": "001",
"locale": "en-US",
"erpEdition": "cloud",
"uri": "https://my-erp.com",
"proxy": "http://my-proxy:8080",
"applicationServer": "my-erp.com",
"instanceNumber": "00"
}
]
}
}
file - The file to be loaded.public void addTestSystem(@Nonnull TestSystem<?> testSystem)
TestSystem to enable retrieval by its alias. Replaces TestSystems that may
already exist for the given alias.public void removeTestSystem(@Nonnull TestSystem<?> testSystem)
TestSystem.public void removeTestSystem(@Nonnull String systemAlias)
TestSystem for the given alias.public void addDefaultErpSystem(@Nonnull ErpSystem erpSystem)
public void clearTestSystems()
TestSystems.@Nonnull public Credentials getCredentials(@Nonnull TestSystem<?> testSystem)
TestSystem. Delegates to getCredentials(String).@Nonnull public Credentials getCredentials(@Nonnull String systemAlias)
Credentials are loaded from the Java system
property PROPERTY_CREDENTIALS and the test resource file
CREDENTIALS_RESOURCE_FILE. For registering additional Credentials, use
loadCredentials(String) or addCredentials(String, Credentials).public void loadCredentials(@Nonnull String resourceFileName)
loadCredentials(File) and loads credential configuration from the resource file with the
given name. The file is assumed to be in JSON format and expected to be located in /src/test/resources/.resourceFileName - The name of the file to be loaded from the resources folder.public void loadCredentials(@Nullable File file)
Note: Configuration specified as Java system properties always overrides configuration loaded from files.
Example (YAML):
---
credentials:
- alias: "ABC_001"
username: "(username)"
password: "(password)"
Example (JSON):
{
"credentials": [
{
"alias": "ABC_001",
"username": "(username)",
"password": "(password)"
}
]
}
file - The file to be loaded.public void addCredentials(@Nonnull String systemAlias, @Nonnull Credentials credentials)
Credentials to enable retrieval by its alias. Replaces Credentials that may
already exist for the given alias.public void removeCredentials(@Nonnull String systemAlias)
Credentials for the given alias.public void clearCredentials()
Credentials.@Nonnull public Tenant mockTenant(@Nonnull String tenantId)
Tenant with the given identifier.public Tenant mockCurrentTenant()
Tenant with tenant identifier MOCKED_TENANT.@Nonnull public Tenant mockCurrentTenant(@Nonnull String tenantId)
Tenant with the given identifier.public void clearTenants()
Tenants.@Nonnull public User mockUser(@Nonnull String userName, @Nullable Locale locale, @Nullable Collection<Authorization> authorizations, @Nullable Map<String,UserAttribute> attributes)
User.userName - Name of the user.locale - Optional locale of the user.authorizations - Optional authorizations of the user.attributes - Optional attributes of the user.@Nonnull public User mockCurrentUser()
User with user name MOCKED_USER.@Nonnull public User mockCurrentUser(String userName)
User with the given name.@Nonnull public User mockCurrentUser(@Nonnull String userName, @Nullable Locale locale, @Nullable Collection<Authorization> authorizations, @Nullable Map<String,UserAttribute> attributes)
User.userName - Name of the user.locale - Optional locale of the user.authorizations - Optional authorizations of the user.attributes - Optional attributes of the user.public void clearUsers()
Users.public void mockSecretStore(@Nonnull String name, @Nonnull SecretStore secretStore)
SecretStore for a given instance.name - The name of the SecretStore.secretStore - The instance of SecretStore.@Nonnull public SecretStore mockSecretStore(@Nonnull String name, @Nonnull String password)
SecretStore for a given password.name - The name of the SecretStore.password - The password of the SecretStore.public void mockKeyStore(@Nonnull String name, @Nonnull SecretStore password, @Nonnull KeyStore keyStore)
KeyStore for a given instance.name - The name of the KeyStore.password - The password of the KeyStore as SecretStore.keyStore - The instance of KeyStore.public void mockKeyStore(@Nonnull String name, @Nonnull String password, @Nonnull KeyStore keyStore)
KeyStore for a given instance.@Nonnull public KeyStore mockKeyStore(@Nonnull String name, @Nonnull SecretStore password, @Nonnull String keyStoreFileName, @Nonnull String keyStoreType)
KeyStore from a key store resource file.name - The name of the KeyStore.password - The password of the KeyStore as SecretStore.keyStoreFileName - The file name pointing to the KeyStore to be loaded.keyStoreType - The type of the KeyStore to be loaded.@Nonnull public KeyStore mockKeyStore(@Nonnull String name, @Nonnull String password, @Nonnull String keyStoreFileName, @Nonnull String keyStoreType)
KeyStore from a key store resource file.public void clearSecretStores()
SecretStores.public void clearKeyStores()
KeyStores.@Nonnull public GenericDestination mockGenericDestination(@Nonnull DestinationType destinationType, @Nonnull String destinationName, @Nullable Map<String,String> propertiesByName)
GenericDestination for the given parameters.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
destinationName - The name of the mocked destination.propertiesByName - Properties of the GenericDestination by their name.@Nonnull public GenericDestination mockGenericDestination(@Nonnull MockGenericDestination destination)
GenericDestination for the given MockGenericDestination.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
@Nonnull public Destination mockDestination(@Nonnull String name, @Nonnull String systemAlias)
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
@Nonnull public Destination mockDestination(@Nonnull String name, @Nonnull TestSystem<?> testSystem)
TestSystem with the registered credentials.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
@Nonnull public Destination mockDestination(@Nonnull String name, @Nonnull URI uri)
URI with no authentication.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
@Nonnull public Destination mockDestination(@Nonnull String name, @Nonnull URI uri, @Nullable Credentials credentials)
URI with the given Credentials.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
@Nonnull public Destination mockDestination(@Nonnull String name, @Nonnull URI uri, @Nullable Credentials credentials, @Nullable ProxyConfiguration proxyConfiguration)
URI with the given Credentials.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
@Nonnull public Destination mockDestination(@Nonnull String name, @Nonnull URI uri, @Nullable AuthenticationType authenticationType, @Nullable ProxyType proxyType, @Nullable ProxyConfiguration proxyConfiguration, @Nullable List<Header> headers, @Nullable KeyStore trustStore, @Nullable String trustStorePassword, @Nullable Boolean isTrustingAllCertificates, @Nullable KeyStore keyStore, @Nullable String keyStorePassword, @Nullable Map<String,String> propertiesByName)
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
@Nonnull public Destination mockDestination(@Nonnull MockDestination destination)
MockDestination.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
@Nonnull public Destination mockErpDestination()
Destination by redirecting to an actual ERP system for destination name "ErpQueryEndpoint".
The system that is used is either defined as property PROPERTY_ERP_ALIAS or in the Java system
property PROPERTY_TEST_SYSTEMS and the test resource file
TEST_SYSTEMS_RESOURCE_FILE (with extension .json/.yml for JSON/YAML format).
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
@Nonnull public Destination mockErpDestination(@Nonnull String systemAlias)
Destination by redirecting to an actual ERP system for destination name "ErpQueryEndpoint".
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
systemAlias - The alias of the ErpSystem that should be used. Must not be null.@Nonnull public Destination mockErpDestination(@Nullable ErpSystem erpSystem)
Destination by redirecting to an actual ERP system for destination name "ErpQueryEndpoint".
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
erpSystem - The ErpSystem to use for mocking. If null, {getErpSystem() is used.@Nonnull public Destination mockErpDestination(@Nullable ErpSystem erpSystem, @Nullable Credentials credentials)
Destination for the given ErpSystem and Credentials for destination name
"ErpQueryEndpoint".
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
erpSystem - The ErpSystem to use for mocking. If null, {getErpSystem() is used.credentials - The Credentials to be used for accessing the system. If null, they are resolved from
configuration files or explicit registration via addCredentials(String, Credentials).
Only adds the respective HTTP header for the given credentials if the header does not yet exist.@Nonnull public Destination mockErpDestination(@Nullable String destinationName, @Nonnull String systemAlias)
Destination by redirecting to an actual ERP system for the given destination name.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
destinationName - The name of the mocked destination. If null, "ErpQueryEndpoint" is used.systemAlias - The alias of the ErpSystem that should be used. Must not be null.@Nonnull public Destination mockErpDestination(@Nullable String destinationName, @Nullable ErpSystem erpSystem)
Destination by redirecting to an actual ERP system for the given destination name.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
destinationName - The name of the mocked destination. If null, "ErpQueryEndpoint" is used.erpSystem - The ErpSystem to use for mocking. If null, {getErpSystem() is used.@Nonnull public Destination mockErpDestination(@Nullable String destinationName, @Nullable ErpSystem erpSystem, @Nullable Credentials credentials)
Destination for the given destination name, ErpSystem and Credentials.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
destinationName - The name of the mocked destination. If null, "ErpQueryEndpoint" is used.erpSystem - The ErpSystem to use for mocking. If null, {getErpSystem() is used.credentials - The Credentials to be used for accessing the system. If null, they are resolved from
configuration files or explicit registration via addCredentials(String, Credentials).
Only adds the respective HTTP header for the given credentials if the header does not yet exist.@Nonnull public Destination mockErpDestination(@Nullable String destinationName, @Nullable ErpSystem erpSystem, @Nullable Credentials credentials, @Nullable AuthenticationType authenticationType, @Nullable ProxyType proxyType, @Nullable ProxyConfiguration proxyConfiguration, @Nullable List<Header> headers, @Nullable KeyStore trustStore, @Nullable String trustStorePassword, @Nullable Boolean isTrustingAllCertificates, @Nullable KeyStore keyStore, @Nullable String keyStorePassword, @Nullable Map<String,String> propertiesByName)
Destination for the given parameters.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
destinationName - The name of the mocked destination. If null, "ErpQueryEndpoint" is used.erpSystem - The ErpSystem to use for mocking. If null, {getErpSystem() is used.credentials - The Credentials to be used for accessing the system. If null, they are resolved from
configuration files or explicit registration via addCredentials(String, Credentials).
Only adds the respective HTTP header for the given credentials if the header does not yet exist.authenticationType - The AuthenticationType to be used.proxyType - The ProxyType to be used. If not null, overrides the ProxyType inferred from
the ErpSystem.proxyConfiguration - The ProxyConfiguration to be used.headers - Headers to be used.trustStore - The trust store to be used.trustStorePassword - The trust store password to be used.isTrustingAllCertificates - Decides whether all certificates are trusted.keyStore - The KeyStore to be used.keyStorePassword - The KeyStore password to be used.propertiesByName - Properties of the Destination by their name. If a property with the respective name is
provided, it will override pre-configured properties such as "sap-client".@Nonnull public Destination mockErpDestination(@Nonnull MockErpDestination destination)
Destination for the given MockErpDestination.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
@Nonnull public RfcDestination mockRfcDestination()
RfcDestination by redirecting to an actual ERP system for destination name "ErpQueryEndpoint".
The system that is used is either defined as property PROPERTY_ERP_ALIAS or in the Java system
property PROPERTY_TEST_SYSTEMS and the test resource file
TEST_SYSTEMS_RESOURCE_FILE (with extension .json/.yml for JSON/YAML format).
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
@Nonnull public RfcDestination mockRfcDestination(@Nonnull String systemAlias)
RfcDestination by redirecting to an actual ERP system for destination name "ErpQueryEndpoint".
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
systemAlias - The alias of the ErpSystem that should be used. Must not be null.@Nonnull public RfcDestination mockRfcDestination(@Nullable ErpSystem erpSystem)
RfcDestination by redirecting to an actual ERP system for destination name "ErpQueryEndpoint".
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
erpSystem - The ErpSystem to use for mocking. If null, {getErpSystem() is used.@Nonnull public RfcDestination mockRfcDestination(@Nullable ErpSystem erpSystem, @Nullable Credentials credentials)
RfcDestination for the given ErpSystem and Credentials for destination name
"ErpQueryEndpoint".
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
erpSystem - The ErpSystem to use for mocking. If null, {getErpSystem() is used.credentials - The Credentials to be used for accessing the system. If null, they are resolved from
configuration files or explicit registration via addCredentials(String, Credentials).@Nonnull public RfcDestination mockRfcDestination(@Nullable String destinationName, @Nonnull String systemAlias)
RfcDestination by redirecting to an actual ERP system for the given destination name.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
destinationName - The name of the mocked destination. If null, "ErpQueryEndpoint" is used.systemAlias - The alias of the ErpSystem that should be used. Must not be null.@Nonnull public RfcDestination mockRfcDestination(@Nullable String destinationName, @Nullable ErpSystem erpSystem)
RfcDestination by redirecting to an actual ERP system for the given destination name.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
destinationName - The name of the mocked destination. If null, "ErpQueryEndpoint" is used.erpSystem - The ErpSystem to use for mocking. If null, {getErpSystem() is used.@Nonnull public RfcDestination mockRfcDestination(@Nullable String destinationName, @Nullable ErpSystem erpSystem, @Nullable Credentials credentials)
RfcDestination for the given destination name, ErpSystem and Credentials.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
destinationName - The name of the mocked destination. If null, "ErpQueryEndpoint" is used.erpSystem - The ErpSystem to use for mocking. If null, {getErpSystem() is used.credentials - The Credentials to be used for accessing the system. If null, they are resolved from
configuration files or explicit registration via addCredentials(String, Credentials).@Nonnull public RfcDestination mockRfcDestination(@Nullable String destinationName, @Nullable ErpSystem erpSystem, @Nullable Credentials credentials, @Nullable Map<String,String> propertiesByName)
RfcDestination for the given parameters.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
destinationName - The name of the mocked destination. If null, "ErpQueryEndpoint" is used.erpSystem - The ErpSystem to use for mocking. If null, {getErpSystem() is used.credentials - The Credentials to be used for accessing the system. If null, they are resolved from
configuration files or explicit registration via addCredentials(String, Credentials).propertiesByName - Properties of the RfcDestination by their name. If a property with the respective name is
provided, it will override pre-configured properties such as "sap-client".@Nonnull public RfcDestination mockRfcDestination(@Nonnull MockRfcDestination destination)
RfcDestination for the given MockRfcDestination.
Note: This invalidates all caches to avoid stale entries within the DestinationsRequestContextListener.
public void clearDestinations()
Destinations.@Nonnull public com.github.tomakehurst.wiremock.junit.WireMockRule mockServer(@Nonnull String destinationName, @Nullable String relativePath, @Nullable com.github.tomakehurst.wiremock.core.WireMockConfiguration configuration)
Destination and starts a mock server pointing all calls against the destination towards the mock
server instance.destinationName - The name of the destination to be mocked. If null, ErpDestination.getDefaultName() is
used.relativePath - An optional relative path to be appended to the ERP URI.configuration - An optional configuration to customize mock server runtime.@Nonnull public com.github.tomakehurst.wiremock.junit.WireMockRule mockServer(@Nonnull String destinationName, @Nullable String relativePath)
Destination and starts a mock server pointing all calls against the destination towards the mock
server instance.destinationName - The name of the destination to be mocked. If null, ErpDestination.getDefaultName() is
used.relativePath - An optional relative path to be appended to the ERP URI.@Nonnull public com.github.tomakehurst.wiremock.junit.WireMockRule mockServer(@Nonnull String destinationName)
Destination and starts a mock server pointing all calls against the destination towards the mock
server instance.destinationName - The name of the destination to be mocked. If null, ErpDestination.getDefaultName() is
used.@Nonnull public com.github.tomakehurst.wiremock.junit.WireMockRule mockErpServer(@Nullable String destinationName, @Nullable SapClient sapClient, @Nullable String relativePath, @Nullable com.github.tomakehurst.wiremock.core.WireMockConfiguration configuration)
Destination and starts a mock server pointing all calls against the ERP destination towards
the mock server instance.destinationName - The name of the destination to be mocked. If null, ErpDestination.getDefaultName() is
used.sapClient - The SapClient to be set as a destination property of the mocked destination. If null,
SapClient.DEFAULT is used.relativePath - An optional relative path to be appended to the ERP URI.configuration - An optional configuration to customize mock server runtime.@Nonnull public com.github.tomakehurst.wiremock.junit.WireMockRule mockErpServer(@Nullable String destinationName, @Nullable SapClient sapClient, @Nullable String relativePath)
Destination and starts a mock server pointing all calls against the ERP destination towards
the mock server instance.destinationName - The name of the destination to be mocked. If null, ErpDestination.getDefaultName() is
used.sapClient - The SapClient to be set as a destination property of the mocked destination. If null,
SapClient.DEFAULT is used.relativePath - An optional relative path to be appended to the ERP URI.@Nonnull public com.github.tomakehurst.wiremock.junit.WireMockRule mockErpServer(@Nullable SapClient sapClient, @Nullable String relativePath)
Destination with name ErpDestination.getDefaultName() and starts a mock server
pointing all calls against the ERP destination towards the mock server instance.sapClient - The SapClient to be set as a destination property of the mocked destination. If omitted,
SapClient.DEFAULT is used.relativePath - An optional relative path to be appended to the ERP URI.@Nonnull public com.github.tomakehurst.wiremock.junit.WireMockRule mockErpServer(@Nullable SapClient sapClient)
Destination with name ErpDestination.getDefaultName() and starts a mock server
pointing all calls against the ERP destination towards the mock server instance.sapClient - The SapClient to be set as a destination property of the mocked destination. If omitted,
SapClient.DEFAULT is used.@Nonnull public com.github.tomakehurst.wiremock.junit.WireMockRule mockErpServer()
Destination with name ErpDestination.getDefaultName() and starts a mock server
pointing all calls against the ERP destination towards the mock server instance.Copyright © 2019 SAP SE. All rights reserved.