1 /*******************************************************************************
2 * ============LICENSE_START====================================================
4 * * ===========================================================================
5 * * Copyright © 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 ******************************************************************************/
22 package org.onap.aaf.auth.rserv.test;
24 import static junit.framework.Assert.assertEquals;
25 import static junit.framework.Assert.assertFalse;
26 import static junit.framework.Assert.assertTrue;
30 import org.junit.Assert;
31 import org.junit.Test;
32 import org.onap.aaf.auth.rserv.Match;
33 import org.onap.aaf.misc.env.Env;
34 import org.onap.aaf.misc.env.TimeTaken;
35 import org.onap.aaf.misc.env.Trans;
36 import org.onap.aaf.misc.env.impl.EnvFactory;
39 public class JU_BetterMatch {
43 Trans trans = EnvFactory.newTrans();
45 Match bm = new Match("/req/1.0.0/:var");
47 assertTrue(bm.match("/req/1.0.0/fred"));
48 assertTrue(bm.match("/req/1.0.0/wilma"));
49 assertTrue(bm.match("/req/1.0.0/wilma/"));
50 assertFalse(bm.match("/req/1.0.0/wilma/bambam"));
51 assertFalse(bm.match("/not/valid/234"));
52 assertFalse(bm.match(""));
54 TimeTaken tt = trans.start("A", Env.SUB);
59 tt2 = trans.start(Integer.toString(++i), Env.SUB);
60 assertTrue(bm.match(""));
62 tt2 = trans.start(Integer.toString(++i), Env.SUB);
63 assertTrue(bm.match(null));
70 tt = trans.start("B", Env.SUB);
73 bm = new Match("/req/1.0.0/:urn/:ref");
74 tt2 = trans.start(Integer.toString(++i), Env.SUB);
75 assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345"));
77 tt2 = trans.start(Integer.toString(++i), Env.SUB);
78 assertFalse(bm.match("/req/1.0.0/urn"));
80 tt2 = trans.start(Integer.toString(++i), Env.SUB);
81 assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/"));
83 tt2 = trans.start(Integer.toString(++i), Env.SUB);
84 assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/x"));
86 tt2 = trans.start(Integer.toString(++i), Env.SUB);
87 assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/xyx"));
93 tt = trans.start("C", Env.SUB);
96 String url = "/req/1.0.0/";
97 bm = new Match(url+":urn*");
98 tt2 = trans.start(Integer.toString(++i), Env.SUB);
99 String value = "urn:fsdb,1.0,req,newreq/0x12345";
101 assertTrue(bm.match(url+value));
102 assertEquals("urn:fsdb,1.0,req,newreq/0x12345",bm.param(url+value, ":urn"));
108 tt = trans.start("D", Env.SUB);
111 bm = new Match("/req/1.0.0/:urn/:ref*");
112 tt2 = trans.start(Integer.toString(++i), Env.SUB);
113 assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345"));
115 tt2 = trans.start(Integer.toString(++i), Env.SUB);
116 assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/"));
122 tt = trans.start("E", Env.SUB);
125 bm = new Match("this*");
126 tt2 = trans.start(Integer.toString(++i), Env.SUB);
127 assertTrue(bm.match("this"));
129 tt2 = trans.start(Integer.toString(++i), Env.SUB);
130 assertTrue(bm.match("thisandthat"));
132 tt2 = trans.start(Integer.toString(++i), Env.SUB);
133 assertTrue(bm.match("this/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/"));
139 tt = trans.start("F", Env.SUB);
143 tt2 = trans.start(Integer.toString(++i), Env.SUB);
144 assertTrue(bm.match("<pass>/this"));
150 StringBuilder sb = new StringBuilder();
151 trans.auditTrail(0, sb);
152 //System.out.println(sb);
157 public void specialTest() {
158 Match match = new Match("/sample");
159 assertTrue(match.match("/sample"));
161 match = new Match("/lpeer//lpeer/:key/:item*");
162 assertTrue(match.match("/lpeer//lpeer/x/y"));
163 assertFalse(match.match("/lpeer/x/lpeer/x/y"));
168 public void testGetParamNames() {
169 Match bm = new Match("/req/1.0.0/:var");
170 Set s = bm.getParamNames();
171 Assert.assertNotNull(s);