/* * Copyright (c) 2002-2013, Mairie de Paris * All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright notice * and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright notice * and the following disclaimer in the documentation and/or other materials * provided with the distribution. * * 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. * * License 1.0 */ package fr.paris.lutece.plugins.${plugin_name}.business; import fr.paris.lutece.test.LuteceTestCase; <#list business_class.attributes as attribute> <#if attribute.type = "Date"> <#assign hasDate = true> <#if hasDate?? && hasDate> import java.sql.Date; public class ${business_class.businessClass}BusinessTest extends LuteceTestCase { <#list business_class.attributes as attribute> <#if attribute.type = "String"> private final static ${attribute.type} ${attribute.name?upper_case}1 = "${attribute.name}1"; private final static ${attribute.type} ${attribute.name?upper_case}2 = "${attribute.name}2"; <#elseif attribute.type = "boolean"> private final static ${attribute.type} ${attribute.name?upper_case}1 = true; private final static ${attribute.type} ${attribute.name?upper_case}2 = false; <#elseif attribute.type = "Date"> private final static ${attribute.type} ${attribute.name?upper_case}1 = new Date( 1000000l ); private final static ${attribute.type} ${attribute.name?upper_case}2 = new Date( 2000000l ); <#else> private final static ${attribute.type} ${attribute.name?upper_case}1 = 1; private final static ${attribute.type} ${attribute.name?upper_case}2 = 2; public void testBusiness( ) { // Initialize an object ${business_class.businessClass} ${business_class.instanceName} = new ${business_class.businessClass}(); <#list business_class.attributes as attribute> ${business_class.instanceName}.set${attribute.name}( ${attribute.name?upper_case}1 ); // Create test ${business_class.businessClass}Home.create( ${business_class.instanceName} ); ${business_class.businessClass} ${business_class.instanceName}Stored = ${business_class.businessClass}Home.findByPrimaryKey( ${business_class.instanceName}.get${business_class.primaryKeyName?cap_first}() ); <#list business_class.attributes as attribute> assertEquals( ${business_class.instanceName}Stored.get${attribute.name}() , ${business_class.instanceName}.get${attribute.name}() ); // Update test <#list business_class.attributes as attribute> ${business_class.instanceName}.set${attribute.name}( ${attribute.name?upper_case}2 ); ${business_class.businessClass}Home.update( ${business_class.instanceName} ); ${business_class.instanceName}Stored = ${business_class.businessClass}Home.findByPrimaryKey( ${business_class.instanceName}.get${business_class.primaryKeyName?cap_first}() ); <#list business_class.attributes as attribute> assertEquals( ${business_class.instanceName}Stored.get${attribute.name}() , ${business_class.instanceName}.get${attribute.name}() ); // List test ${business_class.businessClass}Home.get${business_class.businessClass}sList(); // Delete test ${business_class.businessClass}Home.remove( ${business_class.instanceName}.get${business_class.primaryKeyName?cap_first}() ); ${business_class.instanceName}Stored = ${business_class.businessClass}Home.findByPrimaryKey( ${business_class.instanceName}.get${business_class.primaryKeyName?cap_first}() ); assertNull( ${business_class.instanceName}Stored ); } }