<commit_before>/*
Copyright 2011-2012 Opera Software ASA

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 com.opera.core.systems.scope.stp.services;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;

import com.opera.core.systems.scope.AbstractService;
import com.opera.core.systems.scope.ScopeServices;
import com.opera.core.systems.scope.internal.ServiceCallback;
import com.opera.core.systems.scope.protos.SelftestProtos;
import com.opera.core.systems.scope.protos.SelftestProtos.RunTestsArg;
import com.opera.core.systems.scope.protos.UmsProtos.Response;
import com.opera.core.systems.scope.services.Selftest;
import com.opera.core.systems.scope.stp.services.messages.SelftestMessage;

import org.json.JSONException;
import org.json.JSONObject;
import org.openqa.selenium.WebDriverException;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;

import static com.google.common.base.Preconditions.checkNotNull;

public class ScopeSelftest extends AbstractService implements Selftest {

  private ServiceCallback<SelftestProtos.SelftestResult> callback = null;

  public ScopeSelftest(ScopeServices services) {
    super(services, SERVICE_NAME);

    // Note: Version 2.0 of selftest is not backwards compatible with the previous version 1.1
    if (!isVersionInRange("3.0")) {
      return;
    }

    services.setSelftest(this);
  }

  public void init() {
  }

  public RunStatus runSelftests(Set<String> modules, String groups, String excludes) {
    checkNotNull(modules, "Modules cannot be empty");

    RunTestsArg.Builder argBuilder = RunTestsArg.newBuilder();

    if (groups != null) {
      argBuilder.setTestPattern(groups);
    }

    argBuilder.setModuleList(Joiner.on(',').join(modules));

    if (excludes != null) {
      argBuilder.setExcludePattern(excludes);
    }

    Response response = executeMessage(SelftestMessage.RUN_TESTS, argBuilder);

    SelftestProtos.RunStatus.Builder builder = SelftestProtos.RunStatus.newBuilder();<commit_msg>We require version 2.0 of selftest, not 3.0<commit_after>/*
Copyright 2011-2012 Opera Software ASA

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 com.opera.core.systems.scope.stp.services;

import com.google.common.base.Joiner;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;

import com.opera.core.systems.scope.AbstractService;
import com.opera.core.systems.scope.ScopeServices;
import com.opera.core.systems.scope.internal.ServiceCallback;
import com.opera.core.systems.scope.protos.SelftestProtos;
import com.opera.core.systems.scope.protos.SelftestProtos.RunTestsArg;
import com.opera.core.systems.scope.protos.UmsProtos.Response;
import com.opera.core.systems.scope.services.Selftest;
import com.opera.core.systems.scope.stp.services.messages.SelftestMessage;

import org.json.JSONException;
import org.json.JSONObject;
import org.openqa.selenium.WebDriverException;

import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.logging.Logger;

import static com.google.common.base.Preconditions.checkNotNull;

public class ScopeSelftest extends AbstractService implements Selftest {

  private ServiceCallback<SelftestProtos.SelftestResult> callback = null;

  public ScopeSelftest(ScopeServices services) {
    super(services, SERVICE_NAME);

    // Note: Version 2.0 of selftest is not backwards compatible with the previous version 1.1
    if (!isVersionInRange("2.0")) {
      return;
    }

    services.setSelftest(this);
  }

  public void init() {
  }

  public RunStatus runSelftests(Set<String> modules, String groups, String excludes) {
    checkNotNull(modules, "Modules cannot be empty");

    RunTestsArg.Builder argBuilder = RunTestsArg.newBuilder();

    if (groups != null) {
      argBuilder.setTestPattern(groups);
    }

    argBuilder.setModuleList(Joiner.on(',').join(modules));

    if (excludes != null) {
      argBuilder.setExcludePattern(excludes);
    }

    Response response = executeMessage(SelftestMessage.RUN_TESTS, argBuilder);

    SelftestProtos.RunStatus.Builder builder = SelftestProtos.RunStatus.newBuilder();
{'fraction_non_alphanumeric': 0.09502698535080956, 'fraction_numerical': 0.007710100231303007, 'mean_word_length': 4.714757709251101, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, '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': '1791948', 'n_tokens_mistral': 1574, 'n_tokens_neox': 1522, 'n_words': 396}