FeatureValidator { void validateFeatureUpdateThrowing(Feature feature) throws ServiceException { if (feature.hasOwner()) { validateOwner(feature.getOwner()); } validateKeysThrowing(feature); if (OptionType.flag != feature.getOptions().getOption()) { validateOptionsHaveIdsThrowing(feature); } if (OptionType.flag != feature.getOptions().getOption() && feature.getOptions().getItemsCount() != 0) { validateOptionsThrowing(feature.getOptions()); if (feature.hasNamespaces()) { validateNamespaceFeaturesThrowing(feature); } } }    }
@Test public void validateFeatureThrowingStringOptionUpdateOk() { final Feature.Builder builder = Feature.newBuilder(); final OptionCollection.Builder collectionBuilder = OptionCollection.newBuilder() .setOption(OptionType.string) .addItems(FeatureOption.newBuilder().setValue("red").setKey("opt-red").setWeight(5000).setId("r")) .addItems(FeatureOption.newBuilder().setValue("green").setKey("opt-green").setWeight(3000).setId("g")) .addItems(FeatureOption.newBuilder().setValue("blue").setKey("opt-blue").setWeight(2000).setId("b")); builder.setOwner(Owner.newBuilder().setName("Jayne").setUsername("jayne")) .setKey("key1") .setGroup("app1") .setOptions(collectionBuilder) ; try { new FeatureValidator().validateFeatureUpdateThrowing(builder.build()); } catch (ServiceException e) { fail(); } }
@Test public void validateFeatureThrowingBoolOptionUpdateOk() { Feature.Builder builder = Feature.newBuilder(); OptionCollection.Builder collectionBuilder = OptionCollection.newBuilder() .setOption(OptionType.bool) .addItems(FeatureOption.newBuilder().setValue("true").setKey("true").setWeight(5500).setId("a")) .addItems(FeatureOption.newBuilder().setValue("false").setKey("false").setWeight(4500).setId("b")); builder.setOwner(Owner.newBuilder().setName("Jayne").setUsername("jayne")) .setKey("key1") .setGroup("app1") .setOptions(collectionBuilder) ; try { new FeatureValidator().validateFeatureUpdateThrowing(builder.build()); } catch (ServiceException e) { fail(); } }