Fix java check style warning
[msb/apigateway.git] / apiroute / apiroute-service / src / test / java / org / onap / msb / apiroute / wrapper / consulextend / util / HttpTest.java
1 /*******************************************************************************
2  * Copyright 2016-2017 ZTE, Inc. and others.
3  * 
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
6  * 
7  * http://www.apache.org/licenses/LICENSE-2.0
8  * 
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
12  * the License.
13  ******************************************************************************/
14 package org.onap.msb.apiroute.wrapper.consulextend.util;
15
16 import java.io.InputStream;
17 import java.math.BigInteger;
18 import java.util.List;
19 import java.util.Map;
20
21 import org.apache.http.HttpEntity;
22 import org.apache.http.ProtocolVersion;
23 import org.apache.http.StatusLine;
24 import org.apache.http.entity.BasicHttpEntity;
25 import org.apache.http.message.BasicHttpResponse;
26 import org.apache.http.message.BasicStatusLine;
27 import org.junit.Before;
28 import org.junit.Test;
29 import org.slf4j.Logger;
30 import org.slf4j.LoggerFactory;
31
32 import com.fasterxml.jackson.core.type.TypeReference;
33 import com.orbitz.consul.option.ConsistencyMode;
34 import com.orbitz.consul.option.ImmutableCatalogOptions;
35 import com.orbitz.consul.option.ImmutableQueryOptions;
36 import com.orbitz.consul.option.QueryOptions;
37
38 public class HttpTest {
39     private static final Logger LOGGER = LoggerFactory.getLogger(HttpTest.class);
40
41     @Before
42     public void init() {
43
44     }
45
46     @Test
47     public void testoptionsFrom() {
48         ImmutableCatalogOptions catalogs = ImmutableCatalogOptions.builder().build();
49         catalogs = catalogs.withDatacenter("datacenter").withTag("tag");
50
51         BigInteger index = new BigInteger("1");
52         ImmutableQueryOptions querys = QueryOptions.blockSeconds(10, index).build();
53         querys = querys.withConsistencyMode(ConsistencyMode.STALE).withDatacenter("datacenter").withNear("near")
54                         .withToken("taoken");
55         String url = Http.optionsFrom(catalogs, querys);
56         LOGGER.info(url);
57     }
58
59     @Test
60     public void testconsulResponse() {
61
62         TypeReference<Map<String, List<String>>> TYPE_SERVICES_MAP = new TypeReference<Map<String, List<String>>>() {};
63
64         ProtocolVersion version = new ProtocolVersion("HTTP", 1, 1);
65         StatusLine status = new BasicStatusLine(version, 200, "ok");
66         BasicHttpResponse response = new BasicHttpResponse(status);
67
68         response.setHeader("X-Consul-Index", "1");
69         response.setHeader("X-Consul-Lastcontact", "1");
70         response.setHeader("X-Consul-Knownleader", "true");
71
72         BasicHttpEntity entity = new BasicHttpEntity();
73         InputStream content = HttpTest.class.getResourceAsStream("serviceslist.json");
74         entity.setContent(content);
75         response.setEntity(entity);
76
77         Http.consulResponse(TYPE_SERVICES_MAP, response);
78
79         TypeReference<String> TYPE_SERVICES_MAP_STRING = new TypeReference<String>() {};
80         InputStream content1 = HttpTest.class.getResourceAsStream("serviceslist.json");
81         entity.setContent(content1);
82
83         Http.consulResponse(TYPE_SERVICES_MAP_STRING, response);
84
85         TypeReference<HttpEntity> TYPE_SERVICES_MAP_ENTITY = new TypeReference<HttpEntity>() {};
86         Http.consulResponse(TYPE_SERVICES_MAP_ENTITY, response);
87     }
88 }