-
Notifications
You must be signed in to change notification settings - Fork 807
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WW-5233 Copies Tiles Autotag related tests
- Loading branch information
1 parent
df5cf36
commit 5678282
Showing
6 changed files
with
720 additions
and
0 deletions.
There are no files selected for viewing
153 changes: 153 additions & 0 deletions
153
plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateClassTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.tiles.autotag.model; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import static org.easymock.EasyMock.createMock; | ||
import static org.easymock.EasyMock.expect; | ||
import static org.easymock.EasyMock.replay; | ||
import static org.easymock.EasyMock.verify; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertNull; | ||
import static org.junit.Assert.assertSame; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
public class TemplateClassTest { | ||
|
||
/** | ||
* Test method for {@link TemplateClass#TemplateClass(String)}. | ||
*/ | ||
@Test | ||
public void testTemplateConstructor1() { | ||
TemplateClass templateClass = new TemplateClass("name"); | ||
assertEquals("name", templateClass.getName()); | ||
assertNull(templateClass.getTagName()); | ||
assertNull(templateClass.getTagClassPrefix()); | ||
assertNull(templateClass.getExecuteMethod()); | ||
Collection<TemplateParameter> params = templateClass.getParameters(); | ||
assertTrue(params.isEmpty()); | ||
} | ||
|
||
/** | ||
* Test method for {@link TemplateClass#TemplateClass(String, String, String, TemplateMethod)}. | ||
*/ | ||
@Test | ||
public void testTemplateConstructor2() { | ||
TemplateMethod method = createMock(TemplateMethod.class); | ||
|
||
replay(method); | ||
TemplateClass templateClass = new TemplateClass("name", "tagName", "tagClassPrefix", method); | ||
assertEquals("name", templateClass.getName()); | ||
assertEquals("tagName", templateClass.getTagName()); | ||
assertEquals("tagClassPrefix", templateClass.getTagClassPrefix()); | ||
assertEquals(method, templateClass.getExecuteMethod()); | ||
verify(method); | ||
} | ||
|
||
/** | ||
* Test method for {@link TemplateClass#getSimpleName()}. | ||
*/ | ||
@Test | ||
public void testGetSimpleName() { | ||
TemplateClass templateClass = new TemplateClass("name"); | ||
assertEquals("name", templateClass.getSimpleName()); | ||
templateClass = new TemplateClass("org.whatever.Hello"); | ||
assertEquals("Hello", templateClass.getSimpleName()); | ||
} | ||
|
||
/** | ||
* Test method for {@link TemplateClass#setDocumentation(String)}. | ||
*/ | ||
@Test | ||
public void testSetDocumentation() { | ||
TemplateClass templateClass = new TemplateClass("name"); | ||
templateClass.setDocumentation("docs"); | ||
assertEquals("docs", templateClass.getDocumentation()); | ||
} | ||
|
||
/** | ||
* Test method for {@link TemplateClass#getParameters()}. | ||
*/ | ||
@Test | ||
public void testGetParameters() { | ||
TemplateParameter param1 = createMock(TemplateParameter.class); | ||
TemplateParameter param2 = createMock(TemplateParameter.class); | ||
TemplateParameter param3 = createMock(TemplateParameter.class); | ||
TemplateParameter param4 = createMock(TemplateParameter.class); | ||
TemplateMethod method = createMock(TemplateMethod.class); | ||
List<TemplateParameter> params = new ArrayList<>(); | ||
|
||
expect(method.getParameters()).andReturn(params); | ||
expect(param1.isRequest()).andReturn(true); | ||
expect(param2.isRequest()).andReturn(false); | ||
expect(param2.isBody()).andReturn(true); | ||
expect(param3.isRequest()).andReturn(false); | ||
expect(param3.isBody()).andReturn(false); | ||
expect(param4.isRequest()).andReturn(false); | ||
expect(param4.isBody()).andReturn(false); | ||
expect(param3.getName()).andReturn("param1"); | ||
expect(param4.getName()).andReturn("param2"); | ||
|
||
replay(param1, param2, param3, param4, method); | ||
params.add(param1); | ||
params.add(param2); | ||
params.add(param3); | ||
params.add(param4); | ||
|
||
TemplateClass templateClass = new TemplateClass("name", "tagName", "tagClassPrefix", method); | ||
Collection<TemplateParameter> returnedParams = templateClass.getParameters(); | ||
Iterator<TemplateParameter> paramIt = returnedParams.iterator(); | ||
assertSame(param3, paramIt.next()); | ||
assertSame(param4, paramIt.next()); | ||
assertFalse(paramIt.hasNext()); | ||
verify(param1, param2, param3, param4, method); | ||
} | ||
|
||
/** | ||
* Test method for {@link TemplateClass#hasBody()}. | ||
*/ | ||
@Test | ||
public void testHasBody() { | ||
TemplateMethod method = createMock(TemplateMethod.class); | ||
expect(method.hasBody()).andReturn(true); | ||
|
||
replay(method); | ||
TemplateClass templateClass = new TemplateClass("name", "tagName", "tagClassPrefix", method); | ||
assertTrue(templateClass.hasBody()); | ||
verify(method); | ||
} | ||
|
||
/** | ||
* Test method for {@link TemplateClass#toString()}. | ||
*/ | ||
@Test | ||
public void testToString() { | ||
TemplateMethod method = new TemplateMethod("method", new ArrayList<>()); | ||
TemplateClass templateClass = new TemplateClass("name", "tagName", "tagClassPrefix", method); | ||
assertEquals("TemplateClass [name=name, tagName=tagName, tagClassPrefix=tagClassPrefix, " + "documentation=null, executeMethod=TemplateMethod " + "[name=method, documentation=null, parameters={}]]", templateClass.toString()); | ||
} | ||
|
||
} |
132 changes: 132 additions & 0 deletions
132
plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateMethodTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.tiles.autotag.model; | ||
|
||
import org.junit.Test; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Iterator; | ||
import java.util.List; | ||
|
||
import static org.easymock.EasyMock.createMock; | ||
import static org.easymock.EasyMock.expect; | ||
import static org.easymock.EasyMock.replay; | ||
import static org.easymock.EasyMock.verify; | ||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertSame; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Tests {@link TemplateMethod}. | ||
*/ | ||
public class TemplateMethodTest { | ||
|
||
/** | ||
* Tests {@link TemplateMethod#TemplateMethod(String, Iterable)}. | ||
*/ | ||
@Test | ||
public void testTemplateMethod() { | ||
TemplateParameter param1 = createMock(TemplateParameter.class); | ||
TemplateParameter param2 = createMock(TemplateParameter.class); | ||
|
||
expect(param1.getName()).andReturn("param1"); | ||
expect(param2.getName()).andReturn("param2"); | ||
|
||
replay(param1, param2); | ||
List<TemplateParameter> parameters = new ArrayList<>(); | ||
parameters.add(param1); | ||
parameters.add(param2); | ||
|
||
TemplateMethod method = new TemplateMethod("method", parameters); | ||
assertEquals("method", method.getName()); | ||
Iterator<TemplateParameter> params = method.getParameters().iterator(); | ||
assertSame(param1, params.next()); | ||
assertSame(param2, params.next()); | ||
assertFalse(params.hasNext()); | ||
assertSame(param1, method.getParameterByName("param1")); | ||
assertSame(param2, method.getParameterByName("param2")); | ||
verify(param1, param2); | ||
} | ||
|
||
/** | ||
* Tests {@link TemplateMethod#setDocumentation(String)}. | ||
*/ | ||
@Test | ||
public void testSetDocumentation() { | ||
TemplateMethod method = new TemplateMethod("method", new ArrayList<>()); | ||
method.setDocumentation("docs"); | ||
assertEquals("docs", method.getDocumentation()); | ||
} | ||
|
||
/** | ||
* Tests {@link TemplateMethod#hasBody()}. | ||
*/ | ||
@Test | ||
public void testHasBody() { | ||
TemplateParameter param1 = createMock(TemplateParameter.class); | ||
TemplateParameter param2 = createMock(TemplateParameter.class); | ||
|
||
expect(param1.getName()).andReturn("param1"); | ||
expect(param2.getName()).andReturn("param2"); | ||
expect(param1.isBody()).andReturn(true); | ||
|
||
replay(param1, param2); | ||
List<TemplateParameter> parameters = new ArrayList<>(); | ||
parameters.add(param1); | ||
parameters.add(param2); | ||
|
||
TemplateMethod method = new TemplateMethod("method", parameters); | ||
assertTrue(method.hasBody()); | ||
verify(param1, param2); | ||
} | ||
|
||
/** | ||
* Tests {@link TemplateMethod#hasBody()}. | ||
*/ | ||
@Test | ||
public void testHasBody2() { | ||
TemplateParameter param1 = createMock(TemplateParameter.class); | ||
TemplateParameter param2 = createMock(TemplateParameter.class); | ||
|
||
expect(param1.getName()).andReturn("param1"); | ||
expect(param2.getName()).andReturn("param2"); | ||
expect(param1.isBody()).andReturn(false); | ||
expect(param2.isBody()).andReturn(false); | ||
|
||
replay(param1, param2); | ||
List<TemplateParameter> parameters = new ArrayList<>(); | ||
parameters.add(param1); | ||
parameters.add(param2); | ||
|
||
TemplateMethod method = new TemplateMethod("method", parameters); | ||
assertFalse(method.hasBody()); | ||
verify(param1, param2); | ||
} | ||
|
||
/** | ||
* Tests {@link TemplateMethod#toString()}. | ||
*/ | ||
@Test | ||
public void testToString() { | ||
TemplateMethod method = new TemplateMethod("method", new ArrayList<>()); | ||
assertEquals("TemplateMethod [name=method, documentation=null, parameters={}]", method.toString()); | ||
} | ||
|
||
} |
88 changes: 88 additions & 0 deletions
88
plugins/tiles/src/test/java/org/apache/tiles/autotag/model/TemplateParameterTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.tiles.autotag.model; | ||
|
||
import org.apache.tiles.autotag.core.runtime.ModelBody; | ||
import org.junit.Test; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
/** | ||
* Tests {@link TemplateParameter}. | ||
*/ | ||
public class TemplateParameterTest { | ||
|
||
@Test | ||
public void testTemplateParameter() { | ||
TemplateParameter parameter = new TemplateParameter("name", "exportedName", "type", "defaultValue", true, false); | ||
assertEquals("name", parameter.getName()); | ||
assertEquals("exportedName", parameter.getExportedName()); | ||
assertEquals("type", parameter.getType()); | ||
assertEquals("defaultValue", parameter.getDefaultValue()); | ||
assertTrue(parameter.isRequired()); | ||
assertEquals("ExportedName", parameter.getGetterSetterSuffix()); | ||
assertFalse(parameter.isBody()); | ||
assertFalse(parameter.isRequest()); | ||
|
||
parameter = new TemplateParameter("name", "exportedName", "my.Request", "defaultValue", false, true); | ||
assertEquals("name", parameter.getName()); | ||
assertEquals("exportedName", parameter.getExportedName()); | ||
assertEquals("my.Request", parameter.getType()); | ||
assertEquals("defaultValue", parameter.getDefaultValue()); | ||
assertFalse(parameter.isRequired()); | ||
assertEquals("ExportedName", parameter.getGetterSetterSuffix()); | ||
assertFalse(parameter.isBody()); | ||
assertTrue(parameter.isRequest()); | ||
|
||
parameter = new TemplateParameter("name", "exportedName", ModelBody.class.getName(), "defaultValue", false, false); | ||
assertEquals("name", parameter.getName()); | ||
assertEquals("exportedName", parameter.getExportedName()); | ||
assertEquals(ModelBody.class.getName(), parameter.getType()); | ||
assertEquals("defaultValue", parameter.getDefaultValue()); | ||
assertFalse(parameter.isRequired()); | ||
assertEquals("ExportedName", parameter.getGetterSetterSuffix()); | ||
assertTrue(parameter.isBody()); | ||
assertFalse(parameter.isRequest()); | ||
} | ||
|
||
/** | ||
* Tests {@link TemplateParameter#setDocumentation(String)}. | ||
*/ | ||
@Test | ||
public void testSetDocumentation() { | ||
TemplateParameter parameter = new TemplateParameter("name", "exportedName", "type", "defaultValue", true, false); | ||
parameter.setDocumentation("docs"); | ||
assertEquals("docs", parameter.getDocumentation()); | ||
} | ||
|
||
/** | ||
* Tests {@link TemplateParameter#toString()}. | ||
*/ | ||
@Test | ||
public void testToString() { | ||
TemplateParameter parameter = new TemplateParameter("name", "exportedName", "type", "defaultValue", true, false); | ||
assertEquals( | ||
"TemplateParameter [name=name, exportedName=exportedName, " | ||
+ "documentation=null, type=type, defaultValue=defaultValue, required=true, request=false]", | ||
parameter.toString()); | ||
} | ||
|
||
} |
Oops, something went wrong.