|
Author: adrianc
Date: Tue Jul 3 14:44:13 2012 New Revision: 1356762 URL: http://svn.apache.org/viewvc?rev=1356762&view=rev Log: Added some Mini-language unit tests. These only test the <assert> and <check-errors> elements for now. More to come later. Added: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/test/ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/test/MiniLangTests.java (with props) Modified: ofbiz/trunk/framework/minilang/config/minilang.properties ofbiz/trunk/framework/minilang/testdef/MinilangTests.xml Modified: ofbiz/trunk/framework/minilang/config/minilang.properties URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/config/minilang.properties?rev=1356762&r1=1356761&r2=1356762&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/config/minilang.properties (original) +++ ofbiz/trunk/framework/minilang/config/minilang.properties Tue Jul 3 14:44:13 2012 @@ -26,3 +26,7 @@ validation.level=none # to correct common syntax errors. The corrections are saved in the original # source file. autocorrect=false + +# Enable trace statements in mini-language unit tests. If set to true, mini-language +# unit tests will log trace messages. Log messages will be INFO. +unit.tests.trace.enabled=false Added: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/test/MiniLangTests.java URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/test/MiniLangTests.java?rev=1356762&view=auto ============================================================================== --- ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/test/MiniLangTests.java (added) +++ ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/test/MiniLangTests.java Tue Jul 3 14:44:13 2012 @@ -0,0 +1,94 @@ +/******************************************************************************* + * 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.ofbiz.minilang.test; + +import java.util.List; +import java.util.Locale; +import java.util.Map; +import java.util.TimeZone; + +import org.ofbiz.base.util.Debug; +import org.ofbiz.base.util.UtilMisc; +import org.ofbiz.base.util.UtilProperties; +import org.ofbiz.base.util.UtilXml; +import org.ofbiz.minilang.SimpleMethod; +import org.ofbiz.minilang.method.MethodContext; +import org.ofbiz.service.testtools.OFBizTestCase; + +public class MiniLangTests extends OFBizTestCase { + + private static final String module = MiniLangTests.class.getName(); + + private final boolean traceEnabled; + + public MiniLangTests(String name) { + super(name); + traceEnabled = "true".equals(UtilProperties.getPropertyValue("minilang.properties", "unit.tests.trace.enabled")); + } + + private Map<String, Object> createContext() { + return UtilMisc.toMap("locale", Locale.US, "timeZone", TimeZone.getTimeZone("GMT")); + } + + private MethodContext createServiceMethodContext() { + MethodContext context = new MethodContext(dispatcher.getDispatchContext(), createContext(), null); + context.setUserLogin(dispatcher.getDelegator().makeValidValue("UserLogin", UtilMisc.toMap("userLoginId", "system")), "userLogin"); + if (traceEnabled) { + context.setTraceOn(Debug.INFO); + } + return context; + } + + private SimpleMethod createSimpleMethod(String xmlString) throws Exception { + return new SimpleMethod(UtilXml.readXmlDocument(xmlString).getDocumentElement(), module); + } + + public void testAssignmentOperators() throws Exception { + // <check-errors> and <add-error> tests + SimpleMethod methodToTest = createSimpleMethod("<simple-method name=\"testCheckErrors\"><check-errors/></simple-method>"); + MethodContext context = createServiceMethodContext(); + String result = methodToTest.exec(context); + assertEquals("<check-errors> success result", methodToTest.getDefaultSuccessCode(), result); + List<String> messages = context.getEnv(methodToTest.getServiceErrorMessageListName()); + assertNull("<check-errors> null error message list", messages); + methodToTest = createSimpleMethod("<simple-method name=\"testCheckErrors\"><add-error><fail-message message=\"This should fail\"/></add-error><check-errors/></simple-method>"); + context = createServiceMethodContext(); + result = methodToTest.exec(context); + assertEquals("<check-errors> error result", methodToTest.getDefaultErrorCode(), result); + messages = context.getEnv(methodToTest.getServiceErrorMessageListName()); + assertNotNull("<check-errors> error message list", messages); + assertTrue("<check-errors> error message text", messages.contains("This should fail")); + // <assert>, <not>, and <if-empty> tests + methodToTest = createSimpleMethod("<simple-method name=\"testAssert\"><assert><not><if-empty field=\"locale\"/></not></assert><check-errors/></simple-method>"); + context = createServiceMethodContext(); + result = methodToTest.exec(context); + assertEquals("<assert> success result", methodToTest.getDefaultSuccessCode(), result); + messages = context.getEnv(methodToTest.getServiceErrorMessageListName()); + assertNull("<assert> null error message list", messages); + methodToTest = createSimpleMethod("<simple-method name=\"testAssert\"><assert><if-empty field=\"locale\"/></assert><check-errors/></simple-method>"); + context = createServiceMethodContext(); + result = methodToTest.exec(context); + assertEquals("<assert> error result", methodToTest.getDefaultErrorCode(), result); + messages = context.getEnv(methodToTest.getServiceErrorMessageListName()); + assertNotNull("<assert> error message list", messages); + String errorMessage = messages.get(0); + assertTrue("<assert> error message text", errorMessage.startsWith("Assertion failed:")); + } + +} Propchange: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/test/MiniLangTests.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: ofbiz/trunk/framework/minilang/src/org/ofbiz/minilang/test/MiniLangTests.java ------------------------------------------------------------------------------ svn:keywords = Author Date Id Rev URL Modified: ofbiz/trunk/framework/minilang/testdef/MinilangTests.xml URL: http://svn.apache.org/viewvc/ofbiz/trunk/framework/minilang/testdef/MinilangTests.xml?rev=1356762&r1=1356761&r2=1356762&view=diff ============================================================================== --- ofbiz/trunk/framework/minilang/testdef/MinilangTests.xml (original) +++ ofbiz/trunk/framework/minilang/testdef/MinilangTests.xml Tue Jul 3 14:44:13 2012 @@ -26,4 +26,8 @@ <junit-test-suite class-name="org.ofbiz.minilang.method.ifops.test.IfRegexpTest"/> </test-case> + <test-case case-name="MiniLangUnitTests"> + <junit-test-suite class-name="org.ofbiz.minilang.test.MiniLangTests"/> + </test-case> + </test-suite> |
| Free forum by Nabble | Edit this page |
