Skip to content

Commit a5d7e2b

Browse files
committed
param binding and test - bug fix;
1 parent 1476587 commit a5d7e2b

10 files changed

Lines changed: 47 additions & 9 deletions

src/main/java/act/Destroyable.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,9 @@ public static void tryDestroy(Object o, Class<? extends Annotation> scope) {
9898
}
9999

100100
private static boolean inScope(Object o, Class<? extends Annotation> scope) {
101+
if (null == o) {
102+
return false;
103+
}
101104
if (null == scope || scope == ApplicationScoped.class) {
102105
return true;
103106
}
@@ -106,6 +109,7 @@ private static boolean inScope(Object o, Class<? extends Annotation> scope) {
106109
return true;
107110
}
108111
if (scope == SessionScoped.class) {
112+
// RequestScoped is always inside Session scope
109113
return c.isAnnotationPresent(RequestScoped.class);
110114
}
111115
return false;

src/main/java/act/di/param/StringValueResolverValueLoader.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ public StringValueResolverValueLoader(ParamKey key, StringValueResolver<?> resol
2222

2323
@Override
2424
public Object load(Object bean, ActContext context, boolean noDefaultValue) {
25+
if (paramKey.isSimple()) {
26+
String value = context.paramVal(paramKey.name());
27+
Object obj = (null == value) ? null : stringValueResolver.resolve(value);
28+
return (null == obj) && !noDefaultValue ? defVal : obj;
29+
}
2530
ParamTree paramTree = ParamValueLoaderManager.paramTree();
2631
if (null != paramTree) {
2732
return load(paramTree);
@@ -34,7 +39,7 @@ public Object load(Object bean, ActContext context, boolean noDefaultValue) {
3439
}
3540
}
3641
Object obj = load(context, encode);
37-
if (null == obj && !paramKey.isSimple()) {
42+
if (null == obj) {
3843
HttpRequestParamEncode encode0 = encode;
3944
do {
4045
encode0 = HttpRequestParamEncode.next(encode0);

testapp/src/main/java/testapp/model/ModelBase.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
import act.Act;
44
import org.osgl.util.KVStore;
55

6+
import java.util.UUID;
7+
68
public abstract class ModelBase {
79

810
private String id;
911

1012
private KVStore kv;
1113

1214
public ModelBase() {
13-
id = Act.cuid();
15+
id = UUID.randomUUID().toString();
1416
kv = new KVStore();
1517
}
1618

testapp/src/test/java/testapp/endpoint/ParamEncoding.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ public enum ParamEncoding {
112112
FOUR() {
113113
@Override
114114
public List<$.T2<String, Object>> encode(String paramName, List<?> elements) {
115+
E.illegalStateIf(paramName.contains("."), "Param encoding four does not support param name with \".\" inside");
115116
List<$.T2<String, Object>> retList = C.newList();
116117
for (int i = 0; i < elements.size(); ++i) {
117118
retList.add($.T2(S.fmt("%s.%d", paramName, i), elements.get(i)));
@@ -121,6 +122,7 @@ public enum ParamEncoding {
121122

122123
@Override
123124
public List<$.T2<String, Object>> encode(String paramName, Map<?, ?> elements) {
125+
E.illegalStateIf(paramName.contains("."), "Param encoding four does not support param name with \".\" inside");
124126
List<$.T2<String, Object>> retList = C.newList();
125127
if (null != elements) {
126128
for (Map.Entry<?, ?> entry : elements.entrySet()) {

testapp/src/test/java/testapp/endpoint/binding/map/DoubleTypeMapValBindingTest.java

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package testapp.endpoint.binding.map;
22

3+
import org.junit.Ignore;
34
import org.osgl.util.C;
45

56
import java.util.Map;
@@ -11,7 +12,18 @@ public DoubleTypeMapValBindingTest() {
1112

1213
@Override
1314
public Map<String, Double> nonEmptyMap() {
14-
return C.map("a", Double.MAX_VALUE, "b", Double.MIN_VALUE, "c", 0.02);
15+
return C.map("a", Double.MAX_VALUE, "b", Double.MIN_VALUE, "c", 0.02d);
1516
}
1617

18+
@Ignore
19+
@Override
20+
public void testKeyTypedNonEmptyMapGetFour() throws Exception {
21+
// double does not support param encoding type Four
22+
}
23+
24+
@Ignore
25+
@Override
26+
public void testKeyTypedNonEmptyMapPostFour() throws Exception {
27+
// double does not support param encoding type Four
28+
}
1729
}

testapp/src/test/java/testapp/endpoint/binding/map/FloatTypeMapValBindingTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package testapp.endpoint.binding.map;
22

3+
import org.junit.Ignore;
34
import org.osgl.util.C;
45

56
import java.util.Map;
@@ -14,4 +15,16 @@ public Map<String, Float> nonEmptyMap() {
1415
return C.map("a", Float.MAX_VALUE, "b", Float.MIN_VALUE, "c", 0.02f);
1516
}
1617

18+
@Ignore
19+
@Override
20+
public void testKeyTypedNonEmptyMapGetFour() throws Exception {
21+
// float does not support param encoding type Four
22+
}
23+
24+
@Ignore
25+
@Override
26+
public void testKeyTypedNonEmptyMapPostFour() throws Exception {
27+
// float does not support param encoding type Four
28+
}
29+
1730
}

testapp/src/test/java/testapp/endpoint/binding/map/LongTypeMapValBindingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public LongTypeMapValBindingTest() {
1111

1212
@Override
1313
public Map<String, Long> nonEmptyMap() {
14-
return C.map("a", Long.MAX_VALUE, "b", Long.MIN_VALUE, "c", 0);
14+
return C.map("a", Long.MAX_VALUE, "b", Long.MIN_VALUE, "c", 0L);
1515
}
1616

1717
}

testapp/src/test/java/testapp/endpoint/binding/map/ShortTypeMapValBindingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public ShortTypeMapValBindingTest() {
1111

1212
@Override
1313
public Map<String, Short> nonEmptyMap() {
14-
return C.map("a", Short.MAX_VALUE, "b", Short.MIN_VALUE, "c", 0);
14+
return C.map("a", Short.MAX_VALUE, "b", Short.MIN_VALUE, "c", (short)0);
1515
}
1616

1717
}

testapp/src/test/java/testapp/endpoint/binding/map/SimpleTypeMapValBindingTestBase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public final void testKeyTypedNonEmptyMapGetTwo() throws Exception {
173173
}
174174

175175
@Test
176-
public final void testKeyTypedNonEmptyMapGetFour() throws Exception {
176+
public void testKeyTypedNonEmptyMapGetFour() throws Exception {
177177
_verify(ek(), path_k, keyTypedNonEmptyMap(), RequestMethod.GET, FOUR);
178178
}
179179

@@ -183,7 +183,7 @@ public final void testKeyTypedNonEmptyMapPostTwo() throws Exception {
183183
}
184184

185185
@Test
186-
public final void testKeyTypedNonEmptyMapPostFour() throws Exception {
186+
public void testKeyTypedNonEmptyMapPostFour() throws Exception {
187187
_verify(ek(), path_k, keyTypedNonEmptyMap(), RequestMethod.POST_FORM_DATA, FOUR);
188188
}
189189

testapp/src/test/java/testapp/endpoint/binding/single/DoubleActionParameterBindingTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,13 @@ protected Double nonNullValue() {
2020

2121
@Override
2222
protected String primitiveDefValueStr() {
23-
return "0";
23+
return "0.0";
2424
}
2525

2626
@Override
2727
protected Object outOfScopeValue() {
2828
BigDecimal dec = BigDecimal.valueOf(Double.MAX_VALUE);
29-
dec = dec.add(BigDecimal.ONE);
29+
dec = dec.add(dec);
3030
return dec;
3131
}
3232
}

0 commit comments

Comments
 (0)