2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
23 package org.onap.aai.rest;
25 import static org.junit.Assert.assertTrue;
27 import java.io.PrintWriter;
28 import java.io.StringWriter;
29 import java.lang.reflect.Method;
30 import java.util.List;
33 import org.apache.camel.Exchange;
34 import org.apache.camel.Message;
35 import org.junit.Before;
36 import org.junit.Test;
37 import org.onap.aai.restclient.client.Headers;
39 public class RestClientTest {
42 * Test case initialization
44 * @throws Exception the exception
47 public void init() throws Exception {
51 public void validate() throws Exception {
54 RestClientComponent rc = new RestClientComponent();
55 RestClientEndpoint endpoint = new RestClientEndpoint("http://host.com:8443/endpoint", rc);
57 endpoint.setEcompClientCert("client-cert");
58 endpoint.setEcompKeystore("keystore");
59 endpoint.setEcompKeystorePassword("pwd");
60 endpoint.setOp("operation");
62 assertTrue(endpoint.getEcompClientCert().compareTo("client-cert") == 0);
63 assertTrue(endpoint.getEcompKeystore().compareTo("keystore") == 0);
64 assertTrue(endpoint.getEcompKeystorePassword().compareTo("pwd") == 0);
65 assertTrue(endpoint.getOp().compareTo("operation") == 0);
66 assertTrue(endpoint.isSingleton());
68 RestClientProducer producer = (RestClientProducer)endpoint.createProducer();
69 assertTrue(producer != null);
71 Method method = RestClientProducer.class.getDeclaredMethod("populateRestHeaders", Exchange.class);
72 method.setAccessible(true);
74 Exchange exchange = endpoint.createExchange();
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 catch (Exception ex) {
90 StringWriter writer = new StringWriter();
91 PrintWriter printWriter = new PrintWriter( writer );
92 ex.printStackTrace( printWriter );
94 System.out.println(writer.toString());