01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19: package org.apache.axis2.deployment;
20:
21: import junit.framework.TestCase;
22: import org.apache.axis2.AxisFault;
23: import org.apache.axis2.context.ConfigurationContextFactory;
24: import org.apache.axis2.description.AxisService;
25: import org.apache.axis2.description.AxisServiceGroup;
26: import org.apache.axis2.engine.AxisConfiguration;
27:
28: /**
29: * This test confirms that we behave correctly when adding ServiceGroups with duplicate
30: * Services to ones that have already been deployed.
31: */
32: public class SameServiceAddingTest extends TestCase {
33: AxisConfiguration config;
34:
35: public void testServiceGroup() throws AxisFault {
36: final String SERVICE1 = "serevice1";
37: final String SERVICE2 = "serevice2";
38: final String SERVICE4 = "serevice4";
39: final String SERVICE_GROUP2 = "ServiceGroup2";
40:
41: config = ConfigurationContextFactory
42: .createConfigurationContextFromFileSystem(null, null)
43: .getAxisConfiguration();
44:
45: // First create a ServiceGroup with S1 and S4
46: AxisServiceGroup axisServiceGroup1 = new AxisServiceGroup();
47: axisServiceGroup1.setServiceGroupName("ServiceGroup1");
48: AxisService service1 = new AxisService();
49: service1.setName(SERVICE1);
50: axisServiceGroup1.addService(service1);
51:
52: AxisService service4 = new AxisService();
53: service4.setName(SERVICE4);
54: axisServiceGroup1.addService(service4);
55: config.addServiceGroup(axisServiceGroup1);
56:
57: // Now create another ServiceGroup with S2 and S4
58: AxisServiceGroup axisServiceGroup2 = new AxisServiceGroup();
59: axisServiceGroup2.setServiceGroupName(SERVICE_GROUP2);
60: AxisService service2 = new AxisService();
61: service2.setName(SERVICE2);
62: axisServiceGroup2.addService(service2);
63:
64: AxisService service24 = new AxisService();
65: service24.setName(SERVICE4);
66: axisServiceGroup2.addService(service24);
67: try {
68: // This should fail!
69: config.addServiceGroup(axisServiceGroup2);
70: } catch (AxisFault axisFault) {
71: // This is expected because S4 was a duplicate name to an already existing service
72: assertTrue("Caught the wrong fault!", axisFault
73: .getMessage().indexOf(SERVICE4) > -1);
74: }
75:
76: AxisService service = config.getService(SERVICE1);
77: assertNotNull("Service 1 wasn't deployed!", service);
78: service = config.getService(SERVICE4);
79: assertNotNull("Service 4 wasn't deployed!", service);
80:
81: service = config.getService(SERVICE2);
82: assertNull("Service 2 wasn't supposed to be deployed!", service);
83: assertNull("ServiceGroup2 wasn't supposed to be deployed!",
84: config.getServiceGroup("service2"));
85: }
86:
87: }
|