@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); }
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"); } } }
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"); } } } }
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"); } } }  }
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); }
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);  }