Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

polish #532

Merged
merged 7 commits into from
Jan 4, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ void testPassword() throws Exception {
.params(params))
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath("sub", "livk").exists())
.andExpect(jsonPath("iss", "http://localhost:9000").exists())
.andExpect(jsonPath("token_type", "Bearer").exists())
.andExpect(jsonPath("client_id", "livk-client").exists())
.andExpect(jsonPath("sub").value("livk"))
.andExpect(jsonPath("iss").value("http://localhost"))
.andExpect(jsonPath("token_type").value("Bearer"))
.andExpect(jsonPath("client_id").value("livk-client"))
.andReturn()
.getResponse()
.getContentAsString();
Expand All @@ -93,10 +93,10 @@ void testSms() throws Exception {
.params(params))
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath("sub", "livk").exists())
.andExpect(jsonPath("iss", "http://localhost:9000").exists())
.andExpect(jsonPath("token_type", "Bearer").exists())
.andExpect(jsonPath("client_id", "livk-client").exists())
.andExpect(jsonPath("sub").value("livk"))
.andExpect(jsonPath("iss").value("http://localhost"))
.andExpect(jsonPath("token_type").value("Bearer"))
.andExpect(jsonPath("client_id").value("livk-client"))
.andReturn()
.getResponse()
.getContentAsString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ void infoGet() throws Exception {
mockMvc.perform(get("/info").param("id", encoding).header("id", encoding))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("id.paramId", encoding).exists())
.andExpect(jsonPath("id.headerId", encoding).exists());
.andExpect(jsonPath("id.paramId").value(encoding))
.andExpect(jsonPath("id.headerId").value(encoding));
}

@Test
Expand All @@ -67,8 +67,8 @@ void infoPost() throws Exception {
mockMvc.perform(post("/info").contentType(MediaType.APPLICATION_JSON).content(json))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("body.paramId", encoding).exists())
.andExpect(jsonPath("body.headerId", encoding).exists());
.andExpect(jsonPath("body.paramId").value(encoding))
.andExpect(jsonPath("body.headerId").value(encoding));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ void testGetById() throws Exception {
mockMvc.perform(get("/rest/api/user/{id}", 1))
.andDo(print())
.andExpect(status().is2xxSuccessful())
.andExpect(jsonPath("username", "root").exists())
.andExpect(jsonPath("password", "root").exists())
.andExpect(jsonPath("age", 18).exists());
.andExpect(jsonPath("username").value("root"))
.andExpect(jsonPath("password").value("root"))
.andExpect(jsonPath("age").value(18));
}

@Order(1)
Expand Down Expand Up @@ -102,9 +102,9 @@ void testAuth() throws Exception {
mockMvc.perform(get("/rest/api/user/search/auth").param("name", "admin").param("pwd", "admin"))
.andDo(print())
.andExpect(status().is2xxSuccessful())
.andExpect(jsonPath("username", "admin").exists())
.andExpect(jsonPath("password", "admin").exists())
.andExpect(jsonPath("age", 19).exists());
.andExpect(jsonPath("username").value("admin"))
.andExpect(jsonPath("password").value("admin"))
.andExpect(jsonPath("age").value(19));
}

@Order(5)
Expand All @@ -113,13 +113,13 @@ void testList() throws Exception {
mockMvc.perform(get("/rest/api/user"))
.andDo(print())
.andExpect(status().is2xxSuccessful())
.andExpect(jsonPath("_embedded.users[0].username", "admin").exists())
.andExpect(jsonPath("_embedded.users[0].password", "admin").exists())
.andExpect(jsonPath("_embedded.users[0].age", 19).exists())
.andExpect(jsonPath("page.size", 20).exists())
.andExpect(jsonPath("page.totalElements", 1).exists())
.andExpect(jsonPath("page.totalPages", 1).exists())
.andExpect(jsonPath("page.number", 0).exists());
.andExpect(jsonPath("_embedded.users[0].username").value("admin"))
.andExpect(jsonPath("_embedded.users[0].password").value("admin"))
.andExpect(jsonPath("_embedded.users[0].age").value(19))
.andExpect(jsonPath("page.size").value(20))
.andExpect(jsonPath("page.totalElements").value(1))
.andExpect(jsonPath("page.totalPages").value(1))
.andExpect(jsonPath("page.number").value(0));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ void test() throws Exception {
mockMvc.perform(get("/v3/api-docs"))
.andDo(print())
.andExpect(MockMvcResultMatchers.status().isOk())
.andExpect(jsonPath("openapi", "3.0.1").exists());
.andExpect(jsonPath("openapi").value("3.0.1"));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void init() throws Exception {
.content(JsonMapperUtils.writeValueAsString(body)))
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath("code", "200").exists())
.andExpect(jsonPath("code").value(200))
.andReturn()
.getResponse();
token = "Bearer "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
/**
* @author livk
*/
public class RedissonPropertyEditorRegistrar implements PropertyEditorRegistrar {
final class RedissonPropertyEditorRegistrar implements PropertyEditorRegistrar {

private static final Set<Class<?>> supportType = Set.of(Config.class, AddressResolverGroupFactory.class,
Codec.class, RedissonNodeInitializer.class, LoadBalancer.class, NatMapper.class, NameMapper.class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ void testResult() throws Exception {
mockMvc.perform(get("/shop/result"))
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath("curator.buyCount", 10).exists())
.andExpect(jsonPath("curator.buySucCount", 10).exists())
.andExpect(jsonPath("curator.num", 480).exists());
.andExpect(jsonPath("curator.buyCount").value(10))
.andExpect(jsonPath("curator.buySucCount").value(10))
.andExpect(jsonPath("curator.num").value(480));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ void testResult() throws Exception {
mockMvc.perform(get("/shop/result"))
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath("redisson.buyCount", 10).exists())
.andExpect(jsonPath("redisson.buySucCount", 10).exists())
.andExpect(jsonPath("redisson.num", 480).exists());
.andExpect(jsonPath("redisson.buyCount").value(10))
.andExpect(jsonPath("redisson.buySucCount").value(10))
.andExpect(jsonPath("redisson.num").value(480));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@ void getTest() throws Exception {
mockMvc.perform(get("/get"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("spring-boot-version", SpringBootVersion.getVersion()).exists())
.andExpect(jsonPath("spring-version", SpringVersion.getVersion()).exists())
.andExpect(jsonPath("java-version", System.getProperty("java.version")).exists());
.andExpect(jsonPath("spring-boot-version").value(SpringBootVersion.getVersion()))
.andExpect(jsonPath("spring-version").value(SpringVersion.getVersion()))
.andExpect(jsonPath("java-version").value(System.getProperty("java.version")));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,19 @@ void testList() throws Exception {
mockMvc.perform(get("/user"))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("customize[0:2].username", "livk1", "livk2", "livk3").exists())
.andExpect(jsonPath("customize[0:2].type", "1", "2", "3").exists())
.andExpect(jsonPath("customize[0].username").value("livk1"))
.andExpect(jsonPath("customize[1].username").value("livk2"))
.andExpect(jsonPath("customize[2].username").value("livk3"))
.andExpect(jsonPath("customize[0].type").value(1))
.andExpect(jsonPath("customize[1].type").value(2))
.andExpect(jsonPath("customize[2].type").value(3))
.andExpect(jsonPath("customize[0:2].createTime").exists())
.andExpect(jsonPath("spring[0:2].username", "livk1", "livk2", "livk3").exists())
.andExpect(jsonPath("spring[0:2].type", "1", "2", "3").exists())
.andExpect(jsonPath("spring[0].username").value("livk1"))
.andExpect(jsonPath("spring[1].username").value("livk2"))
.andExpect(jsonPath("spring[2].username").value("livk3"))
.andExpect(jsonPath("spring[0].type").value(1))
.andExpect(jsonPath("spring[1].type").value(2))
.andExpect(jsonPath("spring[2].type").value(3))
.andExpect(jsonPath("spring[0:2].createTime").exists());
}

Expand All @@ -60,11 +68,11 @@ void testGetById() throws Exception {
mockMvc.perform(get("/user/{id}", i))
.andDo(print())
.andExpect(status().isOk())
.andExpect(jsonPath("customize.username", "livk" + i).exists())
.andExpect(jsonPath("customize.type", i).exists())
.andExpect(jsonPath("customize.username").value("livk" + i))
.andExpect(jsonPath("customize.type").value(i))
.andExpect(jsonPath("customize.createTime").exists())
.andExpect(jsonPath("spring.username", "livk" + i).exists())
.andExpect(jsonPath("spring.type", i).exists())
.andExpect(jsonPath("spring.username").value("livk" + i))
.andExpect(jsonPath("spring.type").value(i))
.andExpect(jsonPath("spring.createTime").exists());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void testGetById() throws Exception {
mockMvc.perform(get("/user/{id}", id))
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath("id", id).exists())
.andExpect(jsonPath("id").value(id))
.andExpect(jsonPath("insertTime").isNotEmpty())
.andExpect(jsonPath("updateTime").isNotEmpty());
}
Expand Down Expand Up @@ -109,9 +109,9 @@ void testList() throws Exception {
mockMvc.perform(get("/user"))
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath("list.[*].id", id).exists())
.andExpect(jsonPath("pageNum", 1).exists())
.andExpect(jsonPath("pageSize", 10).exists());
.andExpect(jsonPath("list.[*].id").value(id))
.andExpect(jsonPath("pageNum").value(1))
.andExpect(jsonPath("pageSize").value(10));
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,35 @@ void testList() throws Exception {
mockMvc.perform(get("/student"))
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath("[0:9].name", "livk-0", "livk-1", "livk-2", "livk-3", "livk-4", "livk-5", "livk-6",
"livk-7", "livk-8", "livk-9")
.exists());
.andExpect(jsonPath("[0].name").value("livk-0"))
.andExpect(jsonPath("[1].name").value("livk-1"))
.andExpect(jsonPath("[2].name").value("livk-2"))
.andExpect(jsonPath("[3].name").value("livk-3"))
.andExpect(jsonPath("[4].name").value("livk-4"))
.andExpect(jsonPath("[5].name").value("livk-5"))
.andExpect(jsonPath("[6].name").value("livk-6"))
.andExpect(jsonPath("[7].name").value("livk-7"))
.andExpect(jsonPath("[8].name").value("livk-8"))
.andExpect(jsonPath("[9].name").value("livk-9"));

mockMvc.perform(get("/student").param("query", "@class:{1班}"))
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath("[0].name", "livk-0").exists());
.andExpect(jsonPath("[0].name").value("livk-0"));

mockMvc.perform(get("/student").param("query", "livk"))
.andExpect(status().isOk())
.andDo(print())
.andExpect(jsonPath("[0:9].name", "livk-0", "livk-1", "livk-2", "livk-3", "livk-4", "livk-5", "livk-6",
"livk-7", "livk-8", "livk-9")
.exists());
.andExpect(jsonPath("[0].name").value("livk-0"))
.andExpect(jsonPath("[1].name").value("livk-1"))
.andExpect(jsonPath("[2].name").value("livk-2"))
.andExpect(jsonPath("[3].name").value("livk-3"))
.andExpect(jsonPath("[4].name").value("livk-4"))
.andExpect(jsonPath("[5].name").value("livk-5"))
.andExpect(jsonPath("[6].name").value("livk-6"))
.andExpect(jsonPath("[7].name").value("livk-7"))
.andExpect(jsonPath("[8].name").value("livk-8"))
.andExpect(jsonPath("[9].name").value("livk-9"));

mockMvc.perform(get("/student").param("query", "女")).andExpect(status().isOk()).andDo(print());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,31 +45,19 @@ public final <T> T evaluate(String value, Method method, Object[] args, Class<T>
return evaluate(value, context, returnType);
}

@Override
public final <T> T evaluate(String value, Method method, Object[] args, Map<String, ?> contextMap,
Class<T> returnType) {
Context context = contextFactory.merge(method, args, contextMap);
return evaluate(value, context, returnType);
}

@Override
public final String evaluate(String value, Context context) {
return evaluate(value, context, String.class);
return ExpressionResolver.super.evaluate(value, context);
}

@Override
public final String evaluate(String value, Map<String, ?> contextMap) {
return evaluate(value, contextMap, String.class);
return ExpressionResolver.super.evaluate(value, contextMap);
}

@Override
public final String evaluate(String value, Method method, Object[] args) {
return evaluate(value, method, args, String.class);
}

@Override
public final String evaluate(String value, Method method, Object[] args, Map<String, ?> contextMap) {
return evaluate(value, method, args, contextMap, String.class);
return ExpressionResolver.super.evaluate(value, method, args);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
*
* @author livk
*/
public interface Context {
public sealed interface Context permits Context.ContextImpl {

/**
* Instantiates a new Context.
Expand All @@ -46,19 +46,19 @@ static Context create(Map<String, ?> map) {
* Put all.
* @param m the m
*/
void putAll(Map<? extends String, ?> m);
Context putAll(Map<? extends String, ?> m);

/**
* Put object.
* @param key the key
* @param value the value
* @return the object
*/
Object put(String key, Object value);
Context put(String key, Object value);

Map<String, Object> asMap();

class ContextImpl implements Context {
non-sealed class ContextImpl implements Context {

private final Map<String, Object> variables;

Expand All @@ -71,13 +71,15 @@ private ContextImpl(Map<String, ?> map) {
}

@Override
public Object put(String key, Object value) {
return variables.put(key, value);
public Context put(String key, Object value) {
variables.put(key, value);
return this;
}

@Override
public void putAll(@NonNull Map<? extends String, ?> m) {
public Context putAll(@NonNull Map<? extends String, ?> m) {
variables.putAll(m);
return this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
@FunctionalInterface
public interface ContextFactory {

ContextFactory DEFAULT_FACTORY = new DefaultContextFactory();

/**
* 根据方法与参数创建上下文
* @param method the method
Expand All @@ -43,11 +45,12 @@ public interface ContextFactory {
* @param args the args
* @param expandMap the expand map
* @return the map
* @deprecated use {@link Context#putAll(Map)}
*/
@Deprecated(since = "1.4.2", forRemoval = true)
default Context merge(Method method, Object[] args, Map<String, ?> expandMap) {
Context context = create(method, args);
context.putAll(expandMap);
return context;
return context.putAll(expandMap);
}

}
Loading
Loading