<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.lenya.cms.publication;

import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.apache.lenya.ac.impl.AbstractAccessControlTest;

/**
 * Publication test.
 */
public class PublicationTest extends AbstractAccessControlTest {
    
    /**
     * Tests the publication functionality.
     * @throws Exception
     */
    public void testPublication() throws Exception {
        
        PublicationManager pubMgr = null;
        try {
            pubMgr = (PublicationManager) getManager().lookup(PublicationManager.ROLE);
            
            Publication[] pubs = pubMgr.getPublications(getFactory());
            for (int i = 0; i < pubs.length; i++) {
                doTestPublication(pubs[i]);
            }
            
        }
        finally {
            if (pubMgr != null) {
                getManager().release(pubMgr);
            }
        }
        
        
    }

    protected void doTestPublication(Publication pub) throws PublicationException {
        String contentDirPath = pub.getContentDir();
        assertNotNull(contentDirPath);
        
        File contentDir = new File(contentDirPath);
        
        assertTrue(pub.exists());
        
        String[] areaNames = pub.getAreaNames();
        for (int i = 0; i < areaNames.length; i++) {
            File areaContentDir = pub.getContentDirectory(areaNames[i]);
            assertTrue(areaContentDir.isDirectory());
            assertEquals(new File(contentDir, areaNames[i]), areaContentDir);
        }
        
        String[] languages = pub.getLanguages();
        assertTrue(languages.length > 0);
        
        assertNotNull(pub.getDefaultLanguage());
        assertTrue(Arrays.asList(languages).contains(pub.getDefaultLanguage()));
        
        String[] types = pub.getResourceTypeNames();
        assertTrue(types.length > 0);
        
        Set typeSet = new HashSet(Arrays.asList(types));
        
        String[] templateIds = pub.getTemplateIds();
        for (int i = 0; i < templateIds.length; i++) {
            Publication template = pub.getFactory().getPublication(templateIds[i]);
            String[] templateTypes = template.getResourceTypeNames();
            for (int t = 0; t < templateTypes.length; t++) {
                assertTrue(typeSet.contains(templateTypes[i]));
            }
        }
        
    }

}
<commit_msg>Don't try to detect content dirs of empty areas<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.lenya.cms.publication;

import java.io.File;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;

import org.apache.lenya.ac.impl.AbstractAccessControlTest;

/**
 * Publication test.
 */
public class PublicationTest extends AbstractAccessControlTest {

    /**
     * Tests the publication functionality.
     * @throws Exception
     */
    public void testPublication() throws Exception {

        PublicationManager pubMgr = null;
        try {
            pubMgr = (PublicationManager) getManager().lookup(PublicationManager.ROLE);

            Publication[] pubs = pubMgr.getPublications(getFactory());
            for (int i = 0; i < pubs.length; i++) {
                doTestPublication(pubs[i]);
            }

        } finally {
            if (pubMgr != null) {
                getManager().release(pubMgr);
            }
        }

    }

    protected void doTestPublication(Publication pub) throws PublicationException {
        String contentDirPath = pub.getContentDir();
        assertNotNull(contentDirPath);

        File contentDir = new File(contentDirPath);

        assertTrue(pub.exists());

        String[] areaNames = pub.getAreaNames();
        for (int i = 0; i < areaNames.length; i++) {
            Area area = pub.getArea(areaNames[i]);
            if (area.getDocuments().length > 0) {
                File areaContentDir = pub.getContentDirectory(areaNames[i]);
                assertTrue(areaContentDir.isDirectory());
                assertEquals(new File(contentDir, areaNames[i]), areaContentDir);
            }
        }

        String[] languages = pub.getLanguages();
        assertTrue(languages.length > 0);

        assertNotNull(pub.getDefaultLanguage());
        assertTrue(Arrays.asList(languages).contains(pub.getDefaultLanguage()));

        String[] types = pub.getResourceTypeNames();
        assertTrue(types.length > 0);

        Set typeSet = new HashSet(Arrays.asList(types));

        String[] templateIds = pub.getTemplateIds();
        for (int i = 0; i < templateIds.length; i++) {
            Publication template = pub.getFactory().getPublication(templateIds[i]);
            String[] templateTypes = template.getResourceTypeNames();
            for (int t = 0; t < templateTypes.length; t++) {
                assertTrue(typeSet.contains(templateTypes[i]));
            }
        }

    }

}

{'fraction_non_alphanumeric': 0.09868017188459177, 'fraction_numerical': 0.0032228360957642726, 'mean_word_length': 2.48689138576779, 'pattern_counts': {'":': 0, '<': 11, '<?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': '5044731', 'n_tokens_mistral': 1701, 'n_tokens_neox': 1689, 'n_words': 492}