Keep only clean TestCases, remove 2 license issues
[aaf/authz.git] / auth / auth-core / src / test / java / org / onap / aaf / auth / request / test / RosettaCompare.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 org.onap.aaf.misc.env.APIException;
25 import org.onap.aaf.misc.env.Data;
26 import org.onap.aaf.misc.env.Data.TYPE;
27 import org.onap.aaf.misc.rosetta.env.RosettaDF;
28 import org.onap.aaf.misc.rosetta.env.RosettaData;
29 import org.onap.aaf.misc.rosetta.env.RosettaEnv;
30
31 public abstract class RosettaCompare<T> {
32         protected Class<T> cls;
33         private static int count = 0;
34         
35         public RosettaCompare(Class<T> cls) {
36                 this.cls = cls;
37         }
38         
39         public void run(RosettaEnv env) throws APIException {
40                 RosettaDF<T> nsrDF = env.newDataFactory(cls);
41                 compare(nsrDF.newData().option(Data.PRETTY),newOne(),this);
42         }
43         
44         private void compare(RosettaData<T> rdt, T t, RosettaCompare<T> comp) throws APIException {
45                 //System.out.println("########### Testing " + cls.getName() + " ##############");
46                 String s = rdt.load(t).out(TYPE.JSON).asString();
47                 //System.out.println(s);
48                 T t2 = rdt.in(TYPE.JSON).load(s).asObject();
49                 comp.compare(t, t2);
50                 
51                 //System.out.println();
52                 
53                 s = rdt.load(t).out(TYPE.XML).asString();
54                 //System.out.println(s);
55                 t2 = rdt.in(TYPE.XML).load(s).asObject();
56                 comp.compare(t, t2);
57         }
58         
59         public synchronized static String instance() {
60                 return "_"+ ++count;
61         }
62         
63         public abstract void compare(T t1, T t2);
64         public abstract T newOne();
65         
66 }