|
| 1 | +package em.embedded.ohsome; |
| 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.SutInfoDto; |
| 6 | +import org.evomaster.client.java.controller.api.dto.auth.AuthenticationDto; |
| 7 | +import org.evomaster.client.java.controller.problem.ProblemInfo; |
| 8 | +import org.evomaster.client.java.controller.problem.RestProblem; |
| 9 | +import org.evomaster.client.java.sql.DbSpecification; |
| 10 | +import org.heigit.ohsome.ohsomeapi.Application; |
| 11 | +import org.springframework.context.ConfigurableApplicationContext; |
| 12 | +import java.util.*; |
| 13 | + |
| 14 | +public class EmbeddedEvoMasterController extends EmbeddedSutController { |
| 15 | + |
| 16 | + private ConfigurableApplicationContext ctx; |
| 17 | + |
| 18 | + public EmbeddedEvoMasterController() { |
| 19 | + this(40100); |
| 20 | + } |
| 21 | + |
| 22 | + public EmbeddedEvoMasterController(int port) { |
| 23 | + setControllerPort(port); |
| 24 | + } |
| 25 | + |
| 26 | + public static void main(String[] args) { |
| 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 | + @Override |
| 39 | + public boolean isSutRunning() { |
| 40 | + return ctx!=null && ctx.isRunning(); |
| 41 | + } |
| 42 | + |
| 43 | + @Override |
| 44 | + public String getPackagePrefixesToCover() { |
| 45 | + return "org.heigit.ohsome.ohsomeapi."; |
| 46 | + } |
| 47 | + |
| 48 | + @Override |
| 49 | + public List<AuthenticationDto> getInfoForAuthentication() { |
| 50 | + return null; |
| 51 | + } |
| 52 | + |
| 53 | + @Override |
| 54 | + public ProblemInfo getProblemInfo() { |
| 55 | + return new RestProblem( |
| 56 | + "http://localhost:" + getSutPort() + "/docs?group=Data%20Aggregation", |
| 57 | + null |
| 58 | + ); |
| 59 | + } |
| 60 | + |
| 61 | + @Override |
| 62 | + public SutInfoDto.OutputFormat getPreferredOutputFormat() { |
| 63 | + return SutInfoDto.OutputFormat.JAVA_JUNIT_5; |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public String startSut() { |
| 68 | + Application application = new Application(); |
| 69 | + |
| 70 | + application.main(new String[]{ |
| 71 | + "--server.port=0", |
| 72 | + "--spring.profiles.active=dev", |
| 73 | + "--management.server.port=-1", |
| 74 | + "--logging.level.org.springframework=INFO", |
| 75 | + "--logging.level.root=OFF", |
| 76 | + "--database.db=em/external/rest/ohsome-api/src/main/resources/heidelberg.mv.db", |
| 77 | + }); |
| 78 | + |
| 79 | + ctx = (ConfigurableApplicationContext) application.getApplicationContext(); |
| 80 | + return "http://localhost:" + getSutPort(); |
| 81 | + } |
| 82 | + |
| 83 | + protected int getSutPort() { |
| 84 | + return (Integer) ((Map) ctx.getEnvironment() |
| 85 | + .getPropertySources().get("server.ports").getSource()) |
| 86 | + .get("local.server.port"); |
| 87 | + } |
| 88 | + |
| 89 | + @Override |
| 90 | + public void stopSut() { |
| 91 | + if(ctx!=null) ctx.stop(); |
| 92 | + } |
| 93 | + |
| 94 | + @Override |
| 95 | + public void resetStateOfSUT() { |
| 96 | + } |
| 97 | + |
| 98 | + @Override |
| 99 | + public List<DbSpecification> getDbSpecifications() { |
| 100 | + return null; |
| 101 | + } |
| 102 | +} |
0 commit comments