TemplateResource { protected void orphanOriginalStormTemplate(String originalTemplateId, ItemManager itemMan) { if (!StringUtils.isEmpty(originalTemplateId)) { Item originalTemplate = itemMan.load(originalTemplateId); if (null == originalTemplate) { throw new EntityNotFoundException(String.format( "Could not find template with ID '%s'. " + "Perhaps the template Item was deleted " + "between the time it was persisted and the time it was read?", originalTemplateId)); } else { if (Type.storms.equals(originalTemplate.getType())) { boolean success = itemMan.orphan(originalTemplate); if (!success) { throw new PersistenceException( String.format( "Could not orphan template with ID '%s'", originalTemplateId ) ); } } } } }  @GET @Path("/item/{id}") @Produces(MediaType.APPLICATION_JSON) Response getTemplate(@PathParam("id") String id, @Context Request request); Response instantiateTemplate(Document metadataXml, ParsedMetadata parsedMetadata, String id, String content); @POST @Path("/storm") @Produces(MediaType.APPLICATION_JSON) @ConfiguredRolesAllowed(ConfiguredRolesAllowedDynamicFeature.CCH_ADMIN_USER_PROP) Response instantiateStormTemplate(
			@FormDataParam("layerId") String layerId,
			@FormDataParam("activeStorm") String active,
			@FormDataParam("alias") String alias,
			@FormDataParam("copyType") String copyType,
			@FormDataParam("copyVal") String copyVal,
			@FormDataParam("trackId") String trackId,
			@FormDataParam("file") String metadataFile);  }
@Test public void testNoExceptionsThrownWhileOrphaningNullTemplateId() { instance.orphanOriginalStormTemplate(null, mockItemMan); verifyZeroInteractions(mockItemMan); }
@Test public void testNoExceptionsThrownWhileOrphaningBlankTemplateId() { instance.orphanOriginalStormTemplate("", mockItemMan); verifyZeroInteractions(mockItemMan); }
@Test(expected = EntityNotFoundException.class) public void testMissingTemplateThrowsExceptionWhileOrphaning() { String id = "foo"; when(mockItemMan.load(id)).thenReturn(null); instance.orphanOriginalStormTemplate(id, mockItemMan); }
@Test(expected = PersistenceException.class) public void testThatItemManagerOrphanFailureThrowsException() { String id = "foo"; Item item = new Item(); item.setType(Type.storms); when(mockItemMan.load(id)).thenReturn(item); when(mockItemMan.orphan(item)).thenReturn(false); instance.orphanOriginalStormTemplate(id, mockItemMan); }
@Test public void testThatSuccessfulItemManagerOrphaningThrowsNoException() { String id = "foo"; Item item = new Item(); item.setType(Type.storms); when(mockItemMan.load(id)).thenReturn(item); when(mockItemMan.orphan(item)).thenReturn(true); instance.orphanOriginalStormTemplate(id, mockItemMan); verify(mockItemMan).orphan(eq(item)); }
@Test public void testThatOnlyStormsAreOrphaned() { String id = "foo"; Item item = new Item(); item.setType(Type.vulnerability); when(mockItemMan.load(id)).thenReturn(item); instance.orphanOriginalStormTemplate(id, mockItemMan); verify(mockItemMan, never()).orphan(any()); }