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.brmsInterface.BRMSHandler;
36 public class BRMSPushTest {
38 private final String VALIDFILE = "src/test/resources/config.properties";
39 private final String INVALIDFILE = "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 PropertyChange prop = new PropertyChange();
54 prop.key = "defaultName";
56 List<PropertyChange> props = new LinkedList<>();
58 setFailureProperties(props);
59 new BRMSHandler(INVALIDFILE);
62 @Test (expected = PolicyException.class)
63 public void bRMSHandlerFailTest3() throws PolicyException {
64 PropertyChange prop = new PropertyChange();
65 prop.key = "repositoryID";
67 List<PropertyChange> props = new LinkedList<>();
69 prop = new PropertyChange();
70 prop.key = "RESOURCE_NAME";
73 setFailureProperties(props);
74 new BRMSHandler(INVALIDFILE);
77 @Test (expected = PolicyException.class)
78 public void bRMSHandlerFailTest4() throws PolicyException {
79 PropertyChange prop = new PropertyChange();
80 prop.key = "repositoryURL";
82 List<PropertyChange> props = new LinkedList<>();
84 setFailureProperties(props);
85 new BRMSHandler(INVALIDFILE);
88 @Test (expected = PolicyException.class)
89 public void bRMSHandlerFailTest5() throws PolicyException {
90 PropertyChange prop = new PropertyChange();
91 prop.key = "repositoryName";
93 List<PropertyChange> props = new LinkedList<>();
95 setFailureProperties(props);
96 new BRMSHandler(INVALIDFILE);
99 @Test (expected = PolicyException.class)
100 public void bRMSHandlerFailTest6() throws PolicyException {
101 PropertyChange prop = new PropertyChange();
102 prop.key = "repositoryURL";
103 prop.value = "http://nexus:8081/nexus/content/repositories/releases, http://nexus:8081/nexus/content/repositories/releases";
105 List<PropertyChange> props = new LinkedList<>();
107 prop = new PropertyChange();
108 prop.key = "repositoryUsername";
111 setFailureProperties(props);
112 new BRMSHandler(INVALIDFILE);
115 @Test (expected = PolicyException.class)
116 public void bRMSHandlerFailTest7() throws PolicyException {
117 PropertyChange prop = new PropertyChange();
118 prop.key = "repositoryPassword";
120 List<PropertyChange> props = new LinkedList<>();
122 setFailureProperties(props);
123 new BRMSHandler(INVALIDFILE);
126 @Test (expected = PolicyException.class)
127 public void bRMSHandlerFailTest8() throws PolicyException {
128 PropertyChange prop = new PropertyChange();
129 prop.key = "policyKeyID";
131 List<PropertyChange> props = new LinkedList<>();
133 setFailureProperties(props);
134 new BRMSHandler(INVALIDFILE);
137 @Test (expected = PolicyException.class)
138 public void bRMSHandlerFailTest9() throws PolicyException {
139 PropertyChange prop = new PropertyChange();
143 List<PropertyChange> props = new LinkedList<>();
145 prop = new PropertyChange();
146 prop.key = "brms.dependency.version";
149 prop = new PropertyChange();
150 prop.key = "groupNames";
153 setFailureProperties(props);
154 new BRMSHandler(INVALIDFILE);
157 @Test (expected = PolicyException.class)
158 public void bRMSHandlerFailTest10() throws PolicyException {
159 PropertyChange prop = new PropertyChange();
160 prop.key = "groupNames";
163 List<PropertyChange> props = new LinkedList<>();
165 setFailureProperties(props);
166 new BRMSHandler(INVALIDFILE);
169 @Test (expected = PolicyException.class)
170 public void bRMSHandlerFailTest11() throws PolicyException {
171 PropertyChange prop = new PropertyChange();
172 prop.key = "default.groupID";
174 List<PropertyChange> props = new LinkedList<>();
176 setFailureProperties(props);
177 new BRMSHandler(INVALIDFILE);
180 @Test (expected = PolicyException.class)
181 public void bRMSHandlerFailTest12() throws PolicyException {
182 PropertyChange prop = new PropertyChange();
183 prop.key = "default.artifactID";
185 List<PropertyChange> props = new LinkedList<>();
187 setFailureProperties(props);
188 new BRMSHandler(INVALIDFILE);
191 @Test (expected = PolicyException.class)
192 public void bRMSHandlerFailTest13() throws PolicyException {
193 PropertyChange prop = new PropertyChange();
194 prop.key = "NOTIFICATION_TYPE";
195 prop.value = "dmaap";
197 List<PropertyChange> props = new LinkedList<>();
199 prop = new PropertyChange();
200 prop.key = "NOTIFICATION_SERVERS";
203 setFailureProperties(props);
204 new BRMSHandler(INVALIDFILE);
208 public void BRMSHandlerTest() throws PolicyException {
209 assertNotNull(new BRMSHandler(VALIDFILE));
212 private void setFailureProperties(List<PropertyChange> properties) throws PolicyException {
213 Properties validProp = new Properties();
215 validProp.load(new FileInputStream(VALIDFILE));
216 for (PropertyChange prop: properties) {
218 validProp.remove(prop.key);
220 validProp.setProperty(prop.key, prop.value);
223 validProp.store(new FileOutputStream(INVALIDFILE), null);
224 } catch (IOException e) {
225 throw new PolicyException(e);
229 class PropertyChange {
230 public String key = null;
231 public String value = null;
232 public Boolean remove = false;