FeatureManagerImpl implements FeatureManager { @Override public boolean deleteFeaturesOfProfile(Profile profile) throws FeatureManagementException { boolean bool; try { PolicyManagementDAOFactory.beginTransaction(); bool = featureDAO.deleteFeaturesOfProfile(profile); PolicyManagementDAOFactory.commitTransaction(); } catch (FeatureManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new FeatureManagementException("Error occurred while deleting the feature of - profile (" + profile.getProfileName() + ")", e); } catch (PolicyManagerDAOException e) { throw new FeatureManagementException("Error occurred while deleting the feature of - profile (" + profile.getProfileName() + ") from database", e); } finally { PolicyManagementDAOFactory.closeConnection(); } return bool; } FeatureManagerImpl(); @Override ProfileFeature addProfileFeature(ProfileFeature feature, int profileId); @Override ProfileFeature updateProfileFeature(ProfileFeature feature, int profileId); @Override List<ProfileFeature> addProfileFeatures(List<ProfileFeature> features, int profileId); @Override List<ProfileFeature> updateProfileFeatures(List<ProfileFeature> features, int profileId); @Override List<Feature> getAllFeatures(String deviceType); @Override List<ProfileFeature> getFeaturesForProfile(int profileId); @Override boolean deleteFeaturesOfProfile(Profile profile);  }
@Test(description = "This test case tests handling FeatureManagerDAOException when deleting features of a profile", dependsOnMethods = "testGetFeaturesForProfile") public void testDeleteFeaturesOfProfileThrowingFeatureManagerDAOException() throws Exception { Profile profile = ProfileCreator.getProfile(FeatureCreator.getFeatureList(), DEVICE_TYPE_D); profile1 = profileManager.addProfile(profile); FeatureDAO featureDAO = mock(FeatureDAO.class); when(featureDAO.deleteFeaturesOfProfile(any(Profile.class))).thenThrow(new FeatureManagerDAOException()); testThrowingException(featureManager, profile1, p -> featureManager.deleteFeaturesOfProfile(profile), "featureDAO", featureDAO, FeatureManagerDAOException.class); }
@Test(description = "This test case tests handling SQLException when deleting features of a profile", dependsOnMethods = "testDeleteFeaturesOfProfileThrowingFeatureManagerDAOException", expectedExceptions = IllegalTransactionStateException.class) public void testDeleteFeaturesOfProfileThrowingIllegalTransactionStateException() throws Exception { Pair<Connection, Pair<DataSource, DataSource>> pair = mockConnection(); PowerMockito.doThrow(new SQLException()).when(pair.second().second()).getConnection(); try { featureManager.deleteFeaturesOfProfile(profile1); } finally { PolicyManagementDAOFactory.init(pair.second().first()); } }
@Test(description = "This test case tests deleting features of a profile", dependsOnMethods = "testDeleteFeaturesOfProfileThrowingIllegalTransactionStateException") public void testDeleteFeaturesOfProfile() throws Exception { featureManager.deleteFeaturesOfProfile(profile1); }