File tree Expand file tree Collapse file tree 4 files changed +16
-13
lines changed
main/java/com/michelin/ns4kafka
test/java/com/michelin/ns4kafka/service Expand file tree Collapse file tree 4 files changed +16
-13
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,7 @@ public enum SubjectNameStrategy {
2626 TOPIC_RECORD_NAME ("io.confluent.kafka.serializers.subject.TopicRecordNameStrategy" ),
2727 RECORD_NAME ("io.confluent.kafka.serializers.subject.RecordNameStrategy" );
2828
29+ private final String strategyPrefix = "io.confluent.kafka.serializers.subject" ;
2930 private final String value ;
3031
3132 SubjectNameStrategy (String value ) {
@@ -61,10 +62,14 @@ public String toExpectedFormat() {
6162 * @param strategyRealValue
6263 * @return SubjectNameStrategy enum value from given confluent's strategy value
6364 */
64- public static SubjectNameStrategy getFromConfigValue (final String strategyRealValue ) {
65+ public static SubjectNameStrategy fromConfigValue (final String strategyRealValue ) {
6566 return Arrays .stream (values ())
6667 .filter (s -> s .value .equals (strategyRealValue ))
6768 .findFirst ()
6869 .orElseThrow ();
6970 }
71+
72+ public String toShortName () {
73+ return value .substring (strategyPrefix .length () + 1 );
74+ }
7075}
Original file line number Diff line number Diff line change @@ -740,16 +740,14 @@ public static String invalidSchemaSuffix(String invalidNameValue) {
740740 */
741741 public static String invalidSchemaSubjectName (String subjectName , List <SubjectNameStrategy > strategies ) {
742742 String strategiesString =
743- strategies .stream ().map (SubjectNameStrategy ::toString ).collect (Collectors .joining (", " ));
743+ strategies .stream ().map (SubjectNameStrategy ::toShortName ).collect (Collectors .joining (" or " ));
744744 String formatsString =
745- strategies .stream ().map (SubjectNameStrategy ::toExpectedFormat ).collect (Collectors .joining (", " ));
745+ strategies .stream ().map (SubjectNameStrategy ::toExpectedFormat ).collect (Collectors .joining (" or " ));
746746 return String .format (
747747 INVALID_FIELD ,
748748 subjectName ,
749749 FIELD_NAME ,
750- String .format (
751- "value must follow one of these strategies: %s with format: %s" ,
752- strategiesString , formatsString ));
750+ String .format ("value must follow %s with format %s" , strategiesString , formatsString ));
753751 }
754752
755753 /**
Original file line number Diff line number Diff line change @@ -109,7 +109,7 @@ public List<SubjectNameStrategy> getValidSubjectNameStrategies() {
109109 ResourceValidator .ValidString .in (SubjectNameStrategy .DEFAULT .toString ()));
110110 if (value instanceof ResourceValidator .ValidString validString ) {
111111 return new ArrayList <>(validString .getValidStrings ().stream ()
112- .map (SubjectNameStrategy ::getFromConfigValue )
112+ .map (SubjectNameStrategy ::fromConfigValue )
113113 .toList ());
114114 }
115115 return new ArrayList <>(List .of (SubjectNameStrategy .DEFAULT ));
Original file line number Diff line number Diff line change 3434import com .michelin .ns4kafka .service .client .schema .entities .SchemaCompatibilityCheckResponse ;
3535import com .michelin .ns4kafka .service .client .schema .entities .SchemaCompatibilityResponse ;
3636import com .michelin .ns4kafka .service .client .schema .entities .SchemaResponse ;
37- import com .michelin .ns4kafka .util .FormatErrorUtils ;
3837import com .michelin .ns4kafka .validation .TopicValidator ;
3938import java .util .Arrays ;
4039import java .util .Collections ;
@@ -479,13 +478,14 @@ void shouldNotValidateSchema() {
479478 when (schemaRegistryClient .getSubject (namespace .getMetadata ().getCluster (), "header-value" , "1" ))
480479 .thenReturn (Mono .empty ());
481480
481+ String errorSubjectNameStrategy = "Invalid value \" wrongSubjectName\" for field \" name\" : "
482+ + "value must follow TopicNameStrategy with format {topic}-{key|value}." ;
483+ String errorHeaderValueForReferences = "Invalid value \" header-value\" for field \" references\" : "
484+ + "subject header-value version 1 not found." ;
482485 StepVerifier .create (schemaService .validateSchema (namespace , schema ))
483486 .consumeNextWith (errors -> {
484- assertTrue (errors .contains (FormatErrorUtils .invalidSchemaSubjectName (
485- "wrongSubjectName" ,
486- namespace .getSpec ().getTopicValidator ().getValidSubjectNameStrategies ())));
487- assertTrue (errors .contains ("Invalid value \" header-value\" for field \" references\" : "
488- + "subject header-value version 1 not found." ));
487+ assertTrue (errors .contains (errorSubjectNameStrategy ));
488+ assertTrue (errors .contains (errorHeaderValueForReferences ));
489489 })
490490 .verifyComplete ();
491491 }
You can’t perform that action at this time.
0 commit comments