3c12b37e6d2dbd12d6994e7cdc9e5c1892e69220
[sdc.git] /
1 /*
2  * Copyright © 2016-2018 European Support Limited
3  *
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
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16
17 package org.openecomp.sdcrests.item.rest.services.catalog.notification.http;
18
19 import static org.hamcrest.CoreMatchers.containsString;
20
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;
25
26 /**
27  * @author evitaliy
28  * @since 26 Nov 2018
29  */
30 public class HttpTaskProducerTest {
31
32     @Rule
33     public ExpectedException exception = ExpectedException.none();
34
35     @Test
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);
42     }
43
44     @Test
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);
51     }
52
53     @Test
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);
60     }
61
62     @Test
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);
69     }
70
71     @Test
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);
79     }
80
81     @Test
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);
89     }
90
91     @Test
92     public void okWhenProtocolHttps() {
93         HttpConfiguration config = mockConfiguration();
94         config.setCatalogBeProtocol("https");
95         new HttpTaskProducer(config);
96     }
97
98     @Test
99     public void okWhenProtocolHttpsMixedCase() {
100         HttpConfiguration config = mockConfiguration();
101         config.setCatalogBeProtocol("hTTpS");
102         new HttpTaskProducer(config);
103     }
104
105     @Test
106     public void okWhenProtocolHttpMixedCase() {
107         HttpConfiguration config = mockConfiguration();
108         config.setCatalogBeProtocol("HTtp");
109         new HttpTaskProducer(config);
110     }
111
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");
119         return config;
120     }
121 }