Search in sources :

Example 1 with ViewFactory

use of org.kie.workbench.common.stunner.svg.gen.model.ViewFactory in project kie-wb-common by kiegroup.

the class SVGViewDefinitionGeneratorTest method testGenerate.

@Test
public void testGenerate() throws Exception {
    final ViewFactory viewFactory = new ViewFactoryImpl("view1", "org.kie.test", "MyType.¢lass");
    final RectDefinition mainDef = new RectDefinition("rect1", 1, 2, 0);
    final CircleDefinition circleDefinition = new CircleDefinition("circle1", 25);
    final ViewDefinitionImpl viewDefinition = new ViewDefinitionImpl(ID, X, Y, WIDTH, HEIGHT, styleSheetDefinition, new ViewBoxDefinitionImpl(VBOX_MIN_X, VBOX_MIN_Y, VBOX_WIDTH, VBOX_HEIGHT), mainDef, circleDefinition);
    viewDefinition.setFactoryMethodName("svgViewTest");
    viewDefinition.setPath("svg-view-test.svg");
    final String generated = tested.generate(viewFactory, viewDefinition).toString();
    assertTrue(generated.contains("public SVGShapeViewResource svgViewTest()"));
    assertTrue(generated.contains("private SVGShapeView svgViewTestView(final boolean resizable)"));
    assertTrue(generated.contains("return this.svgViewTestView(25.50d, 225.45d, resizable);"));
    assertTrue(generated.contains("private SVGShapeView svgViewTestView(final double width, final double height, final boolean resizable) {"));
    assertTrue(generated.contains("final SVGShapeViewImpl view = new SVGShapeViewImpl(\"viewDef1\", mainShape, width, height, resizable)"));
    assertTrue(generated.contains("private SVGBasicShapeView svgViewTestBasicView() {"));
    assertTrue(generated.contains("return this.svgViewTestBasicView(25.50d, 225.45d);"));
    assertTrue(generated.contains("private SVGBasicShapeView svgViewTestBasicView(final double width, final double height) {"));
    assertTrue(generated.contains("final SVGBasicShapeViewImpl view = new SVGBasicShapeViewImpl(\"viewDef1\", mainShape, width, height)"));
}
Also used : CircleDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.CircleDefinition) ViewDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl) ViewFactoryImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewFactoryImpl) ViewFactory(org.kie.workbench.common.stunner.svg.gen.model.ViewFactory) ViewBoxDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewBoxDefinitionImpl) RectDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.RectDefinition) Test(org.junit.Test)

Example 2 with ViewFactory

use of org.kie.workbench.common.stunner.svg.gen.model.ViewFactory in project kie-wb-common by kiegroup.

the class SVGGeneratorImplTest method testGenerate.

@Test
public void testGenerate() throws Exception {
    when(viewDefinition.getId()).thenReturn("svg-cancel");
    doAnswer(new Answer<StringBuffer>() {

        @Override
        public StringBuffer answer(final InvocationOnMock invocationOnMock) throws Throwable {
            final ViewFactory factoryArgument = (ViewFactory) invocationOnMock.getArguments()[0];
            assertEquals(SVG_NAME, factoryArgument.getSimpleName());
            assertEquals(SVG_PKG, factoryArgument.getPackage());
            assertEquals(SVG_FQCN, factoryArgument.getImplementedType());
            assertTrue(factoryArgument.getViewDefinitions().size() == 1);
            assertEquals(viewDefinition, factoryArgument.getViewDefinitions().get(0));
            return new StringBuffer("done");
        }
    }).when(viewFactoryGenerator).generate(any(ViewFactory.class));
    final SVGGeneratorRequest request = new SVGGeneratorRequest(SVG_NAME, SVG_PKG, SVG_FQCN, "", mock(Messager.class));
    request.getViewSources().put(SVG_CANCEL_NAME, SVG_CANCEL_PATH);
    tested.generate(request);
    verify(viewDefinition, times(1)).setFactoryMethodName(eq(SVG_CANCEL_NAME));
    verify(viewFactoryGenerator, times(1)).generate(any(ViewFactory.class));
}
Also used : SVGGeneratorRequest(org.kie.workbench.common.stunner.svg.gen.SVGGeneratorRequest) Messager(javax.annotation.processing.Messager) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ViewFactory(org.kie.workbench.common.stunner.svg.gen.model.ViewFactory) Test(org.junit.Test)

Example 3 with ViewFactory

use of org.kie.workbench.common.stunner.svg.gen.model.ViewFactory in project kie-wb-common by kiegroup.

the class SVGViewDefinitionGeneratorTest method testCheckReferencesExist.

@Test(expected = RuntimeException.class)
public void testCheckReferencesExist() throws Exception {
    final ViewFactory viewFactory = new ViewFactoryImpl("view1", "org.kie.test", "MyType.¢lass");
    final RectDefinition mainDef = new RectDefinition("rect1", 1, 2, 0);
    final CircleDefinition circleDefinition = new CircleDefinition("circle1", 25);
    final ViewDefinitionImpl viewDefinition = new ViewDefinitionImpl(ID, X, Y, WIDTH, HEIGHT, styleSheetDefinition, new ViewBoxDefinitionImpl(VBOX_MIN_X, VBOX_MIN_Y, VBOX_WIDTH, VBOX_HEIGHT), null, mainDef, circleDefinition);
    viewDefinition.setFactoryMethodName("svgViewTest");
    viewDefinition.setPath("svg-view-test.svg");
    final ViewRefDefinition refDefinition = new ViewRefDefinitionImpl("#circle1", "rect1", "circle1", "circle1");
    viewDefinition.getSVGViewRefs().add(refDefinition);
    tested.generate(viewFactory, viewDefinition).toString();
}
Also used : CircleDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.CircleDefinition) ViewRefDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewRefDefinitionImpl) ViewDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl) ViewFactoryImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewFactoryImpl) ViewFactory(org.kie.workbench.common.stunner.svg.gen.model.ViewFactory) ViewRefDefinition(org.kie.workbench.common.stunner.svg.gen.model.ViewRefDefinition) ViewBoxDefinitionImpl(org.kie.workbench.common.stunner.svg.gen.model.impl.ViewBoxDefinitionImpl) RectDefinition(org.kie.workbench.common.stunner.svg.gen.model.impl.RectDefinition) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 ViewFactory (org.kie.workbench.common.stunner.svg.gen.model.ViewFactory)3 CircleDefinition (org.kie.workbench.common.stunner.svg.gen.model.impl.CircleDefinition)2 RectDefinition (org.kie.workbench.common.stunner.svg.gen.model.impl.RectDefinition)2 ViewBoxDefinitionImpl (org.kie.workbench.common.stunner.svg.gen.model.impl.ViewBoxDefinitionImpl)2 ViewDefinitionImpl (org.kie.workbench.common.stunner.svg.gen.model.impl.ViewDefinitionImpl)2 ViewFactoryImpl (org.kie.workbench.common.stunner.svg.gen.model.impl.ViewFactoryImpl)2 Messager (javax.annotation.processing.Messager)1 SVGGeneratorRequest (org.kie.workbench.common.stunner.svg.gen.SVGGeneratorRequest)1 ViewRefDefinition (org.kie.workbench.common.stunner.svg.gen.model.ViewRefDefinition)1 ViewRefDefinitionImpl (org.kie.workbench.common.stunner.svg.gen.model.impl.ViewRefDefinitionImpl)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1