@Test public void checkReferentOfferUsageInStrategiesValidOnComplexStrategiesValid() throws FileNotFoundException, InvalidParseOperationException { File staticStrategies = PropertiesUtils.getResourceFile("static-strategy-complex-valid.json"); List<StorageStrategy> storageStrategies = JsonHandler.getFromFileAsTypeReference(staticStrategies, new TypeReference<List<StorageStrategy>>() { }); boolean isValid = StorageStrategyUtils.checkReferentOfferUsageInStrategiesValid(storageStrategies); assertThat(isValid).isTrue(); }
public static boolean checkReferentOfferUsageInStrategiesValid(List<StorageStrategy> storageStrategies) { Map<String, String> referentOfferByStrategy = storageStrategies.stream() .filter(strategy -> strategy.getOffers().stream() .filter(OfferReference::isReferent) .filter(OfferReference::isEnabled) .map(OfferReference::getId) .count() == 1) .collect(Collectors.toMap( StorageStrategy::getId, strategy -> strategy.getOffers().stream() .filter(OfferReference::isReferent) .filter(OfferReference::isEnabled) .map(OfferReference::getId).findFirst().get())); return referentOfferByStrategy.keySet().size() == new HashSet<>(referentOfferByStrategy.values()).size(); }
StorageStrategyUtils { public static boolean checkReferentOfferUsageInStrategiesValid(List<StorageStrategy> storageStrategies) { Map<String, String> referentOfferByStrategy = storageStrategies.stream() .filter(strategy -> strategy.getOffers().stream() .filter(OfferReference::isReferent) .filter(OfferReference::isEnabled) .map(OfferReference::getId) .count() == 1) .collect(Collectors.toMap( StorageStrategy::getId, strategy -> strategy.getOffers().stream() .filter(OfferReference::isReferent) .filter(OfferReference::isEnabled) .map(OfferReference::getId).findFirst().get())); return referentOfferByStrategy.keySet().size() == new HashSet<>(referentOfferByStrategy.values()).size(); } }
StorageStrategyUtils { public static boolean checkReferentOfferUsageInStrategiesValid(List<StorageStrategy> storageStrategies) { Map<String, String> referentOfferByStrategy = storageStrategies.stream() .filter(strategy -> strategy.getOffers().stream() .filter(OfferReference::isReferent) .filter(OfferReference::isEnabled) .map(OfferReference::getId) .count() == 1) .collect(Collectors.toMap( StorageStrategy::getId, strategy -> strategy.getOffers().stream() .filter(OfferReference::isReferent) .filter(OfferReference::isEnabled) .map(OfferReference::getId).findFirst().get())); return referentOfferByStrategy.keySet().size() == new HashSet<>(referentOfferByStrategy.values()).size(); }  }
StorageStrategyUtils { public static boolean checkReferentOfferUsageInStrategiesValid(List<StorageStrategy> storageStrategies) { Map<String, String> referentOfferByStrategy = storageStrategies.stream() .filter(strategy -> strategy.getOffers().stream() .filter(OfferReference::isReferent) .filter(OfferReference::isEnabled) .map(OfferReference::getId) .count() == 1) .collect(Collectors.toMap( StorageStrategy::getId, strategy -> strategy.getOffers().stream() .filter(OfferReference::isReferent) .filter(OfferReference::isEnabled) .map(OfferReference::getId).findFirst().get())); return referentOfferByStrategy.keySet().size() == new HashSet<>(referentOfferByStrategy.values()).size(); }  static void checkStrategy(String storageStrategy, List<StorageStrategy> referentialStrategies,
                                     String variableName, boolean referentOffersMandatory); static List<String> loadOfferIds(String storageStrategyId, List<StorageStrategy> storageStrategies); static boolean checkReferentOfferUsageInStrategiesValid(List<StorageStrategy> storageStrategies); }
StorageStrategyUtils { public static boolean checkReferentOfferUsageInStrategiesValid(List<StorageStrategy> storageStrategies) { Map<String, String> referentOfferByStrategy = storageStrategies.stream() .filter(strategy -> strategy.getOffers().stream() .filter(OfferReference::isReferent) .filter(OfferReference::isEnabled) .map(OfferReference::getId) .count() == 1) .collect(Collectors.toMap( StorageStrategy::getId, strategy -> strategy.getOffers().stream() .filter(OfferReference::isReferent) .filter(OfferReference::isEnabled) .map(OfferReference::getId).findFirst().get())); return referentOfferByStrategy.keySet().size() == new HashSet<>(referentOfferByStrategy.values()).size(); }  static void checkStrategy(String storageStrategy, List<StorageStrategy> referentialStrategies,
                                     String variableName, boolean referentOffersMandatory); static List<String> loadOfferIds(String storageStrategyId, List<StorageStrategy> storageStrategies); static boolean checkReferentOfferUsageInStrategiesValid(List<StorageStrategy> storageStrategies);  }