Showing posts with label disable. Show all posts
Showing posts with label disable. Show all posts

Sunday, 14 February 2021

Spring Shell: How to disable built-in commands

Just exclude 'spring-shell-standard-commands' like below.

<dependency>
    <groupId>org.springframework.shell</groupId>
    <artifactId>spring-shell-starter</artifactId>
    <version>2.0.1.BUILD-SNAPSHOT</version>

    <exclusions>
        <exclusion>
            <groupId>org.springframework.shell</groupId>
            <artifactId>spring-shell-standard-commands</artifactId>
        </exclusion>
    </exclusions>
</dependency>

 

 

Previous                                                    Next                                                    Home

Wednesday, 11 March 2020

TestNG: Ignore or disable test cases from execution

‘@Test(enabled = false)’ statement is used to disable the test cases.

Example
@Test(enabled = false)
public void test1() {
         System.out.println("test1 in execution");
}

IgnoreTests.java
package com.sample.app.tests;

import org.testng.annotations.Test;

public class IgnoreTests {

 @Test(enabled = false)
 public void test1() {
  System.out.println("test1 in execution");
 }

 @Test
 public void test2() {
  System.out.println("test2 in execution");
 }

}

Run IgnoreTests.java, you will see below messages in console.
[RemoteTestNG] detected TestNG version 7.0.0
test2 in execution
PASSED: test2

===============================================
    Default test
    Tests run: 1, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 1, Passes: 1, Failures: 0, Skips: 0
===============================================

As you see the console messages, you can confirm that test1 is not executed.

Previous                                                    Next                                                    Home

Monday, 2 March 2020

RestTemplate: Disable ssl certificate validation

Following snippet return RestTemplate instance which ignores SSL certificate validation.

public RestTemplate getRestTemplate() throws BaseException {

 try {
  TrustStrategy acceptingTrustStrategy = new TrustStrategy() {
   @Override
   public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {
    return true;
   }
  };
  SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom()
    .loadTrustMaterial(null, acceptingTrustStrategy).build();
  SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
  CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build();
  HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
  requestFactory.setHttpClient(httpClient);
  RestTemplate restTemplate = new RestTemplate(requestFactory);
  return restTemplate;
 } catch (Exception e) {
  e.printStackTrace();
 }

}


Previous                                                    Next                                                    Home