AT&T 2.0.19 Code drop, stage 3
[aaf/authz.git] / auth / auth-core / src / test / java / org / onap / aaf / auth / request / test / NSAttribCompare.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.request.test;
23
24 import static junit.framework.Assert.assertEquals;
25 import static junit.framework.Assert.assertTrue;
26
27 import java.util.GregorianCalendar;
28
29 import org.onap.aaf.misc.env.util.Chrono;
30
31 import aaf.v2_0.NsAttribRequest;
32 import aaf.v2_0.NsAttribRequest.Attrib;
33
34 public class NSAttribCompare extends RosettaCompare<NsAttribRequest>  {
35         public NSAttribCompare() {
36                 super(NsAttribRequest.class);
37         }
38         
39         public static NsAttribRequest create() {
40                 NsAttribRequest nar = new NsAttribRequest();
41                 String in = instance();
42                 
43                 nar.setNs("org.osaaf.ns"+in);
44                 Attrib attrib = new Attrib();
45                 attrib.setKey("swm");
46                 attrib.setValue("v"+instance());
47                 nar.getAttrib().add(attrib);
48                 attrib = new Attrib();
49                 attrib.setKey("scamp");
50                 attrib.setValue("v"+instance());
51                 nar.getAttrib().add(attrib);
52                 GregorianCalendar gc = new GregorianCalendar();
53                 nar.setStart(Chrono.timeStamp(gc));
54                 gc.add(GregorianCalendar.MONTH, 1);
55                 nar.setEnd(Chrono.timeStamp(gc));
56                 return nar;
57         }
58         
59         @Override
60         public void compare(NsAttribRequest t1, NsAttribRequest t2) {
61                 assertEquals(t1.getNs(),t2.getNs());
62                 for(Attrib a1 : t1.getAttrib()) {
63                         boolean ok = false;
64                         for(Attrib a2 : t2.getAttrib()) {
65                                 if(a1.getKey().equals(a2.getKey()) &&
66                                         a1.getValue().equals(a2.getValue())) {
67                                         ok = true;
68                                         break;
69                                 }
70                         }
71                         assertTrue("a2 Attribs in a1",ok);
72                 }
73                 for(Attrib a2 : t2.getAttrib()) {
74                         boolean ok = false;
75                         for(Attrib a1 : t1.getAttrib()) {
76                                 if(a1.getKey().equals(a2.getKey()) &&
77                                         a1.getValue().equals(a2.getValue())) {
78                                         ok = true;
79                                         break;
80                                 }
81                         }
82                         assertTrue("a2 Attribs in a1",ok);
83                 }
84                 assertEquals(t1.getStart(),t2.getStart());
85                 assertEquals(t1.getEnd(),t2.getEnd());
86         }
87
88
89         @Override
90         public NsAttribRequest newOne() {
91                 return create();
92         }
93 }