import java.io.IOException;
import java.net.HttpURLConnection;
import java.nio.charset.Charset;
-
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
-
import org.apache.commons.io.FileUtils;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
+import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.client.RestTemplate;
@RunWith(SpringRunner.class)
@SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
@TestPropertySource(locations = "classpath:https/https-test.properties")
+@DirtiesContext
public class HttpsItCase {
@Value("${server.port}")
@Override
public void checkClientTrusted(java.security.cert.X509Certificate[] chain, String authType)
- throws java.security.cert.CertificateException {
+ throws java.security.cert.CertificateException {
}
@Override
public void checkServerTrusted(java.security.cert.X509Certificate[] chain, String authType)
- throws java.security.cert.CertificateException {
+ throws java.security.cert.CertificateException {
}
@Override
return null;
}
};
- ctx.init(null, new TrustManager[] {
- tm
- }, null);
+ ctx.init(null, new TrustManager[] { tm }, null);
SSLContext.setDefault(ctx);
} catch (Exception ex) {
ex.printStackTrace();
}
});
template.setRequestFactory(factory);
- ResponseEntity<String> entity = template
- .getForEntity("http://localhost:" + this.httpPort + "/designer/index.html", String.class);
+ ResponseEntity<String> entity = template.getForEntity("http://localhost:" + this.httpPort + "/swagger.html",
+ String.class);
assertThat(entity.getStatusCode()).isEqualTo(HttpStatus.FOUND);
ResponseEntity<String> httpsEntity = template
- .getForEntity("https://localhost:" + this.httpsPort + "/designer/index.html", String.class);
+ .getForEntity("https://localhost:" + this.httpsPort + "/swagger.html", String.class);
assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
- assertThat(httpsEntity.getBody()).contains("CLDS");
+ assertThat(httpsEntity.getBody()).contains("Clamp Rest API");
}
@Test
});
template.setRequestFactory(factory);
ResponseEntity<String> httpsEntity = template
- .getForEntity("https://localhost:" + this.httpsPort + "/restservices/clds/v1/api-doc", String.class);
+ .getForEntity("https://localhost:" + this.httpsPort + "/restservices/clds/api-doc", String.class);
assertThat(httpsEntity.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(httpsEntity.getBody()).contains("swagger");
- FileUtils.writeStringToFile(
- new File("docs/swagger/swagger.json"), httpsEntity.getBody(), Charset.defaultCharset());
+ FileUtils.writeStringToFile(new File("docs/swagger/swagger.json"), httpsEntity.getBody(),
+ Charset.defaultCharset());
}
/**
@Override
protected void prepareConnection(final HttpURLConnection connection, final String httpMethod)
- throws IOException {
+ throws IOException {
if (connection instanceof HttpsURLConnection) {
((HttpsURLConnection) connection).setHostnameVerifier(this.verifier);
}