Преглед на файлове

解决测试用例不能跑的问题

dev
yeqd преди 4 години
родител
ревизия
2b4203c1e3
променени са 8 файла, в които са добавени 85 реда и са изтрити 78 реда
  1. +1
    -0
      user-client/pom.xml
  2. +3
    -1
      user-client/src/main/java/com/hp/user/client/service/UserAreaService.java
  3. +45
    -18
      user-service/pom.xml
  4. +3
    -4
      user-service/src/main/java/com/hp/user/service/controller/AreaController.java
  5. +0
    -23
      user-service/src/main/java/com/hp/user/service/controller/TestController.java
  6. +3
    -4
      user-service/src/main/java/com/hp/user/service/impl/AreaServiceImpl.java
  7. +30
    -0
      user-service/src/test/java/com/hp/user/service/ControllerTest.java
  8. +0
    -28
      user-service/src/test/java/test/ControllerTest.java

+ 1
- 0
user-client/pom.xml Целия файл

@@ -6,4 +6,5 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>user-client</artifactId>
<version>0.0.2-SNAPSHOT</version>
</project>

user-client/src/main/java/com/hp/user/client/service/AreaService.java → user-client/src/main/java/com/hp/user/client/service/UserAreaService.java Целия файл

@@ -11,7 +11,9 @@ import java.util.List;
*
* @author 王怡静
* @since 2020-11-20
*
* 使用AreaServcie来命名在自动注入bean的时候会保存,不知道和那个类同名了
*/
public interface AreaService{
public interface UserAreaService{
public List<AreaVO> getAllArea();
}

+ 45
- 18
user-service/pom.xml Целия файл

@@ -6,6 +6,7 @@
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>user-service</artifactId>
<packaging>jar</packaging>
<dependencies>
<!-- 内部依赖-->
<dependency>
@@ -17,12 +18,16 @@
<groupId>org.mybatis.spring.boot</groupId>
<artifactId>mybatis-spring-boot-starter</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.hp</groupId>
<artifactId>user-client</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>0.0.2-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.hp</groupId>
@@ -47,6 +52,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
</exclusion>

</exclusions>
</dependency>
@@ -84,21 +93,39 @@


</dependencies>
<!-- <build>-->
<!-- <plugins>-->
<!-- <plugin>-->
<!-- <groupId>org.apache.maven.plugins</groupId>-->
<!-- &lt;!&ndash; 注意打包成war 引入的是 maven-war-plugin,打包为jar则引入的是 maven-jar-plugin &ndash;&gt;-->
<!-- <artifactId>maven-war-plugin</artifactId>-->
<!-- <version>3.2.3</version>-->
<!-- <configuration>-->
<!-- <packagingExcludes>-->
<!-- &lt;!&ndash;war排除conf文件中的properties文件&ndash;&gt;-->
<!-- WEB-INF/conf/*.properties-->
<!-- &lt;!&ndash;排除文件夹下所有的的文件 WEB-INF/classes/config/** &ndash;&gt;-->
<!-- </packagingExcludes>-->
<!-- </configuration>-->
<!-- </plugin>-->
<!-- </plugins>-->
<!-- </build>-->
<!-- <properties>
<failOnMissingWebXml>false</failOnMissingWebXml>
</properties> -->
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<!-- <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>com.xxg.Main</mainClass>
</transformer> -->
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

+ 3
- 4
user-service/src/main/java/com/hp/user/service/controller/AreaController.java Целия файл

@@ -1,9 +1,8 @@
package com.hp.user.service.controller;

import com.hp.user.client.entity.AreaVO;
import com.hp.user.client.service.AreaService;
import com.hp.user.service.dao.AreaMapper;
import com.hp.user.service.entity.Area;
import com.hp.user.client.service.UserAreaService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@@ -15,7 +14,7 @@ import java.util.List;
public class AreaController {

@Autowired
private AreaService areaService;
private UserAreaService areaService;

/**
* 查询所有地区


+ 0
- 23
user-service/src/main/java/com/hp/user/service/controller/TestController.java Целия файл

@@ -1,23 +0,0 @@
package com.hp.user.service.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.hp.user.service.TestService;

/*
@RestController
public class TestController {
@Autowired
private TestService userService;
@RequestMapping("getUser/{id}")
public String GetUser(@PathVariable int id){
return userService.Sel(id).getName().toString();
}

}
*/


+ 3
- 4
user-service/src/main/java/com/hp/user/service/impl/AreaServiceImpl.java Целия файл

@@ -1,9 +1,8 @@
package com.hp.user.service.impl;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hp.user.client.entity.AreaVO;
import com.hp.user.client.service.UserAreaService;
import com.hp.user.service.entity.Area;
import com.hp.user.client.service.AreaService;
import com.hp.user.service.dao.AreaMapper;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
@@ -20,8 +19,8 @@ import java.util.List;
* @author 王怡静
* @since 2020-11-20
*/
@Service
public class AreaServiceImpl implements AreaService {
@Service("area")
public class AreaServiceImpl implements UserAreaService {
@Autowired
private AreaMapper areaMapper;
@Override


+ 30
- 0
user-service/src/test/java/com/hp/user/service/ControllerTest.java Целия файл

@@ -0,0 +1,30 @@
package com.hp.user.service;

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.junit4.SpringRunner;

import com.hp.user.client.entity.AreaVO;
import com.hp.user.client.service.UserAreaService;

import java.util.List;

@SpringBootTest
@RunWith(SpringRunner.class)
//这个class的路径要注意,要和需要注入的一些bean文件的最外层,不如会出现文件扫描不到的情况
//从测试结果来看这边回去找服务的启动类UserServiceApplaction
public class ControllerTest {
@Autowired
private UserAreaService areaService;

@Test
public void testQueryAllArea() {
List<AreaVO> users = areaService.getAllArea();
users.forEach(System.out::println);
}
}

+ 0
- 28
user-service/src/test/java/test/ControllerTest.java Целия файл

@@ -1,28 +0,0 @@
package test;

import com.alibaba.nacos.spring.context.annotation.config.NacosPropertySource;
import com.hp.user.client.entity.AreaVO;
import com.hp.user.service.controller.AreaController;

import org.junit.Test;

import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;

import javax.annotation.Resource;
import java.util.List;
@NacosPropertySource(dataId = "userdatasource", autoRefreshed = true)
@RunWith(SpringRunner.class)
@SpringBootTest
public class ControllerTest {
@Resource
private AreaController areaController;


@Test
public void testQueryAllArea() {
List<AreaVO> users = areaController.queryAllArea();
users.forEach(System.out::println);
}
}

Зареждане…
Отказ
Запис