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.environment;
16
17 import org.figure8.join.core.DuplicateEntityException;
18 import org.figure8.join.businessobjects.environment.Machine;
19 import org.figure8.join.businessobjects.environment.Gateway;
20 import org.figure8.join.businessobjects.environment.Service;
21 import org.figure8.join.businessobjects.environment.GatewayType;
22 import org.figure8.join.businessobjects.environment.ServiceType;
23 import org.figure8.join.util.SpringTestCase;
24
25 import java.util.List;
26 /**
27 * JUnit test case for testing the ResourceManager implementation
28 * @author <a href="mailto:laurent.broudoux@free.fr">Laurent Broudoux</a>
29 * @version $Revision: 1.1 $
30 */
31 public class ResourceManagerTest extends SpringTestCase{
32
33
34
35 /** Spring configuration files */
36 private String[] configLocations = new String[]{
37 "classpath:/org/figure8/join/businessfacades/environment/spring.xml",
38 "classpath:/org/figure8/join/businessobjects/environment/persistence/spring.xml"};
39
40
41
42
43 /** The ResourceManager implementation instance to test. */
44 protected ResourceManager resourceManager = null;
45
46
47
48
49 /** Retrieve resource manager after having initialized context */
50 public void setUp(){
51 super.setUp();
52
53 resourceManager = (ResourceManager)context.getBean("resourceManager");
54 }
55
56
57
58
59 /** Test resource types related methods. */
60 public void testResourceTypes(){
61
62 ServiceType type1 = new ServiceType("servTypeKey", "servTypeLabel");
63 GatewayType type2 = new GatewayType("gateTypeKey", "gateTypeLabel");
64 try{
65 resourceManager.saveResourceType(type1);
66 resourceManager.saveResourceType(type2);
67 }
68 catch (Exception e){
69 fail("No exceptin should be thrown");
70 }
71
72 assertEquals("Two ResourceTypes have been created successfully", 2, resourceManager.getResourceTypes().size());
73
74
75 }
76
77 /** Test resources related methods. */
78 public void testResources(){
79
80
81 }
82
83 /** Test machine related methods. */
84 public void testMachines(){
85
86 Machine machine1 = new Machine("machine1.myorg.org", "127.0.0.1");
87 Machine machine2 = new Machine("machine2.myorg.org", "127.0.0.2");
88 try{
89 resourceManager.saveMachine(machine1);
90 resourceManager.saveMachine(machine2);
91 }
92 catch (Exception e){
93 fail("No exception should be thrown");
94 }
95
96 assertEquals("Two Machines have been created sucessfully", 2, resourceManager.getMachines().size());
97
98
99 boolean exception = false;
100 Machine machine3 = new Machine("machine2.myorg.org", "127.0.0.3");
101 try{
102
103 resourceManager.saveMachine(machine3);
104 }
105 catch (DuplicateEntityException dee){
106
107 assertEquals("Original entity causes duplicate", "machine2.myorg.org", ((Machine)dee.getOriginalEntity()).getName());
108 exception = true;
109 }
110 assertTrue("DuplicateEntityException was thrown", exception);
111 }
112
113
114
115
116 /** @return configLocations inner field */
117 public String[] getConfigLocations(){
118 return configLocations;
119 }
120 }
121