X-Git-Url: http://wamblee.org/gitweb/?a=blobdiff_plain;f=system%2Fgeneral%2Fsrc%2Ftest%2Fjava%2Forg%2Fwamblee%2Fsystem%2Fgraph%2Fcomponent%2FConnectRequiredProvidedEdgeFilterTest.java;h=6010ac39c82eedcf13a7038bc12ae7439450008e;hb=8de36ff0206c996baf3ee4adc3e2293b12ff5f39;hp=0cb9013b742535a886cbb134d733529e3147d3b3;hpb=32a8562695029cf13d915bc7941a61fe07ff0005;p=utils diff --git a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java index 0cb9013b..6010ac39 100644 --- a/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java +++ b/system/general/src/test/java/org/wamblee/system/graph/component/ConnectRequiredProvidedEdgeFilterTest.java @@ -1,23 +1,21 @@ /* * Copyright 2008 the original author or authors. - * + * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. - */ + */ package org.wamblee.system.graph.component; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; +import junit.framework.TestCase; import org.wamblee.system.container.Application; import org.wamblee.system.core.Environment; @@ -25,79 +23,86 @@ import org.wamblee.system.graph.DefaultEdge; import org.wamblee.system.graph.Edge; import org.wamblee.system.graph.EdgeFilter; import org.wamblee.system.graph.Node; + import org.wamblee.test.AssertionUtils; -import junit.framework.TestCase; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +/** + * + * @author $author$ + * @version $Revision$ + */ public class ConnectRequiredProvidedEdgeFilterTest extends TestCase { + private Application app1 = new Application("app1", "pf1."); + + private Application app2 = new Application("app2", "pf2."); + + private Environment env1 = new Environment("env1", "pf3."); - private Application _app1 = new Application("app1", "pf1."); - private Application _app2 = new Application("app2", "pf2."); - - private Environment _env1 = new Environment("env1", "pf3."); - private Environment _env2 = new Environment("env2", "pf4."); - - - private void compare(Boolean[] aExpected, EdgeFilter aRestriction) { - List result = new ArrayList(); - - - - // order will be: - // env1, app1 - // env1, app2 - // env2, app1 - // env2, app2 - for (Environment env: new Environment[] { _env1, _env2} ) { - for (Application app: new Application[] { _app1, _app2} ) { - Node from = new RequiredInterfaceNode( - app, app.getRequiredInterfaces().get(0)); - Node to = new ProvidedInterfaceNode( - env, env.getProvidedInterfaces().get(0)); - Edge edge = new DefaultEdge(from, to); - result.add(aRestriction.isViolated(edge)); - } - } - - - assertEquals(Arrays.asList(aExpected), result); + private Environment env2 = new Environment("env2", "pf4."); + + private void compare(Boolean[] aExpected, EdgeFilter aRestriction) { + List result = new ArrayList(); + + // order will be: + // env1, app1 + // env1, app2 + // env2, app1 + // env2, app2 + for (Environment env : new Environment[] { env1, env2 }) { + for (Application app : new Application[] { app1, app2 }) { + Node from = new RequiredInterfaceNode(app, app + .getRequiredInterfaces().get(0)); + Node to = new ProvidedInterfaceNode(env, env + .getProvidedInterfaces().get(0)); + Edge edge = new DefaultEdge(from, to); + result.add(aRestriction.isViolated(edge)); + } + } + + assertEquals(Arrays.asList(aExpected), result); } - public void testNoRestriction() { + public void testNoRestriction() { AssertionUtils.assertException(new AssertionUtils.ErroneousCode() { @Override public void run() throws Exception { - EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(null, null, null, null); - + EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter( + null, null, null, null); } }, IllegalArgumentException.class); AssertionUtils.assertException(new AssertionUtils.ErroneousCode() { @Override public void run() throws Exception { - EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter(null, null, "x", "y"); + EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter( + null, null, "x", "y"); } }, IllegalArgumentException.class); } - - public void testClientServer() { - EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app1", null, "env1", null); - compare(new Boolean[] { false, false, true, false}, restriction); + + public void testClientServer() { + EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app1", + null, "env1", null); + compare(new Boolean[] { false, false, true, false }, restriction); } - - public void testNoConnectionsAtAll() { - EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app1", null, null, null); - compare(new Boolean[] { true, false, true, false}, restriction); + + public void testNoConnectionsAtAll() { + EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app1", + null, null, null); + compare(new Boolean[] { true, false, true, false }, restriction); } - - public void testExplicitConfig() { - _app1 = new Application("app1"); - _app2 = new Application("app2"); - _env1 = new Environment("env1"); - _env2 = new Environment("env2"); - - EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter( - "app2", "string", "env1", "datasource"); - compare(new Boolean[] { false, false, false, true}, restriction); - + + public void testExplicitConfig() { + app1 = new Application("app1"); + app2 = new Application("app2"); + env1 = new Environment("env1"); + env2 = new Environment("env2"); + + EdgeFilter restriction = new ConnectRequiredProvidedEdgeFilter("app2", + "string", "env1", "datasource"); + compare(new Boolean[] { false, false, false, true }, restriction); } }