GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / commons / org / codehaus / groovy / grails / plugins / MockGrailsPluginManager.java
blobc2e4b66a0bbfd347d13bec8dfdf4d8793e832f73
1 /*
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
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
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.
15 */
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;
26 import java.io.File;
27 import java.io.Writer;
28 import java.math.BigDecimal;
29 import java.util.Collection;
30 import java.util.Map;
32 /**
33 * @author Graeme Rocher
34 * @since 0.4
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) {
47 super(application);
48 loadPlugins();
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) {
82 // do nothing
85 public void doWebDescriptor(File descriptor, Writer target) {
86 // do nothing
89 public boolean isInitialised() {
90 return true;
93 public void refreshPlugin(String name) {
94 GrailsPlugin plugin = (GrailsPlugin)plugins.get(name);
95 if(plugin != null) {
96 plugin.refresh();
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) {
105 // do nothing
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);