<commit_before>import org.junit.Test
import static groovyx.net.http.ContentType.JSON
import static groovyx.net.http.ContentType.XML
import static org.junit.Assert.*

class DataItemIT extends BaseApiTest {

  def dataItemUids = [
          '004CF30590A5',
          '897513300787',
          '6C663D2B8681',
          '9EFA0CE242D0']

  @Test
  void getDataItemsJson() {
    client.contentType = JSON
    def response = client.get(path: '/3.1/categories/Cooking/items;full')
    assertEquals 200, response.status
    assertEquals 'application/json', response.contentType
    assertTrue response.data instanceof net.sf.json.JSON
    assertEquals 'OK', response.data.status
    assertFalse response.data.resultsTruncated
    assertEquals dataItemUids.size(), response.data.items.size()
    assert dataItemUids == response.data.items.collect {it.uid}
  }

  @Test
  void getDataItemsXml() {
    client.contentType = XML
    def response = client.get(path: '/3.1/categories/Cooking/items;full')
    assertEquals 200, response.status
    assertEquals 'application/xml', response.contentType
    assertEquals 'OK', response.data.Status.text()
    assertEquals 'false', response.data.Items.@truncated.text()
    def allDataItems = response.data.Items.Item
    assertEquals dataItemUids.size(), allDataItems.size()
    assert dataItemUids == allDataItems.@uid*.text()
  }

  @Test
  void getDataItemJson() {
    def response = client.get(
            path: '/3.1/categories/Cooking/items/004CF30590A5;full',
            contentType: JSON);
    assertEquals 200, response.status;
    assertEquals 'application/json', response.contentType;
    assertTrue response.data instanceof net.sf.json.JSON;
    assertEquals 'OK', response.data.status;
    assertEquals '54C8A44254AA', response.data.item.categoryUid;
    assertEquals 'Cooking', response.data.item.categoryWikiName;
    assertEquals 'Cooking', response.data.item.itemDefinition.name;
    assertEquals '/home/appliances/cooking/004CF30590A5', response.data.item.fullPath;
  }

  @Test
  void getDataItemXml() {
    def response = client.get(
            path: '/3.1/categories/Cooking/items/004CF30590A5;full',
            contentType: XML);
    assertEquals 200, response.status;
    assertEquals 'application/xml', response.contentType;
    assertEquals 'OK', response.data.Status.text();
    assertEquals '54C8A44254AA', response.data.Item.CategoryUid.text();
    assertEquals 'Cooking', response.data.Item.CategoryWikiName.text();<commit_msg>PL-3828 - Add DataItem label for V3 API. PL-2789 - Added DataItem integration tests.<commit_after>import org.junit.Test
import static groovyx.net.http.ContentType.JSON
import static groovyx.net.http.ContentType.XML
import static org.junit.Assert.assertEquals
import static org.junit.Assert.assertTrue

class DataItemIT extends BaseApiTest {

  def dataItemUids = [
          '004CF30590A5',
          '897513300787',
          '6C663D2B8681',
          '9EFA0CE242D0']

  @Test
  void getDataItemsJson() {
    client.contentType = JSON
    def response = client.get(path: '/3.1/categories/Cooking/items;full',
            query: ['resultLimit': '4'])
    assertEquals 200, response.status
    assertEquals 'application/json', response.contentType
    assertTrue response.data instanceof net.sf.json.JSON
    assertEquals 'OK', response.data.status
    assertTrue response.data.resultsTruncated
    assertEquals dataItemUids.size(), response.data.items.size()
    assert dataItemUids == response.data.items.collect {it.uid}
  }

  @Test
  void getDataItemsXml() {
    client.contentType = XML
    def response = client.get(path: '/3.1/categories/Cooking/items;full',
            query: ['resultLimit': '4'])
    assertEquals 200, response.status
    assertEquals 'application/xml', response.contentType
    assertEquals 'OK', response.data.Status.text()
    assertEquals 'true', response.data.Items.@truncated.text()
    def allDataItems = response.data.Items.Item
    assertEquals dataItemUids.size(), allDataItems.size()
    assert dataItemUids == allDataItems.@uid*.text()
  }

  @Test
  void getDataItemJson() {
    client.contentType = JSON
    def response = client.get(path: '/3.1/categories/Cooking/items/004CF30590A5;full');
    assertEquals 200, response.status;
    assertEquals 'application/json', response.contentType;
    assertTrue response.data instanceof net.sf.json.JSON;
    assertEquals 'OK', response.data.status;
    assertEquals '1, Gas', response.data.item.label;
    assertEquals '54C8A44254AA', response.data.item.categoryUid;
    assertEquals 'Cooking', response.data.item.categoryWikiName;
    assertEquals 'Cooking', response.data.item.itemDefinition.name;
    assertEquals '/home/appliances/cooking/004CF30590A5', response.data.item.fullPath;
  }

  @Test
  void getDataItemXml() {
    client.contentType = XML
    def response = client.get(path: '/3.1/categories/Cooking/items/004CF30590A5;full');
    assertEquals 200, response.status;
    assertEquals 'application/xml', response.contentType;
    assertEquals 'OK', response.data.Status.text();
    assertEquals '1, Gas', response.data.Item.Label.text();
    assertEquals '54C8A44254AA', response.data.Item.CategoryUid.text();
    assertEquals 'Cooking', response.data.Item.CategoryWikiName.text();
{'fraction_non_alphanumeric': 0.11667615253272624, 'fraction_numerical': 0.04003035477139063, 'mean_word_length': 3.8146118721461186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 4}, 'pii_count': 2, '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': '970780', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1565, 'n_words': 309}