restAssured проверка схемы json - сбой при чтении утверждения файла схемы json

Я использую restAssured для проверки моей схемы json. Ниже мой сценарий утверждения: String JsonString = response.asString (); Assert.assertEquals (JsonString, matchJsonSchemaInClasspath ("quotesschema.json"));

И я поместил свой файл quotesschema.json в папку project / bin.

Когда я запускаю свой тестовый скрипт, утверждение не выполняется с сообщением ниже java.lang.AssertionError: ожидаемый [], но обнаружен [фактический ответ api]

Кроме того, я проверил свою схему по ответу api через http://json-schema-validator.herokuapp.com/ валидатор схемы.

Не уверен, читает ли он мою схему внутри файла .son. Ниже моя схема.

{
    "type": "object",
    "$schema": "http://json-schema.org/draft-03/schema",
    "title": "quotes-schema",
    "description": "JSON Schema for Quotes",
        "properties": {
            "result": {
                "type": "object",
                "properties": {
                    "Quotes": {
                        "type": "array",
                            "properties": {
                                "DisplaySymbol": {
                                    "type": "string"
                                    },
                                "Identifier": {
                                    "type": "string"                                    
                                    },
                                "Exchange": {
                                    "type": "string"
                                    },
                                "Trade": {
                                    "type": "string"
                                    },
                                "Date": {
                                    "type": "string"
                                    },
                                "Change": {
                                    "type": "string"
                                    },
                                "Bid": {
                                    "type": "string"
                                    },
                                "BidSize": {
                                    "type": "string"
                                    },
                                "Ask": {
                                    "type": "string"
                                    },
                                "AskSize": {
                                    "type": "string"
                                    },
                                "High": {
                                    "type": "string"
                                    },
                                "Low": {
                                    "type": "string"
                                    },
                                "Volume": {
                                    "type": "string"
                                    },
                                "Open": {
                                    "type": "string"
                                    },
                                "PreviousClose": {
                                    "type": "string"
                                    },
                                "High52Week": {
                                    "type": "string"
                                    },
                                "High52WeekDate": {
                                    "type": "string"
                                    },
                                "Low52Week": {
                                    "type": "string"
                                    },
                                "Low52WeekDate": {
                                    "type": "string"
                                    },
                                "PERatio": {
                                    "type": "string"
                                    },
                                "MarketCap": {
                                    "type": "string"
                                    },
                                "SharesOutstanding": {
                                    "type": "string"
                                    },
                                "RollingEPS": {
                                    "type": "string"
                                    },
                                "IsDefault": {
                                    "type": "string"
                                    },
                                "IsIndex": {
                                    "type": "string"
                                    },
                                "Class": {
                                    "type": "string"
                                    }
                            }
                        }
                    }
                }
}
}

person hrs    schedule 20.01.2016    source источник


Ответы (1)


matchesJsonSchemaInClasspath метод возвращает JsonSchemaValidator класс, а не String.

Вот почему ваш Assert не будет работать там, где сравниваются строки:

JsonString = response.asString();
Assert.assertEquals(JsonString,matchesJsonSchemaInClasspath("quotesschema.json"));   

Фактическое использование должно быть внутри body() метода, как описано ниже:

get("RESTPATH").then().assertThat().body(matchesJsonSchemaInClasspath("quotesschema.json"));
person parishodak    schedule 22.01.2016