@Override public Item doCreateItem(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { //First, we just create this item Item item = null; ItemGroup<? extends TopLevelItem> ig = getOwnerItemGroup(); if (ig instanceof ModifiableItemGroup) item = ((ModifiableItemGroup<? extends TopLevelItem>)ig).doCreateItem(req, rsp); //Checking if we deal with an inheritable job if (item == null || !(item instanceof InheritanceProject)) { return item; } //If we deal with an inheritable project, we assign it to the currently //viewed creation class, if any InheritanceProject ip = (InheritanceProject) item; //Checking if we define a CC if (!this.creationClassFilter.isEmpty()) { ip.setCreationClass(this.creationClassFilter); } return item; }
@Override public TopLevelItem doCreateItem(final StaplerRequest req, final StaplerResponse rsp) throws IOException, ServletException { final ItemGroup<? extends TopLevelItem> ig = getOwnerItemGroup(); if (ig instanceof ModifiableItemGroup) { return ((ModifiableItemGroup<? extends TopLevelItem>) ig).doCreateItem(req, rsp); } return null; }
@Test public void should_create_item_iff_owner_is_modifiable() throws IOException, ServletException { ModifiableItemGroup<?> parentView = mock(ModifiableItemGroup.class); doReturn(parentView).when(myBuildsView).getOwnerItemGroup(); myBuildsView.doCreateItem(null, null); verify(parentView).doCreateItem(null, null); }