|
1 | 1 | package com.neueda.jetbrains.plugin.graphdb.jetbrains.ui.console.params;
|
2 | 2 |
|
| 3 | +import com.fasterxml.jackson.databind.JsonMappingException; |
3 | 4 | import org.junit.Before;
|
4 | 5 | import org.junit.Test;
|
5 | 6 |
|
@@ -39,6 +40,14 @@ public void testParsingEmptyJsonObject() throws Exception {
|
39 | 40 | assertThat(result.isEmpty()).isTrue();
|
40 | 41 | }
|
41 | 42 |
|
| 43 | + @Test |
| 44 | + public void testParsingEmptyParameters() throws Exception { |
| 45 | + parametersProvider.setParametersJson(""); |
| 46 | + Map<String, Object> result = parametersService.getParameters(); |
| 47 | + |
| 48 | + assertThat(result.isEmpty()).isTrue(); |
| 49 | + } |
| 50 | + |
42 | 51 | @Test
|
43 | 52 | public void testParsingStringParameter() throws Exception {
|
44 | 53 | parametersProvider.setParametersJson("{\"name\": \"Anna\"}");
|
@@ -83,4 +92,51 @@ public void testParsingMultipleParameters() throws Exception {
|
83 | 92 | assertThat(result.get("lastName").toString()).isEqualTo("Johnson");
|
84 | 93 | }
|
85 | 94 |
|
| 95 | + @Test |
| 96 | + public void testParsingCommentOnly() throws Exception { |
| 97 | + parametersProvider.setParametersJson("// Provide query parameters in JSON format here:"); |
| 98 | + Map<String, Object> result = parametersService.getParameters(); |
| 99 | + |
| 100 | + assertThat(result.isEmpty()).isTrue(); |
| 101 | + } |
| 102 | + |
| 103 | + |
| 104 | + @Test |
| 105 | + public void testParsingCommentWithParameter() throws Exception { |
| 106 | + parametersProvider.setParametersJson("// Provide query parameters in JSON format here:\n{\"name\": \"Eva\"}"); |
| 107 | + Map<String, Object> result = parametersService.getParameters(); |
| 108 | + |
| 109 | + assertThat(result.size() == 1).isTrue(); |
| 110 | + } |
| 111 | + |
| 112 | + @Test(expected = Exception.class) |
| 113 | + public void testParsingJsonArray() throws Exception { |
| 114 | + parametersProvider.setParametersJson("// Provide query parameters in JSON format here:\n[\"item1\",\"item2\"]"); |
| 115 | + parametersService.getParameters(); |
| 116 | + } |
| 117 | + |
| 118 | + @Test(expected = JsonMappingException.class) |
| 119 | + public void testParsingNumber() throws Exception { |
| 120 | + parametersProvider.setParametersJson("1"); |
| 121 | + parametersService.getParameters(); |
| 122 | + } |
| 123 | + |
| 124 | + @Test(expected = JsonMappingException.class) |
| 125 | + public void testParsingString() throws Exception { |
| 126 | + parametersProvider.setParametersJson("\"abc\""); |
| 127 | + parametersService.getParameters(); |
| 128 | + } |
| 129 | + |
| 130 | + @Test(expected = JsonMappingException.class) |
| 131 | + public void testParsingUnwrappedParameter() throws Exception { |
| 132 | + parametersProvider.setParametersJson("\"param1\":\"val1\""); |
| 133 | + parametersService.getParameters(); |
| 134 | + } |
| 135 | + |
| 136 | + @Test(expected = Exception.class) |
| 137 | + public void testParsingParamWithObjAccessor() throws Exception { |
| 138 | + parametersProvider.setParametersJson("{\"param1\": person[\"name\"]}"); |
| 139 | + parametersService.getParameters(); |
| 140 | + } |
| 141 | + |
86 | 142 | }
|
0 commit comments