當前位置: 首頁>>代碼示例>>Java>>正文


Java JSONCompareMode類代碼示例

本文整理匯總了Java中org.skyscreamer.jsonassert.JSONCompareMode的典型用法代碼示例。如果您正苦於以下問題:Java JSONCompareMode類的具體用法?Java JSONCompareMode怎麽用?Java JSONCompareMode使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JSONCompareMode類屬於org.skyscreamer.jsonassert包,在下文中一共展示了JSONCompareMode類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: assertEqualsJson

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的package包/類
public static void assertEqualsJson(String expectedJson, String actualJson, JSONCompareMode compareMode) {

        try {
            JSONCompareResult result = compareJSON(expectedJson, actualJson, compareMode);

            if (result.failed()) {
                String failureMessage = result.getMessage();
                if (failureMessage != null) {
                    failureMessage = failureMessage.replaceAll(" ; ", "\n");
                }
                failureMessage = "\n================ Expected JSON ================"
                        + new JSONObject(expectedJson).toString(4)
                        + "\n================= Actual JSON ================="
                        + new JSONObject(actualJson).toString(4)
                        + "\n================= Error List ==================\n"
                        + failureMessage + "\n\n";
                fail(failureMessage);
            }
        } catch (JSONException e) {
            throw new RuntimeException("JSON completely failed to parse json", e);
        }
    }
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:23,代碼來源:JsonAssert.java

示例2: shouldValidatePodConfigurationWhenSpecifiedAsYaml

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的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

示例3: shouldAllowPodYamlConfiguration

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的package包/類
@Test
public void shouldAllowPodYamlConfiguration() throws Exception {
    Map<String, String> properties = new HashMap<>();
    properties.put("SpecifiedUsingPodConfiguration", "true");
    String podYaml = "apiVersion: v1\n" +
            "kind: Pod\n" +
            "metadata:\n" +
            "  name: pod-name\n" +
            "  labels:\n" +
            "    app: web\n" +
            "spec:\n" +
            "  containers:\n" +
            "    - name: gocd-agent-container\n" +
            "      image: gocd/fancy-agent-image:latest";

    properties.put("PodConfiguration", podYaml);
    ProfileValidateRequestExecutor executor = new ProfileValidateRequestExecutor(new ProfileValidateRequest(properties));
    String json = executor.execute().responseBody();
    JSONAssert.assertEquals("[]", json, JSONCompareMode.NON_EXTENSIBLE);
}
 
開發者ID:gocd,項目名稱:kubernetes-elastic-agents,代碼行數:21,代碼來源:ProfileValidateRequestExecutorTest.java

示例4: shouldAllowGinjaTemplatedPodYaml

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的package包/類
@Test
public void shouldAllowGinjaTemplatedPodYaml() throws Exception {
    Map<String, String> properties = new HashMap<>();
    properties.put("SpecifiedUsingPodConfiguration", "true");
    String podYaml = "apiVersion: v1\n" +
            "kind: Pod\n" +
            "metadata:\n" +
            "  name: pod-name-prefix-{{ POD_POSTFIX }}\n" +
            "  labels:\n" +
            "    app: web\n" +
            "spec:\n" +
            "  containers:\n" +
            "    - name: gocd-agent-container-{{ CONTAINER_POSTFIX }}\n" +
            "      image: {{ GOCD_AGENT_IMAGE }}:{{ LATEST_VERSION }}";

    properties.put("PodConfiguration", podYaml);
    ProfileValidateRequestExecutor executor = new ProfileValidateRequestExecutor(new ProfileValidateRequest(properties));
    String json = executor.execute().responseBody();
    JSONAssert.assertEquals("[]", json, JSONCompareMode.NON_EXTENSIBLE);
}
 
開發者ID:gocd,項目名稱:kubernetes-elastic-agents,代碼行數:21,代碼來源:ProfileValidateRequestExecutorTest.java

示例5: verifyRedisRepresentation

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的package包/類
@Test
public void verifyRedisRepresentation() throws JSONException {
	OgmSession session = openSession();
	session.getTransaction().begin();

	// given
	Donut donut = new Donut( "homers-donut", 7.5, Donut.Glaze.Pink, "pink-donut" );
	session.persist( donut );

	session.getTransaction().commit();

	// when
	String representation = getConnection().get( "Donut:homers-donut" );

	// then
	JSONAssert.assertEquals(
			"{'alias':'pink-donut','radius':7.5,'glaze':2}",
			representation,
			JSONCompareMode.STRICT
	);

	session.close();
}
 
開發者ID:hibernate,項目名稱:hibernate-ogm-redis,代碼行數:24,代碼來源:RedisJsonMappingTest.java

示例6: testSubsegmentEmittedInLambdaContext

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的package包/類
@Test
public void testSubsegmentEmittedInLambdaContext() throws JSONException {
    TraceHeader header = TraceHeader.fromString(TRACE_HEADER);

    PowerMockito.stub(PowerMockito.method(LambdaSegmentContext.class, "getTraceHeaderFromEnvironment")).toReturn(header);
    PowerMockito.stub(PowerMockito.method(LambdaSegmentContextResolver.class, "getLambdaTaskRoot")).toReturn("/var/task");

    Emitter mockEmitter = Mockito.mock(UDPEmitter.class);
    AWSXRayRecorder recorder = AWSXRayRecorderBuilder.standard().withEmitter(mockEmitter).build();
    recorder.createSubsegment("test", () -> {});

    ArgumentCaptor<Subsegment> emittedSubsegment = ArgumentCaptor.forClass(Subsegment.class);
    Mockito.verify(mockEmitter, Mockito.times(1)).sendSubsegment(emittedSubsegment.capture());

    Subsegment captured = emittedSubsegment.getValue();

    JSONAssert.assertEquals(expectedLambdaSubsegment(header.getRootTraceId(), header.getParentId(), captured.getId(), captured.getStartTime(), captured.getEndTime()).toString(), captured.streamSerialize(), JSONCompareMode.NON_EXTENSIBLE);
}
 
開發者ID:aws,項目名稱:aws-xray-sdk-java,代碼行數:19,代碼來源:AWSXRayRecorderTest.java

示例7: shouldValidateMandatoryKeys

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的package包/類
@Test
public void shouldValidateMandatoryKeys() throws Exception {
    when(request.requestBody()).thenReturn(new Gson().toJson(Collections.emptyMap()));

    GoPluginApiResponse response = AuthConfigValidateRequest.from(request).execute();
    String json = response.responseBody();

    String expectedJSON = "[\n" +
            "  {\n" +
            "    \"message\": \"ClientId must not be blank.\",\n" +
            "    \"key\": \"ClientId\"\n" +
            "  },\n" +
            "  {\n" +
            "    \"message\": \"ClientSecret must not be blank.\",\n" +
            "    \"key\": \"ClientSecret\"\n" +
            "  }\n" +
            "]";

    JSONAssert.assertEquals(expectedJSON, json, JSONCompareMode.NON_EXTENSIBLE);
}
 
開發者ID:gocd-contrib,項目名稱:google-oauth-authorization-plugin,代碼行數:21,代碼來源:AuthConfigValidateRequestExecutorTest.java

示例8: shouldBarfWhenUnknownKeysArePassed

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的package包/類
@Test
public void shouldBarfWhenUnknownKeysArePassed() throws Exception {
    when(request.requestBody()).thenReturn(new Gson().toJson(Collections.singletonMap("foo", "bar")));

    GoPluginApiResponse response = new AuthConfigValidateRequestExecutor(request).execute();
    String json = response.responseBody();

    String expectedJSON = "[\n" +
            "  {\n" +
            "    \"message\": \"PasswordFilePath must not be blank.\",\n" +
            "    \"key\": \"PasswordFilePath\"\n" +
            "  },\n" +
            "  {\n" +
            "    \"key\": \"foo\",\n" +
            "    \"message\": \"Is an unknown property\"\n" +
            "  }\n" +
            "]";
    JSONAssert.assertEquals(expectedJSON, json, JSONCompareMode.NON_EXTENSIBLE);
}
 
開發者ID:gocd,項目名稱:gocd-filebased-authentication-plugin,代碼行數:20,代碼來源:AuthConfigValidateRequestExecutorTest.java

示例9: shouldReturnValidationFailedStatusForInvalidAuthConfig

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的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

示例10: shouldReturnSuccessResponseOnSuccessfulVerification

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的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

示例11: shouldValidateMandatoryKeys

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的package包/類
@Test
public void shouldValidateMandatoryKeys() throws Exception {
    when(request.requestBody()).thenReturn(new Gson().toJson(singletonMap("AuthorizeUsing", "UserAccessToken")));

    GoPluginApiResponse response = AuthConfigValidateRequest.from(request).execute();
    String json = response.responseBody();

    String expectedJSON = "[\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" +
            "]";

    JSONAssert.assertEquals(expectedJSON, json, JSONCompareMode.NON_EXTENSIBLE);
}
 
開發者ID:gocd-contrib,項目名稱:github-oauth-authorization-plugin,代碼行數:21,代碼來源:AuthConfigValidateRequestExecutorTest.java

示例12: shouldValidateGitHubEnterpriseUrl

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的package包/類
@Test
public void shouldValidateGitHubEnterpriseUrl() throws Exception {
    when(request.requestBody()).thenReturn("{\n" +
            "  \"ClientId\": \"client-id\",\n" +
            "  \"AllowedOrganizations\": \"example-1,example-2\",\n" +
            "  \"AuthenticateWith\": \"GitHubEnterprise\",\n" +
            "  \"ClientSecret\": \"client-secret\",\n" +
            "  \"AuthorizeUsing\": \"UserAccessToken\"\n" +
            "}");

    GoPluginApiResponse response = AuthConfigValidateRequest.from(request).execute();

    String expectedJSON = "[\n" +
            "  {\n" +
            "    \"key\": \"GitHubEnterpriseUrl\",\n" +
            "    \"message\": \"GitHubEnterpriseUrl must not be blank.\"\n" +
            "  }\n" +
            "]";

    JSONAssert.assertEquals(expectedJSON, response.responseBody(), JSONCompareMode.NON_EXTENSIBLE);
}
 
開發者ID:gocd-contrib,項目名稱:github-oauth-authorization-plugin,代碼行數:22,代碼來源:AuthConfigValidateRequestExecutorTest.java

示例13: shouldValidatePersonalAccessTokenWhenUsePersonalAccessTokenIsSetToTrue

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的package包/類
@Test
public void shouldValidatePersonalAccessTokenWhenUsePersonalAccessTokenIsSetToTrue() throws Exception {
    final GitHubConfiguration gitHubConfiguration = GitHubConfiguration.fromJSON("{\n" +
            "  \"ClientId\": \"client-id\",\n" +
            "  \"AllowedOrganizations\": \"example-1,example-2\",\n" +
            "  \"AuthenticateWith\": \"GitHubEnterprise\",\n" +
            "  \"GitHubEnterpriseUrl\": \"https://enterprise.url\",\n" +
            "  \"ClientSecret\": \"client-secret\",\n" +
            "  \"AuthorizeUsing\": \"PersonalAccessToken\"\n" +
            "}");

    when(request.requestBody()).thenReturn(gitHubConfiguration.toJSON());

    GoPluginApiResponse response = AuthConfigValidateRequest.from(request).execute();

    String expectedJSON = "[\n" +
            "  {\n" +
            "    \"key\": \"PersonalAccessToken\",\n" +
            "    \"message\": \"PersonalAccessToken must not be blank.\"\n" +
            "  }\n" +
            "]";

    JSONAssert.assertEquals(expectedJSON, response.responseBody(), JSONCompareMode.NON_EXTENSIBLE);
}
 
開發者ID:gocd-contrib,項目名稱:github-oauth-authorization-plugin,代碼行數:25,代碼來源:AuthConfigValidateRequestExecutorTest.java

示例14: shouldValidateEmptyRoleConfig

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的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

示例15: shouldValidateRoleConfigWithBadTeamsValueFormat

import org.skyscreamer.jsonassert.JSONCompareMode; //導入依賴的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


注:本文中的org.skyscreamer.jsonassert.JSONCompareMode類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。