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.apache.camel.impl.DefaultMessage;
34 import org.junit.Before;
35 import org.junit.Test;
36 import org.onap.aai.event.TestCamelContext;
37 import org.onap.aai.logging.RouterCoreMsgs;
38 import org.onap.aai.restclient.client.Headers;
40 public class RestClientTest {
43 * Test case initialization
45 * @throws Exception the exception
48 public void init() throws Exception {
52 public void validate() throws Exception {
55 RestClientComponent rc = new RestClientComponent();
56 RestClientEndpoint endpoint = new RestClientEndpoint("http://host.com:8443/endpoint", rc);
58 endpoint.setEcompClientCert("client-cert");
59 endpoint.setEcompKeystore("keystore");
60 endpoint.setEcompKeystorePassword("OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10");
61 endpoint.setOp("GET");
63 assertTrue(endpoint.getEcompClientCert().compareTo("client-cert") == 0);
64 assertTrue(endpoint.getEcompKeystore().compareTo("keystore") == 0);
65 assertTrue(endpoint.getEcompKeystorePassword().compareTo("OBF:1y0q1uvc1uum1uvg1pil1pjl1uuq1uvk1uuu1y10") == 0);
66 assertTrue(endpoint.getOp().compareTo("GET") == 0);
67 assertTrue(endpoint.isSingleton());
69 RestClientProducer producer = (RestClientProducer)endpoint.createProducer();
70 assertTrue(producer != null);
72 Method method = RestClientProducer.class.getDeclaredMethod("populateRestHeaders", Exchange.class);
73 method.setAccessible(true);
75 Exchange exchange = endpoint.createExchange();
76 exchange.setProperty(Exchange.TO_ENDPOINT, "mock://get");
77 DefaultMessage in = (DefaultMessage)exchange.getIn();
78 in.setCamelContext(new TestCamelContext());
80 in.setHeader(RestClientEndpoint.IN_HEADER_URL, "svc/endpoint");
81 in.setHeader(Headers.FROM_APP_ID, "val1");
82 in.setHeader(Headers.TRANSACTION_ID, "val2");
83 in.setHeader(Headers.RESOURCE_VERSION, "val2");
84 in.setHeader(Headers.ETAG, "val2");
85 in.setHeader(Headers.IF_MATCH, "val2");
86 in.setHeader(Headers.IF_NONE_MATCH, "val2");
87 in.setHeader(Headers.ACCEPT, "val2");
88 in.setHeader("Content-Type", "val2");
90 Map<String, List<String>> headers = (Map<String, List<String>>)method.invoke(producer, exchange);
91 assertTrue(headers.size() == 8);
93 producer.process(exchange);
95 System.out.println(RouterCoreMsgs.EVENT_CONSUMER_CREATION_EXCEPTION);
97 catch (Exception ex) {
98 StringWriter writer = new StringWriter();
99 PrintWriter printWriter = new PrintWriter( writer );
100 ex.printStackTrace( printWriter );
102 System.out.println(writer.toString());