forked from karatelabs/karate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TestService.java
60 lines (49 loc) · 1.96 KB
/
TestService.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package ssl;
import com.intuit.karate.demo.config.ServerStartedInitializingBean;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.*;
/**
*
* @author pthomas3
*/
@Configuration
@EnableAutoConfiguration(exclude = {SecurityAutoConfiguration.class, DataSourceAutoConfiguration.class})
public class TestService {
private static final Logger logger = LoggerFactory.getLogger(TestService.class);
@RestController
@RequestMapping("/test")
class TestController {
@GetMapping
public String test() {
return "{ \"success\": true }";
}
}
public static ConfigurableApplicationContext start() {
String[] args = {
"--server.port=0",
"--server.ssl.key-store=src/test/java/server-keystore.p12",
"--server.ssl.key-store-password=karate-mock",
"--server.ssl.keyStoreType=PKCS12",
"--server.ssl.keyAlias=karate-mock"};
return SpringApplication.run(TestService.class, args);
}
public static void stop(ConfigurableApplicationContext context) {
SpringApplication.exit(context, () -> 0);
}
public static int getPort(ConfigurableApplicationContext context) {
ServerStartedInitializingBean ss = context.getBean(ServerStartedInitializingBean.class);
return ss.getLocalPort();
}
@Bean
public ServerStartedInitializingBean getInitializingBean() {
return new ServerStartedInitializingBean();
}
}