package com.ruoyi.web.controller.common;
import com.google.code.kaptcha.Producer;
import com.ruoyi.common.core.redis.RedisCache;
import com.ruoyi.system.service.ISysConfigService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import java.io.FileWriter;
import java.io.IOException;
import com.google.gson.;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;
import static org.mockito.Mockito.;
class CaptchaControllerTest {
@Mock
Producer captchaProducer;
@Mock
Producer captchaProducerMath;
@Mock
RedisCache redisCache;
@Mock
ISysConfigService configService;
@InjectMocks
CaptchaController captchaController;
@BeforeEach
void setUp() {MockitoAnnotations.initMocks(this);
}@Test
void testGetCode() {when(configService.selectCaptchaOnOff()).thenReturn(true);String jsonString = "{\n" +" \"paths\": {\n" +" \"/dev-api/system/subjectResult/exportUserList\": {\n" +" \"post\": {\n" +" \"tags\": [\n" +" \"bd-subject-result-controller\"\n" +" ],\n" +" \"summary\": \"导出对应成绩信息\",\n" +" \"operationId\": \"exportUserListUsingPOST\",\n" +" \"parameters\": [\n" +" {\n" +" \"name\": \"batch\",\n" +" \"in\": \"query\",\n" +" \"required\": false,\n" +" \"style\": \"form\",\n" +" \"schema\": {\n" +" \"type\": \"string\"\n" +" }\n" +" },\n" +" {\n" +" \"name\": \"year\",\n" +" \"in\": \"query\",\n" +" \"required\": false,\n" +" \"style\": \"form\",\n" +" \"schema\": {\n" +" \"type\": \"string\"\n" +" }\n" +" }\n" +" ]\n" +" \n" +" }\n" +" },\n" +" \"/dev-api/system/subjectResult/test/{subjectId}\": {\n" +" \"get\": {\n" +" \"parameters\": [\n" +" {\n" +" \"name\": \"subjectId\",\n" +" \"in\": \"path\",\n" +" \"description\": \"subjectId\",\n" +" \"required\": true,\n" +" \"style\": \"form\",\n" +" \"schema\": {\n" +" \"type\": \"integer\",\n" +" \"format\": \"int64\"\n" +" }\n" +" },\n" +" {\n" +" \"name\": \"number\",\n" +" \"in\": \"query\",\n" +" \"description\": \"number\",\n" +" \"required\": true,\n" +" \"style\": \"form\",\n" +" \"schema\": {\n" +" \"type\": \"number\",\n" +" \"format\": \"float\"\n" +" }\n" +" },\n" +" {\n" +" \"name\": \"sort\",\n" +" \"in\": \"query\",\n" +" \"description\": \"sort\",\n" +" \"required\": true,\n" +" \"style\": \"form\",\n" +" \"schema\": {\n" +" \"type\": \"number\",\n" +" \"format\": \"float\"\n" +" }\n" +" }\n" +" ]\n" +" }\n" +" }\n" +" }\n" +"}";JsonObject jsonObject = JsonParser.parseString(jsonString).getAsJsonObject();JsonObject paths = jsonObject.getAsJsonObject("paths");StringBuilder output = new StringBuilder();String host = "example.com";String staticUrl = "api/v1";for (Map.Entry<String, JsonElement> entry : paths.entrySet()) {String path = entry.getKey();JsonObject methods = entry.getValue().getAsJsonObject();if (methods.has("get")) {JsonObject getMethod = methods.getAsJsonObject("get");JsonArray parameters = getMethod.getAsJsonArray("parameters");output.append("### GET request with dynamic variables\n");output.append("GET http://").append(host).append("/").append(staticUrl);StringBuilder queryParams = new StringBuilder();for (JsonElement paramElement : parameters) {JsonObject param = paramElement.getAsJsonObject();String in = param.get("in").getAsString();String name = param.get("name").getAsString();if ("query".equals(in)) {if (queryParams.length() == 0) {queryParams.append("?");} else {queryParams.append("&");}queryParams.append(name).append("={{").append(name).append("}}");} else if ("path".equals(in)) {path = path.replace("{" + name + "}", "{{" + name + "}}");}}output.append(path).append(queryParams.toString()).append("\n");output.append("Accept: application/json\n\n");}}try (FileWriter fileWriter = new FileWriter("output.txt")) {fileWriter.write(output.toString());System.out.println(output.toString());} catch (IOException e) {e.printStackTrace();}System.out.println("文件已保存到output.txt");
// AjaxResult result = captchaController.getCode(null);
// Assertions.assertEquals(new AjaxResult(0, “msg”, “data”), result);
}
}
//Generated with love by TestMe 😃 Please report issues and submit feature requests at: http://weirddev.com/forum#!/testme