9a85797111db377076031347b5754c01dec999af
[so.git] / common / src / test / java / org / openecomp / mso / adapter_utils / tests / MsoPropertiesFactoryTest.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * OPENECOMP - MSO
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.mso.adapter_utils.tests;
22
23
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertFalse;
26 import static org.junit.Assert.assertNotNull;
27 import static org.junit.Assert.assertNull;
28 import static org.junit.Assert.assertTrue;
29 import static org.junit.Assert.fail;
30
31 import org.junit.After;
32 import org.junit.Before;
33 import org.junit.BeforeClass;
34 import org.junit.Test;
35 import org.openecomp.mso.properties.MsoJavaProperties;
36 import org.openecomp.mso.properties.MsoJsonProperties;
37 import org.openecomp.mso.properties.MsoPropertiesException;
38 import org.openecomp.mso.properties.MsoPropertiesFactory;
39
40 import com.fasterxml.jackson.databind.JsonNode;
41
42 /**
43  * This class implements test methods of the MsoPropertiesFactory features.
44  *
45  *
46  */
47 public class MsoPropertiesFactoryTest {
48
49         public static MsoPropertiesFactory msoPropertiesFactory = new MsoPropertiesFactory();
50
51         public static final String MSO_JAVA_PROP_ID = "TEST_JAVA_PROP";
52         public static final String MSO_JSON_PROP_ID = "TEST_JSON_PROP";
53         public static final String PATH_MSO_JAVA_PROP1 = MsoJavaProperties.class.getClassLoader().getResource("mso.properties")
54                         .toString().substring(5);
55         public static final String PATH_MSO_JAVA_PROP2 = MsoJavaProperties.class.getClassLoader().getResource("mso2.properties")
56                         .toString().substring(5);
57         public static final String PATH_MSO_JSON_PROP = MsoJavaProperties.class.getClassLoader().getResource("mso.json")
58                         .toString().substring(5);
59         public static final String PATH_MSO_JSON_PROP2 = MsoJavaProperties.class.getClassLoader().getResource("mso2.json")
60                         .toString().substring(5);
61         public static final String PATH_MSO_JSON_PROP_BAD = MsoJavaProperties.class.getClassLoader().getResource("mso-bad.json")
62                         .toString().substring(5);
63
64         @BeforeClass
65         public static final void prepareBeforeAllTests() {
66                 msoPropertiesFactory.removeAllMsoProperties();
67         }
68         /**
69          * This method is called before any test occurs. It creates a fake tree from
70          * scratch
71          *
72          * @throws MsoPropertiesException
73          */
74         @Before
75         public final void prepareBeforeEachTest() throws MsoPropertiesException {
76             
77                 msoPropertiesFactory.initializeMsoProperties(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP1);
78                 msoPropertiesFactory.initializeMsoProperties(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP);
79         }
80         
81         @After
82         public final void cleanAfterEachTest() throws MsoPropertiesException {
83                 msoPropertiesFactory.removeAllMsoProperties ();
84         }
85
86         @Test 
87         public final void testNotRecognizedFile() {
88                 try {
89                         msoPropertiesFactory.initializeMsoProperties("BAD_FILE", "new_file.toto");
90
91                         fail ("MsoPropertiesException should have been raised");
92                 } catch (MsoPropertiesException ep) {
93                         assertTrue(("Unable to load the MSO properties file because format is not recognized (only .json or .properties): new_file.toto").equals(ep.getMessage()));
94                 }
95         }
96         
97         @Test
98         public final void testDoubleInit() {
99
100                 try {
101                         msoPropertiesFactory.initializeMsoProperties(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP1);
102
103                         fail ("MsoPropertiesException should have been raised");
104                 } catch (MsoPropertiesException ep) {
105                         assertTrue(("The factory contains already an instance of this mso properties: "+PATH_MSO_JAVA_PROP1).equals(ep.getMessage()));
106                 }
107
108
109         }
110
111         /**
112          * This method implements a test for the getMsoJavaProperties method.
113          *
114          * @throws MsoPropertiesException
115          */
116         @Test
117         public final void testGetMsoJavaProperties() throws MsoPropertiesException {
118                 assertNotNull(msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID));
119                 assertTrue(msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID).size()==8);
120                 
121                 try {
122                         msoPropertiesFactory.getMsoJavaProperties(MSO_JSON_PROP_ID);
123
124                         fail ("MsoPropertiesException should have been raised");
125                 } catch (MsoPropertiesException ep) {
126                         assertTrue(("Mso properties is not JAVA_PROP properties type:" + MSO_JSON_PROP_ID).equals(ep.getMessage()));
127                 }
128                 
129                 try {
130                         msoPropertiesFactory.getMsoJavaProperties("DUMB_PROP");
131
132                         fail ("MsoPropertiesException should have been raised");
133                 } catch (MsoPropertiesException ep) {
134                         assertTrue(("Mso properties not found in cache:"+"DUMB_PROP").equals(ep.getMessage()));
135                 }
136
137         }
138
139         /**
140          * This method test the MsoJavaProperties Set, equals and hascode
141          * @throws MsoPropertiesException
142          */
143         @Test
144         public final void testSetMsoJavaProperties() throws MsoPropertiesException  {
145                 MsoJavaProperties msoPropChanged = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
146                 msoPropChanged.setProperty("testos", "testos");
147                 assertNotNull(msoPropChanged.getProperty("testos", null));
148                                                 
149                 // Check no modification occurred on cache one
150                 MsoJavaProperties msoPropCache = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
151                 assertNull(msoPropCache.getProperty("testos", null));
152                 assertFalse(msoPropChanged.hashCode() != msoPropCache.hashCode());
153                 
154                 assertFalse(msoPropChanged.equals(null));
155                 assertFalse(msoPropChanged.equals(msoPropCache));
156                 assertFalse(msoPropChanged.equals(new Boolean(true)));
157                 
158                 assertTrue(msoPropChanged.equals(msoPropChanged));
159         }
160         
161         
162         /**
163          * This method implements a test for the testGetMsoJsonProperties method.
164          *
165          * @throws MsoPropertiesException
166          */
167         @Test
168         public final void testGetMsoJsonProperties() throws MsoPropertiesException {
169                 assertNotNull(msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID));
170
171                 try {
172                         msoPropertiesFactory.getMsoJsonProperties(MSO_JAVA_PROP_ID);
173
174                         fail ("MsoPropertiesException should have been raised");
175                 } catch (MsoPropertiesException ep) {
176                         assertTrue(("Mso properties is not JSON_PROP properties type:" + MSO_JAVA_PROP_ID).equals(ep.getMessage()));
177                 }
178                 
179                 try {
180                         msoPropertiesFactory.getMsoJsonProperties("DUMB_PROP");
181
182                         fail ("MsoPropertiesException should have been raised");
183                 } catch (MsoPropertiesException ep) {
184                         assertTrue(("Mso properties not found in cache:"+"DUMB_PROP").equals(ep.getMessage()));
185                 }
186
187         }
188         
189         /**
190          * This method implements a test for the testGetAllMsoProperties method.
191          *
192          * @throws MsoPropertiesException
193          */
194         @Test
195         public final void testGetAllMsoProperties() throws MsoPropertiesException {
196                 assertNotNull(msoPropertiesFactory.getAllMsoProperties().size()==2);
197
198         }
199
200         /**
201          * This method implements a test for the testGetAllMsoProperties method.
202          *
203          * @throws MsoPropertiesException
204          */
205         @Test
206         public final void testToString() throws MsoPropertiesException {
207                 String dump = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID).toString();
208                 assertTrue(dump != null && !dump.isEmpty());
209                 
210                 dump = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID).toString();
211                 assertTrue(dump != null && !dump.isEmpty());
212
213         }
214         
215         /**
216          * This method implements a test for the getProperty of JAVA_PROP type method.
217          *
218          * @throws MsoPropertiesException
219          */
220         @Test
221         public final void testGetProperties() throws MsoPropertiesException {
222                 MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
223
224                 String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
225                 String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
226                 String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
227                 String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
228                 String property5 = msoProperties.getProperty("does.not.exist", "defaultValue");
229                 String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue");
230                 String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
231
232                 assertEquals(property1, "MT");
233                 assertEquals(property2, "http://localhost:5000/v2.0");
234                 assertEquals(property3, "John");
235                 assertEquals(property4, "FD205490A48D48475607C36B9AD902BF");
236                 assertEquals(property5, "defaultValue");
237                 assertEquals(property6, "1234");
238                 assertEquals(property7, "true");
239         }
240
241         /**
242          * This method implements a test for the getIntProperty JAVA_RPOP type method.
243          *
244          * @throws MsoPropertiesException
245          */
246         @Test
247         public final void testGetIntProperties() throws MsoPropertiesException {
248                 MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
249                 int property1 = msoProperties.getIntProperty("ecomp.mso.cloud.1.test", 345);
250                 int property2 = msoProperties.getIntProperty("ecomp.mso.cloud.1.publicNetId", 345);
251                 int property3 = msoProperties.getIntProperty("does.not.exist", 345);
252                 assertEquals(property1, 1234);
253                 assertEquals(property2, 345);
254                 assertEquals(property3, 345);
255         }
256
257         /**
258          * This method implements a test for the getBooleanProperty JAVA_RPOP type method.
259          *
260          * @throws MsoPropertiesException
261          */
262         @Test
263         public final void testGetBooleanProperty() throws MsoPropertiesException {
264                 MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
265                 boolean property1 = msoProperties.getBooleanProperty("ecomp.mso.cloud.1.boolean", false);
266                 boolean property2 = msoProperties.getBooleanProperty("ecomp.mso.cloud.1.publicNetId", false);
267                 boolean property3NotThere = msoProperties.getBooleanProperty("ecomp.mso.cloud.1.publicNetIdBad", true);
268                 
269                 assertEquals(property1, true);
270                 assertEquals(property2, false);
271                 assertEquals(property3NotThere, true);
272         }
273
274         /**
275          * This method implements a test for the getEncryptedProperty JAVA_RPOP type method.
276          *
277          * @throws MsoPropertiesException
278          */
279         @Test
280         public final void testGetEncryptedProperty() throws MsoPropertiesException {
281                 MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
282                 String property1 = msoProperties.getEncryptedProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue",
283                                 "aa3871669d893c7fb8abbcda31b88b4f");
284                 String property2 = msoProperties.getEncryptedProperty("test", "defaultValue",
285                                 "aa3871669d893c7fb8abbcda31b88b4f");
286
287                 
288                 String property3Wrong = msoProperties.getEncryptedProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue",
289                                 "aa3871669d893c7fb8abbcda31b88b4");
290
291                 
292                 assertEquals(property1, "changeme");
293                 assertEquals(property2, "defaultValue");
294                 assertEquals(property3Wrong, "defaultValue");
295         }
296         
297         /**
298          * This method implements a test for the getEncryptedProperty JAVA_RPOP type method.
299          *
300          * @throws MsoPropertiesException
301          */
302         @Test
303         public final void testencryptProperty()  {
304
305                 assertTrue("FD205490A48D48475607C36B9AD902BF"
306                                 .contains(msoPropertiesFactory.encryptProperty("changeme", "aa3871669d893c7fb8abbcda31b88b4f").getEntity().toString()));
307
308         
309                 assertTrue("Invalid AES key length: 15 bytes".contains(msoPropertiesFactory.encryptProperty("changeme", "aa3871669d893c7fb8abbcda31b88b4").getEntity().toString()));
310
311         }
312         
313         /**
314          * This method implements a test for the getJSON JSON_RPOP type method.
315          *
316          * @throws MsoPropertiesException
317          */
318         @Test
319         public final void testGetJsonNode() throws MsoPropertiesException {
320                 MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
321                 
322                 JsonNode propNode = msoProperties.getJsonRootNode();
323                 assertNotNull(propNode);
324                 assertFalse(propNode.toString().isEmpty());
325                 assertTrue(propNode.isContainerNode());
326                 assertNotNull(propNode.path("asdc-connections").path("asdc-controller1"));
327                 assertNotNull(propNode.path("asdc-connections").path("asdc-controller2"));
328                 
329         }
330
331         /**
332          * This method implements a test for the reloadMsoProperties method.
333          *
334          * @throws MsoPropertiesException
335          *
336          */
337         @Test
338         public final void testReloadJavaMsoProperties() throws MsoPropertiesException {
339                 MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
340
341                 // Do some additional test on propertiesHaveChanged method
342                 assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, null));
343                 
344                 // Change path with bad one
345                 try {
346                         msoPropertiesFactory.changeMsoPropertiesFilePath("DO_NOT_EXIST", PATH_MSO_JAVA_PROP2);
347
348                         fail ("MsoPropertiesException should have been raised");
349                 } catch (MsoPropertiesException ep) {
350                         assertTrue(("Mso properties not found in cache:DO_NOT_EXIST").equals(ep.getMessage()));
351                 } 
352                                 
353                 
354                 // Change path with right one
355                 msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP2);
356                 assertTrue(PATH_MSO_JAVA_PROP2.equals(msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID).getPropertiesFileName()));
357                 
358                 assertTrue(msoPropertiesFactory.reloadMsoProperties());
359                 assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
360                 // Do a second time as timer value is set to 2
361                 assertTrue(msoPropertiesFactory.reloadMsoProperties());
362                 assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
363
364                 // Get the new one
365                 msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
366                 String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
367                 String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
368                 String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
369                 String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
370                 String property5 = msoProperties.getProperty("does.not.exist", "defaultValue");
371                 String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue");
372                 String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
373
374                 assertEquals(property1, "MT2");
375                 assertEquals(property2, "defaultValue");
376                 assertEquals(property3, "defaultValue");
377                 assertEquals(property4, "defaultValue");
378                 assertEquals(property5, "defaultValue");
379                 assertEquals(property6, "defaultValue");
380                 assertEquals(property7, "defaultValue");
381                 
382                 // Additional test on propertiesHaveChanged
383                 msoPropertiesFactory.removeAllMsoProperties();
384
385                 // Do some additional test on propertiesHaveChanged method
386                 try {
387                         msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, null);
388
389                         fail ("MsoPropertiesException should have been raised");
390                 } catch (MsoPropertiesException ep) {
391                         assertTrue(("Mso properties not found in cache:"+MSO_JAVA_PROP_ID).equals(ep.getMessage()));
392                 } 
393                 
394                 try {
395                         msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties);
396
397                         fail ("MsoPropertiesException should have been raised");
398                 } catch (MsoPropertiesException ep) {
399                         assertTrue(("Mso properties not found in cache:"+MSO_JAVA_PROP_ID).equals(ep.getMessage()));
400                 } 
401
402         }
403
404         /**
405          * This method implements a test for the reloadMsoProperties method.
406          *
407          * @throws MsoPropertiesException
408          *
409          */
410         @Test
411         public final void testReloadMoreThanAMinuteMsoProperties() throws MsoPropertiesException {
412                 MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
413
414                 msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JAVA_PROP_ID, PATH_MSO_JAVA_PROP2);
415
416                 // Simulate 2 minutes
417                 msoPropertiesFactory.reloadMsoProperties();
418                 assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
419                 msoPropertiesFactory.reloadMsoProperties();
420
421                 assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
422
423                 // Get the new one
424                 msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
425                 String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
426                 String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
427                 String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
428                 String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
429                 String property5 = msoProperties.getProperty("does.not.exist", "defaultValue");
430                 String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue");
431                 String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
432
433                 assertEquals(property1, "MT2");
434                 assertEquals(property2, "defaultValue");
435                 assertEquals(property3, "defaultValue");
436                 assertEquals(property4, "defaultValue");
437                 assertEquals(property5, "defaultValue");
438                 assertEquals(property6, "defaultValue");
439                 assertEquals(property7, "defaultValue");
440
441
442         }
443
444         /**
445          * This method implements a test for the reloadMsoProperties method.
446          *
447          * @throws MsoPropertiesException
448          *
449          */
450         @Test
451         public final void testReloadBadMsoProperties() throws MsoPropertiesException {
452                 MsoJavaProperties msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
453
454                 msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JAVA_PROP_ID, "file-does-not-exist.properties");
455                 msoPropertiesFactory.reloadMsoProperties();
456                 assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
457                 // Reload it a second time as initial timer parameter was set to 2 
458                 msoPropertiesFactory.reloadMsoProperties();
459
460                 assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JAVA_PROP_ID, msoProperties));
461
462                 // Get the new one
463                 msoProperties = msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
464                 String property1 = msoProperties.getProperty("ecomp.mso.cloud.1.cloudId", "defaultValue");
465                 String property2 = msoProperties.getProperty("ecomp.mso.cloud.1.keystoneUrl", "defaultValue");
466                 String property3 = msoProperties.getProperty("ecomp.mso.cloud.1.msoId", "defaultValue");
467                 String property4 = msoProperties.getProperty("ecomp.mso.cloud.1.publicNetId", "defaultValue");
468                 String property5 = msoProperties.getProperty("does.not.exist", "defaultValue");
469                 String property6 = msoProperties.getProperty("ecomp.mso.cloud.1.test", "defaultValue");
470                 String property7 = msoProperties.getProperty("ecomp.mso.cloud.1.boolean", "defaultValue");
471
472                 assertEquals(property1, "defaultValue");
473                 assertEquals(property2, "defaultValue");
474                 assertEquals(property3, "defaultValue");
475                 assertEquals(property4, "defaultValue");
476                 assertEquals(property5, "defaultValue");
477                 assertEquals(property6, "defaultValue");
478                 assertEquals(property7, "defaultValue");
479
480         }
481
482         /**
483          * This method implements a test for the reloadMsoProperties method.
484          *
485          * @throws MsoPropertiesException
486          *
487          */
488         @Test
489         public final void testReloadBadMsoJsonProperties() throws MsoPropertiesException {
490                 // Load a bad JSON file
491                 MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
492
493                 msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP_BAD);
494
495                 msoPropertiesFactory.reloadMsoProperties();
496                 assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties));
497                 // Reload it a second time as initial timer parameter was set to 2 
498                 msoPropertiesFactory.reloadMsoProperties();
499
500                 assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties));
501
502                 // Get the new one
503                 msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
504                 assertNotNull(msoProperties);
505                 assertNotNull(msoProperties.getJsonRootNode());
506                 assertTrue(msoProperties.getJsonRootNode().size() == 0);
507                 
508         }
509         
510         @Test
511         public final void testRemoveMsoProperties() throws MsoPropertiesException {
512                 try {
513                         msoPropertiesFactory.removeMsoProperties("DUMB_PROP");
514
515                         fail ("MsoPropertiesException should have been raised");
516                 } catch (MsoPropertiesException ep) {
517                         assertTrue(("Mso properties not found in cache:"+"DUMB_PROP").equals(ep.getMessage()));
518                 }
519
520                 msoPropertiesFactory.removeMsoProperties(MSO_JAVA_PROP_ID);
521
522                 try {
523                         msoPropertiesFactory.getMsoJavaProperties(MSO_JAVA_PROP_ID);
524
525                         fail ("MsoPropertiesException should have been raised");
526                 } catch (MsoPropertiesException ep) {
527                         assertTrue(("Mso properties not found in cache:"+MSO_JAVA_PROP_ID).equals(ep.getMessage()));
528                 }
529
530         }
531         
532         @Test
533         public final void testInitializeWithNonExistingPropertiesFile () throws MsoPropertiesException  {
534                 try {
535                         msoPropertiesFactory.initializeMsoProperties("NEW_BAD_FILE", "no_file.properties");
536                         fail ("MsoPropertiesException should have been raised");
537                 } catch (MsoPropertiesException ep) {
538                         assertTrue(("Unable to load the MSO properties file because it has not been found:no_file.properties").equals(ep.getMessage()));
539                 }
540                 
541                 // empty object should be returned as no config has been loaded, anyway no exception should be raised because the config ID must be loaded in cache
542                 // This is there for automatic reload attempt
543                 assertTrue(msoPropertiesFactory.getMsoJavaProperties("NEW_BAD_FILE").size()==0);
544         }
545         
546         
547         @Test
548         public final void testInitializeWithNonExistingJsonFile () throws MsoPropertiesException  {
549                 try {
550                         msoPropertiesFactory.initializeMsoProperties("NEW_BAD_FILE", "no_file.json");
551                         fail ("MsoPropertiesException should have been raised");
552                 } catch (MsoPropertiesException ep) {
553                         assertTrue(("Unable to load the MSO properties file because it has not been found:no_file.json").equals(ep.getMessage()));
554                 }
555                 
556                 // empty object should be returned as no config has been loaded, anyway no exception should be raised because the config ID must be loaded in cache
557                 // This is there for automatic reload attempt
558                 assertTrue(msoPropertiesFactory.getMsoJsonProperties("NEW_BAD_FILE").getJsonRootNode()!=null);
559                 assertTrue("{}".equals(msoPropertiesFactory.getMsoJsonProperties("NEW_BAD_FILE").getJsonRootNode().toString()));
560         }
561         
562         @Test
563         public final void testShowProperties() {
564                 assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().contains("/target/test-classes/mso.json(Timer:2mins)"));
565                 assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().contains("asdc-controller1"));
566                 assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().contains("/target/test-classes/mso.properties(Timer:2mins):"));
567                 assertTrue(msoPropertiesFactory.showProperties().getEntity().toString().contains("ecomp.mso.cloud.1.keystoneUrl"));
568                 
569         }
570
571         @Test 
572         public final void testGetEncryptedPropertyJson() throws MsoPropertiesException {
573                 MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
574                 assertTrue("ThePassword".equals(msoProperties.getEncryptedProperty(msoProperties.getJsonRootNode().get("asdc-connections").get("asdc-controller1").get("asdcPassword"),"defautlvalue","566B754875657232314F5548556D3665")));
575                 
576                 assertTrue("defautlvalue".equals(msoProperties.getEncryptedProperty(msoProperties.getJsonRootNode().get("asdc-connections").get("asdc-controller1").get("asdcPassword"),"defautlvalue","566B754875657232314F5548556D366")));
577                 
578                 
579         }
580         
581         @Test
582         public final void testHashcodeAndEqualsMsoJsonProperties() throws MsoPropertiesException {
583         
584                 MsoJsonProperties msoProperties = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
585
586                 msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP2);
587
588                 msoPropertiesFactory.reloadMsoProperties();
589                 assertFalse(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties));
590                 // Reload it a second time as initial timer parameter was set to 2 
591                 msoPropertiesFactory.reloadMsoProperties();
592                 assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties));
593                 
594                 // Get the new one
595                 MsoJsonProperties msoProperties2 = msoPropertiesFactory.getMsoJsonProperties(MSO_JSON_PROP_ID);
596                 assertFalse(msoProperties.hashCode()==msoProperties2.hashCode());
597                 
598                 assertFalse(msoProperties.equals(msoProperties2));
599                 assertTrue(msoProperties.equals(msoProperties));
600                 assertFalse(msoProperties.equals(null));
601                 assertFalse(msoProperties.equals(new String()));
602                 
603                 // Test a reload with timer set to 1 in PATH_MSO_JSON_PROP2
604                 msoPropertiesFactory.changeMsoPropertiesFilePath(MSO_JSON_PROP_ID, PATH_MSO_JSON_PROP);
605
606                 msoPropertiesFactory.reloadMsoProperties();
607                 assertTrue(msoPropertiesFactory.propertiesHaveChanged(MSO_JSON_PROP_ID, msoProperties2));
608         
609         }
610         
611 }