<commit_before>/**
 * Copyright (C) <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package no.digipost.api.client;

import no.digipost.api.client.errorhandling.DigipostClientException;
import no.digipost.api.client.errorhandling.ErrorCode;
import no.digipost.api.client.security.Signer;
import no.digipost.api.client.util.DigipostApiMock;
import no.digipost.api.client.util.DigipostApiMock.Method;
import no.digipost.api.client.util.DigipostApiMock.MockRequest;
import no.digipost.api.client.util.DigipostApiMock.RequestsAndResponses;
import no.digipost.api.client.util.DigipostApiMock.MockRequest;
import no.digipost.http.client3.DigipostHttpClientFactory;
import no.digipost.http.client3.DigipostHttpClientSettings;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.HttpClientBuilder;
import org.xml.sax.ContentHandler;

import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.util.HashMap;
import java.util.Map;

import static no.digipost.api.client.DigipostClientConfig.DigipostClientConfigBuilder.newBuilder;
import static no.digipost.api.client.util.DigipostApiMock.MockRequest;

/**
 * Instansierer en DigipostClient som ikke går mot faktiskt Digipost REST-api endepunkt og
 * som kan brukes av tester o.l for å framprovosere ulike feilsituasjoner.
 */
public class DigipostClientMock {

    private final DigipostClient client;
    private final ApiService apiService;
    public final Map<Method, RequestsAndResponses> requestsAndResponsesMap = new HashMap<>();
    private static DigipostApiMock digipostApiMock = new DigipostApiMock();
    private static final String KEY_STORE_PASSWORD = "<PASSWORD>";
    private static final String KEY_STORE_ALIAS = "apiTest";
    private static final int PORT = 6666;

    public DigipostClientMock() {
        URI host = URI.create("http://localhost:" + PORT);

        HttpClientBuilder httpClientBuilder = DigipostHttpClientFactory.createBuilder(DigipostHttpClientSettings.DEFAULT);

        apiService = new ApiServiceImpl(httpClientBuilder, PORT, null, host, null);
        apiService.buildApacheHttpClientBuilder();
        client = new DigipostClient(newBuilder().build(), "digipostmock-url", 1, new Signer() {

            @Override
            public byte[] sign(String dataToSign) {
                return new byte[0];
            }
        }, apiService);<commit_msg>Rydder vekk 3x import av samme klasse<commit_after>/**
 * Copyright (C) <NAME>
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *         http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package no.digipost.api.client;

import no.digipost.api.client.errorhandling.DigipostClientException;
import no.digipost.api.client.errorhandling.ErrorCode;
import no.digipost.api.client.security.Signer;
import no.digipost.api.client.util.DigipostApiMock;
import no.digipost.api.client.util.DigipostApiMock.Method;
import no.digipost.api.client.util.DigipostApiMock.MockRequest;
import no.digipost.api.client.util.DigipostApiMock.RequestsAndResponses;
import no.digipost.http.client3.DigipostHttpClientFactory;
import no.digipost.http.client3.DigipostHttpClientSettings;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.impl.client.HttpClientBuilder;
import org.xml.sax.ContentHandler;

import javax.xml.XMLConstants;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;
import javax.xml.validation.Schema;
import javax.xml.validation.SchemaFactory;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.net.URI;
import java.security.Key;
import java.security.KeyPair;
import java.security.KeyStore;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.cert.Certificate;
import java.util.HashMap;
import java.util.Map;

import static no.digipost.api.client.DigipostClientConfig.DigipostClientConfigBuilder.newBuilder;

/**
 * Instansierer en DigipostClient som ikke går mot faktiskt Digipost REST-api endepunkt og
 * som kan brukes av tester o.l for å framprovosere ulike feilsituasjoner.
 */
public class DigipostClientMock {

    private final DigipostClient client;
    private final ApiService apiService;
    public final Map<Method, RequestsAndResponses> requestsAndResponsesMap = new HashMap<>();
    private static DigipostApiMock digipostApiMock = new DigipostApiMock();
    private static final String KEY_STORE_PASSWORD = "<PASSWORD>";
    private static final String KEY_STORE_ALIAS = "apiTest";
    private static final int PORT = 6666;

    public DigipostClientMock() {
        URI host = URI.create("http://localhost:" + PORT);

        HttpClientBuilder httpClientBuilder = DigipostHttpClientFactory.createBuilder(DigipostHttpClientSettings.DEFAULT);

        apiService = new ApiServiceImpl(httpClientBuilder, PORT, null, host, null);
        apiService.buildApacheHttpClientBuilder();
        client = new DigipostClient(newBuilder().build(), "digipostmock-url", 1, new Signer() {

            @Override
            public byte[] sign(String dataToSign) {
                return new byte[0];
            }
        }, apiService);
{'fraction_non_alphanumeric': 0.0900928321412266, 'fraction_numerical': 0.0038045959519099073, 'mean_word_length': 4.569491525423729, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 14}, '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': '2767198', 'n_tokens_mistral': 1943, 'n_tokens_neox': 1928, 'n_words': 496}