GRAILS-1019: Allowing expressions to be used with the 'disabled' attribute for g...
[grails.git] / test / commons / org / codehaus / groovy / grails / commons / GrailsClassTests.java
blob5caa453a6f548327472e358c0c41574808ada2ae
1 /*
2 * Copyright 2004-2005 the original author or authors.
3 *
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.commons;
18 import groovy.lang.GroovyClassLoader;
19 import junit.framework.TestCase;
21 /**
24 * @author Steven Devijver
25 * @since Jul 2, 2005
27 public class GrailsClassTests extends TestCase {
29 public GrailsClassTests() {
30 super();
33 public GrailsClassTests(String arg0) {
34 super(arg0);
37 public void testAbstractGrailsClassNoPackage() throws Exception {
38 GroovyClassLoader cl = new GroovyClassLoader();
39 Class clazz = cl.parseClass("class TestService { }");
40 GrailsClass grailsClass = new AbstractGrailsClass(clazz, "Service") {};
41 assertEquals("TestService", clazz.getName());
42 assertEquals("Test", grailsClass.getName());
43 assertEquals("TestService", grailsClass.getFullName());
44 assertNotNull(grailsClass.newInstance());
47 public void testAbstractGrailsClassPackage() throws Exception {
48 GroovyClassLoader cl = new GroovyClassLoader();
49 Class clazz = cl.parseClass("package test.casey; class TestService { }");
50 GrailsClass grailsClass = new AbstractGrailsClass(clazz, "Service") {};
51 assertEquals("test.casey.TestService", clazz.getName());
52 assertEquals("Test", grailsClass.getName());
53 assertEquals("test.casey.TestService", grailsClass.getFullName());
54 assertNotNull(grailsClass.newInstance());
57 public void testGrailsClassNonPublicConstructor() throws Exception {
58 GroovyClassLoader cl = new GroovyClassLoader();
59 Class clazz = cl.parseClass("class ProtectedConstructor { protected ProtectedConstructor(){}}");
60 GrailsClass grailsClass = new AbstractGrailsClass(clazz, "ProtectedConstructor") {};
61 assertNotNull(grailsClass.newInstance());