/**
* ***************************************************************************
* Copyright (c) 2010 Qcadoo Limited
* Project: Qcadoo Framework
* Version: 1.4
*
* This file is part of Qcadoo.
*
* Qcadoo is free software; you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published
* by the Free Software Foundation; either version 3 of the License,
* or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty
* of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
* ***************************************************************************
*/
package com.qcadoo.model.internal;
import static junit.framework.Assert.*;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertSame;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
import java.util.Map;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.qcadoo.model.api.DataDefinition;
import com.qcadoo.model.api.Entity;
import com.qcadoo.model.api.EntityList;
import com.qcadoo.model.api.FieldDefinition;
import com.qcadoo.model.api.types.BelongsToType;
import com.qcadoo.model.api.types.FieldType;
import com.qcadoo.model.api.types.HasManyType;
import com.qcadoo.model.api.types.ManyToManyType;
import com.qcadoo.model.internal.types.DecimalType;
import com.qcadoo.model.internal.types.IntegerType;
public class DefaultEntityTest {
private DefaultEntity defaultEntity;
private DataDefinition dataDefinition;
private FieldDefinition belongsToFieldDefinition;
private DataDefinition belongsToFieldDataDefinition;
private FieldDefinition decimalFieldDefinition;
private FieldDefinition integerFieldDefinition;
private FieldDefinition manyToManyFieldDefinition;
private DataDefinition manyToManyDataDefinition;
private FieldDefinition booleanFieldDefinition;
private FieldDefinition stringFieldDefinition;
private FieldDefinition hasManyFieldDefinition;
private DataDefinition hasManyDataDefinition;
private FieldDefinition secondManyToManyFieldDefinition;
private DataDefinition secondManyToManyDataDefinition;
private static final String BELONGS_TO_FIELD_NAME = "belongsToField";
private static final String STRING_FIELD_NAME = "stringField";
private static final String BOOLEAN_FIELD_NAME = "booleanField";
private static final String DECIMAL_FIELD_NAME = "decimalField";
private static final String INTEGER_FIELD_NAME = "integerField";
private static final String MANY_TO_MANY_FIELD_NAME = "manyToMany";
private static final String SECOND_MANY_TO_MANY_FIELD_NAME = "secondManyToMany";
private static final String HAS_MANY_FIELD_NAME = "hasMany";
private static final String L_FIRST = "first";
private static final String L_SECOND = "second";
private static final String L_THIRD = "third";
private static final String L_FOURTH = "fourth";
private static final String L_DIFFERENCE = "difference";
private static final String DATE_FIELD_NAME = "dateField";
@Before
public final void init() {
belongsToFieldDefinition = mock(FieldDefinition.class);
final BelongsToType belongsToType = mock(BelongsToType.class);
when(belongsToFieldDefinition.getType()).thenReturn(belongsToType);
belongsToFieldDataDefinition = mock(DataDefinition.class);
when(belongsToFieldDefinition.getDataDefinition()).thenReturn(belongsToFieldDataDefinition);
decimalFieldDefinition = mock(FieldDefinition.class);
final DecimalType decimalType = new DecimalType();
when(decimalFieldDefinition.getType()).thenReturn(decimalType);
integerFieldDefinition = mock(FieldDefinition.class);
final IntegerType integerType = new IntegerType();
when(integerFieldDefinition.getType()).thenReturn(integerType);
manyToManyFieldDefinition = mock(FieldDefinition.class);
final ManyToManyType manyToManyType = mock(ManyToManyType.class);
when(manyToManyFieldDefinition.getType()).thenReturn(manyToManyType);
manyToManyDataDefinition = mock(DataDefinition.class);
when(manyToManyFieldDefinition.getDataDefinition()).thenReturn(manyToManyDataDefinition);
secondManyToManyFieldDefinition = mock(FieldDefinition.class);
when(secondManyToManyFieldDefinition.getType()).thenReturn(manyToManyType);
secondManyToManyDataDefinition = mock(DataDefinition.class);
when(secondManyToManyFieldDefinition.getDataDefinition()).thenReturn(secondManyToManyDataDefinition);
hasManyFieldDefinition = mock(FieldDefinition.class);
final HasManyType hasManyType = mock(HasManyType.class);
when(hasManyType.getJoinFieldName()).thenReturn(BELONGS_TO_FIELD_NAME);
when(hasManyFieldDefinition.getType()).thenReturn(hasManyType);
hasManyDataDefinition = mock(DataDefinition.class);
when(hasManyFieldDefinition.getDataDefinition()).thenReturn(hasManyDataDefinition);
stringFieldDefinition = mock(FieldDefinition.class);
when(stringFieldDefinition.isPersistent()).thenReturn(false);
dataDefinition = mock(DataDefinition.class);
booleanFieldDefinition = mock(FieldDefinition.class);
defaultEntity = new DefaultEntity(dataDefinition);
final Map<String, FieldDefinition> fieldsMap = Maps.newHashMap();
fieldsMap.put(BELONGS_TO_FIELD_NAME, belongsToFieldDefinition);
fieldsMap.put(STRING_FIELD_NAME, stringFieldDefinition);
fieldsMap.put(BOOLEAN_FIELD_NAME, booleanFieldDefinition);
fieldsMap.put(DECIMAL_FIELD_NAME, decimalFieldDefinition);
fieldsMap.put(INTEGER_FIELD_NAME, integerFieldDefinition);
fieldsMap.put(MANY_TO_MANY_FIELD_NAME, manyToManyFieldDefinition);
fieldsMap.put(SECOND_MANY_TO_MANY_FIELD_NAME, secondManyToManyFieldDefinition);
fieldsMap.put(HAS_MANY_FIELD_NAME, hasManyFieldDefinition);
for (Map.Entry<String, FieldDefinition> fieldEntry : fieldsMap.entrySet()) {
when(dataDefinition.getField(fieldEntry.getKey())).thenReturn(fieldEntry.getValue());
}
when(dataDefinition.getFields()).thenReturn(fieldsMap);
}
@Test
public final void shouldGetBelongsToFieldReturnEntity() throws Exception {
// given
Entity belongsToEntity = mock(Entity.class);
defaultEntity.setField(BELONGS_TO_FIELD_NAME, belongsToEntity);
// when
Entity returnedEntity = defaultEntity.getBelongsToField(BELONGS_TO_FIELD_NAME);
// then
assertEquals(belongsToEntity, returnedEntity);
}
@Test
public final void shouldGetBelongsToFieldReturnProxyEntity() throws Exception {
// given
Long belongsToEntityId = 1L;
defaultEntity.setField(BELONGS_TO_FIELD_NAME, belongsToEntityId);
// when
Entity returnedEntity = defaultEntity.getBelongsToField(BELONGS_TO_FIELD_NAME);
// then
assertEquals(belongsToEntityId, returnedEntity.getId());
}
@Test
public final void shouldGetBelongsToFieldReturnProxyEntityUsingIntegerValue() throws Exception {
// given
Integer belongsToEntityId = 1;
defaultEntity.setField(BELONGS_TO_FIELD_NAME, belongsToEntityId);
// when
Entity returnedEnti
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
industry4.0-mes 基于 QCADOO的。开源MES,生产制造管理系统,Manufacturing Execution System。机加工MES、食品包装MES、制鞋MES、服装MES、离散MES
资源推荐
资源详情
资源评论
收起资源包目录
基于 QCADOO的 开源MES,生产制造管理系统Manufacturing Execution System (2000个子文件)
bootstrap.min.css 137KB
bootstrap.css 125KB
qcadoo-min.css 121KB
animate.css 71KB
style.css 34KB
_jquery-ui-1.8.5.custom.css 25KB
_jquery-ui-1.8.5.custom.css 24KB
form.css 18KB
languages.min.css 17KB
grid.css 14KB
ui.jqgrid.css 14KB
custom.css 13KB
ui.jqgrid.css 11KB
gantt.css 7KB
window.css 7KB
dropzone.css 6KB
jquery.datepick.css 5KB
style.css 5KB
imageviewer.css 5KB
dashboard.css 5KB
elementHeader.css 5KB
jquery.bubblepopup.v2.3.1.css 5KB
notification.css 4KB
awesomeDynamicList.css 4KB
layout.css 3KB
tree.css 2KB
jqModal.css 2KB
contextualHelpButton.css 2KB
login-min.css 2KB
qcd.css 2KB
passwordReset-min.css 2KB
jquery.autocomplete.css 2KB
menuTopLevel.css 2KB
browserNotSupported-min.css 2KB
pluginInfo.css 2KB
mainPage.css 1KB
example.local.css 1KB
custom.css 1014B
empty.css 1014B
ui.jqgrid-bootstarp.css 662B
index.htm 41KB
overview.html 1KB
DefaultEntityTest.java 105KB
GridComponentFilterUtilsTest.java 48KB
PluginDependencyManagerTest.java 46KB
DataAccessServiceImpl.java 46KB
GridComponentState.java 43KB
OrderDetailsHooks.java 36KB
GridComponentPattern.java 34KB
OrderHooks.java 32KB
PluginManagerInstallTest.java 32KB
AbstractEntityWrapperTest.java 30KB
ValidatorTest.java 30KB
ModelXmlToDefinitionConverterImpl.java 29KB
PluginManagerTest.java 28KB
OrderAndChangeoverIntervalsProviderTest.java 28KB
CrudIntegrationTest.java 27KB
GridComponentPatternTest.java 26KB
AbstractComponentPattern.java 25KB
MenuServiceImplTest.java 24KB
DateUtilsTest.java 24KB
PdfHelperImpl.java 23KB
DataAccessServiceCopyTest.java 23KB
GridComponentFilterSQLUtils.java 22KB
GridComponentFilterUtils.java 22KB
FormComponentState.java 22KB
RibbonTemplates.java 22KB
ViewDefinitionParserImplTest.java 22KB
FormComponentStateTest.java 21KB
SearchRestrictions.java 21KB
ModelXmlToDefinitionConverterTest.java 21KB
ModelXmlToClassConverterImpl.java 21KB
AssignmentToShiftXlsService.java 20KB
ViewDefinitionParserImpl.java 20KB
CriteriaIntegrationTest.java 19KB
TechnologyServiceO.java 19KB
PluginAccessorTest.java 19KB
OrderStateChangeReasonServiceTest.java 19KB
ScheduleDetailsListeners.java 18KB
NegotForOrderSuppliesServiceImpNFOSWTSOverrideUtil.java 18KB
DefaultEntity.java 17KB
RunIfEnabledTest.java 17KB
OrderServiceImplTest.java 17KB
InitializationTest.java 17KB
OrderDetailsListeners.java 17KB
DefaultPluginManager.java 17KB
LookupComponentPattern.java 16KB
ModelXmlToHbmConverterTest.java 16KB
EntityServiceImplTest.java 16KB
EntityServiceImpl.java 16KB
ManyToManyIntegrationTest.java 16KB
AssignmentToShiftDetailsHooks.java 16KB
GridComponentStateTest.java 16KB
DefaultPluginDescriptorParser.java 16KB
DynamicSessionFactory.java 16KB
DataDefinitionImpl.java 16KB
OrderDetailsHooksTest.java 15KB
UserRoleValidationServiceTest.java 15KB
HqlIntegrationTest.java 15KB
TomcatMojo.java 15KB
共 2000 条
- 1
- 2
- 3
- 4
- 5
- 6
- 20
资源评论
Java程序员-张凯
- 粉丝: 1w+
- 资源: 7527
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 造价咨询薪酬管理办法.doc
- 中铁三局集团第二工程有限公司项目薪酬实施办法.doc
- 2025健康管理师三级专业能力考试题及答案.docx
- 2025健康素养知识竞赛题库(含答案).docx
- 2025交管12123驾驶证学法减分(学法免分)测试题及答案.docx
- 造价咨询公司绩效提成方案 (1).docx
- 造价咨询公司绩效提成方案.docx
- 工程造价咨询从业人员绩效考核制度.docx
- 造价咨询公司(咨询工作室)绩效提成方案-2018修订版 (1).docx
- 2025交管12123学法减分考试试题库及答案(通用版).docx
- 2025交管12123学法减分题库大全(附答案).docx
- 2025教师资格证结构化面试题库及答案.docx
- 2025教师招聘义务教育道德与法治课程方案(2022版)必考题库及答案.docx
- 2025教师资格证考试《教育知识与能力》知识点大全.docx
- 2025教育学公共基础知识考试题库及答案(通用版).docx
- 2025京东pop售前客服认证考试题及答案.docx
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功