DefaultPropertyMapper implements PropertyMapper { @Override public String toCleanName(String propName, String type) { HierarchicalType dataType = getDataType(type); String replacement = m_qualifiedToCleanMap.get(propName); if (replacement == null && dataType != null) { FieldMapping fieldMap = dataType.fieldMapping(); if (! fieldMap.fields.containsKey(propName) && propName.contains(".")) { String cleanName = propName.substring(propName.lastIndexOf('.') + 1); if (fieldMap.fields.containsKey(cleanName)) { replacement = cleanName; } } } if (replacement == null) { replacement = propName; } return replacement; } DefaultPropertyMapper();  DefaultPropertyMapper(Map<String, String> qualifiedToCleanMap,
                                 Map<String, String> cleanToQualifiedMap); @Override String toCleanName(String propName, String type); @Override String toFullyQualifiedName(String propName, String type);  }
@Test public void testToCleanName_defaultMappings() { String typeName = "testType"; HierarchicalType dataType = createNiceMock(HierarchicalType.class); Map<String, AttributeInfo> fields = new HashMap<>(); fields.put("foo", null); fields.put("prop", null); FieldMapping fieldMapping = new FieldMapping(fields, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); expect(dataType.fieldMapping()).andReturn(fieldMapping).anyTimes(); replay(dataType); PropertyMapper propertyMapper = new TestDefaultPropertyMapper(dataType); assertEquals(propertyMapper.toCleanName("Prefix.prop", typeName), "prop"); assertEquals(propertyMapper.toCleanName("foo", typeName), "foo"); assertEquals(propertyMapper.toCleanName("other", typeName), "other"); assertEquals(propertyMapper.toCleanName("Prefix.other", typeName), "Prefix.other"); verify(dataType); }
@Test public void testToCleanName_specifiedMappings() { String typeName = "testType"; HierarchicalType dataType = createNiceMock(HierarchicalType.class); Map<String, AttributeInfo> fields = new HashMap<>(); fields.put("foo", null); fields.put("prop", null); FieldMapping fieldMapping = new FieldMapping(fields, null, null, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); expect(dataType.fieldMapping()).andReturn(fieldMapping).anyTimes(); replay(dataType); Map<String, String> cleanToQualifiedMap = new HashMap<>(); cleanToQualifiedMap.put("prop1", "property_1"); Map<String, String> qualifiedToCleanMap = new HashMap<>(); qualifiedToCleanMap.put("property_1", "prop1"); PropertyMapper propertyMapper = new TestDefaultPropertyMapper( typeName, qualifiedToCleanMap, cleanToQualifiedMap, dataType); assertEquals(propertyMapper.toCleanName("property_1", typeName), "prop1"); assertEquals(propertyMapper.toCleanName("Prefix.prop", typeName), "prop"); assertEquals(propertyMapper.toCleanName("foo", typeName), "foo"); assertEquals(propertyMapper.toCleanName("other", typeName), "other"); assertEquals(propertyMapper.toCleanName("Prefix.other", typeName), "Prefix.other"); verify(dataType); }