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 ******************************************************************************/
23 package org.onap.aaf.auth.rserv.test;
25 import static junit.framework.Assert.assertEquals;
26 import static junit.framework.Assert.assertFalse;
27 import static junit.framework.Assert.assertTrue;
31 import org.junit.Assert;
32 import org.junit.Test;
33 import org.onap.aaf.auth.rserv.Match;
34 import org.onap.aaf.misc.env.Env;
35 import org.onap.aaf.misc.env.TimeTaken;
36 import org.onap.aaf.misc.env.Trans;
37 import org.onap.aaf.misc.env.impl.EnvFactory;
40 public class JU_BetterMatch {
44 Trans trans = EnvFactory.newTrans();
46 Match bm = new Match("/req/1.0.0/:var");
48 assertTrue(bm.match("/req/1.0.0/fred"));
49 assertTrue(bm.match("/req/1.0.0/wilma"));
50 assertTrue(bm.match("/req/1.0.0/wilma/"));
51 assertFalse(bm.match("/req/1.0.0/wilma/bambam"));
52 assertFalse(bm.match("/not/valid/234"));
53 assertFalse(bm.match(""));
55 TimeTaken tt = trans.start("A", Env.SUB);
60 tt2 = trans.start(Integer.toString(++i), Env.SUB);
61 assertTrue(bm.match(""));
63 tt2 = trans.start(Integer.toString(++i), Env.SUB);
64 assertTrue(bm.match(null));
71 tt = trans.start("B", Env.SUB);
74 bm = new Match("/req/1.0.0/:urn/:ref");
75 tt2 = trans.start(Integer.toString(++i), Env.SUB);
76 assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345"));
78 tt2 = trans.start(Integer.toString(++i), Env.SUB);
79 assertFalse(bm.match("/req/1.0.0/urn"));
81 tt2 = trans.start(Integer.toString(++i), Env.SUB);
82 assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/"));
84 tt2 = trans.start(Integer.toString(++i), Env.SUB);
85 assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/x"));
87 tt2 = trans.start(Integer.toString(++i), Env.SUB);
88 assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/xyx"));
94 tt = trans.start("C", Env.SUB);
97 String url = "/req/1.0.0/";
98 bm = new Match(url+":urn*");
99 tt2 = trans.start(Integer.toString(++i), Env.SUB);
100 String value = "urn:fsdb,1.0,req,newreq/0x12345";
102 assertTrue(bm.match(url+value));
103 assertEquals("urn:fsdb,1.0,req,newreq/0x12345",bm.param(url+value, ":urn"));
109 tt = trans.start("D", Env.SUB);
112 bm = new Match("/req/1.0.0/:urn/:ref*");
113 tt2 = trans.start(Integer.toString(++i), Env.SUB);
114 assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345"));
116 tt2 = trans.start(Integer.toString(++i), Env.SUB);
117 assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/"));
123 tt = trans.start("E", Env.SUB);
126 bm = new Match("this*");
127 tt2 = trans.start(Integer.toString(++i), Env.SUB);
128 assertTrue(bm.match("this"));
130 tt2 = trans.start(Integer.toString(++i), Env.SUB);
131 assertTrue(bm.match("thisandthat"));
133 tt2 = trans.start(Integer.toString(++i), Env.SUB);
134 assertTrue(bm.match("this/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/"));
140 tt = trans.start("F", Env.SUB);
144 tt2 = trans.start(Integer.toString(++i), Env.SUB);
145 assertTrue(bm.match("<pass>/this"));
151 StringBuilder sb = new StringBuilder();
152 trans.auditTrail(0, sb);
153 //System.out.println(sb);
158 public void specialTest() {
159 Match match = new Match("/sample");
160 assertTrue(match.match("/sample"));
162 match = new Match("/lpeer//lpeer/:key/:item*");
163 assertTrue(match.match("/lpeer//lpeer/x/y"));
164 assertFalse(match.match("/lpeer/x/lpeer/x/y"));
169 public void testGetParamNames() {
170 Match bm = new Match("/req/1.0.0/:var");
171 Set s = bm.getParamNames();
172 Assert.assertNotNull(s);