Ejemplo n.º 1
0
  /*
   * PicoContainer
   */
  @Test
  public void picocontainer() {
    final MutablePicoContainer pico = new DefaultPicoContainer();
    pico.registerComponentImplementation(SuperManager.class);
    pico.registerComponentInstance(new OutputManager1(new OutputHelper(new SystemOutOutput())));
    pico.registerComponentInstance(new OutputManager2(new OutputHelper(new LoggerOutput())));
    pico.registerComponentImplementation(ComputationManager.class);
    pico.registerComponentImplementation(ComputationHelper.class);

    final SuperManager mgr = (SuperManager) pico.getComponentInstance(SuperManager.class);
    mgr.manage1();
    mgr.manage2();
  }
  public void testGetActionWhenActionsContainerAlreadyExists() {
    MutablePicoContainer requestContainer = new DefaultPicoContainer();
    requestContainer.registerComponentInstance(TestService.class, service);
    MutablePicoContainer actionsContainer = new DefaultPicoContainer(requestContainer);

    requestMock
        .stubs()
        .method("getAttribute")
        .with(eq(KeyConstants.ACTIONS_CONTAINER))
        .will(returnValue(actionsContainer));

    StrutsTestAction action1 =
        (StrutsTestAction) actionFactory.getAction(request, mapping1, servlet);
    StrutsTestAction action2 =
        (StrutsTestAction) actionFactory.getAction(request, mapping2, servlet);
    TestAction action3 = (TestAction) actionFactory.getAction(request, mapping1, servlet);
    TestAction action4 = (TestAction) actionFactory.getAction(request, mapping2, servlet);

    assertNotNull(action1);
    assertNotNull(action2);
    assertNotSame(action1, action2);
    assertSame(action1, action3);
    assertSame(action2, action4);

    assertSame(action1, actionsContainer.getComponentInstance("/myPath1"));
    assertSame(action2, actionsContainer.getComponentInstance("/myPath2"));

    assertSame(service, action1.getService());
    assertSame(service, action2.getService());

    assertNotNull(action1.getServlet());
    assertNotNull(action2.getServlet());
    assertSame(servlet, action1.getServlet());
    assertSame(servlet, action2.getServlet());
  }
  public void testApplicationContainerExists() {
    MutablePicoContainer appContainer = new DefaultPicoContainer();
    appContainer.registerComponentInstance(TestService.class, service);

    requestMock
        .expects(once())
        .method("getAttribute")
        .with(eq(KeyConstants.ACTIONS_CONTAINER))
        .will(returnValue(null));
    requestMock
        .expects(once())
        .method("getAttribute")
        .with(eq(KeyConstants.REQUEST_CONTAINER))
        .will(returnValue(null));
    sessionMock
        .expects(once())
        .method("getAttribute")
        .with(eq(KeyConstants.SESSION_CONTAINER))
        .will(returnValue(null));
    servletContextMock
        .expects(once())
        .method("getAttribute")
        .with(eq(KeyConstants.APPLICATION_CONTAINER))
        .will(returnValue(appContainer));
    requestMock
        .expects(once())
        .method("setAttribute")
        .with(eq(KeyConstants.ACTIONS_CONTAINER), isA(MutablePicoContainer.class));

    TestAction action = (TestAction) actionFactory.getAction(request, mapping1, servlet);
    assertNotNull(action);
    assertSame(service, action.getService());
  }
  protected void setUp() throws Exception {
    super.setUp();

    decimal = createAtribute(GML.NAMESPACE, "decimal", XS.STRING, ".");
    ts = createAtribute(GML.NAMESPACE, "ts", XS.STRING, null);
    cs = createAtribute(GML.NAMESPACE, "cs", XS.STRING, null);
    coordinates = createElement(GML.NAMESPACE, "myCoordinates", GML.COORDTYPE, null);
    container = new DefaultPicoContainer();
    container.registerComponentInstance(CoordinateArraySequenceFactory.instance());
    container.registerComponentImplementation(GMLCoordinatesTypeBinding.class);
  }
 @Override
 protected void setUp() throws Exception {
   super.setUp();
   ISetup _setup = this.getSetup();
   this.<ISetup>addExplicitExtension(LanguageSetup.INSTANCE, this.myLanguage, _setup);
   IXtextLanguage _xtextLanguage = this.getXtextLanguage();
   _xtextLanguage.injectMembers(this);
   this.configureFromParserDefinition(this.parserDefinition, this.myFileExt);
   this.<ASTFactory>addExplicitExtension(
       LanguageASTFactory.INSTANCE, this.myLanguage, this.astFactory);
   MockApplicationEx _application = PlatformLiteFixture.getApplication();
   final MutablePicoContainer appContainer = _application.getPicoContainer();
   appContainer.unregisterComponent(EditorFactory.class);
   appContainer.unregisterComponent(FileDocumentManager.class);
   final MockEditorFactory editorFactory =
       new MockEditorFactory() {
         @Override
         public Document createDocument(final CharSequence text) {
           return new DocumentImpl(text, true, false);
         }
       };
   appContainer.registerComponentInstance(EditorFactory.class, editorFactory);
   final Function<CharSequence, Document> _function =
       new Function<CharSequence, Document>() {
         @Override
         public Document fun(final CharSequence charSequence) {
           return editorFactory.createDocument(charSequence);
         }
       };
   MockFileDocumentManagerImpl _mockFileDocumentManagerImpl =
       new MockFileDocumentManagerImpl(
           _function, FileDocumentManagerImpl.HARD_REF_TO_DOCUMENT_KEY);
   appContainer.registerComponentInstance(FileDocumentManager.class, _mockFileDocumentManagerImpl);
   NodeModelPrinter _nodeModelPrinter = this.xtextResourceAsserts.getNodeModelPrinter();
   _nodeModelPrinter.setIgnoreSyntaxErrors(false);
 }
Ejemplo n.º 6
0
 protected void configureContext(MutablePicoContainer container) {
   container.registerComponentInstance(Ows11Factory.eINSTANCE);
 }
Ejemplo n.º 7
0
  /**
   * Creates an encoder from a configuration and a specific schema instance.
   *
   * @param configuration The encoder configuration.
   * @param schema The schema instance.
   */
  public Encoder(Configuration configuration, XSDSchema schema) {
    this.schema = schema;

    index = new SchemaIndexImpl(new XSDSchema[] {schema});

    bindingLoader = new BindingLoader(configuration.setupBindings());
    bindingWalker = new BindingWalker(bindingLoader);

    // create the context
    context = new DefaultPicoContainer();

    // register the binding factory in the context
    BindingFactory bindingFactory = new BindingFactoryImpl(bindingLoader);
    context.registerComponentInstance(bindingFactory);

    // register the element encoder in the context
    encoder = new ElementEncoder(bindingWalker, context);
    context.registerComponentInstance(encoder);

    // register the schema index
    context.registerComponentInstance(index);

    // bindign walker support
    context.registerComponentInstance(new BindingWalkerFactoryImpl(bindingLoader, context));

    // pass the context off to the configuration
    context = configuration.setupContext(context);
    encoder.setContext(context);

    // schema location setup
    schemaLocations = new HashMap();

    // get a logger from the context
    logger = (Logger) context.getComponentInstanceOfType(Logger.class);

    if (logger == null) {
      // create a default
      logger = org.geotools.util.logging.Logging.getLogger("org.geotools.xml");
      context.registerComponentInstance(logger);
    }

    encoder.setLogger(logger);

    // namespaces
    namespaces = new NamespaceSupport();
    context.registerComponentInstance(namespaces);
    context.registerComponentInstance(new NamespaceSupportWrapper(namespaces));

    // add configuration to context;
    context.registerComponentInstance(configuration);

    // property extractors
    propertyExtractors = Schemas.getComponentInstancesOfType(context, PropertyExtractor.class);

    // add the property extractor for bindings as first
    propertyExtractors.add(0, new BindingPropertyExtractor(this, context));

    outputFormat = new OutputFormat();

    configuration.setupEncoder(this);
  }