Return-Path: Delivered-To: apmail-incubator-rat-commits-archive@locus.apache.org Received: (qmail 59419 invoked from network); 11 Mar 2008 23:11:28 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 Mar 2008 23:11:28 -0000 Received: (qmail 26274 invoked by uid 500); 11 Mar 2008 23:11:25 -0000 Delivered-To: apmail-incubator-rat-commits-archive@incubator.apache.org Received: (qmail 26253 invoked by uid 500); 11 Mar 2008 23:11:25 -0000 Mailing-List: contact rat-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: rat-dev@incubator.apache.org Delivered-To: mailing list rat-commits@incubator.apache.org Received: (qmail 26244 invoked by uid 99); 11 Mar 2008 23:11:25 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Mar 2008 16:11:25 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 11 Mar 2008 23:10:33 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3F7FA1A9850; Tue, 11 Mar 2008 16:10:22 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r636144 [6/7] - in /incubator/rat/import: ./ rat/ rat/src/ rat/src/java/ rat/src/java/rat/ rat/src/java/rat/analysis/ rat/src/java/rat/analysis/generation/ rat/src/java/rat/analysis/license/ rat/src/java/rat/analysis/util/ rat/src/java/rat/... Date: Tue, 11 Mar 2008 23:09:27 -0000 To: rat-commits@incubator.apache.org From: rdonkin@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080311231022.3F7FA1A9850@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Added: incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipDirectoryTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipDirectoryTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipDirectoryTest.java (added) +++ incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipDirectoryTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,87 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.document.impl.zip; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.zip.ZipEntry; + +import junit.framework.TestCase; +import rat.document.MockDocument; +import rat.document.MockDocumentCollection; + +public class ZipDirectoryTest extends TestCase { + + private static final String NAME = "directory"; + ZipEntry entry; + ZipDirectory directory; + MockDocument documentOne; + MockDocument documentTwo; + MockDocumentCollection subcollectionOne; + MockDocumentCollection subcollectionTwo; + Collection documents; + Collection subdirectories; + + protected void setUp() throws Exception { + super.setUp(); + entry = new ZipEntry(NAME); + documents = new ArrayList(); + documentOne = new MockDocument(); + documentTwo = new MockDocument(); + documents.add(documentOne); + documents.add(documentTwo); + subdirectories = new ArrayList(); + subcollectionOne = new MockDocumentCollection(); + subcollectionTwo = new MockDocumentCollection(); + subdirectories.add(subcollectionOne); + subdirectories.add(subcollectionTwo); + directory = new ZipDirectory(entry, subdirectories, documents); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testDocumentIterator() { + Iterator iterator = directory.documentIterator(); + assertNotNull("Iterator should be not null", iterator); + assertTrue("Iteration has two elements", iterator.hasNext()); + assertEquals("Iteration returned in order", documentOne, iterator.next()); + assertTrue("Iteration has two elements", iterator.hasNext()); + assertEquals("Iteration returned in order", documentTwo, iterator.next()); + assertFalse("Iteration has two elements", iterator.hasNext()); + } + + public void testSubcollectionIterator() { + Iterator iterator = directory.subcollectionIterator(); + assertNotNull("Iterator should be not null", iterator); + assertTrue("Iteration has two elements", iterator.hasNext()); + assertEquals("Iteration returned in order", subcollectionOne, iterator.next()); + assertTrue("Iteration has two elements", iterator.hasNext()); + assertEquals("Iteration returned in order", subcollectionTwo, iterator.next()); + assertFalse("Iteration has two elements", iterator.hasNext()); + } + + public void testGetName() { + assertEquals(NAME, directory.getName()); + } + + public void testGetURL() { + assertEquals("zip:" + NAME, directory.getURL()); + } + +} Added: incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipDocumentFactoryTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipDocumentFactoryTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipDocumentFactoryTest.java (added) +++ incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipDocumentFactoryTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,39 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.document.impl.zip; + +import java.io.File; + +import rat.document.IDocumentCollection; +import rat.test.utils.RATCase; + +public class ZipDocumentFactoryTest extends RATCase { + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testLoadDummy() throws Exception { + File file = new File("src/test/elements/dummy.jar"); + IDocumentCollection collection = ZipDocumentFactory.load(file); + checkDummyJar(collection); + } + +} Added: incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipDocumentTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipDocumentTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipDocumentTest.java (added) +++ incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipDocumentTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,60 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.document.impl.zip; + +import java.io.BufferedReader; +import java.io.File; +import java.io.Reader; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import junit.framework.TestCase; + +public class ZipDocumentTest extends TestCase { + + private static final String NAME = "Text.txt"; + ZipDocument document; + + protected void setUp() throws Exception { + super.setUp(); + ZipFile zip = new ZipFile(new File("src/test/elements/dummy.jar")); + ZipEntry entry = zip.getEntry(NAME); + assertNotNull(entry); + document = new ZipDocument(entry, zip); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testReader() throws Exception { + Reader reader = document.reader(); + assertNotNull("Reader for entry returned", reader); + BufferedReader bufferedReader = new BufferedReader(reader); + assertEquals("Expected content", "/*", bufferedReader.readLine().trim()); + assertEquals("Expected content", "* Copyright 2006 Robert Burrell Donkin", bufferedReader.readLine().trim()); + bufferedReader.close(); + } + + public void testGetName() { + assertEquals(NAME, document.getName()); + } + + public void testGetURL() { + assertEquals("zip:" + NAME, document.getURL()); + } + +} Added: incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipUtilsTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipUtilsTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipUtilsTest.java (added) +++ incubator/rat/import/rat/src/test/rat/document/impl/zip/ZipUtilsTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,101 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.document.impl.zip; + +import java.io.File; +import java.util.Arrays; +import java.util.Collection; +import java.util.Enumeration; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; + +import junit.framework.TestCase; + +public class ZipUtilsTest extends TestCase { + + private static final String NAME = "Text.txt"; + private static final String SUBDIRECTORY = "sub"; + private static final String SUBDIRECTORY_ELEMENT = "Empty.txt"; + + protected void setUp() throws Exception { + super.setUp(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testSimpleGetName() throws Exception { + ZipFile zip = new ZipFile(new File("src/test/elements/dummy.jar")); + ZipEntry entry = zip.getEntry(NAME); + assertNotNull(entry); + assertEquals(NAME, ZipUtils.getName(entry)); + } + + public void testGetSubDirectoryName() throws Exception { + ZipFile zip = new ZipFile(new File("src/test/elements/dummy.jar")); + ZipEntry entry = zip.getEntry(SUBDIRECTORY); + assertNotNull(entry); + assertEquals(SUBDIRECTORY, ZipUtils.getName(entry)); + } + + public void testGetSubDirectoryNameWithSlash() throws Exception { + ZipFile zip = new ZipFile(new File("src/test/elements/dummy.jar")); + ZipEntry entry = zip.getEntry(SUBDIRECTORY + "/"); + assertNotNull(entry); + assertEquals(SUBDIRECTORY, ZipUtils.getName(entry)); + } + + public void testGetSubDirectoryDocumentName() throws Exception { + ZipFile zip = new ZipFile(new File("src/test/elements/dummy.jar")); + ZipEntry entry = zip.getEntry(SUBDIRECTORY + "/" + SUBDIRECTORY_ELEMENT); + assertNotNull(entry); + assertEquals(SUBDIRECTORY_ELEMENT, ZipUtils.getName(entry)); + } + + public void testSimpleGetStem() throws Exception { + ZipFile zip = new ZipFile(new File("src/test/elements/dummy.jar")); + ZipEntry entry = zip.getEntry(NAME); + assertNotNull(entry); + assertEquals("", ZipUtils.getStem(entry)); + } + + public void testGetSubDirectoryStem() throws Exception { + ZipFile zip = new ZipFile(new File("src/test/elements/dummy.jar")); + ZipEntry entry = zip.getEntry(SUBDIRECTORY); + assertNotNull(entry); + assertEquals("", ZipUtils.getStem(entry)); + } + + public void testGetSubDirectoryDocumentStem() throws Exception { + ZipFile zip = new ZipFile(new File("src/test/elements/dummy.jar")); + ZipEntry entry = zip.getEntry(SUBDIRECTORY + "/" + SUBDIRECTORY_ELEMENT); + assertNotNull(entry); + assertEquals(SUBDIRECTORY, ZipUtils.getStem(entry)); + } + + public void testIsTopLevelDirectory() throws Exception { + String[] topLevelNames = {"Image.png", "LICENSE", "NOTICE", "Source.java", + "Text.txt", "Xml.xml", "META-INF", "META-INF/", "META-INF\\", "sub", "sub/", "sub\\"}; + Collection topLevel = Arrays.asList(topLevelNames); + ZipFile zip = new ZipFile(new File("src/test/elements/dummy.jar")); + for (Enumeration en=zip.entries();en.hasMoreElements();) { + ZipEntry entry = (ZipEntry) en.nextElement(); + assertEquals("Top level element", topLevel.contains(entry.getName()), + ZipUtils.isTopLevel(entry)); + } + } +} Added: incubator/rat/import/rat/src/test/rat/header/ArrayCharFilterTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/header/ArrayCharFilterTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/header/ArrayCharFilterTest.java (added) +++ incubator/rat/import/rat/src/test/rat/header/ArrayCharFilterTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,43 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.header; + +import junit.framework.TestCase; + +public class ArrayCharFilterTest extends TestCase { + + private static final char[] filtered = {'d', 'o', 'a'}; + ArrayCharFilter filter; + + protected void setUp() throws Exception { + super.setUp(); + filter = new ArrayCharFilter(filtered); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testIsFilteredOut() { + assertTrue(filter.isFilteredOut('a')); + assertFalse(filter.isFilteredOut('b')); + assertFalse(filter.isFilteredOut('c')); + assertTrue(filter.isFilteredOut('d')); + assertFalse(filter.isFilteredOut('e')); + assertFalse(filter.isFilteredOut('f')); + } + +} Added: incubator/rat/import/rat/src/test/rat/header/FilteringSequenceFactoryTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/header/FilteringSequenceFactoryTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/header/FilteringSequenceFactoryTest.java (added) +++ incubator/rat/import/rat/src/test/rat/header/FilteringSequenceFactoryTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,75 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.header; + +import java.io.StringReader; + +import junit.framework.TestCase; + +public class FilteringSequenceFactoryTest extends TestCase { + + int capacity; + FilteringSequenceFactory factory; + SimpleCharFilter filter; + + protected void setUp() throws Exception { + super.setUp(); + capacity = 50; + filter = new SimpleCharFilter(); + factory = new FilteringSequenceFactory(capacity, filter); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testNoFiltering() throws Exception { + final String INPUT = "Whatever"; + StringReader reader = new StringReader(INPUT); + CharSequence result = factory.filter(reader); + assertNotNull(result); + String output = new StringBuffer().append(result).toString(); + assertEquals("No filtering so input equals output.", INPUT, output); + reader = new StringReader(INPUT); + result = factory.filter(reader); + assertNotNull(result); + output = new StringBuffer().append(result).toString(); + assertEquals("No filtering so input equals output. Independent of previous input", INPUT, output); + } + + public void testFiltering() throws Exception { + final String INPUT = "Whatever"; + StringReader reader = new StringReader(INPUT); + CharSequence result = factory.filter(reader); + assertNotNull(result); + String output = new StringBuffer().append(result).toString(); + assertEquals("No filtering so input equals output.", INPUT, output); + filter.filterOut = true; + reader = new StringReader(INPUT); + result = factory.filter(reader); + assertNotNull(result); + assertEquals("All filtered output is empty. Independent of previous input", 0, result.length()); + } + + public void testOverCapacity() throws Exception { + final String INPUT = "WhateverWhateverWhateverWhateverWhateverWhateverWhateverWhateverWhateverWhatever"; + StringReader reader = new StringReader(INPUT); + CharSequence result = factory.filter(reader); + assertNotNull(result); + String output = new StringBuffer().append(result).toString(); + assertEquals("No filtering so input equals output.", INPUT.substring(0, capacity), output); + } +} Added: incubator/rat/import/rat/src/test/rat/header/HeaderMatcherTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/header/HeaderMatcherTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/header/HeaderMatcherTest.java (added) +++ incubator/rat/import/rat/src/test/rat/header/HeaderMatcherTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,90 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.header; + +import java.io.StringReader; +import java.util.regex.Pattern; + +import junit.framework.TestCase; + +public class HeaderMatcherTest extends TestCase { + + int capacity; + HeaderMatcher matcher; + SimpleCharFilter filter; + + protected void setUp() throws Exception { + super.setUp(); + capacity = 20; + filter = new SimpleCharFilter(); + matcher = new HeaderMatcher(filter, 20); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testSimpleMatches() throws Exception { + Pattern hatPattern = Pattern.compile("(.*)hat(.*)"); + Pattern headPattern = Pattern.compile("head...."); + StringReader reader = new StringReader("The mad hatter"); + matcher.read(reader); + assertTrue(matcher.matches(hatPattern)); + assertFalse(matcher.matches(headPattern)); + reader = new StringReader("headache"); + matcher.read(reader); + assertFalse(matcher.matches(hatPattern)); + assertTrue(matcher.matches(headPattern)); + } + + public void testFilteredMatches() throws Exception { + Pattern capPattern = Pattern.compile("cap(.*)"); + StringReader reader = new StringReader("capped"); + matcher.read(reader); + assertTrue(matcher.matches(capPattern)); + filter.filterOut = true; + reader = new StringReader("capped"); + matcher.read(reader); + assertFalse(matcher.matches(capPattern)); + } + + public void testNoLines() throws Exception { + StringReader reader = new StringReader("None"); + matcher.read(reader); + assertEquals("No lines read", 0, matcher.lines()); + } + + public void testLines() throws Exception { + StringReader reader = new StringReader("One\n"); + matcher.read(reader); + assertEquals("One line read", 1, matcher.lines()); + reader = new StringReader("One\nTwo"); + matcher.read(reader); + assertEquals("One line read", 1, matcher.lines()); + reader = new StringReader("One\nTwo\nThree"); + matcher.read(reader); + assertEquals("Two lines read", 2, matcher.lines()); + reader = new StringReader("One\nTwo\nThree\n"); + matcher.read(reader); + assertEquals("Three lines read", 3, matcher.lines()); + } + + public void testTooManyLines() throws Exception { + StringReader reader = new StringReader("WhateverWhateverWhateverWhateverWhateverWhateverWhateverWhatever"); + matcher.read(reader); + assertEquals("Too many lines read", -1, matcher.lines()); + } +} \ No newline at end of file Added: incubator/rat/import/rat/src/test/rat/header/HeaderMatcherWithBeansTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/header/HeaderMatcherWithBeansTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/header/HeaderMatcherWithBeansTest.java (added) +++ incubator/rat/import/rat/src/test/rat/header/HeaderMatcherWithBeansTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,75 @@ + +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.header; + +import java.io.StringReader; +import java.util.regex.Pattern; + +import junit.framework.TestCase; + +public class HeaderMatcherWithBeansTest extends TestCase { + + int capacity; + HeaderMatcher matcher; + SimpleCharFilter filter; + HeaderBean[] beans; + + protected void setUp() throws Exception { + super.setUp(); + HeaderBean[] beans = { + new HeaderBean(), + new HeaderBean(), + new HeaderBean() + }; + this.beans = beans; + capacity = 20; + filter = new SimpleCharFilter(); + matcher = new HeaderMatcher(filter, 20, beans); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testNulls() throws Exception { + beans[0].setMatch(false); + beans[1].setMatch(true); + beans[2].setMatch(false); + StringReader reader = new StringReader("Whatever"); + matcher.read(reader); + assertFalse("State preserved", beans[0].isMatch()); + assertTrue("State preserved", beans[1].isMatch()); + assertFalse("State preserved", beans[2].isMatch()); + beans[0].setMatch(true); + beans[1].setMatch(false); + beans[2].setMatch(true); + assertTrue("State preserved", beans[0].isMatch()); + assertFalse("State preserved", beans[1].isMatch()); + assertTrue("State preserved", beans[2].isMatch()); + } + + public void testMatches() throws Exception { + beans[0].setHeaderPattern(Pattern.compile("What(.*)")); + beans[1].setHeaderPattern(Pattern.compile("(.*)ever")); + beans[2].setHeaderPattern(Pattern.compile("What")); + StringReader reader = new StringReader("Whatever"); + matcher.read(reader); + assertTrue("Match header pattern", beans[0].isMatch()); + assertTrue("Match header pattern", beans[1].isMatch()); + assertFalse("Match header pattern", beans[2].isMatch()); + } +} Added: incubator/rat/import/rat/src/test/rat/header/SimpleCharFilter.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/header/SimpleCharFilter.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/header/SimpleCharFilter.java (added) +++ incubator/rat/import/rat/src/test/rat/header/SimpleCharFilter.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,31 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.header; + +public class SimpleCharFilter implements CharFilter { + + public boolean filterOut = false; + + public SimpleCharFilter() {} + public SimpleCharFilter(boolean filterOut) { + this.filterOut = filterOut; + } + + public boolean isFilteredOut(char character) { + return filterOut; + } + +} Added: incubator/rat/import/rat/src/test/rat/policy/DefaultPolicyTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/policy/DefaultPolicyTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/policy/DefaultPolicyTest.java (added) +++ incubator/rat/import/rat/src/test/rat/policy/DefaultPolicyTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,94 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.policy; + +import rat.analysis.Claims; +import rat.license.Apache20LicenseFamily; +import rat.license.OASISLicenseFamily; +import rat.license.W3CDocumentLicenseFamily; +import rat.license.W3CSoftwareLicenseFamily; +import rat.report.claim.impl.xml.MockClaimReporter; +import junit.framework.TestCase; + +public class DefaultPolicyTest extends TestCase { + + MockClaimReporter reporter; + DefaultPolicy policy; + + protected void setUp() throws Exception { + super.setUp(); + reporter = new MockClaimReporter(); + policy = new DefaultPolicy(reporter); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testOtherPredicate() throws Exception { + policy.claim("subject", "predicate", "object", true); + assertEquals("No claim", 0, reporter.claims.size()); + } + + public void testASLFamily() throws Exception { + policy.claim("subject", Claims.LICENSE_FAMILY_PREDICATE, Apache20LicenseFamily.APACHE_SOFTWARE_LICENSE_NAME, true); + assertEquals("Approved claim", 1, reporter.claims.size()); + assertEquals("Approved claim", new MockClaimReporter.Claim("subject", Claims.LICENSE_APPROVAL_PREDICATE, "true", false), reporter.claims.get(0)); + } + + public void testOASISFamily() throws Exception { + policy.claim("subject", Claims.LICENSE_FAMILY_PREDICATE, OASISLicenseFamily.OASIS_OPEN_LICENSE_NAME, true); + assertEquals("Approved claim", 1, reporter.claims.size()); + assertEquals("Approved claim", new MockClaimReporter.Claim("subject", Claims.LICENSE_APPROVAL_PREDICATE, "true", false), reporter.claims.get(0)); + } + + public void testW3CFamily() throws Exception { + policy.claim("subject", Claims.LICENSE_FAMILY_PREDICATE, W3CSoftwareLicenseFamily.W3C_SOFTWARE_COPYRIGHT_NAME, true); + assertEquals("Approved claim", 1, reporter.claims.size()); + assertEquals("Approved claim", new MockClaimReporter.Claim("subject", Claims.LICENSE_APPROVAL_PREDICATE, "true", false), reporter.claims.get(0)); + } + + public void testW3CDocFamily() throws Exception { + policy.claim("subject", Claims.LICENSE_FAMILY_PREDICATE, W3CDocumentLicenseFamily.W3C_DOCUMENT_COPYRIGHT_NAME, true); + assertEquals("Approved claim", 1, reporter.claims.size()); + assertEquals("Approved claim", new MockClaimReporter.Claim("subject", Claims.LICENSE_APPROVAL_PREDICATE, "true", false), reporter.claims.get(0)); + } + + public void testUnknownFamily() throws Exception { + policy.claim("subject", Claims.LICENSE_FAMILY_PREDICATE, "?????", true); + assertEquals("Approved claim", 1, reporter.claims.size()); + assertEquals("Approved claim", new MockClaimReporter.Claim("subject", Claims.LICENSE_APPROVAL_PREDICATE, "false", false), reporter.claims.get(0)); + } + + public void testCustomNames() throws Exception { + reporter = new MockClaimReporter(); + String[] custom = {"Example"}; + policy = new DefaultPolicy(reporter, custom); + policy.claim("subject", Claims.LICENSE_FAMILY_PREDICATE, "?????", true); + policy.claim("subject", Claims.LICENSE_FAMILY_PREDICATE, W3CDocumentLicenseFamily.W3C_DOCUMENT_COPYRIGHT_NAME, true); + policy.claim("subject", Claims.LICENSE_FAMILY_PREDICATE, W3CSoftwareLicenseFamily.W3C_SOFTWARE_COPYRIGHT_NAME, true); + policy.claim("subject", Claims.LICENSE_FAMILY_PREDICATE, Apache20LicenseFamily.APACHE_SOFTWARE_LICENSE_NAME, true); + assertEquals("Four unapproved claims", 4, reporter.claims.size()); + assertEquals("Four unapproved claim", new MockClaimReporter.Claim("subject", Claims.LICENSE_APPROVAL_PREDICATE, "false", false), reporter.claims.get(0)); + assertEquals("Four unapproved claim", new MockClaimReporter.Claim("subject", Claims.LICENSE_APPROVAL_PREDICATE, "false", false), reporter.claims.get(1)); + assertEquals("Four unapproved claim", new MockClaimReporter.Claim("subject", Claims.LICENSE_APPROVAL_PREDICATE, "false", false), reporter.claims.get(2)); + assertEquals("Four unapproved claim", new MockClaimReporter.Claim("subject", Claims.LICENSE_APPROVAL_PREDICATE, "false", false), reporter.claims.get(3)); + policy.claim("subject", Claims.LICENSE_FAMILY_PREDICATE, "Example", true); + assertEquals("Approved claim", 5, reporter.claims.size()); + assertEquals("Approved claim", new MockClaimReporter.Claim("subject", + Claims.LICENSE_APPROVAL_PREDICATE, "true", false), reporter.claims.get(4)); + } +} Added: incubator/rat/import/rat/src/test/rat/report/analyser/AnalyserFactoryTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/report/analyser/AnalyserFactoryTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/report/analyser/AnalyserFactoryTest.java (added) +++ incubator/rat/import/rat/src/test/rat/report/analyser/AnalyserFactoryTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,71 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.report.analyser; + +import java.io.File; +import java.io.StringWriter; + +import junit.framework.TestCase; +import rat.document.IDocumentAnalyser; +import rat.document.impl.MonolithicFileDocument; +import rat.report.claim.impl.xml.SimpleXmlClaimReporter; +import rat.report.xml.writer.impl.base.XmlWriter; + +public class AnalyserFactoryTest extends TestCase { + + StringWriter out; + SimpleXmlClaimReporter reporter; + + protected void setUp() throws Exception { + super.setUp(); + out = new StringWriter(); + XmlWriter writer = new XmlWriter(out); + reporter = new SimpleXmlClaimReporter(writer); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + + public void testStandardTypeAnalyser() throws Exception { + MonolithicFileDocument document = new MonolithicFileDocument(new File("src/test/elements/Text.txt")); + IDocumentAnalyser analyser = DefaultAnalyserFactory.createStandardTypeAnalyser(reporter); + analyser.analyse(document); + assertEquals("Open standard element", "", out.toString()); + } + + public void testNoteTypeAnalyser() throws Exception { + MonolithicFileDocument document = new MonolithicFileDocument(new File("src/test/elements/LICENSE")); + IDocumentAnalyser analyser = DefaultAnalyserFactory.createNoticeTypeAnalyser(reporter); + analyser.analyse(document); + assertEquals("Open note element", "", out.toString()); + } + + public void testBinaryTypeAnalyser() throws Exception { + MonolithicFileDocument document = new MonolithicFileDocument(new File("src/test/elements/Image.png")); + IDocumentAnalyser analyser = DefaultAnalyserFactory.createBinaryTypeAnalyser(reporter); + analyser.analyse(document); + assertEquals("Open note element", "", out.toString()); + } + + public void testArchiveTypeAnalyser() throws Exception { + MonolithicFileDocument document = new MonolithicFileDocument(new File("src/test/elements/Dummy.jar")); + IDocumentAnalyser analyser = DefaultAnalyserFactory.createArchiveTypeAnalyser(reporter); + analyser.analyse(document); + assertEquals("Open note element", "", out.toString()); + } +} Added: incubator/rat/import/rat/src/test/rat/report/analyser/ConstantClaimAnalyserTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/report/analyser/ConstantClaimAnalyserTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/report/analyser/ConstantClaimAnalyserTest.java (added) +++ incubator/rat/import/rat/src/test/rat/report/analyser/ConstantClaimAnalyserTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,78 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.report.analyser; + +import junit.framework.TestCase; +import rat.document.MockDocument; +import rat.report.claim.impl.xml.MockClaimReporter; +import rat.report.claim.impl.xml.MockClaimReporter.Claim; + +public class ConstantClaimAnalyserTest extends TestCase { + + private static final String OBJECT = "OBJECT"; + private static final String PREDICATE = "PREDICATE"; + MockClaimReporter reporter; + AbstractSingleClaimAnalyser analyser; + + protected void setUp() throws Exception { + super.setUp(); + reporter = new MockClaimReporter(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testAnalyseLiteral() throws Exception { + analyser = new ConstantClaimAnalyser(reporter, PREDICATE, OBJECT, true); + MockDocument document = new MockDocument(); + analyser.analyse(document); + assertEquals("One claim per document", 1, reporter.claims.size()); + Claim claim = reporter.getClaim(0); + assertEquals("Subject is name", document.name, claim.subject); + assertEquals("Object is constant", OBJECT, claim.object); + assertEquals("Predicate is constant", PREDICATE, claim.predicate); + assertTrue("Constantly literal", claim.isLiteral); + document.name = "A New Name"; + analyser.analyse(document); + assertEquals("One claim per document", 2, reporter.claims.size()); + claim = reporter.getClaim(1); + assertEquals("Subject is name", document.name, claim.subject); + assertEquals("Object is constant", OBJECT, claim.object); + assertEquals("Predicate is consant", PREDICATE, claim.predicate); + assertTrue("Constantly literal", claim.isLiteral); + } + + public void testAnalyseNotLiteral() throws Exception { + analyser = new ConstantClaimAnalyser(reporter, PREDICATE, OBJECT, false); + MockDocument document = new MockDocument(); + analyser.analyse(document); + assertEquals("One claim per document", 1, reporter.claims.size()); + Claim claim = reporter.getClaim(0); + assertEquals("Subject is name", document.name, claim.subject); + assertEquals("Object is constant", OBJECT, claim.object); + assertEquals("Predicate is constant", PREDICATE, claim.predicate); + assertFalse("Constantly not literal", claim.isLiteral); + document.name = "A New Name"; + analyser.analyse(document); + assertEquals("One claim per document", 2, reporter.claims.size()); + claim = reporter.getClaim(1); + assertEquals("Subject is name", document.name, claim.subject); + assertEquals("Object is constant", OBJECT, claim.object); + assertEquals("Predicate is consant", PREDICATE, claim.predicate); + assertFalse("Constantly not literal", claim.isLiteral); + } +} Added: incubator/rat/import/rat/src/test/rat/report/analyser/HeaderCheckWorkerTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/report/analyser/HeaderCheckWorkerTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/report/analyser/HeaderCheckWorkerTest.java (added) +++ incubator/rat/import/rat/src/test/rat/report/analyser/HeaderCheckWorkerTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,372 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.report.analyser; + +import java.io.StringReader; + +import junit.framework.TestCase; +import rat.analysis.license.ApacheSoftwareLicense20; +import rat.report.analyser.HeaderCheckWorker; +import rat.report.claim.impl.xml.MockClaimReporter; + +public class HeaderCheckWorkerTest extends TestCase { + + private static final String SOME_NAME = "Some Name"; + + private static final String CONTENT_WITHOUT_LICENSE_FIRST_FIVE_LINES = + "'Great deeds, O friends! this wondrous man has wrought,\n" + + "And mighty blessings to his country brought!\n" + + "With ships he parted, and a numerous train,\n" + + "Those, and their ships, he buried in the main.\n" + + "Now he returns, and first essays his hand\n"; + + private static final String CONTENT_WITHOUT_LICENSE = + CONTENT_WITHOUT_LICENSE_FIRST_FIVE_LINES + +"In the best blood of all his native land.\n" + +"Haste, then, and ere to neighbouring Pyle he flies,\n" + +"Or sacred Elis, to procure supplies;\n" + +"Arise (or ye for ever fall), arise!\n" + +"Shame to this age, and all that shall succeed!\n" + +"If unrevenged your sons and brothers bleed.\n" + +"Prove that we live, by vengeance on his head,\n" + +"Or sink at once forgotten with the dead.'\n" + +"Here ceased he, but indignant tears let fall\n" + +"Spoke when he ceased: dumb sorrow touch'd them all.\n" + +"When from the palace to the wondering throng\n" + +"Sage Medon came, and Phemius came along\n" + +"(Restless and early sleep's soft bands they broke);\n" + +"And Medon first the assembled chiefs bespoke;\n" + +"\n" + +"'Hear me, ye peers and elders of the land,\n" + +"Who deem this act the work of mortal hand;\n" + +"As o'er the heaps of death Ulysses strode,\n" + +"These eyes, these eyes beheld a present god,\n" + +"Who now before him, now beside him stood,\n" + +"Fought as he fought, and mark'd his way with blood:\n" + +"In vain old Mentor's form the god belied;\n" + +"'Twas Heaven that struck, and Heaven was on his side.'\n" + +"\n" + +"A sudden horror all the assembly shook,\n" + +"When slowly rising, Halitherses spoke\n" + +"(Reverend and wise, whose comprehensive view\n" + +"At once the present and the future knew):\n" + +"'Me too, ye fathers, hear! from you proceed\n" + +"The ills ye mourn; your own the guilty deed.\n" + +"Ye gave your sons, your lawless sons, the rein\n" + +"(Oft warn'd by Mentor and myself in vain);\n" + +"An absent hero's bed they sought to soil,\n" + +"An absent hero's wealth they made their spoil;\n" + +"Immoderate riot, and intemperate lust!\n" + +"The offence was great, the punishment was just.\n" + +"Weigh then my counsels in an equal scale,\n" + +"Nor rush to ruin. Justice will prevail.'\n" + +"\n" + +"His moderate words some better minds persuade:\n" + +"They part, and join him: but the number stay'd.\n" + +"They storm, they shout, with hasty frenzy fired,\n" + +"And second all Eupithes' rage inspired.\n" + +"They case their limbs in brass; to arms they run;\n" + +"The broad effulgence blazes in the sun.\n" + +"Before the city, and in ample plain,\n" + +"They meet: Eupithes heads the frantic train.\n" + +"Fierce for his son, he breathes his threats in air;\n" + +"Fate bears them not, and Death attends him there.\n" + +"\n" + +"This pass'd on earth, while in the realms above\n" + +"Minerva thus to cloud-compelling Jove!\n" + +"'May I presume to search thy secret soul?\n" + +"O Power Supreme, O Ruler of the whole!\n" + +"Say, hast thou doom'd to this divided state\n" + +"Or peaceful amity or stern debate?\n" + +"Declare thy purpose, for thy will is fate.'\n" + +"\n" + +"'Is not thy thought my own? (the god replies\n" + +"Who rolls the thunder o'er the vaulted skies;)\n" + +"Hath not long since thy knowing soul decreed\n" + +"The chief's return should make the guilty bleed.\n" + +"'Tis done, and at thy will the Fates succeed.\n" + +"Yet hear the issue: Since Ulysses' hand\n" + +"Has slain the suitors, Heaven shall bless the land.\n" + +"None now the kindred of the unjust shall own;\n" + +"Forgot the slaughter'd brother and the son:\n" + +"Each future day increase of wealth shall bring,\n" + +"\n" + +"And o'er the past Oblivion stretch her wing.\n" + +"Long shall Ulysses in his empire rest,\n" + +"His people blessing, by his people bless'd.\n" + +"Let all be peace.'--He said, and gave the nod\n" + +"That binds the Fates; the sanction of the god\n" + +"And prompt to execute the eternal will,\n" + +"Descended Pallas from the Olympian hill.\n" + +"\n" + +"Now sat Ulysses at the rural feast\n" + +"The rage of hunger and of thirst repress'd:\n" + +"To watch the foe a trusty spy he sent:\n" + +"A son of Dolius on the message went,\n" + +"Stood in the way, and at a glance beheld\n" + +"The foe approach, embattled on the field.\n" + +"With backward step he hastens to the bower,\n" + +"And tells the news. They arm with all their power.\n" + +"Four friends alone Ulysses' cause embrace,\n" + +"And six were all the sons of Dolius' race:\n" + +"Old Dolius too his rusted arms put on;\n" + +"And, still more old, in arms Laertes shone.\n" + +"Trembling with warmth, the hoary heroes stand,\n" + +"And brazen panoply invests the band.\n" + +"The opening gates at once their war display:\n" + +"Fierce they rush forth: Ulysses leads the way.\n" + +"That moment joins them with celestial aid,\n" + +"In Mentor's form, the Jove-descended maid:\n" + +"The suffering hero felt his patient breast\n" + +"Swell with new joy, and thus his son address'd:\n" + +"\n" + +"'Behold, Telemachus! (nor fear the sight,)\n" + +"The brave embattled, the grim front of fight!\n" + +"The valiant with the valiant must contend.\n" + +"Shame not the line whence glorious you descend.\n" + +"Wide o'er the world their martial fame was spread;\n" + +"Regard thyself, the living and the dead.'\n" + +"\n" + +"'Thy eyes, great father! on this battle cast,\n" + +"Shall learn from me Penelope was chaste.'\n" + +"\n" + +"So spoke Telemachus: the gallant boy\n" + +"Good old Laertes heard with panting joy.\n" + +"'And bless'd! thrice bless'd this happy day! (he cries,)\n" + +"The day that shows me, ere I close my eyes,\n" + +"A son and grandson of the Arcesian name\n" + +"Strive for fair virtue, and contest for fame!'\n" + +"\n" + +"Then thus Minerva in Laertes' ear:\n" + +"'Son of Arcesius, reverend warrior, hear!\n" + +"Jove and Jove's daughter first implore in prayer,\n" + +"Then, whirling high, discharge thy lance in air.'\n" + +"She said, infusing courage with the word.\n" + +"Jove and Jove's daughter then the chief implored,\n" + +"And, whirling high, dismiss'd the lance in air.\n" + +"Full at Eupithes drove the deathful spear:\n" + +"The brass-cheek'd helmet opens to the wound;\n" + +"He falls, earth thunders, and his arms resound.\n" + +"Before the father and the conquering son\n" + +"Heaps rush on heaps, they fight, they drop, they run\n" + +"Now by the sword, and now the javelin, fall\n" + +"The rebel race, and death had swallow'd all;\n" + +"But from on high the blue-eyed virgin cried;\n" + +"Her awful voice detain'd the headlong tide:\n" + +"'Forbear, ye nations, your mad hands forbear\n" + +"From mutual slaughter; Peace descends to spare.'\n" + +"Fear shook the nations: at the voice divine\n" + +"They drop their javelins, and their rage resign.\n" + +"All scatter'd round their glittering weapons lie;\n" + +"Some fall to earth, and some confusedly fly.\n" + +"With dreadful shouts Ulysses pour'd along,\n" + +"Swift as an eagle, as an eagle strong.\n" + +"But Jove's red arm the burning thunder aims:\n" + +"Before Minerva shot the livid flames;\n" + +"Blazing they fell, and at her feet expired;\n" + +"Then stopped the goddess, trembled and retired.\n" + +"\n" + +"'Descended from the gods! Ulysses, cease;\n" + +"Offend not Jove: obey, and give the peace.'\n" + +"\n" + +"So Pallas spoke: the mandate from above\n" + +"The king obey'd. The virgin-seed of Jove,\n" + +"In Mentor's form, confirm'd the full accord,\n" + +"And willing nations knew their lawful lord."; + + private static final String XML_CONTENT_WITH_LICENSE = + "\n" + + "\n" + + "\n" + + " 3\n" + + " Whatever\n" + + " apache-whatever\n" + + " whatever-madeup\n" + + " 0.1-SNAPSHOT\n" + + " 2006\n" + + " Apache Whatever Madeup Name\n" + + " Example Snippet From Imaginary POM\n" + + " /images/logo.png\n" + + ""; + + private static final String XML_CONTENT_WITHOUT_LICENSE = + "\n" + + "\n" + + "\n" + + " 3\n" + + " Whatever\n" + + " apache-whatever\n" + + " whatever-madeup\n" + + " 0.1-SNAPSHOT\n" + + " 2006\n" + + " Apache Whatever Madeup Name\n" + + " Example Snippet From Imaginary POM\n" + + " /images/logo.png\n" + + ""; + + /** + * Excert from + * http://svn.apache.org/repos/asf/jakarta/commons/proper/betwixt/trunk/project.properties + */ + private static final String PLAIN_CONTENT_WITH_LICENSE = + "# Copyright 2006 The Apache Software Foundation\n" + + "#\n" + + "# Licensed under the Apache License, Version 2.0 (the \"License\");\n" + + "# you may not use this file except in compliance with the License.\n" + + "# You may obtain a copy of the License at\n" + + "#\n" + + "# http://www.apache.org/licenses/LICENSE-2.0\n" + + "#\n" + + "# Unless required by applicable law or agreed to in writing, software\n" + + "# distributed under the License is distributed on an \"AS IS\" BASIS,\n" + + "# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + + "# See the License for the specific language governing permissions and\n" + + "# limitations under the License.\n" + + "\n" + + "# -------------------------------------------------------------------\n" + + "# P R O J E C T P R O P E R T I E S\n" + + "# -------------------------------------------------------------------\n" + + "\n" + + "maven.changelog.factory=org.apache.maven.svnlib.SvnChangeLogFactory\n" + + "\n" + + "maven.compile.debug = on\n" + + "maven.compile.optimize = off\n" + + "maven.compile.deprecation = on\n" + + "maven.compile.target = 1.1\n" + + "maven.compile.source=1.3\n"; + + + /** + * Excert from + * http://svn.apache.org/repos/asf/jakarta/commons/proper/betwixt/trunk/project.properties + */ + + private static final String PLAIN_CONTENT_WITHOUT_LICENSE = + "# Copyright 2006 The Apache Software Foundation\n" + + "\n" + + "# -------------------------------------------------------------------\n" + + "# P R O J E C T P R O P E R T I E S\n" + + "# -------------------------------------------------------------------\n" + + "\n" + + "maven.changelog.factory=org.apache.maven.svnlib.SvnChangeLogFactory\n" + + "\n" + + "maven.compile.debug = on\n" + + "maven.compile.optimize = off\n" + + "maven.compile.deprecation = on\n" + + "maven.compile.target = 1.1\n" + + "maven.compile.source=1.3\n"; + + /** + * Excert from + * http://svn.apache.org/repos/asf/jakarta/commons/proper/betwixt/trunk/src/java/org/apache/commons/betwixt/XMLUtils.java + */ + private static final String CODE_WITH_LICENSE = +"/*\n" + +" * Copyright 2001-2004 The Apache Software Foundation.\n" + +" * \n" + +" * Licensed under the Apache License, Version 2.0 (the \"License\");\n" + +" * you may not use this file except in compliance with the License.\n" + +" * You may obtain a copy of the License at\n" + +" * \n" + +" * http://www.apache.org/licenses/LICENSE-2.0\n" + +" * \n" + +" * Unless required by applicable law or agreed to in writing, software\n" + +" * distributed under the License is distributed on an \"AS IS\" BASIS,\n" + +" * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n" + +" * See the License for the specific language governing permissions and\n" + +" * limitations under the License.\n" + +" */ \n" + +"package org.apache.commons.betwixt;\n" + +" /**\n" + +" *

XMLUtils contains basic utility methods for XML.

\n" + +" * \n" + +" *

The code for {@link #isWellFormedXMLName} is based on code in\n" + +" * org.apache.xerces.util.XMLChar \n" + +" * in Apache Xerces.\n" + +" * The authors of this class are credited below.

\n" + +" *\n" + +" * @author Glenn Marcy, IBM\n" + +" * @author Andy Clark, IBM\n" + +" * @author Eric Ye, IBM\n" + +" * @author Arnaud Le Hors, IBM\n" + +" * @author Rahul Srivastava, Sun Microsystems Inc.\n" + +" *\n" + +" * @author Robert Burrell Donkin\n" + +" * @since 0.5\n" + +" */\n" + +"public class XMLUtils {"; + + private static final String CODE_WITHOUT_LICENSE = + "/*\n" + + " * Copyright 2001-2004 The Apache Software Foundation.\n" + + " * \n" + + " */ \n" + + "package org.apache.commons.betwixt;\n" + + " /**\n" + + " *

XMLUtils contains basic utility methods for XML.

\n" + + " * \n" + + " *

The code for {@link #isWellFormedXMLName} is based on code in\n" + + " * org.apache.xerces.util.XMLChar \n" + + " * in Apache Xerces.\n" + + " * The authors of this class are credited below.

\n" + + " *\n" + + " * @author Glenn Marcy, IBM\n" + + " * @author Andy Clark, IBM\n" + + " * @author Eric Ye, IBM\n" + + " * @author Arnaud Le Hors, IBM\n" + + " * @author Rahul Srivastava, Sun Microsystems Inc.\n" + + " *\n" + + " * @author Robert Burrell Donkin\n" + + " * @since 0.5\n" + + " */\n" + + "public class XMLUtils {"; + + MockClaimReporter reporter; + + protected void setUp() throws Exception { + super.setUp(); + reporter = new MockClaimReporter(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testIsFinished() throws Exception { + HeaderCheckWorker worker = new HeaderCheckWorker(new StringReader(""), new ApacheSoftwareLicense20(), reporter, "subject"); + assertFalse(worker.isFinished()); + worker.read(); + assertTrue(worker.isFinished()); + } +} Added: incubator/rat/import/rat/src/test/rat/report/analyser/ReadableArchiveAnalyserAnalyseTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/report/analyser/ReadableArchiveAnalyserAnalyseTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/report/analyser/ReadableArchiveAnalyserAnalyseTest.java (added) +++ incubator/rat/import/rat/src/test/rat/report/analyser/ReadableArchiveAnalyserAnalyseTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,64 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.report.analyser; + +import java.io.File; +import java.io.StringWriter; + +import junit.framework.TestCase; +import rat.document.impl.zip.ZipFileDocument; +import rat.report.claim.impl.xml.SimpleXmlClaimReporter; +import rat.report.xml.writer.impl.base.XmlWriter; + +public class ReadableArchiveAnalyserAnalyseTest extends TestCase { + + StringWriter out; + ReadableArchiveAnalyser analyser; + + protected void setUp() throws Exception { + super.setUp(); + out = new StringWriter(); + XmlWriter writer = new XmlWriter(out); + analyser = new ReadableArchiveAnalyser(new SimpleXmlClaimReporter(writer)); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testVisitReadableArchive() throws Exception { + String name = "src/test/elements/dummy.jar"; + ZipFileDocument document = new ZipFileDocument(new File(name)); + analyser.analyse(document); + assertEquals("Readable attribute set", + "", out.toString()); + } + + public void testVisitUnreadableArchive() throws Exception { + String name = "src/test/artifacts/dummy.tar.gz"; + ZipFileDocument document = new ZipFileDocument((new File(name))); + analyser.analyse(document); + assertEquals("Readable attribute unset", + "", out.toString()); + + } + + +} Added: incubator/rat/import/rat/src/test/rat/report/analyser/ReadableArchiveAnalyserTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/report/analyser/ReadableArchiveAnalyserTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/report/analyser/ReadableArchiveAnalyserTest.java (added) +++ incubator/rat/import/rat/src/test/rat/report/analyser/ReadableArchiveAnalyserTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,50 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.report.analyser; + +import rat.document.MockArchiveDocument; +import rat.document.MockDocument; +import rat.document.MockDocumentCollection; +import rat.report.claim.impl.xml.MockClaimReporter; +import junit.framework.TestCase; + +public class ReadableArchiveAnalyserTest extends TestCase { + + MockClaimReporter reporter; + ReadableArchiveAnalyser analyser; + + protected void setUp() throws Exception { + super.setUp(); + reporter = new MockClaimReporter(); + analyser = new ReadableArchiveAnalyser(reporter); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testUnreadableArchiveToObject() throws Exception { + MockDocument document = new MockDocument(); + assertEquals("Document is unreadable", ReadableArchiveAnalyser.UNREADABLE_ARCHIVE_VALUE, + analyser.toObject(document)); + } + + public void testReadableArchiveToObject() throws Exception { + MockArchiveDocument document = new MockArchiveDocument("whatever", new MockDocumentCollection()); + assertEquals("Document is readable", ReadableArchiveAnalyser.READABLE_ARCHIVE_VALUE, + analyser.toObject(document)); + } +} Added: incubator/rat/import/rat/src/test/rat/report/claim/impl/xml/MockClaimReporter.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/report/claim/impl/xml/MockClaimReporter.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/report/claim/impl/xml/MockClaimReporter.java (added) +++ incubator/rat/import/rat/src/test/rat/report/claim/impl/xml/MockClaimReporter.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,63 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.report.claim.impl.xml; + +import java.util.ArrayList; +import java.util.List; + +import rat.report.RatReportFailedException; +import rat.report.claim.IClaimReporter; + +public class MockClaimReporter implements IClaimReporter { + + public List claims = new ArrayList(); + + public void claim(CharSequence subject, CharSequence predicate, + CharSequence object, boolean isLiteral) + throws RatReportFailedException { + claims.add(new Claim(subject, predicate, object, isLiteral)); + } + + public Claim getClaim(int index) { + return (Claim) claims.get(index); + } + + public static class Claim { + public final CharSequence subject; + public final CharSequence predicate; + public final CharSequence object; + public final boolean isLiteral; + public Claim(final CharSequence subject, final CharSequence predicate, final CharSequence object, final boolean isLiteral) { + super(); + this.subject = subject; + this.predicate = predicate; + this.object = object; + this.isLiteral = isLiteral; + } + + public boolean equals(Object obj) { + boolean result = false; + if (obj instanceof Claim) { + Claim claim = (Claim) obj; + result = subject.equals(claim.subject) && predicate.equals(claim.predicate) + && object.equals(claim.object) && isLiteral == claim.isLiteral; + } + return result; + } + + + } +} Added: incubator/rat/import/rat/src/test/rat/report/claim/impl/xml/SimpleXmlClaimReporterTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/report/claim/impl/xml/SimpleXmlClaimReporterTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/report/claim/impl/xml/SimpleXmlClaimReporterTest.java (added) +++ incubator/rat/import/rat/src/test/rat/report/claim/impl/xml/SimpleXmlClaimReporterTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,90 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.report.claim.impl.xml; + +import junit.framework.TestCase; +import rat.report.xml.MockXmlWriter; + +public class SimpleXmlClaimReporterTest extends TestCase { + + MockXmlWriter mockWriter; + SimpleXmlClaimReporter reporter; + + protected void setUp() throws Exception { + super.setUp(); + mockWriter = new MockXmlWriter(); + reporter = new SimpleXmlClaimReporter(mockWriter); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testClaimsAboutOneResource() throws Exception { + final String subject = "subject"; + final String predicate = "predicate"; + final String object = "object"; + reporter.claim(subject, predicate, object, false); + assertEquals("Five calls made", 5, mockWriter.calls.size()); + assertTrue("First call is open element 'resource'", mockWriter.isOpenElement("resource", 0)); + assertTrue("Second call is name attribute", mockWriter.isAttribute("name", subject, 1)); + assertTrue("Third call is predicate element", mockWriter.isOpenElement(predicate, 2)); + assertTrue("Forth call is object attribute", mockWriter.isAttribute("name", object, 3)); + assertTrue("Fifth call is close element", mockWriter.isCloseElement(4)); + final String predicateTwo = "another-predicate"; + final String objectTwo = "another-object"; + reporter.claim(subject, predicateTwo, objectTwo, false); + assertEquals("Another three calls made", 8, mockWriter.calls.size()); + assertTrue("Sixth call is predicate element", mockWriter.isOpenElement(predicateTwo, 5)); + assertTrue("Seventh call is object attribute", mockWriter.isAttribute("name", objectTwo, 6)); + assertTrue("Eighth call is close element", mockWriter.isCloseElement(7)); + } + + public void testClaimsAboutTwoResource() throws Exception { + final String subject = "subject"; + final String predicate = "predicate"; + final String object = "object"; + reporter.claim(subject, predicate, object, false); + assertEquals("Five calls made", 5, mockWriter.calls.size()); + assertTrue("First call is open element 'resource'", mockWriter.isOpenElement("resource", 0)); + assertTrue("Second call is name attribute", mockWriter.isAttribute("name", subject, 1)); + assertTrue("Third call is predicate element", mockWriter.isOpenElement(predicate, 2)); + assertTrue("Forth call is object attribute", mockWriter.isAttribute("name", object, 3)); + assertTrue("Fifth call is close element", mockWriter.isCloseElement(4)); + final String subjectTwo = "another-subject"; + reporter.claim(subjectTwo, predicate, object, false); + assertEquals("Another found calls made", 11, mockWriter.calls.size()); + assertTrue("Sixth call is close element", mockWriter.isCloseElement(5)); + assertTrue("Seventh call is open element 'resource'", mockWriter.isOpenElement("resource", 6)); + assertTrue("Eighth call is name attribute", mockWriter.isAttribute("name", subjectTwo, 7)); + assertTrue("Nineth call is predicate element", mockWriter.isOpenElement(predicate, 8)); + assertTrue("Tenth call is object attribute", mockWriter.isAttribute("name", object, 9)); + assertTrue("Eleventh call is close element", mockWriter.isCloseElement(10)); + } + + public void testLiteralClaim() throws Exception { + final String subject = "subject"; + final String predicate = "predicate"; + final String object = "object"; + reporter.claim(subject, predicate, object, true); + assertEquals("Five calls made", 5, mockWriter.calls.size()); + assertTrue("First call is open element 'resource'", mockWriter.isOpenElement("resource", 0)); + assertTrue("Second call is name attribute", mockWriter.isAttribute("name", subject, 1)); + assertTrue("Third call is predicate element", mockWriter.isOpenElement(predicate, 2)); + assertTrue("Forth call is object content", mockWriter.isContent(object, 3)); + assertTrue("Fifth call is close element", mockWriter.isCloseElement(4)); + } +} Added: incubator/rat/import/rat/src/test/rat/report/claim/util/ClaimReporterMultiplexerTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/report/claim/util/ClaimReporterMultiplexerTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/report/claim/util/ClaimReporterMultiplexerTest.java (added) +++ incubator/rat/import/rat/src/test/rat/report/claim/util/ClaimReporterMultiplexerTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,62 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.report.claim.util; + +import rat.report.claim.IClaimReporter; +import rat.report.claim.impl.xml.MockClaimReporter; +import junit.framework.TestCase; + +public class ClaimReporterMultiplexerTest extends TestCase { + + MockClaimReporter reporterOne; + MockClaimReporter reporterTwo; + MockClaimReporter reporterThree; + ClaimReporterMultiplexer multiplexer; + + protected void setUp() throws Exception { + super.setUp(); + reporterOne = new MockClaimReporter(); + reporterTwo = new MockClaimReporter(); + reporterThree = new MockClaimReporter(); + IClaimReporter[] reporters = {reporterOne, reporterTwo, reporterThree}; + multiplexer = new ClaimReporterMultiplexer(reporters); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + public void testClaim() throws Exception { + multiplexer.claim("subject", "predicate", "object", true); + MockClaimReporter.Claim claimOne = new MockClaimReporter.Claim("subject", "predicate", "object", true); + assertEquals("Claim reported", 1 , reporterOne.claims.size()); + assertEquals("Claim reported", claimOne, reporterOne.claims.get(0)); + assertEquals("Claim reported", 1 , reporterTwo.claims.size()); + assertEquals("Claim reported", claimOne, reporterTwo.claims.get(0)); + assertEquals("Claim reported", 1 , reporterThree.claims.size()); + assertEquals("Claim reported", claimOne, reporterThree.claims.get(0)); + multiplexer.claim("another subject", "another predicate", "another object", false); + MockClaimReporter.Claim claimTwo = new MockClaimReporter.Claim("another subject", "another predicate", "another object", false); + assertEquals("Claim reported", 2, reporterOne.claims.size()); + assertEquals("Claim reported", claimTwo, reporterOne.claims.get(1)); + assertEquals("Claim reported", 2, reporterTwo.claims.size()); + assertEquals("Claim reported", claimTwo, reporterTwo.claims.get(1)); + assertEquals("Claim reported", 2, reporterThree.claims.size()); + assertEquals("Claim reported", claimTwo, reporterThree.claims.get(1)); + + } + +} Added: incubator/rat/import/rat/src/test/rat/report/xml/MockXmlWriter.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/report/xml/MockXmlWriter.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/report/xml/MockXmlWriter.java (added) +++ incubator/rat/import/rat/src/test/rat/report/xml/MockXmlWriter.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,123 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.report.xml; + +import java.io.IOException; +import java.util.ArrayList; +import java.util.List; + +import rat.report.xml.writer.IXmlWriter; + +public class MockXmlWriter implements IXmlWriter { + + public final List calls; + + public MockXmlWriter() { + calls = new ArrayList(); + } + + public IXmlWriter attribute(CharSequence name, CharSequence value) + throws IOException { + calls.add(new Attribute(name, value)); + return this; + } + + public IXmlWriter closeDocument() throws IOException { + calls.add(new CloseDocument()); + return this; + } + + public IXmlWriter closeElement() throws IOException { + calls.add(new CloseElement()); + return this; + } + + public IXmlWriter content(CharSequence content) throws IOException { + calls.add(new Content(content)); + return this; + } + + public IXmlWriter openElement(CharSequence elementName) throws IOException { + calls.add(new OpenElement(elementName)); + return this; + } + + public IXmlWriter startDocument() throws IOException { + calls.add(new StartDocument()); + return this; + } + + public boolean isCloseElement(int index) { + boolean result = false; + final Object call = calls.get(index); + result = call instanceof CloseElement; + return result; + } + + public boolean isContent(String content, int index) { + boolean result = false; + final Object call = calls.get(index); + if (call instanceof Content) { + Content contentCall = (Content) call; + result = content.equals(contentCall.content); + } + return result; + } + + public boolean isOpenElement(String name, int index) { + boolean result = false; + final Object call = calls.get(index); + if (call instanceof OpenElement) { + OpenElement openElement = (OpenElement) call; + result = name.equals(openElement.elementName); + } + return result; + } + + public boolean isAttribute(String name, String value, int index) { + boolean result = false; + final Object call = calls.get(index); + if (call instanceof Attribute) { + Attribute attribute = (Attribute) call; + result = name.equals(attribute.name) && value.equals(attribute.value); + } + return result; + } + + public class StartDocument {} + public class CloseDocument {} + public class CloseElement {} + public class OpenElement { + public final CharSequence elementName; + private OpenElement(CharSequence elementName) { + this.elementName = elementName; + } + } + public class Content { + public final CharSequence content; + private Content(CharSequence content) { + this.content = content; + } + } + public class Attribute { + public final CharSequence name; + public final CharSequence value; + private Attribute(CharSequence name, CharSequence value) { + this.name = name; + this.value = value; + } + } +} Added: incubator/rat/import/rat/src/test/rat/report/xml/XmlReportFactoryTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/report/xml/XmlReportFactoryTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/report/xml/XmlReportFactoryTest.java (added) +++ incubator/rat/import/rat/src/test/rat/report/xml/XmlReportFactoryTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,77 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.report.xml; + +import java.io.File; +import java.io.StringWriter; +import java.util.regex.Pattern; + +import junit.framework.TestCase; +import rat.DirectoryWalker; +import rat.analysis.MockLicenseMatcher; +import rat.report.RatReport; +import rat.report.xml.writer.IXmlWriter; +import rat.report.xml.writer.impl.base.XmlWriter; + +public class XmlReportFactoryTest extends TestCase { + + private static final Pattern IGNORE_EMPTY = Pattern.compile(".svn|Empty.txt"); + + StringWriter out; + IXmlWriter writer; + + protected void setUp() throws Exception { + super.setUp(); + out = new StringWriter(); + writer = new XmlWriter(out); + writer.startDocument(); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + + private void report(DirectoryWalker directory, RatReport report) throws Exception { + directory.run(report); + } + + public void testStandardReport() throws Exception { + final MockLicenseMatcher mockLicenseMatcher = new MockLicenseMatcher(); + DirectoryWalker directory = new DirectoryWalker(new File("src/test/elements"), IGNORE_EMPTY); + RatReport report = XmlReportFactory.createStandardReport(writer, mockLicenseMatcher); + report.startReport(); + report(directory, report); + report.endReport(); + writer.closeDocument(); + final String output = out.toString(); + assertEquals( + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "", output); + assertTrue("Is well formed", XmlUtils.isWellFormedXml(output)); + } +} Added: incubator/rat/import/rat/src/test/rat/report/xml/XmlReportTest.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/report/xml/XmlReportTest.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/report/xml/XmlReportTest.java (added) +++ incubator/rat/import/rat/src/test/rat/report/xml/XmlReportTest.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,81 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.report.xml; + +import java.io.File; +import java.io.StringWriter; +import java.util.regex.Pattern; + +import junit.framework.TestCase; +import rat.DirectoryWalker; +import rat.document.IDocumentAnalyser; +import rat.report.analyser.DefaultAnalyserFactory; +import rat.report.claim.impl.xml.SimpleXmlClaimReporter; +import rat.report.xml.writer.IXmlWriter; +import rat.report.xml.writer.impl.base.XmlWriter; + +public class XmlReportTest extends TestCase { + + private static final Pattern IGNORE = Pattern.compile(".svn"); + StringWriter out; + IXmlWriter writer; + XmlReport report; + + protected void setUp() throws Exception { + super.setUp(); + out = new StringWriter(); + writer = new XmlWriter(out); + writer.startDocument(); + final SimpleXmlClaimReporter reporter = new SimpleXmlClaimReporter(writer); + IDocumentAnalyser archiveAnalyser = DefaultAnalyserFactory.createArchiveTypeAnalyser(reporter); + IDocumentAnalyser binaryAnalyser = DefaultAnalyserFactory.createBinaryTypeAnalyser(reporter); + IDocumentAnalyser noticeAnalyser = DefaultAnalyserFactory.createNoticeTypeAnalyser(reporter); + IDocumentAnalyser standardAnalyser = DefaultAnalyserFactory.createStandardTypeAnalyser(reporter); + IDocumentAnalyser analyser =DefaultAnalyserFactory.createDefaultAnalyser(binaryAnalyser, archiveAnalyser, noticeAnalyser, standardAnalyser); + report = new XmlReport(writer, analyser); + } + + protected void tearDown() throws Exception { + super.tearDown(); + } + + private void report(DirectoryWalker directory) throws Exception { + directory.run(report); + } + + public void testBaseReport() throws Exception { + DirectoryWalker directory = new DirectoryWalker(new File("src/test/elements"), IGNORE); + report.startReport(); + report(directory); + report.endReport(); + writer.closeDocument(); + final String output = out.toString();; + assertEquals( + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "" + + "", output); + assertTrue("Is well formed", XmlUtils.isWellFormedXml(output)); + } + +} Added: incubator/rat/import/rat/src/test/rat/report/xml/XmlUtils.java URL: http://svn.apache.org/viewvc/incubator/rat/import/rat/src/test/rat/report/xml/XmlUtils.java?rev=636144&view=auto ============================================================================== --- incubator/rat/import/rat/src/test/rat/report/xml/XmlUtils.java (added) +++ incubator/rat/import/rat/src/test/rat/report/xml/XmlUtils.java Tue Mar 11 16:08:58 2008 @@ -0,0 +1,56 @@ +/* + * Copyright 2006 Robert Burrell Donkin + * + * 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 rat.report.xml; + +import java.io.IOException; +import java.io.InputStream; +import java.io.StringBufferInputStream; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.parsers.FactoryConfigurationError; +import javax.xml.parsers.ParserConfigurationException; + +import org.w3c.dom.Document; +import org.xml.sax.SAXException; + +public final class XmlUtils { + + public static final boolean isWellFormedXml(final String string) throws Exception { + return isWellFormedXml(new StringBufferInputStream(string)); + } + + + + public static final boolean isWellFormedXml(final InputStream in) throws Exception { + boolean result = true; + try { + toDom(in); + } catch (SAXException e) { + System.out.println(e); + e.printStackTrace(); + result = false; + } + return result; + } + + public static final Document toDom(final InputStream in) throws SAXException, IOException, ParserConfigurationException, FactoryConfigurationError { + final DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); + Document result; + result = builder.parse(in); + return result; + } +}