Class APIMIntegrationBaseTest
java.lang.Object
org.wso2.am.integration.test.utils.base.APIMIntegrationBaseTest
- Direct Known Subclasses:
APIManagerLifecycleBaseTest
Base class for all API Manager integration tests
Users need to extend this class to write integration tests.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected org.wso2.carbon.automation.engine.context.AutomationContextprotected Stringprotected Stringprotected APIMURLBeanprotected AdminDashboardRestClientprotected APIMTestCaseUtilsprotected APIPublisherRestClientprotected APIStoreRestClientprotected ApplicationManagementClientprotected org.wso2.carbon.automation.engine.context.AutomationContextprotected APIMURLBeanprotected CarbonApplicationUploaderClientprotected Stringprotected org.wso2.carbon.automation.engine.context.AutomationContextprotected org.wso2.carbon.automation.engine.context.AutomationContextprotected Stringprotected APIMURLBeanprotected APIMURLBeanprotected IdentityProviderMgtClientprotected IdentityProviderMgtServiceClientprotected final intprotected org.wso2.carbon.automation.engine.context.AutomationContextprotected Stringprotected Stringprotected Stringprotected APIMURLBeanprotected OAuthAdminServiceClientprotected final intprotected org.wso2.carbon.automation.engine.context.AutomationContextprotected Stringprotected Stringprotected APIMURLBeanprotected ClaimMetaDataMgtAdminClientprotected RemoteUserStoreManagerServiceClientprotected RestAPIAdminImplprotected RestAPIGovernanceImplprotected RestAPIInternalImplprotected RestAPIPublisherImplprotected RestAPIServiceCatalogImplprotected RestAPIStoreImplprotected org.wso2.carbon.automation.engine.context.AutomationContextprotected Stringprotected Stringprotected APIMURLBeanprotected org.wso2.carbon.automation.engine.context.AutomationContextprotected org.apache.axiom.om.OMElementprotected org.wso2.carbon.integration.common.admin.client.TenantManagementServiceClientprotected org.wso2.carbon.automation.engine.context.beans.Userprotected org.wso2.carbon.integration.common.admin.client.UserManagementClientprotected org.wso2.carbon.automation.engine.context.TestUserMode -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidcleanUp()Cleaning up the API manager by removing all APIs and applications other than default applicationprotected StringcreateAPIProductRevisionAndDeployUsingRest(String apiId, RestAPIPublisherImpl restAPIPublisher) Create API Product Revision and Deploy to gateway using REST API.protected StringcreateAPIRevisionAndDeployToGatewayUsingRest(String apiId, RestAPIPublisherImpl restAPIPublisher, String gatewayEnvironment) Create API Revision and Deploy to given gateway using REST API.protected StringcreateAPIRevisionAndDeployUsingRest(String apiId, RestAPIPublisherImpl restAPIPublisher) Create API Revision and Deploy to gateway using REST API.protected StringcreateSession(org.wso2.carbon.automation.engine.context.AutomationContext automationContext) protected StringGet test artifact resources locationprotected StringgetAPIInvocationURLHttp(String apiContext) protected StringgetAPIInvocationURLHttp(String apiContext, String version) protected StringgetAPIInvocationURLHttps(String apiContext) protected StringgetAPIInvocationURLHttps(String apiContext, String version) To get the API invocation in https with context and version.protected StringgetAPIProductInvocationURLHttps(String apiContext) To get the API Productinvocation in https with context and version.protected intgetAvailablePort(int lowerPortLimit, int upperPortLimit) Find a free port to start backend WebSocket server in given port rangeprotected StringgetBackendEndServiceEndPointHttp(String serviceName) protected StringgetBackendEndServiceEndPointHttps(String serviceName) protected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected Stringprotected RestAPIPublisherImplgetRestAPIPublisherForUser(String user, String pass, String tenantDomain) protected RestAPIStoreImplgetRestAPIStoreForAnonymousUser(String tenantDomain) protected RestAPIStoreImplgetRestAPIStoreForUser(String user, String pass, String tenantDomain) protected Stringprotected Stringprotected StringgetSuperTenantAPIInvocationURLHttp(String apiContext, String version) protected static longprotected StringgetWebSocketAPIInvocationURL(String apiContext, String version) protected StringgetWebSocketTenantAPIInvocationURL(String apiContext, String version, String tenantDomain) protected voidinit()This method will initialize test environment based on user mode and configuration given at automation.xmlprotected voidinit the object with tenant domain, user key and instance of store,publisher and gateway create context objects and construct URL beanprotected voidinit(org.wso2.carbon.automation.engine.context.TestUserMode userMode) init the object with user mode , create context objects and get session cookiesprotected voidloadSynapseConfigurationFromClasspath(String relativeFilePath, org.wso2.carbon.automation.engine.context.AutomationContext automationContext, String sessionCookie) protected org.apache.http.HeaderpickHeader(org.apache.http.Header[] headers, String requiredHeader) protected StringRead the file content and return the content as String.protected StringundeployAndDeleteAPIProductRevisionsUsingRest(String apiId, RestAPIPublisherImpl restAPIPublisher) Undeploy and Delete API Product Revisions using REST API.protected StringundeployAndDeleteAPIRevisionsUsingRest(String apiId, RestAPIPublisherImpl restAPIPublisher) Undeploy and Delete API Revisions using REST API.protected voidupdateSynapseConfiguration(org.apache.axiom.om.OMElement synapseConfig, org.wso2.carbon.automation.engine.context.AutomationContext automationContext, String sessionCookie) update synapse config to serverprotected voidverifyResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse httpResponse) protected voidThis method can be used to wait for API deployment sync in distributed and clustered environment APIStatusMonitor will be invoked to get API related data and then verify that data matches with expected response provided.protected voidwaitForAPIDeploymentSync(String apiProvider, String apiName, String apiVersion, String expectedResponse) This method can be used to wait for API deployment sync in distributed and clustered environment APIStatusMonitor will be invoked to get API related data and then verify that data matches with expected response provided.protected voidwaitForAPIUnDeploymentSync(String apiProvider, String apiName, String apiVersion, String expectedResponse) This method can be used to wait for API Un-deployment sync in distributed and clustered environment APIStatusMonitor will be invoked to get API related data and then verify that data matches with expected response provided.protected voidwaitForKeyManagerDeployment(String tenantDomain, String keyManagerName) protected voidwaitForKeyManagerUnDeployment(String tenantDomain, String keyManagerName) protected static void
-
Field Details
-
storeContext
protected org.wso2.carbon.automation.engine.context.AutomationContext storeContext -
publisherContext
protected org.wso2.carbon.automation.engine.context.AutomationContext publisherContext -
keyManagerContext
protected org.wso2.carbon.automation.engine.context.AutomationContext keyManagerContext -
gatewayContextMgt
protected org.wso2.carbon.automation.engine.context.AutomationContext gatewayContextMgt -
gatewayContextWrk
protected org.wso2.carbon.automation.engine.context.AutomationContext gatewayContextWrk -
backEndServer
protected org.wso2.carbon.automation.engine.context.AutomationContext backEndServer -
superTenantKeyManagerContext
protected org.wso2.carbon.automation.engine.context.AutomationContext superTenantKeyManagerContext -
adminContext
protected org.wso2.carbon.automation.engine.context.AutomationContext adminContext -
synapseConfiguration
protected org.apache.axiom.om.OMElement synapseConfiguration -
apimTestCaseUtils
-
userMode
protected org.wso2.carbon.automation.engine.context.TestUserMode userMode -
executionMode
-
storeUrls
-
publisherUrls
-
gatewayUrlsMgt
-
gatewayUrlsWrk
-
keyMangerUrl
-
backEndServerUrl
-
adminUrls
-
user
protected org.wso2.carbon.automation.engine.context.beans.User user -
apiPublisher
-
apiStore
-
apiAdmin
-
restAPIPublisher
-
restAPIServiceCatalog
-
restAPIStore
-
restAPIAdmin
-
restAPIGovernance
-
userManagementClient
protected org.wso2.carbon.integration.common.admin.client.UserManagementClient userManagementClient -
remoteUserStoreManagerServiceClient
-
remoteClaimMetaDataMgtAdminClient
-
identityProviderMgtClient
-
oAuthAdminServiceClient
-
applicationManagementClient
-
identityProviderMgtServiceClient
-
carbonApplicationUploaderClient
-
tenantManagementServiceClient
protected org.wso2.carbon.integration.common.admin.client.TenantManagementServiceClient tenantManagementServiceClient -
publisherURLHttp
-
publisherURLHttps
-
adminURLHttp
-
adminURLHttps
-
keyManagerHTTPSURL
-
gatewayHTTPSURL
-
storeURLHttp
-
storeURLHttps
-
keymanagerSessionCookie
-
keymanagerSuperTenantSessionCookie
-
restAPIInternal
-
inboundWebSocketPort
protected final int inboundWebSocketPort- See Also:
-
portOffset
protected final int portOffset- See Also:
-
-
Constructor Details
-
APIMIntegrationBaseTest
public APIMIntegrationBaseTest()
-
-
Method Details
-
init
This method will initialize test environment based on user mode and configuration given at automation.xml- Throws:
APIManagerIntegrationTestException- - if test configuration init fails
-
init
protected void init(org.wso2.carbon.automation.engine.context.TestUserMode userMode) throws APIManagerIntegrationTestException init the object with user mode , create context objects and get session cookies- Parameters:
userMode- - user mode to run the tests- Throws:
APIManagerIntegrationTestException- - if test configuration init fails
-
init
init the object with tenant domain, user key and instance of store,publisher and gateway create context objects and construct URL bean- Parameters:
domainKey- - tenant domain keyuserKey- - tenant user key- Throws:
APIManagerIntegrationTestException- - if test configuration init fails
-
loadSynapseConfigurationFromClasspath
protected void loadSynapseConfigurationFromClasspath(String relativeFilePath, org.wso2.carbon.automation.engine.context.AutomationContext automationContext, String sessionCookie) throws APIManagerIntegrationTestException - Parameters:
relativeFilePath- - file path to load config- Throws:
APIManagerIntegrationTestException- - Throws if load synapse configuration from file path fails
-
createSession
protected String createSession(org.wso2.carbon.automation.engine.context.AutomationContext automationContext) throws APIManagerIntegrationTestException - Parameters:
automationContext- - automation context instance of given server- Returns:
- - created session cookie variable
- Throws:
APIManagerIntegrationTestException- - Throws if creating session cookie fails
-
getAMResourceLocation
Get test artifact resources location- Returns:
- - absolute patch of test artifact directory
-
updateSynapseConfiguration
protected void updateSynapseConfiguration(org.apache.axiom.om.OMElement synapseConfig, org.wso2.carbon.automation.engine.context.AutomationContext automationContext, String sessionCookie) throws APIManagerIntegrationTestException update synapse config to server- Parameters:
synapseConfig- - config to uploadautomationContext- - automation context of the server instancesessionCookie- - logged in session cookie- Throws:
APIManagerIntegrationTestException- - If synapse config update fails
-
getStoreURLHttp
-
getStoreURLHttps
-
getPublisherURLHttp
-
getPublisherURLHttps
-
getGatewayMgtURLHttp
-
getGatewayMgtBackendURLHttps
-
getGatewayMgtURLHttps
-
getGatewayURLHttp
-
getGatewayURLNhttp
-
getGatewayURLHttps
-
getGatewayURLNhttps
-
getKeyManagerURLHttp
-
getKeyManagerURLHttps
- Throws:
XPathExpressionException
-
getAPIInvocationURLHttp
- Throws:
XPathExpressionException
-
getAPIInvocationURLHttp
protected String getAPIInvocationURLHttp(String apiContext, String version) throws XPathExpressionException - Throws:
XPathExpressionException
-
getAPIInvocationURLHttps
protected String getAPIInvocationURLHttps(String apiContext, String version) throws XPathExpressionException To get the API invocation in https with context and version.- Parameters:
apiContext- Relevant context of the API.version- Version of the API.- Returns:
- Https url related with api context and version.
- Throws:
XPathExpressionException- XPath Express Exception.
-
getAPIProductInvocationURLHttps
To get the API Productinvocation in https with context and version.- Parameters:
apiContext- Relevant context of the API Product.- Returns:
- Https url related with api context and version.
- Throws:
XPathExpressionException- XPath Express Exception.
-
getWebSocketAPIInvocationURL
protected String getWebSocketAPIInvocationURL(String apiContext, String version) throws XPathExpressionException - Throws:
XPathExpressionException
-
getWebSocketTenantAPIInvocationURL
protected String getWebSocketTenantAPIInvocationURL(String apiContext, String version, String tenantDomain) throws XPathExpressionException - Throws:
XPathExpressionException
-
getAPIInvocationURLHttps
- Throws:
XPathExpressionException
-
getBackendEndServiceEndPointHttp
-
getBackendEndServiceEndPointHttps
-
getSuperTenantAPIInvocationURLHttp
protected String getSuperTenantAPIInvocationURLHttp(String apiContext, String version) throws XPathExpressionException - Throws:
XPathExpressionException
-
cleanUp
Cleaning up the API manager by removing all APIs and applications other than default application- Throws:
APIManagerIntegrationTestException- - occurred when calling the apisException
-
verifyResponse
protected void verifyResponse(org.wso2.carbon.automation.test.utils.http.client.HttpResponse httpResponse) throws org.json.JSONException - Throws:
org.json.JSONException
-
waitForAPIDeployment
protected void waitForAPIDeployment()This method can be used to wait for API deployment sync in distributed and clustered environment APIStatusMonitor will be invoked to get API related data and then verify that data matches with expected response provided. -
waitForAPIDeploymentSync
protected void waitForAPIDeploymentSync(String apiProvider, String apiName, String apiVersion, String expectedResponse) throws APIManagerIntegrationTestException, XPathExpressionException This method can be used to wait for API deployment sync in distributed and clustered environment APIStatusMonitor will be invoked to get API related data and then verify that data matches with expected response provided.- Parameters:
apiProvider- - Provider of the APIapiName- - API nameapiVersion- - API versionexpectedResponse- - Expected response- Throws:
APIManagerIntegrationTestException- - Throws if something goes wrongXPathExpressionException
-
waitForAPIUnDeploymentSync
protected void waitForAPIUnDeploymentSync(String apiProvider, String apiName, String apiVersion, String expectedResponse) throws APIManagerIntegrationTestException This method can be used to wait for API Un-deployment sync in distributed and clustered environment APIStatusMonitor will be invoked to get API related data and then verify that data matches with expected response provided.- Parameters:
apiProvider- - Provider of the APIapiName- - API nameapiVersion- - API versionexpectedResponse- - Expected response- Throws:
APIManagerIntegrationTestException- - Throws if something goes wrong
-
pickHeader
protected org.apache.http.Header pickHeader(org.apache.http.Header[] headers, String requiredHeader) -
getRestAPIPublisherForUser
protected RestAPIPublisherImpl getRestAPIPublisherForUser(String user, String pass, String tenantDomain) -
getRestAPIStoreForUser
-
getRestAPIStoreForAnonymousUser
-
waitForKeyManagerDeployment
protected void waitForKeyManagerDeployment(String tenantDomain, String keyManagerName) throws XPathExpressionException, UnsupportedEncodingException -
waitForKeyManagerUnDeployment
protected void waitForKeyManagerUnDeployment(String tenantDomain, String keyManagerName) throws XPathExpressionException, UnsupportedEncodingException -
createAPIRevisionAndDeployUsingRest
protected String createAPIRevisionAndDeployUsingRest(String apiId, RestAPIPublisherImpl restAPIPublisher) throws ApiException, org.json.JSONException, APIManagerIntegrationTestException Create API Revision and Deploy to gateway using REST API.- Parameters:
apiId- - API UUIDrestAPIPublisher- - Instance of APIPublisherRestClient- Throws:
ApiExceptionorg.json.JSONExceptionAPIManagerIntegrationTestException
-
createAPIRevisionAndDeployToGatewayUsingRest
protected String createAPIRevisionAndDeployToGatewayUsingRest(String apiId, RestAPIPublisherImpl restAPIPublisher, String gatewayEnvironment) throws ApiException, org.json.JSONException, APIManagerIntegrationTestException Create API Revision and Deploy to given gateway using REST API.- Parameters:
apiId- - API UUIDrestAPIPublisher- - Instance of APIPublisherRestClientgatewayEnvironment- - Gateway environment name- Throws:
ApiExceptionorg.json.JSONExceptionAPIManagerIntegrationTestException
-
undeployAndDeleteAPIRevisionsUsingRest
protected String undeployAndDeleteAPIRevisionsUsingRest(String apiId, RestAPIPublisherImpl restAPIPublisher) throws ApiException, org.json.JSONException, XPathExpressionException, APIManagerIntegrationTestException Undeploy and Delete API Revisions using REST API.- Parameters:
apiId- - API UUIDrestAPIPublisher- - Instance of APIPublisherRestClient- Throws:
ApiExceptionorg.json.JSONExceptionXPathExpressionExceptionAPIManagerIntegrationTestException
-
createAPIProductRevisionAndDeployUsingRest
protected String createAPIProductRevisionAndDeployUsingRest(String apiId, RestAPIPublisherImpl restAPIPublisher) throws ApiException, org.json.JSONException, APIManagerIntegrationTestException Create API Product Revision and Deploy to gateway using REST API.- Parameters:
apiId- - API UUIDrestAPIPublisher- - Instance of APIPublisherRestClient- Throws:
ApiExceptionorg.json.JSONExceptionAPIManagerIntegrationTestException
-
undeployAndDeleteAPIProductRevisionsUsingRest
protected String undeployAndDeleteAPIProductRevisionsUsingRest(String apiId, RestAPIPublisherImpl restAPIPublisher) throws ApiException, org.json.JSONException, XPathExpressionException, APIManagerIntegrationTestException Undeploy and Delete API Product Revisions using REST API.- Parameters:
apiId- - API UUIDrestAPIPublisher- - Instance of APIPublisherRestClient- Throws:
ApiExceptionorg.json.JSONExceptionXPathExpressionExceptionAPIManagerIntegrationTestException
-
getAvailablePort
protected int getAvailablePort(int lowerPortLimit, int upperPortLimit) Find a free port to start backend WebSocket server in given port range- Parameters:
lowerPortLimit- from port numberupperPortLimit- to port number- Returns:
- Available Port Number
-
waitUntilClockMinute
- Throws:
InterruptedException
-
getWaitTime
protected static long getWaitTime() -
readFile
Read the file content and return the content as String.- Parameters:
fileLocation- Location of the file.- Returns:
- String Content of the file.
- Throws:
APIManagerIntegrationTestException- exception throws when reading the file.
-