alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Struts example source code file (ContainerImplTest.java)

This example Struts source code file (ContainerImplTest.java) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Struts tags/keywords

containerbuilder, dependencyexception, exception, exception, fieldcheck, fieldcheck, inject, lukasz, lukasz, methodcheck, methodcheck, no, string, testcase

The Struts ContainerImplTest.java source code

package com.opensymphony.xwork2.inject;

import junit.framework.TestCase;

/**
 * ContainerImpl Tester.
 *
 * @author Lukasz Lenart
 * @version 1.0
 * @since <pre>11/26/2008
*/ public class ContainerImplTest extends TestCase { private Container c; @Override protected void setUp() throws Exception { super.setUp(); ContainerBuilder cb = new ContainerBuilder(); cb.constant("methodCheck.name", "Lukasz"); cb.constant("fieldCheck.name", "Lukasz"); c = cb.create(false); } /** * Inject values into field */ public void testFieldInjector() throws Exception { FieldCheck fieldCheck = new FieldCheck(); try { c.inject(fieldCheck); assertTrue(true); } catch (DependencyException expected) { fail("No exception expected!"); } assertEquals(fieldCheck.getName(), "Lukasz"); } /** * Inject values into method */ public void testMethodInjector() throws Exception { MethodCheck methodCheck = new MethodCheck(); try { c.inject(methodCheck); assertTrue(true); } catch (DependencyException expected) { fail("No exception expected!"); } } /** * Inject values into field under SecurityManager */ public void testFieldInjectorWithSecurityEnabled() throws Exception { System.setSecurityManager(new SecurityManager()); FieldCheck fieldCheck = new FieldCheck(); try { c.inject(fieldCheck); assertEquals(fieldCheck.getName(), "Lukasz"); fail("Exception should be thrown!"); } catch (DependencyException expected) { // that was expected } } /** * Inject values into method under SecurityManager */ public void testMethodInjectorWithSecurityEnabled() throws Exception { // not needed, already set //System.setSecurityManager(new SecurityManager()); MethodCheck methodCheck = new MethodCheck(); try { c.inject(methodCheck); assertEquals(methodCheck.getName(), "Lukasz"); fail("Exception sould be thrown!"); } catch (DependencyException expected) { // that was expected } } class FieldCheck { @Inject("fieldCheck.name") private String name; public String getName() { return name; } } class MethodCheck { private String name; @Inject("methodCheck.name") private void setName(String name) { this.name = name; } public String getName() { return name; } } }

Other Struts examples (source code examples)

Here is a short list of links related to this Struts ContainerImplTest.java source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.