Skip to content

Commit

Permalink
3.x Use text blocks in tests (#7354)
Browse files Browse the repository at this point in the history
  • Loading branch information
Captain1653 authored Aug 15, 2023
1 parent fd1b383 commit 835d429
Show file tree
Hide file tree
Showing 15 changed files with 270 additions and 232 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020 Oracle and/or its affiliates.
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -169,15 +169,16 @@ public void testMapToArray() {

@Test
public void testMapToArrayWithParser() {
final String PROPS = ""
+ "uri-array.0=http://localhost\n"
+ "uri-array.1=http://localhost\n"
+ "uri-array.2=http://localhost\n"
+ "uri-localhost=http://localhost\n"
+ "uri.array.0=http://localhost\n"
+ "uri.array.1=http://localhost\n"
+ "uri.array.2=http://localhost\n"
+ "uri.localhost=http://localhost\n";
final String PROPS = """
uri-array.0=http://localhost
uri-array.1=http://localhost
uri-array.2=http://localhost
uri-localhost=http://localhost
uri.array.0=http://localhost
uri.array.1=http://localhost
uri.array.2=http://localhost
uri.localhost=http://localhost
""";

Config config = Config.builder()
.sources(ConfigSources.create(PROPS, PropertiesConfigParser.MEDIA_TYPE_TEXT_JAVA_PROPERTIES))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2020, 2021 Oracle and/or its affiliates.
* Copyright (c) 2020, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -47,10 +47,11 @@ public void testOrderedPropertiesUseInsertionOrderedMap() {
@Test
public void testOrderedPropertiesLoadKeepsOrdering() throws IOException {
OrderedProperties props = new OrderedProperties();
props.load(new StringReader(""
+ "aaa=1\n"
+ "bbb=2\n"
+ "ccc=3\n"
props.load(new StringReader("""
aaa=1
bbb=2
ccc=3
"""
));
assertThat(props.orderedMap().keySet(), contains("aaa", "bbb", "ccc"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2017, 2022 Oracle and/or its affiliates.
* Copyright (c) 2017, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -58,11 +58,11 @@ public class HoconConfigParserTest {
@Test
public void testResolveEnabled() {
ConfigParser parser = createResolvingParser();
ObjectNode node = parser.parse((StringContent) () -> ""
+ "aaa = 1 \n"
+ "bbb = ${aaa} \n"
+ "ccc = \"${aaa}\" \n"
+ "ddd = ${?zzz}",
ObjectNode node = parser.parse((StringContent) () -> """
aaa = 1\s
bbb = ${aaa}\s
ccc = "${aaa}"\s
ddd = ${?zzz}""",
it -> Optional.empty());

assertThat(node.entrySet(), hasSize(3));
Expand Down Expand Up @@ -114,12 +114,11 @@ public void testStringListValue() {
@Test
public void testComplexValue() {
ConfigParser parser = createResolvingParser();
ObjectNode node = parser.parse((StringContent) () -> ""
+ "aaa = \"bbb\"\n"
+ "arr = [ bbb, 13, true, 3.14159 ] \n"
+ "obj1 = { aaa = bbb, ccc = false } \n"
+ "arr2 = [ aaa, false, { bbb = 3.14159, c = true }, { ooo { ppp { xxx = yyy }}}"
+ " ]",
ObjectNode node = parser.parse((StringContent) () -> """
aaa = "bbb"
arr = [ bbb, 13, true, 3.14159 ]\s
obj1 = { aaa = bbb, ccc = false }\s
arr2 = [ aaa, false, { bbb = 3.14159, c = true }, { ooo { ppp { xxx = yyy }}} ]""",
it -> Optional.empty());

assertThat(node.entrySet(), hasSize(4));
Expand Down Expand Up @@ -154,17 +153,18 @@ public void testComplexValue() {
*/
@Test
public void testConfigKeyEscapedNameComplex() {
String JSON = ""
+ "{\n"
+ " \"oracle.com\": {\n"
+ " \"prop1\": \"val1\",\n"
+ " \"prop2\": \"val2\"\n"
+ " },\n"
+ " \"oracle\": {\n"
+ " \"com\": \"1\",\n"
+ " \"cz\": \"2\"\n"
+ " }\n"
+ "}\n";
String JSON = """
{
"oracle.com": {
"prop1": "val1",
"prop2": "val2"
},
"oracle": {
"com": "1",
"cz": "2"
}
}
""";

Config config = Config
.builder(ConfigSources.create(JSON, HoconConfigParser.MEDIA_TYPE_APPLICATION_JSON))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2022 Oracle and/or its affiliates.
* Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -39,8 +39,10 @@ public class JdbcStatementParserTest {
@Test
void testStatementWithNoParameter() {
String stmtIn =
"SELECT *, 2 FROM table\r\n" +
" WHERE name LIKE 'a?e%'\n";
"""
SELECT *, 2 FROM table\r
WHERE name LIKE 'a?e%'
""";
Parser parser = new Parser(stmtIn);
String stmtOut = parser.convert();
List<String> names = parser.namesOrder();
Expand All @@ -55,13 +57,15 @@ void testStatementWithNoParameter() {
@Test
void testStatementWithParameters() {
String stmtIn =
"SELECT t.*, 'first' FROM table t\r\n" +
" WHERE name = :my_n4m3\n" +
" AND age > :ag3";
"""
SELECT t.*, 'first' FROM table t\r
WHERE name = :my_n4m3
AND age > :ag3""";
String stmtExp =
"SELECT t.*, 'first' FROM table t\r\n" +
" WHERE name = ?\n" +
" AND age > ?";
"""
SELECT t.*, 'first' FROM table t\r
WHERE name = ?
AND age > ?""";
Parser parser = new Parser(stmtIn);
String stmtOut = parser.convert();
List<String> names = parser.namesOrder();
Expand All @@ -76,17 +80,19 @@ void testStatementWithParameters() {
@Test
void testStatementWithParametersInMultiLineCommnet() {
String stmtIn =
"SELECT t.*, 'first' FROM table t /* Parameter for name is :n4me\r\n" +
" and for age is :ag3 */\n" +
" WHERE address IS NULL\r\n" +
" AND name = :n4m3\n" +
" AND age > :ag3";
"""
SELECT t.*, 'first' FROM table t /* Parameter for name is :n4me\r
and for age is :ag3 */
WHERE address IS NULL\r
AND name = :n4m3
AND age > :ag3""";
String stmtExp =
"SELECT t.*, 'first' FROM table t /* Parameter for name is :n4me\r\n" +
" and for age is :ag3 */\n" +
" WHERE address IS NULL\r\n" +
" AND name = ?\n" +
" AND age > ?";
"""
SELECT t.*, 'first' FROM table t /* Parameter for name is :n4me\r
and for age is :ag3 */
WHERE address IS NULL\r
AND name = ?
AND age > ?""";
Parser parser = new Parser(stmtIn);
String stmtOut = parser.convert();
List<String> names = parser.namesOrder();
Expand All @@ -101,15 +107,17 @@ void testStatementWithParametersInMultiLineCommnet() {
@Test
void testStatementWithParametersInSingleLineCommnet() {
String stmtIn =
"SELECT t.*, 'first' FROM table t -- Parameter for name is :n4me\r\r\n" +
" WHERE address IS NULL\r\n" +
" AND name = :myN4m3\n" +
" AND age > :ag3";
"""
SELECT t.*, 'first' FROM table t -- Parameter for name is :n4me\r\r
WHERE address IS NULL\r
AND name = :myN4m3
AND age > :ag3""";
String stmtExp =
"SELECT t.*, 'first' FROM table t -- Parameter for name is :n4me\r\r\n" +
" WHERE address IS NULL\r\n" +
" AND name = ?\n" +
" AND age > ?";
"""
SELECT t.*, 'first' FROM table t -- Parameter for name is :n4me\r\r
WHERE address IS NULL\r
AND name = ?
AND age > ?""";
Parser parser = new Parser(stmtIn);
String stmtOut = parser.convert();
List<String> names = parser.namesOrder();
Expand Down Expand Up @@ -144,12 +152,14 @@ void testStatementWithValidandinvalidParameters() {

@Test
void testStatementWithUnderscores() {
String stmtIn = "INSERT INTO example (created_at)\n" +
" VALUES (:created_at)\n" +
" RETURNING example_id, created_at;";
String stmtExp = "INSERT INTO example (created_at)\n" +
" VALUES (?)\n" +
" RETURNING example_id, created_at;";
String stmtIn = """
INSERT INTO example (created_at)
VALUES (:created_at)
RETURNING example_id, created_at;""";
String stmtExp = """
INSERT INTO example (created_at)
VALUES (?)
RETURNING example_id, created_at;""";
Parser parser = new Parser(stmtIn);
String stmtOut = parser.convert();
List<String> names = parser.namesOrder();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019, 2021 Oracle and/or its affiliates.
* Copyright (c) 2019, 2023 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -74,16 +74,18 @@ public void update(Routing.Rules rules) {
*/
private void index(ServerRequest request, ServerResponse response) {
response.headers().contentType(MediaType.TEXT_PLAIN);
response.send("Pokemon JDBC Example:\n"
+ " GET /type - List all pokemon types\n"
+ " GET /pokemon - List all pokemons\n"
+ " GET /pokemon/{id} - Get pokemon by id\n"
+ " GET /pokemon/name/{name} - Get pokemon by name\n"
+ " POST /pokemon - Insert new pokemon:\n"
+ " {\"id\":<id>,\"name\":<name>,\"type\":<type>}\n"
+ " PUT /pokemon - Update pokemon\n"
+ " {\"id\":<id>,\"name\":<name>,\"type\":<type>}\n"
+ " DELETE /pokemon/{id} - Delete pokemon with specified id\n");
response.send("""
Pokemon JDBC Example:
GET /type - List all pokemon types
GET /pokemon - List all pokemons
GET /pokemon/{id} - Get pokemon by id
GET /pokemon/name/{name} - Get pokemon by name
POST /pokemon - Insert new pokemon:
{"id":<id>,"name":<name>,"type":<type>}
PUT /pokemon - Update pokemon
{"id":<id>,"name":<name>,"type":<type>}
DELETE /pokemon/{id} - Delete pokemon with specified id
""");
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,46 +83,47 @@ private String getConnectionString(String path) {
return "http://localhost:" + server.port() + path;
}

static final String FIXTURE = ""
+ "CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})\n"
+ "CREATE (Keanu:Person {name:'Keanu Reeves', born:1964})\n"
+ "CREATE (Carrie:Person {name:'Carrie-Anne Moss', born:1967})\n"
+ "CREATE (Laurence:Person {name:'Laurence Fishburne', born:1961})\n"
+ "CREATE (Hugo:Person {name:'Hugo Weaving', born:1960})\n"
+ "CREATE (LillyW:Person {name:'Lilly Wachowski', born:1967})\n"
+ "CREATE (LanaW:Person {name:'Lana Wachowski', born:1965})\n"
+ "CREATE (JoelS:Person {name:'Joel Silver', born:1952})\n"
+ "CREATE (KevinB:Person {name:'Kevin Bacon', born:1958})\n"
+ "CREATE\n"
+ "(Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix),\n"
+ "(Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrix),\n"
+ "(Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrix),\n"
+ "(Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrix),\n"
+ "(LillyW)-[:DIRECTED]->(TheMatrix),\n"
+ "(LanaW)-[:DIRECTED]->(TheMatrix),\n"
+ "(JoelS)-[:PRODUCED]->(TheMatrix)\n"
+ "\n"
+ "CREATE (Emil:Person {name:\"Emil Eifrem\", born:1978})\n"
+ "CREATE (Emil)-[:ACTED_IN {roles:[\"Emil\"]}]->(TheMatrix)\n"
+ "\n"
+ "CREATE (TheMatrixReloaded:Movie {title:'The Matrix Reloaded', released:2003, tagline:'Free your mind'})\n"
+ "CREATE\n"
+ "(Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrixReloaded),\n"
+ "(Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrixReloaded),\n"
+ "(Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrixReloaded),\n"
+ "(Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrixReloaded),\n"
+ "(LillyW)-[:DIRECTED]->(TheMatrixReloaded),\n"
+ "(LanaW)-[:DIRECTED]->(TheMatrixReloaded),\n"
+ "(JoelS)-[:PRODUCED]->(TheMatrixReloaded)\n"
+ "\n"
+ "CREATE (TheMatrixRevolutions:Movie {title:'The Matrix Revolutions', released:2003, tagline:'Everything that has a beginning has an end'})\n"
+ "CREATE\n"
+ "(Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrixRevolutions),\n"
+ "(Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrixRevolutions),\n"
+ "(Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrixRevolutions),\n"
+ "(KevinB)-[:ACTED_IN {roles:['Unknown']}]->(TheMatrixRevolutions),\n"
+ "(Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrixRevolutions),\n"
+ "(LillyW)-[:DIRECTED]->(TheMatrixRevolutions),\n"
+ "(LanaW)-[:DIRECTED]->(TheMatrixRevolutions),\n"
+ "(JoelS)-[:PRODUCED]->(TheMatrixRevolutions)\n";
static final String FIXTURE = """
CREATE (TheMatrix:Movie {title:'The Matrix', released:1999, tagline:'Welcome to the Real World'})
CREATE (Keanu:Person {name:'Keanu Reeves', born:1964})
CREATE (Carrie:Person {name:'Carrie-Anne Moss', born:1967})
CREATE (Laurence:Person {name:'Laurence Fishburne', born:1961})
CREATE (Hugo:Person {name:'Hugo Weaving', born:1960})
CREATE (LillyW:Person {name:'Lilly Wachowski', born:1967})
CREATE (LanaW:Person {name:'Lana Wachowski', born:1965})
CREATE (JoelS:Person {name:'Joel Silver', born:1952})
CREATE (KevinB:Person {name:'Kevin Bacon', born:1958})
CREATE
(Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrix),
(Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrix),
(Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrix),
(Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrix),
(LillyW)-[:DIRECTED]->(TheMatrix),
(LanaW)-[:DIRECTED]->(TheMatrix),
(JoelS)-[:PRODUCED]->(TheMatrix)
CREATE (Emil:Person {name:"Emil Eifrem", born:1978})
CREATE (Emil)-[:ACTED_IN {roles:["Emil"]}]->(TheMatrix)
CREATE (TheMatrixReloaded:Movie {title:'The Matrix Reloaded', released:2003, tagline:'Free your mind'})
CREATE
(Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrixReloaded),
(Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrixReloaded),
(Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrixReloaded),
(Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrixReloaded),
(LillyW)-[:DIRECTED]->(TheMatrixReloaded),
(LanaW)-[:DIRECTED]->(TheMatrixReloaded),
(JoelS)-[:PRODUCED]->(TheMatrixReloaded)
CREATE (TheMatrixRevolutions:Movie {title:'The Matrix Revolutions', released:2003, tagline:'Everything that has a beginning has an end'})
CREATE
(Keanu)-[:ACTED_IN {roles:['Neo']}]->(TheMatrixRevolutions),
(Carrie)-[:ACTED_IN {roles:['Trinity']}]->(TheMatrixRevolutions),
(Laurence)-[:ACTED_IN {roles:['Morpheus']}]->(TheMatrixRevolutions),
(KevinB)-[:ACTED_IN {roles:['Unknown']}]->(TheMatrixRevolutions),
(Hugo)-[:ACTED_IN {roles:['Agent Smith']}]->(TheMatrixRevolutions),
(LillyW)-[:DIRECTED]->(TheMatrixRevolutions),
(LanaW)-[:DIRECTED]->(TheMatrixRevolutions),
(JoelS)-[:PRODUCED]->(TheMatrixRevolutions)
""";
}
Loading

0 comments on commit 835d429

Please sign in to comment.