1   /*
2    * Copyright 2005 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.vafer.jdeb.changes;
17  
18  import java.io.ByteArrayInputStream;
19  
20  import junit.framework.TestCase;
21  
22  import org.vafer.jdeb.descriptors.PackageDescriptor;
23  
24  public final class TextfileChangesProviderTestCase extends TestCase {
25  
26  	public void testParsing() throws Exception {
27  
28  		final String input =
29  			" * change1\n" +
30  			" * change2\n" +
31  			"release date=14:00 13.01.2007, version=12324, urgency=low, by=tcurdt@joost.com\n" +
32  			" * change1\n" +
33  			" * change2\n" +
34  			"release date=12:00 10.01.2007, version=10324, urgency=low, by=tcurdt@joost.com\n" +
35  			" * change1\n" +
36  			" * change2\n";
37  		
38  		final PackageDescriptor descriptor = new PackageDescriptor();
39  		descriptor.set("Package", "package");
40  		descriptor.set("Version", "version");
41  		descriptor.set("Distribution", "distribution");
42  		descriptor.set("Date", "Mon, 20 Aug 2007 15:25:57 +0200");
43  		
44  		final TextfileChangesProvider provider = new TextfileChangesProvider(new ByteArrayInputStream(input.getBytes("UTF-8")), descriptor);
45  		final ChangeSet[] changeSets = provider.getChangesSets();
46  		
47  		assertNotNull(changeSets);
48  		assertEquals(3, changeSets.length);		
49  	}
50  
51  	public void testDistributionFromChangesProvider() throws Exception {
52  
53  		final String input =
54  			"release distribution=production\n" +
55  			" * change1\n" +
56  			" * change2\n" +
57  			"release distribution=staging, date=14:00 13.01.2007, version=12324, urgency=low, by=tcurdt@joost.com\n" +
58  			" * change1\n" +
59  			" * change2\n" +
60  			"release distribution=development, date=12:00 10.01.2007, version=10324, urgency=low, by=tcurdt@joost.com\n" +
61  			" * change1\n" +
62  			" * change2\n";
63  		
64  		final PackageDescriptor descriptor = new PackageDescriptor();
65  		descriptor.set("Package", "package");
66  		descriptor.set("Version", "version");
67  		descriptor.set("Date", "Mon, 20 Aug 2007 15:25:57 +0200");
68  		
69  		final TextfileChangesProvider provider = new TextfileChangesProvider(new ByteArrayInputStream(input.getBytes("UTF-8")), descriptor);
70  		final ChangeSet[] changeSets = provider.getChangesSets();
71  		
72  		assertNotNull(changeSets);
73  		assertEquals(3, changeSets.length);
74  		
75  		assertEquals("production", changeSets[0].getDistribution());
76  		assertEquals("staging", changeSets[1].getDistribution());
77  		assertEquals("development", changeSets[2].getDistribution());
78  		
79  	}
80  
81  }