Search in sources :

Example 11 with BaseCmd

use of org.apache.cloudstack.api.BaseCmd in project cloudstack by apache.

the class SpecificCmdValidationWorkerTest method testHandle.

@Test
public void testHandle() throws ResourceAllocationException {
    // Prepare
    final BaseCmd cmd = mock(BaseCmd.class);
    final Map<String, String> params = new HashMap<String, String>();
    // Execute
    final SpecificCmdValidationWorker worker = new SpecificCmdValidationWorker();
    worker.handle(new DispatchTask(cmd, params));
    // Assert
    verify(cmd, times(1)).validateSpecificParameters(params);
}
Also used : HashMap(java.util.HashMap) BaseCmd(org.apache.cloudstack.api.BaseCmd) Test(org.junit.Test)

Example 12 with BaseCmd

use of org.apache.cloudstack.api.BaseCmd in project cloudstack by apache.

the class FakeCmdWithRoleAdmin method testHandleWithUnknownParams.

@Test
public void testHandleWithUnknownParams() throws ResourceAllocationException {
    // Prepare
    final String unknownParamKey = "unknownParam";
    final BaseCmd cmd = new FakeCmd();
    final Map<String, String> params = new HashMap<String, String>();
    params.put(ApiConstants.COMMAND, "");
    params.put("addedParam", "");
    params.put(unknownParamKey, "");
    Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
    // Execute
    try {
        driveTest(cmd, params);
    } finally {
        CallContext.unregister();
    }
    // Assert
    assertTrue("There should be error msg, since there is one unknown parameter", loggerOutput.contains(unknownParamKey));
    assertTrue("There should be error msg containing the correct command name", loggerOutput.contains(FAKE_CMD_NAME));
}
Also used : Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) HashMap(java.util.HashMap) BaseCmd(org.apache.cloudstack.api.BaseCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Example 13 with BaseCmd

use of org.apache.cloudstack.api.BaseCmd in project cloudstack by apache.

the class FakeCmdWithRoleAdmin method testHandle.

@Test
public void testHandle() throws ResourceAllocationException {
    // Prepare
    final BaseCmd cmd = new FakeCmd();
    final Map<String, String> params = new HashMap<String, String>();
    params.put(ApiConstants.COMMAND, "");
    params.put(ApiConstants.ACCOUNT_ID, "");
    params.put(ApiConstants.CTX_START_EVENT_ID, "");
    params.put(ApiConstants.COMMAND, "");
    params.put(ApiConstants.CMD_EVENT_TYPE, "");
    params.put(ApiConstants.USERNAME, "");
    params.put(ApiConstants.USER_ID, "");
    params.put(ApiConstants.PASSWORD, "");
    params.put(ApiConstants.DOMAIN, "");
    params.put(ApiConstants.DOMAIN_ID, "");
    params.put(ApiConstants.DOMAIN__ID, "");
    params.put(ApiConstants.SESSIONKEY, "");
    params.put(ApiConstants.RESPONSE, "");
    params.put(ApiConstants.PAGE, "");
    params.put(ApiConstants.USER_API_KEY, "");
    params.put(ApiConstants.API_KEY, "");
    params.put(ApiConstants.PAGE_SIZE, "");
    params.put(ApiConstants.HTTPMETHOD, "");
    params.put(ApiConstants.SIGNATURE, "");
    params.put(ApiConstants.CTX_ACCOUNT_ID, "");
    params.put(ApiConstants.CTX_START_EVENT_ID, "");
    // Make sure it's case insensitive
    params.put(ApiConstants.CTX_START_EVENT_ID, "");
    params.put(ApiConstants.CTX_START_EVENT_ID.toLowerCase(), "");
    params.put(ApiConstants.CTX_USER_ID.toUpperCase(), "");
    params.put(ApiConstants.CTX_USER_ID, "");
    params.put(ApiConstants.UUID, "");
    params.put(ApiConstants.ID, "");
    params.put("_", "");
    params.put("addedParam", "");
    Account account = new AccountVO("testaccount", 1L, "networkdomain", (short) 0, "uuid");
    UserVO user = new UserVO(1, "testuser", "password", "firstname", "lastName", "email", "timezone", UUID.randomUUID().toString(), User.Source.UNKNOWN);
    CallContext.register(user, account);
    // Execute
    try {
        driveTest(cmd, params);
    } finally {
        CallContext.unregister();
    }
    // Assert
    assertEquals("There should be no errors since there are no unknown parameters for this command class", null, loggerOutput);
}
Also used : Account(com.cloud.user.Account) UserVO(com.cloud.user.UserVO) HashMap(java.util.HashMap) BaseCmd(org.apache.cloudstack.api.BaseCmd) AccountVO(com.cloud.user.AccountVO) Test(org.junit.Test)

Aggregations

BaseCmd (org.apache.cloudstack.api.BaseCmd)13 Account (com.cloud.user.Account)6 IOException (java.io.IOException)5 HashMap (java.util.HashMap)5 CloudException (com.cloud.exception.CloudException)4 UserVO (com.cloud.user.UserVO)3 Test (org.junit.Test)3 InvalidParameterValueException (com.cloud.exception.InvalidParameterValueException)2 PermissionDeniedException (com.cloud.exception.PermissionDeniedException)2 ResourceAllocationException (com.cloud.exception.ResourceAllocationException)2 AccountVO (com.cloud.user.AccountVO)2 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)2 ConfigurationException (javax.naming.ConfigurationException)2 Project (net.juniper.contrail.api.types.Project)2 APICommand (org.apache.cloudstack.api.APICommand)2 ServerApiException (org.apache.cloudstack.api.ServerApiException)2 DataCenter (com.cloud.dc.DataCenter)1 Domain (com.cloud.domain.Domain)1 DomainVO (com.cloud.domain.DomainVO)1 AccountLimitException (com.cloud.exception.AccountLimitException)1