Skip to content

Commit

Permalink
missing_params_fix
Browse files Browse the repository at this point in the history
  • Loading branch information
deepakarora3 committed Feb 15, 2024
1 parent a2a5ab3 commit 2f6aa2c
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 23 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

<groupId>com.americanexpress.unify.jdocs</groupId>
<artifactId>unify-jdocs</artifactId>
<version>1.6.0</version>
<version>1.7.0</version>
<packaging>jar</packaging>

<name>unify-jdocs</name>
Expand Down
2 changes: 1 addition & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ JDocs is available as a jar file in Maven central with the following latest Mave
````pom
<groupId>com.americanexpress.unify.jdocs</groupId>
<artifactId>unify-jdocs</artifactId>
<version>1.6.0</version>
<version>1.7.0</version>
````

---
Expand Down
4 changes: 0 additions & 4 deletions src/main/java/com/americanexpress/unify/jdocs/JDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -1403,10 +1403,6 @@ protected final void setValue(String path, List<Token> tokenList, Object value)
}

public static String getStaticPath(String path, String... vargs) {
if (vargs.length == 0) {
return path;
}

int size = path.length();
StringBuffer sb = new StringBuffer();
int counter = 0;
Expand Down
68 changes: 51 additions & 17 deletions src/test/java/com/americanexpress/unify/jdocs/DocumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,7 @@ void testValidateAtReadWriteOnly() {
d = getTypedDocument("sample_23_model", "/jdocs/sample_23.json");
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

d = getTypedDocument("sample_23_model", "/jdocs/sample_23.json", true);
Expand All @@ -827,14 +827,14 @@ void testValidateAtReadWriteOnly() {
d.getString("$.phone_cell");
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

try {
d.getString("$.giberish");
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

String s = d.getString("$.first_name");
Expand All @@ -855,14 +855,14 @@ void testValidateAtReadWriteOnly() {
d.validate("sample_23_model");
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

try {
d.setType("sample_23_model");
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

d.setType("sample_23_model", true);
Expand All @@ -871,7 +871,7 @@ void testValidateAtReadWriteOnly() {
d.validate("sample_23_model");
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

// we now set the default to be true
Expand All @@ -883,14 +883,14 @@ void testValidateAtReadWriteOnly() {
d.validate("sample_23_model"); // will fail validation here
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

try {
d = getTypedDocument("sample_23_model", "/jdocs/sample_23.json"); // will fail validation here
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

d = getTypedDocument("sample_23_model", "/jdocs/sample_23.json", true); // this should pass
Expand Down Expand Up @@ -1297,7 +1297,7 @@ void testValidation() {
d = getTypedDocument("sample_23_model", "/jdocs/sample_23.json", CONSTS_JDOCS.VALIDATION_TYPE.ALL_DATA_PATHS);
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

// test - doc construction will succeed but read of field will fail
Expand All @@ -1306,7 +1306,7 @@ void testValidation() {
d.getString("$.phone_cell");
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

// test - doc construction will succeed but read of field will fail
Expand All @@ -1315,7 +1315,7 @@ void testValidation() {
d.getString("$.phone_cell");
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

// valid test
Expand All @@ -1342,7 +1342,7 @@ void testValidation() {
d.setType("sample_23_model");
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

// test only model paths - will succeed
Expand All @@ -1353,7 +1353,7 @@ void testValidation() {
d.validateAllPaths("sample_23_model");
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

// we now set the default to only at read write
Expand All @@ -1365,15 +1365,15 @@ void testValidation() {
d.validateAllPaths("sample_23_model"); // will fail validation here
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}
d.validateModelPaths("sample_23_model"); // will succeed

try {
d = getTypedDocument("sample_23_model", "/jdocs/sample_23.json"); // will fail validation here
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

d = getTypedDocument("sample_23_model", "/jdocs/sample_23.json", CONSTS_JDOCS.VALIDATION_TYPE.ONLY_MODEL_PATHS); // this should pass
Expand All @@ -1391,15 +1391,15 @@ void testValidation() {
d.validateAllPaths("sample_23_model"); // will fail validation here
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}
d.validateModelPaths("sample_23_model"); // will succeed

try {
d = getTypedDocument("sample_23_model", "/jdocs/sample_23.json"); // will fail validation here
assert (false);
}
catch (UnifyException e) {
catch (Exception e) {
}

d = getTypedDocument("sample_23_model", "/jdocs/sample_23.json", CONSTS_JDOCS.VALIDATION_TYPE.ONLY_MODEL_PATHS); // this should pass
Expand All @@ -1409,4 +1409,38 @@ void testValidation() {
JDocument.init(CONSTS_JDOCS.VALIDATION_TYPE.ALL_DATA_PATHS);
}

@Test
void testMissingParams() {
Document d = new JDocument();

try {
String s = d.getString("$.names[name=%].first_name");
assert (false);
}
catch (Exception e) {
}

try {
String s = d.getString("$.names[name=%].other[number=%].first_name");
assert (false);
}
catch (Exception e) {
}

try {
String s = d.getString("$.names[name=%].other[number=%].first_name", "Deepak");
assert (false);
}
catch (Exception e) {
}

try {
String s = d.getString("$.names[%].first_name");
assert (false);
}
catch (Exception e) {
}

}

}

0 comments on commit 2f6aa2c

Please sign in to comment.