Changeset 3111


Ignore:
Timestamp:
02/01/12 21:50:40 (4 months ago)
Author:
ankitk
Message:

adding license header.

Location:
AnalyzerBeans/trunk/components/json/src
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • AnalyzerBeans/trunk/components/json/src/main/java/org/eobjects/analyzer/beans/ExtractJsonValuesTransformer.java

    r3110 r3111  
     1/** 
     2 * eobjects.org AnalyzerBeans 
     3 * Copyright (C) 2010 eobjects.org 
     4 * 
     5 * This copyrighted material is made available to anyone wishing to use, modify, 
     6 * copy, or redistribute it subject to the terms and conditions of the GNU 
     7 * Lesser General Public License, as published by the Free Software Foundation. 
     8 * 
     9 * This program is distributed in the hope that it will be useful, 
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
     11 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License 
     12 * for more details. 
     13 * 
     14 * You should have received a copy of the GNU Lesser General Public License 
     15 * along with this distribution; if not, write to: 
     16 * Free Software Foundation, Inc. 
     17 * 51 Franklin Street, Fifth Floor 
     18 * Boston, MA  02110-1301  USA 
     19 */ 
    120package org.eobjects.analyzer.beans; 
    221 
  • AnalyzerBeans/trunk/components/json/src/main/java/org/eobjects/analyzer/beans/JsonCreatorTransformer.java

    r3110 r3111  
     1/** 
     2 * eobjects.org AnalyzerBeans 
     3 * Copyright (C) 2010 eobjects.org 
     4 * 
     5 * This copyrighted material is made available to anyone wishing to use, modify, 
     6 * copy, or redistribute it subject to the terms and conditions of the GNU 
     7 * Lesser General Public License, as published by the Free Software Foundation. 
     8 * 
     9 * This program is distributed in the hope that it will be useful, 
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
     11 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License 
     12 * for more details. 
     13 * 
     14 * You should have received a copy of the GNU Lesser General Public License 
     15 * along with this distribution; if not, write to: 
     16 * Free Software Foundation, Inc. 
     17 * 51 Franklin Street, Fifth Floor 
     18 * Boston, MA  02110-1301  USA 
     19 */ 
    120package org.eobjects.analyzer.beans; 
    221 
  • AnalyzerBeans/trunk/components/json/src/test/java/org/eobjects/analyzer/beans/ExtractJsonValuesTransformerTest.java

    r3110 r3111  
     1/** 
     2 * eobjects.org AnalyzerBeans 
     3 * Copyright (C) 2010 eobjects.org 
     4 * 
     5 * This copyrighted material is made available to anyone wishing to use, modify, 
     6 * copy, or redistribute it subject to the terms and conditions of the GNU 
     7 * Lesser General Public License, as published by the Free Software Foundation. 
     8 * 
     9 * This program is distributed in the hope that it will be useful, 
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
     11 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License 
     12 * for more details. 
     13 * 
     14 * You should have received a copy of the GNU Lesser General Public License 
     15 * along with this distribution; if not, write to: 
     16 * Free Software Foundation, Inc. 
     17 * 51 Franklin Street, Fifth Floor 
     18 * Boston, MA  02110-1301  USA 
     19 */ 
    120package org.eobjects.analyzer.beans; 
    221 
     
    423import static org.junit.Assert.assertTrue; 
    524 
    6 import java.util.ArrayList; 
    725import java.util.List; 
    826import java.util.Map; 
     
    1533public class ExtractJsonValuesTransformerTest { 
    1634 
    17     @Test 
    18     public void testExtractJsonValuesTransformerWithoutAnyValidation() { 
    19         InputColumn<String> col1 = new MockInputColumn<String>("jsonDocument", 
    20                 String.class); 
    21         ExtractJsonValuesTransformer transformer = new ExtractJsonValuesTransformer( 
    22                 col1); 
    23         assertEquals(1, transformer.getOutputColumns().getColumnCount()); 
     35        @Test 
     36        public void testExtractJsonValuesTransformerWithoutAnyValidation() { 
     37                InputColumn<String> col1 = new MockInputColumn<String>("jsonDocument", 
     38                                String.class); 
     39                ExtractJsonValuesTransformer transformer = new ExtractJsonValuesTransformer( 
     40                                col1); 
     41                assertEquals(1, transformer.getOutputColumns().getColumnCount()); 
    2442 
    25         String json = "{\"name\":\"shekhar\",\"country\":\"india\"}"; 
     43                String json = "{\"name\":\"shekhar\",\"country\":\"india\"}"; 
    2644 
    27         Map<String, ?>[] values = transformer.transform(new MockInputRow().put( 
    28                 col1, json)); 
    29         assertEquals(1, values.length); 
    30         assertEquals(2, values[0].size()); 
    31         assertEquals("{name=shekhar, country=india}", values[0].toString()); 
    32     } 
     45                Map<String, ?>[] values = transformer.transform(new MockInputRow().put( 
     46                                col1, json)); 
     47                assertEquals(1, values.length); 
     48                assertEquals(2, values[0].size()); 
     49                assertEquals("{name=shekhar, country=india}", values[0].toString()); 
     50        } 
    3351 
    34     @Test 
    35     public void testExtractJsonNumbersAndBooleans() { 
    36         InputColumn<String> col1 = new MockInputColumn<String>("jsonDocument", 
    37                 String.class); 
    38         ExtractJsonValuesTransformer transformer = new ExtractJsonValuesTransformer( 
    39                 col1); 
    40         assertEquals(1, transformer.getOutputColumns().getColumnCount()); 
     52        @Test 
     53        public void testExtractJsonNumbersAndBooleans() { 
     54                InputColumn<String> col1 = new MockInputColumn<String>("jsonDocument", 
     55                                String.class); 
     56                ExtractJsonValuesTransformer transformer = new ExtractJsonValuesTransformer( 
     57                                col1); 
     58                assertEquals(1, transformer.getOutputColumns().getColumnCount()); 
    4159 
    42         String json = "{\"name\":\"kasper\",\"age\":29,\"developer\":true,\"manager\":false,\"balance\":400.17}"; 
     60                String json = "{\"name\":\"kasper\",\"age\":29,\"developer\":true,\"manager\":false,\"balance\":400.17}"; 
    4361 
    44         Map<String, ?>[] values = transformer.transform(new MockInputRow().put( 
    45                 col1, json)); 
     62                Map<String, ?>[] values = transformer.transform(new MockInputRow().put( 
     63                                col1, json)); 
    4664 
    47         assertEquals(1, values.length); 
    48         assertEquals(5, values[0].size()); 
    49         assertEquals("{name=kasper, age=29, developer=true, manager=false, balance=400.17}", 
    50                 values[0].toString()); 
    51     } 
     65                assertEquals(1, values.length); 
     66                assertEquals(5, values[0].size()); 
     67                assertEquals( 
     68                                "{name=kasper, age=29, developer=true, manager=false, balance=400.17}", 
     69                                values[0].toString()); 
     70        } 
    5271 
    53     @Test 
    54     public void shouldReturnEmptyMapWhenNoJsonDocumentExistForColumn() 
    55             throws Exception { 
    56         InputColumn<String> col1 = new MockInputColumn<String>("jsonDocument", 
    57                 String.class); 
    58         ExtractJsonValuesTransformer transformer = new ExtractJsonValuesTransformer( 
    59                 col1); 
    60         assertEquals(1, transformer.getOutputColumns().getColumnCount()); 
    61         Map<String, ?>[] values = transformer.transform(new MockInputRow()); 
    62         assertTrue(values.length == 1); 
    63         assertEquals(true, values[0].isEmpty()); 
    64     } 
     72        @Test 
     73        public void shouldReturnEmptyMapWhenNoJsonDocumentExistForColumn() 
     74                        throws Exception { 
     75                InputColumn<String> col1 = new MockInputColumn<String>("jsonDocument", 
     76                                String.class); 
     77                ExtractJsonValuesTransformer transformer = new ExtractJsonValuesTransformer( 
     78                                col1); 
     79                assertEquals(1, transformer.getOutputColumns().getColumnCount()); 
     80                Map<String, ?>[] values = transformer.transform(new MockInputRow()); 
     81                assertTrue(values.length == 1); 
     82                assertEquals(true, values[0].isEmpty()); 
     83        } 
    6584 
    66     @Test 
    67     public void shouldExtractNestedDocumentsAsCollections() throws Exception { 
    68         InputColumn<String> col1 = new MockInputColumn<String>("jsonDocument", 
    69                 String.class); 
    70         ExtractJsonValuesTransformer transformer = new ExtractJsonValuesTransformer( 
    71                 col1); 
    72         assertEquals(1, transformer.getOutputColumns().getColumnCount()); 
     85        @Test 
     86        public void shouldExtractNestedDocumentsAsCollections() throws Exception { 
     87                InputColumn<String> col1 = new MockInputColumn<String>("jsonDocument", 
     88                                String.class); 
     89                ExtractJsonValuesTransformer transformer = new ExtractJsonValuesTransformer( 
     90                                col1); 
     91                assertEquals(1, transformer.getOutputColumns().getColumnCount()); 
    7392 
    74         String json = "{\"name\":\"shekhar\",\"addresses\":[{\"city\":\"Delhi\",\"country:\":\"India\"},{\"city\":\"Delhi\",\"country:\":\"India\"}],\"emails\":[\"email1\",\"email2\"]}"; 
     93                String json = "{\"name\":\"shekhar\",\"addresses\":[{\"city\":\"Delhi\",\"country:\":\"India\"},{\"city\":\"Delhi\",\"country:\":\"India\"}],\"emails\":[\"email1\",\"email2\"]}"; 
    7594 
    76         Map<String, ?>[] values = transformer.transform(new MockInputRow().put( 
    77                 col1, json)); 
    78         assertEquals(1, values.length); 
    79         Map<String, ?> map = values[0]; 
    80         assertEquals("{name=shekhar, addresses=[{city=Delhi, country:=India}, {city=Delhi, country:=India}], emails=[email1, email2]}", 
    81                 map.toString()); 
     95                Map<String, ?>[] values = transformer.transform(new MockInputRow().put( 
     96                                col1, json)); 
     97                assertEquals(1, values.length); 
     98                Map<String, ?> map = values[0]; 
     99                assertEquals( 
     100                                "{name=shekhar, addresses=[{city=Delhi, country:=India}, {city=Delhi, country:=India}], emails=[email1, email2]}", 
     101                                map.toString()); 
    82102 
    83         assertTrue(map.get("addresses") instanceof List); 
    84         List addresses = (List)map.get("addresses"); 
    85         assertTrue(addresses.get(0) instanceof Map); 
    86         assertTrue(map.get("emails") instanceof List); 
    87     } 
     103                assertTrue(map.get("addresses") instanceof List); 
     104                List addresses = (List) map.get("addresses"); 
     105                assertTrue(addresses.get(0) instanceof Map); 
     106                assertTrue(map.get("emails") instanceof List); 
     107        } 
    88108} 
  • AnalyzerBeans/trunk/components/json/src/test/java/org/eobjects/analyzer/beans/JsonCreatorTransformerTest.java

    r3110 r3111  
     1/** 
     2 * eobjects.org AnalyzerBeans 
     3 * Copyright (C) 2010 eobjects.org 
     4 * 
     5 * This copyrighted material is made available to anyone wishing to use, modify, 
     6 * copy, or redistribute it subject to the terms and conditions of the GNU 
     7 * Lesser General Public License, as published by the Free Software Foundation. 
     8 * 
     9 * This program is distributed in the hope that it will be useful, 
     10 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
     11 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License 
     12 * for more details. 
     13 * 
     14 * You should have received a copy of the GNU Lesser General Public License 
     15 * along with this distribution; if not, write to: 
     16 * Free Software Foundation, Inc. 
     17 * 51 Franklin Street, Fifth Floor 
     18 * Boston, MA  02110-1301  USA 
     19 */ 
    120package org.eobjects.analyzer.beans; 
    221 
Note: See TracChangeset for help on using the changeset viewer.