|
2 | 2 |
|
3 | 3 | import io.swagger.models.*;
|
4 | 4 | import io.swagger.models.properties.Property;
|
| 5 | +import io.swagger.models.properties.RefProperty; |
5 | 6 | import io.swagger.models.refs.RefFormat;
|
6 | 7 | import io.swagger.parser.ResolverCache;
|
7 | 8 | import mockit.*;
|
@@ -150,4 +151,56 @@ private void setupPropertyAndExternalRefProcessors() {
|
150 | 151 | result = externalRefProcessor;
|
151 | 152 | }};
|
152 | 153 | }
|
| 154 | + |
| 155 | + |
| 156 | + @Test |
| 157 | + public void testProcessComposedModelWithProperties(@Injectable final Property property1) throws Exception { |
| 158 | + setupPropertyAndExternalRefProcessors(); |
| 159 | + |
| 160 | + final String ref1 = "http://my.company.com/path/to/file.json#/foo/bar"; |
| 161 | + final String ref2 = "http://my.company.com/path/to/file.json#/this/that"; |
| 162 | + final String ref3 = "http://my.company.com/path/to/file.json#/hello/world"; |
| 163 | + final String ref4 = "http://my.company.com/path/to/file.json#/hello/ref"; |
| 164 | + final Property property2 = new RefProperty(ref4); |
| 165 | + |
| 166 | + ModelProcessor modelProcessor = new ModelProcessor(cache, swagger); |
| 167 | + |
| 168 | + new Expectations() {{ |
| 169 | + externalRefProcessor.processRefToExternalDefinition(ref1, RefFormat.URL); |
| 170 | + times = 1; |
| 171 | + result = "bar"; |
| 172 | + externalRefProcessor.processRefToExternalDefinition(ref2, RefFormat.URL); |
| 173 | + times = 1; |
| 174 | + result = "that"; |
| 175 | + externalRefProcessor.processRefToExternalDefinition(ref3, RefFormat.URL); |
| 176 | + times = 1; |
| 177 | + result = "world"; |
| 178 | + propertyProcessor.processProperty(property1); |
| 179 | + times = 1; |
| 180 | + propertyProcessor.processProperty(property2); |
| 181 | + times = 1; |
| 182 | + }}; |
| 183 | + |
| 184 | + ComposedModel composedModel = new ComposedModel(); |
| 185 | + composedModel.child(new RefModel(ref1)); |
| 186 | + composedModel.parent(new RefModel(ref2)); |
| 187 | + composedModel.interfaces(Arrays.asList(new RefModel(ref3))); |
| 188 | + composedModel.addProperty("foo", property1); |
| 189 | + composedModel.addProperty("bar", property2); |
| 190 | + |
| 191 | + modelProcessor.processModel(composedModel); |
| 192 | + |
| 193 | + new FullVerifications() {{ |
| 194 | + externalRefProcessor.processRefToExternalDefinition(ref1, RefFormat.URL); |
| 195 | + times = 1; |
| 196 | + externalRefProcessor.processRefToExternalDefinition(ref2, RefFormat.URL); |
| 197 | + times = 1; |
| 198 | + externalRefProcessor.processRefToExternalDefinition(ref3, RefFormat.URL); |
| 199 | + times = 1; |
| 200 | + }}; |
| 201 | + |
| 202 | + assertEquals(((RefModel) composedModel.getChild()).get$ref(), "#/definitions/bar"); |
| 203 | + assertEquals(((RefModel) composedModel.getParent()).get$ref(), "#/definitions/that"); |
| 204 | + assertEquals((composedModel.getInterfaces().get(0)).get$ref(), "#/definitions/world"); |
| 205 | + } |
153 | 206 | }
|
0 commit comments