Best Spectrum code snippet using specs.ExampleSpecs
Source:OpenAPIParserTest.java
1package io.swagger.parser;2import io.swagger.v3.oas.models.Components;3import io.swagger.v3.oas.models.OpenAPI;4import io.swagger.v3.oas.models.media.ArraySchema;5import io.swagger.v3.oas.models.media.ObjectSchema;6import io.swagger.v3.oas.models.media.Schema;7import io.swagger.v3.oas.models.PathItem;8import io.swagger.v3.oas.models.media.StringSchema;9import io.swagger.v3.oas.models.parameters.Parameter;10import io.swagger.v3.oas.models.parameters.RequestBody;11import io.swagger.v3.parser.core.models.ParseOptions;12import io.swagger.v3.parser.core.models.SwaggerParseResult;13import io.swagger.v3.core.util.Json;14import java.math.BigDecimal;15import java.math.MathContext;16import org.junit.Test;17import org.testng.Assert;18import java.util.Map;19import java.util.List;20import static org.testng.Assert.assertEquals;21import static org.testng.Assert.assertNotNull;22import static org.testng.Assert.assertTrue;23import static org.testng.AssertJUnit.assertNull;24public class OpenAPIParserTest {25 @Test26 public void testNPE_1685() {27 OpenAPIParser openAPIParser = new OpenAPIParser();28 ParseOptions options = new ParseOptions();29 options.setResolveFully(true);30 SwaggerParseResult swaggerParseResult = openAPIParser.readLocation("issue1685.json", null, options);31 assertNull(swaggerParseResult.getOpenAPI());32 assertNotNull(swaggerParseResult.getMessages());33 assertTrue(swaggerParseResult.getMessages().size() == 2);34 assertEquals(swaggerParseResult.getMessages().get(0), "attribute notswagger is unexpected");35 assertEquals(swaggerParseResult.getMessages().get(1), "attribute swagger is missing");36 }37 @Test38 public void testIssue1608(){39 ParseOptions options = new ParseOptions();40 options.setResolveFully(true);41 OpenAPIParser openAPIParser = new OpenAPIParser();42 SwaggerParseResult swaggerParseResult = openAPIParser.readLocation("issue1608.json", null, options);43 Schema schema = swaggerParseResult.getOpenAPI().getPaths().get("/pet").getPut().getRequestBody().getContent().get("application/json").getSchema();44 assertEquals(schema.getRequired().size(), 1);45 }46 @Test47 public void testIssue1143(){48 ParseOptions options = new ParseOptions();49 options.setResolve(true);50 SwaggerParseResult result = new OpenAPIParser().readLocation("issue-1143.json",null,options);51 assertNotNull(result.getOpenAPI());52 assertNotNull(result.getOpenAPI().getComponents().getSchemas().get("RedisResource"));53 assertNotNull(result.getOpenAPI().getComponents().getSchemas().get("identificacion_usuario_aplicacion"));54 }55 @Test56 public void testIssue1621() {57 final ParseOptions parseOptions = new ParseOptions();58 parseOptions.setResolve(true);59 parseOptions.setResolveFully(true);60 parseOptions.setResolveCombinators(false);61 OpenAPIParser openAPIParser = new OpenAPIParser();62 SwaggerParseResult swaggerParseResult = openAPIParser.readLocation("issue-1621/example.openapi.yaml", null, parseOptions);63 assertEquals(0, swaggerParseResult.getMessages().size());64 OpenAPI api = swaggerParseResult.getOpenAPI();65 assertEquals("POST Example", api.getPaths()66 .get("/example")67 .getPost()68 .getRequestBody()69 .getContent()70 .get("application/json")71 .getSchema()72 .getTitle());73 }74 @Test75 public void testIssue749() {76 ParseOptions options = new ParseOptions();77 options.setResolve(true);78 SwaggerParseResult result = new OpenAPIParser().readLocation("issue749-main.yaml", null, options);79 assertNotNull(result);80 OpenAPI openAPI = result.getOpenAPI();81 assertNotNull(openAPI);82 Components components = openAPI.getComponents();83 assertNotNull(components);84 PathItem pathItem = openAPI.getPaths().get("/some/ping");85 assertNotNull(pathItem);86 List<Parameter> parameters = pathItem.getGet().getParameters();87 assertNotNull(parameters);88 assertEquals(parameters.size(), 1);89 assertEquals(parameters.get(0).getName(), "i");90 assertNotNull(parameters.get(0).getSchema());91 assertEquals(parameters.get(0).getSchema().get$ref(), "#/components/schemas/SomeId");92 Map<String, Schema> schemas = components.getSchemas();93 assertNotNull(schemas);94 assertEquals(schemas.size(), 1);95 assertNotNull(schemas.get("SomeId"));96 }97 @Test98 public void testSimple() {99 SwaggerParseResult result = new OpenAPIParser().readLocation("petstore.yaml", null, null);100 assertNotNull(result);101 assertNotNull(result.getOpenAPI());102 assertEquals(result.getOpenAPI().getOpenapi(), "3.0.1");103 }104 @Test105 public void testIssue887() {106 ParseOptions options = new ParseOptions();107 SwaggerParseResult result = new OpenAPIParser().readLocation("apiWithMultipleTags.json", null, null);108 System.out.println(result.getMessages());109 assertNotNull(result);110 assertNotNull(result.getOpenAPI());111 assertEquals(result.getMessages().get(1), "attribute tags.sample is repeated");112 }113 @Test114 public void testIssue895() {115 SwaggerParseResult result = new OpenAPIParser().readLocation("issue895.yaml", null, null);116 assertNotNull(result);117 assertNotNull(result.getOpenAPI());118 assertEquals(result.getMessages().get(0),"info.contact.test");119 assertEquals(result.getMessages().get(1),"info.license.test1");120 }121 @Test122 public void testIssue892() {123 SwaggerParseResult result = new OpenAPIParser().readLocation("issue892-main.yaml", null, null);124 assertEquals(result.getMessages().size(),1);125 assertNotNull(result.getOpenAPI());126 assertEquals(result.getOpenAPI().getOpenapi(), "3.0.1");127 }128 @Test129 public void testIssue934() {130 SwaggerParseResult result = new OpenAPIParser().readLocation("issue-934.yaml", null, null);131 assertNotNull(result);132 assertEquals(result.getMessages().size(),1);133 assertNotNull(result.getOpenAPI());134 assertEquals(result.getOpenAPI().getOpenapi(), "3.0.1");135 }136 @Test137 public void testIssue768() {138 ParseOptions options = new ParseOptions();139 options.setResolve(true);140 SwaggerParseResult result = new OpenAPIParser().readLocation("issue768-main.yaml", null, options);141 assertNotNull(result);142 OpenAPI openAPI = result.getOpenAPI();143 assertNotNull(openAPI);144 Components components = openAPI.getComponents();145 assertNotNull(components);146 Map<String, Schema> schemas = components.getSchemas();147 assertNotNull(schemas);148 assertEquals(schemas.size(), 1);149 }150 @Test151 public void test30Url() {152 String location = "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/master/examples/v3.0/petstore.yaml";153 SwaggerParseResult result = new OpenAPIParser().readLocation(location, null, null);154 assertNotNull(result);155 assertNotNull(result.getOpenAPI());156 assertEquals(result.getOpenAPI().getOpenapi(), "3.0.0");157 }158 @Test159 public void testConverterWithFlatten() {160 String yaml = "swagger: \"2.0\"\n" +161 "info:\n" +162 " description: \"Foo\"\n" +163 " version: \"1.0.0\"\n" +164 "host: \"something.com\"\n" +165 "basePath: \"/\"\n" +166 "schemes:\n" +167 " - \"https\"\n" +168 "consumes:\n" +169 " - \"application/json\"\n" +170 "produces:\n" +171 " - \"application/json\"\n" +172 "paths:\n" +173 " /example:\n" +174 " get:\n" +175 " responses:\n" +176 " 200:\n" +177 " description: \"OK\"\n" +178 " schema:\n" +179 " $ref: \"#/definitions/Foo\"\n" +180 " parameters: []\n" +181 "definitions:\n" +182 " Foo:\n" +183 " type: \"object\"\n" +184 " required:\n" +185 " properties:\n" +186 " nested:\n" +187 " type: \"object\"\n" +188 " properties:\n" +189 " color:\n" +190 " type: \"string\"";191 ParseOptions options = new ParseOptions();192 options.setResolve(true);193 options.setFlatten(true);194 SwaggerParseResult result = new OpenAPIParser().readContents(yaml, null, options);195 OpenAPI openAPI = result.getOpenAPI();196 assertEquals(openAPI.getComponents().getSchemas().size(), 2);197 }198 @Test199 public void test30() {200 String json =201 "{\n" +202 " \"openapi\": \"3.0.1\",\n" +203 " \"info\": {\n" +204 " \"title\": \"Swagger Petstore\",\n" +205 " \"description\": \"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.\",\n" +206 " \"termsOfService\": \"http://swagger.io/terms/\",\n" +207 " \"contact\": {\n" +208 " \"email\": \"apiteam@swagger.io\"\n" +209 " },\n" +210 " \"license\": {\n" +211 " \"name\": \"Apache 2.0\",\n" +212 " \"url\": \"http://www.apache.org/licenses/LICENSE-2.0.html\"\n" +213 " },\n" +214 " \"version\": \"1.0.0\"\n" +215 " }\n" +216 "}";217 ParseOptions options = new ParseOptions();218 options.setResolve(true);219 SwaggerParseResult result = new OpenAPIParser().readContents(json, null, options);220 assertNotNull(result);221 assertNotNull(result.getOpenAPI());222 assertEquals(result.getOpenAPI().getOpenapi(), "3.0.1");223 }224 @Test225 public void testParsingPrettifiedExtensions() throws Exception {226 String json =227 "{\n" +228 " \"openapi\": \"3.0.1\",\n" +229 " \"x-some-extension\": \"some-value\"\n" +230 "}";231 SwaggerParseResult result = new OpenAPIParser().readContents(json, null, null);232 assertNotNull(result);233 OpenAPI openAPI = result.getOpenAPI();234 assertNotNull(openAPI);235 assertNotNull(openAPI.getExtensions());236 assertEquals(openAPI.getExtensions().get("x-some-extension"), "some-value");237 String prettyJson = Json.pretty(openAPI);238 SwaggerParseResult prettyResult = new OpenAPIParser().readContents(prettyJson, null, null);239 assertNotNull(prettyResult);240 OpenAPI prettyOpenAPI = prettyResult.getOpenAPI();241 assertNotNull(prettyOpenAPI);242 assertNotNull(prettyOpenAPI.getExtensions());243 assertEquals(prettyOpenAPI.getExtensions().get("x-some-extension"), "some-value");244 }245 @Test246 public void testIssue799() {247 OpenAPIParser openApiParser = new OpenAPIParser();248 ParseOptions options = new ParseOptions();249 options.setResolve(true);250 options.setFlatten(true);251 OpenAPI openAPI = openApiParser.readLocation("issue799.json", null, options).getOpenAPI();252 Assert.assertEquals(((Schema)openAPI.getComponents().getSchemas().get("v1beta3.Binding").getProperties().get("metadata")).get$ref(),"#/components/schemas/v1beta3.ObjectMeta");253 RequestBody bodyParameter = openAPI.getPaths().get("/api/v1beta3/namespaces/{namespaces}/bindings").getPost().getRequestBody();254 Assert.assertEquals( bodyParameter.getContent().get("*/*").getSchema().get$ref(), "#/components/schemas/v1beta3.Binding");255 Assert.assertEquals( openAPI.getPaths().get("/api/v1beta3/namespaces/{namespaces}/componentstatuses/{name}").getGet().getResponses().get("200").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/v1beta3.ComponentStatus");256 Assert.assertEquals( openAPI.getPaths().get("/api/v1beta3/namespaces/{namespaces}/componentstatuses").getGet().getResponses().get("200").getContent().get("application/json").getSchema().get$ref(), "#/components/schemas/v1beta3.ComponentStatusList");257 Schema conditionsProperty = (Schema) openAPI.getComponents().getSchemas().get("v1beta3.ComponentStatus").getProperties().get("conditions");258 assertTrue( conditionsProperty instanceof ArraySchema);259 Schema items = ((ArraySchema)conditionsProperty).getItems();260 assertTrue( items.get$ref() != null);261 Assert.assertEquals( items.get$ref(), "#/components/schemas/v1beta3.ObjectReference");262 }263 @Test264 public void testIssue813() throws Exception {265 String inputSpec = "{\n" +266 " \"swagger\": \"2.0\",\n" +267 " \"info\": {\n" +268 " \"description\": \"This is a sample server Petstore server. You can find out more about Swagger at <a href=\\\"http://swagger.io\\\">http://swagger.io</a> or on irc.freenode.net, #swagger. For this sample, you can use the api key \\\"special-key\\\" to test the authorization filters\",\n" +269 " \"version\": \"1.0.0\",\n" +270 " \"title\": \"Swagger Petstore\",\n" +271 " \"termsOfService\": \"http://helloreverb.com/terms/\",\n" +272 " \"contact\": {\n" +273 " \"email\": \"apiteam@wordnik.com\"\n" +274 " },\n" +275 " \"license\": {\n" +276 " \"name\": \"Apache-2.0\",\n" +277 " \"url\": \"http://www.apache.org/licenses/LICENSE-2.0.html\"\n" +278 " }\n" +279 " },\n" +280 " \"host\": \"petstore.swagger.io\",\n" +281 " \"basePath\": \"/v2\",\n" +282 " \"schemes\": [\n" +283 " \"http\"\n" +284 " ],\n" +285 " \"paths\": {\n" +286 " \"/pet\": {\n" +287 " \"post\": {\n" +288 " \"tags\": [\n" +289 " \"pet\"\n" +290 " ],\n" +291 " \"summary\": \"Add a new pet to the store\",\n" +292 " \"description\": \"\",\n" +293 " \"operationId\": \"addPet\",\n" +294 " \"consumes\": [\n" +295 " \"application/json\",\n" +296 " \"application/xml\"\n" +297 " ],\n" +298 " \"produces\": [\n" +299 " \"application/json\",\n" +300 " \"application/xml\"\n" +301 " ],\n" +302 " \"parameters\": [{\n" +303 " \"in\": \"body\",\n" +304 " \"name\": \"body\",\n" +305 " \"description\": \"Pet object that needs to be added to the store\",\n" +306 " \"required\": false,\n" +307 " \"schema\": {\n" +308 " \"$ref\": \"#/definitions/Pet\"\n" +309 " }\n" +310 " }],\n" +311 " \"responses\": {\n" +312 " \"405\": {\n" +313 " \"description\": \"Invalid input\"\n" +314 " }\n" +315 " },\n" +316 " \"security\": [{\n" +317 " \"petstore_auth\": [\n" +318 " \"write:pets\",\n" +319 " \"read:pets\"\n" +320 " ]\n" +321 " }]\n" +322 " },\n" +323 " \"put\": {\n" +324 " \"tags\": [\n" +325 " \"pet\"\n" +326 " ],\n" +327 " \"summary\": \"Update an existing pet\",\n" +328 " \"description\": \"\",\n" +329 " \"operationId\": \"updatePet\",\n" +330 " \"consumes\": [\n" +331 " \"application/json\",\n" +332 " \"application/xml\"\n" +333 " ],\n" +334 " \"produces\": [\n" +335 " \"application/json\",\n" +336 " \"application/xml\"\n" +337 " ],\n" +338 " \"parameters\": [{\n" +339 " \"in\": \"body\",\n" +340 " \"name\": \"body\",\n" +341 " \"description\": \"Pet object that needs to be added to the store\",\n" +342 " \"required\": false,\n" +343 " \"schema\": {\n" +344 " \"$ref\": \"#/definitions/Pet\"\n" +345 " }\n" +346 " }],\n" +347 " \"responses\": {\n" +348 " \"405\": {\n" +349 " \"description\": \"Validation exception\"\n" +350 " },\n" +351 " \"404\": {\n" +352 " \"description\": \"Pet not found\"\n" +353 " },\n" +354 " \"400\": {\n" +355 " \"description\": \"Invalid ID supplied\"\n" +356 " }\n" +357 " },\n" +358 " \"security\": [{\n" +359 " \"petstore_auth\": [\n" +360 " \"write:pets\",\n" +361 " \"read:pets\"\n" +362 " ]\n" +363 " }]\n" +364 " }\n" +365 " },\n" +366 " \"securityDefinitions\": {\n" +367 " \"api_key\": {\n" +368 " \"type\": \"apiKey\",\n" +369 " \"name\": \"api_key\",\n" +370 " \"in\": \"header\"\n" +371 " },\n" +372 " \"petstore_auth\": {\n" +373 " \"type\": \"oauth2\",\n" +374 " \"authorizationUrl\": \"http://petstore.swagger.io/api/oauth/dialog\",\n" +375 " \"flow\": \"implicit\",\n" +376 " \"scopes\": {\n" +377 " \"write:pets\": \"modify pets in your account\",\n" +378 " \"read:pets\": \"read your pets\"\n" +379 " }\n" +380 " }\n" +381 " },\n" +382 " \"definitions\": {\n" +383 " \"Pet\": {\n" +384 " \"required\": [\n" +385 " \"name\",\n" +386 " \"photoUrls\"\n" +387 " ],\n" +388 " \"properties\": {\n" +389 " \"id\": {\n" +390 " \"type\": \"integer\",\n" +391 " \"format\": \"int64\"\n" +392 " },\n" +393 " \"category\": {\n" +394 " \"$ref\": \"#/definitions/Category\"\n" +395 " },\n" +396 " \"name\": {\n" +397 " \"type\": \"string\",\n" +398 " \"example\": \"doggie\"\n" +399 " },\n" +400 " \"photoUrls\": {\n" +401 " \"type\": \"array\",\n" +402 " \"xml\": {\n" +403 " \"name\": \"photoUrl\",\n" +404 " \"wrapped\": true\n" +405 " },\n" +406 " \"items\": {\n" +407 " \"type\": \"string\"\n" +408 " }\n" +409 " },\n" +410 " \"tags\": {\n" +411 " \"type\": \"array\",\n" +412 " \"xml\": {\n" +413 " \"name\": \"tag\",\n" +414 " \"wrapped\": true\n" +415 " },\n" +416 " \"items\": {\n" +417 " \"$ref\": \"#/definitions/Tag\"\n" +418 " }\n" +419 " },\n" +420 " \"status\": {\n" +421 " \"type\": \"string\",\n" +422 " \"description\": \"pet status in the store\",\n" +423 " \"enum\": [\n" +424 " \"available\",\n" +425 " \"pending\",\n" +426 " \"sold\"\n" +427 " ]\n" +428 " }\n" +429 " },\n" +430 " \"xml\": {\n" +431 " \"name\": \"Pet\"\n" +432 " }\n" +433 " }\n" +434 " }\n" +435 " }\n" +436 "}";437 ParseOptions options = new ParseOptions();438 options.setResolve(true);439 options.setFlatten(true);440 SwaggerParseResult result = new OpenAPIParser().readContents(inputSpec, null, options);441 assertTrue(result.getOpenAPI() != null);442 }443 @Test444 public void testIssue258() {445 ParseOptions options = new ParseOptions();446 options.setResolve(true);447 SwaggerParseResult result = new OpenAPIParser().readLocation("duplicateOperationId.json", null, options);448 System.out.println(result.getMessages());449 assertNotNull(result);450 assertNotNull(result.getOpenAPI());451 assertEquals(result.getMessages().get(0), "attribute paths.'/pets/{id}'(post).operationId is repeated");452 }453 @Test454 public void testIssueRelativeRefs2(){455 String location = "exampleSpecs/specs/my-domain/test-api/v1/test-api-swagger_v1.json";456 ParseOptions po = new ParseOptions();457 po.setResolve(true);458 SwaggerParseResult result = new OpenAPIParser().readLocation(location, null, po);459 assertNotNull(result.getOpenAPI());460 OpenAPI openAPI = result.getOpenAPI();461 Map<String, Schema> schemas = openAPI.getComponents().getSchemas();462 Assert.assertTrue(schemas.get("confirmMessageType_v01").getProperties().get("resources") instanceof ArraySchema);463 ArraySchema arraySchema = (ArraySchema) schemas.get("confirmMessageType_v01").getProperties().get("resources");464 Schema prop = (Schema) arraySchema.getItems().getProperties().get("resourceID");465 assertEquals(prop.get$ref(),"#/components/schemas/simpleIDType_v01");466 }467 @Test468 public void testIssueRelativeRefs1(){469 String location = "specs2/my-domain/test-api/v1/test-api-swagger_v1.json";470 ParseOptions po = new ParseOptions();471 po.setResolve(true);472 SwaggerParseResult result = new OpenAPIParser().readLocation(location, null, po);473 assertNotNull(result.getOpenAPI());474 OpenAPI openAPI = result.getOpenAPI();475 Map<String, Schema> schemas = openAPI.getComponents().getSchemas();476 Assert.assertTrue(schemas.get("test-api-schema_v01").getProperties().get("testingApi") instanceof ArraySchema);477 ArraySchema arraySchema = (ArraySchema) schemas.get("test-api-schema_v01").getProperties().get("testingApi");478 Schema prop = (Schema) arraySchema.getItems().getProperties().get("itemID");479 assertEquals(prop.get$ref(),"#/components/schemas/simpleIDType_v01");480 }481 @Test482 public void testIssue879() {483 OpenAPIParser openApiParser = new OpenAPIParser();484 ParseOptions options = new ParseOptions();485 OpenAPI openAPI = openApiParser.readLocation("issue_879.yaml", null, options).getOpenAPI();486 String ref = openAPI.getPaths()487 .get("/register")488 .getPost()489 .getCallbacks()490 .get("myEvent")491 .get$ref();492 assertEquals(ref, "#/components/callbacks/callbackEvent");493 }494 @Test495 public void testIssue959() {496 OpenAPIParser openAPIParser = new OpenAPIParser();497 SwaggerParseResult result = openAPIParser.readLocation("issue959.json",null,null);498 assertEquals(result.getMessages().get(0),"paths.'/pets/{petId}'(get).parameters. There are duplicate parameter values");499 result = openAPIParser.readLocation("issue959PathLevelDuplication.json",null,null);500 assertEquals(result.getMessages().get(0),"paths.'/pets'. There are duplicate parameter values");501 }502 @Test503 public void testIssue1003_ExtensionsClassloader() {504 ClassLoader tccl = Thread.currentThread().getContextClassLoader();505 SwaggerParseResult api = null;506 try {507 // Temporarily switch tccl to an unproductive cl508 final ClassLoader tcclTemp = new java.net.URLClassLoader(new java.net.URL[] {},509 ClassLoader.getSystemClassLoader());510 Thread.currentThread().setContextClassLoader(tcclTemp);511 api = new OpenAPIParser().readLocation("src/test/resources/petstore.yaml",null,null);512 } finally {513 Thread.currentThread().setContextClassLoader(tccl);514 }515 assertNotNull(api);516 }517 @Test518 public void testIssue1070() {519 SwaggerParseResult result = new OpenAPIParser().readLocation("issue1070.yaml", null, null);520 List required = result.getOpenAPI().getComponents().getSchemas().get("AmountAndCurrency").getRequired();521 assertEquals(required.size(), 2);522 assertTrue(required.contains("Amount"));523 assertTrue(required.contains("Currency"));524 }525 public void testIssue1086() {526 OpenAPIParser openApiParser = new OpenAPIParser();527 ParseOptions options = new ParseOptions();528 OpenAPI openAPI = openApiParser.readLocation("issue1086.yaml", null, options).getOpenAPI();529 Map<String, Schema> schemas = openAPI.getComponents().getSchemas();530 ObjectSchema schema = (ObjectSchema) schemas.get("AssessCandidate").getProperties().get("test_results");531 Schema score = schema.getProperties().get("score");532 assertEquals(score.getMultipleOf().intValue(), 1);533 }534 @Test535 public void testIssue1433_ResolveSchemaWithoutType() {536 OpenAPIParser openApiParser = new OpenAPIParser();537 ParseOptions options = new ParseOptions();538 options.setResolveFully(true);539 OpenAPI openAPI = openApiParser.readLocation("issue_1433-resolve-schema-without-type.yaml", null, options).getOpenAPI();540 final Schema requestBodySchema = openAPI.getPaths().get("/foo").getPost().getRequestBody().getContent().get("application/json").getSchema();541 assertNotNull(requestBodySchema);542 final Map properties = requestBodySchema.getProperties();543 assertEquals(properties.size(), 2);544 final Object bar = properties.get("bar");545 assertEquals(bar.getClass(), StringSchema.class);546 final Object input = properties.get("input");547 assertEquals(input.getClass(), Schema.class);548 final Map inputProperties = ((Schema) input).getProperties();549 assertNotNull(inputProperties);550 assertEquals(inputProperties.size(),1);551 final Object baz = inputProperties.get("baz");552 assertEquals(baz.getClass(), StringSchema.class);553 }554 @Test555 public void testMultipleOfBetweenZeroAndOne() {556 String spec =557 "openapi: 3.0.0\n" +558 "info:\n" +559 " version: 0.0.0\n" +560 " title: \"test\"\n" +561 "components:\n" +562 " schemas:\n" +563 " Test:\n" +564 " type: object\n" +565 " properties:\n" +566 " decimal_value:\n" +567 " type: number\n" +568 " multipleOf: 0.3\n";569 OpenAPIParser openApiParser = new OpenAPIParser();570 ParseOptions options = new ParseOptions();571 OpenAPI openAPI = openApiParser.readContents(spec, null, options).getOpenAPI();572 ObjectSchema schema = (ObjectSchema) openAPI.getComponents().getSchemas().get("Test");573 Schema decimalValue = schema.getProperties().get("decimal_value");574 BigDecimal multipleOf = decimalValue.getMultipleOf();575 assertEquals(multipleOf, new BigDecimal("0.3", new MathContext(multipleOf.precision())));576 }577 @Test578 public void testConvertWindowsPathsToUnixWhenResolvingServerPaths() {579 ParseOptions options = new ParseOptions();580 options.setResolve(true);581 SwaggerParseResult result = new OpenAPIParser().readLocation("exampleSpecs\\specs\\issue1553.yaml", null, options);582 assertEquals("/api/customer1/v1", result.getOpenAPI().getServers().get(0).getUrl());583 }584}...
Source:ExampleSpecs.java
...33import java.util.ArrayList;34import java.util.List;35import java.util.function.Supplier;36@RunWith(Spectrum.class)37public class ExampleSpecs {38 {39 describe("A spec", () -> {40 final int foo = 1;41 it("is just a code block that verifies something", () -> {42 assertEquals(1, foo);43 });44 it("can use any assertion library you like", () -> {45 org.junit.Assert.assertEquals(1, foo);46 org.hamcrest.MatcherAssert.assertThat(true, is(true));47 });48 describe("nested inside a second describe", () -> {49 final int bar = 1;50 it("can reference both scopes as needed", () -> {51 assertThat(bar, is(equalTo(foo)));52 });53 });54 it("can have `it`s and `describe`s in any order", () -> {55 assertThat(foo, is(1));56 });57 });58 describe("A suite using beforeEach and afterEach", () -> {59 final List<String> items = new ArrayList<>();60 beforeEach(() -> {61 items.add("foo");62 });63 beforeEach(() -> {64 items.add("bar");65 });66 afterEach(() -> {67 items.clear();68 });69 it("runs the beforeEach() blocks in order", () -> {70 assertThat(items, contains("foo", "bar"));71 items.add("bogus");72 });73 it("runs them before every spec", () -> {74 assertThat(items, contains("foo", "bar"));75 items.add("bogus");76 });77 it("runs afterEach after every spec", () -> {78 assertThat(items, not(contains("bogus")));79 });80 describe("when nested", () -> {81 beforeEach(() -> {82 items.add("baz");83 });84 it("runs beforeEach and afterEach from inner and outer scopes", () -> {85 assertThat(items, contains("foo", "bar", "baz"));86 });87 });88 });89 describe("A suite using beforeAll", () -> {90 final List<Integer> numbers = new ArrayList<>();91 beforeAll(() -> {92 numbers.add(1);93 });94 it("sets the initial state before any specs run", () -> {95 assertThat(numbers, contains(1));96 numbers.add(2);97 });98 describe("and afterAll", () -> {99 afterAll(() -> {100 numbers.clear();101 });102 it("does not reset anything between tests", () -> {103 assertThat(numbers, contains(1, 2));104 numbers.add(3);105 });106 it("so proceed with caution; this *will* leak shared state across specs", () -> {107 assertThat(numbers, contains(1, 2, 3));108 });109 });110 it("cleans up after running all specs in the describe block", () -> {111 assertThat(numbers, is(empty()));112 });113 });114 describe("a spec can have a context", () -> {115 context("surrounding the specs", () -> {116 it("helping to document the specification", () -> {117 });118 });119 });120 describe("selective running", () -> {121 context("with contexts", () -> {122 it("focusing is possible", ExampleSpecs::focusingContextExample);123 it("ignoring is possible", ExampleSpecs::ignoringContextExample);124 });125 });126 }127 private static void focusingContextExample() throws Exception {128 class Example {129 {130 describe("a spec with", () -> {131 fcontext("a focused context", () -> {132 it("runs the spec", () -> {133 });134 });135 it("doesn't run this one", () -> {136 });137 });...
ExampleSpecs
Using AI Code Generation
1import specs.ExampleSpecs;2class Example{3 public static void main(String[] args){4 ExampleSpecs obj = new ExampleSpecs();5 obj.display();6 }7}8import specs.ExampleSpecs;9class Example{10 public static void main(String[] args){11 ExampleSpecs obj = new ExampleSpecs();12 obj.display();13 }14}15import specs.ExampleSpecs;16class Example{17 public static void main(String[] args){18 ExampleSpecs obj = new ExampleSpecs();19 obj.display();20 }21}22import specs.ExampleSpecs;23class Example{24 public static void main(String[] args){25 ExampleSpecs obj = new ExampleSpecs();26 obj.display();27 }28}29import specs.ExampleSpecs;30class Example{31 public static void main(String[] args){32 ExampleSpecs obj = new ExampleSpecs();33 obj.display();34 }35}36import specs.ExampleSpecs;37class Example{38 public static void main(String[] args){39 ExampleSpecs obj = new ExampleSpecs();40 obj.display();41 }42}43import specs.ExampleSpecs;44class Example{45 public static void main(String[] args){46 ExampleSpecs obj = new ExampleSpecs();47 obj.display();48 }49}50import specs.ExampleSpecs;51class Example{52 public static void main(String[] args){53 ExampleSpecs obj = new ExampleSpecs();54 obj.display();55 }56}57import specs.ExampleSpecs;58class Example{59 public static void main(String[] args){60 ExampleSpecs obj = new ExampleSpecs();61 obj.display();62 }63}
ExampleSpecs
Using AI Code Generation
1package mypackage;2import specs.ExampleSpecs;3public class Example {4 public static void main(String[] args) {5 ExampleSpecs es = new ExampleSpecs();6 es.print();7 }8}9package specs;10public class ExampleSpecs {11 public void print() {12 System.out.println("Hello, World!");13 }14}15We can also import the package using the wildcard character * . It means that we are importing all the classes of the package. Let’s see an example:16package mypackage;17import specs.*;18public class Example {19 public static void main(String[] args) {20 ExampleSpecs es = new ExampleSpecs();21 es.print();22 }23}24package specs;25public class ExampleSpecs {26 public void print() {27 System.out.println("Hello, World!");28 }29}30We can also import a class using the wildcard character * . It means that we are importing all the static members of the class. Let’s see an example:31package mypackage;32import specs.ExampleSpecs.*;33public class Example {34 public static void main(String[] args) {35 ExampleSpecs es = new ExampleSpecs();36 es.print();37 }38}39package specs;40public class ExampleSpecs {41 public static void print() {42 System.out.println("Hello, World!");43 }44}45We can also import a single static member of a class. Let’s see an example:46package mypackage;47import static specs.ExampleSpec
ExampleSpecs
Using AI Code Generation
1package example;2import specs.ExampleSpecs;3public class Example {4 public static void main(String[] args) {5 ExampleSpecs exampleSpecs = new ExampleSpecs();6 System.out.println("exampleSpecs is " + exampleSpecs);7 }8}9package specs;10public class ExampleSpecs {11 public ExampleSpecs() {12 System.out.println("ExampleSpecs constructor");13 }14}15module example {16 requires java.base;17 requires specs;18}19module example {20 requires java.base;21 requires specs 1.0.0;22}23module example {24 requires java.base;25 requires specs;26 exports example;27 exports specs;28}29module example {30 requires java.base;31 requires specs;32 exports example to another;33 exports specs to another;34}35module example {36 requires java.base;37 requires specs;38 exports example;39 exports specs;40 opens example;41 opens specs;42}43module example {44 requires java.base;
ExampleSpecs
Using AI Code Generation
1import specs.ExampleSpecs;2import java.util.*;3public class ExampleSpecsTest {4 public static void main(String[] args) {5 ExampleSpecs ex = new ExampleSpecs();6 ex.setNum(10);7 ex.setStr("Hello");8 ex.setStrArray(new String[] {"Hello", "World"});9 ex.setStrList(new ArrayList<String>());10 ex.getStrList().add("Hello");11 ex.getStrList().add("World");12 System.out.println(ex);13 }14}15import specs.ExampleSpecs;16public class ExampleSpecsTest {17 public static void main(String[] args) {18 ExampleSpecs ex = new ExampleSpecs();19 ex.setNum(10);20 ex.setStr("Hello");21 ex.setStrArray(new String[] {"Hello", "World"});22 ex.setStrList(new ArrayList<String>());23 ex.getStrList().add("Hello");24 ex.getStrList().add("World");25 System.out.println(ex);26 }27}28import specs.ExampleSpecs;29import java.util.*;30public class ExampleSpecsTest {31 public static void main(String[] args) {32 ExampleSpecs ex = new ExampleSpecs();33 ex.setNum(10);34 ex.setStr("Hello");35 ex.setStrArray(new String[] {"Hello", "World"});36 ex.setStrList(new ArrayList<String>());37 ex.getStrList().add("Hello");38 ex.getStrList().add("World");39 System.out.println(ex);40 }41}42import specs.ExampleSpecs;43import java.util.*;44public class ExampleSpecsTest {45 public static void main(String[] args) {46 ExampleSpecs ex = new ExampleSpecs();47 ex.setNum(10);48 ex.setStr("Hello");49 ex.setStrArray(new String[] {"Hello", "World"});50 ex.setStrList(new ArrayList<String>());51 ex.getStrList().add("Hello");52 ex.getStrList().add("World");53 System.out.println(ex);54 }55}56import specs.ExampleSpecs
ExampleSpecs
Using AI Code Generation
1{2 public static void main(String args[])3 {4 System.out.println("Hello World!");5 }6}7import specs.ExampleSpecs;8{9 public static void main(String args[])10 {11 System.out.println("Hello World!");12 }13}
ExampleSpecs
Using AI Code Generation
1import specs.ExampleSpecs;2import java.io.*;3public class ExampleSpecsTest {4 public static void main(String args[]) {5 ExampleSpecs obj = new ExampleSpecs();6 obj.print();7 }8}9package specs;10public class ExampleSpecs {11 public void print() {12 System.out.println("Hello World");13 }14}15import specs.ExampleSpecs;16import java.io.*;17public class ExampleSpecsTest {18 public static void main(String args[]) {19 ExampleSpecs obj = new ExampleSpecs();20 obj.print();21 }22}23package specs;24public class ExampleSpecs {25 public void print() {26 System.out.println("Hello World");27 }28}29import specs.ExampleSpecs;30import java.io.*;31public class ExampleSpecsTest {32 public static void main(String args[]) {33 ExampleSpecs obj = new ExampleSpecs();34 obj.print();35 }36}37package specs;38public class ExampleSpecs {39 public void print() {40 System.out.println("Hello World");41 }42}43import specs.ExampleSpecs;44import java.io.*;45public class ExampleSpecsTest {46 public static void main(String args[]) {47 ExampleSpecs obj = new ExampleSpecs();48 obj.print();49 }50}51package specs;52public class ExampleSpecs {53 public void print() {54 System.out.println("Hello World");55 }56}
ExampleSpecs
Using AI Code Generation
1package myPackage;2import specs.ExampleSpecs;3public class 1 {4public static void main(String[] args) {5System.out.println("Hello");6ExampleSpecs ex = new ExampleSpecs();7ex.printExample();8}9}10package specs;11public class ExampleSpecs {12public void printExample() {13System.out.println("ExampleSpecs");14}15}
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!