Skip to content

Commit

Permalink
secureCodeBox#121 Extract Proxy Config As Field to Make it Injectable…
Browse files Browse the repository at this point in the history
… in Tests

Signed-off-by: Sven Strittmatter <[email protected]>
  • Loading branch information
Weltraumschaf committed Jul 3, 2024
1 parent 307747c commit e00225a
Showing 1 changed file with 15 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.securecodebox.persistence.defectdojo.exception.TooManyResponsesException;
import io.securecodebox.persistence.defectdojo.http.AuthHeaderFactory;
import io.securecodebox.persistence.defectdojo.http.Foo;
import io.securecodebox.persistence.defectdojo.http.ProxyConfig;
import io.securecodebox.persistence.defectdojo.http.ProxyConfigFactory;
import io.securecodebox.persistence.defectdojo.model.Engagement;
import io.securecodebox.persistence.defectdojo.model.Model;
Expand Down Expand Up @@ -44,21 +45,33 @@
abstract class GenericDefectDojoService<T extends Model> implements DefectDojoService<T> {
private static final long DEFECT_DOJO_OBJET_LIMIT = 100L;
private final ClientConfig clientConfig;
private final ProxyConfig proxyConfig;

protected ObjectMapper objectMapper;
protected ObjectMapper searchStringMapper;

@Getter // TODO: Remove this getter
private final RestTemplate restTemplate;

/**
* Convenience constructor which initializes {@link #proxyConfig}
*
* @param clientConfig not {@code null}
*/
public GenericDefectDojoService(ClientConfig clientConfig) {
this(clientConfig, new ProxyConfigFactory().create());
}

/**
* Dedicated constructor
*
* @param clientConfig not {@code null}
* @param proxyConfig not {@code null}
*/
public GenericDefectDojoService(@NonNull ClientConfig clientConfig) {
public GenericDefectDojoService(@NonNull ClientConfig clientConfig, @NonNull ProxyConfig proxyConfig) {
super();
this.clientConfig = clientConfig;
this.proxyConfig = proxyConfig;

this.objectMapper = new ObjectMapper();
this.objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
Expand Down Expand Up @@ -198,7 +211,7 @@ final URI createBaseUrl() {
*/
private HttpHeaders getDefectDojoAuthorizationHeaders() {
final var factory = new AuthHeaderFactory(clientConfig);
factory.setProxyConfig(new ProxyConfigFactory().create());
factory.setProxyConfig(proxyConfig);
return factory.generateAuthorizationHeaders();
}

Expand Down

0 comments on commit e00225a

Please sign in to comment.