1   /**
2    * Copyright 2005-2006 the original author or authors.
3    *
4    * Licensed under the Gnu General Pubic License, Version 2.0 (the
5    * "License"); you may not use this file except in compliance with
6    * the License. You may obtain a copy of the License at
7    *
8    *      http://www.opensource.org/licenses/gpl-license.php
9    *
10   * This program is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13   * See the Gnu General Public License for more details.
14   */
15  package org.figure8.join.businessobjects.artifact;
16  
17  import org.figure8.join.core.InvalidParameterException;
18  import org.figure8.join.businessobjects.commons.Release;
19  import org.figure8.join.services.vcs.SubversionAccessor;
20  
21  import junit.framework.Test;
22  import junit.framework.TestCase;
23  import junit.framework.TestSuite;
24  
25  import java.util.Date;
26  /**
27   * JUnit tests for DeliverableType business object.
28   * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
29   * @version $Revision: 1.2 $
30   */
31  public class DeliverableTypeTest extends TestCase{
32  
33     // Constructors -------------------------------------------------------------
34  
35     /** Build a test case using a name */
36     public DeliverableTypeTest(String name){
37        super(name);
38     }
39  
40  
41     // Override of TestCase -----------------------------------------------------
42  
43     /**
44      * Make this class a TestSuite.
45      * @return A TestSuite containing this TestCase.
46      */
47     public static Test suite(){
48        TestSuite suite = new TestSuite(DeliverableTypeTest.class);
49        return suite;
50     }
51  
52  
53     // Public -------------------------------------------------------------------
54  
55     /** Test the generation of deliverable key */
56     public void testGenerateDeliverableKey(){
57        // Create the test fixtures.
58        Release release = new Release("1.0", 1, 0, new Date());
59        DeliverableType type = new DeliverableType("myKey", "mylabel", "myKey-r{0}-v{1}", true, true);
60        Deliverable deliverable = new Deliverable("01", "comments", "supplierId", release, type);
61        // Generate a key for deliverable.
62        String key = type.generateDeliverableKey(deliverable);
63        // Assert.
64        assertNotNull("Generated key is not null", key);
65        assertEquals("Key generation is successfull", "myKey-r1.0-v01", key);
66     }
67  
68     /** Test the retrieval of a VCSAccesor */
69     public void testGetVCSAccessor(){
70        // Create the test fixture.
71        DeliverableType type = new DeliverableType("myKey", "mylabel", "myKey-r{0}-v{1}", true, true);
72        type.setVcsDeliverable(true);
73        type.setVcsUser("myUser");
74        type.setVcsRoot("myRoot");
75        type.setVcsModule("myModule");
76        type.setVcsPassword("myPwd");
77  
78        SubversionAccessor accessor = null;
79        try{
80           // Build and retrieve accessor.
81           type.setVcsAccessorClass("org.figure8.join.services.vcs.SubversionAccessor");
82           accessor = (SubversionAccessor)type.getVCSAccessor();
83        }
84        catch (Exception e){
85           fail("VCSAccessor implementation is not recognized: " + e.getMessage());
86        }
87        // Assert that accessor is ready to use.
88        assertNotNull("VCSAccessor is not null", accessor);
89        assertEquals("VCSAccessor has correct user", "myUser", accessor.getUser());
90        assertEquals("VCSAccessor has correct password", "myPwd", accessor.getPassword());
91        assertEquals("VCSAccessor has correct module", "myModule", accessor.getModule());
92        assertEquals("VCSAccessor has correct root", "myRoot", accessor.getRootRepository());
93     }
94  
95     /** Test the failure of instantiating a VCSAccessor */
96     public void testVCSAccessorInstantiationFailure(){
97        // Create the test fixture.
98        DeliverableType type = new DeliverableType("myKey", "mylabel", "myKey-r{0}-v{1}", true, true);
99        type.setVcsDeliverable(true);
100       type.setVcsUser("myUser");
101       type.setVcsRoot("myRoot");
102       type.setVcsModule("myModule");
103       type.setVcsPassword("myPwd");
104 
105       try{
106          // Build fake VCSAccessor.
107          type.setVcsAccessorClass("org.figure8.join.services.vcs.MyFakeAccessor");
108       }
109       catch (Exception e){
110          assertTrue("Fake VCSAccessor implementation cannot be assign", (e instanceof InvalidParameterException));
111       }
112    }
113 }