use of au.gov.asd.tac.constellation.graph.schema.visual.VertexDecorators in project constellation by constellation-app.
the class DecoratorsAttributeInteraction method getDisplayText.
@Override
public String getDisplayText(final Object value) {
if (value == null) {
return null;
}
final VertexDecorators decoratorsVal = ((VertexDecorators) value);
final StringBuilder decoratorsString = new StringBuilder();
if (decoratorsVal.getNorthWestDecoratorAttribute() != null) {
decoratorsString.append(String.format("NW: %s, ", decoratorsVal.getNorthWestDecoratorAttribute()));
}
if (decoratorsVal.getNorthEastDecoratorAttribute() != null) {
decoratorsString.append(String.format("NE: %s, ", decoratorsVal.getNorthEastDecoratorAttribute()));
}
if (decoratorsVal.getSouthEastDecoratorAttribute() != null) {
decoratorsString.append(String.format("SE: %s, ", decoratorsVal.getSouthEastDecoratorAttribute()));
}
if (decoratorsVal.getSouthWestDecoratorAttribute() != null) {
decoratorsString.append(String.format("SW: %s, ", decoratorsVal.getSouthWestDecoratorAttribute()));
}
return decoratorsString.length() > 0 ? decoratorsString.substring(0, decoratorsString.length() - 2) : decoratorsString.toString();
}
use of au.gov.asd.tac.constellation.graph.schema.visual.VertexDecorators in project constellation by constellation-app.
the class DecoratorsIOProviderNGTest method testWriteObject.
/**
* Test of writeObject method, of class DecoratorsIOProvider.
*/
@Test
public void testWriteObject() throws Exception {
System.out.println("DecoratorsIOProviderNGTest.testWriteObject");
// int attributeId = 23;
// int elementId = 41;
// String attrType = "attrType";
// String attrName = "attrName";
// String attrDesc = "attrDesc";
// GraphAttribute attr = new GraphAttribute(attributeId, GraphElementType.GRAPH, attrType, attrName, attrDesc, null, null);
// Test not verbose and graph.IsDefaultValue is true skips all processing
resetMocking();
when(mockGraphReadMethods.isDefaultValue(anyInt(), anyInt())).thenReturn(true);
instance.writeObject(attr, elementId, mockJsonGenerator, mockGraphReadMethods, null, false);
Mockito.verify(mockGraphReadMethods, times(0)).getObjectValue(anyInt(), anyInt());
// Test not verbose but graph.IsDefaultValue is false, graph.getObjectValue returns null
resetMocking();
when(mockGraphReadMethods.isDefaultValue(anyInt(), anyInt())).thenReturn(false);
when(mockGraphReadMethods.getObjectValue(anyInt(), anyInt())).thenReturn(null);
instance.writeObject(attr, elementId, mockJsonGenerator, mockGraphReadMethods, null, false);
Mockito.verify(mockGraphReadMethods, times(1)).getObjectValue(attributeId, elementId);
Mockito.verify(mockJsonGenerator, times(1)).writeNullField(attr.getName());
Mockito.verify(mockJsonGenerator, times(0)).writeObjectFieldStart(any());
// Test verbose and graph.IsDefaultValue is false, graph.getObjectValue returns null
resetMocking();
when(mockGraphReadMethods.isDefaultValue(anyInt(), anyInt())).thenReturn(false);
when(mockGraphReadMethods.getObjectValue(anyInt(), anyInt())).thenReturn(null);
instance.writeObject(attr, elementId, mockJsonGenerator, mockGraphReadMethods, null, true);
Mockito.verify(mockGraphReadMethods, times(1)).getObjectValue(attributeId, elementId);
Mockito.verify(mockJsonGenerator, times(1)).writeNullField(attr.getName());
Mockito.verify(mockJsonGenerator, times(0)).writeObjectFieldStart(any());
// Test verbose and graph.IsDefaultValue is true, graph.getObjectValue returns decotrator object
resetMocking();
when(mockGraphReadMethods.isDefaultValue(anyInt(), anyInt())).thenReturn(true);
when(mockGraphReadMethods.getObjectValue(anyInt(), anyInt())).thenReturn(new VertexDecorators("NW", "NE", "SE", "SW"));
instance.writeObject(attr, elementId, mockJsonGenerator, mockGraphReadMethods, null, true);
Mockito.verify(mockJsonGenerator, times(0)).writeNullField(any());
Mockito.verify(mockJsonGenerator, times(1)).writeObjectFieldStart(attr.getName());
Mockito.verify(mockJsonGenerator, times(4)).writeStringField(captorField.capture(), captorValue.capture());
assertEquals(captorField.getAllValues().get(0), "north_west");
assertEquals(captorValue.getAllValues().get(0), "NW");
assertEquals(captorField.getAllValues().get(1), "north_east");
assertEquals(captorValue.getAllValues().get(1), "NE");
assertEquals(captorField.getAllValues().get(2), "south_east");
assertEquals(captorValue.getAllValues().get(2), "SE");
assertEquals(captorField.getAllValues().get(3), "south_west");
assertEquals(captorValue.getAllValues().get(3), "SW");
}
use of au.gov.asd.tac.constellation.graph.schema.visual.VertexDecorators in project constellation by constellation-app.
the class DecoratorsIOProvider method writeObject.
/**
* Write this object to the JSON generator.
* <p>
* Refer to base class for detailed description.
*
* @param attr The attribute being written.
* @param elementId The id of the element being written.
* @param jsonGenerator The JsonGenerator used to write to the JSON document.
* @param graph The graph that the object belongs to. Provided in case the object requires some
* graph data.
* @param byteWriter (not used) For ancillary data (e.g. images) that doesn't easily
* fit into a JSON document.
* @param verbose Determines whether to write default values of attributes or not.
* @throws IOException
*/
@Override
public void writeObject(final Attribute attr, final int elementId, final JsonGenerator jsonGenerator, final GraphReadMethods graph, final GraphByteWriter byteWriter, final boolean verbose) throws IOException {
if (verbose || !graph.isDefaultValue(attr.getId(), elementId)) {
final VertexDecorators decorators = graph.getObjectValue(attr.getId(), elementId);
if (decorators == null) {
jsonGenerator.writeNullField(attr.getName());
} else {
jsonGenerator.writeObjectFieldStart(attr.getName());
jsonGenerator.writeStringField(NORTH_WEST, decorators.getNorthWestDecoratorAttribute());
jsonGenerator.writeStringField(NORTH_EAST, decorators.getNorthEastDecoratorAttribute());
jsonGenerator.writeStringField(SOUTH_EAST, decorators.getSouthEastDecoratorAttribute());
jsonGenerator.writeStringField(SOUTH_WEST, decorators.getSouthWestDecoratorAttribute());
jsonGenerator.writeEndObject();
}
}
}
use of au.gov.asd.tac.constellation.graph.schema.visual.VertexDecorators in project constellation by constellation-app.
the class DecoratorsAttributeDescriptionNGTest method testConvertFromString.
/**
* Test of convertFromString method, of class DecoratorsAttributeDescription.
*/
@Test
public void testConvertFromString() {
System.out.println("convertFromString");
final DecoratorsAttributeDescription instance = new DecoratorsAttributeDescription();
final VertexDecorators nullResult = instance.convertFromString(null);
// should be the default here
assertEquals(nullResult, VertexDecorators.NO_DECORATORS);
final VertexDecorators blankResult = instance.convertFromString(" ");
// should be the default here as well
assertEquals(blankResult, VertexDecorators.NO_DECORATORS);
final VertexDecorators validResult = instance.convertFromString("\"decorator1\";\"decorator2\";\"decorator3\";\"decorator4\";");
final VertexDecorators expResult = new VertexDecorators("decorator1", "decorator2", "decorator3", "decorator4");
assertEquals(validResult.getNorthEastDecoratorAttribute(), expResult.getNorthEastDecoratorAttribute());
assertEquals(validResult.getNorthWestDecoratorAttribute(), expResult.getNorthWestDecoratorAttribute());
assertEquals(validResult.getSouthEastDecoratorAttribute(), expResult.getSouthEastDecoratorAttribute());
assertEquals(validResult.getSouthWestDecoratorAttribute(), expResult.getSouthWestDecoratorAttribute());
}
use of au.gov.asd.tac.constellation.graph.schema.visual.VertexDecorators in project constellation by constellation-app.
the class DecoratorsAttributeInteractionNGTest method testGetDisplayText.
/**
* Test of getDisplayText method, of class DecoratorsAttributeInteraction.
*/
@Test
public void testGetDisplayText() {
System.out.println("getDisplayText");
final DecoratorsAttributeInteraction instance = new DecoratorsAttributeInteraction();
final String nullResult = instance.getDisplayText(null);
assertNull(nullResult);
final VertexDecorators nullDecorators = new VertexDecorators(null, null, null, null);
final String nullDecoratorsResult = instance.getDisplayText(nullDecorators);
assertEquals(nullDecoratorsResult, "");
final VertexDecorators decorators = new VertexDecorators("testAttribute1", "testAttribute2", "testAttribute3", "testAttribute4");
final String decoratorsResult = instance.getDisplayText(decorators);
assertEquals(decoratorsResult, "NW: testAttribute1, NE: testAttribute2, SE: testAttribute3, SW: testAttribute4");
}
Aggregations