blob: abfa5606c4777a2e51a2f4d400744841c86e8278 [file] [log] [blame]
/**
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.streamnative.pulsar.manager.dao;
import com.github.pagehelper.Page;
import io.streamnative.pulsar.manager.PulsarManagerApplication;
import io.streamnative.pulsar.manager.entity.TenantEntity;
import io.streamnative.pulsar.manager.entity.TenantsRepository;
import io.streamnative.pulsar.manager.profiles.SqliteDBTestProfile;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import java.util.List;
@RunWith(SpringRunner.class)
@SpringBootTest(
classes = {
PulsarManagerApplication.class,
SqliteDBTestProfile.class
}
)
@ActiveProfiles("test")
public class TenantsRepositoryImplTest {
@Autowired
private TenantsRepository tenantsRepository;
@Test
public void getTenantsListTest() {
for (int i = 0; i < 10; i++) {
TenantEntity tenantsEntity = new TenantEntity(i, "test" + i, "testrole", "testCluster");
tenantsRepository.save(tenantsEntity);
}
Page<TenantEntity> tenantsEntities = tenantsRepository.getTenantsList(1, 10);
tenantsEntities.count(true);
long total = tenantsEntities.getTotal();
Assert.assertEquals(total, 10);
List<TenantEntity> tenantsEntityList = tenantsEntities.getResult();
for (int i = 0; i < total; i ++) {
TenantEntity tenantsEntity = tenantsEntityList.get(i);
Assert.assertEquals(tenantsEntity.getTenantId(), i);
Assert.assertEquals(tenantsEntity.getTenant(), "test" + i);
Assert.assertEquals(tenantsEntity.getAdminRoles(), "testrole");
Assert.assertEquals(tenantsEntity.getAllowedClusters(), "testCluster");
}
tenantsEntities.getResult().forEach((result) -> {
tenantsRepository.remove(result.getTenantId());
});
}
}