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;
20 import static org.junit.Assert.assertEquals;
21 import static org.junit.Assert.assertFalse;
23 import java.util.HashSet;
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;
35 public class HttpTaskProducerTest {
38 public ExpectedException exception = ExpectedException.none();
41 public void uniquePathExistsForEveryAction() {
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);
51 assertEquals("Paths not unique for some actions", availableActions.length, collectedPaths.size());
55 public void restorePathEqualsRestored() {
56 assertEquals("restored", HttpTaskProducer.getApiPath(ItemAction.RESTORE));
60 public void archivePathEqualsArchived() {
61 assertEquals("archived", HttpTaskProducer.getApiPath(ItemAction.ARCHIVE));
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);
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);
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);
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);
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);
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);
121 public void okWhenProtocolHttps() {
122 HttpConfiguration config = mockConfiguration();
123 config.setCatalogBeProtocol("https");
124 new HttpTaskProducer(config);
128 public void okWhenProtocolHttpsMixedCase() {
129 HttpConfiguration config = mockConfiguration();
130 config.setCatalogBeProtocol("hTTpS");
131 new HttpTaskProducer(config);
135 public void okWhenProtocolHttpMixedCase() {
136 HttpConfiguration config = mockConfiguration();
137 config.setCatalogBeProtocol("HTtp");
138 new HttpTaskProducer(config);
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");