|
| 1 | +package em.embedded.http.patch.spring; |
| 2 | + |
| 3 | + |
| 4 | +import com.cassiomolin.patch.PatchApplication; |
| 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.api.dto.database.schema.DatabaseType; |
| 11 | +import org.evomaster.client.java.controller.problem.ProblemInfo; |
| 12 | +import org.evomaster.client.java.controller.problem.RestProblem; |
| 13 | +import org.evomaster.client.java.sql.DbCleaner; |
| 14 | +import org.evomaster.client.java.sql.DbSpecification; |
| 15 | +import org.springframework.boot.SpringApplication; |
| 16 | +import org.springframework.context.ConfigurableApplicationContext; |
| 17 | + |
| 18 | +import java.util.List; |
| 19 | +import java.util.Map; |
| 20 | + |
| 21 | +/** |
| 22 | + * Class used to start/stop the SUT. This will be controller by the EvoMaster process |
| 23 | + */ |
| 24 | +public class EmbeddedEvoMasterController extends EmbeddedSutController { |
| 25 | + |
| 26 | + public static void main(String[] args) { |
| 27 | + |
| 28 | + int port = 40100; |
| 29 | + if (args.length > 0) { |
| 30 | + port = Integer.parseInt(args[0]); |
| 31 | + } |
| 32 | + |
| 33 | + EmbeddedEvoMasterController controller = new EmbeddedEvoMasterController(port); |
| 34 | + InstrumentedSutStarter starter = new InstrumentedSutStarter(controller); |
| 35 | + |
| 36 | + starter.start(); |
| 37 | + } |
| 38 | + |
| 39 | + |
| 40 | + private ConfigurableApplicationContext ctx; |
| 41 | + private List<DbSpecification> dbSpecification; |
| 42 | + |
| 43 | + |
| 44 | + public EmbeddedEvoMasterController() { |
| 45 | + this(40100); |
| 46 | + } |
| 47 | + |
| 48 | + public EmbeddedEvoMasterController(int port) { |
| 49 | + setControllerPort(port); |
| 50 | + } |
| 51 | + |
| 52 | + @Override |
| 53 | + public String startSut() { |
| 54 | + |
| 55 | + ctx = SpringApplication.run(PatchApplication.class, new String[]{ |
| 56 | + "--server.port=0" |
| 57 | + }); |
| 58 | + |
| 59 | + return "http://localhost:" + getSutPort(); |
| 60 | + } |
| 61 | + |
| 62 | + protected int getSutPort() { |
| 63 | + return (Integer) ((Map) ctx.getEnvironment() |
| 64 | + .getPropertySources().get("server.ports").getSource()) |
| 65 | + .get("local.server.port"); |
| 66 | + } |
| 67 | + |
| 68 | + |
| 69 | + @Override |
| 70 | + public boolean isSutRunning() { |
| 71 | + return ctx != null && ctx.isRunning(); |
| 72 | + } |
| 73 | + |
| 74 | + @Override |
| 75 | + public void stopSut() { |
| 76 | + ctx.stop(); |
| 77 | + } |
| 78 | + |
| 79 | + @Override |
| 80 | + public String getPackagePrefixesToCover() { |
| 81 | + return "com.cassiomolin.patch."; |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public void resetStateOfSUT() { |
| 86 | + } |
| 87 | + |
| 88 | + @Override |
| 89 | + public ProblemInfo getProblemInfo() { |
| 90 | + |
| 91 | + return new RestProblem( |
| 92 | + "http://localhost:" + getSutPort() + "/v3/api-docs", |
| 93 | + null, |
| 94 | + null |
| 95 | + ); |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public SutInfoDto.OutputFormat getPreferredOutputFormat() { |
| 100 | + return SutInfoDto.OutputFormat.JAVA_JUNIT_5; |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public List<AuthenticationDto> getInfoForAuthentication() { |
| 105 | + return null; |
| 106 | + } |
| 107 | + |
| 108 | + @Override |
| 109 | + public List<DbSpecification> getDbSpecifications() { |
| 110 | + return dbSpecification; |
| 111 | + } |
| 112 | +} |
0 commit comments