<commit_before>/*
 * Licensed to Apereo under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Apereo 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 the following location:
 *
 *   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.jasig.cas.services;

import org.apache.commons.io.FileUtils;
import org.jasig.cas.authentication.principal.ShibbolethCompatiblePersistentIdGenerator;
import org.jasig.cas.services.support.RegisteredServiceRegexAttributeFilter;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;

/**
 * Handles test cases for {@link JsonServiceRegistryDao}.
 * @author <NAME>
 * @since 4.1.0
 */
public class JsonServiceRegistryDaoTests {

    private static final ClassPathResource RESOURCE = new ClassPathResource("services");

    private ServiceRegistryDao dao;

    public JsonServiceRegistryDaoTests() throws Exception {
        this.dao = new JsonServiceRegistryDao(RESOURCE.getFile());
    }

    @BeforeClass
    public static void prepTests() throws Exception {
        FileUtils.cleanDirectory(RESOURCE.getFile());
    }

    @Test
    public void verifySaveMethodWithNonExistentServiceAndNoAttributes() {
        final RegisteredServiceImpl r = new RegisteredServiceImpl();
        r.setName("testSaveMethodWithNonExistentServiceAndNoAttributes");
        r.setServiceId("testId");
        r.setTheme("theme");
        r.setDescription("description");

        final RegisteredService r2 = this.dao.save(r);
        final RegisteredService r3 = this.dao.findServiceById(r2.getId());

        assertEquals(r, r2);
        assertEquals(r2, r3);
    }

    @Test
    public void testSaveMethodWithDefaultUsernameAttribute() {
        final RegisteredServiceImpl r = new RegisteredServiceImpl();
        r.setName("testSaveMethodWithDefaultUsernameAttribute");
        r.setServiceId("testId");
        r.setTheme("theme");
        r.setDescription("description");
        r.setUsernameAttributeProvider(new DefaultRegisteredServiceUsernameProvider());
        final RegisteredService r2 = this.dao.save(r);
        assertEquals(r2, r);
    }

    @Test
    public void testSaveMethodWithDefaultPrincipalAttribute() {
        final RegisteredServiceImpl r = new RegisteredServiceImpl();
        r.setName("testSaveMethodWithDefaultPrincipalAttribute");
        r.setServiceId("testId");
        r.setTheme("theme");
        r.setDescription("description");
        r.setUsernameAttributeProvider(new PrincipalAttributeRegisteredServiceUsernameProvider("cn"));
        final RegisteredService r2 = this.dao.save(r);
        assertEquals(r2, r);
    }
    @Test
    public void testSaveMethodWithDefaultAnonymousAttribute() {
        final RegisteredServiceImpl r = new RegisteredServiceImpl();
        r.setName("testSaveMethodWithDefaultAnonymousAttribute");
        r.setServiceId("testId");
        r.setTheme("theme");
        r.setDescription("description");
        r.setUsernameAttributeProvider(new AnonymousRegisteredServiceUsernameAttributeProvider(
                new ShibbolethCompatiblePersistentIdGenerator("helloworld")
        ));
        final RegisteredService r2 = this.dao.save(r);
        final RegisteredService r3 = this.dao.findServiceById(r2.getId());
        assertEquals(r2, r3);
    }

    @Test
    public void verifySaveAttributeReleasePolicy() {
        final RegisteredServiceImpl r = new RegisteredServiceImpl();
        r.setName("testSaveAttributeReleasePolicy");
        r.setServiceId("testId");
        r.setTheme("theme");
        r.setDescription("description");
        r.setAttributeReleasePolicy(new ReturnAllAttributeReleasePolicy());

        final RegisteredService r2 = this.dao.save(r);
        final RegisteredService r3 = this.dao.findServiceById(r2.getId());

        assertEquals(r, r2);
        assertEquals(r2, r3);
        assertNotNull(r3.getAttributeReleasePolicy());<commit_msg>Fixed CS issues<commit_after>/*
 * Licensed to Apereo under one or more contributor license
 * agreements. See the NOTICE file distributed with this work
 * for additional information regarding copyright ownership.
 * Apereo 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 the following location:
 *
 *   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.jasig.cas.services;

import org.apache.commons.io.FileUtils;
import org.jasig.cas.authentication.principal.ShibbolethCompatiblePersistentIdGenerator;
import org.jasig.cas.services.support.RegisteredServiceRegexAttributeFilter;
import org.junit.BeforeClass;
import org.junit.Test;
import org.springframework.core.io.ClassPathResource;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;

import static org.junit.Assert.*;

/**
 * Handles test cases for {@link JsonServiceRegistryDao}.
 * @author <NAME>
 * @since 4.1.0
 */
public class JsonServiceRegistryDaoTests {

    private static final ClassPathResource RESOURCE = new ClassPathResource("services");

    private ServiceRegistryDao dao;

    public JsonServiceRegistryDaoTests() throws Exception {
        this.dao = new JsonServiceRegistryDao(RESOURCE.getFile());
    }

    @BeforeClass
    public static void prepTests() throws Exception {
        FileUtils.cleanDirectory(RESOURCE.getFile());
    }

    @Test
    public void checkSaveMethodWithNonExistentServiceAndNoAttributes() {
        final RegisteredServiceImpl r = new RegisteredServiceImpl();
        r.setName("testSaveMethodWithNonExistentServiceAndNoAttributes");
        r.setServiceId("testId");
        r.setTheme("theme");
        r.setDescription("description");

        final RegisteredService r2 = this.dao.save(r);
        final RegisteredService r3 = this.dao.findServiceById(r2.getId());

        assertEquals(r, r2);
        assertEquals(r2, r3);
    }

    @Test
    public void execSaveMethodWithDefaultUsernameAttribute() {
        final RegisteredServiceImpl r = new RegisteredServiceImpl();
        r.setName("testSaveMethodWithDefaultUsernameAttribute");
        r.setServiceId("testId");
        r.setTheme("theme");
        r.setDescription("description");
        r.setUsernameAttributeProvider(new DefaultRegisteredServiceUsernameProvider());
        final RegisteredService r2 = this.dao.save(r);
        assertEquals(r2, r);
    }

    @Test
    public void ensureSaveMethodWithDefaultPrincipalAttribute() {
        final RegisteredServiceImpl r = new RegisteredServiceImpl();
        r.setName("testSaveMethodWithDefaultPrincipalAttribute");
        r.setServiceId("testId");
        r.setTheme("theme");
        r.setDescription("description");
        r.setUsernameAttributeProvider(new PrincipalAttributeRegisteredServiceUsernameProvider("cn"));
        final RegisteredService r2 = this.dao.save(r);
        assertEquals(r2, r);
    }
    @Test
    public void verifySaveMethodWithDefaultAnonymousAttribute() {
        final RegisteredServiceImpl r = new RegisteredServiceImpl();
        r.setName("testSaveMethodWithDefaultAnonymousAttribute");
        r.setServiceId("testId");
        r.setTheme("theme");
        r.setDescription("description");
        r.setUsernameAttributeProvider(new AnonymousRegisteredServiceUsernameAttributeProvider(
                new ShibbolethCompatiblePersistentIdGenerator("helloworld")
        ));
        final RegisteredService r2 = this.dao.save(r);
        final RegisteredService r3 = this.dao.findServiceById(r2.getId());
        assertEquals(r2, r3);
    }

    @Test
    public void verifySaveAttributeReleasePolicy() {
        final RegisteredServiceImpl r = new RegisteredServiceImpl();
        r.setName("testSaveAttributeReleasePolicy");
        r.setServiceId("testId");
        r.setTheme("theme");
        r.setDescription("description");
        r.setAttributeReleasePolicy(new ReturnAllAttributeReleasePolicy());

        final RegisteredService r2 = this.dao.save(r);
        final RegisteredService r3 = this.dao.findServiceById(r2.getId());

        assertEquals(r, r2);
        assertEquals(r2, r3);
        assertNotNull(r3.getAttributeReleasePolicy());
{'fraction_non_alphanumeric': 0.09366684406599254, 'fraction_numerical': 0.006173496540713145, 'mean_word_length': 3.7622909275215406, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6276310', 'n_tokens_mistral': 2463, 'n_tokens_neox': 2460, 'n_words': 601}