本文整理汇总了Java中org.skyscreamer.jsonassert.JSONAssert类的典型用法代码示例。如果您正苦于以下问题:Java JSONAssert类的具体用法?Java JSONAssert怎么用?Java JSONAssert使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JSONAssert类属于org.skyscreamer.jsonassert包,在下文中一共展示了JSONAssert类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: shouldReturnSuccessResponseOnSuccessfulVerification
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Test
public void shouldReturnSuccessResponseOnSuccessfulVerification() throws Exception {
final GitHubConfiguration gitHubConfiguration = mock(GitHubConfiguration.class);
when(request.githubConfiguration()).thenReturn(gitHubConfiguration);
GoPluginApiResponse response = executor.execute();
String expectedJSON = "{\n" +
" \"message\": \"Connection ok\",\n" +
" \"status\": \"success\"\n" +
"}";
assertThat(response.responseCode(), is(200));
JSONAssert.assertEquals(expectedJSON, response.responseBody(), JSONCompareMode.NON_EXTENSIBLE);
}
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:17,代码来源:VerifyConnectionRequestExecutorTest.java
示例2: shouldValidateSecureSiteUrl
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Test
public void shouldValidateSecureSiteUrl() throws Exception {
ValidatePluginSettings settings = new ValidatePluginSettings();
serverInfo.setSecureSiteUrl(null);
settings.put("kubernetes_cluster_url", "https://cluster.example.com");
settings.put("auto_register_timeout", "10");
settings.put("pending_pods_count", "10");
GoPluginApiResponse response = new ValidateConfigurationExecutor(settings, pluginRequest).execute();
assertThat(response.responseCode(), is(200));
JSONAssert.assertEquals("[" +
" {\n" +
" \"message\": \"Secure site url is not configured. Please specify Go Server Url.\",\n" +
" \"key\": \"go_server_url\"\n" +
" }\n" +
"]", response.responseBody(), true);
}
示例3: shouldValidateGoServerUrlFormat
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Test
public void shouldValidateGoServerUrlFormat() throws Exception {
ValidatePluginSettings settings = new ValidatePluginSettings();
settings.put("go_server_url", "https://foo.com");
settings.put("kubernetes_cluster_url", "https://cluster.example.com");
settings.put("auto_register_timeout", "10");
settings.put("pending_pods_count", "10");
GoPluginApiResponse response = new ValidateConfigurationExecutor(settings, pluginRequest).execute();
assertThat(response.responseCode(), is(200));
JSONAssert.assertEquals("[" +
" {\n" +
" \"message\": \"Go Server URL must be in format https://<GO_SERVER_URL>:<GO_SERVER_PORT>/go.\",\n" +
" \"key\": \"go_server_url\"\n" +
" }\n" +
"]", response.responseBody(), true);
}
示例4: shouldValidateEmptyRoleConfig
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Test
public void shouldValidateEmptyRoleConfig() throws Exception {
when(request.requestBody()).thenReturn(new Gson().toJson(Collections.emptyMap()));
GoPluginApiResponse response = RoleConfigValidateRequest.from(request).execute();
String json = response.responseBody();
String expectedJSON = "[\n" +
" {\n" +
" \"key\": \"Users\",\n" +
" \"message\": \"At least one of the fields(organizations,teams or users) should be specified.\"\n" +
" },\n" +
" {\n" +
" \"key\": \"Teams\",\n" +
" \"message\": \"At least one of the fields(organizations,teams or users) should be specified.\"\n" +
" },\n" +
" {\n" +
" \"key\": \"Organizations\",\n" +
" \"message\": \"At least one of the fields(organizations,teams or users) should be specified.\"\n" +
" }\n" +
"]";
JSONAssert.assertEquals(expectedJSON, json, JSONCompareMode.NON_EXTENSIBLE);
}
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:25,代码来源:RoleConfigValidateRequestExecutorTest.java
示例5: shouldValidatePodConfigurationWhenSpecifiedAsYaml
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Test
public void shouldValidatePodConfigurationWhenSpecifiedAsYaml() throws Exception {
Map<String, String> properties = new HashMap<>();
properties.put("SpecifiedUsingPodConfiguration", "true");
properties.put("PodConfiguration", "this is my invalid fancy pod yaml!!");
ProfileValidateRequestExecutor executor = new ProfileValidateRequestExecutor(new ProfileValidateRequest(properties));
String json = executor.execute().responseBody();
JSONAssert.assertEquals("[{\"message\":\"Invalid Pod Yaml.\",\"key\":\"PodConfiguration\"}]", json, JSONCompareMode.NON_EXTENSIBLE);
}
示例6: matchingSingleCharacter
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Test
public void matchingSingleCharacter() throws JSONException {
String text = "a";
String regex = ".";
fn.givenEvent()
.withMethod("POST")
.withBody(String.format("{\"text\": \"%s\", \"regex\": \"%s\"}", text, regex))
.enqueue();
fn.thenRun(RegexQuery.class, "query");
JSONAssert.assertEquals(String.format("{\"text\":\"%s\"," +
"\"regex\":\"%s\"," +
"\"matches\":[" +
"{\"start\": 0, \"end\": 1, \"match\": \"a\"}" +
"]}", text, regex),
fn.getOnlyResult().getBodyAsString(), false);
}
示例7: test_model2jsonSub
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Test
public void test_model2jsonSub() throws Exception {
Message.Sub subMsg = new Message.Sub("collection", "subscriptionId");
EntityOrder order = new EntityOrder();
order.putOrder("manufacturer", Sorting.ASC);
order.putOrder("model", Sorting.DESC);
subMsg.setOrder(order);
Filter.Group filter = new Filter.And();
filter.add(new FilterValue("model", new FilterValue.StringPropertyValue(TYPE_EQUAL, "A5")));
subMsg.setFilter(filter);
subMsg.setLimit(10);
subMsg.setSkip(0);
JSONAssert.assertEquals(subMsg.toJson().toString(), "{\"sub\": {\"evt-id\": \""+subMsg.getEventId()+"\", \"col-id\":\"collection\", " +
"\"sub-id\":\"subscriptionId\", \"filter\":{\"and\":[{\"model\":\"A5\"}]}, \"order\":[{\"manufacturer\":\"asc\"}," +
"{\"model\":\"desc\"}], \"limit\":10,\"skip\":0}}", false);
}
示例8: serialize_GivesEmptyResult_WhenQueryIsEmpty
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Test
public void serialize_GivesEmptyResult_WhenQueryIsEmpty() throws IOException, JSONException {
// Arrange
JsonFactory factory = new JsonFactory();
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
JsonGenerator jsonGenerator = factory.createGenerator(outputStream);
when(tupleQueryResult.hasNext()).thenReturn(false);
// Act
jsonSerializer.serialize(tupleQueryResult, jsonGenerator, null);
// Assert
jsonGenerator.close();
String result = outputStream.toString();
JSONAssert.assertEquals("[]", result, true);
}
示例9: writeTo_SparqlResultJsonFormat_ForQueryResult
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Test
public void writeTo_SparqlResultJsonFormat_ForQueryResult() throws IOException, JSONException {
// Arrange
final JsonTupleEntityWriter provider = new JsonTupleEntityWriter();
when(tupleEntity.getQueryResult()).thenReturn(tupleQueryResult);
when(tupleQueryResult.hasNext()).thenReturn(true, true, false);
BindingSet bindingSetHeineken = mock(BindingSet.class);
BindingSet bindingSetAmstel = mock(BindingSet.class);
when(tupleQueryResult.next()).thenReturn(bindingSetHeineken, bindingSetAmstel);
configureBindingSetWithValue(bindingSetHeineken, "Heineken");
configureBindingSetWithValue(bindingSetAmstel, "Amstel");
// Act
provider.writeTo(tupleEntity, null, null, null, null, null, outputStream);
// Assert
verify(outputStream).write(byteCaptor.capture(), anyInt(), anyInt());
String result = new String(byteCaptor.getValue());
JSONArray expected = new JSONArray().put(new JSONObject().put("beer", "Heineken")).put(
new JSONObject().put("beer", "Amstel"));
JSONAssert.assertEquals(expected.toString(), result, true);
}
示例10: match
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Override
public void match(MvcResult result) throws Exception {
String content = result.getResponse().getContentAsString();
final JsonParser parser = new JsonParser();
final JsonElement actual = parser.parse(content);
if (actual.isJsonPrimitive()) {
final JsonElement expected = parser.parse(expectedJsonResponse);
assertThat(actual, is(expected));
} else {
try {
JSONAssert.assertEquals(expectedJsonResponse, content, false);
} catch (AssertionError e) {
throw new ComparisonFailure(e.getMessage(), expectedJsonResponse, content);
}
}
}
示例11: shouldReturnValidationFailedStatusForInvalidAuthConfig
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Test
public void shouldReturnValidationFailedStatusForInvalidAuthConfig() throws Exception {
when(request.githubConfiguration()).thenReturn(new GitHubConfiguration());
GoPluginApiResponse response = executor.execute();
String expectedJSON = "{\n" +
" \"message\": \"Validation failed for the given Auth Config\",\n" +
" \"errors\": [\n" +
" {\n" +
" \"key\": \"ClientId\",\n" +
" \"message\": \"ClientId must not be blank.\"\n" +
" },\n" +
" {\n" +
" \"key\": \"ClientSecret\",\n" +
" \"message\": \"ClientSecret must not be blank.\"\n" +
" }\n" +
" ],\n" +
" \"status\": \"validation-failed\"\n" +
"}";
assertThat(response.responseCode(), is(200));
JSONAssert.assertEquals(expectedJSON, response.responseBody(), JSONCompareMode.NON_EXTENSIBLE);
}
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:25,代码来源:VerifyConnectionRequestExecutorTest.java
示例12: shouldFetchAccessToken
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Test
public void shouldFetchAccessToken() throws Exception {
final TokenInfo tokenInfo = new TokenInfo("31239032-xycs.xddasdasdasda", 7200, "foo-type", "refresh-xysaddasdjlascdas");
when(request.authConfigs()).thenReturn(Collections.singletonList(authConfig));
when(request.requestParameters()).thenReturn(Collections.singletonMap("code", "code-received-in-previous-step"));
when(googleApiClient.fetchAccessToken(request.requestParameters())).thenReturn(tokenInfo);
final GoPluginApiResponse response = executor.execute();
final String expectedJSON = "{\n" +
" \"access_token\": \"31239032-xycs.xddasdasdasda\",\n" +
" \"expires_in\": 7200,\n" +
" \"token_type\": \"foo-type\",\n" +
" \"refresh_token\": \"refresh-xysaddasdjlascdas\"\n" +
"}";
assertThat(response.responseCode(), is(200));
JSONAssert.assertEquals(expectedJSON, response.responseBody(), true);
}
开发者ID:gocd-contrib,项目名称:google-oauth-authorization-plugin,代码行数:22,代码来源:FetchAccessTokenRequestExecutorTest.java
示例13: shouldValidateRoleConfigWithBadTeamsValueFormat
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Test
public void shouldValidateRoleConfigWithBadTeamsValueFormat() throws Exception {
when(request.requestBody()).thenReturn(new Gson().toJson(singletonMap("Teams", "Org")));
GoPluginApiResponse response = RoleConfigValidateRequest.from(request).execute();
String json = response.responseBody();
String expectedJSON = "[\n" +
" {\n" +
" \"key\": \"Teams\",\n" +
" \"message\": \"Invalid format. It should be in <organization>:<team-1>,<team-2> format.\"\n" +
" }\n" +
"]";
JSONAssert.assertEquals(expectedJSON, json, JSONCompareMode.NON_EXTENSIBLE);
}
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:17,代码来源:RoleConfigValidateRequestExecutorTest.java
示例14: shouldSerializeToJSON
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Test
public void shouldSerializeToJSON() throws Exception {
GitHubConfiguration gitHubConfiguration = new GitHubConfiguration("client-id", "client-secret",
AuthenticateWith.GITHUB_ENTERPRISE, "http://enterprise.url", "example-1");
String expectedJSON = "{\n" +
" \"ClientId\": \"client-id\",\n" +
" \"ClientSecret\": \"client-secret\",\n" +
" \"AuthenticateWith\": \"GitHubEnterprise\",\n" +
" \"GitHubEnterpriseUrl\": \"http://enterprise.url\",\n" +
" \"AllowedOrganizations\": \"example-1\",\n" +
" \"AuthorizeUsing\": PersonalAccessToken\n" +
"}";
JSONAssert.assertEquals(expectedJSON, gitHubConfiguration.toJSON(), true);
}
示例15: shouldSerializeVersion
import org.skyscreamer.jsonassert.JSONAssert; //导入依赖的package包/类
@Test
public void shouldSerializeVersion() throws Exception {
Version version = versionBuilder()
.withMajor(2L)
.withMinor(4L)
.withPatch(1L)
.withLabel("someLabel")
.build();
JsonElement serialize = testee.serialize(version, null, null);
JSONAssert.assertEquals(serialize.toString(), "{\n" +
" \"major\": 2,\n" +
" \"minor\": 4,\n" +
" \"patch\": 1,\n" +
" \"label\": \"someLabel\"\n" +
"}", false);
}