Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generated builders service discovery honoring #8648

Merged
merged 1 commit into from
Apr 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,8 @@ private static void fromInstanceMethod(InnerClass.Builder builder, TypeContext t
Method.Builder methodBuilder = Method.builder()
.name("from")
.returnType(TypeArgument.create("BUILDER"))
.description("Update this builder from an existing prototype instance.")
.description("Update this builder from an existing prototype instance. "
+ "This method disables automatic service discovery.")
.addParameter(param -> param.name("prototype")
.type(prototype)
.description("existing prototype to update this builder from"))
Expand Down Expand Up @@ -383,6 +384,9 @@ private static void fromInstanceMethod(InnerClass.Builder builder, TypeContext t
methodBuilder.addContentLine("());");
}
}
if (property.configuredOption().provider()) {
methodBuilder.addContentLine(property.typeHandler().name() + "DiscoverServices = false;");
}
}
methodBuilder.addContentLine("return self();");
builder.addMethod(methodBuilder);
Expand Down Expand Up @@ -457,7 +461,10 @@ private static void fromBuilderMethod(InnerClass.Builder classBuilder,
methodBuilder.addContentLine(setterName + "(builder." + getterName + "());");
}
}

if (property.configuredOption().provider()) {
methodBuilder.addContent(property.name() + "DiscoverServices");
methodBuilder.addContentLine(" = builder." + property.name() + "DiscoverServices;");
}
}
methodBuilder.addContentLine("return self();");
classBuilder.addMethod(methodBuilder);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2023 Oracle and/or its affiliates.
* Copyright (c) 2023, 2024 Oracle and/or its affiliates.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -123,4 +123,50 @@ Single value list (when not using discovery). When discovery is used, all in ser
assertThat(value.listNotDiscover(), hasSize(1));
assertThat(services.get(0).prop(), is("config2"));
}

@Test
void testDisabledDiscoveryOnTheCopy() {
SomeProvider.SomeService someService = new DummyService();
WithProvider value = WithProvider.builder()
.listDiscoverDiscoverServices(false)
.oneNotDiscover(someService) //This needs to be set, otherwise validation fails
.build();
assertThat(value.listDiscover(), is(List.of()));

WithProvider copy = WithProvider.builder()
.from(value)
.build();
assertThat(copy.listDiscover(), is(List.of()));
}

@Test
void testDisabledDiscoveryOnTheCopiedBuilder() {
SomeProvider.SomeService someService = new DummyService();
WithProvider.Builder value = WithProvider.builder()
.listDiscoverDiscoverServices(false)
.oneNotDiscover(someService);

WithProvider copy = WithProvider.builder()
.from(value)
.build();
assertThat(copy.listDiscover(), is(List.of()));
}

private static class DummyService implements SomeProvider.SomeService {
@Override
public String prop() {
return null;
}

@Override
public String name() {
return null;
}

@Override
public String type() {
return null;
}
}

}