[AAF-21] Initial code import
[aaf/cadi.git] / client / src / test / java / com / client / test / JU_PropertyLocator.java
1 /*******************************************************************************\r
2  * ============LICENSE_START====================================================\r
3  * * org.onap.aai\r
4  * * ===========================================================================\r
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.\r
6  * * Copyright © 2017 Amdocs\r
7  * * ===========================================================================\r
8  * * Licensed under the Apache License, Version 2.0 (the "License");\r
9  * * you may not use this file except in compliance with the License.\r
10  * * You may obtain a copy of the License at\r
11  * * \r
12  *  *      http://www.apache.org/licenses/LICENSE-2.0\r
13  * * \r
14  *  * Unless required by applicable law or agreed to in writing, software\r
15  * * distributed under the License is distributed on an "AS IS" BASIS,\r
16  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
17  * * See the License for the specific language governing permissions and\r
18  * * limitations under the License.\r
19  * * ============LICENSE_END====================================================\r
20  * *\r
21  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.\r
22  * *\r
23  ******************************************************************************/\r
24 package com.client.test;\r
25 \r
26 import java.net.URI;\r
27 \r
28 import org.junit.AfterClass;\r
29 import org.junit.Test;\r
30 \r
31 import static org.junit.Assert.*;\r
32 \r
33 import com.att.cadi.Locator.Item;\r
34 import com.att.cadi.locator.PropertyLocator;\r
35 \r
36 public class JU_PropertyLocator {\r
37 \r
38         @AfterClass\r
39         public static void tearDownAfterClass() throws Exception {\r
40         }\r
41 \r
42         @Test\r
43         public void test() throws Exception {\r
44                 PropertyLocator pl = new PropertyLocator("https://localhost:2345,https://fred.wilma.com:26444,https://tom.jerry.com:534");\r
45                 \r
46                 Item i;\r
47                 int count;\r
48                 boolean print = false;\r
49                 for(int j=0;j<900000;++j) {\r
50                         count = 0;\r
51                         for(i = pl.first();i!=null;i=pl.next(i)) {\r
52                                 URI loc = pl.get(i);\r
53                                 if(print)System.out.println(loc.toString());\r
54                                 ++count;\r
55                         }\r
56                         assertEquals(3,count);\r
57                         assertTrue(pl.hasItems());\r
58                         if(print)System.out.println("---");\r
59                         pl.invalidate(pl.best());\r
60                         \r
61                         count = 0;\r
62                         for(i = pl.first();i!=null;i=pl.next(i)) {\r
63                                 URI loc = pl.get(i);\r
64                                 if(print)System.out.println(loc.toString());\r
65                                 ++count;\r
66                         }\r
67         \r
68                         assertEquals(2,count);\r
69                         assertTrue(pl.hasItems());\r
70                         if(print)System.out.println("---");\r
71                         pl.invalidate(pl.best());\r
72                         \r
73                         count = 0;\r
74                         for(i = pl.first();i!=null;i=pl.next(i)) {\r
75                                 URI loc = pl.get(i);\r
76                                 if(print)System.out.println(loc.toString());\r
77                                 ++count;\r
78                         }\r
79         \r
80                         assertEquals(1,count);\r
81                         assertTrue(pl.hasItems());\r
82                         if(print)System.out.println("---");\r
83                         pl.invalidate(pl.best());\r
84                         \r
85                         count = 0;\r
86                         for(i = pl.first();i!=null;i=pl.next(i)) {\r
87                                 URI loc = pl.get(i);\r
88                                 if(print)System.out.println(loc.toString());\r
89                                 ++count;\r
90                         }\r
91         \r
92                         assertEquals(0,count);\r
93                         assertFalse(pl.hasItems());\r
94                         \r
95                         pl.refresh();\r
96                 }\r
97         }\r
98 \r
99 }\r