我正在为下面的 REST 控制器编写单元测试,它采用用户 ID 并向该用户授予权限列表。
@RestController
@RequestMapping("/user")
@Api(value = "User", description = "User API")
public class UserController{
// some code
@RequestMapping(method = RequestMethod.POST, value = "/{userId}/grantAuthz")
@ApiOperation(value = "GrantAuthz", notes = "Grant Authorization")
public Collection<UserEntity.UserAuthz> grantAuthz(@PathVariable("userId") String userId,
@RequestBody ArrayList<String> authorities) {
UserEntity userEntity = userRepository.findOne(userId);
if(userEntity == null) {
//TODO: throw and send resource not found
return null;
}
log.debug("Authorities to be granted to user " + userId + " are : " + authorities);
for(String authz : authorities) …Run Code Online (Sandbox Code Playgroud) 我正在开发一个FontViewer应用程序,它根据所选的字体样式更改文本的字体.
这是我的应用程序的控制器类
public class FXMLDocumentController implements Initializable {
@FXML
private ListView fontListView;
@FXML
private TextArea fontTextArea;
int[] fontSizes = {34, 28, 24, 20, 18, 16, 14, 12, 11, 10, 9, 8, 7, 6};
String fontText = "";
@Override
public void initialize(URL url, ResourceBundle rb) {
ObservableList<String> fontsList = FXCollections.observableArrayList(Font.getFontNames());
fontListView.setItems(fontsList);
}
@FXML
public void handleMouseClickEvent(MouseEvent mouseEvent) {
changeFont();
}
public void changeFont() {
for (int i = 0; i < fontSizes.length; i++) {
fontText += "<p style='font-family:" + fontListView.getSelectionModel().getSelectedItem() + …Run Code Online (Sandbox Code Playgroud) 我有一些Spring测试可以启动应用程序上下文并测试一些服务.我可以使用Maven和IDE运行这些测试.现在我需要在无法访问Maven的其他机器上运行这些测试.我的想法是创建一个测试jar并通过命令行运行它们.
所以我创建了一个自定义Runner来调用我需要的测试类,这些测试将启动Spring Application上下文并测试一些服务.
以下是示例代码:
我的自定义亚军:
public class Main {
public static void main(String[] args) {
System.out.println("Running tests!");
JUnitCore engine = new JUnitCore();
engine.addListener(new TextListener(System.out));
engine.run(SpringSampleTest.class);
}
}
Run Code Online (Sandbox Code Playgroud)
上面的跑步者正在调用此测试
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {AppConfig.class})
public class SpringSampleTest {
@Autowired
TestService testService;
@Test
public void testSimple() {
assertTrue("Test Simple", testService.isValid());
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的配置和服务
@Configuration
@ComponentScan(basePackages = {"mypackage"})
public class AppConfig {
}
@Service
public class TestService {
public boolean isValid() {
return true;
}
}
Run Code Online (Sandbox Code Playgroud)
因此,若要从罐子这些测试中,我用汇编插件来创建一个可执行的JAR,其中包括我的所有测试和依赖关系(感谢这个答案在这里).现在,当我运行这个可执行的JAR,我定制的运行(Main.java)能够触发测试,但它不加载Spring上下文,并与一个空指针异常失败,因为我的依赖不会被自动装配.这是日志:
Running tests!
Sep 05, 2018 …Run Code Online (Sandbox Code Playgroud) 当通过企业代理后面的 maven-front-end 插件运行 yarn install 时,安装在目标“yarn”失败,并出现以下错误:
[ERROR] error 发生意外错误:“ https://registry.yarnpkg.com/@angular/forms/-/forms-4.4.3.tgz : Request failed \"403 Forbidden\"”。
pom.xml 的相应部分
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>install node and yarn</id>
<phase>generate-resources</phase>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<yarnVersion>${yarn.version}</yarnVersion>
</configuration>
</execution>
<execution>
<id>yarn set proxy config</id>
<phase>generate-resources</phase>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>config set strict-ssl false -g</arguments>
</configuration>
</execution>
<execution>
<id>yarn install</id>
<phase>generate-resources</phase>
<goals>
<goal>yarn</goal> --- Fails here
</goals>
</execution>
</executions>
</plugin>
Run Code Online (Sandbox Code Playgroud)
谁能指出可能是什么问题?这是日志:
[信息] --- maven-clean-plugin:2.5:clean (default-clean) @ plmapp-web2
[信息] --- frontend-maven-plugin:1.6:install-node-and-yarn(安装节点和纱线)@ plmapp-web2 ---
[INFO] 找到代理:[optional{protocol='http', …