2 * ============LICENSE_START====================================================
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
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====================================================
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;
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;
36 public class JU_BetterMatch1 {
40 Trans trans = EnvFactory.newTrans();
42 Match bm = new Match("/req/1.0.0/:var");
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(""));
51 TimeTaken tt = trans.start("A", Env.SUB);
56 tt2 = trans.start(Integer.toString(++i), Env.SUB);
57 assertTrue(bm.match(""));
59 tt2 = trans.start(Integer.toString(++i), Env.SUB);
60 assertTrue(bm.match(null));
67 tt = trans.start("B", Env.SUB);
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"));
74 tt2 = trans.start(Integer.toString(++i), Env.SUB);
75 assertFalse(bm.match("/req/1.0.0/urn"));
77 tt2 = trans.start(Integer.toString(++i), Env.SUB);
78 assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/"));
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"));
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"));
90 tt = trans.start("C", Env.SUB);
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";
98 assertTrue(bm.match(url+value));
99 assertEquals("urn:fsdb,1.0,req,newreq/0x12345",bm.param(url+value, ":urn"));
105 tt = trans.start("D", Env.SUB);
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"));
112 tt2 = trans.start(Integer.toString(++i), Env.SUB);
113 assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/"));
119 tt = trans.start("E", Env.SUB);
122 bm = new Match("this*");
123 tt2 = trans.start(Integer.toString(++i), Env.SUB);
124 assertTrue(bm.match("this"));
126 tt2 = trans.start(Integer.toString(++i), Env.SUB);
127 assertTrue(bm.match("thisandthat"));
129 tt2 = trans.start(Integer.toString(++i), Env.SUB);
130 assertTrue(bm.match("this/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/"));
136 tt = trans.start("F", Env.SUB);
140 tt2 = trans.start(Integer.toString(++i), Env.SUB);
141 assertTrue(bm.match("whatever/this"));
147 StringBuilder sb = new StringBuilder();
148 trans.auditTrail(0, sb);
149 //System.out.println(sb);
154 public void specialTest() {
155 Match match = new Match("/sample");
156 assertTrue(match.match("/sample"));
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"));