@Test
  public void testGetAllUserWorkflowActionsWithAttachmentsWhenUnknownClass() {
    // given
    final String COMPOSED_TYPE_CODE = "unknownClass";
    final List<WorkflowActionModel> actions = new ArrayList<WorkflowActionModel>();
    actions.add(mock(WorkflowActionModel.class));
    final ComposedTypeModel mockProductComposedType = mock(ComposedTypeModel.class);
    when(typeService.getComposedTypeForCode(COMPOSED_TYPE_CODE))
        .thenThrow(new UnknownIdentifierException(""));
    when(typeService.getComposedTypeForClass(ProductModel.class))
        .thenReturn(mockProductComposedType);
    when(workflowActionDao.findWorkflowActionsByStatusAndAttachmentType(
            Collections.singletonList(mockProductComposedType),
            Collections.singletonList(WorkflowActionStatus.IN_PROGRESS)))
        .thenReturn(actions);

    final List<String> attachmentTypes = new ArrayList<String>();
    attachmentTypes.add(COMPOSED_TYPE_CODE);

    // when
    final List<WorkflowActionModel> endWorkflowActions =
        workflowActionService.getAllUserWorkflowActionsWithAttachments(attachmentTypes);

    // then
    assertThat(endWorkflowActions).isEmpty();
  }
 /** {@inheritDoc} */
 @Override
 public Set<String> getVariantAttributes(final String variantProductType) {
   final ComposedTypeModel composedTypeModel =
       typeService.getComposedTypeForCode(variantProductType);
   if (composedTypeModel instanceof VariantTypeModel) {
     final VariantTypeModel variantTypeModel = (VariantTypeModel) composedTypeModel;
     final Collection<VariantAttributeDescriptorModel> variantAttributtes =
         getVariantAttributesForVariantType(variantTypeModel);
     if (CollectionUtils.isEmpty(variantAttributtes)) {
       return Collections.EMPTY_SET;
     } else {
       final Set<String> ret = new HashSet<String>(variantAttributtes.size());
       for (final VariantAttributeDescriptorModel vad : variantAttributtes) {
         ret.add(vad.getQualifier());
       }
       return ret;
     }
   } else {
     throw new IllegalArgumentException(
         "there is no variant type '"
             + variantProductType
             + "'"
             + (composedTypeModel == null
                 ? ""
                 : " - found composed type (" + composedTypeModel + ") instead"));
   }
 }
  @Test
  public void testUniqueNullAttributeSlayerAPI() {

    final ComposedTypeModel typeUnderInvestigation =
        typeService.getComposedTypeForClass(LinkModel.class);
    final AttributeDescriptorModel attributeDesc =
        typeService.getAttributeDescriptor(typeUnderInvestigation, LinkModel.LANGUAGE);
    Assert.assertTrue(attributeDesc.getOptional().booleanValue());
    Assert.assertTrue(attributeDesc.getUnique().booleanValue());

    final LinkModel link1 = modelService.create(LinkModel.class);
    link1.setQualifier("link1");
    link1.setSource(source);
    link1.setTarget(target);
    // the optional unique attribute
    link1.setLanguage(language);

    modelService.save(link1); // <-- OK!

    final LinkModel link2 = modelService.create(LinkModel.class);
    link2.setQualifier("link2");
    link2.setSource(source);
    link2.setTarget(target);
    // the optional unique attribute
    link2.setLanguage(null);

    modelService.save(link2); // <-- OK! //<-- still OK, only one null value!

    final LinkModel link3 = modelService.create(LinkModel.class);
    link3.setQualifier("link3");
    link3.setSource(source);
    link3.setTarget(target);
    // the optional unique attribute
    link3.setLanguage(null);

    boolean success = false;
    try {
      modelService.save(link3); // <-- what happens now?!
      Assert.fail(
          "Should have failed with 'ModelSavingException' for ambiguous unique attribute, which is 'null'");
    } catch (final ModelSavingException e) {
      success = true;
    }
    Assert.assertTrue(
        "Should have failed with 'ModelSavingException' for ambiguous unique attribute, which is 'null'",
        success);
  }
  /** {@inheritDoc} */
  @Override
  public VariantTypeModel getVariantTypeForCode(final String code) {
    validateParameterNotNullStandardMessage("code", code);

    final ComposedTypeModel composedTypeModel = typeService.getComposedTypeForCode(code);
    if (!(composedTypeModel instanceof VariantTypeModel)) {
      throw new UnknownIdentifierException(
          "There is no variant type '" + code + "' (found composed type instead)");
    }

    return (VariantTypeModel) composedTypeModel;
  }
  @Test
  public void testCreateWorkflowAction() {
    // given
    final WorkflowActionTemplateModel template = mock(WorkflowActionTemplateModel.class);
    final WorkflowActionModel mockAction = mock(WorkflowActionModel.class);
    when(modelService.create(WorkflowActionModel.class)).thenReturn(mockAction);
    final ComposedTypeModel composedTypeModel = mock(ComposedTypeModel.class);
    when(typeService.getComposedTypeForCode(AbstractWorkflowActionModel._TYPECODE))
        .thenReturn(composedTypeModel);
    when(composedTypeModel.getDeclaredattributedescriptors())
        .thenReturn(new ArrayList<AttributeDescriptorModel>());
    // when
    final WorkflowActionModel action =
        workflowActionService.createWorkflowAction(template, workflow);

    // then
    assertThat(action).isNotNull();
    assertThat(action).isSameAs(mockAction);
  }
  /** {@inheritDoc} */
  @Override
  public List<VariantAttributeDescriptorModel> getVariantAttributesForVariantType(
      final VariantTypeModel variantType) {
    // Currently a deprecated typeService - method is in use, the dedicated replacement
    // (getAttributeDescriptorsForType(...) doesn't return the updated AttributeDescriptor List.
    final List<AttributeDescriptorModel> attributes =
        new ArrayList(typeService.getAttributeDescriptors(variantType));
    final List<VariantAttributeDescriptorModel> attributesResult =
        new ArrayList<VariantAttributeDescriptorModel>(attributes.size());
    for (final Iterator<AttributeDescriptorModel> it = attributes.iterator(); it.hasNext(); ) {
      final AttributeDescriptorModel attributeDescriptorModel = it.next();
      if ((attributeDescriptorModel instanceof VariantAttributeDescriptorModel)) {
        attributesResult.add((VariantAttributeDescriptorModel) attributeDescriptorModel);
      }
    }

    Collections.sort(attributesResult, VARIANT_ATTRIBUTES_COMPARATOR);
    return attributesResult;
  }
  @Test
  public void testGetAllUserWorkflowActionsWithAttachmentForString() {
    // given
    final List<WorkflowActionModel> actions = new ArrayList<WorkflowActionModel>();
    actions.add(mock(WorkflowActionModel.class));
    final ComposedTypeModel mockProductComposedType = mock(ComposedTypeModel.class);
    when(mockProductComposedType.getJaloclass()).thenReturn(Product.class);
    when(typeService.getComposedTypeForCode(ProductModel._TYPECODE))
        .thenReturn(mockProductComposedType);
    when(workflowActionDao.findWorkflowActionsByStatusAndAttachmentType(
            Collections.singletonList(mockProductComposedType),
            Collections.singletonList(WorkflowActionStatus.IN_PROGRESS)))
        .thenReturn(actions);

    // when
    final List<WorkflowActionModel> endWorkflowActions =
        workflowActionService.getAllUserWorkflowActionsWithAttachment(ProductModel._TYPECODE);

    // then
    assertThat(endWorkflowActions).isSameAs(actions);
  }