|
1 | 1 | package test_locally.api.model; |
2 | 2 |
|
| 3 | +import com.google.gson.Gson; |
3 | 4 | import com.slack.api.model.manifest.AppManifest; |
| 5 | +import com.slack.api.model.manifest.AppManifestParams; |
4 | 6 | import org.junit.Test; |
5 | 7 | import test_locally.unit.GsonFactory; |
6 | 8 |
|
| 9 | +import java.util.Arrays; |
| 10 | + |
| 11 | +import static org.hamcrest.CoreMatchers.containsString; |
7 | 12 | import static org.hamcrest.CoreMatchers.is; |
8 | 13 | import static org.hamcrest.CoreMatchers.notNullValue; |
9 | 14 | import static org.hamcrest.MatcherAssert.assertThat; |
@@ -103,4 +108,48 @@ public void parser() { |
103 | 108 | .fromJson(json, AppManifest.class); |
104 | 109 | assertThat(appManifest.getSettings(), is(notNullValue())); |
105 | 110 | } |
| 111 | + |
| 112 | + @Test |
| 113 | + public void userConnections() { |
| 114 | + String json = "{\n" + |
| 115 | + " \"display_information\": {\n" + |
| 116 | + " \"name\": \"connector\"\n" + |
| 117 | + " },\n" + |
| 118 | + " \"features\": {\n" + |
| 119 | + " \"user_connections\": {\n" + |
| 120 | + " \"is_enabled\": true,\n" + |
| 121 | + " \"auth_hosts\": [\n" + |
| 122 | + " \"example.com\",\n" + |
| 123 | + " \"auth.example.com\"\n" + |
| 124 | + " ]\n" + |
| 125 | + " }\n" + |
| 126 | + " }\n" + |
| 127 | + "}"; |
| 128 | + |
| 129 | + Gson gson = GsonFactory.createSnakeCase(true, true); |
| 130 | + AppManifest appManifest = gson.fromJson(json, AppManifest.class); |
| 131 | + AppManifest.UserConnections userConnections = appManifest.getFeatures().getUserConnections(); |
| 132 | + assertThat(userConnections.getIsEnabled(), is(true)); |
| 133 | + assertThat(userConnections.getAuthHosts(), is(Arrays.asList("example.com", "auth.example.com"))); |
| 134 | + |
| 135 | + String serialized = gson.toJson(appManifest); |
| 136 | + assertThat(serialized, containsString( |
| 137 | + "\"user_connections\":{\"is_enabled\":true,\"auth_hosts\":[\"example.com\",\"auth.example.com\"]}")); |
| 138 | + } |
| 139 | + |
| 140 | + @Test |
| 141 | + public void userConnectionsParams() { |
| 142 | + AppManifestParams params = AppManifestParams.builder() |
| 143 | + .features(AppManifestParams.Features.builder() |
| 144 | + .userConnections(AppManifestParams.UserConnections.builder() |
| 145 | + .isEnabled(false) |
| 146 | + .authHosts(Arrays.asList("example.com")) |
| 147 | + .build()) |
| 148 | + .build()) |
| 149 | + .build(); |
| 150 | + |
| 151 | + String serialized = GsonFactory.createSnakeCase(true, true).toJson(params); |
| 152 | + assertThat(serialized, containsString( |
| 153 | + "\"user_connections\":{\"is_enabled\":false,\"auth_hosts\":[\"example.com\"]}")); |
| 154 | + } |
106 | 155 | } |
0 commit comments