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