Search in sources :

Example 1 with Tenant

use of com.icthh.xm.commons.gen.model.Tenant in project xm-ms-entity by xm-online.

the class TenantResourceIntTest method createDeleteTenant.

@Test
@Transactional
public void createDeleteTenant() throws Exception {
    Connection connection = dataSource.getConnection();
    // int countXm = countTables(connection, TENANT_SUPER);
    Tenant tenant = new Tenant();
    tenant.setTenantKey(TENANT_NEW);
    // Create tenant
    mockMvc.perform(post(API_ENDPOINT).contentType(TestUtil.APPLICATION_JSON_UTF8).content(TestUtil.convertObjectToJsonBytes(tenant))).andExpect(status().isOk());
    // Check schema created
    ResultSet schemas = connection.getMetaData().getSchemas();
    boolean found = false;
    while (schemas.next()) {
        if (TENANT_NEW.equals(schemas.getString(1))) {
            found = true;
        }
    }
    assertEquals(true, found);
    // Check tables created
    assertTrue(countTables(connection, TENANT_NEW) > 1);
    // delete tenant
    mockMvc.perform(delete(API_ENDPOINT + "{tenantKey}", TENANT_NEW).accept(TestUtil.APPLICATION_JSON_UTF8)).andExpect(status().isOk());
    // Check schema deleted
    ResultSet schemasNew = connection.getMetaData().getSchemas();
    boolean foundDeleted = false;
    while (!foundDeleted && schemasNew.next()) {
        if (TENANT_NEW.equals(schemasNew.getString(1))) {
            foundDeleted = true;
        }
    }
    assertEquals(false, foundDeleted);
}
Also used : Tenant(com.icthh.xm.commons.gen.model.Tenant) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) Test(org.junit.Test) SpringBootTest(org.springframework.boot.test.context.SpringBootTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Tenant

use of com.icthh.xm.commons.gen.model.Tenant 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

Tenant (com.icthh.xm.commons.gen.model.Tenant)2 TenantClient (com.icthh.xm.ms.entity.web.client.tenant.TenantClient)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 Test (org.junit.Test)1 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)1 Transactional (org.springframework.transaction.annotation.Transactional)1