Best Cerberus-source code snippet using org.cerberus.service.xray.impl.XRayService.getXRayAuthenticationToken
Source:XRayService.java
...132 try {133 Tag currentTag = new Tag();134 if ((TestCase.TESTCASE_ORIGIN_JIRAXRAYCLOUD.equalsIgnoreCase(execution.getTestCaseObj().getOrigine()))135 || TestCase.TESTCASE_ORIGIN_JIRAXRAYDC.equalsIgnoreCase(execution.getTestCaseObj().getOrigine())) {136 getXRayAuthenticationToken(execution.getTestCaseObj().getOrigine(), execution.getSystem());137 JSONObject xRayRequest = new JSONObject();138 LOG.debug("Calling JIRA XRay TestExecution creation. {}", execution.getId());139 if (!StringUtil.isNullOrEmpty(execution.getTag())) {140 currentTag = tagService.convert(tagService.readByKey(execution.getTag()));141 if ((currentTag != null)) {142 int lock = 0;143 // We lock the tag updating it to PENDING when empty.144 if (StringUtil.isNullOrEmpty(currentTag.getXRayTestExecution())) {145 lock = tagService.lockXRayTestExecution(currentTag.getTag(), currentTag);146 LOG.debug("Lock attempt : {}", lock);147 }148 if (lock == 0) {149 int maxIteration = 0;150 // We wait that JIRA provide the Epic and Cerberus update it.151 while ("PENDING".equals(currentTag.getXRayTestExecution()) && maxIteration++ < 20) {152 LOG.debug("Loop Until Tag is no longuer PENDING {}/20 - {}", maxIteration, execution.getId());153 currentTag = tagService.convert(tagService.readByKey(execution.getTag()));154 Thread.sleep(5000);155 }156 }157 xRayRequest = xRayGenerationService.generateCreateTestExecution(currentTag, execution);158 String xRayUrl = XRAYCLOUD_TESTEXECUTIONCREATION_URL;159 if (TestCase.TESTCASE_ORIGIN_JIRAXRAYDC.equalsIgnoreCase(execution.getTestCaseObj().getOrigine())) {160 xRayUrl = parameterService.getParameterStringByKey(Parameter.VALUE_cerberus_xraydc_url, execution.getSystem(), "");161 xRayUrl += XRAYDC_TESTEXECUTIONCREATION_URLPATH;162 }163 CloseableHttpClient httpclient = null;164 HttpClientBuilder httpclientBuilder;165 if (proxyService.useProxy(xRayUrl, "")) {166 String proxyHost = parameterService.getParameterStringByKey("cerberus_proxy_host", "", DEFAULT_PROXY_HOST);167 int proxyPort = parameterService.getParameterIntegerByKey("cerberus_proxy_port", "", DEFAULT_PROXY_PORT);168 HttpHost proxyHostObject = new HttpHost(proxyHost, proxyPort);169 if (parameterService.getParameterBooleanByKey("cerberus_proxyauthentification_active", "", DEFAULT_PROXYAUTHENT_ACTIVATE)) {170 String proxyUser = parameterService.getParameterStringByKey("cerberus_proxyauthentification_user", "", DEFAULT_PROXYAUTHENT_USER);171 String proxyPassword = parameterService.getParameterStringByKey("cerberus_proxyauthentification_password", "", DEFAULT_PROXYAUTHENT_PASSWORD);172 CredentialsProvider credsProvider = new BasicCredentialsProvider();173 credsProvider.setCredentials(new AuthScope(proxyHost, proxyPort), new UsernamePasswordCredentials(proxyUser, proxyPassword));174 LOG.debug("Activating Proxy With Authentification.");175 httpclientBuilder = HttpClientBuilder.create().setProxy(proxyHostObject)176 .setProxyAuthenticationStrategy(new ProxyAuthenticationStrategy())177 .setDefaultCredentialsProvider(credsProvider);178 } else {179 LOG.debug("Activating Proxy (No Authentification).");180 httpclientBuilder = HttpClientBuilder.create().setProxy(proxyHostObject);181 }182 } else {183 httpclientBuilder = HttpClientBuilder.create();184 }185 boolean acceptUnsignedSsl = parameterService.getParameterBooleanByKey("cerberus_accept_unsigned_ssl_certificate", "", true);186 if (acceptUnsignedSsl) {187 // authorize non valide certificat ssl188 SSLContext sslContext = new SSLContextBuilder().loadTrustMaterial(null, new TrustSelfSignedStrategy() {189 @Override190 public boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException {191 return true;192 }193 }).build();194 httpclientBuilder195 .setSSLContext(sslContext)196 .setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE);197 }198 httpclient = httpclientBuilder.build();199 HttpPost post = new HttpPost(xRayUrl);200 StringEntity entity = new StringEntity(xRayRequest.toString());201 post.setEntity(entity);202 post.setHeader("Accept", "application/json");203 post.setHeader("Content-type", "application/json");204 post.setHeader("Authorization", "Bearer " + getToken(execution.getSystem(), execution.getTestCaseObj().getOrigine()));205 LOG.debug("Bearer " + getToken(execution.getSystem(), execution.getTestCaseObj().getOrigine()));206 try {207 HttpResponse response = httpclient.execute(post);208 int rc = response.getStatusLine().getStatusCode();209 if (rc >= 200 && rc < 300) {210 LOG.debug("XRay Test Execution request http return code : " + rc);211 String responseString = EntityUtils.toString(response.getEntity());212 LOG.debug("Response : {}", responseString);213 JSONObject xRayResponse = new JSONObject(responseString);214 String xrayURL = "";215 String xrayTestExecution = "";216 if (xRayResponse.has("key")) {217 xrayTestExecution = xRayResponse.getString("key");218 if (xRayResponse.has("self")) {219 URL xrURL = new URL(xRayResponse.getString("self"));220 xrayURL = xrURL.getProtocol() + "://" + xrURL.getHost();221 }222 if (!xrayURL.equals(currentTag.getXRayURL()) || !xrayTestExecution.equals(currentTag.getXRayTestExecution())) {223 // We avoid updating is the data did not change.224 currentTag.setXRayURL(xrayURL);225 currentTag.setXRayTestExecution(xrayTestExecution);226 tagService.updateXRayTestExecution(currentTag.getTag(), currentTag);227 }228 }229 LOG.debug("Setting new XRay TestExecution '{}' to tag '{}'", xRayResponse.getString("key"), currentTag.getTag());230 } else {231 LOG.warn("XRay Test Execution request http return code : " + rc);232 logEventService.createForPrivateCalls("XRAY", "APICALL", "Xray Execution creation request to '" + xRayUrl + "' failed with http return code : " + rc + ".");233 String responseString = EntityUtils.toString(response.getEntity());234 LOG.warn("Message sent to " + xRayUrl + " :");235 LOG.warn(xRayRequest.toString(1));236 LOG.warn("Response : {}", responseString);237 }238 } catch (IOException e) {239 logEventService.createForPrivateCalls("XRAY", "APICALL", "Xray Execution creation request to '" + xRayUrl + "' failed : " + e.toString() + ".");240 }241 }242 }243 }244 } catch (Exception ex) {245 LOG.error(ex, ex);246 }247 }248 private void getXRayAuthenticationToken(String origin, String system) throws Exception {249 String xRayUrl = XRAYCLOUD_AUTHENT_URL;250 if (getToken(system, origin) == null) {251 if (TestCase.TESTCASE_ORIGIN_JIRAXRAYCLOUD.equals(origin)) {252 LOG.debug("Getting new XRay Token.");253 String clientID = parameterService.getParameterStringByKey(Parameter.VALUE_cerberus_xraycloud_clientid, system, "");254 String clientSecret = parameterService.getParameterStringByKey(Parameter.VALUE_cerberus_xraycloud_clientsecret, system, "");255 if (StringUtil.isNullOrEmpty(clientID) || StringUtil.isNullOrEmpty(clientSecret)) {256 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.NO_DATA_FOUND));257 }258 JSONObject authenMessage = xRayGenerationService.generateAuthenticationRequest(clientID, clientSecret);259 // curl -H "Content-Type: application/json" -X POST --data '{ "client_id": "E5A6F0FC4A8941C88CF4D1CAACFFAA81","client_secret": "2625a68b1953e66fff5b64642f6a9f59c6885db83fb3a9f9a73b34170513ad3f" }' https://xray.cloud.getxray.app/api/v2/authenticate260 CloseableHttpClient httpclient = null;261 HttpClientBuilder httpclientBuilder;262 if (proxyService.useProxy(xRayUrl, "")) {...
getXRayAuthenticationToken
Using AI Code Generation
1import org.cerberus.service.xray.impl.XRayService;2import org.cerberus.service.xray.impl.XRayService;3XRayService xrayService = new XRayService();4xrayService.getXRayAuthenticationToken();5import org.cerberus.service.xray.impl.XRayService;6import org.cerberus.service.xray.impl.XRayService;7XRayService xrayService = new XRayService();8xrayService.getXRayAuthenticationToken();9import org.cerberus.service.xray.impl.XRayService;10import org.cerberus.service.xray.impl.XRayService;11XRayService xrayService = new XRayService();12xrayService.getXRayAuthenticationToken();13import org.cerberus.service.xray.impl.XRayService;14import org.cerberus.service.xray.impl.XRayService;15XRayService xrayService = new XRayService();16xrayService.getXRayAuthenticationToken();17import org.cerberus.service.xray.impl.XRayService;18import org.cerberus.service.xray.impl.XRayService;19XRayService xrayService = new XRayService();20xrayService.getXRayAuthenticationToken();21import org.cerberus.service.xray.impl.XRayService;22import org.cerberus.service.xray.impl.XRayService;23XRayService xrayService = new XRayService();24xrayService.getXRayAuthenticationToken();25import org.cerberus.service.xray.impl.XRayService;26import org.cerberus.service.xray.impl.XRayService;27XRayService xrayService = new XRayService();28xrayService.getXRayAuthenticationToken();
getXRayAuthenticationToken
Using AI Code Generation
1XRayService xRayService = new XRayService();2xRayService.getXRayAuthenticationToken();3XRayService xRayService = new XRayService();4xRayService.getXRayTestExecution();5XRayService xRayService = new XRayService();6xRayService.getXRayTestExecution();7XRayService xRayService = new XRayService();8xRayService.getXRayTestExecution();9XRayService xRayService = new XRayService();10xRayService.getXRayTestExecution();11XRayService xRayService = new XRayService();12xRayService.getXRayTestExecution();13XRayService xRayService = new XRayService();14xRayService.getXRayTestExecution();
getXRayAuthenticationToken
Using AI Code Generation
1String token = xRayService.getXRayAuthenticationToken();2XRayTestExecution xRayTestExecution = xRayService.getXRayTestExecution(token, test, testCase);3XRayTestExecutionResult xRayTestExecutionResult = xRayService.getXRayTestExecutionResult(token, test, testCase);4XRayTestExecutionStatus xRayTestExecutionStatus = xRayService.getXRayTestExecutionStatus(token, test, testCase);5XRayTestExecutionStep xRayTestExecutionStep = xRayService.getXRayTestExecutionStep(token, test, testCase);6XRayTestExecutionStepResult xRayTestExecutionStepResult = xRayService.getXRayTestExecutionStepResult(token, test, testCase);7XRayTestExecutionStepStatus xRayTestExecutionStepStatus = xRayService.getXRayTestExecutionStepStatus(token, test, testCase);
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!