Search in sources :

Example 6 with GraphLabels

use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels in project constellation by constellation-app.

the class VertexGraphLabelsAttributeInteractionNGTest method testGetDisplayText.

/**
 * Test of getDisplayText method, of class VertexGraphLabelsAttributeInteraction.
 */
@Test
public void testGetDisplayText() {
    System.out.println("getDisplayText");
    final VertexGraphLabelsAttributeInteraction instance = new VertexGraphLabelsAttributeInteraction();
    final String nullResult = instance.getDisplayText(null);
    assertNull(nullResult);
    final GraphLabels emptyLabels = new GraphLabels(Collections.emptyList());
    final String emptyGraphLabelsResult = instance.getDisplayText(emptyLabels);
    assertEquals(emptyGraphLabelsResult, "");
    final GraphLabel testLabel1 = new GraphLabel("test1", ConstellationColor.BANANA, 5F);
    final GraphLabel testLabel2 = new GraphLabel("test2", ConstellationColor.getColorValue(0.1F, 0.2F, 0.3F, 1F), 7F);
    final GraphLabels labels = new GraphLabels(Arrays.asList(testLabel1, testLabel2));
    final String graphLabelsResult = instance.getDisplayText(labels);
    assertEquals(graphLabelsResult, "test1: (Banana), test2: (#19334c)");
}
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 7 with GraphLabels

use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels 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 8 with GraphLabels

use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels 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 9 with GraphLabels

use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels 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 10 with GraphLabels

use of au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels 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)

Aggregations

GraphLabels (au.gov.asd.tac.constellation.graph.schema.visual.GraphLabels)20 GraphLabel (au.gov.asd.tac.constellation.graph.schema.visual.GraphLabel)16 ArrayList (java.util.ArrayList)6 Test (org.testng.annotations.Test)6 GraphElementType (au.gov.asd.tac.constellation.graph.GraphElementType)2 VertexDecorators (au.gov.asd.tac.constellation.graph.schema.visual.VertexDecorators)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 GraphAttribute (au.gov.asd.tac.constellation.graph.GraphAttribute)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