TabularDataExtractor implements Extractor { public Class getType() { return TabularData.class; }  Class getType(); Object extractObject(ObjectToJsonConverter pConverter, Object pValue,
                                Stack<String> pPathParts,boolean pJsonify); Object setObjectValue(StringToObjectConverter pConverter, Object pInner, String pAttribute, Object pValue); boolean canSetValue();  }
@Test public void extractMapWithComplexType() throws OpenDataException, AttributeNotFoundException { CompositeTypeAndJson cdj = new CompositeTypeAndJson(STRING, "name", "roland", INTEGER, "date", 1968); TabularData data = getMapTabularData(cdj.getType(),cdj.getCompositeData(),TEST_VALUE); JSONObject result = (JSONObject) extract(true,data); assertEquals(result.size(), 2); assertTrue(result.containsKey("indexNames")); assertTrue(result.containsKey("values")); List indexNames = (List) result.get("indexNames"); assertEquals(indexNames.size(), 1); assertTrue(indexNames.contains("key")); List values = (List) result.get("values"); assertEquals(values.size(),1); JSONObject value = (JSONObject) values.get(0); JSONObject key = (JSONObject) value.get("key"); assertEquals(key.get("name"),"roland"); assertEquals(key.get("date"),1968); assertEquals(key.size(), 2); assertEquals(value.get("value"), TEST_VALUE); assertEquals(key.size(),2); }
@Test void extractGenericTabularDataWithJsonEmpty() throws OpenDataException, AttributeNotFoundException { CompositeTypeAndJson ctj = new CompositeTypeAndJson( STRING,"name",null, STRING,"firstname",null, INTEGER,"age",null, BOOLEAN,"male",null ); TabularTypeAndJson taj = new TabularTypeAndJson(new String[] { "name", "firstname" },ctj); TabularData data = new TabularDataSupport(taj.getType()); JSONObject result = (JSONObject) extract(true, data); assertTrue(result.isEmpty()); }
@Test void extractGenericTabularDataWithIntegerAndObjectNamePath() throws OpenDataException, AttributeNotFoundException, MalformedObjectNameException { TabularTypeAndJson taj = new TabularTypeAndJson( new String[] { "bundleId", "oName" }, new CompositeTypeAndJson( LONG,"bundleId",null, OBJECTNAME,"oName",null, BOOLEAN,"active",null )); TabularData data = new TabularDataSupport(taj.getType()); data.put(new CompositeDataSupport( taj.getType().getRowType(), new String[]{"bundleId", "oName", "active"}, new Object[]{10L,new ObjectName("test:type=bundle"), false} )); JSONObject result = (JSONObject) extract(true, data, "10", "test:type=bundle"); assertEquals(result.size(),3); assertEquals(result.get("bundleId"),10L); assertEquals(result.get("active"),false); }
@Test public void extractWithWildCardPath() throws OpenDataException, MalformedObjectNameException, AttributeNotFoundException { TabularTypeAndJson taj = new TabularTypeAndJson( new String[] { "id"}, new CompositeTypeAndJson( LONG,"id",null, OBJECTNAME,"oName",null, BOOLEAN,"flag",null )); TabularData data = new TabularDataSupport(taj.getType()); data.put(new CompositeDataSupport( taj.getType().getRowType(), new String[]{"id","oName","flag" }, new Object[]{10L,new ObjectName("test:type=bundle"), false} )); data.put(new CompositeDataSupport( taj.getType().getRowType(), new String[]{"id","oName","flag" }, new Object[]{20L,new ObjectName("java.lang:type=Memory"), true} )); result = (JSONObject) extract(true, data, null, "oName"); assertEquals(result.size(),2); inner = (JSONObject) result.get(10L); assertEquals(inner.get("domain"),"test"); inner = (JSONObject) result.get(20L); assertEquals(inner.get("domain"),"java.lang"); }
@Test(expectedExceptions = ValueFaultHandler.AttributeFilteredException.class) public void noMatchWithWildcardPattern() throws OpenDataException, MalformedObjectNameException, AttributeNotFoundException { TabularTypeAndJson taj = new TabularTypeAndJson( new String[] { "oName"}, new CompositeTypeAndJson( OBJECTNAME,"oName",null )); TabularData data = new TabularDataSupport(taj.getType()); data.put(new CompositeDataSupport( taj.getType().getRowType(), new String[]{"oName" }, new Object[]{new ObjectName("test:type=bundle")} )); extract(true, data, null, "oName2"); }
@Test(expectedExceptions = IllegalArgumentException.class,expectedExceptionsMessageRegExp = ".*Boolean.*") void extractTabularDataWithPathButWrongIndexType() throws OpenDataException, AttributeNotFoundException { TabularTypeAndJson taj = new TabularTypeAndJson( new String[] { "verein", "absteiger" }, new CompositeTypeAndJson( STRING,"verein",null, INTEGER,"platz",null, BOOLEAN,"absteiger",null )); TabularData data = new TabularDataSupport(taj.getType()); data.put(new CompositeDataSupport( taj.getType().getRowType(), new String[] { "verein", "platz", "absteiger" }, new Object[] { "fcn", 6, false } )); extract(true,data,"fcn","true"); }