1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.bremersee.test.web;
18
19 import java.util.ArrayList;
20 import java.util.Collection;
21 import java.util.List;
22 import lombok.EqualsAndHashCode;
23 import org.springframework.util.StringUtils;
24
25
26
27
28
29
30 public interface RestApiTesterPath {
31
32
33
34
35
36
37 static RestApiTesterPath.Builder pathBuilder() {
38 return new BuilderImpl();
39 }
40
41
42
43
44
45
46 RestApiTesterPath.Builder toPathBuilder();
47
48
49
50
51 interface Builder {
52
53
54
55
56
57
58
59
60 Builder add(PathType stepType, String value);
61
62
63
64
65
66
67 RestApiTesterPath build();
68 }
69
70
71
72
73 class Impl extends ArrayList<RestApiTesterPathValues> implements RestApiTesterPath {
74
75 private Impl(Collection<? extends RestApiTesterPathValues> collection) {
76 super(collection);
77 }
78
79 @Override
80 public RestApiTesterPath.Builder toPathBuilder() {
81 return new BuilderImpl(this);
82 }
83
84 @Override
85 public String toString() {
86 return StringUtils.collectionToDelimitedString(this, " -> ");
87 }
88 }
89
90
91
92
93 class BuilderImpl implements RestApiTesterPath.Builder {
94
95 private final List<RestApiTesterPathValues> values = new ArrayList<>();
96
97 private BuilderImpl() {
98 }
99
100 private BuilderImpl(Collection<? extends RestApiTesterPathValues> collection) {
101 if (collection != null) {
102 values.addAll(collection);
103 }
104 }
105
106 @Override
107 public Builder add(PathType stepType, String value) {
108 values.add(new RestApiTesterPathValues(stepType, value));
109 return this;
110 }
111
112 @Override
113 public RestApiTesterPath build() {
114 return new Impl(new ArrayList<>(values));
115 }
116 }
117
118
119
120
121 enum PathType {
122
123
124
125
126 CLASS("Class"),
127
128
129
130
131 METHOD("Method"),
132
133
134
135
136 METHOD_PARAMETER("Parameter"),
137
138
139
140
141 ANNOTATION("Annotation"),
142
143
144
145
146 ATTRIBUTE("Attribute");
147
148 private final String value;
149
150 PathType(String value) {
151 this.value = value;
152 }
153
154 @Override
155 public String toString() {
156 return value;
157 }
158 }
159
160
161
162
163 @EqualsAndHashCode(doNotUseGetters = true)
164 class RestApiTesterPathValues {
165
166 private final PathType type;
167
168 private final String value;
169
170
171
172
173
174
175
176 RestApiTesterPathValues(PathType type, String value) {
177 this.type = type;
178 this.value = value;
179 }
180
181 @Override
182 public String toString() {
183 return type + " (" + value + ")";
184 }
185 }
186 }