Search in sources :

Example 1 with Param

use of com.canoo.platform.remoting.client.Param in project dolphin-platform-examples by canoo.

the class ToDoControllerTests method testElementStateSync.

@Test
public void testElementStateSync() {
    // given:
    ControllerUnderTest<ToDoList> controllerUnderTest = createController(TODO_CONTROLLER_NAME);
    ControllerUnderTest<ToDoList> controllerUnderTest2 = createController(TODO_CONTROLLER_NAME);
    // when:
    controllerUnderTest.getModel().getNewItemText().set("Banana");
    controllerUnderTest.invoke(ADD_ACTION);
    controllerUnderTest.invoke(CHANGE_ACTION, new Param(ITEM_PARAM, "Banana"));
    // then:
    Assert.assertEquals(controllerUnderTest2.getModel().getItems().size(), 1);
    Assert.assertEquals(controllerUnderTest2.getModel().getItems().get(0).isCompleted(), true);
}
Also used : ToDoList(com.canoo.platform.samples.distribution.common.model.ToDoList) Param(com.canoo.platform.remoting.client.Param) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringTestNGControllerTest(com.canoo.platform.spring.test.SpringTestNGControllerTest) Test(org.testng.annotations.Test) ControllerUnderTest(com.canoo.platform.spring.test.ControllerUnderTest)

Example 2 with Param

use of com.canoo.platform.remoting.client.Param in project dolphin-platform-examples by canoo.

the class ToDoControllerTests method testChangeElementState.

@Test
public void testChangeElementState() {
    // given:
    ControllerUnderTest<ToDoList> controllerUnderTest = createController(TODO_CONTROLLER_NAME);
    // when:
    controllerUnderTest.getModel().getNewItemText().set("Banana");
    controllerUnderTest.invoke(ADD_ACTION);
    controllerUnderTest.invoke(CHANGE_ACTION, new Param(ITEM_PARAM, "Banana"));
    // then:
    Assert.assertEquals(controllerUnderTest.getModel().getItems().get(0).isCompleted(), true);
}
Also used : ToDoList(com.canoo.platform.samples.distribution.common.model.ToDoList) Param(com.canoo.platform.remoting.client.Param) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringTestNGControllerTest(com.canoo.platform.spring.test.SpringTestNGControllerTest) Test(org.testng.annotations.Test) ControllerUnderTest(com.canoo.platform.spring.test.ControllerUnderTest)

Example 3 with Param

use of com.canoo.platform.remoting.client.Param in project dolphin-platform-examples by canoo.

the class ToDoControllerTests method testDeleteElement.

@Test
public void testDeleteElement() {
    // given:
    ControllerUnderTest<ToDoList> controllerUnderTest = createController(TODO_CONTROLLER_NAME);
    // when:
    controllerUnderTest.getModel().getNewItemText().set("Banana");
    controllerUnderTest.invoke(ADD_ACTION);
    controllerUnderTest.invoke(REMOVE_ACTION, new Param(ITEM_PARAM, "Banana"));
    // then:
    Assert.assertEquals(controllerUnderTest.getModel().getItems().size(), 0);
}
Also used : ToDoList(com.canoo.platform.samples.distribution.common.model.ToDoList) Param(com.canoo.platform.remoting.client.Param) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) SpringTestNGControllerTest(com.canoo.platform.spring.test.SpringTestNGControllerTest) Test(org.testng.annotations.Test) ControllerUnderTest(com.canoo.platform.spring.test.ControllerUnderTest)

Example 4 with Param

use of com.canoo.platform.remoting.client.Param in project dolphin-platform by canoo.

the class ControllerProxyImpl method invoke.

@Override
public CompletableFuture<Void> invoke(final String actionName, final Param... params) {
    if (destroyed) {
        throw new IllegalStateException("The controller was already destroyed");
    }
    final ClientControllerActionCallBean bean = platformBeanRepository.createControllerActionCallBean(controllerId, actionName, params);
    final CallActionCommand callActionCommand = new CallActionCommand();
    callActionCommand.setControllerId(controllerId);
    callActionCommand.setActionName(actionName);
    if (params != null) {
        for (Param param : params) {
            Object value = param.getValue();
            if (value == null) {
                callActionCommand.addParam(param.getName(), null);
            } else {
                try {
                    callActionCommand.addParam(param.getName(), converters.getConverter(value.getClass()).convertToDolphin(value));
                } catch (ValueConverterException e) {
                    throw new MappingException("Error in value conversion of param '" + param.getName() + "' for action '" + actionName + "'", e);
                }
            }
        }
    }
    final CompletableFuture<Void> result = new CompletableFuture<>();
    clientConnector.send(callActionCommand, () -> {
        if (bean.isError()) {
            result.completeExceptionally(new ControllerActionException("Error on calling action on the server. Please check the server log."));
        } else {
            result.complete(null);
        }
        bean.unregister();
    });
    return result;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ControllerActionException(com.canoo.platform.remoting.client.ControllerActionException) CallActionCommand(com.canoo.dp.impl.remoting.commands.CallActionCommand) Param(com.canoo.platform.remoting.client.Param) ValueConverterException(com.canoo.platform.remoting.spi.converter.ValueConverterException) MappingException(com.canoo.dp.impl.remoting.MappingException)

Example 5 with Param

use of com.canoo.platform.remoting.client.Param in project dolphin-platform by canoo.

the class ActionControllerTest method testCallPublicMethodWithFloatParams.

/**
 * End Long Type Related Integration Test
 */
/**
 * Start Float Type Related Integration Test
 */
@Test(dataProvider = ENDPOINTS_DATAPROVIDER, description = "Tests if an public action method with Float param can be called")
public void testCallPublicMethodWithFloatParams(String containerType, String endpoint) {
    final float value = 10.0F;
    performActionForFloat(containerType, endpoint, PUBLIC_WITH_FLOAT_PARAM_ACTION, value, new Param(PARAM_NAME, value));
}
Also used : Param(com.canoo.platform.remoting.client.Param) Test(org.testng.annotations.Test)

Aggregations

Param (com.canoo.platform.remoting.client.Param)95 Test (org.testng.annotations.Test)94 ControllerUnderTest (com.canoo.platform.spring.test.ControllerUnderTest)49 SpringTestNGControllerTest (com.canoo.platform.spring.test.SpringTestNGControllerTest)49 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)49 BigDecimal (java.math.BigDecimal)8 BigInteger (java.math.BigInteger)8 ActionTestBean (com.canoo.dolphin.integration.action.ActionTestBean)5 ClientContext (com.canoo.platform.remoting.client.ClientContext)5 ToDoList (com.canoo.platform.samples.distribution.common.model.ToDoList)4 ElementType (java.lang.annotation.ElementType)4 Calendar (java.util.Calendar)4 Date (java.util.Date)4 UUID (java.util.UUID)4 MappingException (com.canoo.dp.impl.remoting.MappingException)1 CallActionCommand (com.canoo.dp.impl.remoting.commands.CallActionCommand)1 ControllerActionException (com.canoo.platform.remoting.client.ControllerActionException)1 ValueConverterException (com.canoo.platform.remoting.spi.converter.ValueConverterException)1 CompletableFuture (java.util.concurrent.CompletableFuture)1