use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.
the class AbstractGraphLabelsIOProviderNGTest method testWriteObject.
/**
* Test of writeObject method, of class AbstractGraphLabelsIOProvider.
*/
@Test
public void testWriteObject() throws Exception {
System.out.println("AbstractGraphLabelsIOProviderNGTest.testWriteObject");
// Test case where not verbose and default graph value
resetMocking();
when(mockGraphReadMethods.isDefaultValue(attributeId, elementId)).thenReturn(true);
instance.writeObject(attr, elementId, mockJsonGenerator, mockGraphReadMethods, null, false);
Mockito.verify(mockGraphReadMethods, times(0)).getObjectValue(anyInt(), anyInt());
// Test case where not verbose and not default graph value
resetMocking();
when(mockGraphReadMethods.isDefaultValue(attributeId, elementId)).thenReturn(false);
when(mockGraphReadMethods.getObjectValue(attributeId, elementId)).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)).writeArrayFieldStart(anyString());
// Test case where verbose and default graph value
final List<GraphLabel> labels = new ArrayList<>();
labels.add(new GraphLabel("test_name1", ConstellationColor.RED, 0.1f));
labels.add(new GraphLabel("test_name2", ConstellationColor.BLUE, 0.2f));
resetMocking();
when(mockGraphReadMethods.isDefaultValue(attributeId, elementId)).thenReturn(true);
when(mockGraphReadMethods.getObjectValue(attributeId, elementId)).thenReturn(new GraphLabels(labels));
instance.writeObject(attr, elementId, mockJsonGenerator, mockGraphReadMethods, null, true);
Mockito.verify(mockGraphReadMethods, times(1)).getObjectValue(attributeId, elementId);
Mockito.verify(mockJsonGenerator, times(0)).writeNullField(anyString());
Mockito.verify(mockJsonGenerator, times(1)).writeArrayFieldStart(attr.getName());
Mockito.verify(mockJsonGenerator, times(2)).writeStartObject();
Mockito.verify(mockJsonGenerator, times(1)).writeStringField("attribute_name", "test_name1");
Mockito.verify(mockJsonGenerator, times(1)).writeStringField("attribute_name", "test_name2");
Mockito.verify(mockJsonGenerator, times(2)).writeObjectFieldStart("color");
Mockito.verify(mockJsonGenerator, times(1)).writeNumberField("radius", 0.1f);
Mockito.verify(mockJsonGenerator, times(1)).writeNumberField("radius", 0.2f);
Mockito.verify(mockJsonGenerator, times(4)).writeEndObject();
// Test case where verbose and not default graph value
resetMocking();
when(mockGraphReadMethods.isDefaultValue(attributeId, elementId)).thenReturn(false);
when(mockGraphReadMethods.getObjectValue(attributeId, elementId)).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)).writeArrayFieldStart(anyString());
}
use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.
the class TransactionGraphLabelsAttributeDescriptionNGTest method testConvertFromString.
/**
* Test of convertFromString method, of class TransactionGraphLabelsAttributeDescription.
*/
@Test
public void testConvertFromString() {
System.out.println("convertFromString");
final TransactionGraphLabelsAttributeDescription instance = new TransactionGraphLabelsAttributeDescription();
final GraphLabels nullResult = instance.convertFromString(null);
// should be the default here
assertEquals(nullResult, GraphLabels.NO_LABELS);
final GraphLabels blankResult = instance.convertFromString(" ");
// should be the default here as well
assertEquals(blankResult, GraphLabels.NO_LABELS);
final GraphLabels validResult = instance.convertFromString("Label1;Blue;1|Label2;Red;2|Label3;Yellow;3");
assertEquals(validResult.getNumberOfLabels(), 3);
final List<GraphLabel> validResultLabels = validResult.getLabels();
assertEquals(validResultLabels.get(0).toString(), "Label1;Blue;1.0");
assertEquals(validResultLabels.get(1).toString(), "Label2;Red;2.0");
assertEquals(validResultLabels.get(2).toString(), "Label3;Yellow;3.0");
}
use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.
the class VertexGraphLabelsAttributeDescriptionNGTest method testConvertFromString.
/**
* Test of convertFromString method, of class VertexGraphLabelsAttributeDescription.
*/
@Test
public void testConvertFromString() {
System.out.println("convertFromString");
final VertexGraphLabelsAttributeDescription instance = new VertexGraphLabelsAttributeDescription();
final GraphLabels nullResult = instance.convertFromString(null);
// should be the default here
assertEquals(nullResult, GraphLabels.NO_LABELS);
final GraphLabels blankResult = instance.convertFromString(" ");
// should be the default here as well
assertEquals(blankResult, GraphLabels.NO_LABELS);
final GraphLabels validResult = instance.convertFromString("Label1;Blue;1|Label2;Red;2|Label3;Yellow;3");
assertEquals(validResult.getNumberOfLabels(), 3);
final List<GraphLabel> validResultLabels = validResult.getLabels();
assertEquals(validResultLabels.get(0).toString(), "Label1;Blue;1.0");
assertEquals(validResultLabels.get(1).toString(), "Label2;Red;2.0");
assertEquals(validResultLabels.get(2).toString(), "Label3;Yellow;3.0");
}
use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.
the class GraphVisualAccess method recalculateConnectionLabels.
private void recalculateConnectionLabels(final ReadableGraph readGraph) {
final GraphLabels connectionLabels = graphConnectionLabels != Graph.NOT_FOUND ? readGraph.getObjectValue(graphConnectionLabels, 0) : VisualGraphDefaults.DEFAULT_CONNECTION_LABELS;
final int numLabels = connectionLabels.getNumberOfLabels();
connectionLabelAttrs = new int[numLabels];
connectionLabelSizes = new float[numLabels];
connectionLabelColors = new ConstellationColor[numLabels];
int i = 0;
for (final GraphLabel label : connectionLabels.getLabels()) {
connectionLabelAttrs[i] = readGraph.getAttribute(GraphElementType.TRANSACTION, label.getAttributeName());
connectionLabelSizes[i] = label.getSize();
connectionLabelColors[i] = label.getColor() != null ? label.getColor() : VisualGraphDefaults.DEFAULT_LABEL_COLOR;
i++;
}
}
use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel in project constellation by constellation-app.
the class GraphVisualAccess method recalculateTopLabels.
private void recalculateTopLabels(final ReadableGraph readGraph) {
final GraphLabels topLabels = graphTopLabels != Graph.NOT_FOUND ? readGraph.getObjectValue(graphTopLabels, 0) : VisualGraphDefaults.DEFAULT_TOP_LABELS;
final int numLabels = topLabels.getNumberOfLabels();
topLabelAttrs = new int[numLabels];
topLabelSizes = new float[numLabels];
topLabelColors = new ConstellationColor[numLabels];
int i = 0;
for (final GraphLabel label : topLabels.getLabels()) {
topLabelAttrs[i] = readGraph.getAttribute(GraphElementType.VERTEX, label.getAttributeName());
topLabelSizes[i] = label.getSize();
topLabelColors[i] = label.getColor() != null ? label.getColor() : VisualGraphDefaults.DEFAULT_LABEL_COLOR;
i++;
}
}
Aggregations