2 * Copyright © 2016-2018 European Support Limited
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package org.openecomp.sdcrests.item.rest.services.catalog.notification.http;
19 import static org.hamcrest.CoreMatchers.containsString;
21 import org.junit.Rule;
22 import org.junit.Test;
23 import org.junit.rules.ExpectedException;
24 import org.openecomp.sdcrests.item.rest.services.catalog.notification.EntryNotConfiguredException;
30 public class HttpTaskProducerTest {
33 public ExpectedException exception = ExpectedException.none();
36 public void errorWhenProtocolNotDefined() {
37 HttpConfiguration config = mockConfiguration();
38 config.setCatalogBeProtocol(null);
39 exception.expect(EntryNotConfiguredException.class);
40 exception.expectMessage(containsString("Protocol"));
41 new HttpTaskProducer(config);
45 public void errorWhenFqdnNotDefined() {
46 HttpConfiguration config = mockConfiguration();
47 config.setCatalogBeFqdn(null);
48 exception.expect(EntryNotConfiguredException.class);
49 exception.expectMessage(containsString("Catalog host"));
50 new HttpTaskProducer(config);
54 public void errorWhenNotificationUrlNotDefined() {
55 HttpConfiguration config = mockConfiguration();
56 config.setCatalogNotificationUrl(null);
57 exception.expect(EntryNotConfiguredException.class);
58 exception.expectMessage(containsString("Notification URL"));
59 new HttpTaskProducer(config);
63 public void errorWhenUnknownProtocol() {
64 HttpConfiguration config = mockConfiguration();
65 config.setCatalogBeProtocol("invented-protocol");
66 exception.expect(IllegalArgumentException.class);
67 exception.expectMessage(containsString("Unsupported protocol"));
68 new HttpTaskProducer(config);
72 public void errorWhenHttpUsedButHttpPortUndefined() {
73 HttpConfiguration config = mockConfiguration();
74 config.setCatalogBeProtocol("http");
75 config.setCatalogBeHttpPort(null);
76 exception.expect(EntryNotConfiguredException.class);
77 exception.expectMessage(containsString("HTTP port"));
78 new HttpTaskProducer(config);
82 public void errorWhenSslUsedButHttpsPortUndefined() {
83 HttpConfiguration config = mockConfiguration();
84 config.setCatalogBeProtocol("https");
85 config.setCatalogBeSslPort(null);
86 exception.expect(EntryNotConfiguredException.class);
87 exception.expectMessage(containsString("SSL port"));
88 new HttpTaskProducer(config);
92 public void okWhenProtocolHttps() {
93 HttpConfiguration config = mockConfiguration();
94 config.setCatalogBeProtocol("https");
95 new HttpTaskProducer(config);
99 public void okWhenProtocolHttpsMixedCase() {
100 HttpConfiguration config = mockConfiguration();
101 config.setCatalogBeProtocol("hTTpS");
102 new HttpTaskProducer(config);
106 public void okWhenProtocolHttpMixedCase() {
107 HttpConfiguration config = mockConfiguration();
108 config.setCatalogBeProtocol("HTtp");
109 new HttpTaskProducer(config);
112 private HttpConfiguration mockConfiguration() {
113 HttpConfiguration config = new HttpConfiguration();
114 config.setCatalogBeFqdn("fqdn");
115 config.setCatalogBeHttpPort("http-port");
116 config.setCatalogBeProtocol("http");
117 config.setCatalogBeSslPort("ssl-port");
118 config.setCatalogNotificationUrl("url");