2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.brmsgw.test;
23 import static org.junit.Assert.assertNotNull;
25 import java.io.FileInputStream;
26 import java.io.FileOutputStream;
27 import java.io.IOException;
28 import java.util.LinkedList;
29 import java.util.List;
30 import java.util.Properties;
32 import org.junit.Test;
33 import org.onap.policy.api.PolicyException;
34 import org.onap.policy.brms.api.BrmsHandler;
36 public class BrmsPushTest {
38 private static final String VALID_FILE = "src/test/resources/config.properties";
39 private static final String INVALID_FILE = "src/test/resources/failure.properties";
41 @Test(expected = PolicyException.class)
42 public void brmsHandlerFailTest() throws PolicyException {
43 new BrmsHandler(null);
46 @Test(expected = PolicyException.class)
47 public void brmsHandlerFailTest1() throws PolicyException {
48 new BrmsHandler("src/test/resources/filenotexists.txt");
51 @Test(expected = PolicyException.class)
52 public void brmsHandlerFailTest2() throws PolicyException {
53 final PropertyChange prop = new PropertyChange();
54 prop.key = "defaultName";
56 final List<PropertyChange> props = new LinkedList<>();
58 setFailureProperties(props);
59 new BrmsHandler(INVALID_FILE);
62 @Test(expected = PolicyException.class)
63 public void brmsHandlerFailTest3() throws PolicyException {
64 PropertyChange prop = new PropertyChange();
65 prop.key = "repositoryID";
67 final List<PropertyChange> props = new LinkedList<>();
69 prop = new PropertyChange();
70 prop.key = "RESOURCE_NAME";
73 setFailureProperties(props);
74 new BrmsHandler(INVALID_FILE);
77 @Test(expected = PolicyException.class)
78 public void brmsHandlerFailTest4() throws PolicyException {
79 final PropertyChange prop = new PropertyChange();
80 prop.key = "repositoryURL";
82 final List<PropertyChange> props = new LinkedList<>();
84 setFailureProperties(props);
85 new BrmsHandler(INVALID_FILE);
88 @Test(expected = PolicyException.class)
89 public void brmsHandlerFailTest5() throws PolicyException {
90 final PropertyChange prop = new PropertyChange();
91 prop.key = "repositoryName";
93 final List<PropertyChange> props = new LinkedList<>();
95 setFailureProperties(props);
96 new BrmsHandler(INVALID_FILE);
99 @Test(expected = PolicyException.class)
100 public void brmsHandlerFailTest6() throws PolicyException {
101 PropertyChange prop = new PropertyChange();
102 prop.key = "repositoryURL";
104 "http://nexus:8081/nexus/content/repositories/releases, http://nexus:8081/nexus/content/repositories/releases";
106 final List<PropertyChange> props = new LinkedList<>();
108 prop = new PropertyChange();
109 prop.key = "repositoryUsername";
112 setFailureProperties(props);
113 new BrmsHandler(INVALID_FILE);
116 @Test(expected = PolicyException.class)
117 public void brmsHandlerFailTest7() throws PolicyException {
118 final PropertyChange prop = new PropertyChange();
119 prop.key = "repositoryPassword";
121 final List<PropertyChange> props = new LinkedList<>();
123 setFailureProperties(props);
124 new BrmsHandler(INVALID_FILE);
127 @Test(expected = PolicyException.class)
128 public void brmsHandlerFailTest8() throws PolicyException {
129 final PropertyChange prop = new PropertyChange();
130 prop.key = "policyKeyID";
132 final List<PropertyChange> props = new LinkedList<>();
134 setFailureProperties(props);
135 new BrmsHandler(INVALID_FILE);
138 @Test(expected = PolicyException.class)
139 public void brmsHandlerFailTest9() throws PolicyException {
140 PropertyChange prop = new PropertyChange();
144 final List<PropertyChange> props = new LinkedList<>();
146 prop = new PropertyChange();
147 prop.key = "brms.dependency.version";
150 prop = new PropertyChange();
151 prop.key = "groupNames";
154 setFailureProperties(props);
155 new BrmsHandler(INVALID_FILE);
158 @Test(expected = PolicyException.class)
159 public void brmsHandlerFailTest10() throws PolicyException {
160 final PropertyChange prop = new PropertyChange();
161 prop.key = "groupNames";
164 final List<PropertyChange> props = new LinkedList<>();
166 setFailureProperties(props);
167 new BrmsHandler(INVALID_FILE);
170 @Test(expected = PolicyException.class)
171 public void brmsHandlerFailTest11() throws PolicyException {
172 final PropertyChange prop = new PropertyChange();
173 prop.key = "default.groupID";
175 final List<PropertyChange> props = new LinkedList<>();
177 setFailureProperties(props);
178 new BrmsHandler(INVALID_FILE);
181 @Test(expected = PolicyException.class)
182 public void brmsHandlerFailTest12() throws PolicyException {
183 final PropertyChange prop = new PropertyChange();
184 prop.key = "default.artifactID";
186 final List<PropertyChange> props = new LinkedList<>();
188 setFailureProperties(props);
189 new BrmsHandler(INVALID_FILE);
192 @Test(expected = PolicyException.class)
193 public void brmsHandlerFailTest13() throws PolicyException {
194 PropertyChange prop = new PropertyChange();
195 prop.key = "NOTIFICATION_TYPE";
196 prop.value = "dmaap";
198 final List<PropertyChange> props = new LinkedList<>();
200 prop = new PropertyChange();
201 prop.key = "NOTIFICATION_SERVERS";
204 setFailureProperties(props);
205 new BrmsHandler(INVALID_FILE);
209 public void brmsHandlerTest() throws PolicyException {
210 assertNotNull(new BrmsHandler(VALID_FILE));
213 private void setFailureProperties(final List<PropertyChange> properties) throws PolicyException {
214 final Properties validProp = new Properties();
216 validProp.load(new FileInputStream(VALID_FILE));
217 for (final PropertyChange prop : properties) {
219 validProp.remove(prop.key);
221 validProp.setProperty(prop.key, prop.value);
224 validProp.store(new FileOutputStream(INVALID_FILE), null);
225 } catch (final IOException e) {
226 throw new PolicyException(e);
230 class PropertyChange {
231 public String key = null;
232 public String value = null;
233 public Boolean remove = false;