@Test public void testLookupAbsoluteParentWhenParentIsNotStructure() { final String type = "type"; final String referenceUUID = "referenceUUID"; final ItemDefinition parent = mock(ItemDefinition.class); final Optional<ItemDefinition> expectedParent = Optional.of(mock(ItemDefinition.class)); final QName qName = mock(QName.class); when(qName.getLocalPart()).thenReturn(type); when(parent.getTypeRef()).thenReturn(qName); when(itemDefinitionStore.get(referenceUUID)).thenReturn(parent); when(itemDefinitionUtils.findByName(type)).thenReturn(expectedParent); final Optional<ItemDefinition> actualParent = handler.lookupAbsoluteParent(referenceUUID); assertEquals(expectedParent, actualParent); }
Optional<ItemDefinition> lookupAbsoluteParent(final String parentUUID) { final Optional<ItemDefinition> optionalParent = Optional.ofNullable(getIndexedItemDefinition(parentUUID)); if (optionalParent.isPresent()) { final ItemDefinition parent = optionalParent.get(); final boolean isStructure = parent.getTypeRef() == null; if (isStructure) { return Optional.of(parent); } else { return findItemDefinitionByName(parent.getTypeRef().getLocalPart()); } } return Optional.empty(); }
ItemDefinitionCreateHandler { Optional<ItemDefinition> lookupAbsoluteParent(final String parentUUID) { final Optional<ItemDefinition> optionalParent = Optional.ofNullable(getIndexedItemDefinition(parentUUID)); if (optionalParent.isPresent()) { final ItemDefinition parent = optionalParent.get(); final boolean isStructure = parent.getTypeRef() == null; if (isStructure) { return Optional.of(parent); } else { return findItemDefinitionByName(parent.getTypeRef().getLocalPart()); } } return Optional.empty(); } }
ItemDefinitionCreateHandler { Optional<ItemDefinition> lookupAbsoluteParent(final String parentUUID) { final Optional<ItemDefinition> optionalParent = Optional.ofNullable(getIndexedItemDefinition(parentUUID)); if (optionalParent.isPresent()) { final ItemDefinition parent = optionalParent.get(); final boolean isStructure = parent.getTypeRef() == null; if (isStructure) { return Optional.of(parent); } else { return findItemDefinitionByName(parent.getTypeRef().getLocalPart()); } } return Optional.empty(); } @Inject  ItemDefinitionCreateHandler(final ItemDefinitionUtils itemDefinitionUtils,
                                       final ItemDefinitionStore itemDefinitionStore); }
ItemDefinitionCreateHandler { Optional<ItemDefinition> lookupAbsoluteParent(final String parentUUID) { final Optional<ItemDefinition> optionalParent = Optional.ofNullable(getIndexedItemDefinition(parentUUID)); if (optionalParent.isPresent()) { final ItemDefinition parent = optionalParent.get(); final boolean isStructure = parent.getTypeRef() == null; if (isStructure) { return Optional.of(parent); } else { return findItemDefinitionByName(parent.getTypeRef().getLocalPart()); } } return Optional.empty(); } @Inject  ItemDefinitionCreateHandler(final ItemDefinitionUtils itemDefinitionUtils,
                                       final ItemDefinitionStore itemDefinitionStore); ItemDefinition appendItemDefinition(); ItemDefinition insertNested(final DataType record,
                                       final DataType reference); ItemDefinition insertSibling(final DataType record,
                                        final DataType reference,
                                        final CreationType creationType); }
ItemDefinitionCreateHandler { Optional<ItemDefinition> lookupAbsoluteParent(final String parentUUID) { final Optional<ItemDefinition> optionalParent = Optional.ofNullable(getIndexedItemDefinition(parentUUID)); if (optionalParent.isPresent()) { final ItemDefinition parent = optionalParent.get(); final boolean isStructure = parent.getTypeRef() == null; if (isStructure) { return Optional.of(parent); } else { return findItemDefinitionByName(parent.getTypeRef().getLocalPart()); } } return Optional.empty(); } @Inject  ItemDefinitionCreateHandler(final ItemDefinitionUtils itemDefinitionUtils,
                                       final ItemDefinitionStore itemDefinitionStore); ItemDefinition appendItemDefinition(); ItemDefinition insertNested(final DataType record,
                                       final DataType reference); ItemDefinition insertSibling(final DataType record,
                                        final DataType reference,
                                        final CreationType creationType);  }