Class APIMIntegrationBaseTest
- java.lang.Object
-
- org.wso2.am.integration.test.utils.base.APIMIntegrationBaseTest
-
public class APIMIntegrationBaseTest extends Object
Base class for all API Manager integration tests Users need to extend this class to write integration tests.
-
-
Field Summary
Fields Modifier and Type Field Description protected org.wso2.carbon.automation.engine.context.AutomationContextadminContextprotected StringadminURLHttpprotected StringadminURLHttpsprotected APIMURLBeanadminUrlsprotected AdminDashboardRestClientapiAdminprotected APIMTestCaseUtilsapimTestCaseUtilsprotected APIPublisherRestClientapiPublisherprotected APIStoreRestClientapiStoreprotected ApplicationManagementClientapplicationManagementClientprotected org.wso2.carbon.automation.engine.context.AutomationContextbackEndServerprotected APIMURLBeanbackEndServerUrlprotected StringexecutionModeprotected org.wso2.carbon.automation.engine.context.AutomationContextgatewayContextMgtprotected org.wso2.carbon.automation.engine.context.AutomationContextgatewayContextWrkprotected StringgatewayHTTPSURLprotected APIMURLBeangatewayUrlsMgtprotected APIMURLBeangatewayUrlsWrkprotected IdentityProviderMgtClientidentityProviderMgtClientprotected IdentityProviderMgtServiceClientidentityProviderMgtServiceClientprotected intinboundWebSocketPortprotected org.wso2.carbon.automation.engine.context.AutomationContextkeyManagerContextprotected StringkeyManagerHTTPSURLprotected StringkeymanagerSessionCookieprotected StringkeymanagerSuperTenantSessionCookieprotected APIMURLBeankeyMangerUrlprotected OAuthAdminServiceClientoAuthAdminServiceClientprotected intportOffsetprotected org.wso2.carbon.automation.engine.context.AutomationContextpublisherContextprotected StringpublisherURLHttpprotected StringpublisherURLHttpsprotected APIMURLBeanpublisherUrlsprotected ClaimMetaDataMgtAdminClientremoteClaimMetaDataMgtAdminClientprotected RemoteUserStoreManagerServiceClientremoteUserStoreManagerServiceClientprotected RestAPIAdminImplrestAPIAdminprotected RestAPIInternalImplrestAPIInternalprotected RestAPIPublisherImplrestAPIPublisherprotected RestAPIServiceCatalogImplrestAPIServiceCatalogprotected RestAPIStoreImplrestAPIStoreprotected org.wso2.carbon.automation.engine.context.AutomationContextstoreContextprotected StringstoreURLHttpprotected StringstoreURLHttpsprotected APIMURLBeanstoreUrlsprotected org.wso2.carbon.automation.engine.context.AutomationContextsuperTenantKeyManagerContextprotected org.apache.axiom.om.OMElementsynapseConfigurationprotected org.wso2.carbon.integration.common.admin.client.TenantManagementServiceClienttenantManagementServiceClientprotected org.wso2.carbon.automation.engine.context.beans.Useruserprotected org.wso2.carbon.integration.common.admin.client.UserManagementClientuserManagementClientprotected org.wso2.carbon.automation.engine.context.TestUserModeuserMode
-
Constructor Summary
Constructors Constructor Description APIMIntegrationBaseTest()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected 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 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 StringgetAMResourceLocation()Get 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 StringgetGatewayMgtBackendURLHttps()protected StringgetGatewayMgtURLHttp()protected StringgetGatewayMgtURLHttps()protected StringgetGatewayURLHttp()protected StringgetGatewayURLHttps()protected StringgetGatewayURLNhttp()protected StringgetGatewayURLNhttps()protected StringgetKeyManagerURLHttp()protected StringgetKeyManagerURLHttps()protected StringgetPublisherURLHttp()protected StringgetPublisherURLHttps()protected RestAPIPublisherImplgetRestAPIPublisherForUser(String user, String pass, String tenantDomain)protected RestAPIStoreImplgetRestAPIStoreForAnonymousUser(String tenantDomain)protected RestAPIStoreImplgetRestAPIStoreForUser(String user, String pass, String tenantDomain)protected StringgetStoreURLHttp()protected StringgetStoreURLHttps()protected StringgetSuperTenantAPIInvocationURLHttp(String apiContext, String version)protected static longgetWaitTime()protected 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(String domainKey, String userKey)init 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 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 voidwaitForAPIDeployment()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 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 voidwaitUntilClockHour()
-
-
-
Field Detail
-
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
protected APIMTestCaseUtils apimTestCaseUtils
-
userMode
protected org.wso2.carbon.automation.engine.context.TestUserMode userMode
-
executionMode
protected String executionMode
-
storeUrls
protected APIMURLBean storeUrls
-
publisherUrls
protected APIMURLBean publisherUrls
-
gatewayUrlsMgt
protected APIMURLBean gatewayUrlsMgt
-
gatewayUrlsWrk
protected APIMURLBean gatewayUrlsWrk
-
keyMangerUrl
protected APIMURLBean keyMangerUrl
-
backEndServerUrl
protected APIMURLBean backEndServerUrl
-
adminUrls
protected APIMURLBean adminUrls
-
user
protected org.wso2.carbon.automation.engine.context.beans.User user
-
apiPublisher
protected APIPublisherRestClient apiPublisher
-
apiStore
protected APIStoreRestClient apiStore
-
apiAdmin
protected AdminDashboardRestClient apiAdmin
-
restAPIPublisher
protected RestAPIPublisherImpl restAPIPublisher
-
restAPIServiceCatalog
protected RestAPIServiceCatalogImpl restAPIServiceCatalog
-
restAPIStore
protected RestAPIStoreImpl restAPIStore
-
restAPIAdmin
protected RestAPIAdminImpl restAPIAdmin
-
userManagementClient
protected org.wso2.carbon.integration.common.admin.client.UserManagementClient userManagementClient
-
remoteUserStoreManagerServiceClient
protected RemoteUserStoreManagerServiceClient remoteUserStoreManagerServiceClient
-
remoteClaimMetaDataMgtAdminClient
protected ClaimMetaDataMgtAdminClient remoteClaimMetaDataMgtAdminClient
-
identityProviderMgtClient
protected IdentityProviderMgtClient identityProviderMgtClient
-
oAuthAdminServiceClient
protected OAuthAdminServiceClient oAuthAdminServiceClient
-
applicationManagementClient
protected ApplicationManagementClient applicationManagementClient
-
identityProviderMgtServiceClient
protected IdentityProviderMgtServiceClient identityProviderMgtServiceClient
-
tenantManagementServiceClient
protected org.wso2.carbon.integration.common.admin.client.TenantManagementServiceClient tenantManagementServiceClient
-
publisherURLHttp
protected String publisherURLHttp
-
publisherURLHttps
protected String publisherURLHttps
-
adminURLHttp
protected String adminURLHttp
-
adminURLHttps
protected String adminURLHttps
-
keyManagerHTTPSURL
protected String keyManagerHTTPSURL
-
gatewayHTTPSURL
protected String gatewayHTTPSURL
-
storeURLHttp
protected String storeURLHttp
-
storeURLHttps
protected String storeURLHttps
-
keymanagerSessionCookie
protected String keymanagerSessionCookie
-
keymanagerSuperTenantSessionCookie
protected String keymanagerSuperTenantSessionCookie
-
restAPIInternal
protected RestAPIInternalImpl restAPIInternal
-
inboundWebSocketPort
protected final int inboundWebSocketPort
- See Also:
- Constant Field Values
-
portOffset
protected final int portOffset
- See Also:
- Constant Field Values
-
-
Method Detail
-
init
protected void init() throws APIManagerIntegrationTestExceptionThis 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 APIManagerIntegrationTestExceptioninit 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
protected void init(String domainKey, String userKey) throws APIManagerIntegrationTestException
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
protected String 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 APIManagerIntegrationTestExceptionupdate 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
protected String getStoreURLHttp()
-
getStoreURLHttps
protected String getStoreURLHttps()
-
getPublisherURLHttp
protected String getPublisherURLHttp()
-
getPublisherURLHttps
protected String getPublisherURLHttps()
-
getGatewayMgtURLHttp
protected String getGatewayMgtURLHttp()
-
getGatewayMgtBackendURLHttps
protected String getGatewayMgtBackendURLHttps()
-
getGatewayMgtURLHttps
protected String getGatewayMgtURLHttps()
-
getGatewayURLHttp
protected String getGatewayURLHttp()
-
getGatewayURLNhttp
protected String getGatewayURLNhttp()
-
getGatewayURLHttps
protected String getGatewayURLHttps()
-
getGatewayURLNhttps
protected String getGatewayURLNhttps()
-
getKeyManagerURLHttp
protected String getKeyManagerURLHttp()
-
getKeyManagerURLHttps
protected String getKeyManagerURLHttps() throws XPathExpressionException
- Throws:
XPathExpressionException
-
getAPIInvocationURLHttp
protected String getAPIInvocationURLHttp(String apiContext) throws XPathExpressionException
- 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
protected String getAPIProductInvocationURLHttps(String apiContext) throws XPathExpressionException
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
protected String getAPIInvocationURLHttps(String apiContext) throws XPathExpressionException
- Throws:
XPathExpressionException
-
getBackendEndServiceEndPointHttp
protected String getBackendEndServiceEndPointHttp(String serviceName)
-
getBackendEndServiceEndPointHttps
protected String getBackendEndServiceEndPointHttps(String serviceName)
-
getSuperTenantAPIInvocationURLHttp
protected String getSuperTenantAPIInvocationURLHttp(String apiContext, String version) throws XPathExpressionException
- Throws:
XPathExpressionException
-
cleanUp
protected void cleanUp() throws ExceptionCleaning 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
protected RestAPIStoreImpl getRestAPIStoreForUser(String user, String pass, String tenantDomain)
-
getRestAPIStoreForAnonymousUser
protected RestAPIStoreImpl getRestAPIStoreForAnonymousUser(String tenantDomain)
-
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
-
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
-
waitUntilClockHour
protected static void waitUntilClockHour() throws InterruptedException- Throws:
InterruptedException
-
getWaitTime
protected static long getWaitTime()
-
-