<commit_before>package com.siftscience;

import com.siftscience.model.ApplyDecisionFieldSet;
import okhttp3.HttpUrl;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.Assert;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;

import static com.siftscience.model.ApplyDecisionFieldSet.*;
import static java.net.HttpURLConnection.HTTP_OK;

public class ApplyDecisionTest {

    @Test
    public void testApplyDecisionToUserEntity() throws Exception {
        String requestBody =
        "{\n" +
            "\"decision_id\": \"looks_ok_account_abuse\",\n" +
            "\"source\": \"manual_review\",\n" +
            "\"analyst\":\"<EMAIL>\",\n" +
            "\"time\": 1480618362\n" +
        "}";

        String responseBody =
        "{" +
            "\"time\":" + System.currentTimeMillis() + "," +
            "\"request\":" + requestBody + "," +
            "\"status\":" + 0 + "," +
            "\"error_message\":\"OK\"" +
        "}";

        MockWebServer server = new MockWebServer();
        MockResponse response = new MockResponse();
        response.setResponseCode(HTTP_OK);
        response.setBody(responseBody);

        server.enqueue(response);
        server.start();

        String accountId = "your_account_id";
        String userId = "a_user_id";

        HttpUrl baseApi3Url = server.url("").newBuilder().build();

        // Create a new client and link it to the mock server.
        SiftClient client = new SiftClient("your_api_key");
        client.setBaseApi3Url(baseApi3Url);

        // Build and execute the request against the mock server.
        ApplyDecisionRequest request = client.buildRequest(
                new ApplyDecisionFieldSet()
                        .setAccountId(accountId)
                        .setUserId(userId)
                        .setDecisionId("looks_ok_account_abuse")
                        .setSource(DecisionSource.MANUAL_REVIEW)
                        .setAnalyst("<EMAIL>")
                        .setTime(System.currentTimeMillis()));

        ApplyDecisionResponse siftResponse = request.send();

        // Verify the request.
        RecordedRequest request1 = server.takeRequest();
        Assert.assertEquals("POST", request1.getMethod());
        Assert.assertEquals("/v3/accounts/" + accountId + "/users/" + userId + "/decisions",
                request1.getPath());
        Assert.assertEquals(request1.getHeader("Authorization"), "Basic eW91cl9hcGlfa2V5Og==");

        // Verify the response was parsed correctly.
        Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode());
        JSONAssert.assertEquals(response.getBody().readUtf8(),
                siftResponse.getBody().toJson(), true);
    }

    @Test
    public void testApplyDecisionToOrderEntity() throws Exception {
        String requestBody =
                "{" +
                    "\"decision_id\":\"looks_ok_account_abuse\"," +
                    "\"source\":\"automated_rule\"," +
                    "\"time\":1480618362" +
                "}";

        String responseBody =
                "{" +
                    "\"time\":" + System.currentTimeMillis() + "," +
                    "\"request\":" + requestBody + "," +
                    "\"status\":" + 0 + "," +
                    "\"error_message\":\"OK\"" +
                "}";<commit_msg>update response form in test<commit_after>package com.siftscience;

import com.siftscience.model.ApplyDecisionFieldSet;
import okhttp3.HttpUrl;
import okhttp3.mockwebserver.MockResponse;
import okhttp3.mockwebserver.MockWebServer;
import okhttp3.mockwebserver.RecordedRequest;
import org.junit.Assert;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;

import static com.siftscience.model.ApplyDecisionFieldSet.*;
import static java.net.HttpURLConnection.HTTP_OK;

public class ApplyDecisionTest {

    @Test
    public void testApplyDecisionToUserEntity() throws Exception {
        String requestBody =
        "{\n" +
            "\"decision_id\": \"looks_ok_account_abuse\",\n" +
            "\"source\": \"manual_review\",\n" +
            "\"analyst\":\"<EMAIL>\",\n" +
            "\"time\": 1480618362\n" +
        "}";

        String responseBody = "" +
                "{" +
                    "\"entity\": {" +
                        "\"id\": \"a_user_id\"," +
                        "\"type\": \"user\"" +
                    "}," +
                    "\"decision\": {" +
                        "\"id\": \"looks_ok_account_abuse\"" +
                    "}," +
                    "\"time\": 123213123" +
                "}";

        MockWebServer server = new MockWebServer();
        MockResponse response = new MockResponse();
        response.setResponseCode(HTTP_OK);
        response.setBody(responseBody);

        server.enqueue(response);
        server.start();

        String accountId = "your_account_id";
        String userId = "a_user_id";

        HttpUrl baseApi3Url = server.url("").newBuilder().build();

        // Create a new client and link it to the mock server.
        SiftClient client = new SiftClient("your_api_key");
        client.setBaseApi3Url(baseApi3Url);

        // Build and execute the request against the mock server.
        ApplyDecisionRequest request = client.buildRequest(
                new ApplyDecisionFieldSet()
                        .setAccountId(accountId)
                        .setUserId(userId)
                        .setDecisionId("looks_ok_account_abuse")
                        .setSource(DecisionSource.MANUAL_REVIEW)
                        .setAnalyst("<EMAIL>")
                        .setTime(System.currentTimeMillis()));

        ApplyDecisionResponse siftResponse = request.send();

        // Verify the request.
        RecordedRequest request1 = server.takeRequest();
        Assert.assertEquals("POST", request1.getMethod());
        Assert.assertEquals("/v3/accounts/" + accountId + "/users/" + userId + "/decisions",
                request1.getPath());
        Assert.assertEquals(request1.getHeader("Authorization"), "Basic eW91cl9hcGlfa2V5Og==");

        // Verify the response was parsed correctly.
        Assert.assertEquals(HTTP_OK, siftResponse.getHttpStatusCode());
        JSONAssert.assertEquals(response.getBody().readUtf8(),
                siftResponse.getBody().toJson(), true);
    }

    @Test
    public void testApplyDecisionToOrderEntity() throws Exception {
        String requestBody =
                "{" +
                    "\"decision_id\":\"looks_ok_account_abuse\"," +
                    "\"source\":\"automated_rule\"," +
                    "\"time\":1480618362" +
                "}";

        String responseBody = "" +
                "{" +
                    "\"entity\": {" +
                        "\"id\": \"an_order_id\"," +
                        "\"type\": \"order\"" +
                    "}," +
                    "\"decision\": {" +
                        "\"id\": \"order_looks_bad_payment_abuse\"" +
                    "}," +
                    "\"time\": 123213123" +
                "}";
{'fraction_non_alphanumeric': 0.13590348079323256, 'fraction_numerical': 0.013312994036888088, 'mean_word_length': 1.8630408892417627, 'pattern_counts': {'":': 34, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5623809', 'n_tokens_mistral': 2041, 'n_tokens_neox': 1920, 'n_words': 330}