Skip to content

Commit

Permalink
!314 @EnableMybatisPlusPlugin单元测试
Browse files Browse the repository at this point in the history
Merge pull request !314 from KamToHung/my-test
  • Loading branch information
VampireAchao authored and gitee-org committed Apr 18, 2023
2 parents 5db9ff3 + e7413c4 commit 3f07580
Show file tree
Hide file tree
Showing 11 changed files with 482 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.dromara.streamquery.stream.plugin.mybatisplus.annotation;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.test.context.junit.jupiter.SpringExtension;

/**
* MybatisPlusTestApplication less Create Retrieve Update Delete
*
* @author VampireAchao Cizai_
* @since 2022/5/21
*/
@ExtendWith(SpringExtension.class)
public abstract class AbstractMybatisPlusTestApplication {

protected ConfigurableApplicationContext context;

@BeforeEach
void before() {
context = SpringApplication.run(this.getClass());
}

@AfterEach
void after() {
context.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.dromara.streamquery.stream.plugin.mybatisplus.annotation;

import org.dromara.streamquery.stream.plugin.mybatisplus.engine.annotation.EnableMybatisPlusPlugin;
import org.dromara.streamquery.stream.plugin.mybatisplus.engine.annotation.GenerateMapper;
import org.dromara.streamquery.stream.plugin.mybatisplus.engine.configuration.StreamScannerConfigurer;
import org.dromara.streamquery.stream.plugin.mybatisplus.engine.mapper.IGenerateMapper;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.RoleInfo;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.UserInfo;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.UserRole;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.inner.AddressInfo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* EnableMybatisPlusPluginByClassesTest
*
* @author <a href = "[email protected]">KamTo Hung</a>
*/
@EnableAutoConfiguration
@EnableMybatisPlusPlugin(
basePackages = "org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po",
annotation = GenerateMapper.class,
interfaceClass = IGenerateMapper.class)
public class EnableMybatisPlusPluginByAnnotationAndInterfaceClassTest
extends AbstractMybatisPlusTestApplication {

@Test
void testScanByValue() {
StreamScannerConfigurer bean = context.getBean(StreamScannerConfigurer.class);
assertNotNull(bean);
assertNotNull(bean.getEntityClasses());
assertTrue(bean.getEntityClasses().contains(RoleInfo.class));
assertTrue(bean.getEntityClasses().contains(UserInfo.class));
assertFalse(bean.getEntityClasses().contains(UserRole.class));
assertTrue(bean.getEntityClasses().contains(AddressInfo.class));
assertFalse(bean.getEntityClasses().contains(AddressInfo.InnerAddressInfo.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.dromara.streamquery.stream.plugin.mybatisplus.annotation;

import org.dromara.streamquery.stream.plugin.mybatisplus.engine.annotation.EnableMybatisPlusPlugin;
import org.dromara.streamquery.stream.plugin.mybatisplus.engine.annotation.GenerateMapper;
import org.dromara.streamquery.stream.plugin.mybatisplus.engine.configuration.StreamScannerConfigurer;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.RoleInfo;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.UserInfo;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.UserRole;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.inner.AddressInfo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* EnableMybatisPlusPluginByClassesTest
*
* @author <a href = "[email protected]">KamTo Hung</a>
*/
@EnableAutoConfiguration
@EnableMybatisPlusPlugin(
basePackages = "org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po",
annotation = GenerateMapper.class)
public class EnableMybatisPlusPluginByAnnotationTest extends AbstractMybatisPlusTestApplication {

@Test
void testScanByValue() {
StreamScannerConfigurer bean = context.getBean(StreamScannerConfigurer.class);
assertNotNull(bean);
assertNotNull(bean.getEntityClasses());
assertTrue(bean.getEntityClasses().contains(RoleInfo.class));
assertFalse(bean.getEntityClasses().contains(UserInfo.class));
assertFalse(bean.getEntityClasses().contains(UserRole.class));
assertTrue(bean.getEntityClasses().contains(AddressInfo.class));
assertFalse(bean.getEntityClasses().contains(AddressInfo.InnerAddressInfo.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.dromara.streamquery.stream.plugin.mybatisplus.annotation;

import org.dromara.streamquery.stream.plugin.mybatisplus.engine.annotation.EnableMybatisPlusPlugin;
import org.dromara.streamquery.stream.plugin.mybatisplus.engine.configuration.StreamScannerConfigurer;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.RoleInfo;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.UserInfo;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.UserRole;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.inner.AddressInfo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* EnableMybatisPlusPluginByBasePackageClassesTest
*
* @author <a href = "[email protected]">KamTo Hung</a>
*/
@EnableAutoConfiguration
@EnableMybatisPlusPlugin(basePackageClasses = {UserInfo.class})
public class EnableMybatisPlusPluginByBasePackageClassesTest
extends AbstractMybatisPlusTestApplication {

@Test
void testScanByValue() {
StreamScannerConfigurer bean = context.getBean(StreamScannerConfigurer.class);
assertNotNull(bean);
assertNotNull(bean.getEntityClasses());
assertTrue(bean.getEntityClasses().contains(RoleInfo.class));
assertTrue(bean.getEntityClasses().contains(UserInfo.class));
assertTrue(bean.getEntityClasses().contains(UserRole.class));
assertTrue(bean.getEntityClasses().contains(AddressInfo.class));
assertFalse(bean.getEntityClasses().contains(AddressInfo.InnerAddressInfo.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.dromara.streamquery.stream.plugin.mybatisplus.annotation;

import org.dromara.streamquery.stream.plugin.mybatisplus.engine.annotation.EnableMybatisPlusPlugin;
import org.dromara.streamquery.stream.plugin.mybatisplus.engine.configuration.StreamScannerConfigurer;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.RoleInfo;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.UserInfo;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.UserRole;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.inner.AddressInfo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* EnableMybatisPlusPluginByBasePackagesGeneralTest
*
* @author <a href = "[email protected]">KamTo Hung</a>
*/
@EnableAutoConfiguration
@EnableMybatisPlusPlugin(basePackages = "org.dromara.streamquery.stream.plugin.*.pojo.po")
public class EnableMybatisPlusPluginByBasePackagesGeneralTest
extends AbstractMybatisPlusTestApplication {

@Test
void testScanByValue() {
StreamScannerConfigurer bean = context.getBean(StreamScannerConfigurer.class);
assertNotNull(bean);
assertNotNull(bean.getEntityClasses());
assertTrue(bean.getEntityClasses().contains(RoleInfo.class));
assertTrue(bean.getEntityClasses().contains(UserInfo.class));
assertTrue(bean.getEntityClasses().contains(UserRole.class));
assertTrue(bean.getEntityClasses().contains(AddressInfo.class));
assertFalse(bean.getEntityClasses().contains(AddressInfo.InnerAddressInfo.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.dromara.streamquery.stream.plugin.mybatisplus.annotation;

import org.dromara.streamquery.stream.plugin.mybatisplus.engine.annotation.EnableMybatisPlusPlugin;
import org.dromara.streamquery.stream.plugin.mybatisplus.engine.configuration.StreamScannerConfigurer;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.RoleInfo;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.UserInfo;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.UserRole;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.inner.AddressInfo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* EnableMybatisPlusPluginByBasePackagesTest
*
* @author <a href = "[email protected]">KamTo Hung</a>
*/
@EnableAutoConfiguration
@EnableMybatisPlusPlugin(basePackages = "org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po")
public class EnableMybatisPlusPluginByBasePackagesTest extends AbstractMybatisPlusTestApplication {

@Test
void testScanByValue() {
StreamScannerConfigurer bean = context.getBean(StreamScannerConfigurer.class);
assertNotNull(bean);
assertNotNull(bean.getEntityClasses());
assertTrue(bean.getEntityClasses().contains(RoleInfo.class));
assertTrue(bean.getEntityClasses().contains(UserInfo.class));
assertTrue(bean.getEntityClasses().contains(UserRole.class));
assertTrue(bean.getEntityClasses().contains(AddressInfo.class));
assertFalse(bean.getEntityClasses().contains(AddressInfo.InnerAddressInfo.class));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.dromara.streamquery.stream.plugin.mybatisplus.annotation;

import org.dromara.streamquery.stream.plugin.mybatisplus.engine.annotation.EnableMybatisPlusPlugin;
import org.dromara.streamquery.stream.plugin.mybatisplus.engine.configuration.StreamScannerConfigurer;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.RoleInfo;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.UserInfo;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.UserRole;
import org.dromara.streamquery.stream.plugin.mybatisplus.pojo.po.inner.AddressInfo;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* EnableMybatisPlusPluginByClassesTest
*
* @author <a href = "[email protected]">KamTo Hung</a>
*/
@EnableAutoConfiguration
@EnableMybatisPlusPlugin(classes = {UserInfo.class})
public class EnableMybatisPlusPluginByClassesTest extends AbstractMybatisPlusTestApplication {

@Test
void testScanByValue() {
StreamScannerConfigurer bean = context.getBean(StreamScannerConfigurer.class);
assertNotNull(bean);
assertNotNull(bean.getEntityClasses());
assertFalse(bean.getEntityClasses().contains(RoleInfo.class));
assertTrue(bean.getEntityClasses().contains(UserInfo.class));
assertFalse(bean.getEntityClasses().contains(UserRole.class));
assertFalse(bean.getEntityClasses().contains(AddressInfo.class));
assertFalse(bean.getEntityClasses().contains(AddressInfo.InnerAddressInfo.class));
}
}
Loading

0 comments on commit 3f07580

Please sign in to comment.