コード例 #1
0
  @Test
  public void testFindComposedTypeForClass() {
    when(modelService.getModelType(java.lang.String.class)).thenReturn("String");
    when(typeDao.findComposedTypeByCode("String")).thenReturn(model1);

    final ComposedTypeModel actualModel = typeService.getComposedTypeForCode("String");
    Assert.assertEquals("Method returned unexpected model", model1, actualModel);
  }
コード例 #2
0
 @Test
 public void testFindNonExistingComposedType() {
   when(typeDao.findComposedTypeByCode("noCodeFound"))
       .thenThrow(new UnknownIdentifierException(""));
   try {
     typeService.getComposedTypeForCode("noCodeFound");
     Assert.fail("Non existing component model found!");
   } catch (final UnknownIdentifierException e) {
     // perfectly ok
   }
 }
コード例 #3
0
  @Test
  public void testGetUniqueAttributesWithoutModelConverter() {
    final AttributeDescriptorModel attributeDescriptor1 = new AttributeDescriptorModel();
    attributeDescriptor1.setUnique(Boolean.TRUE);

    final ModelConverter nonItemModelConverter = mock(ModelConverter.class);
    final ComposedTypeModel nonItemModel = mock(ComposedTypeModel.class);
    when(converterRegistry.getModelConverterBySourceType("nonItemModel"))
        .thenReturn(nonItemModelConverter);
    when((nonItemModel).getDeclaredattributedescriptors())
        .thenReturn(Collections.singletonList(attributeDescriptor1));
    when(typeDao.findComposedTypeByCode("nonItemModel")).thenReturn(nonItemModel);

    final Set<String> actualUnique = typeService.getUniqueAttributes("nonItemModel");
    Assert.assertEquals("One attribute expected", 1, actualUnique.size());
  }
コード例 #4
0
  @Test
  public void testFindMandatoryAttributesWithoutModelConverter() {
    final AttributeDescriptorModel attributeDescriptor1 = new AttributeDescriptorModel();
    attributeDescriptor1.setModifiers(Integer.valueOf(AttributeDescriptor.WRITE_FLAG));

    final ModelConverter nonItemModelConverter = mock(ModelConverter.class);
    final ComposedTypeModel nonItemModel = mock(ComposedTypeModel.class);
    when(converterRegistry.getModelConverterBySourceType("nonItemModel"))
        .thenReturn(nonItemModelConverter);
    when((nonItemModel).getDeclaredattributedescriptors())
        .thenReturn(Collections.singletonList(attributeDescriptor1));
    when(typeDao.findComposedTypeByCode("nonItemModel")).thenReturn(nonItemModel);

    final Set<String> actualMandatory = typeService.getMandatoryAttributes("nonItemModel", false);
    Assert.assertEquals("One attribute expected", 1, actualMandatory.size());
  }
コード例 #5
0
  @Test
  public void testFindUniqueModelRootType() {
    final Set<String> unique = new HashSet<String>();
    unique.add("unique1");
    final ItemModelConverter modelConverter = mock(ItemModelConverter.class);
    when(modelConverter.getUniqueAttributes()).thenReturn(unique);

    when(converterRegistry.getModelConverterBySourceType("type1")).thenReturn(modelConverter);
    when(converterRegistry.getModelConverterBySourceType("type2")).thenReturn(modelConverter);

    final ComposedTypeModel composedType1 = mock(ComposedTypeModel.class);
    final ComposedTypeModel composedType2 = mock(ComposedTypeModel.class);
    when((composedType1).getCode()).thenReturn("type1");
    when((composedType2).getCode()).thenReturn("type2");
    when((composedType2).getSuperType()).thenReturn(composedType1);
    when(typeDao.findComposedTypeByCode("type2")).thenReturn(composedType2);

    final String actualUnique = typeService.getUniqueModelRootType("type2");
    Assert.assertEquals("Got unexpected unique root type", "type1", actualUnique);
  }
コード例 #6
0
  @Test
  public void testGetAttributesForModiferCriteria() {
    final AttributeDescriptorModel declaredDescriptor = mock(AttributeDescriptorModel.class);
    when(declaredDescriptor.getModifiers()).thenReturn(Integer.valueOf(AttributeModifiers.READ));

    final AttributeDescriptorModel privateDescriptor = mock(AttributeDescriptorModel.class);
    when(privateDescriptor.getModifiers())
        .thenReturn(Integer.valueOf(AttributeModifiers.READ | AttributeModifiers.PRIVATE));
    when(privateDescriptor.getPrivate()).thenReturn(Boolean.TRUE);

    final AttributeDescriptorModel inheritedDescriptor = mock(AttributeDescriptorModel.class);
    when(inheritedDescriptor.getModifiers())
        .thenReturn(Integer.valueOf(AttributeModifiers.READ | AttributeModifiers.INHERITED));

    final AttributeDescriptorModel writableDescriptor = mock(AttributeDescriptorModel.class);
    when(writableDescriptor.getModifiers())
        .thenReturn(Integer.valueOf(AttributeModifiers.READ | AttributeModifiers.WRITE));
    when(writableDescriptor.getWritable()).thenReturn(Boolean.TRUE);

    final AttributeDescriptorModel partofDescriptor = mock(AttributeDescriptorModel.class);
    when(partofDescriptor.getModifiers())
        .thenReturn(
            Integer.valueOf(
                AttributeModifiers.READ | AttributeModifiers.PARTOF | AttributeModifiers.WRITE));
    when(partofDescriptor.getWritable()).thenReturn(Boolean.TRUE);
    when(partofDescriptor.getPartOf()).thenReturn(Boolean.TRUE);

    final Set<AttributeDescriptorModel> declaredDescriptorModels =
        new HashSet<AttributeDescriptorModel>();
    declaredDescriptorModels.add(declaredDescriptor);
    declaredDescriptorModels.add(writableDescriptor);
    declaredDescriptorModels.add(partofDescriptor);

    final Set<AttributeDescriptorModel> inheritedDescriptorModels =
        new HashSet<AttributeDescriptorModel>();
    inheritedDescriptorModels.add(inheritedDescriptor);

    final ComposedTypeModel typeModel = mock(ComposedTypeModel.class);
    when((typeModel).getDeclaredattributedescriptors()).thenReturn(declaredDescriptorModels);
    when((typeModel).getInheritedattributedescriptors()).thenReturn(inheritedDescriptorModels);

    final PK descriptorPk = PK.fromLong(1234567890);
    final AttributeDescriptor privateDescriptorItem = mock(AttributeDescriptor.class);
    when(privateDescriptorItem.getPK()).thenReturn(descriptorPk);
    when(Boolean.valueOf(privateDescriptorItem.isPrivate())).thenReturn(Boolean.TRUE);

    final Set<AttributeDescriptor> privateDescriptorItems = new HashSet<AttributeDescriptor>();
    privateDescriptorItems.add(privateDescriptorItem);

    final ComposedType composedType = mock(ComposedType.class);
    when(modelService.getSource(typeModel)).thenReturn(composedType);
    when(composedType.getAttributeDescriptorsIncludingPrivate()).thenReturn(privateDescriptorItems);
    when(modelService.get(privateDescriptorItem)).thenReturn(privateDescriptor);

    when(typeDao.findComposedTypeByCode("modifierTest")).thenReturn(typeModel);

    final AttributeModifierCriteria modifierCriteria =
        new AttributeModifierCriteria(0, AttributeModifiers.ALL, 0);
    Assert.assertEquals(
        "Five declared descriptors expected",
        5,
        typeService.getAttributesForModifiers("modifierTest", modifierCriteria).size());

    modifierCriteria.addDisallowed(AttributeModifiers.PRIVATE);
    Assert.assertEquals(
        "Four declared descriptors expected",
        4,
        typeService.getAttributesForModifiers("modifierTest", modifierCriteria).size());

    modifierCriteria.addDisallowed(AttributeModifiers.INHERITED);
    Assert.assertEquals(
        "Three declared descriptors expected",
        3,
        typeService.getAttributesForModifiers("modifierTest", modifierCriteria).size());

    modifierCriteria.addRequired(AttributeModifiers.WRITE);
    Assert.assertEquals(
        "Two declared descriptors expected",
        2,
        typeService.getAttributesForModifiers("modifierTest", modifierCriteria).size());

    modifierCriteria.addRequired(AttributeModifiers.PARTOF);
    Assert.assertEquals(
        "One declared descriptor expected",
        1,
        typeService.getAttributesForModifiers("modifierTest", modifierCriteria).size());
  }
コード例 #7
0
 @Test
 public void testFindComposedTypeForCode() {
   when(typeDao.findComposedTypeByCode("singleCodeFound")).thenReturn(model1);
   Assert.assertNotNull(
       "One composed type should be found", typeService.getComposedTypeForCode("singleCodeFound"));
 }