1 /*******************************************************************************
\r
2 * ============LICENSE_START====================================================
\r
4 * * ===========================================================================
\r
5 * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
\r
6 * * Copyright © 2017 Amdocs
\r
7 * * ===========================================================================
\r
8 * * Licensed under the Apache License, Version 2.0 (the "License");
\r
9 * * you may not use this file except in compliance with the License.
\r
10 * * You may obtain a copy of the License at
\r
12 * * http://www.apache.org/licenses/LICENSE-2.0
\r
14 * * Unless required by applicable law or agreed to in writing, software
\r
15 * * distributed under the License is distributed on an "AS IS" BASIS,
\r
16 * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
\r
17 * * See the License for the specific language governing permissions and
\r
18 * * limitations under the License.
\r
19 * * ============LICENSE_END====================================================
\r
21 * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
\r
23 ******************************************************************************/
\r
24 package com.att.cssa.rserv.test;
\r
26 import static junit.framework.Assert.assertEquals;
\r
27 import static junit.framework.Assert.assertFalse;
\r
28 import static junit.framework.Assert.assertTrue;
\r
30 import org.junit.Test;
\r
32 import com.att.cssa.rserv.Match;
\r
33 import com.att.inno.env.Env;
\r
34 import com.att.inno.env.TimeTaken;
\r
35 import com.att.inno.env.Trans;
\r
36 import com.att.inno.env.impl.EnvFactory;
\r
39 public class JU_BetterMatch {
\r
42 public void test() {
\r
43 Trans trans = EnvFactory.newTrans();
\r
45 Match bm = new Match("/req/1.0.0/:var");
\r
47 assertTrue(bm.match("/req/1.0.0/fred"));
\r
48 assertTrue(bm.match("/req/1.0.0/wilma"));
\r
49 assertTrue(bm.match("/req/1.0.0/wilma/"));
\r
50 assertFalse(bm.match("/req/1.0.0/wilma/bambam"));
\r
51 assertFalse(bm.match("/not/valid/234"));
\r
52 assertFalse(bm.match(""));
\r
54 TimeTaken tt = trans.start("A", Env.SUB);
\r
58 bm = new Match(null);
\r
59 tt2 = trans.start(Integer.toString(++i), Env.SUB);
\r
60 assertTrue(bm.match(""));
\r
62 tt2 = trans.start(Integer.toString(++i), Env.SUB);
\r
63 assertTrue(bm.match(null));
\r
70 tt = trans.start("B", Env.SUB);
\r
73 bm = new Match("/req/1.0.0/:urn/:ref");
\r
74 tt2 = trans.start(Integer.toString(++i), Env.SUB);
\r
75 assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345"));
\r
77 tt2 = trans.start(Integer.toString(++i), Env.SUB);
\r
78 assertFalse(bm.match("/req/1.0.0/urn"));
\r
80 tt2 = trans.start(Integer.toString(++i), Env.SUB);
\r
81 assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/"));
\r
83 tt2 = trans.start(Integer.toString(++i), Env.SUB);
\r
84 assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/x"));
\r
86 tt2 = trans.start(Integer.toString(++i), Env.SUB);
\r
87 assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/xyx"));
\r
93 tt = trans.start("C", Env.SUB);
\r
96 String url = "/req/1.0.0/";
\r
97 bm = new Match(url+":urn*");
\r
98 tt2 = trans.start(Integer.toString(++i), Env.SUB);
\r
99 String value = "urn:fsdb,1.0,req,newreq/0x12345";
\r
101 assertTrue(bm.match(url+value));
\r
102 assertEquals("urn:fsdb,1.0,req,newreq/0x12345",bm.param(url+value, ":urn"));
\r
108 tt = trans.start("D", Env.SUB);
\r
111 bm = new Match("/req/1.0.0/:urn/:ref*");
\r
112 tt2 = trans.start(Integer.toString(++i), Env.SUB);
\r
113 assertTrue(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/0x12345"));
\r
115 tt2 = trans.start(Integer.toString(++i), Env.SUB);
\r
116 assertFalse(bm.match("/req/1.0.0/urn:fsdb,1.0,req,newreq/"));
\r
122 tt = trans.start("E", Env.SUB);
\r
125 bm = new Match("this*");
\r
126 tt2 = trans.start(Integer.toString(++i), Env.SUB);
\r
127 assertTrue(bm.match("this"));
\r
129 tt2 = trans.start(Integer.toString(++i), Env.SUB);
\r
130 assertTrue(bm.match("thisandthat"));
\r
132 tt2 = trans.start(Integer.toString(++i), Env.SUB);
\r
133 assertTrue(bm.match("this/1.0.0/urn:fsdb,1.0,req,newreq/0x12345/"));
\r
139 tt = trans.start("F", Env.SUB);
\r
142 bm = new Match("*");
\r
143 tt2 = trans.start(Integer.toString(++i), Env.SUB);
\r
144 assertTrue(bm.match("<pass>/this"));
\r
150 StringBuilder sb = new StringBuilder();
\r
151 trans.auditTrail(0, sb);
\r
152 System.out.println(sb);
\r
157 public void specialTest() {
\r
158 Match match = new Match("/sample");
\r
159 assertTrue(match.match("/sample"));
\r
161 match = new Match("/lpeer//lpeer/:key/:item*");
\r
162 assertTrue(match.match("/lpeer//lpeer/x/y"));
\r
163 assertFalse(match.match("/lpeer/x/lpeer/x/y"));
\r