Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
R
RAGO - RAG OpenAPI Framework
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
JastAdd
RAGO - RAG OpenAPI Framework
Commits
a6635c54
Commit
a6635c54
authored
3 years ago
by
Jueun Park
Browse files
Options
Downloads
Patches
Plain Diff
Update test
parent
c5afb7dd
Branches
Branches containing commit
No related tags found
1 merge request
!1
Tests/openapi generator
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/test/java/openapi/OpenAPIMain_test.java
+31
-22
31 additions, 22 deletions
src/test/java/openapi/OpenAPIMain_test.java
with
31 additions
and
22 deletions
src/test/java/openapi/OpenAPIMain_test.java
+
31
−
22
View file @
a6635c54
...
@@ -13,16 +13,12 @@ import io.swagger.v3.oas.models.OpenAPI;
...
@@ -13,16 +13,12 @@ import io.swagger.v3.oas.models.OpenAPI;
import
io.swagger.v3.parser.OpenAPIV3Parser
;
import
io.swagger.v3.parser.OpenAPIV3Parser
;
import
io.swagger.v3.parser.core.models.ParseOptions
;
import
io.swagger.v3.parser.core.models.ParseOptions
;
import
io.swagger.v3.parser.core.models.SwaggerParseResult
;
import
io.swagger.v3.parser.core.models.SwaggerParseResult
;
import
org.apache.commons.lang3.StringUtils
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.Assertions
;
import
org.junit.jupiter.api.Test
;
import
org.junit.jupiter.api.Test
;
import
de.tudresden.inf.st.jastadd.dumpAst.ast.Dumper
;
import
java.awt.*
;
import
java.io.File
;
import
java.io.File
;
import
java.io.FileWriter
;
import
java.io.FileWriter
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.net.URL
;
import
java.nio.file.Path
;
import
java.nio.file.Path
;
import
java.nio.file.Paths
;
import
java.nio.file.Paths
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -30,15 +26,6 @@ import java.util.List;
...
@@ -30,15 +26,6 @@ import java.util.List;
public
class
OpenAPIMain_test
{
public
class
OpenAPIMain_test
{
protected
static
boolean
isNumeric
(
String
str
)
{
try
{
int
d
=
Integer
.
parseInt
(
str
);
}
catch
(
NumberFormatException
nfe
)
{
return
false
;
}
return
true
;
}
@Test
@Test
public
void
test
()
throws
Exception
{
public
void
test
()
throws
Exception
{
OpenAPIObject
jastAddObject
;
OpenAPIObject
jastAddObject
;
...
@@ -71,8 +58,11 @@ public class OpenAPIMain_test {
...
@@ -71,8 +58,11 @@ public class OpenAPIMain_test {
// validation of OpenAPI in POJO
// validation of OpenAPI in POJO
JsonNode
expectedNode
=
mapper
.
readTree
(
Json
.
mapper
().
writeValueAsString
(
POJOOpenAPI
));
JsonNode
expectedNode
=
mapper
.
readTree
(
Json
.
mapper
().
writeValueAsString
(
POJOOpenAPI
));
validation
=
new
OpenAPIV3Parser
().
readContents
(
expectedNode
.
toString
()).
getMessages
();
validation
=
new
OpenAPIV3Parser
().
readContents
(
expectedNode
.
toString
()).
getMessages
();
if
(
validation
.
size
()
!=
0
)
if
(
validation
.
size
()
!=
0
)
{
System
.
out
.
println
(
"validation failed!"
);
System
.
out
.
println
(
"validation failed!"
);
for
(
String
s
:
validation
)
System
.
out
.
println
(
s
);
}
else
else
System
.
out
.
println
(
"validated!"
);
System
.
out
.
println
(
"validated!"
);
...
@@ -82,7 +72,6 @@ public class OpenAPIMain_test {
...
@@ -82,7 +72,6 @@ public class OpenAPIMain_test {
// OpenAPI in POJO to OpenAPI in JastAdd
// OpenAPI in POJO to OpenAPI in JastAdd
jastAddObject
=
OpenAPIObject
.
parseOpenAPI
(
POJOOpenAPI
);
jastAddObject
=
OpenAPIObject
.
parseOpenAPI
(
POJOOpenAPI
);
Dumper
.
read
(
jastAddObject
).
dumpAsPNG
(
Paths
.
get
(
writerName
+
".png"
));
// OpenAPI in JastAdd to OpenAPI in POJO
// OpenAPI in JastAdd to OpenAPI in POJO
OpenAPI
transformedAPI
=
OpenAPIObject
.
reverseOpenAPI
(
jastAddObject
);
OpenAPI
transformedAPI
=
OpenAPIObject
.
reverseOpenAPI
(
jastAddObject
);
...
@@ -90,8 +79,11 @@ public class OpenAPIMain_test {
...
@@ -90,8 +79,11 @@ public class OpenAPIMain_test {
// validation of transferred OpenAPI
// validation of transferred OpenAPI
JsonNode
actualNode
=
mapper
.
readTree
(
Json
.
mapper
().
writeValueAsString
(
transformedAPI
));
JsonNode
actualNode
=
mapper
.
readTree
(
Json
.
mapper
().
writeValueAsString
(
transformedAPI
));
validation
=
new
OpenAPIV3Parser
().
readContents
(
actualNode
.
toString
()).
getMessages
();
validation
=
new
OpenAPIV3Parser
().
readContents
(
actualNode
.
toString
()).
getMessages
();
if
(
validation
.
size
()
!=
0
)
if
(
validation
.
size
()
!=
0
)
{
System
.
out
.
println
(
"validation failed!"
);
System
.
out
.
println
(
"validation failed!"
);
for
(
String
s
:
validation
)
System
.
out
.
println
(
s
);
}
else
else
System
.
out
.
println
(
"validated"
);
System
.
out
.
println
(
"validated"
);
...
@@ -116,26 +108,34 @@ public class OpenAPIMain_test {
...
@@ -116,26 +108,34 @@ public class OpenAPIMain_test {
protected
void
compareJson
(
JsonNode
expectedNode
,
JsonNode
actualNode
,
Path
path
)
throws
IOException
{
protected
void
compareJson
(
JsonNode
expectedNode
,
JsonNode
actualNode
,
Path
path
)
throws
IOException
{
JsonNode
diff
=
JsonDiff
.
asJson
(
expectedNode
,
actualNode
);
JsonNode
diff
=
JsonDiff
.
asJson
(
expectedNode
,
actualNode
);
String
pathNode
;
String
pathNode
;
String
result
=
""
;
for
(
int
i
=
diff
.
size
()
-
1
;
i
>=
0
;
i
--)
{
for
(
int
i
=
diff
.
size
()
-
1
;
i
>=
0
;
i
--)
{
// get the path of a node involving difference.
// get the path of a node involving difference.
pathNode
=
"$"
+
diff
.
get
(
i
).
get
(
"path"
).
toString
()
pathNode
=
"$"
+
diff
.
get
(
i
).
get
(
"path"
).
toString
();
for
(
String
s
:
pathNode
.
split
(
"/"
))
{
if
(
s
.
contains
(
"."
))
pathNode
=
pathNode
.
replace
(
s
,
"['"
+
s
+
"']"
);
}
pathNode
=
pathNode
.
replace
(
"/"
,
"."
)
.
replace
(
"/"
,
"."
)
.
replace
(
"~1"
,
"/"
)
.
replace
(
"~1"
,
"/"
)
.
replace
(
"\""
,
""
);
.
replace
(
"\""
,
""
);
for
(
String
s
:
pathNode
.
split
(
"\\."
))
{
for
(
String
s
:
pathNode
.
split
(
"\\."
))
{
if
(
isNumeric
(
s
)
&&
Integer
.
parseInt
(
s
)
<
100
)
if
(
!
s
.
contains
(
"['"
)
&&
isNumeric
(
s
)
&&
Integer
.
parseInt
(
s
)
<
100
)
pathNode
=
pathNode
.
replace
(
s
,
"["
+
s
+
"]"
);
result
=
result
.
concat
(
"["
+
s
+
"]."
);
else
result
=
result
.
concat
(
s
+
"."
);
}
}
pathNode
=
result
.
substring
(
0
,
result
.
length
()-
1
);
// check, if this node exists or has an empty value.
// check, if this node exists or has an empty value.
System
.
out
.
println
(
"1"
);
System
.
out
.
println
(
pathNode
);
if
(
JsonPath
.
parse
(
actualNode
.
toString
()).
read
(
pathNode
,
String
.
class
)
==
null
||
JsonPath
.
parse
(
actualNode
.
toString
()).
read
(
pathNode
,
String
.
class
).
isEmpty
())
if
(
JsonPath
.
parse
(
actualNode
.
toString
()).
read
(
pathNode
,
String
.
class
)
==
null
||
JsonPath
.
parse
(
actualNode
.
toString
()).
read
(
pathNode
,
String
.
class
).
isEmpty
())
((
ArrayNode
)
diff
).
remove
(
i
);
((
ArrayNode
)
diff
).
remove
(
i
);
else
if
(!
JsonPath
.
parse
(
actualNode
.
toString
()).
read
(
pathNode
.
substring
(
0
,
pathNode
.
lastIndexOf
(
"."
)).
concat
(
".$ref"
),
String
.
class
).
isEmpty
())
else
if
(!
JsonPath
.
parse
(
actualNode
.
toString
()).
read
(
pathNode
.
substring
(
0
,
pathNode
.
lastIndexOf
(
"."
)).
concat
(
".$ref"
),
String
.
class
).
isEmpty
())
((
ArrayNode
)
diff
).
remove
(
i
);
((
ArrayNode
)
diff
).
remove
(
i
);
result
=
""
;
}
}
// if the Jsons are equivalent, there is no reason to to the text comparison.
// if the Jsons are equivalent, there is no reason to to the text comparison.
...
@@ -144,4 +144,13 @@ public class OpenAPIMain_test {
...
@@ -144,4 +144,13 @@ public class OpenAPIMain_test {
Assertions
.
assertEquals
(
actualNode
.
toPrettyString
(),
expectedNode
.
toPrettyString
(),
"JSONs for "
+
path
+
" are different:\n"
+
diff
.
toPrettyString
());
Assertions
.
assertEquals
(
actualNode
.
toPrettyString
(),
expectedNode
.
toPrettyString
(),
"JSONs for "
+
path
+
" are different:\n"
+
diff
.
toPrettyString
());
}
}
}
}
protected
static
boolean
isNumeric
(
String
str
)
{
try
{
int
d
=
Integer
.
parseInt
(
str
);
}
catch
(
NumberFormatException
nfe
)
{
return
false
;
}
return
true
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment