|
| 1 | +package em.embedded.quartz.manager; |
| 2 | + |
| 3 | + |
| 4 | +import it.fabioformosa.QuartzManagerDemoApplication; |
| 5 | +import org.evomaster.client.java.controller.AuthUtils; |
| 6 | +import org.evomaster.client.java.controller.EmbeddedSutController; |
| 7 | +import org.evomaster.client.java.controller.InstrumentedSutStarter; |
| 8 | +import org.evomaster.client.java.controller.api.dto.SutInfoDto; |
| 9 | +import org.evomaster.client.java.controller.api.dto.auth.AuthenticationDto; |
| 10 | +import org.evomaster.client.java.controller.problem.ProblemInfo; |
| 11 | +import org.evomaster.client.java.controller.problem.RestProblem; |
| 12 | +import org.evomaster.client.java.sql.DbSpecification; |
| 13 | +import org.springframework.boot.SpringApplication; |
| 14 | +import org.springframework.context.ConfigurableApplicationContext; |
| 15 | + |
| 16 | +import java.util.Arrays; |
| 17 | +import java.util.List; |
| 18 | +import java.util.Map; |
| 19 | + |
| 20 | +/** |
| 21 | + * Class used to start/stop the SUT. This will be controller by the EvoMaster process |
| 22 | + */ |
| 23 | +public class EmbeddedEvoMasterController extends EmbeddedSutController { |
| 24 | + |
| 25 | + public static void main(String[] args) { |
| 26 | + |
| 27 | + int port = 40100; |
| 28 | + if (args.length > 0) { |
| 29 | + port = Integer.parseInt(args[0]); |
| 30 | + } |
| 31 | + |
| 32 | + EmbeddedEvoMasterController controller = new EmbeddedEvoMasterController(port); |
| 33 | + InstrumentedSutStarter starter = new InstrumentedSutStarter(controller); |
| 34 | + |
| 35 | + starter.start(); |
| 36 | + } |
| 37 | + |
| 38 | + |
| 39 | + private ConfigurableApplicationContext ctx; |
| 40 | + |
| 41 | + |
| 42 | + public EmbeddedEvoMasterController() { |
| 43 | + this(40100); |
| 44 | + } |
| 45 | + |
| 46 | + public EmbeddedEvoMasterController(int port) { |
| 47 | + setControllerPort(port); |
| 48 | + } |
| 49 | + |
| 50 | + @Override |
| 51 | + public String startSut() { |
| 52 | + |
| 53 | + ctx = SpringApplication.run(QuartzManagerDemoApplication.class, new String[]{ |
| 54 | + "--server.port=0", |
| 55 | + "--quartz-manager.security.accounts.in-memory.users[0].username=foo", |
| 56 | + "--quartz-manager.security.accounts.in-memory.users[0].password=bar", |
| 57 | + "--quartz-manager.security.accounts.in-memory.users[0].roles[0]=admin", |
| 58 | + "--quartz-manager.security.accounts.in-memory.users[1].username=foo2", |
| 59 | + "--quartz-manager.security.accounts.in-memory.users[1].password=bar", |
| 60 | + "--quartz-manager.security.accounts.in-memory.users[1].roles[0]=admin", |
| 61 | + }); |
| 62 | + |
| 63 | + return "http://localhost:" + getSutPort(); |
| 64 | + } |
| 65 | + |
| 66 | + protected int getSutPort() { |
| 67 | + return (Integer) ((Map) ctx.getEnvironment() |
| 68 | + .getPropertySources().get("server.ports").getSource()) |
| 69 | + .get("local.server.port"); |
| 70 | + } |
| 71 | + |
| 72 | + |
| 73 | + @Override |
| 74 | + public boolean isSutRunning() { |
| 75 | + return ctx != null && ctx.isRunning(); |
| 76 | + } |
| 77 | + |
| 78 | + @Override |
| 79 | + public void stopSut() { |
| 80 | + ctx.stop(); |
| 81 | + } |
| 82 | + |
| 83 | + @Override |
| 84 | + public String getPackagePrefixesToCover() { |
| 85 | + return "it.fabioformosa."; |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public void resetStateOfSUT() { |
| 90 | + } |
| 91 | + |
| 92 | + @Override |
| 93 | + public ProblemInfo getProblemInfo() { |
| 94 | + |
| 95 | + return new RestProblem( |
| 96 | + "http://localhost:" + getSutPort() + "/v3/api-docs", |
| 97 | + null, |
| 98 | + null |
| 99 | + ); |
| 100 | + } |
| 101 | + |
| 102 | + @Override |
| 103 | + public SutInfoDto.OutputFormat getPreferredOutputFormat() { |
| 104 | + return SutInfoDto.OutputFormat.JAVA_JUNIT_5; |
| 105 | + } |
| 106 | + |
| 107 | + @Override |
| 108 | + public List<AuthenticationDto> getInfoForAuthentication() { |
| 109 | + return Arrays.asList( |
| 110 | + AuthUtils.getForJsonToken( |
| 111 | + "USER_1", |
| 112 | + "/quartz-manager/auth/login", |
| 113 | + "username=foo&password=bar", |
| 114 | + "/accessToken", |
| 115 | + "Bearer ", |
| 116 | + "application/x-www-form-urlencoded"), |
| 117 | + AuthUtils.getForJsonToken( |
| 118 | + "USER_2", |
| 119 | + "/quartz-manager/auth/login", |
| 120 | + "username=foo2&password=bar", |
| 121 | + "/accessToken", |
| 122 | + "Bearer ", |
| 123 | + "application/x-www-form-urlencoded") |
| 124 | + ); |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public List<DbSpecification> getDbSpecifications() { |
| 129 | + return null; |
| 130 | + } |
| 131 | +} |
0 commit comments