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.businessfacades.artifact;
16
17 import org.figure8.join.core.DuplicateEntityException;
18 import org.figure8.join.businessobjects.artifact.DeliverableType;
19 import org.figure8.join.util.SpringTestCase;
20 /**
21 * JUnit test case for testing the ArtifactProcessManager implementation
22 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
23 * @version $Revision: 1.1 $
24 */
25 public class ArtifactManagerTest extends SpringTestCase{
26
27
28
29 /** Spring configuration files */
30 private String[] configLocations = new String[]{
31 "classpath:/org/figure8/join/businessfacades/artifact/spring.xml",
32 "classpath:/org/figure8/join/businessobjects/artifact/persistence/spring.xml"};
33
34
35
36
37 /** The ArtifactManager implementation to test */
38 protected ArtifactManager artifactManager = null;
39
40
41
42
43 /** Retrieve artifact manager after having initialized context */
44 public void setUp(){
45 super.setUp();
46
47 artifactManager = (ArtifactManager)context.getBean("artifactManager");
48 }
49
50
51
52
53 /** Test deliverable types related method */
54 public void testDeliverableTypes(){
55
56 DeliverableType type1 = new DeliverableType("type1", "Type 1 label", "type1-r{0}-v{1}", true, true);
57 DeliverableType type2 = new DeliverableType("type2", "Type 2 label", "type2-r{0}-v{1}", true, false);
58 try{
59 artifactManager.saveDeliverableType(type1);
60 artifactManager.saveDeliverableType(type2);
61 }
62 catch (Exception e){
63 fail("No exception should be thrown");
64 }
65
66 assertEquals("Two DeliverableTypes have been successfully created", 2, artifactManager.getDeliverableTypes().size());
67
68
69 DeliverableType foundType = artifactManager.getDeliverableType("type2");
70
71 assertNotNull("Found a DeliverableType", foundType);
72 assertEquals("Found the correct DeliverableType", "Type 2 label", foundType.getLabel());
73 assertEquals("Found the correct DeliverableType", "type2-r{0}-v{1}", foundType.getKeyTemplate());
74 assertEquals("Found the correct DeliverableType", true, foundType.getVersionable());
75 assertEquals("Found the correct DeliverableType", false, foundType.getMandatory());
76 assertEquals("Found the correct DeliverableType", false, foundType.getVcsDeliverable());
77
78
79 foundType.setLabel("Type 2 updated label");
80 foundType.setMandatory(true);
81 try {artifactManager.saveDeliverableType(foundType);}
82 catch (Exception e) {fail("No exception should be thrown");}
83
84 assertEquals("Two DeliverableTypes are enlisted", 2, artifactManager.getDeliverableTypes().size());
85
86
87 boolean exception = false;
88 DeliverableType type3 = new DeliverableType("type1", "Type 3 label", "type2-r{0}-v{1}", true, false);
89 try{
90
91 artifactManager.saveDeliverableType(type3);
92 }
93 catch (DuplicateEntityException de){
94
95 assertEquals("Original entity causes duplicate", "type1", ((DeliverableType)de.getOriginalEntity()).getKey());
96 exception = true;
97 }
98 assertTrue("DuplicateEntityException was thrown", exception);
99 }
100
101
102
103
104 /** @return configLocations inner field */
105 public String[] getConfigLocations(){
106 return configLocations;
107 }
108 }