use of easytests.core.models.QuestionTypeModelInterface in project easy-tests by malinink.
the class QuestionTypesService method map.
private QuestionTypeModelInterface map(QuestionTypeEntity questionTypeEntity) {
if (questionTypeEntity == null) {
return null;
}
final QuestionTypeModelInterface questionTypeModel = new QuestionTypeModel();
questionTypeModel.map(questionTypeEntity);
return questionTypeModel;
}
use of easytests.core.models.QuestionTypeModelInterface in project easy-tests by malinink.
the class QuestionModelDtoValidator method validateQuestionTypes.
private void validateQuestionTypes(Errors errors, QuestionModelDto questionModelDto) {
final Integer questionTypeId = questionModelDto.getQuestionTypeId();
final String questionTypeIdField = "questionTypeId";
final List<QuestionTypeModelInterface> questionTypeModels = questionTypesService.findAll();
final ArrayList<Integer> questionTypeModelsIds = new ArrayList();
for (QuestionTypeModelInterface questionTypeModel : questionTypeModels) {
questionTypeModelsIds.add(questionTypeModel.getId());
}
if (questionTypeId == null) {
reject(errors, questionTypeIdField, "Select question type");
} else if (!questionTypeModelsIds.contains(questionTypeId)) {
reject(errors, questionTypeIdField, "Wrong question type");
}
}
use of easytests.core.models.QuestionTypeModelInterface in project easy-tests by malinink.
the class QuestionEntityTest method testMap.
@Test
public void testMap() throws Exception {
final Integer questionId = 1;
final String text = "test1";
final Integer questionTypeId = 1;
final Integer topicId = 1;
final TopicModelInterface topic = Mockito.mock(TopicModelInterface.class);
Mockito.when(topic.getId()).thenReturn(topicId);
final QuestionTypeModelInterface questionType = Mockito.mock(QuestionTypeModelInterface.class);
Mockito.when(questionType.getId()).thenReturn(questionTypeId);
final QuestionModelInterface questionModel = Mockito.mock(QuestionModelInterface.class);
Mockito.when(questionModel.getId()).thenReturn(questionId);
Mockito.when(questionModel.getText()).thenReturn(text);
Mockito.when(questionModel.getQuestionType()).thenReturn(questionType);
Mockito.when(questionModel.getTopic()).thenReturn(topic);
final QuestionEntity questionEntity = new QuestionEntity();
questionEntity.map(questionModel);
Assert.assertEquals(questionId, questionEntity.getId());
Assert.assertEquals(text, questionEntity.getText());
Assert.assertEquals(questionTypeId, questionEntity.getQuestionTypeId());
Assert.assertEquals(topicId, questionEntity.getTopicId());
}
use of easytests.core.models.QuestionTypeModelInterface in project easy-tests by malinink.
the class IssueStandardQuestionTypeOptionsOptionsTest method testWithRelationsOnSingleModel.
@Test
public void testWithRelationsOnSingleModel() throws Exception {
final IssueStandardQuestionTypeOptionsOptionsInterface questionTypeOptionsOptions = new IssueStandardQuestionTypeOptionsOptions();
final QuestionTypesServiceInterface questionTypesService = Mockito.mock(QuestionTypesServiceInterface.class);
final QuestionTypesOptionsInterface questionTypesOptions = Mockito.mock(QuestionTypesOptionsInterface.class);
final IssueStandardsServiceInterface issueStandardsService = Mockito.mock(IssueStandardsServiceInterface.class);
final IssueStandardsOptionsInterface issueStandardsOptions = Mockito.mock(IssueStandardsOptionsInterface.class);
final Integer questionTypeId = 3;
final Integer issueStandardId = 10;
final IssueStandardQuestionTypeOptionModelInterface questionTypeOptionModel = Mockito.mock(IssueStandardQuestionTypeOptionModelInterface.class);
Mockito.when(questionTypeOptionModel.getQuestionType()).thenReturn(new QuestionTypeModelEmpty(questionTypeId));
Mockito.when(questionTypeOptionModel.getIssueStandard()).thenReturn(new IssueStandardModelEmpty(issueStandardId));
final QuestionTypeModelInterface questionTypeModel = Mockito.mock(QuestionTypeModelInterface.class);
Mockito.when(questionTypeModel.getId()).thenReturn(questionTypeId);
given(questionTypesService.find(questionTypeId, questionTypesOptions)).willReturn(questionTypeModel);
final IssueStandardModelInterface issueStandardModel = Mockito.mock(IssueStandardModelInterface.class);
Mockito.when(issueStandardModel.getId()).thenReturn(issueStandardId);
given(issueStandardsService.find(issueStandardId, issueStandardsOptions)).willReturn(issueStandardModel);
// options не заданы
final IssueStandardQuestionTypeOptionModelInterface questionTypeOptionModelWithoutRelations = questionTypeOptionsOptions.withRelations(questionTypeOptionModel);
verify(questionTypesService, times(0)).find(questionTypeId, questionTypesOptions);
verify(issueStandardsService, times(0)).find(issueStandardId, issueStandardsOptions);
Assert.assertEquals(questionTypeOptionModel, questionTypeOptionModelWithoutRelations);
Mockito.verify(questionTypeOptionModel, times(0)).setQuestionType(questionTypeModel);
Mockito.verify(questionTypeOptionModel, times(0)).setIssueStandard(issueStandardModel);
questionTypeOptionsOptions.setQuestionTypesService(questionTypesService);
questionTypeOptionsOptions.setIssueStandardsService(issueStandardsService);
questionTypeOptionsOptions.withQuestionType(questionTypesOptions).withIssueStandard(issueStandardsOptions);
// теперь options заданы
final IssueStandardQuestionTypeOptionModelInterface questionTypeOptionModelWithRelations = questionTypeOptionsOptions.withRelations(questionTypeOptionModel);
verify(questionTypesService, times(1)).find(questionTypeId, questionTypesOptions);
verify(issueStandardsService, times(1)).find(issueStandardId, issueStandardsOptions);
Assert.assertEquals(questionTypeOptionModel, questionTypeOptionModelWithRelations);
Mockito.verify(questionTypeOptionModel, times(1)).setQuestionType(questionTypeModel);
Mockito.verify(questionTypeOptionModel, times(1)).setIssueStandard(issueStandardModel);
}
use of easytests.core.models.QuestionTypeModelInterface in project easy-tests by malinink.
the class IssueStandardQuestionTypeOptionsOptionsTest method testWithRelationsOnModelsList.
@Test
public void testWithRelationsOnModelsList() throws Exception {
final IssueStandardQuestionTypeOptionsOptionsInterface questionTypeOptionsOptions = new IssueStandardQuestionTypeOptionsOptions();
final QuestionTypesServiceInterface questionTypesService = Mockito.mock(QuestionTypesServiceInterface.class);
final QuestionTypesOptionsInterface questionTypesOptions = Mockito.mock(QuestionTypesOptionsInterface.class);
final IssueStandardsServiceInterface issueStandardsService = Mockito.mock(IssueStandardsServiceInterface.class);
final IssueStandardsOptionsInterface issueStandardsOptions = Mockito.mock(IssueStandardsOptionsInterface.class);
final Integer issueStandardIdFirst = 10;
final Integer issueStandardIdSecond = 20;
final Integer questionTypeIdFirst = 2;
final Integer questionTypeIdSecond = 3;
final IssueStandardQuestionTypeOptionModelInterface questionTypeOptionModelFirst = Mockito.mock(IssueStandardQuestionTypeOptionModelInterface.class);
Mockito.when(questionTypeOptionModelFirst.getQuestionType()).thenReturn(new QuestionTypeModelEmpty(questionTypeIdFirst));
Mockito.when(questionTypeOptionModelFirst.getIssueStandard()).thenReturn(new IssueStandardModelEmpty(issueStandardIdFirst));
final IssueStandardQuestionTypeOptionModelInterface questionTypeOptionModelSecond = Mockito.mock(IssueStandardQuestionTypeOptionModelInterface.class);
Mockito.when(questionTypeOptionModelSecond.getQuestionType()).thenReturn(new QuestionTypeModelEmpty(questionTypeIdSecond));
Mockito.when(questionTypeOptionModelSecond.getIssueStandard()).thenReturn(new IssueStandardModelEmpty(issueStandardIdSecond));
final List<IssueStandardQuestionTypeOptionModelInterface> questionTypeOptionModels = new ArrayList<>(2);
questionTypeOptionModels.add(questionTypeOptionModelFirst);
questionTypeOptionModels.add(questionTypeOptionModelSecond);
final QuestionTypeModelInterface questionTypeModelFirst = Mockito.mock(QuestionTypeModelInterface.class);
Mockito.when(questionTypeModelFirst.getId()).thenReturn(questionTypeIdFirst);
given(questionTypesService.find(questionTypeIdFirst, questionTypesOptions)).willReturn(questionTypeModelFirst);
final QuestionTypeModelInterface questionTypeModelSecond = Mockito.mock(QuestionTypeModelInterface.class);
Mockito.when(questionTypeModelSecond.getId()).thenReturn(questionTypeIdSecond);
given(questionTypesService.find(questionTypeIdSecond, questionTypesOptions)).willReturn(questionTypeModelSecond);
final IssueStandardModelInterface issueStandardModelFirst = Mockito.mock(IssueStandardModelInterface.class);
Mockito.when(issueStandardModelFirst.getId()).thenReturn(issueStandardIdFirst);
given(issueStandardsService.find(issueStandardIdFirst, issueStandardsOptions)).willReturn(issueStandardModelFirst);
final IssueStandardModelInterface issueStandardModelSecond = Mockito.mock(IssueStandardModelInterface.class);
Mockito.when(issueStandardModelSecond.getId()).thenReturn(issueStandardIdSecond);
given(issueStandardsService.find(issueStandardIdSecond, issueStandardsOptions)).willReturn(issueStandardModelSecond);
// options не заданы
final List<IssueStandardQuestionTypeOptionModelInterface> questionTypeOptionModelsWithoutRelations = questionTypeOptionsOptions.withRelations(questionTypeOptionModels);
verify(questionTypesService, times(0)).find(questionTypeIdFirst, questionTypesOptions);
verify(questionTypesService, times(0)).find(questionTypeIdSecond, questionTypesOptions);
verify(issueStandardsService, times(0)).find(issueStandardIdFirst, issueStandardsOptions);
verify(issueStandardsService, times(0)).find(issueStandardIdSecond, issueStandardsOptions);
Assert.assertEquals(questionTypeOptionModels, questionTypeOptionModelsWithoutRelations);
Mockito.verify(questionTypeOptionModelFirst, times(0)).setQuestionType(questionTypeModelFirst);
Mockito.verify(questionTypeOptionModelFirst, times(0)).setIssueStandard(issueStandardModelFirst);
Mockito.verify(questionTypeOptionModelSecond, times(0)).setQuestionType(questionTypeModelSecond);
Mockito.verify(questionTypeOptionModelSecond, times(0)).setIssueStandard(issueStandardModelSecond);
questionTypeOptionsOptions.setQuestionTypesService(questionTypesService);
questionTypeOptionsOptions.setIssueStandardsService(issueStandardsService);
questionTypeOptionsOptions.withQuestionType(questionTypesOptions).withIssueStandard(issueStandardsOptions);
// теперь options заданы
final List<IssueStandardQuestionTypeOptionModelInterface> questionTypeOptionModelsWithRelations = questionTypeOptionsOptions.withRelations(questionTypeOptionModels);
verify(questionTypesService, times(1)).find(questionTypeIdFirst, questionTypesOptions);
verify(questionTypesService, times(1)).find(questionTypeIdSecond, questionTypesOptions);
verify(issueStandardsService, times(1)).find(issueStandardIdFirst, issueStandardsOptions);
verify(issueStandardsService, times(1)).find(issueStandardIdSecond, issueStandardsOptions);
Assert.assertEquals(questionTypeOptionModels, questionTypeOptionModelsWithRelations);
Mockito.verify(questionTypeOptionModelFirst, times(1)).setQuestionType(questionTypeModelFirst);
Mockito.verify(questionTypeOptionModelFirst, times(1)).setIssueStandard(issueStandardModelFirst);
Mockito.verify(questionTypeOptionModelSecond, times(1)).setQuestionType(questionTypeModelSecond);
Mockito.verify(questionTypeOptionModelSecond, times(1)).setIssueStandard(issueStandardModelSecond);
}
Aggregations