小编Gri*_*rim的帖子

在node.js中嵌套的promises是否正常?

在学习node.js时,我一直在努力解决两周的问题是如何使用node进行同步编程.我发现无论我如何按顺序做事,我总是以嵌套的承诺结束.我发现有一些模块如Q可以帮助保证链的承诺链.

做研究时我不明白的是Promise.all(),Promise.resolve()Promise.reject().Promise.reject通过名称几乎可以自我解释但是在编写应用程序时,我很困惑如何在不破坏应用程序行为的情况下将任何这些包含在函数或对象中.

当来自Java或C#等编程语言时,node.js肯定存在学习曲线.仍然存在的问题是如果promise.js中的promise链接是正常的(最佳实践).

例:

driver.get('https://website.com/login').then(function () {
    loginPage.login('company.admin', 'password').then(function () {
        var employeePage = new EmployeePage(driver.getDriver());

        employeePage.clickAddEmployee().then(function() {
            setTimeout(function() {
                var addEmployeeForm = new AddEmployeeForm(driver.getDriver());

                addEmployeeForm.insertUserName(employee.username).then(function() {
                    addEmployeeForm.insertFirstName(employee.firstName).then(function() {
                        addEmployeeForm.insertLastName(employee.lastName).then(function() {
                            addEmployeeForm.clickCreateEmployee().then(function() {
                                employeePage.searchEmployee(employee);
                            });
                        });
                    });
                });
            }, 750);
        });
    });
});
Run Code Online (Sandbox Code Playgroud)

javascript node.js promise

58
推荐指数
2
解决办法
4万
查看次数

无法匹配任何路线

我的组件显示,但加载页面时收到错误消息.在查看一堆资源后,我似乎无法解决错误消息.

错误

EXCEPTION: Error: Uncaught (in promise): Cannot match any routes. Current segment: 'index.html'. Available routes: ['/login'].
Run Code Online (Sandbox Code Playgroud)

main.component.ts位于index.html中,一旦页面加载,它就会显示上面的错误消息.

import { Component } from '@angular/core';
import { Routes, ROUTER_DIRECTIVES, ROUTER_PROVIDERS } from '@angular/router';

import { LoginComponent } from './login/login.component';

@Component({
    selector: 'main-component',
    template: 
      ' <header>
           <h1>Budget Calculator</h1>
           <a id='login' [routerLink]="['/login']">Login</a>
           <router-outlet></router-outlet>
        </header> '
    directives: [ROUTER_DIRECTIVES],
    providers: [ROUTER_PROVIDERS]
})

@Routes([
    {path: '/login', component: LoginComponent}
])

export class MainComponent {}
Run Code Online (Sandbox Code Playgroud)

login.component.ts通过main.component.ts路由,并在我点击链接时显示,尽管有错误消息.现在我将它设置为在main.component中弹出其他元素,但希望它是页面上显示的唯一组件.基本上用index.component替换index.html中的main.component,如果可能的话,而不是做一大堆样式来显示:none.

import { Component } from '@angular/core';

@Component({
    selector: 'login',
    template: 
        ' <div …
Run Code Online (Sandbox Code Playgroud)

angular2-routing angular

18
推荐指数
1
解决办法
8万
查看次数

是否可以在Java中进行猴子修补,如果没有替代方案?

这是8年前在这里被问到的,从那时起已经过了8年.我想再次问这个问题,看看是否有人开发了一个猴子修补的框架,工具或库.

基本上我需要它是一个java应用程序,我应用自己的补丁.由于这个项目由另一个团队维护,我希望能够保留/应用我制作的任何补丁,以及他们制作的补丁.

java monkeypatching

10
推荐指数
2
解决办法
3332
查看次数

如何测试@Cacheable?

我正在努力在Spring Boot Integration Test中测试@Cacheable.这是我第二天学习如何进行集成测试以及我发现使用旧版本的所有示例.我还看到了一个例子assetEquals("some value", is())但没有任何一个import语句来知道哪个依赖"是"属于哪个.测试在第二次失败

这是我的集成测试....

@RunWith(SpringRunner.class)
@DataJpaTest // used for other methods
@SpringBootTest(classes = TestApplication.class)
@SqlGroup({
        @Sql(executionPhase = ExecutionPhase.BEFORE_TEST_METHOD,
                scripts = "classpath:data/Setting.sql") })
public class SettingRepositoryIT {

    @Mock
    private SettingRepository settingRepository;

    @Autowired
    private Cache applicationCache;


    @Test
    public void testCachedMethodInvocation() {
        List<Setting> firstList = new ArrayList<>();
        Setting settingOne = new Setting();
        settingOne.setKey("first");
        settingOne.setValue("method invocation");
        firstList.add(settingOne);

        List<Setting> secondList = new ArrayList<>();
        Setting settingTwo = new Setting();
        settingTwo.setKey("second");
        settingTwo.setValue("method invocation");
        secondList.add(settingTwo);

        // Set up the mock to return *different* …
Run Code Online (Sandbox Code Playgroud)

java junit integration-testing spring-test

10
推荐指数
1
解决办法
1万
查看次数

函数接口作为lambda来对集合进行排序?

我正在研究lambda表达式,我正在努力研究如何使用java.util.function.Function对集合进行排序.有人可以帮助我,或者给我一些关于如何实现这一点的指示?

我有一本书POJO和一个将书籍存储在一个集合中的类.我试图使用Function接口的lambda表达式返回相同的集合但已排序.我可以使用Collections.sort()并以这种方式返回它,但我认为有一种方法可以使用Function接口.

public class BookTable {

  private Map<Integer, Book> bookMap;

  public BookTable() {
      this.bookMap = new HashMap<>();
  }

  public void addBook(Book book) {
     bookMap.put(size(), book);
  }

  public int size() {
      return bookMap.size();
  }

  public List<Book> getRecord(int key) {
      return Collections.singletonList(bookMap.get(key));
  }

  public List<Book> getRecordsWhere(Predicate<Book> predicate) {
      return bookMap.values()
              .stream()
              .filter(predicate)
              .collect(Collectors.toList());
  }

  public List<Book> getSortedRecords(Function<Book, Comparable> fieldExtractor) {
      // Return sorted list....
  }
}
Run Code Online (Sandbox Code Playgroud)

预订POJO

public class Book {

  private String title;
  private String author;

  public String getTitle() {
      return …
Run Code Online (Sandbox Code Playgroud)

java lambda java-8

8
推荐指数
1
解决办法
2127
查看次数

你如何关闭ChromeDriver服务?

我已经尝试了一段时间试图关闭ChromeDriver服务,我无法开发出如何解决方案.我正在使用mocha和chai进行单元测试.第一次测试通过,第二次测试因错误而失败.

我试着查看selenium-webdrive/chrome.js模块,找不到关闭服务的功能.我试着寻找答案但在网上找不到任何东西.也许我的创建Chrome驱动程序的方法需要重新设计.我尝试使用'selenium-webdriver/chrome.js'.getDefaultService().isRunning()在if语句中包装服务的创建和默认服务的设置,但是第一次测试失败了.我很难过,这很可能是由于缺乏知识.

在每个单元测试期间调用此被调用块

    var service = new chrome.ServiceBuilder(chromePath).build();
    chrome.setDefaultService(service);

    driver = new webdriver.Builder()
        .withCapabilities(webdriver.Capabilities.chrome())
        .build();
Run Code Online (Sandbox Code Playgroud)

这是第一次无错误通过的单元测试

it('Should pass if the Driver is set to equal the Chrome driver by using chrome', function()
{
        var chromeDriver = Driver( { browserName: 'chrome' } );
        expect(chromeDriver.getCapabilities().browserName).to.equal('Google Chrome');
});
Run Code Online (Sandbox Code Playgroud)

这是导致其失败的第二个单元测试

it('Should pass if the Driver is set to equal the Chrome driver by using google chrome', function()
{
        var chromeDriver = Driver( { browserName: 'google chrome' } );
        expect(chromeDriver.getCapabilities().browserName).to.equal('Google Chrome');
});
Run Code Online (Sandbox Code Playgroud)

错误信息:

Error: The …
Run Code Online (Sandbox Code Playgroud)

node.js selenium-chromedriver selenium-webdriver

5
推荐指数
1
解决办法
1094
查看次数

使用Nightwatch.js启动Selenium Server

我正在使用selenium-webdriver并想尝试使用nightwatch.js以查看它是否更易于使用.我按照这里的说明操作.我决定让Nightwatch自动为我启动selenium服务器,所以我做了我认为基于上面提供的链接的正确配置.我得到一个我无法弄清楚的错误,输出结果如下:

Starting selenium server... started - PID:  1760

[Test] Test Suite
=================

Running:  demoTestGoogle

Error retrieving a new session from the selenium server
Error: connect ECONNREFUSED 127.0.0.1:8080
    at Object.exports._errnoException (util.js:856:11)
    at exports._exceptionWithHostPort (util.js:879:20)
    at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1053:14)


Connection refused! Is selenium server started?


Process finished with exit code 1
Run Code Online (Sandbox Code Playgroud)

selenium调试日志文件说明了这一点

13:43:03.394 INFO - Launching a standalone Selenium Server
13:43:03.474 INFO - Java: Oracle Corporation 25.73-b02
13:43:03.474 INFO - OS: Windows 7 6.1 amd64
13:43:03.483 INFO - v2.52.0, …
Run Code Online (Sandbox Code Playgroud)

selenium node.js selenium-server selenium-webdriver nightwatch.js

5
推荐指数
1
解决办法
3346
查看次数

Angular 4 Reactive Form Validator required 在预设值时显示触摸错误

我遇到的问题是表单显示输入字段错误。我不知道它为什么显示,可能是由于缺乏理解。所以我有一个叫做编辑团队的组件。在这个编辑团队组件中,我有一个输入字段,其值设置为当前团队名称。如果我将焦点放在输入文本字段上,然后移除焦点以让我们说背景,那么即使值预设且未更改,表单也会触发“必需”错误。

<div class="form-group">
    <label class="control-label" for="name">Name</label>
    <input tabindex="0" type="text" placeholder="Please enter the team name" title="Please enter the team name" required value=""
               id="name" class="form-control" name="name" formControlName="name" [value]="nameValue">

    // This is the condition for when the error is shown. 
    // So when the input field is touched, check if an error 
    // exists for the validator required. 
    <div class='form-text error' *ngIf="editTeamFormGroup.controls.name.touched">
        <div *ngIf="editTeamFormGroup.controls.name.hasError('required')" class="help-block error small">Team name is required.</div>
    </div>
</div>
Run Code Online (Sandbox Code Playgroud)

这是组件的构造函数和 ngOnIt 方法。订阅用于团队服务中的可观察对象,当团队更改时,值也会更改。

constructor(private fb: FormBuilder,
              private teamService: TeamService,
              private router: …
Run Code Online (Sandbox Code Playgroud)

angular angular-reactive-forms

2
推荐指数
1
解决办法
1943
查看次数

JPA错误 - 没有名为的EntityManager的持久性提供程序

我根本无法解决这个问题,并且有大量的堆栈溢出帖子具有完全相同的错误消息.我已经尝试了所有这些,但仍然无法让它工作.也许我看起来很小.我真的需要帮助,并提前感谢你.

错误信息

Initial EntityManagerFactory creation failed.javax.persistence.PersistenceException: No Persistence provider for EntityManager named org.hibernate.ejb.HibernatePersistence
Exception in thread "main" java.lang.ExceptionInInitializerError
    at util.DatabaseUtil.buildSessionFactory(DatabaseUtil.java:18)
    at util.DatabaseUtil.<clinit>(DatabaseUtil.java:8)
    at Test.main(Test.java:68)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named org.hibernate.ejb.HibernatePersistence
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:61)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:39)
    at util.DatabaseUtil.buildSessionFactory(DatabaseUtil.java:13)
    ... 7 more
Run Code Online (Sandbox Code Playgroud)

目录结构请忽略hibernate.cfg.xml文件,我尝试使用hibernate sessionFactory并遇到了一个我无法解决的重大错误,并说了它的地狱.加上这个帖子说,JPA是首选 在此输入图像描述

这是所需的jar文件 在此输入图像描述

这是persistence.xml文件

<persistence xmlns="http://java.sun.com/xml/ns/persistence"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"
         version="2.0">

  <persistence-unit name="com.learning.jpa">
    <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider>

    <class>com.learning.jpa.entities.User</class>
    <class>com.learning.jpa.entities.Expense</class>
    <class>com.learning.jpa.entities.Category</class>

    <properties>
        <property name="hibernate.connection.pool_size" value="1"/>
        <property name="hibernate.connection.driver_class" value="com.mysql.jdbc.Driver"/>
        <property …
Run Code Online (Sandbox Code Playgroud)

orm hibernate jpa

0
推荐指数
1
解决办法
5633
查看次数