Added oparent to sdc main
[sdc.git] / openecomp-be / api / openecomp-sdc-rest-webapp / item-rest / item-rest-services / src / test / java / org / openecomp / sdcrests / item / rest / services / catalog / notification / http / HttpTaskProducerTest.java
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 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertFalse;
22
23 import java.util.HashSet;
24 import java.util.Set;
25 import org.junit.Rule;
26 import org.junit.Test;
27 import org.junit.rules.ExpectedException;
28 import org.openecomp.sdcrests.item.rest.services.catalog.notification.EntryNotConfiguredException;
29 import org.openecomp.sdcrests.item.types.ItemAction;
30
31 /**
32  * @author evitaliy
33  * @since 26 Nov 2018
34  */
35 public class HttpTaskProducerTest {
36
37     @Rule
38     public ExpectedException exception = ExpectedException.none();
39
40     @Test
41     public void uniquePathExistsForEveryAction() {
42
43         ItemAction[] availableActions = ItemAction.values();
44         Set<String> collectedPaths = new HashSet<>(availableActions.length);
45         for (ItemAction action : availableActions) {
46             String path = HttpTaskProducer.getApiPath(action);
47             assertFalse("Path empty for action '" + action.name() + "'", path == null || path.isEmpty());
48             collectedPaths.add(path);
49         }
50
51         assertEquals("Paths not unique for some actions", availableActions.length, collectedPaths.size());
52     }
53
54     @Test
55     public void restorePathEqualsRestored() {
56         assertEquals("restored", HttpTaskProducer.getApiPath(ItemAction.RESTORE));
57     }
58
59     @Test
60     public void archivePathEqualsArchived() {
61         assertEquals("archived", HttpTaskProducer.getApiPath(ItemAction.ARCHIVE));
62     }
63
64     @Test
65     public void errorWhenProtocolNotDefined() {
66         HttpConfiguration config = mockConfiguration();
67         config.setCatalogBeProtocol(null);
68         exception.expect(EntryNotConfiguredException.class);
69         exception.expectMessage(containsString("Protocol"));
70         new HttpTaskProducer(config);
71     }
72
73     @Test
74     public void errorWhenFqdnNotDefined() {
75         HttpConfiguration config = mockConfiguration();
76         config.setCatalogBeFqdn(null);
77         exception.expect(EntryNotConfiguredException.class);
78         exception.expectMessage(containsString("Catalog host"));
79         new HttpTaskProducer(config);
80     }
81
82     @Test
83     public void errorWhenNotificationUrlNotDefined() {
84         HttpConfiguration config = mockConfiguration();
85         config.setCatalogNotificationUrl(null);
86         exception.expect(EntryNotConfiguredException.class);
87         exception.expectMessage(containsString("Notification URL"));
88         new HttpTaskProducer(config);
89     }
90
91     @Test
92     public void errorWhenUnknownProtocol() {
93         HttpConfiguration config = mockConfiguration();
94         config.setCatalogBeProtocol("invented-protocol");
95         exception.expect(IllegalArgumentException.class);
96         exception.expectMessage(containsString("Unsupported protocol"));
97         new HttpTaskProducer(config);
98     }
99
100     @Test
101     public void errorWhenHttpUsedButHttpPortUndefined() {
102         HttpConfiguration config = mockConfiguration();
103         config.setCatalogBeProtocol("http");
104         config.setCatalogBeHttpPort(null);
105         exception.expect(EntryNotConfiguredException.class);
106         exception.expectMessage(containsString("HTTP port"));
107         new HttpTaskProducer(config);
108     }
109
110     @Test
111     public void errorWhenSslUsedButHttpsPortUndefined() {
112         HttpConfiguration config = mockConfiguration();
113         config.setCatalogBeProtocol("https");
114         config.setCatalogBeSslPort(null);
115         exception.expect(EntryNotConfiguredException.class);
116         exception.expectMessage(containsString("SSL port"));
117         new HttpTaskProducer(config);
118     }
119
120     @Test
121     public void okWhenProtocolHttps() {
122         HttpConfiguration config = mockConfiguration();
123         config.setCatalogBeProtocol("https");
124         new HttpTaskProducer(config);
125     }
126
127     @Test
128     public void okWhenProtocolHttpsMixedCase() {
129         HttpConfiguration config = mockConfiguration();
130         config.setCatalogBeProtocol("hTTpS");
131         new HttpTaskProducer(config);
132     }
133
134     @Test
135     public void okWhenProtocolHttpMixedCase() {
136         HttpConfiguration config = mockConfiguration();
137         config.setCatalogBeProtocol("HTtp");
138         new HttpTaskProducer(config);
139     }
140
141     private HttpConfiguration mockConfiguration() {
142         HttpConfiguration config = new HttpConfiguration();
143         config.setCatalogBeFqdn("fqdn");
144         config.setCatalogBeHttpPort("http-port");
145         config.setCatalogBeProtocol("http");
146         config.setCatalogBeSslPort("ssl-port");
147         config.setCatalogNotificationUrl("url");
148         return config;
149     }
150 }