Keep only clean TestCases, remove 2 license issues
[aaf/authz.git] / auth / auth-core / src / test / java / org / onap / aaf / auth / rserv / test / JU_BetterMatch1.java
1 /**
2  * ============LICENSE_START====================================================
3  * org.onap.aaf
4  * ===========================================================================
5  * Copyright (c) 2018 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
22 package org.onap.aaf.auth.rserv.test;
23
24 import static junit.framework.Assert.assertEquals;
25 import static junit.framework.Assert.assertFalse;
26 import static junit.framework.Assert.assertTrue;
27
28 import org.junit.Test;
29 import org.onap.aaf.auth.rserv.Match;
30 import org.onap.aaf.misc.env.Env;
31 import org.onap.aaf.misc.env.TimeTaken;
32 import org.onap.aaf.misc.env.Trans;
33 import org.onap.aaf.misc.env.impl.EnvFactory;
34
35
36 public class JU_BetterMatch1 {
37
38         @Test
39         public void test() {
40                 Trans trans = EnvFactory.newTrans();
41                 // Bad Match
42                 Match bm = new Match("/req/1.0.0/:var");
43
44                 assertTrue(bm.match("/req/1.0.0/fred"));
45                 assertTrue(bm.match("/req/1.0.0/wilma"));
46                 assertTrue(bm.match("/req/1.0.0/wilma/"));
47                 assertFalse(bm.match("/req/1.0.0/wilma/bambam"));
48                 assertFalse(bm.match("/not/valid/234"));
49                 assertFalse(bm.match(""));
50                 
51                 TimeTaken tt = trans.start("A", Env.SUB);
52                 TimeTaken tt2;
53                 int i = 0;
54                 try {
55                         bm = new Match(null);
56                         tt2 = trans.start(Integer.toString(++i), Env.SUB);
57                         assertTrue(bm.match(""));
58                         tt2.done();
59                         tt2 = trans.start(Integer.toString(++i), Env.SUB);
60                         assertTrue(bm.match(null));
61                         tt2.done();
62                 } finally {
63                         tt.done();
64                 }
65                 
66         
67                 tt = trans.start("B", Env.SUB);
68                 i = 0;
69                 try {
70                         bm = new Match("/req/1.0.0/:urn/:ref");
71                         tt2 = trans.start(Integer.toString(++i), Env.SUB);
72                         assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345"));
73                         tt2.done();
74                         tt2 = trans.start(Integer.toString(++i), Env.SUB);
75                         assertFalse(bm.match("/req/1.0.0/urn"));
76                         tt2.done();
77                         tt2 = trans.start(Integer.toString(++i), Env.SUB);
78                         assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/"));
79                         tt2.done();
80                         tt2 = trans.start(Integer.toString(++i), Env.SUB);
81                         assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/x"));
82                         tt2.done();
83                         tt2 = trans.start(Integer.toString(++i), Env.SUB);
84                         assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/xyx"));
85                 } finally {
86                         tt2.done();
87                         tt.done();      
88                 }
89                 
90                 tt = trans.start("C", Env.SUB);
91                 i = 0;
92                 try {
93                         String url = "/req/1.0.0/";
94                         bm = new Match(url+":urn*");
95                         tt2 = trans.start(Integer.toString(++i), Env.SUB);
96                         String value = "urn:fsdb,1.0,req,newreq/0x12345";
97                         
98                         assertTrue(bm.match(url+value));
99                         assertEquals("urn:fsdb,1.0,req,newreq/0x12345",bm.param(url+value, ":urn"));
100                 } finally {
101                         tt2.done();
102                         tt.done();      
103                 }
104
105                 tt = trans.start("D", Env.SUB);
106                 i = 0;
107                 try {
108                         bm = new Match("/req/1.0.0/:urn/:ref*");
109                         tt2 = trans.start(Integer.toString(++i), Env.SUB);
110                         assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345"));
111                         tt2.done();
112                         tt2 = trans.start(Integer.toString(++i), Env.SUB);
113                         assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/"));
114                 } finally {
115                         tt2.done();
116                         tt.done();      
117                 }
118
119                 tt = trans.start("E", Env.SUB);
120                 i = 0;
121                 try {
122                         bm = new Match("this*");
123                         tt2 = trans.start(Integer.toString(++i), Env.SUB);
124                         assertTrue(bm.match("this"));
125                         tt2.done();
126                         tt2 = trans.start(Integer.toString(++i), Env.SUB);
127                         assertTrue(bm.match("thisandthat"));
128                         tt2.done();
129                         tt2 = trans.start(Integer.toString(++i), Env.SUB);
130                         assertTrue(bm.match("this/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/"));
131                 } finally {
132                         tt2.done();
133                         tt.done();      
134                 }
135
136                 tt = trans.start("F", Env.SUB);
137                 i = 0;
138                 try {
139                         bm = new Match("*");
140                         tt2 = trans.start(Integer.toString(++i), Env.SUB);
141                         assertTrue(bm.match("whatever/this"));
142                 } finally {
143                         tt2.done();
144                         tt.done();      
145                 }
146                 
147                 StringBuilder sb = new StringBuilder();
148                 trans.auditTrail(0, sb);
149                 //System.out.println(sb);
150                 
151         }
152         
153         @Test
154         public void specialTest() {
155                 Match match = new Match("/sample");
156                 assertTrue(match.match("/sample"));
157                 
158                 match = new Match("/lpeer//lpeer/:key/:item*");
159                 assertTrue(match.match("/lpeer//lpeer/x/y"));
160                 assertFalse(match.match("/lpeer/x/lpeer/x/y"));
161
162         }
163
164 }