<commit_before>/**
 * Copyright (C) 2014-2015 <NAME> (www.helger.com)
 * philip[at]helger[dot]com
 *
 * 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.helger.photon.core.mock;

import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.helger.commons.annotation.ReturnsMutableCopy;
import com.helger.commons.id.factory.GlobalIDFactory;
import com.helger.commons.id.factory.MemoryIntIDFactory;
import com.helger.commons.url.SMap;
import com.helger.photon.core.servlet.WebAppListener;
import com.helger.web.mock.MockHttpListener;
import com.helger.web.scope.mock.MockServletRequestListenerScopeAware;
import com.helger.web.scope.mock.WebScopeTestRule;

/**
 * A JUnit test rule that is suitable for all ph-oton projects. It is optimized
 * for the use within Java libraries. For the use within Java web applications
 * using {@link PhotonCoreWebAppTestRule} is preferred, since the correct
 * resource base path is used.
 *
 * @author <NAME>
 */
public class PhotonCoreTestRule extends WebScopeTestRule
{
  @Nonnull
  @ReturnsMutableCopy
  public static SMap createDefaultServletContextInitParameters ()
  {
    return new SMap ().add (WebAppListener.INIT_PARAMETER_NO_STARTUP_INFO, true).add (WebAppListener.INIT_PARAMETER_NO_CHECK_FILE_ACCESS, true);
  }

  public PhotonCoreTestRule ()
  {
    this (createDefaultServletContextInitParameters ());
  }

  public PhotonCoreTestRule (@Nullable final Map <String, String> aServletContextInitParameters)
  {
    super (aServletContextInitParameters);
  }

  @Override
  protected void initListener ()
  {
    MockHttpListener.removeAllDefaultListeners ();
    MockHttpListener.addDefaultListener (new WebAppListener ()
    {
      @Override
      protected void initGlobalIDFactory ()
      {
        // Set persistent ID provider: in memory only
        GlobalIDFactory.setPersistentIntIDFactory (new MemoryIntIDFactory ());
      }
    });
    MockHttpListener.addDefaultListener (new MockServletRequestListenerScopeAware ());
    MockHttpListener.setToDefault ();
  }
}<commit_msg>No statistics on shutdown for tests<commit_after>/**
 * Copyright (C) 2014-2015 <NAME> (www.helger.com)
 * philip[at]helger[dot]com
 *
 * 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.helger.photon.core.mock;

import java.util.Map;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.helger.commons.annotation.ReturnsMutableCopy;
import com.helger.commons.url.SMap;
import com.helger.photon.core.servlet.WebAppListener;
import com.helger.web.mock.MockHttpListener;
import com.helger.web.scope.mock.MockServletRequestListenerScopeAware;
import com.helger.web.scope.mock.WebScopeTestRule;

/**
 * A JUnit test rule that is suitable for all ph-oton projects. It is optimized
 * for the use within Java libraries. For the use within Java web applications
 * using {@link PhotonCoreWebAppTestRule} is preferred, since the correct
 * resource base path is used.
 *
 * @author <NAME>
 */
public class PhotonCoreTestRule extends WebScopeTestRule
{
  @Nonnull
  @ReturnsMutableCopy
  public static SMap createDefaultServletContextInitParameters ()
  {
    return new SMap ().add (WebAppListener.INIT_PARAMETER_NO_STARTUP_INFO, true).add (WebAppListener.INIT_PARAMETER_NO_CHECK_FILE_ACCESS, true);
  }

  public PhotonCoreTestRule ()
  {
    this (createDefaultServletContextInitParameters ());
  }

  public PhotonCoreTestRule (@Nullable final Map <String, String> aServletContextInitParameters)
  {
    super (aServletContextInitParameters);
  }

  @Override
  protected void initListener ()
  {
    MockHttpListener.removeAllDefaultListeners ();
    MockHttpListener.addDefaultListener (new WebAppListener ()
    {
      @Override
      public boolean isHandleStatisticsOnEnd ()
      {
        return false;
      }
    });
    MockHttpListener.addDefaultListener (new MockServletRequestListenerScopeAware ());
    MockHttpListener.setToDefault ();
  }
}
{'fraction_non_alphanumeric': 0.0848, 'fraction_numerical': 0.0048, 'mean_word_length': 4.360128617363344, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, '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': '1796083', 'n_tokens_mistral': 1413, 'n_tokens_neox': 1386, 'n_words': 413}