<commit_before>package io.oasp.gastronomy.restaurant.salesmanagement.service.impl.rest;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.codec.binary.Base64;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import io.oasp.gastronomy.restaurant.general.common.RestTestClientBuilder;
import io.oasp.gastronomy.restaurant.salesmanagement.logic.api.to.OrderPositionEto;
import io.oasp.gastronomy.restaurant.salesmanagement.service.api.rest.SalesmanagementRestService;

/**
 * TODO shuber This type ...
 *
 * @author shuber
 * @since dev
 */

public class SalesmanagementWebRestServiceTest extends SalesmanagementTest {

  private HttpEntity<String> request;

  private long numberOfOrderPositions = 0;

  private final HttpHeaders AUTHENTIFICATED_HEADERS = getAuthentificatedHeaders();

  private static final String BASE_URL_PRAEFIX = "http://localhost:";

  private static final String BASE_URL_SUFFIX = "/services/rest/salesmanagement/v1/";

  // TODO evtl. combine with EXPECTED_NUMBER_OF_ORDERS
  private static final long SAMPLE_ORDER_ID = 1L;

  // TODO talk to Jonas, that this does not work for empty strings

  private SalesmanagementRestService service;

  // TODO Inject ...
  private RestTemplate template;

  public SalesmanagementWebRestServiceTest() {
    super();
    this.template = new RestTemplate();
  }

  @Override
  @Before
  public void prepareTest() {

    this.flyway.clean();
    this.flyway.migrate();
    // cannot be put into constructor, as port is set after the constructor invocation
    this.service = RestTestClientBuilder.build(SalesmanagementRestService.class, this.ROLE, this.ROLE,
        "http://localhost:" + this.port + "/services/rest", this.jacksonJsonProvider);
    this.numberOfOrderPositions = getNumberOfOrderPositions();

  }

  @Test
  public void getOrder() {

    // setup
    HttpEntity<String> getRequest = new HttpEntity<String>(this.AUTHENTIFICATED_HEADERS);

    OrderPositionEto sampleOrderPositionEto = createSampleOrderPositionEto(SAMPLE_ORDER_ID);

    this.service.saveOrderPosition(sampleOrderPositionEto);

    // execute
    ResponseEntity<String> getResponse =
        this.template.exchange(generateBaseUrl() + "orderposition/" + Long.toString(this.numberOfOrderPositions + 1),
            HttpMethod.GET, getRequest, String.class);

    // validate
    String getResponseJson = getResponse.getBody();
    JSONAssert.assertEquals("{id:" + Long.toString(this.numberOfOrderPositions + 1) + "}", getResponseJson, false);
    JSONAssert.assertEquals("{orderId:" + Long.toString(SAMPLE_ORDER_ID) + "}", getResponseJson, false);
    JSONAssert.assertEquals("{offerId:" + Long.toString(this.SAMPLE_OFFER_ID) + "}", getResponseJson, false);<commit_msg>backup<commit_after>package io.oasp.gastronomy.restaurant.salesmanagement.service.impl.rest;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.codec.binary.Base64;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.Before;
import org.junit.Test;
import org.skyscreamer.jsonassert.JSONAssert;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;

import io.oasp.gastronomy.restaurant.general.common.RestTestClientBuilder;
import io.oasp.gastronomy.restaurant.salesmanagement.logic.api.to.OrderCto;
import io.oasp.gastronomy.restaurant.salesmanagement.logic.api.to.OrderPositionEto;
import io.oasp.gastronomy.restaurant.salesmanagement.service.api.rest.SalesmanagementRestService;

/**
 * TODO shuber This type ...
 *
 * @author shuber
 * @since dev
 */

public class SalesmanagementWebRestServiceTest extends SalesmanagementTest {

  private HttpEntity<String> request;

  private long numberOfOrderPositions = 0;

  private final HttpHeaders AUTHENTIFICATED_HEADERS = getAuthentificatedHeaders();

  private static final String BASE_URL_PRAEFIX = "http://localhost:";

  private static final String BASE_URL_SUFFIX = "/services/rest/salesmanagement/v1/";

  // TODO evtl. combine with EXPECTED_NUMBER_OF_ORDERS
  private static final long SAMPLE_ORDER_ID = 1L;

  // TODO talk to Jonas, that this does not work for empty strings

  private SalesmanagementRestService service;

  // TODO Inject ...
  private RestTemplate template;

  public SalesmanagementWebRestServiceTest() {
    super();
    this.template = new RestTemplate();
  }

  @Override
  @Before
  public void prepareTest() {

    this.flyway.clean();
    this.flyway.migrate();
    // cannot be put into constructor, as port is set after the constructor invocation
    this.service = RestTestClientBuilder.build(SalesmanagementRestService.class, this.ROLE, this.ROLE,
        "http://localhost:" + this.port + "/services/rest", this.jacksonJsonProvider);
    this.numberOfOrderPositions = getNumberOfOrderPositions();

  }

  @Test
  public void getOrder() {

    // setup
    HttpEntity<String> getRequest = new HttpEntity<String>(this.AUTHENTIFICATED_HEADERS);
    OrderCto sampleOrderCto = createSampleOrderCto(this.SAMPLE_TABLE_ID);

    // this.service.saveOrderPosition(sampleOrderPositionEto);

    // execute
    ResponseEntity<String> getResponse =
        this.template.exchange(generateBaseUrl() + "orderposition/" + Long.toString(this.numberOfOrderPositions + 1),
            HttpMethod.GET, getRequest, String.class);

    // validate
    String getResponseJson = getResponse.getBody();
    JSONAssert.assertEquals("{id:" + Long.toString(this.numberOfOrderPositions + 1) + "}", getResponseJson, false);
    JSONAssert.assertEquals("{orderId:" + Long.toString(SAMPLE_ORDER_ID) + "}", getResponseJson, false);
    JSONAssert.assertEquals("{offerId:" + Long.toString(this.SAMPLE_OFFER_ID) + "}", getResponseJson, false);
{'fraction_non_alphanumeric': 0.10410192666252331, 'fraction_numerical': 0.002175264139216905, 'mean_word_length': 4.927255985267035, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '4830080', 'n_tokens_mistral': 1920, 'n_tokens_neox': 1848, 'n_words': 371}