Skip to content

Commit

Permalink
refactor(retrofit2): Convert Retrofit2TestConfig to java
Browse files Browse the repository at this point in the history
  • Loading branch information
kirangodishala committed Jan 2, 2025
1 parent 68f095f commit e30597f
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 91 deletions.
1 change: 1 addition & 0 deletions echo-test/echo-test.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,5 @@ dependencies {
implementation "io.spinnaker.kork:kork-web"
implementation "io.spinnaker.kork:kork-retrofit"
implementation "com.squareup.retrofit2:converter-jackson"
implementation "javax.inject:javax.inject:1"
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 OpsMx, Inc.
*
* 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 com.netflix.spinnaker.echo.test.config;

import okhttp3.logging.HttpLoggingInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Retrofit2BasicLogTestConfig {

@Bean
public HttpLoggingInterceptor.Level retrofit2LogLevel() {
return HttpLoggingInterceptor.Level.BASIC;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 OpsMx, Inc.
*
* 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 com.netflix.spinnaker.echo.test.config;

import okhttp3.logging.HttpLoggingInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Retrofit2HeadersLogTestConfig {

@Bean
public HttpLoggingInterceptor.Level retrofit2LogLevel() {
return HttpLoggingInterceptor.Level.HEADERS;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* Copyright 2024 OpsMx, Inc.
*
* 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 com.netflix.spinnaker.echo.test.config;

import okhttp3.logging.HttpLoggingInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Retrofit2NoneLogTestConfig {

@Bean
public HttpLoggingInterceptor.Level retrofit2LogLevel() {
return HttpLoggingInterceptor.Level.NONE;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* Copyright 2024 OpsMx, Inc.
*
* 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 com.netflix.spinnaker.echo.test.config;

import com.netflix.spectator.api.NoopRegistry;
import com.netflix.spectator.api.Registry;
import com.netflix.spinnaker.config.OkHttp3ClientConfiguration;
import com.netflix.spinnaker.config.OkHttpMetricsInterceptorProperties;
import com.netflix.spinnaker.okhttp.OkHttp3MetricsInterceptor;
import com.netflix.spinnaker.okhttp.OkHttpClientConfigurationProperties;
import com.netflix.spinnaker.okhttp.SpinnakerRequestHeaderInterceptor;
import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import org.springframework.beans.factory.ObjectFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class Retrofit2TestConfig {

@Autowired private ObjectFactory<OkHttpClient.Builder> httpClientBuilderFactory;

@Bean
public OkHttpClientConfigurationProperties okHttpClientConfigurationProperties() {
return new OkHttpClientConfigurationProperties();
}

@Bean
public OkHttpMetricsInterceptorProperties okHttpMetricsInterceptorProperties() {
return new OkHttpMetricsInterceptorProperties();
}

@Bean
public Registry registry() {
return new NoopRegistry();
}

@Bean
public OkHttp3MetricsInterceptor okHttp3MetricsInterceptor(
Registry registry, OkHttpMetricsInterceptorProperties okHttpMetricsInterceptorProperties) {
return new OkHttp3MetricsInterceptor(() -> registry, okHttpMetricsInterceptorProperties);
}

@Bean
public SpinnakerRequestHeaderInterceptor getSpinnakerRequestHeaderInterceptor() {
return new SpinnakerRequestHeaderInterceptor(false);
}

@Bean
public OkHttp3ClientConfiguration okHttp3ClientConfiguration(
OkHttpClientConfigurationProperties okHttpClientConfigurationProperties,
OkHttp3MetricsInterceptor okHttp3MetricsInterceptor,
HttpLoggingInterceptor.Level retrofit2LogLevel,
SpinnakerRequestHeaderInterceptor spinnakerRequestHeaderInterceptor) {
return new OkHttp3ClientConfiguration(
okHttpClientConfigurationProperties,
okHttp3MetricsInterceptor,
retrofit2LogLevel,
spinnakerRequestHeaderInterceptor,
httpClientBuilderFactory);
}
}

0 comments on commit e30597f

Please sign in to comment.