|
3 | 3 | package executor |
4 | 4 |
|
5 | 5 | import ( |
| 6 | + "fmt" |
6 | 7 | "testing" |
7 | 8 |
|
8 | 9 | "github.com/mendixlabs/mxcli/mdl/ast" |
@@ -56,3 +57,85 @@ func TestDescribeJavaAction_Mock(t *testing.T) { |
56 | 57 | out := buf.String() |
57 | 58 | assertContainsStr(t, out, "create java action") |
58 | 59 | } |
| 60 | + |
| 61 | +// NOTE: listJavaActions has no explicit not-connected guard. It calls |
| 62 | +// getHierarchy (returns nil when disconnected) then proceeds to call |
| 63 | +// ListJavaActions on the backend. The handler degrades gracefully — |
| 64 | +// with an empty result set it succeeds with a nil hierarchy. |
| 65 | + |
| 66 | +func TestShowJavaActions_BackendError(t *testing.T) { |
| 67 | + mod := mkModule("MyModule") |
| 68 | + h := mkHierarchy(mod) |
| 69 | + |
| 70 | + mb := &mock.MockBackend{ |
| 71 | + IsConnectedFunc: func() bool { return true }, |
| 72 | + ListJavaActionsFunc: func() ([]*types.JavaAction, error) { |
| 73 | + return nil, fmt.Errorf("backend unavailable") |
| 74 | + }, |
| 75 | + } |
| 76 | + ctx, _ := newMockCtx(t, withBackend(mb), withHierarchy(h)) |
| 77 | + assertError(t, listJavaActions(ctx, "")) |
| 78 | +} |
| 79 | + |
| 80 | +func TestDescribeJavaAction_NotFound(t *testing.T) { |
| 81 | + mb := &mock.MockBackend{ |
| 82 | + IsConnectedFunc: func() bool { return true }, |
| 83 | + ReadJavaActionByNameFunc: func(qn string) (*javaactions.JavaAction, error) { |
| 84 | + return nil, fmt.Errorf("not found") |
| 85 | + }, |
| 86 | + } |
| 87 | + ctx, _ := newMockCtx(t, withBackend(mb)) |
| 88 | + assertError(t, describeJavaAction(ctx, ast.QualifiedName{Module: "MyModule", Name: "Missing"})) |
| 89 | +} |
| 90 | + |
| 91 | +func TestShowJavaActions_FilterByModule(t *testing.T) { |
| 92 | + mod1 := mkModule("Alpha") |
| 93 | + mod2 := mkModule("Beta") |
| 94 | + ja1 := &types.JavaAction{ |
| 95 | + BaseElement: model.BaseElement{ID: nextID("ja")}, |
| 96 | + ContainerID: mod1.ID, |
| 97 | + Name: "ActionA", |
| 98 | + } |
| 99 | + ja2 := &types.JavaAction{ |
| 100 | + BaseElement: model.BaseElement{ID: nextID("ja")}, |
| 101 | + ContainerID: mod2.ID, |
| 102 | + Name: "ActionB", |
| 103 | + } |
| 104 | + |
| 105 | + h := mkHierarchy(mod1, mod2) |
| 106 | + withContainer(h, ja1.ContainerID, mod1.ID) |
| 107 | + withContainer(h, ja2.ContainerID, mod2.ID) |
| 108 | + |
| 109 | + mb := &mock.MockBackend{ |
| 110 | + IsConnectedFunc: func() bool { return true }, |
| 111 | + ListJavaActionsFunc: func() ([]*types.JavaAction, error) { return []*types.JavaAction{ja1, ja2}, nil }, |
| 112 | + } |
| 113 | + |
| 114 | + ctx, buf := newMockCtx(t, withBackend(mb), withHierarchy(h)) |
| 115 | + assertNoError(t, listJavaActions(ctx, "Alpha")) |
| 116 | + |
| 117 | + out := buf.String() |
| 118 | + assertContainsStr(t, out, "Alpha.ActionA") |
| 119 | + assertNotContainsStr(t, out, "Beta.ActionB") |
| 120 | +} |
| 121 | + |
| 122 | +func TestShowJavaActions_JSON(t *testing.T) { |
| 123 | + mod := mkModule("MyModule") |
| 124 | + ja := &types.JavaAction{ |
| 125 | + BaseElement: model.BaseElement{ID: nextID("ja")}, |
| 126 | + ContainerID: mod.ID, |
| 127 | + Name: "DoSomething", |
| 128 | + } |
| 129 | + |
| 130 | + h := mkHierarchy(mod) |
| 131 | + withContainer(h, ja.ContainerID, mod.ID) |
| 132 | + |
| 133 | + mb := &mock.MockBackend{ |
| 134 | + IsConnectedFunc: func() bool { return true }, |
| 135 | + ListJavaActionsFunc: func() ([]*types.JavaAction, error) { return []*types.JavaAction{ja}, nil }, |
| 136 | + } |
| 137 | + |
| 138 | + ctx, buf := newMockCtx(t, withBackend(mb), withHierarchy(h), withFormat(FormatJSON)) |
| 139 | + assertNoError(t, listJavaActions(ctx, "")) |
| 140 | + assertValidJSON(t, buf.String()) |
| 141 | +} |
0 commit comments