1 /*******************************************************************************
2 * Copyright 2017 ZTE, Inc. and others.
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5 * in compliance with the License. You may obtain a copy of the License at
7 * http://www.apache.org/licenses/LICENSE-2.0
9 * Unless required by applicable law or agreed to in writing, software distributed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11 * or implied. See the License for the specific language governing permissions and limitations under
13 ******************************************************************************/
17 package org.onap.msb.sdk.httpclient.handler;
19 import static org.junit.Assert.assertEquals;
21 import java.util.List;
23 import org.junit.Before;
24 import org.junit.Test;
25 import org.onap.msb.sdk.httpclient.annotaion.LoadBalance.LBSTYLE;
26 import org.onap.msb.sdk.httpclient.conf.HttpClientConf;
27 import org.onap.msb.sdk.httpclient.convert.jackson.JacksonConverterFactoryBuilder;
28 import org.onap.msb.sdk.httpclient.handler.impl.ConnectionParamsBuilder;
29 import org.onap.msb.sdk.httpclient.handler.impl.ConverterFactoryBuilder;
30 import org.onap.msb.sdk.httpclient.handler.impl.LBBuilder;
31 import org.onap.msb.sdk.httpclient.handler.impl.MetricmanagerBuilder;
32 import org.onap.msb.sdk.httpclient.handler.impl.RetrofitHandlerContextBuilder;
33 import org.onap.msb.sdk.httpclient.handler.impl.ServiceHttpEndPointBeanObjectBuilder;
34 import org.onap.msb.sdk.httpclient.lb.RoundRobinLBStrategy;
36 import com.google.common.collect.Lists;
39 public class ServiceBuilderTest {
41 private List<HandlerContextBuilder> builders = Lists.newArrayList();
42 private HttpClientConf globalHttpClientConf;
45 * @throws java.lang.Exception
48 public void setUp() throws Exception {
51 globalHttpClientConf = new HttpClientConf();
52 RetrofitServiceHandlerContext.setGlobalHttpClientConf(globalHttpClientConf);
58 public void test_buildDefaultHandlerContext() {
61 RetrofitServiceHandlerContext ctx = buildCtx(AnimalServiceClient1.class);
63 assertEquals(RoundRobinLBStrategy.class,ctx.getLbStrategy().getClass());
64 assertEquals(LBSTYLE.CLIENT, ctx.getLbStyle());
65 assertEquals("animals",ctx.getServiceHttpEndPointBeanObject().getServiceName());
66 assertEquals("v1",ctx.getServiceHttpEndPointBeanObject().getServiceVersion());
74 public void test_buildCustomizationHandlerContext() {
77 RetrofitServiceHandlerContext ctx = buildCtx(AnimalServiceClient2.class);
79 assertEquals(RoundRobinLBStrategy.class,ctx.getLbStrategy().getClass());
80 assertEquals(LBSTYLE.MSB, ctx.getLbStyle());
81 assertEquals("animals",ctx.getServiceHttpEndPointBeanObject().getServiceName());
82 assertEquals("v1",ctx.getServiceHttpEndPointBeanObject().getServiceVersion());
83 assertEquals(JacksonConverterFactoryBuilder.class,ctx.getConverterFactoryBuilder().getClass());
84 assertEquals(1000,ctx.getHttpClientConf().getReadTimeout());
85 assertEquals(2000,ctx.getHttpClientConf().getConnectTimeout());
86 assertEquals(3000,ctx.getHttpClientConf().getWriteTimeout());
90 private RetrofitServiceHandlerContext buildCtx(Class<?> retrofitSrvInterfaceClazz){
91 RetrofitServiceHandlerContext ctx = new RetrofitServiceHandlerContext();
92 ctx.setRetrofitSrvInterfaceClazz(retrofitSrvInterfaceClazz);
93 for (HandlerContextBuilder builder : builders) {
101 private void init() {
102 builders.add(new ServiceHttpEndPointBeanObjectBuilder());
103 builders.add(new MetricmanagerBuilder());
104 builders.add(new LBBuilder());
105 builders.add(new ConnectionParamsBuilder());
106 builders.add(new ConverterFactoryBuilder());
107 builders.add(new RetrofitHandlerContextBuilder());