<commit_before>/*
 * Copyright 2002-2015 the original author or authors.
 *
 * 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 docs;

import static org.assertj.core.api.Assertions.*;

import org.junit.Test;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.mock.web.MockServletContext;
import org.springframework.session.ExpiringSession;
import org.springframework.session.MapSessionRepository;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.session.data.redis.RedisOperationsSessionRepository;
import org.springframework.session.web.http.SessionRepositoryFilter;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

/**
 * @author <NAME>
 */
public class IndexDocTests {
	static final String ATTR_USER = "user";

	@Test
	public void repositoryDemo() {
		ExpiringRepositoryDemo<ExpiringSession> demo = new ExpiringRepositoryDemo<ExpiringSession>();
		demo.repository = new MapSessionRepository();

		demo.demo();
	}

	// tag::repository-demo[]
	public class RepositoryDemo<S extends Session> {
		private SessionRepository<S> repository; // <1>

		public void demo() {
			S toSave = repository.createSession(); // <2>

			// <3>
			User rwinch = new User("rwinch");
			toSave.setAttribute(ATTR_USER, rwinch);

			repository.save(toSave); // <4>

			S session = repository.getSession(toSave.getId()); // <5>

			// <6>
			User user = session.getAttribute(ATTR_USER);
			assertThat(user).isEqualTo(rwinch);
		}

		// ... setter methods ...
	}
	// end::repository-demo[]


	@Test
	public void expireRepositoryDemo() {
		ExpiringRepositoryDemo<ExpiringSession> demo = new ExpiringRepositoryDemo<ExpiringSession>();
		demo.repository = new MapSessionRepository();

		demo.demo();
	}

	@SuppressWarnings("unused")
	// tag::expire-repository-demo[]
	public class ExpiringRepositoryDemo<S extends ExpiringSession> {
		private SessionRepository<S> repository; // <1>

		public void demo() {
			S toSave = repository.createSession(); // <2>
			// ...
			toSave.setMaxInactiveIntervalInSeconds(30); // <3>

			repository.save(toSave); // <4>

			S session = repository.getSession(toSave.getId()); // <5>
			// ...
		}<commit_msg>Fix bad reference in IndexDocTests<commit_after>/*
 * Copyright 2002-2015 the original author or authors.
 *
 * 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 docs;

import static org.assertj.core.api.Assertions.*;

import org.junit.Test;
import org.springframework.data.redis.connection.jedis.JedisConnectionFactory;
import org.springframework.mock.web.MockServletContext;
import org.springframework.session.ExpiringSession;
import org.springframework.session.MapSessionRepository;
import org.springframework.session.Session;
import org.springframework.session.SessionRepository;
import org.springframework.session.data.redis.RedisOperationsSessionRepository;
import org.springframework.session.web.http.SessionRepositoryFilter;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

/**
 * @author <NAME>
 */
public class IndexDocTests {
	static final String ATTR_USER = "user";

	@Test
	public void repositoryDemo() {
		RepositoryDemo<ExpiringSession> demo = new RepositoryDemo<ExpiringSession>();
		demo.repository = new MapSessionRepository();

		demo.demo();
	}

	// tag::repository-demo[]
	public class RepositoryDemo<S extends Session> {
		private SessionRepository<S> repository; // <1>

		public void demo() {
			S toSave = repository.createSession(); // <2>

			// <3>
			User rwinch = new User("rwinch");
			toSave.setAttribute(ATTR_USER, rwinch);

			repository.save(toSave); // <4>

			S session = repository.getSession(toSave.getId()); // <5>

			// <6>
			User user = session.getAttribute(ATTR_USER);
			assertThat(user).isEqualTo(rwinch);
		}

		// ... setter methods ...
	}
	// end::repository-demo[]


	@Test
	public void expireRepositoryDemo() {
		ExpiringRepositoryDemo<ExpiringSession> demo = new ExpiringRepositoryDemo<ExpiringSession>();
		demo.repository = new MapSessionRepository();

		demo.demo();
	}

	// tag::expire-repository-demo[]
	public class ExpiringRepositoryDemo<S extends ExpiringSession> {
		private SessionRepository<S> repository; // <1>

		public void demo() {
			S toSave = repository.createSession(); // <2>
			// ...
			toSave.setMaxInactiveIntervalInSeconds(30); // <3>

			repository.save(toSave); // <4>

			S session = repository.getSession(toSave.getId()); // <5>
			// ...
		}
{'fraction_non_alphanumeric': 0.11795332136445243, 'fraction_numerical': 0.008976660682226212, 'mean_word_length': 4.372227579556413, 'pattern_counts': {'":': 0, '<': 43, '<?xml version=': 0, '>': 43, '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': '3619298', 'n_tokens_mistral': 1700, 'n_tokens_neox': 1559, 'n_words': 421}