<commit_before>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.apache.clerezza.uima.metadatagenerator;

import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
import org.apache.clerezza.rdf.utils.GraphNode;
import org.apache.clerezza.uima.utils.ExternalServicesFacade;
import org.junit.Test;

import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.fail;

/**
 * Testcase for {@link UIMABaseMetadataGenerator}
 */
public class UIMABaseMetadataGeneratorTest {
  private static final String TEXT_TO_ANALYZE = "Italy, the defending champions and four-time World Cup winners, suffer a shock World Cup defeat to Slovakia, who win a remarkable game 3-2 to book their place in the last 16";

  @Test
  public void testConstructor() {
    try {
      new UIMABaseMetadataGenerator();
    }
    catch (Exception e) {
      fail(e.getLocalizedMessage());
    }
  }

  @Test
  public void testGenerateMethodWithUnsupportedMediaType() {
    try {
      UIMABaseMetadataGenerator baseMetadataGenerator = new UIMABaseMetadataGenerator();
      String textToAnalyze = TEXT_TO_ANALYZE;
      MGraph mGraph = new SimpleMGraph();
      GraphNode node = new GraphNode(new UriRef("test"), mGraph);
      MediaType wrongMediaType = MediaType.valueOf("multipart/form-data; boundary=AaB03x");
      baseMetadataGenerator.generate(node, textToAnalyze.getBytes(), wrongMediaType);
    } catch (Exception e) {
      fail(e.getLocalizedMessage());
    }

  }

  @Test
  public void testGenerateMethodWithsupportedMediaType() {
    try {

      ExternalServicesFacade externalServicesFacade = new ExternalServicesFacade();
      Map<String, Object> parameterSettings = new HashMap<String, Object>();
      parameterSettings.put("apikey", "<KEY>");
      parameterSettings.put("licenseID", "g6h9zamsdtwhb93nc247ecrs");
      externalServicesFacade.setParameterSetting(parameterSettings);
      UIMABaseMetadataGenerator baseMetadataGenerator = new UIMABaseMetadataGenerator(externalServicesFacade);
      String textToAnalyze = TEXT_TO_ANALYZE;
      MGraph mGraph = new SimpleMGraph();
      GraphNode node = new GraphNode(new UriRef("test"), mGraph);
      baseMetadataGenerator.generate(node, textToAnalyze.getBytes(), MediaType.TEXT_PLAIN_TYPE);
    } catch (Exception e) {
      fail(e.getLocalizedMessage());
    }

  }

}<commit_msg>[CLEREZZA-695] - minor refactoring to uima.metadata-generator tests<commit_after>/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you 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 org.apache.clerezza.uima.metadatagenerator;

import org.apache.clerezza.rdf.core.MGraph;
import org.apache.clerezza.rdf.core.UriRef;
import org.apache.clerezza.rdf.core.impl.SimpleMGraph;
import org.apache.clerezza.rdf.utils.GraphNode;
import org.apache.clerezza.uima.utils.ExternalServicesFacade;
import org.junit.Test;

import javax.ws.rs.core.MediaType;
import java.util.HashMap;
import java.util.Map;

/**
 * Testcase for {@link UIMABaseMetadataGenerator}
 */
public class UIMABaseMetadataGeneratorTest {
  private static final String TEXT_TO_ANALYZE = "Italy, the defending champions and four-time World Cup winners, suffer a shock World Cup defeat to Slovakia, who win a remarkable game 3-2 to book their place in the last 16";

  @Test
  public void testConstructor() throws Exception {
    new UIMABaseMetadataGenerator();
  }

  @Test
  public void testGenerateMethodWithUnsupportedMediaType() throws Exception {
    UIMABaseMetadataGenerator baseMetadataGenerator = new UIMABaseMetadataGenerator();
    String textToAnalyze = TEXT_TO_ANALYZE;
    MGraph mGraph = new SimpleMGraph();
    GraphNode node = new GraphNode(new UriRef("test"), mGraph);
    MediaType wrongMediaType = MediaType.valueOf("multipart/form-data; boundary=AaB03x");
    baseMetadataGenerator.generate(node, textToAnalyze.getBytes(), wrongMediaType);
  }

  @Test
  public void testGenerateMethodWithsupportedMediaType() throws Exception {
    ExternalServicesFacade externalServicesFacade = new ExternalServicesFacade();
    Map<String, Object> parameterSettings = new HashMap<String, Object>();
    parameterSettings.put("apikey", "04490000a72fe7ec5cb3497f14e77f338c86f2fe");
    parameterSettings.put("licenseID", "g6h9zamsdtwhb93nc247ecrs");
    externalServicesFacade.setParameterSetting(parameterSettings);
    UIMABaseMetadataGenerator baseMetadataGenerator = new UIMABaseMetadataGenerator(externalServicesFacade);
    String textToAnalyze = TEXT_TO_ANALYZE;
    MGraph mGraph = new SimpleMGraph();
    GraphNode node = new GraphNode(new UriRef("test"), mGraph);
    baseMetadataGenerator.generate(node, textToAnalyze.getBytes(), MediaType.TEXT_PLAIN_TYPE);
  }

}
{'fraction_non_alphanumeric': 0.08505893596686843, 'fraction_numerical': 0.010035043007327174, 'mean_word_length': 4.672086720867209, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '383038', 'n_tokens_mistral': 1803, 'n_tokens_neox': 1762, 'n_words': 527}