ViewUtil { public static void removeProperties(final View view, final Element element) { if (null != view && null != element) { removeProperties(view.getElement(element.getGroup()), element); } } private  ViewUtil(); static void removeProperties(final View view, final Element element); static void removeProperties(final ViewElementDefinition elDef, final Element element); static void removeProperties(final ViewElementDefinition elDef, final Properties properties); static View removeGroups(final View view, final String... groups);  }
@Test public void shouldNotRemovePropertiesWhenNotSet() { final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .allProperties() .build()) .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .properties(TestPropertyNames.PROP_2) .build()) .build(); final Edge edge = new Edge.Builder() .group(TestGroups.EDGE) .property(TestPropertyNames.PROP_1, "1") .property(TestPropertyNames.PROP_2, "2") .property(TestPropertyNames.PROP_3, "3") .build(); ViewUtil.removeProperties(view, edge); assertEquals(3, edge.getProperties().size()); assertEquals("1", edge.getProperties().get(TestPropertyNames.PROP_1)); assertEquals("2", edge.getProperties().get(TestPropertyNames.PROP_2)); assertEquals("3", edge.getProperties().get(TestPropertyNames.PROP_3)); }
@Test public void shouldNotRemovePropertiesWhenNoRelevantExcludeProperties() { final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .excludeProperties(TestPropertyNames.COUNT) .build()) .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .properties(TestPropertyNames.PROP_2) .build()) .build(); final Edge edge = new Edge.Builder() .group(TestGroups.EDGE) .property(TestPropertyNames.PROP_1, "1") .property(TestPropertyNames.PROP_2, "2") .property(TestPropertyNames.PROP_3, "3") .build(); ViewUtil.removeProperties(view, edge); assertEquals(3, edge.getProperties().size()); assertEquals("1", edge.getProperties().get(TestPropertyNames.PROP_1)); assertEquals("2", edge.getProperties().get(TestPropertyNames.PROP_2)); assertEquals("3", edge.getProperties().get(TestPropertyNames.PROP_3)); }
@Test public void shouldNotRemoveAllPropertiesWhenNoRelevantProperties() { final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .properties(TestPropertyNames.COUNT) .build()) .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .properties(TestPropertyNames.PROP_2) .build()) .build(); final Edge edge = new Edge.Builder() .group(TestGroups.EDGE) .property(TestPropertyNames.PROP_1, "1") .property(TestPropertyNames.PROP_2, "2") .property(TestPropertyNames.PROP_3, "3") .build(); ViewUtil.removeProperties(view, edge); assertEquals(0, edge.getProperties().size()); }
@Test public void shouldKeepOnlyProvidedProperties() { final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .properties(TestPropertyNames.PROP_1) .build()) .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .properties(TestPropertyNames.PROP_2) .build()) .build(); final Edge edge = new Edge.Builder() .group(TestGroups.EDGE) .property(TestPropertyNames.PROP_1, "1") .property(TestPropertyNames.PROP_2, "2") .property(TestPropertyNames.PROP_3, "3") .build(); ViewUtil.removeProperties(view, edge); assertEquals(1, edge.getProperties().size()); assertEquals("1", edge.getProperties().get(TestPropertyNames.PROP_1)); }
@Test public void shouldRemoveExcludedProperties() { final View view = new View.Builder() .edge(TestGroups.EDGE, new ViewElementDefinition.Builder() .excludeProperties(TestPropertyNames.PROP_1) .build()) .entity(TestGroups.ENTITY, new ViewElementDefinition.Builder() .excludeProperties(TestPropertyNames.PROP_2) .build()) .build(); final Edge edge = new Edge.Builder() .group(TestGroups.EDGE) .property(TestPropertyNames.PROP_1, "1") .property(TestPropertyNames.PROP_2, "2") .property(TestPropertyNames.PROP_3, "3") .build(); ViewUtil.removeProperties(view, edge); assertEquals(2, edge.getProperties().size()); assertEquals("2", edge.getProperties().get(TestPropertyNames.PROP_2)); assertEquals("3", edge.getProperties().get(TestPropertyNames.PROP_3)); }