FeatureSetValidator { public static void validateSpec(FeatureSet featureSet) { if (featureSet.getSpec().getProject().isEmpty()) { throw new IllegalArgumentException("Project name must be provided"); } if (featureSet.getSpec().getName().isEmpty()) { throw new IllegalArgumentException("Feature set name must be provided"); } if (featureSet.getSpec().getLabelsMap().containsKey("")) { throw new IllegalArgumentException("Feature set label keys must not be empty"); } checkValidCharacters(featureSet.getSpec().getProject(), "project"); checkValidCharacters(featureSet.getSpec().getName(), "featureset"); checkUniqueColumns( featureSet.getSpec().getEntitiesList(), featureSet.getSpec().getFeaturesList()); checkReservedColumns(featureSet.getSpec().getFeaturesList()); for (EntitySpec entitySpec : featureSet.getSpec().getEntitiesList()) { checkValidCharacters(entitySpec.getName(), "entity"); } for (FeatureSpec featureSpec : featureSet.getSpec().getFeaturesList()) { checkValidCharacters(featureSpec.getName(), "feature"); if (featureSpec.getLabelsMap().containsKey("")) { throw new IllegalArgumentException("Feature label keys must not be empty"); } } }  static void validateSpec(FeatureSet featureSet);  }
@Test public void shouldThrowExceptionForFeatureLabelsWithAnEmptyKey() { Map<String, String> featureLabels = new HashMap<>() { { put("", "empty_key"); } }; List<FeatureSetProto.FeatureSpec> featureSpecs = new ArrayList<>(); featureSpecs.add( FeatureSetProto.FeatureSpec.newBuilder() .setName("feature1") .setValueType(ValueProto.ValueType.Enum.INT64) .putAllLabels(featureLabels) .build()); FeatureSetProto.FeatureSetSpec featureSetSpec = FeatureSetProto.FeatureSetSpec.newBuilder() .setProject("project1") .setName("featureSetWithConstraints") .addAllFeatures(featureSpecs) .build(); FeatureSetProto.FeatureSet featureSet = FeatureSetProto.FeatureSet.newBuilder().setSpec(featureSetSpec).build(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Feature label keys must not be empty"); FeatureSetValidator.validateSpec(featureSet); }
@Test public void shouldThrowExceptionForFeatureSetLabelsWithAnEmptyKey() { Map<String, String> featureSetLabels = new HashMap<>() { { put("", "empty_key"); } }; FeatureSetProto.FeatureSetSpec featureSetSpec = FeatureSetProto.FeatureSetSpec.newBuilder() .setProject("project1") .setName("featureSetWithConstraints") .putAllLabels(featureSetLabels) .build(); FeatureSetProto.FeatureSet featureSet = FeatureSetProto.FeatureSet.newBuilder().setSpec(featureSetSpec).build(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("Feature set label keys must not be empty"); FeatureSetValidator.validateSpec(featureSet); }