Package com.opensymphony.xwork2.mock

Examples of com.opensymphony.xwork2.mock.MockObjectTypeDeterminer


        }

        try {
            return DateUtil.convertStringToDate(value[0]);
        } catch (ParseException pe) {
            throw new TypeConversionException(pe.getMessage(), pe);
        }
    }
View Full Code Here


        // Initialize ActionContext
        ConfigurationManager configurationManager = new ConfigurationManager();
        configurationManager.addContainerProvider(new XWorkConfigurationProvider());
        Configuration config = configurationManager.getConfiguration();
        Container container = config.getContainer();

        ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
        stack.getContext().put(ActionContext.CONTAINER, container);
        ActionContext.setContext(new ActionContext(stack.getContext()));

        ActionContext.getContext().setSession(new HashMap<String, Object>());
View Full Code Here

        StringBuilder link = new StringBuilder();

        boolean changedScheme = false;

        // FIXME: temporary hack until class is made a properly injected bean
        Container cont = ActionContext.getContext().getContainer();
        int httpPort = Integer.parseInt(cont.getInstance(String.class, StrutsConstants.STRUTS_URL_HTTP_PORT));
        int httpsPort = Integer.parseInt(cont.getInstance(String.class, StrutsConstants.STRUTS_URL_HTTPS_PORT));

        // only append scheme if it is different to the current scheme *OR*
        // if we explicity want it to be appended by having forceAddSchemeHostAndPort = true
        if (forceAddSchemeHostAndPort) {
            String reqScheme = request.getScheme();
View Full Code Here

            @Override
            public void register(ContainerBuilder builder,
                    LocatableProperties props) throws ConfigurationException {
                builder.factory(ObjectTypeDeterminer.class, new Factory() {
                    public Object create(Context context) throws Exception {
                        return new MockObjectTypeDeterminer(null,Cat.class,null,allowAdditions);
                    }
                   
                });
            }
        });
View Full Code Here

    }

    public void doTestAddingToMapsWithObjects(boolean allowAdditions) throws Exception {

        loadButAdd(ObjectTypeDeterminer.class, new MockObjectTypeDeterminer(Long.class,Cat.class,null,allowAdditions));

        Foo foo = new Foo();
        foo.setAnotherCatMap(new HashMap());
        String spielname = "Spielen";
        ValueStack vs = ActionContext.getContext().getValueStack();
View Full Code Here

            }
        }

    }
    public void testAddingToCollectionBasedOnPermission() {
        final MockObjectTypeDeterminer determiner = new MockObjectTypeDeterminer(Long.class,Bar.class,"id",true);
        loadConfigurationProviders(new StubConfigurationProvider() {
            @Override
            public void register(ContainerBuilder builder,
                    LocatableProperties props) throws ConfigurationException {
                builder.factory(ObjectTypeDeterminer.class, new Factory() {
                    public Object create(Context context) throws Exception {
                        return determiner;
                    }
                   
                }, Scope.SINGLETON);
            }
        });

        Collection barColl=new HashSet();

        ValueStack vs = ActionContext.getContext().getValueStack();
        ReflectionContextState.setCreatingNullObjects(vs.getContext(), true);
        ReflectionContextState.setReportingConversionErrors(vs.getContext(), true);
        Foo foo = new Foo();

        foo.setBarCollection(barColl);

        vs.push(foo);

        String bar1Title="title";
        vs.setValue("barCollection(11).title", bar1Title);

        assertEquals(1, barColl.size());
        Object bar=barColl.iterator().next();
        assertTrue(bar instanceof Bar);
        assertEquals(((Bar)bar).getTitle(), bar1Title);
        assertEquals(((Bar)bar).getId(), new Long(11));

        //now test where there is no permission
        determiner.setShouldCreateIfNew(false);

        String bar2Title="another title";
        vs.setValue("barCollection(22).title", bar1Title);

        assertEquals(1, barColl.size());
View Full Code Here

    public <T> T getInstance(Class<T> type) {
      try {
        T obj = type.newInstance();
        if (obj instanceof ObjectFactory) {
          ((ObjectFactory) obj).setReflectionProvider(new OgnlReflectionProvider() {

            @Override
            public void setProperties(Map<String, String> properties, Object o) {
            }
View Full Code Here

    if (messageKey == null || StringUtils.isBlank(messageKey) && StringUtils.isNotBlank(defaultValue)) {
      message = StringUtils.capitalize(defaultValue);
    }
    // the titleKey attribute is used
    else {
      OgnlValueStack stack = (OgnlValueStack) TagUtils.getStack(pageContext);
     
      for (Object o : stack.getRoot()) {
        if (o instanceof TextProvider) {
          TextProvider tp = (TextProvider) o;
          message = tp.getText(messageKey, UNDEFINED_KEY + messageKey + UNDEFINED_KEY);
          break;
        }
View Full Code Here

   */
  @Override
  public Locale resolveLocale(HttpServletRequest request) {

    Locale result = null;
    OgnlValueStack stack = (OgnlValueStack) ActionContext.getContext().getValueStack();

    for (Object o : stack.getRoot()) {
      if (o instanceof LocaleProvider) {
        LocaleProvider lp = (LocaleProvider) o;
        result = lp.getLocale();
        break;
      }
View Full Code Here

    this.configuration = configuration;
    this.objectFactory = objectFactory;
    this.defaultParentPackage = "beangle";
    if (objectFactory instanceof SpringObjectFactory) {
      beanNameFinder = new SpringBeanNameFinder();
      SpringObjectFactory sf = (SpringObjectFactory) objectFactory;
      sf.autoWireBean(beanNameFinder);
    }
  }
View Full Code Here

TOP

Related Classes of com.opensymphony.xwork2.mock.MockObjectTypeDeterminer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.