当前位置: 首页>>代码示例>>Java>>正文


Java JSONAssert类代码示例

本文整理汇总了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);
}
 
开发者ID:gocd,项目名称:kubernetes-elastic-agents,代码行数:18,代码来源:ValidateConfigurationExecutorTest.java

示例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);
}
 
开发者ID:gocd,项目名称:kubernetes-elastic-agents,代码行数:18,代码来源:ValidateConfigurationExecutorTest.java

示例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);
}
 
开发者ID:gocd,项目名称:kubernetes-elastic-agents,代码行数:10,代码来源:ProfileValidateRequestExecutorTest.java

示例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);
}
 
开发者ID:fnproject,项目名称:fdk-java,代码行数:19,代码来源:RegexQueryTests.java

示例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);
}
 
开发者ID:rapid-io,项目名称:rapid-io-android,代码行数:17,代码来源:MessageJsonTest.java

示例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);
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:17,代码来源:TupleQueryResultJsonSerializerTest.java

示例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);
}
 
开发者ID:dotwebstack,项目名称:dotwebstack-framework,代码行数:25,代码来源:JsonTupleEntityWriterTest.java

示例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);
        }
    }
}
 
开发者ID:tyro,项目名称:pact-spring-mvc,代码行数:19,代码来源:JsonResponseBodyMatcher.java

示例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);

}
 
开发者ID:gocd-contrib,项目名称:github-oauth-authorization-plugin,代码行数:18,代码来源:GitHubConfigurationTest.java

示例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);
}
 
开发者ID:mazzeb,项目名称:gradle-auto-version,代码行数:18,代码来源:VersionSerializerTest.java


注:本文中的org.skyscreamer.jsonassert.JSONAssert类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。