1e40cf3be52ad91867d287b08eed0ab09288316b
[portal/sdk.git] /
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * ECOMP is a trademark and service mark of AT&T Intellectual Property.
37  */
38 package org.onap.portalsdk.analytics.xmlobj;
39
40 import static org.junit.Assert.*;
41 import javax.xml.namespace.QName;
42
43 import java.io.IOException;
44 import java.io.InputStream;
45 import java.io.OutputStream;
46 import java.io.Reader;
47 import java.io.StringReader;
48 import java.io.Writer;
49 import java.sql.Clob;
50 import java.sql.Connection;
51 import java.sql.PreparedStatement;
52 import java.sql.ResultSet;
53 import java.sql.ResultSetMetaData;
54 import java.sql.SQLException;
55 import java.util.*;
56
57 import javax.servlet.http.HttpServletRequest;
58 import javax.servlet.http.HttpServletResponse;
59 import javax.servlet.http.HttpSession;
60 import javax.xml.bind.JAXBContext;
61 import javax.xml.bind.JAXBElement;
62 import javax.xml.bind.JAXBException;
63 import javax.xml.bind.Marshaller;
64 import javax.xml.bind.Unmarshaller;
65
66 import org.hibernate.Session;
67 import org.junit.Before;
68 import org.junit.Test;
69 import org.junit.runner.RunWith;
70 import org.mockito.InjectMocks;
71 import org.mockito.Matchers;
72 import org.mockito.Mock;
73 import org.mockito.Mockito;
74 import org.mockito.MockitoAnnotations;
75 import org.onap.portalsdk.analytics.error.RaptorException;
76 import org.onap.portalsdk.analytics.model.ReportLoader;
77 import org.onap.portalsdk.analytics.model.base.ReportWrapper;
78 import org.onap.portalsdk.analytics.model.runtime.ChartJSONHelper;
79 import org.onap.portalsdk.analytics.model.runtime.FormField;
80 import org.onap.portalsdk.analytics.model.runtime.ReportFormFields;
81 import org.onap.portalsdk.analytics.model.runtime.ReportRuntime;
82 import org.onap.portalsdk.analytics.system.AppUtils;
83 import org.onap.portalsdk.analytics.system.DbUtils;
84 import org.onap.portalsdk.analytics.system.Globals;
85 import org.onap.portalsdk.analytics.util.AppConstants;
86 import org.onap.portalsdk.analytics.util.DataSet;
87 import org.onap.portalsdk.analytics.xmlobj.CustomReportType;
88 import org.onap.portalsdk.core.domain.User;
89 import org.onap.portalsdk.core.restful.domain.EcompRole;
90 import org.onap.portalsdk.core.web.support.UserUtils;
91 import org.powermock.api.mockito.PowerMockito;
92 import org.powermock.core.classloader.annotations.PrepareForTest;
93 import org.powermock.modules.junit4.PowerMockRunner;
94
95 import com.fasterxml.jackson.databind.ObjectMapper;
96
97 @RunWith(PowerMockRunner.class)
98 @PrepareForTest({UserUtils.class,AppUtils.class, DbUtils.class, ReportRuntime.class, Globals.class, UserUtils.class,ReportLoader.class})
99 public class ChartJSONHelperTest {
100     
101         @InjectMocks
102         ChartJSONHelper chartJSONHelper= new ChartJSONHelper();
103         
104         @Mock
105         Connection connection;
106         @Mock
107         PreparedStatement stmt;
108         @Mock
109         ResultSet rs ;
110         @Mock
111         java.sql.Clob clob;
112         @Mock
113         InputStream in;
114         
115         @Before
116         public void setup() {
117                 MockitoAnnotations.initMocks(this);
118         }
119
120         MockitoTestSuite mockitoTestSuite = new MockitoTestSuite();
121         HttpServletRequest mockedRequest = mockitoTestSuite.getMockedRequest();
122         HttpServletResponse mockedResponse = mockitoTestSuite.getMockedResponse();
123
124         
125         @Test(expected = java.lang.ClassCastException.class)
126         public void generateJSONTest() throws RaptorException, Exception
127         {
128                 EcompRole role = new EcompRole();
129                 mockedRequest.getSession().setAttribute("test", role);
130                 Set<String> set = new HashSet<String>(); 
131                 set.add("test");
132             Enumeration<String> x = new IteratorEnumeration<String>(set.iterator());
133                 Mockito.when(mockedRequest.getSession().getAttributeNames()).thenReturn(x);
134                 
135                 User user = new User();
136                 user.setOrgUserId("test12");
137                 PowerMockito.mockStatic(UserUtils.class);
138                 Mockito.when(UserUtils.getUserId(mockedRequest)).thenReturn(3); 
139                 PowerMockito.mockStatic(AppUtils.class);
140                 Mockito.when(mockedRequest.getParameter(AppConstants.RI_REFRESH)).thenReturn("yes");
141                 Mockito.when(AppUtils.getRequestFlag(mockedRequest,"display_content")).thenReturn(true);
142                 Mockito.when(AppUtils.getRequestFlag(mockedRequest, "noFormFields")).thenReturn(true);
143                 PowerMockito.mockStatic(ReportLoader.class);
144                 String str = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CustomReportType xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xs:string\"><reportName>name</reportName><reportDescr>desc</reportDescr><chartType>type</chartType><showChartTitle>false</showChartTitle><public>false</public><createId>id</createId><pageNav>false</pageNav></CustomReportType>";
145         Mockito.when(ReportLoader.loadCustomReportXML("1")).thenReturn(str);
146        
147                 ReportRuntime rr = mockReportRunTime1();
148                 rr.setChartType("BarChart3D");
149                 rr.setMultiSeries(true);
150                 rr.setDashboardType(true);
151                 Mockito.when(mockedRequest.getSession().getAttribute("report_runtime")).thenReturn(rr);
152                 
153                 PowerMockito.mockStatic(Globals.class);
154                 PowerMockito.mockStatic(DbUtils.class);
155
156                 Mockito.when(Globals.getReportUserAccess()).thenReturn("test");
157                 ResultSet rs = PowerMockito.mock(ResultSet.class);
158                 ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
159                 Mockito.when(rsmd.getColumnCount()).thenReturn(1);
160                 Mockito.when(rs.getMetaData()).thenReturn(rsmd);
161                 DataSet datset = PowerMockito.mock(DataSet.class);
162                 Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
163                 Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
164                 Mockito.when(Globals.getNewScheduleData()).thenReturn("test");
165                 Mockito.when(DbUtils.getConnection()).thenReturn(connection);
166                 Mockito.when(Globals.getLoadCustomReportXml()).thenReturn("java.lang.String");
167                 Mockito.when(connection.prepareStatement("test")).thenReturn(stmt);
168                 Mockito.when(stmt.executeQuery()).thenReturn(rs);
169                 Mockito.when(Globals.isWeblogicServer()).thenReturn(true);
170                 Mockito.when(rs.getClob(1)).thenReturn(clob);
171                 Mockito.when(rs.next()).thenReturn(true);
172                 Mockito.when(clob.getAsciiStream()).thenReturn(in);
173                 Mockito.when(in.read(Matchers.any())).thenReturn(1);
174 //               PowerMockito.mockStatic(ReportRuntime.class);
175               Mockito.when(ReportRuntime.unmarshal(str, "1", mockedRequest)).thenReturn(rr);
176                         Mockito.when(AppUtils.getRequestNvlValue(mockedRequest, "pdfAttachmentKey")).thenReturn("test");
177                         Mockito.when(AppUtils.nvl(rr.getLegendLabelAngle())).thenReturn("standard");
178                         Mockito.when(AppUtils.getRequestNvlValue(Matchers.any(), Matchers.anyString())).thenReturn("test");
179                         Mockito.when(AppUtils.nvl("Y")).thenReturn("Y");
180                         Mockito.when(AppUtils.nvl("bottom")).thenReturn("Y");
181                         Mockito.when(AppUtils.nvl("test")).thenReturn("test|");
182                         Mockito.when(AppUtils.getRequestValue(mockedRequest, "c_dashboard")).thenReturn("1");
183                         Mockito.when(ReportLoader.isDashboardType("-1")).thenReturn(false);
184                 assertEquals(chartJSONHelper.generateJSON("1", mockedRequest, false).getClass(), String.class);
185         }
186         
187         
188         @Test(expected = java.lang.NullPointerException.class)
189         public void generateJSONTest1() throws RaptorException, Exception
190         {
191                 EcompRole role = new EcompRole();
192                 mockedRequest.getSession().setAttribute("test", role);
193                 
194                 Set<String> set = new HashSet<String>(); 
195             Enumeration<String> x = new IteratorEnumeration<String>(set.iterator());
196                 Mockito.when(mockedRequest.getSession().getAttributeNames()).thenReturn(x);
197                 User user = new User();
198                 user.setOrgUserId("test12");
199                 PowerMockito.mockStatic(UserUtils.class);
200                 Mockito.when(UserUtils.getUserId(mockedRequest)).thenReturn(3); 
201                 PowerMockito.mockStatic(AppUtils.class);
202                 Mockito.when(mockedRequest.getParameter(AppConstants.RI_REFRESH)).thenReturn("yes");
203                 Mockito.when(AppUtils.getRequestFlag(mockedRequest,AppConstants.RI_DISPLAY_CONTENT)).thenReturn(true);
204                 Mockito.when(AppUtils.getRequestFlag(mockedRequest, "noFormFields")).thenReturn(false);
205                 PowerMockito.mockStatic(ReportLoader.class);
206             ReportRuntime rr = mockReportRunTime();
207                 PowerMockito.mockStatic(Globals.class);
208                 PowerMockito.mockStatic(DbUtils.class);
209
210                 Mockito.when(Globals.getReportUserAccess()).thenReturn("test");
211                 ResultSet rs = PowerMockito.mock(ResultSet.class);
212                 ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
213                 Mockito.when(rsmd.getColumnCount()).thenReturn(1);
214                 Mockito.when(rs.getMetaData()).thenReturn(rsmd);
215                 DataSet datset = PowerMockito.mock(DataSet.class);
216                 Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
217                 Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
218                 Mockito.when(Globals.getNewScheduleData()).thenReturn("test");
219                 CustomReportType customReportType = new CustomReportType();
220                 Mockito.when(DbUtils.getConnection()).thenReturn(connection);
221                 Mockito.when(Globals.getLoadCustomReportXml()).thenReturn("test");
222                 Mockito.when(connection.prepareStatement("test")).thenReturn(stmt);
223                 Mockito.when(stmt.executeQuery()).thenReturn(rs);
224                 Mockito.when(Globals.isWeblogicServer()).thenReturn(false);
225                 Mockito.when(Globals.isPostgreSQL()).thenReturn(true);
226                 Mockito.when(rs.getClob(1)).thenReturn(clob);
227                 Mockito.when(rs.next()).thenReturn(true);
228                 Mockito.when(clob.getAsciiStream()).thenReturn(in);
229                 Mockito.when(in.read(Matchers.any())).thenReturn(1);
230                 Mockito.when(AppUtils.getRequestValue(mockedRequest, AppConstants.RI_DASHBOARD_ID)).thenReturn("test");
231                 mockedRequest.getSession().setAttribute("report_runtime", rr);          
232                 chartJSONHelper.generateJSON("1", mockedRequest, false);
233         }
234         
235         @Test
236         public void generateJSON1Test() throws RaptorException, Exception
237         {
238                 
239                 PowerMockito.mockStatic(Globals.class);
240                 PowerMockito.mockStatic(DbUtils.class);
241
242                 Mockito.when(Globals.getReportUserAccess()).thenReturn("test");
243                 ResultSet rs = PowerMockito.mock(ResultSet.class);
244                 ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
245                 Mockito.when(rsmd.getColumnCount()).thenReturn(1);
246                 Mockito.when(rs.getMetaData()).thenReturn(rsmd);
247                 DataSet datset = PowerMockito.mock(DataSet.class);
248                 Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
249                 Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
250                 Mockito.when(Globals.getNewScheduleData()).thenReturn("test");
251                 CustomReportType customReportType = new CustomReportType();
252                 DataSourceList dataSourceList = new DataSourceList();
253                 List<DataSourceType> list = new ArrayList<>();
254                 DataSourceType dataSourceType = new DataSourceType();
255                 dataSourceType.setTableName("test");
256                 dataSourceType.setRefTableId("1");
257                 List<DataColumnType> dataColumnTypeList = new ArrayList<>();
258                 DataColumnType dataColumnType = new DataColumnType();
259                 dataColumnType.setChartGroup("test");
260                 dataColumnType.setYAxis("test");
261                 dataColumnTypeList.add(dataColumnType);
262                 DataColumnList dataColumnList = new DataColumnList();
263                 dataColumnList.dataColumn = dataColumnTypeList;
264                 dataSourceType.setDataColumnList(dataColumnList);
265                 list.add(dataSourceType);
266                 dataSourceList.dataSource = list;
267                 customReportType.setReportType("test");
268                 customReportType.setDataSourceList(dataSourceList);
269                 ChartAdditionalOptions chartAdditionalOptions = new ChartAdditionalOptions();
270                 chartAdditionalOptions.setLabelAngle("test");
271                 chartAdditionalOptions.setTimeSeriesRender("test");
272                 chartAdditionalOptions.setMultiSeries(false);
273                 customReportType.setChartAdditionalOptions(chartAdditionalOptions);
274                 FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class);
275                 formFieldList.setComment("test");
276                 customReportType.setFormFieldList(formFieldList);
277                 ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1", "1", true);
278                 PowerMockito.mockStatic(UserUtils.class);
279                 ReportRuntime rr = new ReportRuntime(reportWrapper, mockedRequest);
280                 rr.setLegendLabelAngle("test");
281                 rr.setMultiSeries(false);
282                 rr.setChartType("test");
283                 PowerMockito.mockStatic(AppUtils.class);
284                 Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test12");
285                 Mockito.when(AppUtils.nvl("test")).thenReturn("test");
286                 Mockito.when(AppUtils.nvl("N")).thenReturn("Y");
287                 Mockito.when(AppUtils.nvl("bottom")).thenReturn("Y");
288                 Mockito.when(UserUtils.getUserId(mockedRequest)).thenReturn(1);
289                 assertEquals(chartJSONHelper.generateJSON(rr, mockedRequest, false).getClass(), String.class);
290         }
291         
292
293         
294         public ReportRuntime mockReportRunTime() throws Exception
295         {               
296                 PowerMockito.mockStatic(Globals.class);
297                 PowerMockito.mockStatic(DbUtils.class);
298                 Mockito.when(Globals.getReportUserAccess()).thenReturn("test");
299                 ResultSet rs = PowerMockito.mock(ResultSet.class);
300                 ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
301                 Mockito.when(rsmd.getColumnCount()).thenReturn(1);
302                 Mockito.when(rs.getMetaData()).thenReturn(rsmd);
303                 DataSet datset = PowerMockito.mock(DataSet.class);
304                 // datset = new DataSet(rs);
305                 Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
306                 Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
307                 Mockito.when(Globals.getNewScheduleData()).thenReturn("test");
308                 CustomReportType customReportType = new CustomReportType();
309                 DataSourceList dataSourceList = new DataSourceList();
310                 List<DataSourceType> list = new ArrayList<>();
311                 DataSourceType dataSourceType = new DataSourceType();
312                 dataSourceType.setTableName("test");
313                 dataSourceType.setRefTableId("1");
314                 List<DataColumnType> dataColumnTypeList = new ArrayList<>();
315                 DataColumnType dataColumnType = new DataColumnType();
316                 dataColumnType.setChartGroup("test");
317                 dataColumnType.setYAxis("test");
318                 dataColumnType.setColName("test");
319                 dataColumnType.setColOnChart("test");
320                 dataColumnType.setDisplayName("test");
321                 dataColumnTypeList.add(dataColumnType);
322                 DataColumnList dataColumnList = new DataColumnList();
323                 dataColumnList.dataColumn = dataColumnTypeList;
324                 dataSourceType.setDataColumnList(dataColumnList);
325                 list.add(dataSourceType);
326                 dataSourceList.dataSource = list;
327                 customReportType.setReportType("test");
328                 customReportType.setDataSourceList(dataSourceList);
329                 ChartAdditionalOptions chartAdditionalOptions = new ChartAdditionalOptions();
330                 chartAdditionalOptions.setLabelAngle("test");
331                 chartAdditionalOptions.setTimeSeriesRender("test");
332                 chartAdditionalOptions.setMultiSeries(false);
333                 customReportType.setChartAdditionalOptions(chartAdditionalOptions);
334                 FormFieldList formFieldList = PowerMockito.mock(FormFieldList.class);
335                 formFieldList.setComment("test");
336                 customReportType.setFormFieldList(formFieldList);
337                 ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1", "1", true);
338                 PowerMockito.mockStatic(UserUtils.class);
339                 ReportRuntime rr = new ReportRuntime(reportWrapper, mockedRequest);
340                 rr.setLegendLabelAngle("test");
341                 rr.setMultiSeries(false);
342                 rr.setChartType("test");
343                 return rr;
344         }
345         
346         public ReportRuntime mockReportRunTime1() throws Exception
347         {               
348                 PowerMockito.mockStatic(Globals.class);
349                 PowerMockito.mockStatic(DbUtils.class);
350                 Mockito.when(Globals.getReportUserAccess()).thenReturn("test");
351                 ResultSet rs = PowerMockito.mock(ResultSet.class);
352                 ResultSetMetaData rsmd = PowerMockito.mock(ResultSetMetaData.class);
353                 Mockito.when(rsmd.getColumnCount()).thenReturn(1);
354                 Mockito.when(rs.getMetaData()).thenReturn(rsmd);
355                 DataSet datset = PowerMockito.mock(DataSet.class);
356                 // datset = new DataSet(rs);
357                 Mockito.when(datset.getString(Matchers.anyInt(), Matchers.anyInt())).thenReturn(null);
358                 Mockito.when(DbUtils.executeQuery(Matchers.anyString())).thenReturn(datset);
359                 Mockito.when(Globals.getNewScheduleData()).thenReturn("test");
360                 CustomReportType customReportType = new CustomReportType();
361                 DataSourceList dataSourceList = new DataSourceList();
362                 List<DataSourceType> list = new ArrayList<>();
363                 DataSourceType dataSourceType = new DataSourceType();
364                 dataSourceType.setTableName("test");
365                 dataSourceType.setRefTableId("1");
366                 dataSourceType.setTableId("1");
367                 List<DataColumnType> dataColumnTypeList = new ArrayList<>();
368                 DataColumnType dataColumnType = new DataColumnType();
369                 dataColumnType.setChartGroup("test");
370                 dataColumnType.setYAxis("test");
371                 dataColumnType.setColName("[test");
372                 dataColumnType.setColOnChart("LEGEND");
373                 dataColumnType.setDisplayName("chart_total");
374                 dataColumnType.setColId("1");
375                 dataColumnType.setTableId("1");
376                 dataColumnType.setColType("DATE");
377                 dataColumnTypeList.add(dataColumnType);
378                 DataColumnList dataColumnList = new DataColumnList();
379                 dataColumnList.dataColumn = dataColumnTypeList;
380                 dataSourceType.setDataColumnList(dataColumnList);
381                 list.add(dataSourceType);
382                 dataSourceList.dataSource = list;
383                 customReportType.setReportType("test");
384                 customReportType.setReportTitle("test");
385                 customReportType.setDataSourceList(dataSourceList);
386                 ChartAdditionalOptions chartAdditionalOptions = new ChartAdditionalOptions();
387                 chartAdditionalOptions.setLabelAngle("test");
388                 chartAdditionalOptions.setTimeSeriesRender("test");
389                 chartAdditionalOptions.setMultiSeries(false);
390                 customReportType.setChartAdditionalOptions(chartAdditionalOptions);
391                 FormFieldList formFieldList = new FormFieldList();
392                 formFieldList.setComment("test");
393                 List<FormFieldType> formFields = new ArrayList<>();
394                 FormFieldType formFieldType = new FormFieldType();
395                 formFieldType.setFieldId("test");
396                 formFieldType.setColId("1");
397                 formFieldType.setFieldName("test");
398                 formFieldType.setFieldType("type");
399                 formFieldType.setValidationType("validation");
400                 formFieldType.setMandatory("Y");
401                 formFieldType.setDefaultValue("test");
402                 formFields.add(formFieldType);
403                 formFieldList.formField = formFields;
404                 customReportType.setFormFieldList(formFieldList);
405                 ReportWrapper reportWrapper = new ReportWrapper(customReportType, "-1", "test", "testId", "test", "test", "1", "1", true);
406                 PowerMockito.mockStatic(UserUtils.class);
407                 Mockito.when(Globals.getRequestParams()).thenReturn("test");
408                 Mockito.when(Globals.getSessionParams()).thenReturn("test");
409                 Mockito.when(Globals.getSessionParamsForScheduling()).thenReturn("test");
410                 PowerMockito.mockStatic(AppUtils.class);
411                 Mockito.when(AppUtils.getUserID(mockedRequest)).thenReturn("test12");
412                 ReportRuntime rr = new ReportRuntime(reportWrapper, mockedRequest);
413                 rr.setLegendLabelAngle("test");
414                 rr.setMultiSeries(false);
415                 rr.setChartType("test");
416                 return rr;
417         }
418         
419         @Test
420         public void getFlagFromDateStrTest()
421         {       
422                 assertEquals(chartJSONHelper.getFlagFromDateStr("11/11/2000"),3);
423                 assertEquals(chartJSONHelper.getFlagFromDateStr("111, 11/11/2000"),0);
424                 assertEquals(chartJSONHelper.getFlagFromDateStr("00/00/0000"),3);
425         }
426         
427         @Test
428         public void getDateFromDateStrTest()
429         {
430                 Date date = new Date("Sat Nov 11 00:00:00 EST 2000");
431                 assertNull(chartJSONHelper.getDateFromDateStr("111, 11/11/2000"));
432         }
433         
434         @Test
435         public void generateChartSQLTest() throws Exception
436         {
437                 ReportRuntime rr = mockReportRunTime();
438                 rr.setWholeSQL("select * from test");
439                 chartJSONHelper = new ChartJSONHelper(rr);
440                 assertEquals(chartJSONHelper.generateChartSQL("test", mockedRequest),"SELECT 1 a, 1 a_1, 1 FROM test  ORDER BY 1");
441         }
442         
443         @Test
444         public void generateChartSQL1Test() throws Exception
445         {
446                 ReportRuntime rr = mockReportRunTime1();
447                 rr.setWholeSQL("select * from test");
448                 rr.setReportType("Hive");
449                 chartJSONHelper = new ChartJSONHelper(rr);
450                 assertEquals(chartJSONHelper.generateChartSQL("test", mockedRequest),"SELECT TO_CHAR([test, '%m/%d/%Y') 1, TO_CHAR([test, '%m/%d/%Y') 1_1, chart_total chart_total, 1 FROM test ");
451         }
452         
453         public static void main(String[] args) throws Exception {
454                 CustomReportType t = new CustomReportType();
455                 t.setPageNav(false);
456                 t.setReportName("name");
457                 t.setReportDescr("desc");
458                 t.setChartType("type");
459                 t.setCreateId("id");
460                 t.setCreateDate(null);
461                 
462                 ObjectMapper mapper = new ObjectMapper();
463
464                 
465                 EcompRole  role = new EcompRole();
466                 role.setName("test");
467                 role.setId((long) 1);
468                 role.setRoleFunctions(null);
469                 
470                 System.out.println(mapper.writeValueAsString(role));
471                 JAXBContext jc = JAXBContext.newInstance("org.onap.portalsdk.analytics.xmlobj");
472                 JAXBElement<CustomReportType> jaxbElement =
473                                   new JAXBElement(new QName("CustomReportType"), 
474                                                   CustomReportType.class,t);
475                 Unmarshaller u = jc.createUnmarshaller();
476                 StringReader rs = new java.io.StringReader(
477                                 mapper.writeValueAsString(role));
478                 System.out.println(rs);
479                 
480                 Marshaller jaxbMarshaller = jc.createMarshaller();
481                 jaxbMarshaller.marshal(jaxbElement, System.out);
482                 String str = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><CustomReportType xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xsi:type=\"xs:string\"><reportName>name</reportName><reportDescr>desc</reportDescr><chartType>type</chartType><showChartTitle>false</showChartTitle><public>false</public><createId>id</createId><pageNav>false</pageNav></CustomReportType>";
483
484                 javax.xml.bind.JAXBElement<CustomReportType> doc = (javax.xml.bind.JAXBElement<CustomReportType>) u.unmarshal(new java.io.StringReader(
485                                 str));
486                 System.out.println(doc.getValue());
487                         
488         }
489         
490         
491 }
492