2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights
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============================================
20 * ===================================================================
21 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
24 package org.onap.clamp.clds.it;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertTrue;
28 import static org.junit.Assert.fail;
30 import java.io.IOException;
32 import javax.ws.rs.BadRequestException;
34 import org.junit.Test;
35 import org.junit.runner.RunWith;
36 import org.onap.clamp.clds.AbstractItCase;
37 import org.onap.clamp.clds.client.DcaeHttpConnectionManager;
38 import org.springframework.beans.factory.annotation.Value;
39 import org.springframework.boot.test.context.SpringBootTest;
40 import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
41 import org.springframework.test.context.TestPropertySource;
42 import org.springframework.test.context.junit4.SpringRunner;
45 * Test HTTP and HTTPS settings + redirection of HTTP to HTTPS.
47 @RunWith(SpringRunner.class)
48 @SpringBootTest(webEnvironment = WebEnvironment.DEFINED_PORT)
49 @TestPropertySource(locations = "classpath:https/https-test.properties")
50 public class DcaeHttpConnectionManagerItCase extends AbstractItCase {
51 @Value("${server.port}")
52 private String httpsPort;
53 @Value("${server.http-to-https-redirection.port}")
54 private String httpPort;
57 public void testHttpGet() throws Exception {
58 String response = DcaeHttpConnectionManager
59 .doDcaeHttpQuery("http://localhost:" + this.httpPort + "/designer/index.html", "GET", null, null, true);
60 assertNotNull(response);
61 // Should be a redirection so 302, so empty
62 assertTrue(response.isEmpty());
66 public void testHttpsGet() throws Exception {
67 String response = DcaeHttpConnectionManager.doDcaeHttpQuery(
68 "https://localhost:" + this.httpsPort + "/designer/index.html", "GET", null, null, true);
69 assertNotNull(response);
70 // Should contain something
71 assertTrue(!response.isEmpty());
74 @Test(expected = BadRequestException.class)
75 public void testHttpsGet404() throws IOException {
76 DcaeHttpConnectionManager.doDcaeHttpQuery("https://localhost:" + this.httpsPort + "/designer/index1.html",
77 "GET", null, null, true);
78 fail("Should have raised an BadRequestException exception");
81 @Test(expected = BadRequestException.class)
82 public void testHttpsPost404() throws IOException {
83 DcaeHttpConnectionManager.doDcaeHttpQuery("https://localhost:" + this.httpsPort + "/designer/index1.html",
84 "POST", "", "application/json", true);
85 fail("Should have raised an BadRequestException exception");
88 @Test(expected = IOException.class)
89 public void testHttpException() throws IOException {
90 DcaeHttpConnectionManager.doDcaeHttpQuery("http://localhost:" + this.httpsPort + "/designer/index.html", "GET",
92 fail("Should have raised an IOException exception");