Skip to content

Commit 4155cd6

Browse files
committed
Fixed sonar and added tests
1 parent c59e280 commit 4155cd6

File tree

9 files changed

+660
-70
lines changed

9 files changed

+660
-70
lines changed

src/main/java/io/github/vishalmysore/a2ui/A2UIAware.java

Lines changed: 70 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ default Map<String, Object> createRootColumn(String rootId, List<String> childId
3535

3636
Map<String, Object> rootComponent = new HashMap<>();
3737
Map<String, Object> columnProps = new HashMap<>();
38-
columnProps.put("children", new HashMap<String, Object>() {{
39-
put("explicitList", childIds);
40-
}});
38+
Map<String, Object> childrenMap = new HashMap<>();
39+
childrenMap.put("explicitList", childIds);
40+
columnProps.put("children", childrenMap);
4141
rootComponent.put("Column", columnProps);
4242
root.put("component", rootComponent);
4343

@@ -67,9 +67,9 @@ default Map<String, Object> createTextComponent(String id, String text, String u
6767

6868
Map<String, Object> textComponent = new HashMap<>();
6969
Map<String, Object> textProps = new HashMap<>();
70-
textProps.put("text", new HashMap<String, Object>() {{
71-
put("literalString", text);
72-
}});
70+
Map<String, Object> textMap = new HashMap<>();
71+
textMap.put("literalString", text);
72+
textProps.put("text", textMap);
7373

7474
if (usageHint != null && !usageHint.isEmpty()) {
7575
textProps.put("usageHint", usageHint);
@@ -184,14 +184,14 @@ default Map<String, Object> createTextFieldComponent(String id, String label, St
184184
Map<String, Object> textFieldProps = new HashMap<>();
185185

186186
// Label is required for TextField
187-
textFieldProps.put("label", new HashMap<String, Object>() {{
188-
put("literalString", label);
189-
}});
187+
Map<String, Object> labelMap = new HashMap<>();
188+
labelMap.put("literalString", label);
189+
textFieldProps.put("label", labelMap);
190190

191191
// Bind text to data model path (A2UI v0.8 uses 'text' property for TextField)
192-
textFieldProps.put("text", new HashMap<String, Object>() {{
193-
put("path", dataPath);
194-
}});
192+
Map<String, Object> textMap = new HashMap<>();
193+
textMap.put("path", dataPath);
194+
textFieldProps.put("text", textMap);
195195

196196
textFieldComponent.put("TextField", textFieldProps);
197197
component.put("component", textFieldComponent);
@@ -228,9 +228,9 @@ default Map<String, Object> createButtonComponent(String id, String buttonText,
228228
for (Map.Entry<String, String> binding : contextBindings.entrySet()) {
229229
Map<String, Object> contextItem = new HashMap<>();
230230
contextItem.put("key", binding.getKey());
231-
contextItem.put("value", new HashMap<String, Object>() {{
232-
put("path", binding.getValue());
233-
}});
231+
Map<String, Object> valueMap = new HashMap<>();
232+
valueMap.put("path", binding.getValue());
233+
contextItem.put("value", valueMap);
234234
context.add(contextItem);
235235
}
236236
action.put("context", context);
@@ -332,9 +332,9 @@ default Map<String, Object> createImageComponent(String id, String url, String f
332332
Map<String, Object> imageComponent = new HashMap<>();
333333
Map<String, Object> imageProps = new HashMap<>();
334334

335-
imageProps.put("url", new HashMap<String, Object>() {{
336-
put("literalString", url);
337-
}});
335+
Map<String, Object> urlMap = new HashMap<>();
336+
urlMap.put("literalString", url);
337+
imageProps.put("url", urlMap);
338338

339339
if (fit != null) {
340340
imageProps.put("fit", fit);
@@ -359,13 +359,13 @@ default Map<String, Object> createCheckBoxComponent(String id, String label, Str
359359
Map<String, Object> checkBoxComponent = new HashMap<>();
360360
Map<String, Object> checkBoxProps = new HashMap<>();
361361

362-
checkBoxProps.put("label", new HashMap<String, Object>() {{
363-
put("literalString", label);
364-
}});
362+
Map<String, Object> labelMap = new HashMap<>();
363+
labelMap.put("literalString", label);
364+
checkBoxProps.put("label", labelMap);
365365

366-
checkBoxProps.put("value", new HashMap<String, Object>() {{
367-
put("path", dataPath);
368-
}});
366+
Map<String, Object> valueMap = new HashMap<>();
367+
valueMap.put("path", dataPath);
368+
checkBoxProps.put("value", valueMap);
369369

370370
checkBoxComponent.put("CheckBox", checkBoxProps);
371371
component.put("component", checkBoxComponent);
@@ -384,13 +384,13 @@ default Map<String, Object> createSliderComponent(String id, String label, Strin
384384
Map<String, Object> sliderComponent = new HashMap<>();
385385
Map<String, Object> sliderProps = new HashMap<>();
386386

387-
sliderProps.put("label", new HashMap<String, Object>() {{
388-
put("literalString", label);
389-
}});
387+
Map<String, Object> labelMap = new HashMap<>();
388+
labelMap.put("literalString", label);
389+
sliderProps.put("label", labelMap);
390390

391-
sliderProps.put("value", new HashMap<String, Object>() {{
392-
put("path", dataPath);
393-
}});
391+
Map<String, Object> valueMap = new HashMap<>();
392+
valueMap.put("path", dataPath);
393+
sliderProps.put("value", valueMap);
394394

395395
if (minValue != null) {
396396
sliderProps.put("minValue", minValue);
@@ -434,9 +434,9 @@ default Map<String, Object> createRowComponent(String id, List<String> childIds,
434434
Map<String, Object> rowComponent = new HashMap<>();
435435
Map<String, Object> rowProps = new HashMap<>();
436436

437-
rowProps.put("children", new HashMap<String, Object>() {{
438-
put("explicitList", childIds);
439-
}});
437+
Map<String, Object> childrenMap = new HashMap<>();
438+
childrenMap.put("explicitList", childIds);
439+
rowProps.put("children", childrenMap);
440440

441441
if (alignment != null) {
442442
rowProps.put("alignment", alignment);
@@ -496,10 +496,10 @@ default Map<String, Object> createListComponent(String id, String dataPath, Stri
496496
Map<String, Object> listComponent = new HashMap<>();
497497
Map<String, Object> listProps = new HashMap<>();
498498

499-
listProps.put("children", new HashMap<String, Object>() {{
500-
put("path", dataPath);
501-
put("componentId", templateComponentId);
502-
}});
499+
Map<String, Object> childrenMap = new HashMap<>();
500+
childrenMap.put("path", dataPath);
501+
childrenMap.put("componentId", templateComponentId);
502+
listProps.put("children", childrenMap);
503503

504504
listComponent.put("List", listProps);
505505
component.put("component", listComponent);
@@ -519,9 +519,9 @@ default Map<String, Object> createLoadingComponent(String id, String message) {
519519
Map<String, Object> columnProps = new HashMap<>();
520520

521521
List<String> childIds = Arrays.asList("loading_icon", "loading_text");
522-
columnProps.put("children", new HashMap<String, Object>() {{
523-
put("explicitList", childIds);
524-
}});
522+
Map<String, Object> childrenMap = new HashMap<>();
523+
childrenMap.put("explicitList", childIds);
524+
columnProps.put("children", childrenMap);
525525
columnProps.put("alignment", "center");
526526
columnProps.put("distribution", "center");
527527

@@ -580,18 +580,18 @@ default Map<String, Object> createChoicePickerComponent(String id, String label,
580580
Map<String, Object> choiceComponent = new HashMap<>();
581581
Map<String, Object> choiceProps = new HashMap<>();
582582

583-
choiceProps.put("label", new HashMap<String, Object>() {{
584-
put("literalString", label);
585-
}});
583+
Map<String, Object> labelMap = new HashMap<>();
584+
labelMap.put("literalString", label);
585+
choiceProps.put("label", labelMap);
586586

587587
List<Map<String, Object>> optionList = new ArrayList<>();
588588
for (Map<String, String> option : options) {
589-
optionList.add(new HashMap<String, Object>() {{
590-
put("value", option.get("value"));
591-
put("label", new HashMap<String, Object>() {{
592-
put("literalString", option.get("label"));
593-
}});
594-
}});
589+
Map<String, Object> optionMap = new HashMap<>();
590+
optionMap.put("value", option.get("value"));
591+
Map<String, Object> optionLabelMap = new HashMap<>();
592+
optionLabelMap.put("literalString", option.get("label"));
593+
optionMap.put("label", optionLabelMap);
594+
optionList.add(optionMap);
595595
}
596596
choiceProps.put("options", optionList);
597597

@@ -615,9 +615,9 @@ default Map<String, Object> createVideoComponent(String id, String url, String u
615615
Map<String, Object> videoComponent = new HashMap<>();
616616
Map<String, Object> videoProps = new HashMap<>();
617617

618-
videoProps.put("url", new HashMap<String, Object>() {{
619-
put("literalString", url);
620-
}});
618+
Map<String, Object> urlMap = new HashMap<>();
619+
urlMap.put("literalString", url);
620+
videoProps.put("url", urlMap);
621621

622622
if (usageHint != null) {
623623
videoProps.put("usageHint", usageHint);
@@ -639,14 +639,14 @@ default Map<String, Object> createAudioPlayerComponent(String id, String url, St
639639
Map<String, Object> audioComponent = new HashMap<>();
640640
Map<String, Object> audioProps = new HashMap<>();
641641

642-
audioProps.put("url", new HashMap<String, Object>() {{
643-
put("literalString", url);
644-
}});
642+
Map<String, Object> urlMap = new HashMap<>();
643+
urlMap.put("literalString", url);
644+
audioProps.put("url", urlMap);
645645

646646
if (description != null) {
647-
audioProps.put("description", new HashMap<String, Object>() {{
648-
put("literalString", description);
649-
}});
647+
Map<String, Object> descriptionMap = new HashMap<>();
648+
descriptionMap.put("literalString", description);
649+
audioProps.put("description", descriptionMap);
650650
}
651651

652652
audioComponent.put("AudioPlayer", audioProps);
@@ -667,12 +667,12 @@ default Map<String, Object> createTabsComponent(String id, List<Map<String, Obje
667667

668668
List<Map<String, Object>> items = new ArrayList<>();
669669
for (Map<String, Object> tab : tabItems) {
670-
items.add(new HashMap<String, Object>() {{
671-
put("title", new HashMap<String, Object>() {{
672-
put("literalString", tab.get("title"));
673-
}});
674-
put("child", tab.get("child"));
675-
}});
670+
Map<String, Object> itemMap = new HashMap<>();
671+
Map<String, Object> titleMap = new HashMap<>();
672+
titleMap.put("literalString", tab.get("title"));
673+
itemMap.put("title", titleMap);
674+
itemMap.put("child", tab.get("child"));
675+
items.add(itemMap);
676676
}
677677
tabsProps.put("tabItems", items);
678678

@@ -712,14 +712,14 @@ default Map<String, Object> createDateTimeInputComponent(String id, String label
712712
Map<String, Object> dateTimeComponent = new HashMap<>();
713713
Map<String, Object> dateTimeProps = new HashMap<>();
714714

715-
dateTimeProps.put("label", new HashMap<String, Object>() {{
716-
put("literalString", label);
717-
}});
715+
Map<String, Object> labelMap = new HashMap<>();
716+
labelMap.put("literalString", label);
717+
dateTimeProps.put("label", labelMap);
718718

719719
if (dataPath != null) {
720-
dateTimeProps.put("value", new HashMap<String, Object>() {{
721-
put("path", dataPath);
722-
}});
720+
Map<String, Object> valueMap = new HashMap<>();
721+
valueMap.put("path", dataPath);
722+
dateTimeProps.put("value", valueMap);
723723
}
724724

725725
if (enableDate != null) {
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
package io.github.vishalmysore.a2a.domain;
2+
3+
import org.junit.jupiter.api.Test;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
6+
import java.util.Arrays;
7+
import java.util.HashMap;
8+
import java.util.List;
9+
import java.util.Map;
10+
11+
public class A2UIClientCapabilitiesTest {
12+
13+
@Test
14+
public void testNoArgsConstructor() {
15+
A2UIClientCapabilities capabilities = new A2UIClientCapabilities();
16+
assertNotNull(capabilities);
17+
assertNull(capabilities.getSupportedCatalogIds());
18+
assertNull(capabilities.getInlineCatalogs());
19+
}
20+
21+
@Test
22+
public void testAllArgsConstructor() {
23+
List<String> catalogIds = Arrays.asList("catalog1", "catalog2");
24+
List<Map<String, Object>> inlineCatalogs = Arrays.asList(new HashMap<>());
25+
A2UIClientCapabilities capabilities = new A2UIClientCapabilities(catalogIds, inlineCatalogs);
26+
assertEquals(catalogIds, capabilities.getSupportedCatalogIds());
27+
assertEquals(inlineCatalogs, capabilities.getInlineCatalogs());
28+
}
29+
30+
@Test
31+
public void testSettersAndGetters() {
32+
A2UIClientCapabilities capabilities = new A2UIClientCapabilities();
33+
List<String> catalogIds = Arrays.asList("test1", "test2");
34+
capabilities.setSupportedCatalogIds(catalogIds);
35+
List<Map<String, Object>> inlineCatalogs = Arrays.asList(new HashMap<>());
36+
capabilities.setInlineCatalogs(inlineCatalogs);
37+
38+
assertEquals(catalogIds, capabilities.getSupportedCatalogIds());
39+
assertEquals(inlineCatalogs, capabilities.getInlineCatalogs());
40+
}
41+
42+
@Test
43+
public void testToString() {
44+
List<String> catalogIds = Arrays.asList("catalog");
45+
A2UIClientCapabilities capabilities = new A2UIClientCapabilities(catalogIds, null);
46+
String toString = capabilities.toString();
47+
assertNotNull(toString);
48+
assertTrue(toString.contains("catalog"));
49+
}
50+
51+
@Test
52+
public void testEqualsAndHashCode() {
53+
List<String> catalogIds = Arrays.asList("catalog");
54+
A2UIClientCapabilities cap1 = new A2UIClientCapabilities(catalogIds, null);
55+
A2UIClientCapabilities cap2 = new A2UIClientCapabilities(catalogIds, null);
56+
A2UIClientCapabilities cap3 = new A2UIClientCapabilities(Arrays.asList("different"), null);
57+
58+
assertEquals(cap1, cap2);
59+
assertNotEquals(cap1, cap3);
60+
assertEquals(cap1.hashCode(), cap2.hashCode());
61+
assertNotEquals(cap1.hashCode(), cap3.hashCode());
62+
}
63+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package io.github.vishalmysore.a2a.domain;
2+
3+
import org.junit.jupiter.api.Test;
4+
import static org.junit.jupiter.api.Assertions.*;
5+
6+
import java.util.HashMap;
7+
import java.util.Map;
8+
9+
public class AgentExtensionTest {
10+
11+
@Test
12+
public void testNoArgsConstructor() {
13+
AgentExtension extension = new AgentExtension();
14+
assertNotNull(extension);
15+
assertNull(extension.getUri());
16+
assertNull(extension.getDescription());
17+
assertFalse(extension.isRequired());
18+
assertNull(extension.getParams());
19+
}
20+
21+
@Test
22+
public void testAllArgsConstructor() {
23+
Map<String, Object> params = new HashMap<>();
24+
params.put("key", "value");
25+
AgentExtension extension = new AgentExtension("uri", "description", true, params);
26+
assertEquals("uri", extension.getUri());
27+
assertEquals("description", extension.getDescription());
28+
assertTrue(extension.isRequired());
29+
assertEquals(params, extension.getParams());
30+
}
31+
32+
@Test
33+
public void testSettersAndGetters() {
34+
AgentExtension extension = new AgentExtension();
35+
extension.setUri("testUri");
36+
extension.setDescription("testDescription");
37+
extension.setRequired(true);
38+
Map<String, Object> params = new HashMap<>();
39+
params.put("test", "value");
40+
extension.setParams(params);
41+
42+
assertEquals("testUri", extension.getUri());
43+
assertEquals("testDescription", extension.getDescription());
44+
assertTrue(extension.isRequired());
45+
assertEquals(params, extension.getParams());
46+
}
47+
48+
@Test
49+
public void testToString() {
50+
AgentExtension extension = new AgentExtension("uri", "desc", false, null);
51+
String toString = extension.toString();
52+
assertNotNull(toString);
53+
assertTrue(toString.contains("uri"));
54+
assertTrue(toString.contains("desc"));
55+
}
56+
57+
@Test
58+
public void testEqualsAndHashCode() {
59+
AgentExtension ext1 = new AgentExtension("uri", "desc", true, null);
60+
AgentExtension ext2 = new AgentExtension("uri", "desc", true, null);
61+
AgentExtension ext3 = new AgentExtension("different", "desc", true, null);
62+
63+
assertEquals(ext1, ext2);
64+
assertNotEquals(ext1, ext3);
65+
assertEquals(ext1.hashCode(), ext2.hashCode());
66+
assertNotEquals(ext1.hashCode(), ext3.hashCode());
67+
}
68+
}

0 commit comments

Comments
 (0)