2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017-2018 Amdocs
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.aai.rest;
23 import static org.junit.Assert.assertTrue;
25 import java.io.PrintWriter;
26 import java.io.StringWriter;
27 import java.lang.reflect.Method;
28 import java.util.List;
31 import org.apache.camel.Exchange;
32 import org.apache.camel.Message;
33 import org.junit.Before;
34 import org.junit.Test;
35 import org.onap.aai.logging.RouterCoreMsgs;
36 import org.onap.aai.restclient.client.Headers;
38 public class RestClientTest {
41 * Test case initialization
43 * @throws Exception the exception
46 public void init() throws Exception {
50 public void validate() throws Exception {
53 RestClientComponent rc = new RestClientComponent();
54 RestClientEndpoint endpoint = new RestClientEndpoint("http://host.com:8443/endpoint", rc);
56 endpoint.setEcompClientCert("client-cert");
57 endpoint.setEcompKeystore("keystore");
58 endpoint.setEcompKeystorePassword("OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10");
59 endpoint.setOp("GET");
61 assertTrue(endpoint.getEcompClientCert().compareTo("client-cert") == 0);
62 assertTrue(endpoint.getEcompKeystore().compareTo("keystore") == 0);
63 assertTrue(endpoint.getEcompKeystorePassword().compareTo("OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10") == 0);
64 assertTrue(endpoint.getOp().compareTo("GET") == 0);
65 assertTrue(endpoint.isSingleton());
67 RestClientProducer producer = (RestClientProducer)endpoint.createProducer();
68 assertTrue(producer != null);
70 Method method = RestClientProducer.class.getDeclaredMethod("populateRestHeaders", Exchange.class);
71 method.setAccessible(true);
73 Exchange exchange = endpoint.createExchange();
74 exchange.setProperty(Exchange.TO_ENDPOINT, "mock://get");
75 Message in = exchange.getIn();
76 in.setHeader(RestClientEndpoint.IN_HEADER_URL, "svc/endpoint");
77 in.setHeader(Headers.FROM_APP_ID, "val1");
78 in.setHeader(Headers.TRANSACTION_ID, "val2");
79 in.setHeader(Headers.RESOURCE_VERSION, "val2");
80 in.setHeader(Headers.ETAG, "val2");
81 in.setHeader(Headers.IF_MATCH, "val2");
82 in.setHeader(Headers.IF_NONE_MATCH, "val2");
83 in.setHeader(Headers.ACCEPT, "val2");
84 in.setHeader("Content-Type", "val2");
86 Map<String, List<String>> headers = (Map<String, List<String>>)method.invoke(producer, exchange);
87 assertTrue(headers.size() == 8);
89 producer.process(exchange);
91 System.out.println(RouterCoreMsgs.EVENT_CONSUMER_CREATION_EXCEPTION);
93 catch (Exception ex) {
94 StringWriter writer = new StringWriter();
95 PrintWriter printWriter = new PrintWriter( writer );
96 ex.printStackTrace( printWriter );
98 System.out.println(writer.toString());