FeatureValidator { void validateFeatureRegistrationThrowing(Feature feature) throws ServiceException { validateOwnerThrowing(feature); validateKeysThrowing(feature); validateOptionsThrowing(feature.getOptions()); if (feature.hasNamespaces()) { validateNamespaceFeaturesThrowing(feature); } }    }
@Test public void validateFeatureThrowingFlagOptionOk() { Feature.Builder builder = Feature.newBuilder(); builder.setOwner(Owner.newBuilder().setName("Jayne").setUsername("jayne")) .setKey("key1") .setGroup("app1"); try { new FeatureValidator().validateFeatureRegistrationThrowing(builder.build()); } catch (ServiceException e) { fail(); } }
@Test public void validateFeatureThrowingStringOptionOk() { 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)) .addItems(FeatureOption.newBuilder().setValue("green").setKey("opt-green").setWeight(3000)) .addItems(FeatureOption.newBuilder().setValue("blue").setKey("opt-blue").setWeight(2000)); builder.setOwner(Owner.newBuilder().setName("Jayne").setUsername("jayne")) .setKey("key1") .setGroup("app1") .setOptions(collectionBuilder); try { new FeatureValidator().validateFeatureRegistrationThrowing(builder.build()); } catch (ServiceException e) { fail(); } }
@Test public void validateFeatureThrowingBoolOptionOk() { Feature.Builder builder = Feature.newBuilder(); OptionCollection.Builder collectionBuilder = OptionCollection.newBuilder() .setOption(OptionType.bool) .addItems(FeatureOption.newBuilder().setValue("true").setKey("true").setWeight(5500)) .addItems(FeatureOption.newBuilder().setValue("false").setKey("false").setWeight(4500)); builder.setOwner(Owner.newBuilder().setName("Jayne").setUsername("jayne")) .setKey("key1") .setGroup("app1") .setOptions(collectionBuilder) ; try { new FeatureValidator().validateFeatureRegistrationThrowing(builder.build()); } catch (ServiceException e) { fail(); } }