Skip to content

Commit d2f2bd2

Browse files
committed
feat: align generated Application and tests with the enhanced developer guide
1 parent 0ea4a22 commit d2f2bd2

File tree

2 files changed

+46
-25
lines changed

2 files changed

+46
-25
lines changed
Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,47 @@
11
package ${package};
22

33
import org.tinystruct.AbstractApplication;
4+
import org.tinystruct.ApplicationException;
45
import org.tinystruct.system.annotation.Action;
6+
import org.tinystruct.system.annotation.Action.Mode;
57

6-
@Action(value = "", description = "Sample tinystruct application", mode = Action.Mode.CLI)
78
public class Application extends AbstractApplication {
9+
810
@Override
911
public void init() {
10-
this.setTemplateRequired(false);
12+
// Initialization logic (e.g., setting up resources)
13+
// Note: Do NOT register actions here — use the @Action annotation instead.
14+
this.setTemplateRequired(false); // Skip .view template lookup if returning data directly
1115
}
1216

13-
@Action(value = "hello", description = "Say hello")
14-
public String sayHello() {
15-
return "Hello from generated tinystruct app!";
17+
@Override
18+
public String version() {
19+
return "1.0.0";
1620
}
1721

18-
@Action(value = "hello", description = "Say hello")
19-
public String sayHello(String words) {
20-
return words;
22+
// Handles: bin/dispatcher hello AND GET /?q=hello
23+
@Action(value = "hello", description = "Say hello to tinystruct")
24+
public String sayHello() {
25+
return "Hello, tinystruct!";
2126
}
2227

23-
@Action(value = "hello", mode = Mode.HTTP_GET)
24-
public String helloGet() {
25-
return "GET";
28+
// Path parameter: GET /?q=greet/James OR bin/dispatcher greet/James
29+
@Action(value = "greet", description = "Greet a user by name")
30+
public String greet(String name) {
31+
return "Hello, " + name + "!";
2632
}
2733

28-
@Action(value = "hello", mode = Mode.HTTP_POST)
29-
public String helloPost() {
30-
return "POST";
34+
// HTTP-only POST handler
35+
@Action(value = "submit", mode = Mode.HTTP_POST, description = "Handle form submission")
36+
public String submit() throws ApplicationException {
37+
// Logic for handling submission
38+
return "Submitted successfully";
3139
}
3240

33-
@Action(value = "--help", description = "Print help information")
41+
// Built-in help command
42+
@Action(value = "--help", description = "Print help information", mode = Mode.CLI)
3443
@Override
3544
public String help() {
3645
return super.help();
3746
}
38-
39-
@Override
40-
public String version() {
41-
return "";
42-
}
4347
}
Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,30 @@
1-
package ${packageName};
1+
package ${package};
22

3+
import org.junit.jupiter.api.Assertions;
4+
import org.junit.jupiter.api.BeforeEach;
35
import org.junit.jupiter.api.Test;
4-
import static org.junit.jupiter.api.Assertions.*;
6+
import org.tinystruct.system.Settings;
57

68
public class ApplicationTest {
79

10+
private Application app;
11+
12+
@BeforeEach
13+
public void setUp() {
14+
app = new Application();
15+
// Setting configuration triggers init() and annotation processing
16+
app.setConfiguration(new Settings());
17+
}
18+
19+
@Test
20+
public void testSayHello() throws Exception {
21+
Object result = app.invoke("hello");
22+
Assertions.assertEquals("Hello, tinystruct!", result);
23+
}
24+
825
@Test
9-
public void testSayHello() {
10-
Application app = new Application();
11-
assertEquals("Hello from generated tinystruct app!", app.sayHello());
26+
public void testGreet() throws Exception {
27+
Object result = app.invoke("greet", new Object[]{"James"});
28+
Assertions.assertEquals("Hello, James!", result);
1229
}
1330
}

0 commit comments

Comments
 (0)