Skip to content

Commit

Permalink
is it sorted
Browse files Browse the repository at this point in the history
  • Loading branch information
shortcuts committed Apr 27, 2022
1 parent c251cf3 commit b3a3600
Show file tree
Hide file tree
Showing 24 changed files with 4,827 additions and 4,820 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import java.io.File;
import java.io.IOException;
import java.util.*;
import java.util.Collections;
import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.stream.Collectors;
import org.openapitools.codegen.*;

@SuppressWarnings("unchecked")
Expand Down Expand Up @@ -228,28 +231,32 @@ private Map<String, Request[]> loadCTS()
}

// operationId -> CodegenOperation
private HashMap<String, CodegenOperation> buildOperations(
private TreeMap<String, CodegenOperation> buildOperations(
Map<String, Object> objs
) {
HashMap<String, CodegenOperation> result = new HashMap<>();
List<Map<String, Object>> apis =
((Map<String, List<Map<String, Object>>>) objs.get("apiInfo")).get(
"apis"
);

for (Map<String, Object> api : apis) {
String apiName = ((String) api.get("baseName")).toLowerCase();
if (!apiName.equals(client.replace("-", ""))) {
continue;
}

List<CodegenOperation> operations =
((Map<String, List<CodegenOperation>>) api.get("operations")).get(
"operation"
);

for (CodegenOperation ope : operations) {
result.put(ope.operationId, ope);
}
}
return result;

return new TreeMap<String, CodegenOperation>(result);
}

private String createImportName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,80 @@ void init() {
}

@Test
@DisplayName("deleteABTest")
void deleteABTestTest0() {
int id0 = 42;
@DisplayName("addABTests with minimal parameters")
void addABTestsTest0() {
AddABTestsRequest addABTestsRequest0 = new AddABTestsRequest();
{
String endAt1 = "2022-12-31T00:00:00.000Z";

addABTestsRequest0.setEndAt(endAt1);
String name1 = "myABTest";

addABTestsRequest0.setName(name1);

List<AddABTestsVariant> variant1 = new ArrayList<>();
{
AbTestsVariant variant_02 = new AbTestsVariant();
{
String index3 = "AB_TEST_1";

variant_02.setIndex(index3);

int trafficPercentage3 = 30;

variant_02.setTrafficPercentage(trafficPercentage3);
}
variant1.add(AddABTestsVariant.ofAbTestsVariant(variant_02));

AbTestsVariant variant_12 = new AbTestsVariant();
{
String index3 = "AB_TEST_2";

variant_12.setIndex(index3);

int trafficPercentage3 = 50;

variant_12.setTrafficPercentage(trafficPercentage3);
}
variant1.add(AddABTestsVariant.ofAbTestsVariant(variant_12));
}
addABTestsRequest0.setVariant(variant1);
}

EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> {
return client.deleteABTest(id0);
return client.addABTests(addABTestsRequest0);
}
);

assertEquals(req.getPath(), "/2/abtests/42");
assertEquals(req.getMethod(), "DELETE");
assertEquals(req.getPath(), "/2/abtests");
assertEquals(req.getMethod(), "POST");

assertDoesNotThrow(() -> {
JSONAssert.assertEquals(
"{\"endAt\":\"2022-12-31T00:00:00.000Z\",\"name\":\"myABTest\",\"variant\":[{\"index\":\"AB_TEST_1\",\"trafficPercentage\":30},{\"index\":\"AB_TEST_2\",\"trafficPercentage\":50}]}",
req.getBody(),
JSONCompareMode.STRICT_ORDER
);
});
}

@Test
@DisplayName("allow post method for a custom path with minimal parameters")
void postTest0() {
@DisplayName("allow del method for a custom path with minimal parameters")
void delTest0() {
String path0 = "/test/minimal";

EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> {
return client.post(path0);
return client.del(path0);
}
);

assertEquals(req.getPath(), "/1/test/minimal");
assertEquals(req.getMethod(), "POST");
assertEquals(req.getMethod(), "DELETE");
}

@Test
@DisplayName("allow post method for a custom path with all parameters")
void postTest1() {
@DisplayName("allow del method for a custom path with all parameters")
void delTest1() {
String path0 = "/test/all";

Map<String, Object> parameters0 = new HashMap<>();
Expand All @@ -68,28 +112,13 @@ void postTest1() {
parameters0.put("query", query1);
}

Map<String, String> body0 = new HashMap<>();
{
String body1 = "parameters";

body0.put("body", body1);
}

EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> {
return client.post(path0, parameters0, body0);
return client.del(path0, parameters0);
}
);

assertEquals(req.getPath(), "/1/test/all");
assertEquals(req.getMethod(), "POST");

assertDoesNotThrow(() -> {
JSONAssert.assertEquals(
"{\"body\":\"parameters\"}",
req.getBody(),
JSONCompareMode.STRICT_ORDER
);
});
assertEquals(req.getMethod(), "DELETE");

Map<String, String> expectedQuery = JSON.deserialize(
"{\"query\":\"parameters\"}",
Expand All @@ -114,75 +143,17 @@ void postTest1() {
}

@Test
@DisplayName("stopABTest")
void stopABTestTest0() {
@DisplayName("deleteABTest")
void deleteABTestTest0() {
int id0 = 42;

EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> {
return client.stopABTest(id0);
}
);

assertEquals(req.getPath(), "/2/abtests/42/stop");
assertEquals(req.getMethod(), "POST");
}

@Test
@DisplayName("addABTests with minimal parameters")
void addABTestsTest0() {
AddABTestsRequest addABTestsRequest0 = new AddABTestsRequest();
{
String endAt1 = "2022-12-31T00:00:00.000Z";

addABTestsRequest0.setEndAt(endAt1);
String name1 = "myABTest";

addABTestsRequest0.setName(name1);

List<AddABTestsVariant> variant1 = new ArrayList<>();
{
AbTestsVariant variant_02 = new AbTestsVariant();
{
String index3 = "AB_TEST_1";

variant_02.setIndex(index3);

int trafficPercentage3 = 30;

variant_02.setTrafficPercentage(trafficPercentage3);
}
variant1.add(AddABTestsVariant.ofAbTestsVariant(variant_02));

AbTestsVariant variant_12 = new AbTestsVariant();
{
String index3 = "AB_TEST_2";

variant_12.setIndex(index3);

int trafficPercentage3 = 50;

variant_12.setTrafficPercentage(trafficPercentage3);
}
variant1.add(AddABTestsVariant.ofAbTestsVariant(variant_12));
}
addABTestsRequest0.setVariant(variant1);
}

EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> {
return client.addABTests(addABTestsRequest0);
return client.deleteABTest(id0);
}
);

assertEquals(req.getPath(), "/2/abtests");
assertEquals(req.getMethod(), "POST");

assertDoesNotThrow(() -> {
JSONAssert.assertEquals(
"{\"endAt\":\"2022-12-31T00:00:00.000Z\",\"name\":\"myABTest\",\"variant\":[{\"index\":\"AB_TEST_1\",\"trafficPercentage\":30},{\"index\":\"AB_TEST_2\",\"trafficPercentage\":50}]}",
req.getBody(),
JSONCompareMode.STRICT_ORDER
);
});
assertEquals(req.getPath(), "/2/abtests/42");
assertEquals(req.getMethod(), "DELETE");
}

@Test
Expand Down Expand Up @@ -241,6 +212,20 @@ void getTest1() {
}
}

@Test
@DisplayName("getABTest")
void getABTestTest0() {
int id0 = 42;

EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> {
return client.getABTest(id0);
}
);

assertEquals(req.getPath(), "/2/abtests/42");
assertEquals(req.getMethod(), "GET");
}

@Test
@DisplayName("listABTests with minimal parameters")
void listABTestsTest0() {
Expand Down Expand Up @@ -279,22 +264,22 @@ void listABTestsTest0() {
}

@Test
@DisplayName("allow del method for a custom path with minimal parameters")
void delTest0() {
@DisplayName("allow post method for a custom path with minimal parameters")
void postTest0() {
String path0 = "/test/minimal";

EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> {
return client.del(path0);
return client.post(path0);
}
);

assertEquals(req.getPath(), "/1/test/minimal");
assertEquals(req.getMethod(), "DELETE");
assertEquals(req.getMethod(), "POST");
}

@Test
@DisplayName("allow del method for a custom path with all parameters")
void delTest1() {
@DisplayName("allow post method for a custom path with all parameters")
void postTest1() {
String path0 = "/test/all";

Map<String, Object> parameters0 = new HashMap<>();
Expand All @@ -304,13 +289,28 @@ void delTest1() {
parameters0.put("query", query1);
}

Map<String, String> body0 = new HashMap<>();
{
String body1 = "parameters";

body0.put("body", body1);
}

EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> {
return client.del(path0, parameters0);
return client.post(path0, parameters0, body0);
}
);

assertEquals(req.getPath(), "/1/test/all");
assertEquals(req.getMethod(), "DELETE");
assertEquals(req.getMethod(), "POST");

assertDoesNotThrow(() -> {
JSONAssert.assertEquals(
"{\"body\":\"parameters\"}",
req.getBody(),
JSONCompareMode.STRICT_ORDER
);
});

Map<String, String> expectedQuery = JSON.deserialize(
"{\"query\":\"parameters\"}",
Expand Down Expand Up @@ -406,16 +406,16 @@ void putTest1() {
}

@Test
@DisplayName("getABTest")
void getABTestTest0() {
@DisplayName("stopABTest")
void stopABTestTest0() {
int id0 = 42;

EchoResponseInterface req = (EchoResponseInterface) assertDoesNotThrow(() -> {
return client.getABTest(id0);
return client.stopABTest(id0);
}
);

assertEquals(req.getPath(), "/2/abtests/42");
assertEquals(req.getMethod(), "GET");
assertEquals(req.getPath(), "/2/abtests/42/stop");
assertEquals(req.getMethod(), "POST");
}
}
Loading

0 comments on commit b3a3600

Please sign in to comment.