1 package org.codehaus.plexus.spring;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import junit.framework.TestCase;
24 import org.springframework.context.ConfigurableApplicationContext;
26 public class PlexusClassPathXmlApplicationContextTest
32 * @see junit.framework.TestCase#setUp()
34 protected void setUp()
37 System.setProperty( "plexus-spring.debug", "true" );
40 public void testInjectSpringBeansInPlexusComponent()
43 ConfigurableApplicationContext applicationContext =
44 new PlexusClassPathXmlApplicationContext( new String[] {
45 "testInjectSpringBeansInPlexusComponent.xml",
46 "testInjectSpringBeansInPlexusComponent-context.xml" } );
47 PlexusBean plexusBean = (PlexusBean) applicationContext.getBean( "plexusBean" );
48 assertEquals( "field injection failed", "expected SpringBean", plexusBean.describe() );
49 applicationContext.close();
52 public void testPlexusLifecycleSupport()
55 ConfigurableApplicationContext applicationContext =
56 new PlexusClassPathXmlApplicationContext( new String[] {
57 "testPlexusLifecycleSupport.xml" } );
58 PlexusBean plexusBean = (PlexusBean) applicationContext.getBean( "plexusBean" );
59 assertEquals( PlexusBean.INITIALIZED, plexusBean.getState() );
60 assertNotNull( plexusBean.getContext() );
61 assertNotNull( plexusBean.getLogger() );
62 applicationContext.close();
63 assertEquals( PlexusBean.DISPOSED, plexusBean.getState() );
67 public void testInjectMapForRole()
70 ConfigurableApplicationContext applicationContext =
71 new PlexusClassPathXmlApplicationContext( new String[] {
72 "testInjectMapForRole.xml",
73 "testInjectMapForRole-context.xml" } );
74 ComplexPlexusBean plexusBean = (ComplexPlexusBean) applicationContext.getBean( "complexPlexusBean" );
75 assertTrue( plexusBean.getBeans().containsKey( "spring" ) );
76 assertTrue( plexusBean.getBeans().containsKey( "plexus" ) );
77 assertEquals( "2 components for role org.codehaus.plexus.spring.PlexusBean", plexusBean.toString() );
80 public void testInjectListForRole()
83 ConfigurableApplicationContext applicationContext =
84 new PlexusClassPathXmlApplicationContext( new String[] {
85 "testInjectListForRole.xml",
86 "testInjectListForRole-context.xml" } );
87 ComplexPlexusBean plexusBean = (ComplexPlexusBean) applicationContext.getBean( "complexPlexusBean" );
88 assertEquals( 2, plexusBean.getBeansList().size() );
91 public void testInjectPlexusConfiguration()
94 ConfigurableApplicationContext applicationContext =
95 new PlexusClassPathXmlApplicationContext( new String[] {
96 "testInjectPlexusConfiguration.xml" } );
97 ConfigPlexusBean plexusBean = (ConfigPlexusBean) applicationContext.getBean( "plexusBean" );
98 assertEquals( "expected", plexusBean.getConfig().getChild( "xml" ).getAttribute( "test" ) );