KEYCLOAK-7977 Release failing due the NPE during swagger2markup-maven-plugin execution

This commit is contained in:
mposolda 2018-07-31 18:26:50 +02:00 committed by Marek Posolda
parent f32e258a18
commit a2afe7c205
3 changed files with 36 additions and 9 deletions

View file

@ -182,6 +182,7 @@ public class ResourceRepresentation {
} }
@Deprecated @Deprecated
@JsonSetter("uri")
public void setUri(String uri) { public void setUri(String uri) {
if (uri != null && !"".equalsIgnoreCase(uri.trim())) { if (uri != null && !"".equalsIgnoreCase(uri.trim())) {
this.uris = Collections.singleton(uri); this.uris = Collections.singleton(uri);
@ -201,15 +202,6 @@ public class ResourceRepresentation {
} }
} }
@JsonProperty("uri")
public void addUri(String uri) {
if (this.uris == null) {
this.uris = new HashSet<>();
}
uris.add(uri);
}
public void setType(String type) { public void setType(String type) {
if (type != null && !"".equalsIgnoreCase(type.trim())) { if (type != null && !"".equalsIgnoreCase(type.trim())) {
this.type = type; this.type = type;

View file

@ -22,11 +22,13 @@ import org.junit.Test;
import org.keycloak.representations.IDToken; import org.keycloak.representations.IDToken;
import org.keycloak.representations.JsonWebToken; import org.keycloak.representations.JsonWebToken;
import org.keycloak.representations.adapters.config.AdapterConfig; import org.keycloak.representations.adapters.config.AdapterConfig;
import org.keycloak.representations.idm.authorization.ResourceRepresentation;
import org.keycloak.representations.oidc.OIDCClientRepresentation; import org.keycloak.representations.oidc.OIDCClientRepresentation;
import org.keycloak.util.JsonSerialization; import org.keycloak.util.JsonSerialization;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.regex.Matcher; import java.util.regex.Matcher;
@ -153,4 +155,35 @@ public class JsonParserTest {
Assert.assertNotNull(clientRep.getJwks()); Assert.assertNotNull(clientRep.getJwks());
} }
@Test
public void testResourceRepresentationParsing() throws Exception {
Map<String, Object> resource = parseResourceRepresentation("{ \"_id\": \"123\", \"name\": \"foo\" }");
Assert.assertFalse(resource.containsKey("uri"));
Assert.assertFalse(resource.containsKey("uris"));
resource = parseResourceRepresentation("{ \"_id\": \"123\", \"name\": \"foo\", \"uris\": [ \"uri1\", \"uri2\" ] }");
Assert.assertFalse(resource.containsKey("uri"));
Assert.assertTrue(resource.containsKey("uris"));
Collection<String> uris = (Collection) resource.get("uris");
Assert.assertEquals(2, uris.size());
Assert.assertTrue(uris.contains("uri1"));
Assert.assertTrue(uris.contains("uri2"));
// Backwards compatibility (using old property "uri")
resource = parseResourceRepresentation("{ \"_id\": \"123\", \"name\": \"foo\", \"uri\": \"uri1\" }");
Assert.assertFalse(resource.containsKey("uri"));
Assert.assertTrue(resource.containsKey("uris"));
uris = (Collection) resource.get("uris");
Assert.assertEquals(1, uris.size());
Assert.assertTrue(uris.contains("uri1"));
}
private Map<String, Object> parseResourceRepresentation(String resourceJson) throws Exception {
ResourceRepresentation rep = JsonSerialization.readValue(resourceJson, ResourceRepresentation.class);
String repp = JsonSerialization.writeValueAsString(rep);
return JsonSerialization.readValue(repp, Map.class);
}
} }

View file

@ -60,6 +60,8 @@ fi
if [ $1 == "unit" ]; then if [ $1 == "unit" ]; then
mvn -B test -DskipTestsuite mvn -B test -DskipTestsuite
# Generate documentation to catch potential issues earlier than during the release
mvn test -B -nsu -f services -Pjboss-release
fi fi
if [ $1 == "server-group1" ]; then if [ $1 == "server-group1" ]; then