Search in sources :

Example 6 with GraphLabel

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());
}
Also used : ArrayList(java.util.ArrayList) GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel) Test(org.testng.annotations.Test)

Example 7 with GraphLabel

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");
}
Also used : GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel) Test(org.testng.annotations.Test)

Example 8 with GraphLabel

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");
}
Also used : GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel) Test(org.testng.annotations.Test)

Example 9 with GraphLabel

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++;
    }
}
Also used : GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)

Example 10 with GraphLabel

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++;
    }
}
Also used : GraphLabels(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels) GraphLabel(au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)

Aggregations

GraphLabel (au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)16 GraphLabels (au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels)16 ArrayList (java.util.ArrayList)5 Test (org.testng.annotations.Test)4 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)2 VisualConcept (au.gov.asd.tac.constellation.graph.schema.visual.concept.VisualConcept)2 ConstellationColor (au.gov.asd.tac.constellation.utilities.color.ConstellationColor)2 Arrays (java.util.Arrays)2 List (java.util.List)2 ServiceProvider (org.openide.util.lookup.ServiceProvider)2 Graph (au.gov.asd.tac.constellation.graph.Graph)1 GraphConstants (au.gov.asd.tac.constellation.graph.GraphConstants)1 GraphWriteMethods (au.gov.asd.tac.constellation.graph.GraphWriteMethods)1 StoreGraph (au.gov.asd.tac.constellation.graph.StoreGraph)1 BooleanAttributeDescription (au.gov.asd.tac.constellation.graph.attribute.BooleanAttributeDescription)1 FloatAttributeDescription (au.gov.asd.tac.constellation.graph.attribute.FloatAttributeDescription)1 StringAttributeDescription (au.gov.asd.tac.constellation.graph.attribute.StringAttributeDescription)1 InteractiveGraphPluginRegistry (au.gov.asd.tac.constellation.graph.interaction.InteractiveGraphPluginRegistry)1 SchemaFactory (au.gov.asd.tac.constellation.graph.schema.SchemaFactory)1 SchemaFactoryUtilities (au.gov.asd.tac.constellation.graph.schema.SchemaFactoryUtilities)1