|
| 1 | +package em.external.swagger.petstore; |
| 2 | + |
| 3 | + |
| 4 | +import org.evomaster.client.java.controller.ExternalSutController; |
| 5 | +import org.evomaster.client.java.controller.InstrumentedSutStarter; |
| 6 | +import org.evomaster.client.java.controller.api.dto.SutInfoDto; |
| 7 | +import org.evomaster.client.java.controller.api.dto.auth.AuthenticationDto; |
| 8 | +import org.evomaster.client.java.controller.problem.ProblemInfo; |
| 9 | +import org.evomaster.client.java.controller.problem.RestProblem; |
| 10 | +import org.evomaster.client.java.sql.DbSpecification; |
| 11 | + |
| 12 | +import java.util.List; |
| 13 | + |
| 14 | +public class ExternalEvoMasterController extends ExternalSutController { |
| 15 | + |
| 16 | + public static void main(String[] args) { |
| 17 | + |
| 18 | + |
| 19 | + int controllerPort = 40100; |
| 20 | + if (args.length > 0) { |
| 21 | + controllerPort = Integer.parseInt(args[0]); |
| 22 | + } |
| 23 | + int sutPort = 12345; |
| 24 | + if (args.length > 1) { |
| 25 | + sutPort = Integer.parseInt(args[1]); |
| 26 | + } |
| 27 | + String jarLocation = "cs/rest/original/swagger-petstore/target"; |
| 28 | + if (args.length > 2) { |
| 29 | + jarLocation = args[2]; |
| 30 | + } |
| 31 | + if(! jarLocation.endsWith(".jar")) { |
| 32 | + jarLocation += "/swagger-petstore-sut.jar"; |
| 33 | + } |
| 34 | + |
| 35 | + int timeoutSeconds = 120; |
| 36 | + if(args.length > 3){ |
| 37 | + timeoutSeconds = Integer.parseInt(args[3]); |
| 38 | + } |
| 39 | + String command = "java"; |
| 40 | + if(args.length > 4){ |
| 41 | + command = args[4]; |
| 42 | + } |
| 43 | + |
| 44 | + |
| 45 | + ExternalEvoMasterController controller = |
| 46 | + new ExternalEvoMasterController(controllerPort, jarLocation, |
| 47 | + sutPort, timeoutSeconds, command); |
| 48 | + |
| 49 | + InstrumentedSutStarter starter = new InstrumentedSutStarter(controller); |
| 50 | + starter.start(); |
| 51 | + |
| 52 | + } |
| 53 | + |
| 54 | + private final int timeoutSeconds; |
| 55 | + private final int sutPort; |
| 56 | + private String jarLocation; |
| 57 | + |
| 58 | + private List<DbSpecification> dbSpecification; |
| 59 | + |
| 60 | + public ExternalEvoMasterController(){ |
| 61 | + this(40100, "cs/rest/original/swagger-petstore/target/swagger-petstore-sut.jar", 12345, 120, "java"); |
| 62 | + } |
| 63 | + |
| 64 | + public ExternalEvoMasterController(String jarLocation) { |
| 65 | + this(); |
| 66 | + this.jarLocation = jarLocation; |
| 67 | + } |
| 68 | + |
| 69 | + public ExternalEvoMasterController( |
| 70 | + int controllerPort, String jarLocation, int sutPort, int timeoutSeconds, String command |
| 71 | + ) { |
| 72 | + |
| 73 | + if(jarLocation==null || jarLocation.isEmpty()){ |
| 74 | + throw new IllegalArgumentException("Missing jar location"); |
| 75 | + } |
| 76 | + |
| 77 | + this.sutPort = sutPort; |
| 78 | + this.jarLocation = jarLocation; |
| 79 | + this.timeoutSeconds = timeoutSeconds; |
| 80 | + setControllerPort(controllerPort); |
| 81 | + setJavaCommand(command); |
| 82 | + } |
| 83 | + |
| 84 | + @Override |
| 85 | + public String[] getInputParameters() { |
| 86 | + return new String[]{ |
| 87 | + "" + sutPort |
| 88 | + }; |
| 89 | + } |
| 90 | + |
| 91 | + @Override |
| 92 | + public String[] getJVMParameters() { |
| 93 | + return new String[]{ |
| 94 | + }; |
| 95 | + } |
| 96 | + |
| 97 | + |
| 98 | + @Override |
| 99 | + public String getBaseURL() { |
| 100 | + return "http://localhost:" + sutPort; |
| 101 | + } |
| 102 | + |
| 103 | + @Override |
| 104 | + public String getPathToExecutableJar() { |
| 105 | + return jarLocation; |
| 106 | + } |
| 107 | + |
| 108 | + @Override |
| 109 | + public String getLogMessageOfInitializedServer() { |
| 110 | + return "Starting ProtocolHandler "; |
| 111 | + } |
| 112 | + |
| 113 | + @Override |
| 114 | + public void preStart() { |
| 115 | + } |
| 116 | + |
| 117 | + @Override |
| 118 | + public void postStart() { |
| 119 | + |
| 120 | + } |
| 121 | + |
| 122 | + @Override |
| 123 | + public void preStop() { |
| 124 | + |
| 125 | + } |
| 126 | + |
| 127 | + @Override |
| 128 | + public void postStop() { |
| 129 | + |
| 130 | + } |
| 131 | + |
| 132 | + @Override |
| 133 | + public long getMaxAwaitForInitializationInSeconds() { |
| 134 | + return timeoutSeconds; |
| 135 | + } |
| 136 | + |
| 137 | + @Override |
| 138 | + public String getPackagePrefixesToCover() { |
| 139 | + return "io.swagger.petstore."; |
| 140 | + } |
| 141 | + |
| 142 | + |
| 143 | + public void resetStateOfSUT() { |
| 144 | + } |
| 145 | + |
| 146 | + |
| 147 | + @Override |
| 148 | + public ProblemInfo getProblemInfo() { |
| 149 | + return new RestProblem( |
| 150 | + getBaseURL() + "/api/v3/openapi.json", |
| 151 | + null |
| 152 | + ); |
| 153 | + } |
| 154 | + |
| 155 | + @Override |
| 156 | + public SutInfoDto.OutputFormat getPreferredOutputFormat() { |
| 157 | + return SutInfoDto.OutputFormat.JAVA_JUNIT_5; |
| 158 | + } |
| 159 | + |
| 160 | + @Override |
| 161 | + public List<AuthenticationDto> getInfoForAuthentication() { |
| 162 | + return null; |
| 163 | + } |
| 164 | + |
| 165 | + |
| 166 | + @Override |
| 167 | + public List<DbSpecification> getDbSpecifications() { |
| 168 | + return dbSpecification; |
| 169 | + } |
| 170 | + |
| 171 | +} |
0 commit comments