forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Qute: improve the key/property/method "not found" error message
- which may occur at runtime
- Loading branch information
Showing
11 changed files
with
188 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
independent-projects/qute/core/src/main/java/io/quarkus/qute/MapperMapWrapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.quarkus.qute; | ||
|
||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
final class MapperMapWrapper implements Mapper { | ||
|
||
private final Map<String, ?> map; | ||
|
||
MapperMapWrapper(Map<String, ?> map) { | ||
this.map = map; | ||
} | ||
|
||
@Override | ||
public boolean appliesTo(String key) { | ||
return map.containsKey(key); | ||
} | ||
|
||
@Override | ||
public Object get(String key) { | ||
return map.get(key); | ||
} | ||
|
||
@Override | ||
public Set<String> mappedKeys() { | ||
return map.keySet(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
independent-projects/qute/core/src/test/java/io/quarkus/qute/NotFoundResultTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
package io.quarkus.qute; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.CompletionStage; | ||
import java.util.stream.Collectors; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import io.quarkus.qute.Results.NotFound; | ||
|
||
public class NotFoundResultTest { | ||
|
||
@Test | ||
public void testAsMessage() { | ||
assertEquals("Key \"foo\" not found in the template data map with keys []", | ||
NotFound.from(evalContext(Map.of(TemplateInstanceBase.DATA_MAP_KEY, true))).asMessage()); | ||
assertEquals("Key \"foo\" not found in the map with keys [baz]", | ||
NotFound.from(evalContext(Map.of("baz", true))).asMessage()); | ||
assertEquals("Property \"foo\" not found on the base object \"java.lang.Boolean\"", | ||
NotFound.from(evalContext(Boolean.TRUE)).asMessage()); | ||
assertEquals("Method \"foo(param)\" not found on the base object \"java.lang.Boolean\"", | ||
NotFound.from(evalContext(Boolean.TRUE, "param")).asMessage()); | ||
assertEquals("Key \"foo\" not found in the map with keys [baz]", | ||
NotFound.from(evalContext(Mapper.wrap(Map.of("baz", false)))).asMessage()); | ||
} | ||
|
||
EvalContext evalContext(Object base, Object... params) { | ||
return new EvalContext() { | ||
|
||
@Override | ||
public List<Expression> getParams() { | ||
return Arrays.stream(params).map(p -> ExpressionImpl.from(p.toString())).collect(Collectors.toList()); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return "foo"; | ||
} | ||
|
||
@Override | ||
public Object getBase() { | ||
return base; | ||
} | ||
|
||
@Override | ||
public Object getAttribute(String key) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public CompletionStage<Object> evaluate(Expression expression) { | ||
return null; | ||
} | ||
|
||
@Override | ||
public CompletionStage<Object> evaluate(String expression) { | ||
return null; | ||
} | ||
}; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters