forked from keycloak/keycloak
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: using stable ordering for deprecated metadata
closes: keycloak#34858 Signed-off-by: Steve Hawkins <[email protected]> (cherry picked from commit 245498c)
- Loading branch information
Showing
6 changed files
with
54 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,32 +17,36 @@ | |
|
||
package org.keycloak.config; | ||
|
||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.LinkedHashSet; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
/** | ||
* @author Vaclav Muzikar <[email protected]> | ||
*/ | ||
public class DeprecatedMetadata { | ||
private final Set<String> newOptionsKeys; | ||
private final List<String> newOptionsKeys; | ||
private final String note; | ||
private final Set<String> deprecatedValues; | ||
|
||
private DeprecatedMetadata(Set<String> newOptionsKeys, String note, Set<String> deprecatedValues) { | ||
this.newOptionsKeys = newOptionsKeys == null ? Collections.emptySet() : Collections.unmodifiableSet(newOptionsKeys); | ||
private DeprecatedMetadata(List<String> newOptionsKeys, String note, Set<String> deprecatedValues) { | ||
this.newOptionsKeys = newOptionsKeys; | ||
this.note = note; | ||
this.deprecatedValues = deprecatedValues == null ? Collections.emptySet() : Collections.unmodifiableSet(deprecatedValues); | ||
this.deprecatedValues = deprecatedValues; | ||
} | ||
|
||
public static DeprecatedMetadata deprecateOption(String note, Set<String> newOptionsKeys) { | ||
return new DeprecatedMetadata(newOptionsKeys, note, null); | ||
public static DeprecatedMetadata deprecateOption(String note, String... newOptionsKeys) { | ||
return new DeprecatedMetadata(Arrays.asList(newOptionsKeys), note, Set.of()); | ||
} | ||
|
||
public static DeprecatedMetadata deprecateValues(Set<String> values, String note) { | ||
return new DeprecatedMetadata(null, note, values); | ||
public static DeprecatedMetadata deprecateValues(String note, String... values) { | ||
return new DeprecatedMetadata(Collections.emptyList(), note, | ||
Collections.unmodifiableSet(new LinkedHashSet<String>(Arrays.asList(values)))); | ||
} | ||
|
||
public Set<String> getNewOptionsKeys() { | ||
public List<String> getNewOptionsKeys() { | ||
return newOptionsKeys; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
quarkus/runtime/src/test/java/org/keycloak/config/OptionBuilderTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/* | ||
* Copyright 2024 Red Hat, Inc. and/or its affiliates | ||
* and other contributors as indicated by the @author tags. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.keycloak.config; | ||
|
||
import static org.junit.Assert.assertArrayEquals; | ||
|
||
import org.junit.Test; | ||
|
||
public class OptionBuilderTest { | ||
|
||
@Test | ||
public void testDeprecatedOptionOrdering() { | ||
String[] values = new String[] {"a", "d", "b", "1"}; | ||
var option = new OptionBuilder<>("key", String.class).deprecatedValues("These are deprecated", values).build(); | ||
assertArrayEquals(option.getDeprecatedMetadata().get().getDeprecatedValues().toArray(String[]::new), values); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters