下面列出了org.testng.annotations.AfterTest#org.wso2.carbon.automation.engine.context.TestUserMode 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@BeforeClass(alwaysRun = true)
public void init() throws Exception {
super.init();
rabbitMQServer = RabbitMQTestUtils.getRabbitMQServerInstance();
sender = new RabbitMQProducerClient("localhost", 5672, "guest", "guest");
consumer = new RabbitMQConsumerClient("localhost");
configurationManagerAxis2 =
new ServerConfigurationManager(new AutomationContext("ESB", TestUserMode.SUPER_TENANT_ADMIN));
File customAxisConfigAxis2 = new File(getESBResourceLocation() + File.separator +
"axis2config" + File.separator + "axis2.xml");
configurationManagerAxis2.applyConfiguration(customAxisConfigAxis2);
super.init();
logViewer = new LogViewerClient(contextUrls.getBackEndUrl(), getSessionCookie());
loadESBConfigurationFromClasspath("/artifacts/ESB/rabbitmq/transport/rabbitmq_consumer_proxy.xml");
}
/**
* Prepare environment for tests.
*
* @throws XPathExpressionException
* @throws LoginAuthenticationExceptionException
* @throws IOException
* @throws XMLStreamException
* @throws URISyntaxException
* @throws SAXException
* @throws AutomationUtilException
*/
@BeforeClass(alwaysRun = true)
public void init() throws XPathExpressionException, LoginAuthenticationExceptionException, IOException,
XMLStreamException, URISyntaxException, SAXException, AutomationUtilException {
super.initCluster(TestUserMode.SUPER_TENANT_ADMIN);
AutomationContext automationContext1 = getAutomationContextWithKey("mb002");
AutomationContext automationContext2 = getAutomationContextWithKey("mb003");
hostNode1 = automationContext1.getInstance().getHosts().get("default");
hostNode2 = automationContext2.getInstance().getHosts().get("default");
portInNode1 = Integer.parseInt(automationContext1.getInstance().getPorts().get("amqp"));
portInNode2 = Integer.parseInt(automationContext2.getInstance().getPorts().get("amqp"));
topicAdminClient = new TopicAdminClient(automationContext1.getContextUrls().getBackEndUrl(),
super.login(automationContext1));
super.initAndesAdminClients();
}
@BeforeClass(alwaysRun = true)
public void setUp() throws Exception {
super.init();
driver = new ESWebDriver(BrowserManager.getWebDriver());
baseUrl = getWebAppURL();
adminUserName = userInfo.getUserName();
adminUserPwd = userInfo.getPassword();
acceptNextAlert = true;
wait = new WebDriverWait(driver, MAX_DRIVER_WAIT_TIME_SEC);
AutomationContext automationContext = new AutomationContext(PRODUCT_GROUP_NAME,
TestUserMode.SUPER_TENANT_ADMIN);
adminUserName = automationContext.getSuperTenant().getTenantAdmin().getUserName();
adminUserPwd = automationContext.getSuperTenant().getTenantAdmin().getPassword();
backendURL = automationContext.getContextUrls().getBackEndUrl();
resourceAdminServiceClient = new ResourceAdminServiceClient(backendURL, adminUserName,
adminUserPwd);
driver.get(baseUrl + "/" + STORE_APP);
}
@BeforeClass(alwaysRun = true)
public void setUp() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
currentUserName = userInfo.getUserName();
currentUserPwd = userInfo.getPassword();
driver = new ESWebDriver(BrowserManager.getWebDriver());
baseUrl = getWebAppURL();
wait = new WebDriverWait(driver, MAX_WAIT_TIME);
driver.get(baseUrl + MANAGEMENT_CONSOLE_URL);
driver.findElement(By.id("txtUserName")).clear();
driver.findElement(By.id("txtUserName")).sendKeys(currentUserName);
driver.findElement(By.id("txtPassword")).clear();
driver.findElement(By.id("txtPassword")).sendKeys(currentUserPwd);
driver.findElement(By.xpath("//input[@value='Sign-in']")).click();
}
public StratosIntegrationTest() {
try {
stratosAutomationCtx = new AutomationContext("STRATOS", "stratos-001", TestUserMode.SUPER_TENANT_ADMIN);
adminUsername = stratosAutomationCtx
.getConfigurationValue("/automation/userManagement/superTenant/tenant/admin/user/userName");
adminPassword = stratosAutomationCtx
.getConfigurationValue("/automation/userManagement/superTenant/tenant/admin/user/password");
// Do not rely on automation context for context URLs since ports are dynamically picked
stratosBackendURL = StratosServerExtension.getStratosTestServerManager().getWebAppURL();
stratosSecuredBackendURL = StratosServerExtension.getStratosTestServerManager().getWebAppURLHttps();
restClient = new RestClient(stratosBackendURL, stratosSecuredBackendURL, adminUsername, adminPassword);
mockIaasApiClient = new MockIaasApiClient(stratosBackendURL + "/mock-iaas/api");
// initialize topology handler before running the tests
TopologyHandler.getInstance();
} catch (Exception e) {
throw new RuntimeException("Could not initialize StratosIntegrationTest", e);
}
}
@BeforeClass(alwaysRun = true, enabled = false)
public void initialize() throws Exception {
super.init();
String resourceFileLocation;
feedURL = "https://mail.google.com/mail/feed/atom";
mailCountBeforeTestStart = getMailCount(feedURL);
modifiedTime = getModifiedTime(feedURL);
eventingSampleStub = new EventingSampleStub(serverEpr);
serverEpr = getServiceUrlHttp(serviceName);
// productCode = "code" + System.currentTimeMillis();
productCode = "999";
updateAxis2_ClientXML();
new ServerConfigurationManager("DSS", TestUserMode.SUPER_TENANT_ADMIN).restartGracefully();
super.init();
resourceFileLocation = getResourceLocation();
deployService(serviceName, new DataHandler(
new URL("file:///" + resourceFileLocation + File.separator + "samples" + File.separator + "dbs"
+ File.separator + "rdbms" + File.separator + "EventingSample.dbs")));
log.info(serviceName + " uploaded");
}
@BeforeClass(alwaysRun = true)
public void uploadSynapseConfig() throws Exception {
super.init();
serverConfigurationManager = new ServerConfigurationManager(
new AutomationContext("ESB", TestUserMode.SUPER_TENANT_ADMIN));
loadESBConfigurationFromClasspath(
File.separator + "artifacts" + File.separator + "ESB" + File.separator + "synapseconfig"
+ File.separator + "servletTransport" + File.separator + "soap_2_pox.xml");
httpServer = new SimpleHttpServer(8098, new Properties());
httpServer.start();
Thread.sleep(5000);
interceptor = new TestRequestInterceptor();
httpServer.getRequestHandler().setInterceptor(interceptor);
}
@BeforeClass(alwaysRun = true)
public void setEnvironment() throws Exception {
super.init();
serverManager = new ServerConfigurationManager(new AutomationContext("ESB", TestUserMode.SUPER_TENANT_ADMIN));
File sourceFile = new File(
FrameworkPathUtil.getSystemResourceLocation() + "artifacts" + File.separator + "ESB" + File.separator
+ "streamingxpath" + File.separator + "synapse.properties");
serverManager.applyConfiguration(sourceFile);
super.init();
String relativePath = "artifacts" + File.separator + "ESB" + File.separator + "streamingxpath" + File.separator
+ "StreamingException.xml";
ESBTestCaseUtils util = new ESBTestCaseUtils();
OMElement proxyConfig = util.loadResource(relativePath);
try {
addProxyService(proxyConfig);
} catch (Exception ignore) {
exceptionCaught = true;
}
}
@BeforeClass(alwaysRun = true)
public void init() throws Exception {
super.init();
rabbitMQServer = RabbitMQTestUtils.getRabbitMQServerInstance();
configurationManagerAxis2 =
new ServerConfigurationManager(new AutomationContext("ESB", TestUserMode.SUPER_TENANT_ADMIN));
File customAxisConfigAxis2 = new File(getESBResourceLocation() + File.separator +
"axis2config" + File.separator + "axis2.xml");
configurationManagerAxis2.applyConfiguration(customAxisConfigAxis2);
super.init();
loadESBConfigurationFromClasspath("/artifacts/ESB/rabbitmq/transport/rabbitmq_endpoint_proxy.xml");
}
@BeforeClass(alwaysRun = true)
protected void initialize() throws Exception {
//Starting the thrift port to listen to statistics events
thriftServer = new ThriftServer("Wso2EventTestCase", 7612, true);
thriftServer.start(7612);
log.info("Thrift Server is Started on port 7612");
//Changing synapse configuration to enable statistics and tracing
ServerConfigurationManager serverConfigurationManager = new ServerConfigurationManager(
new AutomationContext("ESB", TestUserMode.SUPER_TENANT_ADMIN));
serverConfigurationManager.applyMIConfigurationWithRestart(new File(
getESBResourceLocation() + File.separator + "StatisticTestResources" + File.separator
+ "deployment.toml"));
super.init();
thriftServer.waitToReceiveEvents(20000); //waiting for esb to send artifact config data to the thriftserver
}
@BeforeClass
public void init() throws Exception {
super.init();
serverConfigurationManager = new ServerConfigurationManager(
new AutomationContext("ESB", TestUserMode.SUPER_TENANT_ADMIN));
/*
* If test run in external distributed deployment you need to copy
* following configFiles/preserveContentType/passthru-http.properties resource
*/
serverConfigurationManager.applyMIConfigurationWithRestart(new File(
getESBResourceLocation() + File.separator + "passthru" + File.separator + "transport" + File.separator
+ "preserveheaders" + File.separator + "passthru-http.properties"));
super.init();
wireServer = new WireMonitorServer(8992);
}
@BeforeClass(alwaysRun = true)
protected void startServerWithEagerLoading() throws Exception {
super.init(TestUserMode.SUPER_TENANT_USER);
serverManager = new ServerConfigurationManager(context);
AutomationContext autoContext = new AutomationContext();
// upload a faulty sequence which refer registry resource doesn't exists
FileUtils.copyFileToDirectory(new File(FrameworkPathUtil.getSystemResourceLocation() +
"/artifacts/ESB/eager/loading/ESBJAVA3602-FaultySeq.xml"),
getSynapseDeploymentDir());
File carbonXml = new File(FrameworkPathUtil.getSystemResourceLocation() +
"/artifacts/ESB/eager/loading/ESBJAVA3602Carbon.xml");
serverManager.applyConfiguration(carbonXml, getCarbonXmlFile());
super.init(TestUserMode.TENANT_ADMIN);
logViewerClient = new LogViewerClient(contextUrls.getBackEndUrl(), getSessionCookie());
}
/**
* Prepare environment for tests.
*
* @throws XPathExpressionException
* @throws URISyntaxException
* @throws SAXException
* @throws XMLStreamException
* @throws LoginAuthenticationExceptionException
* @throws IOException
*/
@BeforeClass(alwaysRun = true)
public void init()
throws XPathExpressionException, URISyntaxException, SAXException, XMLStreamException,
LoginAuthenticationExceptionException, IOException, AutomationUtilException {
super.initCluster(TestUserMode.SUPER_TENANT_ADMIN);
automationContextForMB2 = getAutomationContextWithKey("mb002");
automationContextForMB3 = getAutomationContextWithKey("mb003");
topicAdminClientForMB2 = new TopicAdminClient(automationContextForMB2.getContextUrls().getBackEndUrl(),
super.login(automationContextForMB2));
topicAdminClientForMB3 = new TopicAdminClient(automationContextForMB3.getContextUrls().getBackEndUrl(),
super.login(automationContextForMB3));
}
@BeforeClass(alwaysRun = true)
public void init() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
serverManager = new ServerConfigurationManager(cepServer);
serverManager.applyConfiguration(
new File(getTestArtifactLocation() + CEPIntegrationTestConstants.RELATIVE_PATH_TO_TEST_ARTIFACTS +
ARTIFACTS_FOLDER + File.separator + "carbon.xml"),
new File(ServerConfigurationManager.getCarbonHome() + File.separator + "repository" + File.separator +
"conf" + File.separator + "carbon.xml"),
true,
true);
sessionCookie = getSessionCookie();
eventSimulatorAdminServiceClient = configurationUtil
.getEventSimulatorAdminServiceClient(backendURL, sessionCookie);
eventStreamManagerAdminServiceClient = configurationUtil
.getEventStreamManagerAdminServiceClient(backendURL, sessionCookie);
eventPublisherAdminServiceClient = configurationUtil
.getEventPublisherAdminServiceClient(backendURL, sessionCookie);
eventReceiverAdminServiceClient = configurationUtil
.getEventReceiverAdminServiceClient(backendURL, sessionCookie);
eventProcessorAdminServiceClient = configurationUtil
.getEventProcessorAdminServiceClient(backendURL, sessionCookie);
}
@Override
public void initiate() throws AutomationFrameworkException {
try {
automationContext = new AutomationContext("IOT", TestUserMode.SUPER_TENANT_USER);
if(getParameters().get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND) == null) {
getParameters().put(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND, "2");
}
serverManager = new CustomTestServerManager(getAutomationContext(), null, getParameters());
executionEnvironment =
automationContext.getConfigurationValue(ContextXpathConstants.EXECUTION_ENVIRONMENT);
} catch (XPathExpressionException e) {
handleException("Error while initiating test environment", e);
}
}
private void validateServiceUrl(String serviceUrl, Tenant tenant) {
//if user mode is null can not validate the service url
if (userMode != null) {
if ((userMode == TestUserMode.TENANT_ADMIN || userMode == TestUserMode.TENANT_USER)) {
Assert.assertTrue(serviceUrl.contains("/t/" + tenant.getDomain() + "/"),
"invalid service url for tenant. " + serviceUrl);
} else {
Assert.assertFalse(serviceUrl.contains("/t/"), "Invalid service url for user. " + serviceUrl);
}
}
}
@Override
public void initiate() {
try {
automationContext = new AutomationContext("IOT", TestUserMode.SUPER_TENANT_USER);
if (getParameters().get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND) == null) {
getParameters().put(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND, IOT_CORE_PORT_OFFSET);
}
serverManager = new CustomTestServerManager(getAutomationContext(), null, getParameters());
executionEnvironment =
automationContext.getConfigurationValue(ContextXpathConstants.EXECUTION_ENVIRONMENT);
} catch (XPathExpressionException e) {
throw new RuntimeException("Error while initiating test environment", e);
}
}
@BeforeClass(alwaysRun = true)
public void init() throws Exception {
super.init();
serverConfigurationManager = new ServerConfigurationManager(new AutomationContext("ESB", TestUserMode.SUPER_TENANT_ADMIN));
serverConfigurationManager.applyConfiguration(new File(getESBResourceLocation() + File.separator + "passthru" +
File.separator + "transport" + File.separator + "ESBJAVA4883" + File.separator + "synapse-handlers.xml"));
super.init();
verifyProxyServiceExistence("SynapseHandlerTestProxy");
logViewerClient = new LogViewerClient(contextUrls.getBackEndUrl(), getSessionCookie());
logViewerClient.clearLogs();
}
@DataProvider
private static TestUserMode[][] userModeProvider() {
return new TestUserMode[][]{
new TestUserMode[]{TestUserMode.SUPER_TENANT_ADMIN}
// new TestUserMode[]{TestUserMode.TENANT_USER},
};
}
@BeforeClass
public void init() throws Exception {
super.init();
serverConfigurationManager = new ServerConfigurationManager(new AutomationContext("ESB", TestUserMode.SUPER_TENANT_ADMIN));
/*
* If test run in external distributed deployment you need to copy
* following configFiles/preserveContentType/passthru-http.properties resource
*/
serverConfigurationManager.applyConfiguration(new File(getESBResourceLocation() + File.separator + "passthru" +
File.separator + "transport" + File.separator + "preserveheaders" + File.separator + "passthru-http.properties"));
super.init();
wireServer = new WireMonitorServer(8992);
verifyAPIExistence("ContentTypePreserveAPI");
}
@BeforeClass(alwaysRun = true)
public void setUp() throws Exception {
super.init();
driver = new ESWebDriver(BrowserManager.getWebDriver());
baseUrl = getWebAppURL();
buildTenantDetails(TestUserMode.SUPER_TENANT_ADMIN);
login();
assetName = "Asset Recent";
resourcePath = GADGET_REGISTRY_BASE_PATH + currentUserName + "/" + assetName + "/" + ASSET_VERSION;
resourcePathSite = SITE_REGISTRY_BASE_PATH + currentUserName + "/" + assetName + "/" + ASSET_VERSION;
//navigate to publisher and add and publish a new gadget to support sort by created time
driver.get(baseUrl + PUBLISHER_URL);
AssetUtil.addNewAsset(driver, baseUrl, ASSET_TYPE1, assetName, ASSET_VERSION, "", "", "");
driver.findElementPoll(By.linkText(assetName),MAX_POLL_COUNT);
driver.findElement(By.linkText(assetName)).click();
AssetUtil.publishAssetToStore(driver, assetName);
driver.get(baseUrl + PUBLISHER_URL);
AssetUtil.addNewAsset(driver, baseUrl, ASSET_TYPE2, assetName, ASSET_VERSION, "", "", "");
driver.findElementPoll(By.linkText(assetName),MAX_POLL_COUNT);
driver.findElement(By.linkText(assetName)).click();
AssetUtil.publishAssetToStore(driver, assetName);
driver.get(baseUrl + PUBLISHER_LOGOUT_URL);
//navigate to store and wait for the new gadget to be visible in store
driver.get(baseUrl + STORE_GADGET_LIST_PAGE);
driver.findElementPoll(By.xpath("//a[contains(.,'Asset Recent')]"), MAX_POLL_COUNT);
}
@Override
public void initiate() throws AutomationFrameworkException {
try {
automationContext = new AutomationContext("IOT", TestUserMode.SUPER_TENANT_USER);
if(getParameters().get(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND) == null) {
getParameters().put(ExtensionConstants.SERVER_STARTUP_PORT_OFFSET_COMMAND, "0");
}
serverManager = new CustomTestServerManager(getAutomationContext(), null, getParameters());
executionEnvironment =
automationContext.getConfigurationValue(ContextXpathConstants.EXECUTION_ENVIRONMENT);
} catch (XPathExpressionException e) {
handleException("Error while initiating test environment", e);
}
}
@AfterClass(alwaysRun = true)
public void tearDown() throws Exception {
AutomationContext automationContext = new AutomationContext(PRODUCT_GROUP_NAME, TestUserMode.SUPER_TENANT_ADMIN);
adminUserName = automationContext.getSuperTenant().getTenantAdmin().getUserName();
adminUserPwd = automationContext.getSuperTenant().getTenantAdmin().getPassword();
String backendURL = automationContext.getContextUrls().getBackEndUrl();
resourceAdminServiceClient = new ResourceAdminServiceClient(backendURL, adminUserName, adminUserPwd);
resourceAdminServiceClient.deleteResource(resourcePath);
resourceAdminServiceClient.deleteResource(resourcePathSite);
driver.quit();
}
@BeforeClass(alwaysRun = true)
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
public void serverRestart() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
sessionCookie = new LoginLogoutClient(automationContext).login();
resourceAdminServiceClient =
new ResourceAdminServiceClient(backendURL, sessionCookie);
}
@AfterClass(alwaysRun = true)
public void tearDown() throws Exception {
AutomationContext automationContext = new AutomationContext(PRODUCT_GROUP_NAME, TestUserMode.SUPER_TENANT_ADMIN);
adminUserName = automationContext.getSuperTenant().getTenantAdmin().getUserName();
adminUserPwd = automationContext.getSuperTenant().getTenantAdmin().getPassword();
String backendURL = automationContext.getContextUrls().getBackEndUrl();
resourceAdminServiceClient = new ResourceAdminServiceClient(backendURL, adminUserName, adminUserPwd);
resourceAdminServiceClient.deleteResource(resourcePath);
driver.quit();
}
@BeforeClass(alwaysRun = true)
public void init() throws Exception {
super.init();
toUrl = getBackEndServiceUrl(ESBTestConstant.SIMPLE_STOCK_QUOTE_SERVICE);
serverConfigurationManager = new ServerConfigurationManager(new AutomationContext("ESB", TestUserMode.SUPER_TENANT_ADMIN));
URL url = getClass().getResource(separator + "artifacts" + separator + "ESB" + separator
+ "synapseconfig" + separator + "nhttp_transport" + separator
+ "nhttp.properties");
File srcFile = new File(url.getPath());
serverConfigurationManager.applyConfiguration(srcFile);
super.init();
loadESBConfigurationFromClasspath(separator + "artifacts" + separator + "ESB" + separator + "synapseconfig" +
separator + "nhttp_transport" + separator + "response_nhttp_synapse.xml");
}
public PPaaSIntegrationTest() throws Exception {
ppaasAutomationCtx = new AutomationContext("PPAAS", "ppaas-001", TestUserMode.SUPER_TENANT_ADMIN);
adminUsername = ppaasAutomationCtx
.getConfigurationValue("/automation/userManagement/superTenant/tenant/admin/user/userName");
adminPassword = ppaasAutomationCtx
.getConfigurationValue("/automation/userManagement/superTenant/tenant/admin/user/password");
restClient = new RestClient(ppaasAutomationCtx.getContextUrls().getWebAppURL(),
ppaasAutomationCtx.getContextUrls().getWebAppURLHttps(), adminUsername, adminPassword);
String mockIaaSEndpoint = ppaasAutomationCtx.getContextUrls().getWebAppURL() + "/mock-iaas/api";
mockIaasApiClient = new IntegrationMockClient(mockIaaSEndpoint);
log.info("Mock IaaS endpoint URL: " + mockIaaSEndpoint);
}
@BeforeClass(alwaysRun = true)
public void init() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
serverManager = new ServerConfigurationManager(cepServer);
String loggedInSessionCookie = new LoginLogoutClient(cepServer).login();
eventProcessorAdminServiceClient = configurationUtil.getEventProcessorAdminServiceClient(backendURL, loggedInSessionCookie);
eventStreamManagerAdminServiceClient = configurationUtil.getEventStreamManagerAdminServiceClient(backendURL, loggedInSessionCookie);
eventReceiverAdminServiceClient = configurationUtil.getEventReceiverAdminServiceClient(backendURL, loggedInSessionCookie);
eventPublisherAdminServiceClient = configurationUtil.getEventPublisherAdminServiceClient(backendURL, loggedInSessionCookie);
}
@BeforeClass(alwaysRun = true)
@SetEnvironment(executionEnvironments = { ExecutionEnvironment.STANDALONE })
public void serverRestart() throws Exception {
super.init(TestUserMode.SUPER_TENANT_ADMIN);
sessionCookie = new LoginLogoutClient(automationContext).login();
resourceAdminServiceClient =
new ResourceAdminServiceClient(backendURL, sessionCookie);
}
@DataProvider
private static TestUserMode[][] userModeProvider() {
return new TestUserMode[][]{
new TestUserMode[]{TestUserMode.SUPER_TENANT_ADMIN}
// new TestUserMode[]{TestUserMode.TENANT_USER},
};
}