You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hivemind.apache.org by hl...@apache.org on 2004/09/27 16:37:27 UTC

cvs commit: jakarta-hivemind/framework/src/test/org/apache/hivemind/parse TestSchemaInjector.java SchemaHolder.java

hlship      2004/09/27 07:37:27

  Added:       framework/src/test/org/apache/hivemind/parse
                        TestSchemaInjector.java SchemaHolder.java
  Log:
  HIVEMIND-58: Add visibility attribute to the <schema> element.
  
  Revision  Changes    Path
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/parse/TestSchemaInjector.java
  
  Index: TestSchemaInjector.java
  ===================================================================
  //  Copyright 2004 The Apache Software Foundation
  //
  // 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.apache.hivemind.parse;
  
  import org.apache.commons.logging.Log;
  import org.apache.hivemind.ErrorHandler;
  import org.apache.hivemind.Location;
  import org.apache.hivemind.impl.RegistryAssembly;
  import org.apache.hivemind.schema.Schema;
  import org.apache.hivemind.test.HiveMindTestCase;
  import org.easymock.MockControl;
  
  /**
   * Tests for {@link org.apache.hivemind.parse.SchemaInjector}.
   * 
   * @author Howard M. Lewis Ship
   * @since 1.1
   */
  public class TestSchemaInjector extends HiveMindTestCase
  {
      public void testFound()
      {
          MockControl schemaControl = newControl(Schema.class);
          Schema schema = (Schema) schemaControl.getMock();
  
          MockControl raControl = newControl(RegistryAssembly.class);
          RegistryAssembly ra = (RegistryAssembly) raControl.getMock();
  
          // Training.
  
          ra.getSchema("foo.bar.Baz");
          raControl.setReturnValue(schema);
  
          schema.visibleToModule("zip.zoop");
          schemaControl.setReturnValue(true);
  
          replayControls();
  
          SchemaHolder h = new SchemaHolder();
  
          SchemaInjector si = new SchemaInjector(null, null, "foo.bar.Baz", "zip.zoop", h, "schema",
                  ra, null);
  
          si.run();
  
          assertSame(schema, h.getSchema());
  
          verifyControls();
      }
  
      public void testNotVisible()
      {
          MockControl ehControl = newControl(ErrorHandler.class);
          ErrorHandler eh = (ErrorHandler) ehControl.getMock();
  
          Log log = (Log) newMock(Log.class);
  
          MockControl schemaControl = newControl(Schema.class);
          Schema schema = (Schema) schemaControl.getMock();
  
          MockControl raControl = newControl(RegistryAssembly.class);
          RegistryAssembly ra = (RegistryAssembly) raControl.getMock();
  
          Location l = fabricateLocation(13);
  
          // Training.
  
          ra.getSchema("foo.bar.Baz");
          raControl.setReturnValue(schema);
  
          schema.visibleToModule("zip.zoop");
          schemaControl.setReturnValue(false);
  
          eh.error(log, ParseMessages.schemaNotVisible("foo.bar.Baz", "zip.zoop"), l, null);
  
          replayControls();
  
          SchemaHolder h = new SchemaHolder();
  
          SchemaInjector si = new SchemaInjector(eh, log, "foo.bar.Baz", "zip.zoop", h, "schema", ra,
                  l);
  
          si.run();
  
          assertNull(h.getSchema());
  
          verifyControls();
      }
  
      public void testQueuedNotFound()
      {
          MockControl ehControl = newControl(ErrorHandler.class);
          ErrorHandler eh = (ErrorHandler) ehControl.getMock();
  
          Log log = (Log) newMock(Log.class);
  
          MockControl raControl = newControl(RegistryAssembly.class);
          RegistryAssembly ra = (RegistryAssembly) raControl.getMock();
  
          SchemaHolder h = new SchemaHolder();
  
          Location l = fabricateLocation(99);
          SchemaInjector si = new SchemaInjector(eh, log, "foo.bar.Baz", "zip.zoop", h, "schema", ra,
                  l);
  
          // Training.
  
          ra.getSchema("foo.bar.Baz");
          raControl.setReturnValue(null);
  
          ra.addPostProcessor(si);
  
          ra.getSchema("foo.bar.Baz");
          raControl.setReturnValue(null);
  
          eh.error(log, ParseMessages.unableToResolveSchema("foo.bar.Baz"), l, null);
  
          replayControls();
  
          si.run();
  
          // Simulate re-run as a post-processor
  
          si.run();
  
          assertNull(h.getSchema());
  
          verifyControls();
      }
  }
  
  
  1.1                  jakarta-hivemind/framework/src/test/org/apache/hivemind/parse/SchemaHolder.java
  
  Index: SchemaHolder.java
  ===================================================================
  //  Copyright 2004 The Apache Software Foundation
  //
  // 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.apache.hivemind.parse;
  
  import org.apache.hivemind.schema.Schema;
  
  /**
   * @author Howard M. Lewis Ship
   * @since 1.1
   */
  public class SchemaHolder
  {
      private Schema _schema;
  
      public Schema getSchema()
      {
          return _schema;
      }
  
      public void setSchema(Schema schema)
      {
          _schema = schema;
      }
  }
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-cvs-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-cvs-help@jakarta.apache.org