2 * Copyright 2004-2006 Graeme Rocher
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.codehaus
.groovy
.grails
.plugins
;
18 import groovy
.lang
.GroovyClassLoader
;
19 import junit
.framework
.Assert
;
20 import org
.codehaus
.groovy
.grails
.commons
.DefaultGrailsApplication
;
21 import org
.codehaus
.groovy
.grails
.commons
.GrailsApplication
;
22 import org
.codehaus
.groovy
.grails
.plugins
.exceptions
.PluginException
;
23 import org
.springframework
.core
.io
.Resource
;
25 import javax
.servlet
.ServletContext
;
27 import java
.io
.Writer
;
28 import java
.math
.BigDecimal
;
29 import java
.util
.Collection
;
33 * @author Graeme Rocher
38 public class MockGrailsPluginManager
extends AbstractGrailsPluginManager
{
39 private ServletContext servletContext
;
40 private boolean checkForChangesExpected
= false;
42 public ServletContext
getServletContext() {
43 return servletContext
;
46 public MockGrailsPluginManager(GrailsApplication application
) {
51 public MockGrailsPluginManager() {
52 this(new DefaultGrailsApplication(new Class
[0], new GroovyClassLoader()));
55 public GrailsPlugin
getGrailsPlugin(String name
) {
56 return (GrailsPlugin
)this.plugins
.get(name
);
59 public GrailsPlugin
getGrailsPlugin(String name
, BigDecimal version
) {
60 return (GrailsPlugin
)this.plugins
.get(name
);
63 public boolean hasGrailsPlugin(String name
) {
64 return this.plugins
.containsKey(name
);
67 public void registerMockPlugin(GrailsPlugin plugin
) {
68 this.plugins
.put(plugin
.getName(), plugin
);
69 this.pluginList
.add(plugin
);
72 public void loadPlugins() throws PluginException
{
73 this.initialised
= true;
76 public void checkForChanges() {
77 Assert
.assertTrue(this.checkForChangesExpected
);
78 this.checkForChangesExpected
= false;
81 public void doWebDescriptor(Resource descriptor
, Writer target
) {
85 public void doWebDescriptor(File descriptor
, Writer target
) {
89 public boolean isInitialised() {
93 public void refreshPlugin(String name
) {
94 GrailsPlugin plugin
= (GrailsPlugin
)plugins
.get(name
);
100 public Collection
getPluginObservers(GrailsPlugin plugin
) {
101 throw new UnsupportedOperationException("The class [MockGrailsPluginManager] doesn't support the method getPluginObservers");
104 public void informObservers(String pluginName
, Map event
) {
108 public void setServletContext(ServletContext servletContext
) {
109 this.servletContext
= servletContext
;
112 public void expectCheckForChanges() {
113 Assert
.assertFalse(this.checkForChangesExpected
);
114 this.checkForChangesExpected
= true;
117 public void verify() {
118 Assert
.assertFalse(this.checkForChangesExpected
);