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());
}
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));
}
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());
}
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());
}
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);
}
}
}