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