Search in sources :

Example 1 with TenantClient

use of com.icthh.xm.ms.entity.web.client.tenant.TenantClient in project xm-ms-entity by xm-online.

the class XmTenantLifecycleServiceUnitTest method testServiceCallFail.

@Test
public void testServiceCallFail() {
    XmEntity xmEntity = getEntity();
    context.put(LepXmEntityMsConstants.BINDING_KEY_SERVICES, Collections.singletonList(SERVICE_NAME));
    TenantClient client = new FailClient();
    tenantClients.add(client);
    xmTenantLifecycleService.changeState(xmEntity, EntityState.ACTIVE.name(), context);
    assertEquals(1, xmEntity.getData().size());
    assertEquals(false, ((ServiceInfo) ((Map) xmEntity.getData().get(SERVICE_NAME)).get("create")).isSuccess());
    assertEquals(EXEC_ERROR, ((ServiceInfo) ((Map) xmEntity.getData().get(SERVICE_NAME)).get("create")).getErrorMessage());
}
Also used : TenantClient(com.icthh.xm.ms.entity.web.client.tenant.TenantClient) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 2 with TenantClient

use of com.icthh.xm.ms.entity.web.client.tenant.TenantClient in project xm-ms-entity by xm-online.

the class XmTenantLifecycleServiceUnitTest method testServiceCallPass.

@Test
public void testServiceCallPass() {
    XmEntity xmEntity = getEntity();
    Map<String, Object> serviceInfo = new HashMap<>();
    Map<String, Object> action = new HashMap<>();
    serviceInfo.put("create", action);
    action.put(SUCCESS_NAME, true);
    xmEntity.getData().put(SERVICE_NAME, serviceInfo);
    context.put(LepXmEntityMsConstants.BINDING_KEY_SERVICES, Collections.singletonList(SERVICE_NAME));
    TenantClient client = new FailClient();
    tenantClients.add(client);
    xmTenantLifecycleService.changeState(xmEntity, EntityState.ACTIVE.name(), context);
    assertEquals(1, xmEntity.getData().size());
    assertEquals(true, ((Map) ((Map) xmEntity.getData().get(SERVICE_NAME)).get("create")).get(SUCCESS_NAME));
}
Also used : HashMap(java.util.HashMap) TenantClient(com.icthh.xm.ms.entity.web.client.tenant.TenantClient) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 3 with TenantClient

use of com.icthh.xm.ms.entity.web.client.tenant.TenantClient in project xm-ms-entity by xm-online.

the class XmTenantLifecycleServiceUnitTest method testServiceCallSuccessWithNullContext.

@Test
public void testServiceCallSuccessWithNullContext() {
    when(applicationProperties.getTenantCreateServiceList()).thenReturn(Collections.singletonList(SERVICE_NAME));
    XmEntity xmEntity = getEntity();
    TenantClient client = new SuccessClient();
    tenantClients.add(client);
    xmTenantLifecycleService.changeState(xmEntity, EntityState.ACTIVE.name(), null);
    assertEquals(1, xmEntity.getData().size());
    assertEquals(true, ((ServiceInfo) ((Map) xmEntity.getData().get(SERVICE_NAME)).get("create")).isSuccess());
}
Also used : TenantClient(com.icthh.xm.ms.entity.web.client.tenant.TenantClient) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 4 with TenantClient

use of com.icthh.xm.ms.entity.web.client.tenant.TenantClient in project xm-ms-entity by xm-online.

the class XmTenantLifecycleServiceUnitTest method testServiceCallSuccess.

@Test
public void testServiceCallSuccess() {
    XmEntity xmEntity = getEntity();
    context.put(LepXmEntityMsConstants.BINDING_KEY_SERVICES, Collections.singletonList(SERVICE_NAME));
    TenantClient client = new SuccessClient();
    tenantClients.add(client);
    xmTenantLifecycleService.changeState(xmEntity, EntityState.ACTIVE.name(), context);
    assertEquals(1, xmEntity.getData().size());
    assertEquals(true, ((ServiceInfo) ((Map) xmEntity.getData().get(SERVICE_NAME)).get("create")).isSuccess());
}
Also used : TenantClient(com.icthh.xm.ms.entity.web.client.tenant.TenantClient) XmEntity(com.icthh.xm.ms.entity.domain.XmEntity) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 5 with TenantClient

use of com.icthh.xm.ms.entity.web.client.tenant.TenantClient in project xm-ms-entity by xm-online.

the class XmTenantLifecycleService method manageClient.

private void manageClient(String serviceName, XmEntity xmEntity, String nextStateKey) {
    if (StringUtils.isNotBlank(serviceName)) {
        TenantClient client = getClient(serviceName);
        String tenantName = xmEntity.getName();
        String currStateKey = xmEntity.getStateKey();
        if (ACTIVE.name().equals(nextStateKey) && CURRENT_STATE_CREATE_ALLOWED.contains(currStateKey)) {
            client.addTenant(new Tenant().tenantKey(tenantName).name(tenantName));
        } else if (ACTIVE.name().equals(nextStateKey) && SUSPENDED.name().equals(currStateKey)) {
            client.manageTenant(tenantName, ACTIVE.name());
        } else if (SUSPENDED.name().equals(nextStateKey) && ACTIVE.name().equals(currStateKey)) {
            client.manageTenant(tenantName, SUSPENDED.name());
        } else if (DELETED.name().equals(nextStateKey)) {
            client.deleteTenant(tenantName);
        }
    }
}
Also used : Tenant(com.icthh.xm.commons.gen.model.Tenant) TenantClient(com.icthh.xm.ms.entity.web.client.tenant.TenantClient)

Aggregations

TenantClient (com.icthh.xm.ms.entity.web.client.tenant.TenantClient)5 XmEntity (com.icthh.xm.ms.entity.domain.XmEntity)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Test (org.junit.Test)4 Tenant (com.icthh.xm.commons.gen.model.Tenant)1