AT&T 2.0.19 Code drop, stage 2
[aaf/authz.git] / cadi / aaf / src / test / java / org / onap / aaf / content / JU_Content.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
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
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.content;
23
24 import java.io.StringReader;
25
26 import org.junit.AfterClass;
27 import org.junit.BeforeClass;
28 import org.junit.Test;
29 import org.onap.aaf.misc.rosetta.env.RosettaDF;
30 import org.onap.aaf.misc.rosetta.env.RosettaData;
31 import org.onap.aaf.misc.rosetta.env.RosettaEnv;
32
33 import aaf.v2_0.Error;
34
35 public class JU_Content {
36
37         @BeforeClass
38         public static void setUpBeforeClass() throws Exception {
39         }
40
41         @AfterClass
42         public static void tearDownAfterClass() throws Exception {
43         }
44
45
46         @Test
47         public void parseErrorJSON() throws Exception {
48                 final String msg = "{\"messageId\":\"SVC2000\",\"text\":\"Select which cred to delete (or 0 to delete all):" +
49                         "1) %1" +
50                         "2) %2" +
51                         "3) %3" +
52                         "4) %4" +
53                         "Run same command again with chosen entry as last parameter\"," +
54                         "\"variables\":[" +
55                         "\"m55555@jr583u.cred.test.com 1 Wed Oct 08 11:48:08 CDT 2014\"," +
56                         "\"m55555@jr583u.cred.test.com 1 Thu Oct 09 12:54:46 CDT 2014\"," +
57                         "\"m55555@jr583u.cred.test.com 1 Tue Jan 06 05:00:00 CST 2015\"," +
58                         "\"m55555@jr583u.cred.test.com 1 Wed Jan 07 05:00:00 CST 2015\"]}";
59                 
60                 Error err = new Error();
61                 err.setText("Hello");
62                 err.getVariables().add("I'm a teapot");
63                 err.setMessageId("12");
64                 
65                 
66 //              System.out.println(msg);
67                 RosettaEnv env = new RosettaEnv();
68                 RosettaDF<aaf.v2_0.Error> errDF = env.newDataFactory(aaf.v2_0.Error.class);
69                 errDF.in(RosettaData.TYPE.JSON);
70                 errDF.out(RosettaData.TYPE.JSON);
71                 RosettaData<Error> data = errDF.newData();
72                 data.load(err);
73                 System.out.println(data.asString());
74                 
75                 data.load(new StringReader(msg));
76                 err = data.asObject();
77                 System.out.println(err.getText());
78         }
79                 
80
81 }