Tags
Tags are used to provide additional information for the request and contribute to a better control over deduplication. A request can only contain a unique tag with same name and value.
Last updated
@GetMapping("/updateBalance")
public ResponseEntity<?> updateBalance(@RequestParam("userId") String userId,
@RequestParam("amount") BigDecimal amount,
@RequestParam("action") String action) {
// Use the CASE tag to record the branch of execution based on the action parameter.
HypertestAgent.addTag("action", action, EnumManager.TagType.CASE);
// Fetch the current balance for the user
BigDecimal currentBalance = userService.getBalance(userId);
if ("credit".equalsIgnoreCase(action)) {
// Credit branch: add the specified amount to the current balance
BigDecimal updatedBalance = currentBalance.add(amount);
userService.updateBalance(userId, updatedBalance);
return ResponseEntity.ok("User " + userId + " credited with " + amount +
". Current balance: " + updatedBalance);
} else if ("debit".equalsIgnoreCase(action)) {
// Debit branch: subtract the specified amount from the current balance
BigDecimal updatedBalance = currentBalance.subtract(amount);
userService.updateBalance(userId, updatedBalance);
return ResponseEntity.ok("User " + userId + " debited with " + amount +
". Current balance: " + updatedBalance);
} else {
// Invalid action handling
return ResponseEntity.badRequest().body("Invalid action specified.");
}
}import hypertest.javaagent.HypertestAgent;
import hypertest.javaagent.bootstrap.EnumManager;
HypertestAgent.addTag("label name", "label value", EnumManager.TagType.LABEL);import hypertest.javaagent.HypertestAgent;
HypertestAgent.addRootLabel("label name", "label value");@GetMapping("/users")
public ResponseEntity<?> getUser(@RequestParam("detailLevel") String detailLevel) {
// By adding a label with a constant value (e.g., "v1"),
// we ensure that differences in the output details don't result in separate test cases.
HypertestAgent.addTag("outputSchema", "v1", EnumManager.TagType.LABEL);
if ("full".equals(detailLevel)) {
// Full branch: returns comprehensive user details.
User fullUser = userService.getFullUser();
return ResponseEntity.ok(fullUser);
} else {
// Basic branch: returns minimal user details.
User basicUser = userService.getBasicUser();
return ResponseEntity.ok(basicUser);
}
}import hypertest.javaagent.HypertestAgent;
import hypertest.javaagent.bootstrap.EnumManager;
HypertestAgent.addTag("annotation name", "annotation value", EnumManager.TagType.ANNOTATION);import hypertest.javaagent.HypertestAgent;
HypertestAgent.addRootAnnotation("label name", "label value");@RestController
public class Controller {
@PostMapping("/create")
public ResponseEntity<?> createUser(@RequestBody User user) {
// Annotate this endpoint as belonging to the "user" group.
HypertestAgent.addTag("apiGroup", "user", EnumManager.TagType.ANNOTATION);
// Business logic for creating a user
userService.createUser(user);
return ResponseEntity.ok("User created successfully");
}
@PostMapping("/login")
public ResponseEntity<?> loginUser(@RequestBody LoginRequest loginRequest) {
// Annotate this endpoint as belonging to the "user" group.
HypertestAgent.addTag("apiGroup", "user", EnumManager.TagType.ANNOTATION);
// Business logic for logging in a user
boolean success = userService.login(loginRequest);
if (success) {
return ResponseEntity.ok("User logged in successfully");
} else {
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body("Invalid credentials");
}
}
@PostMapping("/place")
public ResponseEntity<?> placeOrder(@RequestBody Order order) {
// Annotate this endpoint as belonging to the "order" group.
HypertestAgent.addTag("apiGroup", "order", EnumManager.TagType.ANNOTATION);
// Business logic for placing an order
orderService.placeOrder(order);
return ResponseEntity.ok("Order placed successfully");
}
}