Skip to content

Commit a7cc201

Browse files
committed
some test fixes, 25 failures remain
1 parent 3447109 commit a7cc201

File tree

5 files changed

+45
-40
lines changed

5 files changed

+45
-40
lines changed

src/main/java/com/github/erosb/kappa/operation/validator/util/convert/TypeConverter.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ public IJsonValue convertArray(final OAIContext context,
108108
public IJsonValue convertPrimitive(final OAIContext context,
109109
final Schema schema,
110110
Object value) {
111-
111+
if (value == null) {
112+
return new JsonNull();
113+
}
112114
return new JsonString(value.toString());
113115
}
114116

src/main/java/com/github/erosb/kappa/operation/validator/validation/ParameterValidator.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ void validate(final Map<String, IJsonValue> values,
5656
validator.validate(paramValue,
5757
// uriFactory.pathParam(paramName),
5858
validation,
59-
ValidatorConfig.builder().primitiveValidationStrategy(PrimitiveValidationStrategy.STRICT).build());
59+
ValidatorConfig.builder().primitiveValidationStrategy(PrimitiveValidationStrategy.LENIENT).build());
6060
}
6161
}
6262
}

src/test/java/com/github/erosb/kappa/operation/validator/convert/ParamChecker.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
abstract class ParamChecker {
1111
static void checkPrimitive(Map<String, IJsonValue> nodes, String propName) {
1212
assertEquals(1, nodes.size());
13-
assertEquals(5, nodes.get(propName).requireInt());
13+
assertEquals("5", nodes.get(propName).requireString().getValue());
1414
}
1515

1616
static void checkWrongPrimitive(Map<String, IJsonValue> nodes, String propName) {
@@ -23,9 +23,9 @@ static void checkArray(Map<String, IJsonValue> nodes, String propName) {
2323
System.out.println("propName = " + propName);
2424
assertEquals(1, nodes.size());
2525
assertEquals(3, nodes.get(propName).requireArray().length());
26-
assertEquals(3, nodes.get(propName).requireArray().get(0).requireInt());
27-
assertEquals(4, nodes.get(propName).requireArray().get(1).requireInt());
28-
assertEquals(5, nodes.get(propName).requireArray().get(2).requireInt());
26+
assertEquals("3", nodes.get(propName).requireArray().get(0).requireString().getValue());
27+
assertEquals("4", nodes.get(propName).requireArray().get(1).requireString().getValue());
28+
assertEquals("5", nodes.get(propName).requireArray().get(2).requireString().getValue());
2929
}
3030

3131
static void checkWrongArray(Map<String, IJsonValue> nodes, String propName) {
@@ -39,7 +39,7 @@ static void checkObject(Map<String, IJsonValue> nodes, String propName) {
3939
System.out.println("propName = " + propName);
4040
assertEquals(1, nodes.size());
4141
assertEquals("admin", nodes.get(propName).requireObject().get("stringProp").requireString().getValue());
42-
assertTrue(nodes.get(propName).requireObject().get("boolProp").requireBoolean().getValue());
42+
assertEquals("true", nodes.get(propName).requireObject().get("boolProp").requireString().getValue());
4343
}
4444

4545
static void checkWrongObject(Map<String, IJsonValue> nodes, String propName) {

src/test/java/com/github/erosb/kappa/operation/validator/convert/TypeConverterTest.java

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import com.github.erosb.jsonsKema.IJsonArray;
44
import com.github.erosb.jsonsKema.IJsonValue;
55
import com.github.erosb.jsonsKema.JsonNull;
6+
import org.junit.Ignore;
67
import org.junit.Test;
78
import com.github.erosb.kappa.operation.validator.util.convert.TypeConverter;
89
import com.github.erosb.kappa.parser.model.v3.Schema;
10+
import org.skyscreamer.jsonassert.JSONAssert;
911

1012
import java.math.BigDecimal;
1113
import java.math.BigInteger;
@@ -45,9 +47,9 @@ public void convertObjectNullNode() {
4547
Map<String, Object> rootValue = new HashMap<>();
4648
rootValue.put("foo", value);
4749

48-
assertEquals(
49-
"{\"foo\":{\"bar\":1}}",
50-
TypeConverter.instance().convertObject(null, schema, rootValue).toString());
50+
JSONAssert.assertEquals(
51+
"{\"foo\":{\"bar\":\"1\"}}",
52+
TypeConverter.instance().convertObject(null, schema, rootValue).toString(), false);
5153
}
5254

5355
@Test
@@ -63,15 +65,15 @@ public void convertObjectOfObject() {
6365
Map<String, Object> foo = new HashMap<>();
6466
foo.put("foo", bar);
6567

66-
assertEquals(
67-
"{\"foo\":{\"bar\":1}}",
68-
TypeConverter.instance().convertObject(null, schema, foo).toString());
68+
JSONAssert.assertEquals(
69+
"{\"foo\":{\"bar\":\"1\"}}",
70+
TypeConverter.instance().convertObject(null, schema, foo).toString(), false);
6971

7072
// wrong value
7173
foo.put("foo", "bar");
72-
assertEquals(
74+
JSONAssert.assertEquals(
7375
"{\"foo\":null}",
74-
TypeConverter.instance().convertObject(null, schema, foo).toString());
76+
TypeConverter.instance().convertObject(null, schema, foo).toString(), false);
7577
}
7678

7779
@Test
@@ -94,8 +96,8 @@ public void convertArrayNullNode() {
9496
values.add(1);
9597
values.add(10);
9698
IJsonArray convertedNode = TypeConverter.instance().convertArray(null, schema, values).requireArray();
97-
assertEquals(1, convertedNode.get(0).requireInt());
98-
assertEquals(10, convertedNode.get(1).requireInt());
99+
assertEquals("1", convertedNode.get(0).requireString().getValue());
100+
assertEquals("10", convertedNode.get(1).requireString().getValue());
99101
}
100102

101103
@Test
@@ -109,8 +111,8 @@ public void convertArrayPrimitive() {
109111

110112
IJsonArray convertedNode = TypeConverter.instance().convertArray(null, schema, values).requireArray();
111113

112-
assertEquals(1, convertedNode.get(0).requireInt());
113-
assertEquals(10, convertedNode.get(1).requireInt());
114+
assertEquals("1", convertedNode.get(0).requireString().getValue());
115+
assertEquals("10", convertedNode.get(1).requireString().getValue());
114116
}
115117

116118
@Test
@@ -129,15 +131,15 @@ public void convertArrayObject() {
129131
List<Object> value = new ArrayList<>();
130132
value.add(foo);
131133

132-
assertEquals(
133-
"[{\"foo\":{\"bar\":1}}]",
134-
TypeConverter.instance().convertArray(null, schema, value).toString());
134+
JSONAssert.assertEquals(
135+
"[{\"foo\":{\"bar\":\"1\"}}]",
136+
TypeConverter.instance().convertArray(null, schema, value).toString(), false);
135137

136138
// wrong value
137139
foo.put("foo", "bar");
138-
assertEquals(
140+
JSONAssert.assertEquals(
139141
"[{\"foo\":null}]",
140-
TypeConverter.instance().convertArray(null, schema, value).toString());
142+
TypeConverter.instance().convertArray(null, schema, value).toString(), false);
141143
}
142144

143145
@Test
@@ -153,23 +155,22 @@ public void convertArrayArray() {
153155
List<Object> rootList = new ArrayList<>();
154156
rootList.add(valueList);
155157

156-
157-
assertEquals(
158-
"[[1,2]]",
159-
TypeConverter.instance().convertArray(null, schema, rootList).toString());
158+
JSONAssert.assertEquals(
159+
"[[\"1\",\"2\"]]",
160+
TypeConverter.instance().convertArray(null, schema, rootList).toString(), false);
160161

161162
// wrong value
162163
valueList.add("foo");
163-
assertEquals(
164-
"[[1,2,\"foo\"]]",
165-
TypeConverter.instance().convertArray(null, schema, rootList).toString());
164+
JSONAssert.assertEquals(
165+
"[[\"1\",\"2\",\"foo\"]]",
166+
TypeConverter.instance().convertArray(null, schema, rootList).toString(), false);
166167

167168
// wrong sub list
168169
rootList.clear();
169170
rootList.add("foo");
170-
assertEquals(
171+
JSONAssert.assertEquals(
171172
"[null]",
172-
TypeConverter.instance().convertArray(null, schema, rootList).toString());
173+
TypeConverter.instance().convertArray(null, schema, rootList).toString(), false);
173174
}
174175

175176
@Test
@@ -197,18 +198,19 @@ public void convertPrimitiveNullNode() {
197198
}
198199

199200
@Test
201+
@Ignore
200202
public void convertPrimitiveValues() {
201203
Schema schema = new Schema();
202204
// INTEGER
203205
schema.setType("integer");
204206
// no format
205207
assertEquals(
206-
BigInteger.valueOf(1),
207-
TypeConverter.instance().convertPrimitive(null, schema, 1).requireNumber().getValue());
208+
"1",
209+
TypeConverter.instance().convertPrimitive(null, schema, 1).requireString().getValue());
208210
schema.setFormat("int32");
209211
assertEquals(
210-
1,
211-
TypeConverter.instance().convertPrimitive(null, schema, 1).requireInt());
212+
"1",
213+
TypeConverter.instance().convertPrimitive(null, schema, 1).requireString());
212214
schema.setFormat("int64");
213215
assertEquals(
214216
1L,

src/test/java/com/github/erosb/kappa/operation/validator/model/impl/BodyTest.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import org.junit.Test;
77
import com.github.erosb.kappa.parser.model.v3.MediaType;
88
import com.github.erosb.kappa.parser.model.v3.Schema;
9+
import org.skyscreamer.jsonassert.JSONAssert;
910

1011
import java.io.ByteArrayInputStream;
1112
import java.io.IOException;
@@ -46,8 +47,8 @@ private void checkBody(Body body, JsonNode values) throws IOException {
4647
Schema schema = new Schema();
4748
schema.setProperty("key", new Schema().setType("string"));
4849

49-
assertEquals(
50-
values,
51-
body.getContentAsNode(null, new MediaType().setSchema(schema), "application/json"));
50+
JSONAssert.assertEquals(
51+
values.toString(),
52+
body.getContentAsNode(null, new MediaType().setSchema(schema), "application/json").toString(), false);
5253
}
5354
}

0 commit comments

Comments
 (0)