2 * Copyright 2008 the original author or authors.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package org.wamblee.system.core;
18 import java.util.ArrayList;
19 import java.util.Arrays;
20 import java.util.List;
22 import org.wamblee.test.AssertionUtils;
24 import junit.framework.TestCase;
26 public class DefaultInterfaceRestrictionTest extends TestCase {
27 private Application _app1 = new Application("app1", "pf1.");
28 private Application _app2 = new Application("app2", "pf2.");
30 private Environment _env1 = new Environment("env1", "pf3.");
31 private Environment _env2 = new Environment("env2", "pf4.");
34 private void compare(Boolean[] aExpected, InterfaceRestriction aRestriction) {
35 List<Boolean> result = new ArrayList<Boolean>();
42 for (Environment env: new Environment[] { _env1, _env2} ) {
43 for (Application app: new Application[] { _app1, _app2} ) {
44 result.add(aRestriction.isViolated(
45 app, app.getRequiredInterfaces()[0],
47 env.getProvidedInterfaces()[0]
53 assertEquals(Arrays.asList(aExpected), result);
56 public void testNoRestriction() {
57 AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
59 public void run() throws Exception {
60 InterfaceRestriction restriction = new DefaultInterfaceRestriction(null, null, null, null);
63 }, IllegalArgumentException.class);
64 AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
66 public void run() throws Exception {
67 InterfaceRestriction restriction = new DefaultInterfaceRestriction(null, null, "x", "y");
70 }, IllegalArgumentException.class);
71 AssertionUtils.assertException(new AssertionUtils.ErroneousCode() {
73 public void run() throws Exception {
74 InterfaceRestriction restriction = new DefaultInterfaceRestriction("x", "y", null, null);
77 }, IllegalArgumentException.class);
80 public void testClientServer() {
81 InterfaceRestriction restriction = new DefaultInterfaceRestriction("app1", null, "env1", null);
82 compare(new Boolean[] { false, false, true, false}, restriction);
85 public void testRequiredServer() {
86 InterfaceRestriction restriction = new DefaultInterfaceRestriction(null, "pf1.string", "env1", null);
87 compare(new Boolean[] { false, false, true, false}, restriction);
90 public void testClientProvided() {
91 InterfaceRestriction restriction = new DefaultInterfaceRestriction("app1", null, null, "pf4.datasource");
92 compare(new Boolean[] { true, false, false, false}, restriction);
95 public void testRequiredProvide() {
96 InterfaceRestriction restriction = new DefaultInterfaceRestriction(null, "pf1.string", null, "pf4.datasource");
97 compare(new Boolean[] { true, false, false, false}, restriction);
100 public void testExplicitConfig() {
101 _app1 = new Application("app1");
102 _app2 = new Application("app2");
103 _env1 = new Environment("env1");
104 _env2 = new Environment("env2");
106 InterfaceRestriction restriction = new DefaultInterfaceRestriction(
107 "app2", "string", "env1", "datasource");
108 compare(new Boolean[] { false, false, false, true}, restriction);